Kompex SQLite Wrapper
1.11.14
|
Administration of existing BLOBs. More...
#include <KompexSQLiteBlob.h>
Public Member Functions | |
SQLiteBlob () | |
Constructor. More... | |
SQLiteBlob (SQLiteDatabase *db, std::string symbolicDatabaseName, std::string tableName, std::string columnName, int64 rowId, BLOB_ACCESS_MODE accessMode=BLOB_READWRITE) | |
virtual | ~SQLiteBlob () |
void | OpenBlob (SQLiteDatabase *db, std::string symbolicDatabaseName, std::string tableName, std::string columnName, int64 rowId, BLOB_ACCESS_MODE accessMode=BLOB_READWRITE) |
void | CloseBlob () |
int | GetBlobSize () const |
Returns the size in bytes of the BLOB. More... | |
void | ReadBlob (void *buffer, int numberOfBytes, int offset=0) |
void | WriteBlob (const void *buffer, int numberOfBytes, int offset=0) |
Protected Member Functions | |
sqlite3_blob * | GetBlobHandle () const |
Returns the BLOB handle. More... | |
Private Attributes | |
sqlite3_blob * | mBlobHandle |
BLOB handle. More... | |
SQLiteDatabase * | mDatabase |
Database pointer. More... | |
Administration of existing BLOBs.
Kompex::SQLiteBlob::SQLiteBlob | ( | ) |
Constructor.
Kompex::SQLiteBlob::SQLiteBlob | ( | SQLiteDatabase * | db, |
std::string | symbolicDatabaseName, | ||
std::string | tableName, | ||
std::string | columnName, | ||
int64 | rowId, | ||
BLOB_ACCESS_MODE | accessMode = BLOB_READWRITE |
||
) |
Constructor.
Opens a handle to a BLOB located in row 'rowId', column 'columnName', table 'tableName' in database 'symbolicDatabaseName',
in other words, the same BLOB that would be selected by: SELECT columnName FROM symbolicDatabaseName.tableName WHERE rowid = rowId;
db | Database in which we will work. |
symbolicDatabaseName | Name of the database in which the BLOB is located - note that the database name is not the filename that contains the database but rather the symbolic name of the database that appears after the AS keyword when the database is connected using ATTACH. For the main database file, the database name is "main". For TEMP tables, the database name is "temp". |
tableName | Name of the table in which the BLOB is located. |
columnName | Name of the column in which the BLOB is located. |
rowId | ID of the dataset in which the BLOB is located. |
accessMode | BLOB_READONLY - opens the blob in read-only mode. BLOB_READWRITE - opens the blob in read and write mode. It is not possible to open a column that is part of an index or primary key for writing. If foreign key constraints are enabled, it is not possible to open a column that is part of a child key for writing. |
|
virtual |
Destructor.
Calls also CloseBlob() so that you don't need to close the BLOB explicitly.
void Kompex::SQLiteBlob::CloseBlob | ( | ) |
Closes an open BLOB handle.
Shall cause the current transaction to commit if there are no other BLOBs,
no pending prepared statements, and the database connection is in autocommit mode.
If any writes were made to the BLOB, they might be held in cache until the close operation if they will fit.
|
inlineprotected |
Returns the BLOB handle.
int Kompex::SQLiteBlob::GetBlobSize | ( | ) | const |
Returns the size in bytes of the BLOB.
void Kompex::SQLiteBlob::OpenBlob | ( | SQLiteDatabase * | db, |
std::string | symbolicDatabaseName, | ||
std::string | tableName, | ||
std::string | columnName, | ||
int64 | rowId, | ||
BLOB_ACCESS_MODE | accessMode = BLOB_READWRITE |
||
) |
Opens a handle to a BLOB located in row 'rowId', column 'columnName', table 'tableName' in database 'symbolicDatabaseName',
in other words, the same BLOB that would be selected by: SELECT columnName FROM symbolicDatabaseName.tableName WHERE rowid = rowId;
db | Database in which we will work. |
symbolicDatabaseName | Name of the database in which the BLOB is located - note that the database name is not the filename that contains the database but rather the symbolic name of the database that appears after the AS keyword when the database is connected using ATTACH. For the main database file, the database name is "main". For TEMP tables, the database name is "temp". |
tableName | Name of the table in which the BLOB is located. |
columnName | Name of the column in which the BLOB is located. |
rowId | ID of the dataset in which the BLOB is located. |
accessMode | BLOB_READONLY - opens the blob in read-only mode. BLOB_READWRITE - opens the blob in read and write mode. It is not possible to open a column that is part of an index or primary key for writing. If foreign key constraints are enabled, it is not possible to open a column that is part of a child key for writing. |
void Kompex::SQLiteBlob::ReadBlob | ( | void * | buffer, |
int | numberOfBytes, | ||
int | offset = 0 |
||
) |
Reads the data from the BLOB into your supplied buffer.
Please note: If the row that a BLOB handle points to is modified by an UPDATE, DELETE, or by ON CONFLICT side-effects
then the BLOB handle is marked as "expired". This is true if any column of the row is changed, even a column other than
the one the BLOB handle is open on. If a BLOB handle is marked as "expired", the call of ReadBlob() will fail and throw an exception.
buffer | Buffer in which the BLOB data will be read. |
numberOfBytes | Number of bytes which will be copied in the buffer. |
offset | Read the BLOB data starting at this offset. |
void Kompex::SQLiteBlob::WriteBlob | ( | const void * | buffer, |
int | numberOfBytes, | ||
int | offset = 0 |
||
) |
Writes the data from your supplied buffer into the BLOB.
This function may only modify the contents of the BLOB; it is not possible to increase the size of the BLOB.
Please note: If the row that a BLOB handle points to is modified by an UPDATE, DELETE, or by ON CONFLICT side-effects
then the BLOB handle is marked as "expired". This is true if any column of the row is changed, even a column other than
the one the BLOB handle is open on. If a BLOB handle is marked as "expired", the call of WriteBlob() will fail and throw an exception.
Writes to the BLOB that occurred before the BLOB handle expired are not rolled back by the expiration of the handle,
though of course those changes might have been overwritten by the statement that expired the BLOB handle or by other independent statements.
buffer | Buffer in which the BLOB data will be read. |
numberOfBytes | Number of bytes which will be copied in the BLOB. |
offset | Write the buffer data in the BLOB starting at this offset. |
|
private |
BLOB handle.
|
private |
Database pointer.