HFSQtLi 0.0.1
A Qt/C++ wrapper for SQLite3.
Public Member Functions | Protected Attributes | List of all members
HFSQtLi::Blob Class Reference

Provides direct read/write access to a blob. More...

#include <HFSQtLi.h>

Public Member Functions

 Blob (bool readWrite=false, bool autoOpen=true)
 Constructor. More...
 
 Blob (Blob &source)
 
bool close (QString *errorMsg=nullptr)
 Closes the blob if open. More...
 
bool open (QString *errorMsg=nullptr)
 Opens the blob if closed. More...
 
bool open (qint64 rowid, QString *errorMsg=nullptr)
 Open the blob to a particular row id. More...
 
bool reopenFast (qint64 newId, QString *errorMsg=nullptr)
 Reopens the blob with a new id. More...
 
bool isOpen ()
 Checks if the blob is currently open. More...
 
bool isReadWrite ()
 Returns the read/write mode. More...
 
bool autoOpen ()
 Returns the autoOpen mode. More...
 
qint64 size ()
 Get the size of the blob. More...
 
bool read (void *data, qsizetype size, qsizetype offset=0)
 Reads data from the blob. More...
 
QByteArray read (qsizetype size, qsizetype offset=0)
 Read data from the blob an returns a QByteArray with read data. More...
 
QByteArray readAll ()
 Reads all the data in the blob. More...
 
bool write (const void *data, qsizetype size, qsizetype offset)
 Writes data to the blob. More...
 
bool write (const QByteArray &data, qsizetype offset=0)
 Writes data to the blob. More...
 
QString database ()
 Returns current database name. More...
 
QString table ()
 Returns current table name. More...
 
QString column ()
 Returns current column name. More...
 
qint64 rowId ()
 Returns current row id. More...
 
Functions to set parameters

The functions here are used to set all parameters needed for succesfully opening a blob.

Warning
Calling any function in this group with values differents from the ones already set closes the Blob if autoOpen is not true or reopens it if it is false
bool set (Db *db, const char *database, const char *table, const char *column, qint64 rowid)
 Sets several parameters at once. More...
 
bool set (Db *db, const char *database, const char *table, const char *column)
 Sets several parameters at once. More...
 
bool set (Db *db, const char *database, const char *table, qint64 rowid)
 Sets several parameters at once. More...
 
bool setDatabase (const char *database)
 Sets the database name. If not set it will "main". More...
 
bool setTable (const char *table)
 Sets the table name. More...
 
bool setColumn (const char *column)
 Sets the column name. More...
 
bool setRowId (qint64 rowId)
 Sets the row id. More...
 
bool setReadWrite (bool readWrite)
 Sets the read/write mode. More...
 
bool setDbPointer (Db *db)
 Sets the connection this blob refers to. More...
 
void setAutoOpen (bool newAutoOpen)
 Sets the autoOpen mode. More...
 

Protected Attributes

QExplicitlySharedDataPointer< Helper::BlobData > m_data
 

Detailed Description

Provides direct read/write access to a blob.

Blob has two options that influence its behaviour:

There are three ways of setting blob parameters:

Typical usage case will be like setting everything by hand:

Blob b; // Note that auto-open is enabled by default
b.set(m_db, nullptr, "TestTable", "blobColumn", 4); // "main" database selected by default
Blob(bool readWrite=false, bool autoOpen=true)
Constructor.
Definition: HFSQtLi.h:1542

or set all the parameters except the rowid by hand and then using a "SELECT" to retive it

