SQLite Android Bindings

Check-in [3558b4d73c]
Login

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

Overview
Comment:Fix a resource leak in SQLiteConnection.nativeExecuteForCursorWindow().
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3558b4d73cc688c2608d64ce75e09751ef76d86b
User & Date: dan 2014-06-18 10:11:37.890
Context
2014-10-16
20:06
Update to 3.8.7. Add -DHAVE_STRCHRNUL to Android.mk file. (check-in: f9a25feeb0 user: dan tags: trunk)
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
18:59
Changes so that package names always match paths on disk, as required by eclipse. (check-in: c93d2517dc user: dan tags: trunk)
Changes
Unified Diff 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
      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')");







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







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
      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')");
307
308
309
310
311
312
313

314
315
316
317
318
319
320
    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) {







>







355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
    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) {