NCBI C++ ToolKit
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
CSQLITE_Blob Class Reference

Search Toolkit Book for CSQLITE_Blob

Object reading and writing blob directly (mostly without executing select or update statements), can read and write blob incrementally. More...

#include <db/sqlite/sqlitewrapp.hpp>

+ Collaboration diagram for CSQLITE_Blob:

Public Member Functions

 CSQLITE_Blob (CSQLITE_Connection *conn, CTempString table, CTempString column, Int8 rowid)
 Create object reading and writing blob Identified row with blob should exist in database, exception is thrown otherwise. More...
 
 CSQLITE_Blob (CSQLITE_Connection *conn, CTempString db_name, CTempString table, CTempString column, Int8 rowid)
 Create object reading and writing blob Identified row with blob should exist in database, exception is thrown otherwise. More...
 
 ~CSQLITE_Blob (void)
 
void ResetPosition (size_t position=0)
 Set current position inside the blob to desired value. More...
 
size_t GetPosition (void)
 Get current position inside the blob. More...
 
size_t GetSize (void)
 Get size of the blob. More...
 
size_t Read (void *buffer, size_t size)
 Read from blob at current position. More...
 
void Write (const void *data, size_t size)
 Write to blob at current position. More...
 
void SetAppendStatement (CSQLITE_Statement *stmt)
 Set statement to use when appending to existing blob if necessary. More...
 

Private Member Functions

 CSQLITE_Blob (const CSQLITE_Blob &)
 
CSQLITE_Bloboperator= (const CSQLITE_Blob &)
 
void x_Init (void)
 Initialize the object. More...
 
void x_OpenBlob (bool readwrite=false)
 Open low-level blob object. More...
 
void x_CloseBlob (void)
 Close low-level blob object. More...
 

Private Attributes

CSQLITE_Connectionm_Conn
 Connection this blob object belongs to. More...
 
sqlite3 * m_ConnHandle
 Low-level connection handle provided for this blob object. More...
 
AutoPtr< CSQLITE_Statementm_AppendStmt
 Statement used for appending to existing blob value. More...
 
string m_Database
 Database name for blob. More...
 
string m_Table
 Table name for blob. More...
 
string m_Column
 Column name for blob. More...
 
Int8 m_Rowid
 Rowid for the row where blob is located. More...
 
sqlite3_blob * m_BlobHandle
 Low-level handle of the blob. More...
 
size_t m_Size
 Size of the blob. More...
 
size_t m_Position
 Current position inside the blob. More...
 

Friends

template<bool readwrite>
struct SSQLITE_BlobOpen
 
struct SSQLITE_BlobClose
 

Detailed Description

Object reading and writing blob directly (mostly without executing select or update statements), can read and write blob incrementally.

Class assumes that from the moment of its creation till deletion nobody else writes to the blob and/or changes its size.

Definition at line 549 of file sqlitewrapp.hpp.

Constructor & Destructor Documentation

◆ CSQLITE_Blob() [1/3]

CSQLITE_Blob::CSQLITE_Blob ( CSQLITE_Connection conn,
CTempString  table,
CTempString  column,
Int8  rowid 
)

Create object reading and writing blob Identified row with blob should exist in database, exception is thrown otherwise.

Parameters
connConnection which object will work over
tableTable name where blob is located
columnColumn name where blob is located
rowidRowid of the row where blob is located

Definition at line 895 of file sqlitewrapp.cpp.

References x_Init().

◆ CSQLITE_Blob() [2/3]

CSQLITE_Blob::CSQLITE_Blob ( CSQLITE_Connection conn,
CTempString  db_name,
CTempString  table,
CTempString  column,
Int8  rowid 
)

Create object reading and writing blob Identified row with blob should exist in database, exception is thrown otherwise.

Parameters
connConnection which object will work over
db_nameDatabase name where blob is located
tableTable name where blob is located
columnColumn name where blob is located
rowidRowid of the row where blob is located

Definition at line 908 of file sqlitewrapp.cpp.

References x_Init().

◆ ~CSQLITE_Blob()

CSQLITE_Blob::~CSQLITE_Blob ( void  )
inline

◆ CSQLITE_Blob() [3/3]

CSQLITE_Blob::CSQLITE_Blob ( const CSQLITE_Blob )
private

Member Function Documentation

◆ GetPosition()

size_t CSQLITE_Blob::GetPosition ( void  )
inline

Get current position inside the blob.

Definition at line 924 of file sqlitewrapp.hpp.

References m_Position.

◆ GetSize()

size_t CSQLITE_Blob::GetSize ( void  )

Get size of the blob.

Definition at line 958 of file sqlitewrapp.cpp.

References m_Size.

◆ operator=()

CSQLITE_Blob& CSQLITE_Blob::operator= ( const CSQLITE_Blob )
private

◆ Read()

size_t CSQLITE_Blob::Read ( void *  buffer,
size_t  size 
)

Read from blob at current position.

Parameters
bufferPointer to buffer where to write read data
sizeSize of buffer available for writing
Returns
Number of bytes read from blob. If current position is beyond end of the blob then 0 is returned and buffer is unchanged.

Definition at line 970 of file sqlitewrapp.cpp.

References _ASSERT, BLOB_SAFE_CALL, buffer, m_BlobHandle, m_Position, m_Size, and ncbi::grid::netcache::search::fields::size.

