HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_SqlDatabase Class Reference

#include <UT_SQL.h>

Public Types

using driver_factory_t ) = UT_UniquePtr< UT_SqlBaseDriver >(*)(
 

Public Member Functions

 UT_SqlDatabase (driver_factory_t factory=UTsqliteFactory)
 
UT_SqlBaseDriverdriver ()
 
const UT_SqlBaseDriverdriver () const
 
void setHostName (const UT_StringRef &host)
 
void setPort (int port)
 
void setUserName (const UT_StringRef &user)
 
void setPassword (const UT_StringRef &password)
 
void setDatabaseName (const UT_StringRef &db_name)
 
void setConnectOptions (const UT_Options &options)
 
bool close (UT_ErrorCode *ec=nullptr)
 Close the sql connection to the db backend. More...
 
bool connect (UT_ErrorCode *ec=nullptr)
 Create a db connection with a custom db backend. More...
 
NO_DISCARD bool isValid () const
 Check the underlying connection is valid and usable. More...
 
NO_DISCARD bool isReadOnly (const char *db="main", UT_ErrorCode *ec=nullptr) const
 
NO_DISCARD UT_SharedPtr
< UT_SqlStatementImpl
createStatementImpl ()
 
NO_DISCARD UT_SharedPtr
< UT_SqlStatementImpl
createStatementImpl () const
 
UT_SharedPtr< UT_SqlStatementImplcachedStatement (const UT_SqlStatementHandleId &id, const UT_StringRef &sql, UT_ErrorCode *ec=nullptr) const
 
UT_SharedPtr< UT_SqlStatementImplcachedStatement (const UT_SqlStatementHandleId &id, UT_Function< UT_StringHolder()> &&creator, UT_ErrorCode *ec=nullptr) const
 
UT_SharedPtr< UT_SqlStatementImplfindCachedStatement (const UT_SqlStatementHandleId &id) const
 
template<typename... Args>
bool run (UT_ErrorCode *ec, const UT_StringRef &sql, Args &&...args)
 Helper function to run an sql statement with provided typed args. More...
 
int exec (const UT_StringRef &sql, UT_ErrorCode *ec=nullptr) const
 Returns the number of rows modified, inserted or deleted. More...
 
NO_DISCARD bool tableExists (const UT_StringRef &name, UT_ErrorCode *ec=nullptr) const
 Check if the specified table exists. More...
 
NO_DISCARD bool indexExists (const UT_StringRef &name, UT_ErrorCode *ec=nullptr) const
 
NO_DISCARD bool viewExists (const UT_StringRef &name, UT_ErrorCode *ec=nullptr) const
 
NO_DISCARD bool columnExists (const UT_StringRef &table_name, const UT_StringRef &column_name, UT_ErrorCode *ec=nullptr) const
 
NO_DISCARD UT_StringHolder errorMessage () const
 
NO_DISCARD int errorCode () const
 
NO_DISCARD int extendedErrorCode () const
 
bool startTransaction (UT_ErrorCode *ec=nullptr)
 
bool endTransaction (bool commit, UT_ErrorCode *ec=nullptr)
 
NO_DISCARD UT_StringHolder getSchema (UT_ErrorCode *ec=nullptr) const
 
NO_DISCARD voidnativeAPI ()
 
NO_DISCARD voidnativeAPI () const
 
void rollbackSavePoint (const UT_StringHolder &sid, UT_ErrorCode &ec)
 
void commitSavePoint (const UT_StringHolder &sid, UT_ErrorCode &ec)
 
UT_StringHolder createSavePoint (UT_ErrorCode &ec)
 
void commit (UT_ErrorCode &ec)
 
void rollback (UT_ErrorCode &ec)
 
void setAutoCommit (bool autocommit, UT_ErrorCode *ec=nullptr)
 
bool getAutoCommit () const
 

Protected Attributes

UT_UniquePtr< UT_SqlBaseDrivermyDriver
 
bool myIsInAtomicBlock = false
 
bool myCommitOnExit = false
 
bool myNeedsRollback = false
 
UT_StringArray mySavePoints
 
int mySavePointCounter = 0
 
bool myAutocommit = true
 

Friends

class UT_AutoSqlTransaction
 

Detailed Description

Definition at line 1313 of file UT_SQL.h.

Member Typedef Documentation

using UT_SqlDatabase::driver_factory_t = UT_UniquePtr<UT_SqlBaseDriver>(*)(

Definition at line 1316 of file UT_SQL.h.

Constructor & Destructor Documentation

UT_SqlDatabase::UT_SqlDatabase ( driver_factory_t  factory = UTsqliteFactory)
inline

Definition at line 1318 of file UT_SQL.h.

Member Function Documentation

UT_SharedPtr<UT_SqlStatementImpl> UT_SqlDatabase::cachedStatement ( const UT_SqlStatementHandleId id,
const UT_StringRef sql,
UT_ErrorCode ec = nullptr 
) const
inline

Get a sql statement that is retrieved from the cache. If the statement is not already cached then its compiled and then cached if the compiled statement is valid.

Definition at line 1385 of file UT_SQL.h.

UT_SharedPtr<UT_SqlStatementImpl> UT_SqlDatabase::cachedStatement ( const UT_SqlStatementHandleId id,
UT_Function< UT_StringHolder()> &&  creator,
UT_ErrorCode ec = nullptr 
) const
inline

Definition at line 1393 of file UT_SQL.h.

bool UT_SqlDatabase::close ( UT_ErrorCode ec = nullptr)
inline

Close the sql connection to the db backend.

Definition at line 1357 of file UT_SQL.h.

NO_DISCARD bool UT_SqlDatabase::columnExists ( const UT_StringRef table_name,
const UT_StringRef column_name,
UT_ErrorCode ec = nullptr 
) const
inline

Definition at line 1444 of file UT_SQL.h.

void UT_SqlDatabase::commit ( UT_ErrorCode ec)
void UT_SqlDatabase::commitSavePoint ( const UT_StringHolder sid,
UT_ErrorCode ec 
)
bool UT_SqlDatabase::connect ( UT_ErrorCode ec = nullptr)
inline

Create a db connection with a custom db backend.

Definition at line 1359 of file UT_SQL.h.

UT_StringHolder UT_SqlDatabase::createSavePoint ( UT_ErrorCode ec)
NO_DISCARD UT_SharedPtr<UT_SqlStatementImpl> UT_SqlDatabase::createStatementImpl ( )
inline

Definition at line 1374 of file UT_SQL.h.

NO_DISCARD UT_SharedPtr<UT_SqlStatementImpl> UT_SqlDatabase::createStatementImpl ( ) const
inline

Definition at line 1378 of file UT_SQL.h.

UT_SqlBaseDriver* UT_SqlDatabase::driver ( )
inline

Definition at line 1322 of file UT_SQL.h.

const UT_SqlBaseDriver* UT_SqlDatabase::driver ( ) const
inline

Definition at line 1326 of file UT_SQL.h.

bool UT_SqlDatabase::endTransaction ( bool  commit,
UT_ErrorCode ec = nullptr 
)
inline

Definition at line 1472 of file UT_SQL.h.

NO_DISCARD int UT_SqlDatabase::errorCode ( ) const
inline

Definition at line 1455 of file UT_SQL.h.

NO_DISCARD UT_StringHolder UT_SqlDatabase::errorMessage ( ) const
inline

Definition at line 1451 of file UT_SQL.h.

int UT_SqlDatabase::exec ( const UT_StringRef sql,
UT_ErrorCode ec = nullptr 
) const
inline

Returns the number of rows modified, inserted or deleted.

Definition at line 1423 of file UT_SQL.h.

NO_DISCARD int UT_SqlDatabase::extendedErrorCode ( ) const
inline

Definition at line 1459 of file UT_SQL.h.

UT_SharedPtr<UT_SqlStatementImpl> UT_SqlDatabase::findCachedStatement ( const UT_SqlStatementHandleId id) const
inline

Find an sql handle based on its id. The sql statement must have already been added from cachedStatement(). This method is typically used when a statement has already been compiled and added to the cache but needs to be dynamically looked up some time later.

Definition at line 1405 of file UT_SQL.h.

bool UT_SqlDatabase::getAutoCommit ( ) const
inline

Definition at line 1491 of file UT_SQL.h.

NO_DISCARD UT_StringHolder UT_SqlDatabase::getSchema ( UT_ErrorCode ec = nullptr) const
inline

Definition at line 1477 of file UT_SQL.h.

NO_DISCARD bool UT_SqlDatabase::indexExists ( const UT_StringRef name,
UT_ErrorCode ec = nullptr 
) const
inline

Definition at line 1434 of file UT_SQL.h.

NO_DISCARD bool UT_SqlDatabase::isReadOnly ( const char *  db = "main",
UT_ErrorCode ec = nullptr 
) const
inline

Definition at line 1368 of file UT_SQL.h.

NO_DISCARD bool UT_SqlDatabase::isValid ( ) const
inline

Check the underlying connection is valid and usable.

Definition at line 1364 of file UT_SQL.h.

NO_DISCARD void* UT_SqlDatabase::nativeAPI ( )
inline

Definition at line 1482 of file UT_SQL.h.

NO_DISCARD void* UT_SqlDatabase::nativeAPI ( ) const
inline

Definition at line 1483 of file UT_SQL.h.

void UT_SqlDatabase::rollback ( UT_ErrorCode ec)
void UT_SqlDatabase::rollbackSavePoint ( const UT_StringHolder sid,
UT_ErrorCode ec 
)
template<typename... Args>
bool UT_SqlDatabase::run ( UT_ErrorCode ec,
const UT_StringRef sql,
Args &&...  args 
)
inline

Helper function to run an sql statement with provided typed args.

Definition at line 1412 of file UT_SQL.h.

void UT_SqlDatabase::setAutoCommit ( bool  autocommit,
UT_ErrorCode ec = nullptr 
)
void UT_SqlDatabase::setConnectOptions ( const UT_Options options)
inline

Definition at line 1351 of file UT_SQL.h.

void UT_SqlDatabase::setDatabaseName ( const UT_StringRef db_name)
inline

Definition at line 1347 of file UT_SQL.h.

void UT_SqlDatabase::setHostName ( const UT_StringRef host)
inline

Definition at line 1331 of file UT_SQL.h.

void UT_SqlDatabase::setPassword ( const UT_StringRef password)
inline

Definition at line 1343 of file UT_SQL.h.

void UT_SqlDatabase::setPort ( int  port)
inline

Definition at line 1335 of file UT_SQL.h.

void UT_SqlDatabase::setUserName ( const UT_StringRef user)
inline

Definition at line 1339 of file UT_SQL.h.

bool UT_SqlDatabase::startTransaction ( UT_ErrorCode ec = nullptr)
inline

These are primarily used by UT_SqlTransaction (but can be used by any client code) and provide an abstraction that resembles nested transations. This is inspired by (and follows the same behaviour as): https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#beginTransaction()

Definition at line 1468 of file UT_SQL.h.

NO_DISCARD bool UT_SqlDatabase::tableExists ( const UT_StringRef name,
UT_ErrorCode ec = nullptr 
) const
inline

Check if the specified table exists.

Definition at line 1429 of file UT_SQL.h.

NO_DISCARD bool UT_SqlDatabase::viewExists ( const UT_StringRef name,
UT_ErrorCode ec = nullptr 
) const
inline

Definition at line 1439 of file UT_SQL.h.

Friends And Related Function Documentation

Definition at line 1494 of file UT_SQL.h.

Member Data Documentation

bool UT_SqlDatabase::myAutocommit = true
protected

Definition at line 1503 of file UT_SQL.h.

bool UT_SqlDatabase::myCommitOnExit = false
protected

Definition at line 1499 of file UT_SQL.h.

UT_UniquePtr<UT_SqlBaseDriver> UT_SqlDatabase::myDriver
protected

Definition at line 1496 of file UT_SQL.h.

bool UT_SqlDatabase::myIsInAtomicBlock = false
protected

Definition at line 1498 of file UT_SQL.h.

bool UT_SqlDatabase::myNeedsRollback = false
protected

Definition at line 1500 of file UT_SQL.h.

int UT_SqlDatabase::mySavePointCounter = 0
protected

Definition at line 1502 of file UT_SQL.h.

UT_StringArray UT_SqlDatabase::mySavePoints
protected

Definition at line 1501 of file UT_SQL.h.


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