SQLite Android Bindings
Check-in [71351f6267]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a resource leak in SQLiteConnection.nativeExecuteForCursorWindow().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | api-level-15
Files: files | file ages | folders
SHA1:71351f6267818789a7699aa3ec23899acf07ffa4
User & Date: dan 2014-06-18 10:14:46
Context
2014-11-05
19:19
Merge latest fixes with this branch. check-in: 60e268f5be user: dan tags: api-level-15
2014-06-18
10:14
Fix a resource leak in SQLiteConnection.nativeExecuteForCursorWindow(). check-in: 71351f6267 user: dan tags: api-level-15
10:11
Fix a resource leak in SQLiteConnection.nativeExecuteForCursorWindow(). check-in: 3558b4d73c user: dan tags: trunk
2014-06-11
19:10
Merge trunk with this branch. check-in: 7fbe992d8f user: dan tags: api-level-15
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to jni/sqlite/android_database_SQLiteConnection.cpp.

673
674
675
676
677
678
679

680
681
682
683
684
685
686
687
688
689
690
691

692
693
694
695
696
697
698
        break;
      }

      case SQLITE_TEXT: {
        const char *zVal = (const char*)sqlite3_column_text(pStmt, i);
        jstring val = pEnv->NewStringUTF(zVal);
        bOk = pEnv->CallBooleanMethod(win, aMethod[CW_PUTSTRING].id, val, iRow, i);

        break;
      }

      default: {
        assert( sqlite3_column_type(pStmt, i)==SQLITE_BLOB );

        const jbyte *p = (const jbyte*)sqlite3_column_blob(pStmt, i);
        int n = sqlite3_column_bytes(pStmt, i);

        jbyteArray val = pEnv->NewByteArray(n);
        pEnv->SetByteArrayRegion(val, 0, n, p);
        bOk = pEnv->CallBooleanMethod(win, aMethod[CW_PUTBLOB].id, val, iRow, i);

        break;
      }
    }

    if( bOk==0 ){
      pEnv->CallVoidMethod(win, aMethod[CW_FREELASTROW].id);
    }







>





<


<



>







673
674
675
676
677
678
679
680
681
682
683
684
685

686
687

688
689
690
691
692
693
694
695
696
697
698
        break;
      }

      case SQLITE_TEXT: {
        const char *zVal = (const char*)sqlite3_column_text(pStmt, i);
        jstring val = pEnv->NewStringUTF(zVal);
        bOk = pEnv->CallBooleanMethod(win, aMethod[CW_PUTSTRING].id, val, iRow, i);
        pEnv->DeleteLocalRef(val);
        break;
      }

      default: {
        assert( sqlite3_column_type(pStmt, i)==SQLITE_BLOB );

        const jbyte *p = (const jbyte*)sqlite3_column_blob(pStmt, i);
        int n = sqlite3_column_bytes(pStmt, i);

        jbyteArray val = pEnv->NewByteArray(n);
        pEnv->SetByteArrayRegion(val, 0, n, p);
        bOk = pEnv->CallBooleanMethod(win, aMethod[CW_PUTBLOB].id, val, iRow, i);
        pEnv->DeleteLocalRef(val);
        break;
      }
    }

    if( bOk==0 ){
      pEnv->CallVoidMethod(win, aMethod[CW_FREELASTROW].id);
    }

Changes to src/org/sqlite/app/customsqlite/CustomSqlite.java.

166
167
168
169
170
171
172
















































173
174
175
176
177
178
179
...
307
308
309
310
311
312
313

314
315
316
317
318
319
320
      test_result("thread_test_2", res, "concurrent");
    }
  }

  /*
  ** Use a Cursor to loop through the results of a SELECT query.
  */
















































  public void csr_test_1() throws Exception {
    SQLiteDatabase.deleteDatabase(DB_PATH);
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(DB_PATH, null);
    String res = "";

    db.execSQL("CREATE TABLE t1(x)");
    db.execSQL("INSERT INTO t1 VALUES ('one'), ('two'), ('three')");
................................................................................
    myTV.setText("");
    myNErr = 0;
    myNTest = 0;

    try {
      report_version();
      csr_test_1();

      thread_test_1();
      thread_test_2(); 
      see_test_1();
      see_test_2();

      myTV.append("\n" + myNErr + " errors from " + myNTest + " tests\n");
    } catch(Exception e) {







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>







166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
...
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
      test_result("thread_test_2", res, "concurrent");
    }
  }

  /*
  ** Use a Cursor to loop through the results of a SELECT query.
  */
  public void csr_test_2() throws Exception {
    SQLiteDatabase.deleteDatabase(DB_PATH);
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(DB_PATH, null);
    String res = "";
    String expect = "";
    int i;
    int nRow = 0;

    db.execSQL("CREATE TABLE t1(x)");
    db.execSQL("BEGIN");
    for(i=0; i<1000; i++){
      db.execSQL("INSERT INTO t1 VALUES ('one'), ('two'), ('three')");
      expect += ".one.two.three";
    }
    db.execSQL("COMMIT");
    Cursor c = db.rawQuery("SELECT x FROM t1", null);
    if( c!=null ){
      boolean bRes;
      for(bRes=c.moveToFirst(); bRes; bRes=c.moveToNext()){
        String x = c.getString(0);
        res = res + "." + x;
      }
    }else{
      test_warning("csr_test_1", "c==NULL");
    }
    test_result("csr_test_2.1", res, expect);

    db.execSQL("BEGIN");
    for(i=0; i<1000; i++){
      db.execSQL("INSERT INTO t1 VALUES (X'123456'), (X'789ABC'), (X'DEF012')");
      db.execSQL("INSERT INTO t1 VALUES (45), (46), (47)");
      db.execSQL("INSERT INTO t1 VALUES (8.1), (8.2), (8.3)");
      db.execSQL("INSERT INTO t1 VALUES (NULL), (NULL), (NULL)");
    }
    db.execSQL("COMMIT");

    c = db.rawQuery("SELECT x FROM t1", null);
    if( c!=null ){
      boolean bRes;
      for(bRes=c.moveToFirst(); bRes; bRes=c.moveToNext()) nRow++;
    }else{
      test_warning("csr_test_1", "c==NULL");
    }
    test_result("csr_test_2.2", "" + nRow, "15000");

    db.close();
  }

  public void csr_test_1() throws Exception {
    SQLiteDatabase.deleteDatabase(DB_PATH);
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(DB_PATH, null);
    String res = "";

    db.execSQL("CREATE TABLE t1(x)");
    db.execSQL("INSERT INTO t1 VALUES ('one'), ('two'), ('three')");
................................................................................
    myTV.setText("");
    myNErr = 0;
    myNTest = 0;

    try {
      report_version();
      csr_test_1();
      csr_test_2();
      thread_test_1();
      thread_test_2(); 
      see_test_1();
      see_test_2();

      myTV.append("\n" + myNErr + " errors from " + myNTest + " tests\n");
    } catch(Exception e) {