17
17
package net .sqlcipher ;
18
18
19
19
import android .database .CharArrayBuffer ;
20
+ import android .database .Cursor ;
21
+
22
+ import android .content .res .Resources ;
23
+ import android .database .sqlite .SQLiteClosable ;
24
+ import android .os .Binder ;
20
25
import android .os .IBinder ;
21
26
import android .os .Parcel ;
22
27
import android .os .Parcelable ;
28
+ import android .os .Process ;
29
+ import android .util .Log ;
30
+ import android .util .SparseIntArray ;
23
31
24
32
/**
25
33
* A buffer containing multiple cursor rows.
26
34
*/
27
35
public class CursorWindow extends android .database .CursorWindow implements Parcelable {
28
36
/** The pointer to the native window class */
29
37
@ SuppressWarnings ("unused" )
38
+
39
+ /** The pointer to the native window class. set by the native methods in
40
+ * android_database_CursorWindow.cpp
41
+ */
30
42
private int nWindow ;
31
43
32
44
private int mStartPos ;
@@ -227,9 +239,9 @@ public boolean isNull(int row, int col) {
227
239
releaseReference ();
228
240
}
229
241
}
230
-
242
+
231
243
private native boolean isNull_native (int row , int col );
232
-
244
+
233
245
/**
234
246
* Returns a byte array for the given field.
235
247
*
@@ -246,14 +258,50 @@ public byte[] getBlob(int row, int col) {
246
258
}
247
259
}
248
260
261
+ /**
262
+ * Returns the value at (<code>row</code>, <code>col</code>) as a <code>byte</code> array.
263
+ *
264
+ * <p>If the value is null, then <code>null</code> is returned. If the
265
+ * type of column <code>col</code> is a string type, then the result
266
+ * is the array of bytes that make up the internal representation of the
267
+ * string value. If the type of column <code>col</code> is integral or floating-point,
268
+ * then an {@link SQLiteException} is thrown.
269
+ */
249
270
private native byte [] getBlob_native (int row , int col );
250
271
272
+ /**
273
+ * Returns data type of the given column's value.
274
+ *<p>
275
+ * Returned column types are
276
+ * <ul>
277
+ * <li>{@link Cursor#FIELD_TYPE_NULL}</li>
278
+ * <li>{@link Cursor#FIELD_TYPE_INTEGER}</li>
279
+ * <li>{@link Cursor#FIELD_TYPE_FLOAT}</li>
280
+ * <li>{@link Cursor#FIELD_TYPE_STRING}</li>
281
+ * <li>{@link Cursor#FIELD_TYPE_BLOB}</li>
282
+ *</ul>
283
+ *</p>
284
+ *
285
+ * @param row the row to read from, row - getStartPosition() being the actual row in the window
286
+ * @param col the column to read from
287
+ * @return the value type
288
+ */
289
+ public int getType (int row , int col ) {
290
+ acquireReference ();
291
+ try {
292
+ return getType_native (row - mStartPos , col );
293
+ } finally {
294
+ releaseReference ();
295
+ }
296
+ }
297
+
251
298
/**
252
299
* Checks if a field contains either a blob or is null.
253
300
*
254
301
* @param row the row to read from, row - getStartPosition() being the actual row in the window
255
302
* @param col the column to read from
256
303
* @return {@code true} if given field is {@code NULL} or a blob
304
+ * @deprecated use {@link #getType(int, int)} instead
257
305
*/
258
306
public boolean isBlob (int row , int col ) {
259
307
acquireReference ();
@@ -270,6 +318,7 @@ public boolean isBlob(int row, int col) {
270
318
* @param row the row to read from, row - getStartPosition() being the actual row in the window
271
319
* @param col the column to read from
272
320
* @return {@code true} if given field is a long
321
+ * @deprecated use {@link #getType(int, int)} instead
273
322
*/
274
323
public boolean isLong (int row , int col ) {
275
324
acquireReference ();
@@ -286,6 +335,7 @@ public boolean isLong(int row, int col) {
286
335
* @param row the row to read from, row - getStartPosition() being the actual row in the window
287
336
* @param col the column to read from
288
337
* @return {@code true} if given field is a float
338
+ * @deprecated use {@link #getType(int, int)} instead
289
339
*/
290
340
public boolean isFloat (int row , int col ) {
291
341
acquireReference ();
@@ -302,6 +352,7 @@ public boolean isFloat(int row, int col) {
302
352
* @param row the row to read from, row - getStartPosition() being the actual row in the window
303
353
* @param col the column to read from
304
354
* @return {@code true} if given field is {@code NULL} or a String
355
+ * @deprecated use {@link #getType(int, int)} instead
305
356
*/
306
357
public boolean isString (int row , int col ) {
307
358
acquireReference ();
@@ -317,6 +368,8 @@ public boolean isString(int row, int col) {
317
368
private native boolean isInteger_native (int row , int col );
318
369
private native boolean isFloat_native (int row , int col );
319
370
371
+ private native int getType_native (int row , int col );
372
+
320
373
/**
321
374
* Returns a String for the given field.
322
375
*
@@ -333,6 +386,19 @@ public String getString(int row, int col) {
333
386
}
334
387
}
335
388
389
+ /**
390
+ * Returns the value at (<code>row</code>, <code>col</code>) as a <code>String</code>.
391
+ *
392
+ * <p>If the value is null, then <code>null</code> is returned. If the
393
+ * type of column <code>col</code> is integral, then the result is the string
394
+ * that is obtained by formatting the integer value with the <code>printf</code>
395
+ * family of functions using format specifier <code>%lld</code>. If the
396
+ * type of column <code>col</code> is floating-point, then the result is the string
397
+ * that is obtained by formatting the floating-point value with the
398
+ * <code>printf</code> family of functions using format specifier <code>%g</code>.
399
+ * If the type of column <code>col</code> is a blob type, then an
400
+ * {@link SQLiteException} is thrown.
401
+ */
336
402
private native String getString_native (int row , int col );
337
403
338
404
/**
@@ -384,6 +450,17 @@ public long getLong(int row, int col) {
384
450
}
385
451
}
386
452
453
+ /**
454
+ * Returns the value at (<code>row</code>, <code>col</code>) as a <code>long</code>.
455
+ *
456
+ * <p>If the value is null, then <code>0L</code> is returned. If the
457
+ * type of column <code>col</code> is a string type, then the result
458
+ * is the <code>long</code> that is obtained by parsing the string value with
459
+ * <code>strtoll</code>. If the type of column <code>col</code> is
460
+ * floating-point, then the result is the floating-point value casted to a <code>long</code>.
461
+ * If the type of column <code>col</code> is a blob type, then an
462
+ * {@link SQLiteException} is thrown.
463
+ */
387
464
private native long getLong_native (int row , int col );
388
465
389
466
/**
@@ -403,6 +480,17 @@ public double getDouble(int row, int col) {
403
480
}
404
481
}
405
482
483
+ /**
484
+ * Returns the value at (<code>row</code>, <code>col</code>) as a <code>double</code>.
485
+ *
486
+ * <p>If the value is null, then <code>0.0</code> is returned. If the
487
+ * type of column <code>col</code> is a string type, then the result
488
+ * is the <code>double</code> that is obtained by parsing the string value with
489
+ * <code>strtod</code>. If the type of column <code>col</code> is
490
+ * integral, then the result is the integer value casted to a <code>double</code>.
491
+ * If the type of column <code>col</code> is a blob type, then an
492
+ * {@link SQLiteException} is thrown.
493
+ */
406
494
private native double getDouble_native (int row , int col );
407
495
408
496
/**
@@ -485,6 +573,9 @@ public void close() {
485
573
@ Override
486
574
protected void finalize () {
487
575
// Just in case someone forgot to call close...
576
+ if (nWindow == 0 ) {
577
+ return ;
578
+ }
488
579
close_native ();
489
580
}
490
581
@@ -534,6 +625,7 @@ public CursorWindow(Parcel source,int foo) {
534
625
@ Override
535
626
protected void onAllReferencesReleased () {
536
627
close_native ();
537
- super .onAllReferencesReleased ();
628
+
629
+ super .onAllReferencesReleased ();
538
630
}
539
631
}
0 commit comments