-
- 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 int
PREFERRED_CURSOR_WINDOW_SIZE
public final static int
DEFAULT_CURSOR_WINDOW_SIZE
public long
mWindowPtr
-
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 String
getName()
Gets the name of this cursor window, never null. void
clear()
Clears out the existing contents of the window, making it safe to reusefor new data. int
getStartPosition()
Gets the start position of this cursor window. void
setStartPosition(int pos)
Sets the start position of this cursor window. int
getNumRows()
Gets the number of rows in this window. boolean
setNumColumns(int columnNum)
Sets the number of columns in this window. boolean
allocRow()
Allocates a new row at the end of this cursor window. void
freeLastRow()
Frees the last row in this cursor window. int
getType(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. String
getString(int row, int column)
Gets the value of the field at the specified row and column index as a string. void
copyStringToBuffer(int row, int column, CharArrayBuffer buffer)
Copies the text of the field at the specified row and column index intoa CharArrayBuffer. long
getLong(int row, int column)
Gets the value of the field at the specified row and column index as a long
.double
getDouble(int row, int column)
Gets the value of the field at the specified row and column index as a double
.short
getShort(int row, int column)
Gets the value of the field at the specified row and column index as a short
.int
getInt(int row, int column)
Gets the value of the field at the specified row and column index as an int
.float
getFloat(int row, int column)
Gets the value of the field at the specified row and column index as a float
.boolean
putBlob(Array<byte> value, int row, int column)
Copies a byte array into the field at the specified row and column index. boolean
putString(String value, int row, int column)
Copies a string into the field at the specified row and column index. boolean
putLong(long value, int row, int column)
Puts a long integer into the field at the specified row and column index. boolean
putDouble(double value, int row, int column)
Puts a double-precision floating point value into the field at thespecified row and column index. boolean
putNull(int row, int column)
Puts a null value into the field at the specified row and column index. boolean
isNull(int row, int column)
boolean
isBlob(int row, int column)
String
toString()
int
getWindowSizeBytes()
-
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.- 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 reusefor 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 containsrelative to the entire result set of the Cursor.
-
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 containsrelative 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.
-
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, otherwiseit will fail to set the number of columns if it differs from the current numberof columns.
- Parameters:
columnNum
- The new number of columns.
-
allocRow
boolean allocRow()
Allocates a new row at the end of this cursor window.
-
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.
-
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 resultis
null
. - If the field is of type FIELD_TYPE_BLOB, then the resultis the blob value.
- If the field is of type FIELD_TYPE_STRING, then the resultis the array of bytes that make up the internal representation of thestring 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.
- If the field is of type FIELD_TYPE_NULL, then the resultis
-
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 resultis
null
. - If the field is of type FIELD_TYPE_STRING, then the resultis the string value.
- If the field is of type FIELD_TYPE_INTEGER, then the resultis a string representation of the integer in decimal, obtained by formatting thevalue with the
printf
family of functions usingformat specifier%lld
. - If the field is of type FIELD_TYPE_FLOAT, then the resultis a string representation of the floating-point value in decimal, obtained byformatting the value with the
printf
family of functions usingformat 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.
- If the field is of type FIELD_TYPE_NULL, then the resultis
-
copyStringToBuffer
void copyStringToBuffer(int row, int column, CharArrayBuffer buffer)
Copies the text of the field at the specified row and column index intoa CharArrayBuffer.
The buffer is populated as follows:
- If the buffer is too small for the value to be copied, then it isautomatically resized.
- If the field is of type FIELD_TYPE_NULL, then the bufferis set to an empty string.
- If the field is of type FIELD_TYPE_STRING, then the bufferis set to the contents of the string.
- If the field is of type FIELD_TYPE_INTEGER, then the bufferis set to a string representation of the integer in decimal, obtained by formatting thevalue with the
printf
family of functions usingformat specifier%lld
. - If the field is of type FIELD_TYPE_FLOAT, then the buffer isset to a string representation of the floating-point value in decimal, obtained byformatting the value with the
printf
family of functions usingformat 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 resultis
0L
. - If the field is of type FIELD_TYPE_STRING, then the resultis the value obtained by parsing the string value with
strtoll
. - If the field is of type FIELD_TYPE_INTEGER, then the resultis the
long
value. - If the field is of type FIELD_TYPE_FLOAT, then the resultis 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.
- If the field is of type FIELD_TYPE_NULL, then the resultis
-
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 resultis
0.0
. - If the field is of type FIELD_TYPE_STRING, then the resultis the value obtained by parsing the string value with
strtod
. - If the field is of type FIELD_TYPE_INTEGER, then the resultis the integer value converted to a
double
. - If the field is of type FIELD_TYPE_FLOAT, then the resultis the
double
value. - 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.
- If the field is of type FIELD_TYPE_NULL, then the resultis
-
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 theresult to
short
.- Parameters:
row
- The zero-based row index.column
- The zero-based column index.
-
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 theresult to
int
.- Parameters:
row
- The zero-based row index.column
- The zero-based column index.
-
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 theresult to
float
.- Parameters:
row
- The zero-based row index.column
- The zero-based column index.
-
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.
-
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.
-
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.
-
putDouble
boolean putDouble(double value, int row, int column)
Puts a double-precision floating point value into the field at thespecified row and column index.
- Parameters:
value
- The value to store.row
- The zero-based row index.column
- The zero-based column index.
-
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.
-
isNull
boolean isNull(int row, int column)
-
isBlob
boolean isBlob(int row, int column)
-
getWindowSizeBytes
int getWindowSizeBytes()
-
-
-
-