1717package net .sqlcipher ;
1818
1919import 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 ;
2025import android .os .IBinder ;
2126import android .os .Parcel ;
2227import android .os .Parcelable ;
28+ import android .os .Process ;
29+ import android .util .Log ;
30+ import android .util .SparseIntArray ;
2331
2432/**
2533 * A buffer containing multiple cursor rows.
2634 */
2735public class CursorWindow extends android .database .CursorWindow implements Parcelable {
2836 /** The pointer to the native window class */
2937 @ SuppressWarnings ("unused" )
38+
39+ /** The pointer to the native window class. set by the native methods in
40+ * android_database_CursorWindow.cpp
41+ */
3042 private int nWindow ;
3143
3244 private int mStartPos ;
@@ -227,9 +239,9 @@ public boolean isNull(int row, int col) {
227239 releaseReference ();
228240 }
229241 }
230-
242+
231243 private native boolean isNull_native (int row , int col );
232-
244+
233245 /**
234246 * Returns a byte array for the given field.
235247 *
@@ -246,14 +258,50 @@ public byte[] getBlob(int row, int col) {
246258 }
247259 }
248260
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+ */
249270 private native byte [] getBlob_native (int row , int col );
250271
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+
251298 /**
252299 * Checks if a field contains either a blob or is null.
253300 *
254301 * @param row the row to read from, row - getStartPosition() being the actual row in the window
255302 * @param col the column to read from
256303 * @return {@code true} if given field is {@code NULL} or a blob
304+ * @deprecated use {@link #getType(int, int)} instead
257305 */
258306 public boolean isBlob (int row , int col ) {
259307 acquireReference ();
@@ -270,6 +318,7 @@ public boolean isBlob(int row, int col) {
270318 * @param row the row to read from, row - getStartPosition() being the actual row in the window
271319 * @param col the column to read from
272320 * @return {@code true} if given field is a long
321+ * @deprecated use {@link #getType(int, int)} instead
273322 */
274323 public boolean isLong (int row , int col ) {
275324 acquireReference ();
@@ -286,6 +335,7 @@ public boolean isLong(int row, int col) {
286335 * @param row the row to read from, row - getStartPosition() being the actual row in the window
287336 * @param col the column to read from
288337 * @return {@code true} if given field is a float
338+ * @deprecated use {@link #getType(int, int)} instead
289339 */
290340 public boolean isFloat (int row , int col ) {
291341 acquireReference ();
@@ -302,6 +352,7 @@ public boolean isFloat(int row, int col) {
302352 * @param row the row to read from, row - getStartPosition() being the actual row in the window
303353 * @param col the column to read from
304354 * @return {@code true} if given field is {@code NULL} or a String
355+ * @deprecated use {@link #getType(int, int)} instead
305356 */
306357 public boolean isString (int row , int col ) {
307358 acquireReference ();
@@ -317,6 +368,8 @@ public boolean isString(int row, int col) {
317368 private native boolean isInteger_native (int row , int col );
318369 private native boolean isFloat_native (int row , int col );
319370
371+ private native int getType_native (int row , int col );
372+
320373 /**
321374 * Returns a String for the given field.
322375 *
@@ -333,6 +386,19 @@ public String getString(int row, int col) {
333386 }
334387 }
335388
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+ */
336402 private native String getString_native (int row , int col );
337403
338404 /**
@@ -384,6 +450,17 @@ public long getLong(int row, int col) {
384450 }
385451 }
386452
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+ */
387464 private native long getLong_native (int row , int col );
388465
389466 /**
@@ -403,6 +480,17 @@ public double getDouble(int row, int col) {
403480 }
404481 }
405482
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+ */
406494 private native double getDouble_native (int row , int col );
407495
408496 /**
@@ -485,6 +573,9 @@ public void close() {
485573 @ Override
486574 protected void finalize () {
487575 // Just in case someone forgot to call close...
576+ if (nWindow == 0 ) {
577+ return ;
578+ }
488579 close_native ();
489580 }
490581
@@ -534,6 +625,7 @@ public CursorWindow(Parcel source,int foo) {
534625 @ Override
535626 protected void onAllReferencesReleased () {
536627 close_native ();
537- super .onAllReferencesReleased ();
628+
629+ super .onAllReferencesReleased ();
538630 }
539631}
0 commit comments