◆ ResetPosition()

void CSQLITE_Blob::ResetPosition ( size_t  position = 0)
inline

Set current position inside the blob to desired value.

Definition at line 930 of file sqlitewrapp.hpp.

References m_Position.

◆ SetAppendStatement()

void CSQLITE_Blob::SetAppendStatement ( CSQLITE_Statement stmt)
inline

Set statement to use when appending to existing blob if necessary.

Statement should be of the form "update ... set ... = ...||?2 where rowid=?1" If not set object creates its own statement on the first append. Created statement is destroyed together with this blob object. Statement set by this method is not destroyed with blob object. This method can be useful if one wants to cache statement between different blob objects creation and deletion to not prepare it with each blob object.

Definition at line 936 of file sqlitewrapp.hpp.

References eNoOwnership, m_AppendStmt, AutoPtr< X, Del >::reset(), and stmt.

◆ Write()

void CSQLITE_Blob::Write ( const void *  data,
size_t  size 
)

◆ x_CloseBlob()

void CSQLITE_Blob::x_CloseBlob ( void  )
private

Close low-level blob object.

Definition at line 946 of file sqlitewrapp.cpp.

References _ASSERT, BLOB_SAFE_CALL, m_BlobHandle, and NULL.

Referenced by SSQLITE_BlobClose::operator()(), and ~CSQLITE_Blob().

◆ x_Init()

void CSQLITE_Blob::x_Init ( void  )
inlineprivate

Initialize the object.

Definition at line 887 of file sqlitewrapp.cpp.

References m_BlobHandle, m_ConnHandle, m_Position, m_Size, and NULL.

Referenced by CSQLITE_Blob().

◆ x_OpenBlob()

void CSQLITE_Blob::x_OpenBlob ( bool  readwrite = false)
private

Open low-level blob object.

Parameters
readwriteTRUE if there's need for write access, FALSE if read-only access is sufficient

Definition at line 923 of file sqlitewrapp.cpp.

References _ASSERT, BLOB_SAFE_CALL, CSQLITE_Connection::LockHandle(), m_BlobHandle, m_Column, m_Conn, m_ConnHandle, m_Database, m_Rowid, m_Size, and m_Table.

Referenced by SSQLITE_BlobOpen< readwrite >::operator()().

Friends And Related Function Documentation

◆ SSQLITE_BlobClose

friend struct SSQLITE_BlobClose
friend

Definition at line 640 of file sqlitewrapp.hpp.

◆ SSQLITE_BlobOpen

template<bool readwrite>
friend struct SSQLITE_BlobOpen
friend

Definition at line 639 of file sqlitewrapp.hpp.

Member Data Documentation

◆ m_AppendStmt

AutoPtr<CSQLITE_Statement> CSQLITE_Blob::m_AppendStmt
private

Statement used for appending to existing blob value.

Definition at line 648 of file sqlitewrapp.hpp.

Referenced by SetAppendStatement(), and Write().

◆ m_BlobHandle

sqlite3_blob* CSQLITE_Blob::m_BlobHandle
private

Low-level handle of the blob.

Definition at line 658 of file sqlitewrapp.hpp.

Referenced by Read(), Write(), x_CloseBlob(), x_Init(), and x_OpenBlob().

◆ m_Column

string CSQLITE_Blob::m_Column
private

Column name for blob.

Definition at line 654 of file sqlitewrapp.hpp.

Referenced by Write(), and x_OpenBlob().

◆ m_Conn

CSQLITE_Connection* CSQLITE_Blob::m_Conn
private

Connection this blob object belongs to.

Definition at line 644 of file sqlitewrapp.hpp.

Referenced by x_OpenBlob(), and ~CSQLITE_Blob().

◆ m_ConnHandle

sqlite3* CSQLITE_Blob::m_ConnHandle
private

Low-level connection handle provided for this blob object.

Definition at line 646 of file sqlitewrapp.hpp.

Referenced by Write(), x_Init(), x_OpenBlob(), and ~CSQLITE_Blob().

◆ m_Database

string CSQLITE_Blob::m_Database
private

Database name for blob.

Definition at line 650 of file sqlitewrapp.hpp.

Referenced by Write(), and x_OpenBlob().

◆ m_Position

size_t CSQLITE_Blob::m_Position
private

Current position inside the blob.

Definition at line 662 of file sqlitewrapp.hpp.

Referenced by GetPosition(), Read(), ResetPosition(), Write(), and x_Init().

◆ m_Rowid

Int8 CSQLITE_Blob::m_Rowid
private

Rowid for the row where blob is located.

Definition at line 656 of file sqlitewrapp.hpp.

Referenced by Write(), and x_OpenBlob().

◆ m_Size

size_t CSQLITE_Blob::m_Size
private

Size of the blob.

Definition at line 660 of file sqlitewrapp.hpp.

Referenced by GetSize(), Read(), Write(), x_Init(), and x_OpenBlob().

◆ m_Table

string CSQLITE_Blob::m_Table
private

Table name for blob.

Definition at line 652 of file sqlitewrapp.hpp.

Referenced by Write(), and x_OpenBlob().


The documentation for this class was generated from the following files:
Modified on Sun May 19 04:42:19 2024 by modify_doxy.py rev. 669887