Blob b; // Note that auto-open is enabled by default
b.set(m_db, nullptr, "TestTable", "blobColumn"); // "main" database selected by default
m_db->executeSingle("SELECT rowid FROM TestTable WHERE name="Foo", b)

or set all the parameters via a select:

Blob b; // Note that auto-open is enabled by default
m_db->executeSingle("SELECT blobColumn, rowid FROM TestTable WHERE name="Foo", b, b);

Constructor & Destructor Documentation

◆ Blob()

HFSQtLi::Blob::Blob ( bool  readWrite = false,
bool  autoOpen = true 
)
inline

Constructor.

Parameters
readWriteRead/write mode. See isReadWrite()
autoOpen.See autoOpen()

Member Function Documentation

◆ autoOpen()

bool HFSQtLi::Blob::autoOpen ( )
inline

Returns the autoOpen mode.

If true the blob will try to automatically open the blob when all of db pointer, tableName, columnName and rowid are set.

Returns
autoOpen status

◆ close()

bool HFSQtLi::Blob::close ( QString *  errorMsg = nullptr)
inline

Closes the blob if open.

Parameters
errorMsgOptional pointer to a string that will receive the error message
Returns
true on success or if the blob was already closed

◆ column()

QString HFSQtLi::Blob::column ( )
inline

Returns current column name.

Returns
String with column name or empty string if unset

◆ database()

QString HFSQtLi::Blob::database ( )
inline

Returns current database name.

Returns
String with database name

◆ isOpen()

bool HFSQtLi::Blob::isOpen ( )
inline

Checks if the blob is currently open.

Returns
True if the blob is open, false otherwise

◆ isReadWrite()

bool HFSQtLi::Blob::isReadWrite ( )
inline

Returns the read/write mode.

If false the blob is in read-only mode and any write call will fail.

Returns
Read/write status

◆ open() [1/2]

bool HFSQtLi::Blob::open ( qint64  rowid,
QString *  errorMsg = nullptr 
)
inline

Open the blob to a particular row id.

If the blob is closed tries to open it with the given id, if it is already open tries to reopen it with the new id.

Parameters
errorMsgOptional pointer to a string that will receive the error message
Returns
true on success, false on failure

◆ open() [2/2]

bool HFSQtLi::Blob::open ( QString *  errorMsg = nullptr)
inline

Opens the blob if closed.

Parameters
errorMsgOptional pointer to a string that will receive the error message
Returns
true on success or if the blob was already opened

◆ read() [1/2]

QByteArray HFSQtLi::Blob::read ( qsizetype  size,
qsizetype  offset = 0 
)
inline

Read data from the blob an returns a QByteArray with read data.

Parameters
sizeSize of the buffer to read
offsetOffset in blob to read
Returns
QByteArray filled with read data, or an empty one on error

◆ read() [2/2]

bool HFSQtLi::Blob::read ( void *  data,
qsizetype  size,
qsizetype  offset = 0 
)
inline

Reads data from the blob.

Parameters
dataPointer to the buffer to read
sizeSize of the buffer to read
offsetOffset in blob to read
Returns
True on success, false on error

◆ readAll()

QByteArray HFSQtLi::Blob::readAll ( )
inline

Reads all the data in the blob.

This call is equivalent to read(size(), 0);

Returns
QByteArray fill with the data from blob or an empty one on error

◆ reopenFast()

bool HFSQtLi::Blob::reopenFast ( qint64  newId,
QString *  errorMsg = nullptr 
)
inline

Reopens the blob with a new id.

This function must be called on an open blob or it will return an error

Parameters
errorMsgOptional pointer to a string that will receive the error message
Returns
true on success

◆ rowId()

qint64 HFSQtLi::Blob::rowId ( )
inline

Returns current row id.

Returns
Current row id. Result is undefined if no row-id was set.

◆ set() [1/3]

bool Blob::set ( Db *  db,
const char *  database,
const char *  table,
const char *  column 
)

Sets several parameters at once.

Parameters
dbDatabase pointer
databaseName of the database
tableName of table
columnName of column
Returns
True on success, false on error

◆ set() [2/3]

bool Blob::set ( Db *  db,
const char *  database,
const char *  table,
const char *  column,
qint64  rowid 
)

Sets several parameters at once.

Parameters
dbDatabase pointer
databaseName of the database
tableName of table
columnName of column
rowidRow id
Returns
True on success, false on error

◆ set() [3/3]

bool Blob::set ( Db *  db,
const char *  database,
const char *  table,
qint64  rowid 
)

Sets several parameters at once.

Parameters
dbDatabase pointer
databaseName of the database
tableName of table
rowidRow id
Returns
True on success, false on error

◆ setAutoOpen()

void HFSQtLi::Blob::setAutoOpen ( bool  newAutoOpen)
inline

Sets the autoOpen mode.

Note that setting autoOpen to true will not try to open the blob until the next call to setXXX.

Parameters
newAutoOpenNew value.

◆ setColumn()

bool HFSQtLi::Blob::setColumn ( const char *  column)
inline

Sets the column name.

Parameters
tableString pointing to column name or NULL to unset.
Returns
True on success, false on error

◆ setDatabase()

bool HFSQtLi::Blob::setDatabase ( const char *  database)
inline

Sets the database name. If not set it will "main".

Parameters
databaseString pointing to database name or NULL to unset.
Returns
True on success, false on error

◆ setDbPointer()

bool HFSQtLi::Blob::setDbPointer ( Db *  db)
inline

Sets the connection this blob refers to.

Parameters
dbPointer to an open connection
Returns
True on success

◆ setReadWrite()

bool HFSQtLi::Blob::setReadWrite ( bool  readWrite)
inline

Sets the read/write mode.

Parameters
readWriteNew value.
Returns
True on success, false on error

◆ setRowId()

bool HFSQtLi::Blob::setRowId ( qint64  rowId)
inline

Sets the row id.

Parameters
rowidInteger of the row id.
Returns
True on success, false on error

◆ setTable()

bool HFSQtLi::Blob::setTable ( const char *  table)
inline

Sets the table name.

Parameters
tableString pointing to table name or NULL to unset.
Returns
True on success, false on error

◆ size()

qint64 HFSQtLi::Blob::size ( )
inline

Get the size of the blob.

Returns
Size of the blob on success, -1 on error or if the blob is closed

◆ table()

QString HFSQtLi::Blob::table ( )
inline

Returns current table name.

Returns
String with table name or empty string if unset

◆ write() [1/2]

bool HFSQtLi::Blob::write ( const QByteArray &  data,
qsizetype  offset = 0 
)
inline

Writes data to the blob.

Parameters
dataData to write
offsetOffset in the blob to write
Returns
True on success, false on error

◆ write() [2/2]

bool HFSQtLi::Blob::write ( const void *  data,
qsizetype  size,
qsizetype  offset 
)
inline

Writes data to the blob.

Parameters
dataPointer to the buffer to write
sizeSize of the buffer to write
offsetOffset in the blob to write
Returns
True on success, false on error

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