Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-5196

Reading from a database crashes the app

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Cannot Reproduce
    • Affects Version/s: None
    • Fix Version/s: Sprint 2011-37
    • Component/s: iOS
    • Labels:
    • Environment:

      Description

      Starting from 1.7.0 up to the current 1.7.3.v20110808134952 CI build I'm getting random crashes in my app. I've managed to reproduce them, just copy the following code into the app.js of a new project:

      app.js

      function read_from_db(thisLabel)
      {
        Ti.API.info('read_from_db: start');
        Ti.API.info('thisLabel' + thisLabel);
        thisLabel.text = 'Reading from the database...';
        var db = Ti.Database.open('data.db');
       
        for(var i=0; i<10000; i++){
          var resultSet = db.execute('select * from data');
          if(resultSet.isValidRow()) {
            Ti.API.info('Database row: (' + i + ') ' + resultSet.fieldByName('col1') + ' / '+ resultSet.fieldByName('col2'));
          }
          resultSet.close();
        }
        db.close();
        thisLabel.text = 'Finished reading from the database.';
        Ti.API.info('read_from_db: end');
      }
       
      var number_of_iterations = 5000;	// This is not required
      var number_of_db_rows = 200;
       
      //Create and initialize the database
      var db = Ti.Database.open('data.db');
      db.execute('create table if not exists data (col1 primary key,col2)');
      db.execute('begin transaction');
      db.execute('delete from data');
      for(var i=0; i<number_of_db_rows; i++) {
        db.execute('insert or replace into data (col1,col2) values (?,?)',i,i+1);
      }
      db.execute('commit transaction');
      db.close();
       
      var tabGroup = Ti.UI.createTabGroup();
       
      var win1 = Ti.UI.createWindow({
        backgroundColor: 'green',
        layout:'vertical'
      });
       
      var b = Ti.UI.createButton({
        title:'Read from the DB',
        top:60,
        height:50
      });
      win1.add(b);
       
      var label = Ti.UI.createLabel({
        top:60,
        height:60,
        color:'white',
        text:'Click the button to start'
      });
      win1.add(label);
       
      var Tab1 = Titanium.UI.createTab({
        title:'Tab 1',
        window:win1
      });
       
      tabGroup.addTab(Tab1);
      tabGroup.open();
       
      b.addEventListener('click',function(e) {
        read_from_db(label);
      });
      

      Clicking the button will crash the iPhone simulator.

      Depending on the timing or the numbers chosen at the start sometimes this code will fail with a 'resultSet.isValidRow is not a valid function' instead of crashing.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                srahim Sabil Rahim
                Reporter:
                jsilva João Silva
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-4397
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Integration