Class CursorWindow
-
- All Implemented Interfaces:
-
java.io.Closeable,java.lang.AutoCloseable
public class CursorWindow extends SQLiteClosable
A buffer containing multiple cursor rows.
-
-
Field Summary
Fields Modifier and Type Field Description public static intPREFERRED_CURSOR_WINDOW_SIZEpublic final static intDEFAULT_CURSOR_WINDOW_SIZEpublic longmWindowPtr
-
Constructor Summary
Constructors Constructor Description CursorWindow(String name)Creates a new empty cursor with default cursor size (currently 2MB) CursorWindow(String name, int windowSizeBytes)Creates a new empty cursor window and gives it a name.
-
Method Summary
Modifier and Type Method Description StringgetName()Gets the name of this cursor window, never null. voidclear()Clears out the existing contents of the window, making it safe to reuse for new data. intgetStartPosition()Gets the start position of this cursor window. voidsetStartPosition(int pos)Sets the start position of this cursor window. intgetNumRows()Gets the number of rows in this window. booleansetNumColumns(int columnNum)Sets the number of columns in this window. booleanallocRow()Allocates a new row at the end of this cursor window. voidfreeLastRow()Frees the last row in this cursor window. intgetType(int row, int column)Returns the type of the field at the specified row and column index. Array<byte>getBlob(int row, int column)Gets the value of the field at the specified row and column index as a byte array. StringgetString(int row, int column)Gets the value of the field at the specified row and column index as a string. voidcopyStringToBuffer(int row, int column, CharArrayBuffer buffer)Copies the text of the field at the specified row and column index into a CharArrayBuffer. longgetLong(int row, int column)Gets the value of the field at the specified row and column index as a long.doublegetDouble(int row, int column)Gets the value of the field at the specified row and column index as a double.shortgetShort(int row, int column)Gets the value of the field at the specified row and column index as a short.intgetInt(int row, int column)Gets the value of the field at the specified row and column index as an int.floatgetFloat(int row, int column)Gets the value of the field at the specified row and column index as a float.booleanputBlob(Array<byte> value, int row, int column)Copies a byte array into the field at the specified row and column index. booleanputString(String value, int row, int column)Copies a string into the field at the specified row and column index. booleanputLong(long value, int row, int column)Puts a long integer into the field at the specified row and column index. booleanputDouble(double value, int row, int column)Puts a double-precision floating point value into the field at the specified row and column index. booleanputNull(int row, int column)Puts a null value into the field at the specified row and column index. booleanisNull(int row, int column)booleanisBlob(int row, int column)StringtoString()intgetWindowSizeBytes()-
Methods inherited from class net.zetetic.database.sqlcipher.SQLiteClosable
acquireReference, close, releaseReference, releaseReferenceFromContainer -
Methods inherited from class java.io.Closeable
close -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
CursorWindow
CursorWindow(String name)
Creates a new empty cursor with default cursor size (currently 2MB)
-
CursorWindow
CursorWindow(String name, int windowSizeBytes)
Creates a new empty cursor window and gives it a name.
The cursor initially has no rows or columns. Call setNumColumns to set the number of columns before adding any rows to the cursor.
- Parameters:
name- The name of the cursor window, or null if none.windowSizeBytes- Size of cursor window in bytes.Note: Memory is dynamically allocated as data rows are added tothe window.
-
-
Method Detail
-
clear
void clear()
Clears out the existing contents of the window, making it safe to reuse for new data.
The start position (getStartPosition), number of rows (getNumRows), and number of columns in the cursor are all reset to zero.
-
getStartPosition
int getStartPosition()
Gets the start position of this cursor window.
The start position is the zero-based index of the first row that this window contains relative to the entire result set of the Cursor.
- Returns:
The zero-based start position.
-
setStartPosition
void setStartPosition(int pos)
Sets the start position of this cursor window.
The start position is the zero-based index of the first row that this window contains relative to the entire result set of the Cursor.
- Parameters:
pos- The new zero-based start position.
-
getNumRows
int getNumRows()
Gets the number of rows in this window.
- Returns:
The number of rows in this cursor window.
-
setNumColumns
boolean setNumColumns(int columnNum)
Sets the number of columns in this window.
This method must be called before any rows are added to the window, otherwise it will fail to set the number of columns if it differs from the current number of columns.
- Parameters:
columnNum- The new number of columns.- Returns:
True if successful.
-
allocRow
boolean allocRow()
Allocates a new row at the end of this cursor window.
- Returns:
True if successful, false if the cursor window is out of memory.
-
freeLastRow
void freeLastRow()
Frees the last row in this cursor window.
-
getType
int getType(int row, int column)
Returns the type of the field at the specified row and column index.
The returned field types are:
- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
The field type.
-
getBlob
Array<byte> getBlob(int row, int column)
Gets the value of the field at the specified row and column index as a byte array.
The result is determined as follows:
- If the field is of type FIELD_TYPE_NULL, then the result is
null. - If the field is of type FIELD_TYPE_BLOB, then the result is the blob value.
- If the field is of type FIELD_TYPE_STRING, then the result is the array of bytes that make up the internal representation of the string value.
- If the field is of type FIELD_TYPE_INTEGER or FIELD_TYPE_FLOAT, then a SQLiteException is thrown.
- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
The value of the field as a byte array.
- If the field is of type FIELD_TYPE_NULL, then the result is
-
getString
String getString(int row, int column)
Gets the value of the field at the specified row and column index as a string.
The result is determined as follows:
- If the field is of type FIELD_TYPE_NULL, then the result is
null. - If the field is of type FIELD_TYPE_STRING, then the result is the string value.
- If the field is of type FIELD_TYPE_INTEGER, then the result is a string representation of the integer in decimal, obtained by formatting the value with the
printffamily of functions using format specifier%lld. - If the field is of type FIELD_TYPE_FLOAT, then the result is a string representation of the floating-point value in decimal, obtained by formatting the value with the
printffamily of functions using format specifier%g. - If the field is of type FIELD_TYPE_BLOB, then a SQLiteException is thrown.
- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
The value of the field as a string.
- If the field is of type FIELD_TYPE_NULL, then the result is
-
copyStringToBuffer
void copyStringToBuffer(int row, int column, CharArrayBuffer buffer)
Copies the text of the field at the specified row and column index into a CharArrayBuffer.
The buffer is populated as follows:
- If the buffer is too small for the value to be copied, then it is automatically resized.
- If the field is of type FIELD_TYPE_NULL, then the buffer is set to an empty string.
- If the field is of type FIELD_TYPE_STRING, then the buffer is set to the contents of the string.
- If the field is of type FIELD_TYPE_INTEGER, then the buffer is set to a string representation of the integer in decimal, obtained by formatting the value with the
printffamily of functions using format specifier%lld. - If the field is of type FIELD_TYPE_FLOAT, then the buffer is set to a string representation of the floating-point value in decimal, obtained by formatting the value with the
printffamily of functions using format specifier%g. - If the field is of type FIELD_TYPE_BLOB, then a SQLiteException is thrown.
- Parameters:
row- The zero-based row index.column- The zero-based column index.buffer- The CharArrayBuffer to hold the string.
-
getLong
long getLong(int row, int column)
Gets the value of the field at the specified row and column index as a
long.The result is determined as follows:
- If the field is of type FIELD_TYPE_NULL, then the result is
0L. - If the field is of type FIELD_TYPE_STRING, then the result is the value obtained by parsing the string value with
strtoll. - If the field is of type FIELD_TYPE_INTEGER, then the result is the
longvalue. - If the field is of type FIELD_TYPE_FLOAT, then the result is the floating-point value converted to a
long. - If the field is of type FIELD_TYPE_BLOB, then a SQLiteException is thrown.
- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
The value of the field as a
long.
- If the field is of type FIELD_TYPE_NULL, then the result is
-
getDouble
double getDouble(int row, int column)
Gets the value of the field at the specified row and column index as a
double.The result is determined as follows:
- If the field is of type FIELD_TYPE_NULL, then the result is
0.0. - If the field is of type FIELD_TYPE_STRING, then the result is the value obtained by parsing the string value with
strtod. - If the field is of type FIELD_TYPE_INTEGER, then the result is the integer value converted to a
double. - If the field is of type FIELD_TYPE_FLOAT, then the result is the
doublevalue. - If the field is of type FIELD_TYPE_BLOB, then a SQLiteException is thrown.
- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
The value of the field as a
double.
- If the field is of type FIELD_TYPE_NULL, then the result is
-
getShort
short getShort(int row, int column)
Gets the value of the field at the specified row and column index as a
short.The result is determined by invoking getLong and converting the result to
short.- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
The value of the field as a
short.
-
getInt
int getInt(int row, int column)
Gets the value of the field at the specified row and column index as an
int.The result is determined by invoking getLong and converting the result to
int.- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
The value of the field as an
int.
-
getFloat
float getFloat(int row, int column)
Gets the value of the field at the specified row and column index as a
float.The result is determined by invoking getDouble and converting the result to
float.- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
The value of the field as an
float.
-
putBlob
boolean putBlob(Array<byte> value, int row, int column)
Copies a byte array into the field at the specified row and column index.
- Parameters:
value- The value to store.row- The zero-based row index.column- The zero-based column index.- Returns:
True if successful.
-
putString
boolean putString(String value, int row, int column)
Copies a string into the field at the specified row and column index.
- Parameters:
value- The value to store.row- The zero-based row index.column- The zero-based column index.- Returns:
True if successful.
-
putLong
boolean putLong(long value, int row, int column)
Puts a long integer into the field at the specified row and column index.
- Parameters:
value- The value to store.row- The zero-based row index.column- The zero-based column index.- Returns:
True if successful.
-
putDouble
boolean putDouble(double value, int row, int column)
Puts a double-precision floating point value into the field at the specified row and column index.
- Parameters:
value- The value to store.row- The zero-based row index.column- The zero-based column index.- Returns:
True if successful.
-
putNull
boolean putNull(int row, int column)
Puts a null value into the field at the specified row and column index.
- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
True if successful.
-
isNull
boolean isNull(int row, int column)
-
isBlob
boolean isBlob(int row, int column)
-
getWindowSizeBytes
int getWindowSizeBytes()
-
-
-
-