Kompex SQLite Wrapper  1.11.14
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
Kompex::SQLiteBlob Class Reference

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...
 
SQLiteDatabasemDatabase
 Database pointer. More...
 

Detailed Description

Administration of existing BLOBs.

Constructor & Destructor Documentation

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;

Parameters
dbDatabase in which we will work.
symbolicDatabaseNameName 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".
tableNameName of the table in which the BLOB is located.
columnNameName of the column in which the BLOB is located.
rowIdID of the dataset in which the BLOB is located.
accessModeBLOB_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.
Kompex::SQLiteBlob::~SQLiteBlob ( )
virtual

Destructor.
Calls also CloseBlob() so that you don't need to close the BLOB explicitly.

Member Function Documentation

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.

sqlite3_blob* Kompex::SQLiteBlob::GetBlobHandle ( ) const
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;

Parameters
dbDatabase in which we will work.
symbolicDatabaseNameName 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".
tableNameName of the table in which the BLOB is located.
columnNameName of the column in which the BLOB is located.
rowIdID of the dataset in which the BLOB is located.
accessModeBLOB_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.

Parameters
bufferBuffer in which the BLOB data will be read.
numberOfBytesNumber of bytes which will be copied in the buffer.
offsetRead 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.

Parameters
bufferBuffer in which the BLOB data will be read.
numberOfBytesNumber of bytes which will be copied in the BLOB.
offsetWrite the buffer data in the BLOB starting at this offset.

Member Data Documentation

sqlite3_blob* Kompex::SQLiteBlob::mBlobHandle
private

BLOB handle.

SQLiteDatabase* Kompex::SQLiteBlob::mDatabase
private

Database pointer.


The documentation for this class was generated from the following files: