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_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
 

Protected Attributes

UT_UniquePtr< UT_SqlBaseDrivermyDriver
 

Detailed Description

Definition at line 1117 of file UT_SQL.h.

Member Typedef Documentation

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

Definition at line 1120 of file UT_SQL.h.

Constructor & Destructor Documentation

UT_SqlDatabase::UT_SqlDatabase ( driver_factory_t  factory = UTsqliteFactory)
inline

Definition at line 1122 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 1189 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 1161 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 1240 of file UT_SQL.h.

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

Create a db connection with a custom db backend.

Definition at line 1163 of file UT_SQL.h.

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

Definition at line 1178 of file UT_SQL.h.

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

Definition at line 1182 of file UT_SQL.h.

UT_SqlBaseDriver* UT_SqlDatabase::driver ( )
inline

Definition at line 1126 of file UT_SQL.h.

const UT_SqlBaseDriver* UT_SqlDatabase::driver ( ) const
inline

Definition at line 1130 of file UT_SQL.h.

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

Definition at line 1268 of file UT_SQL.h.

NO_DISCARD int UT_SqlDatabase::errorCode ( ) const
inline

Definition at line 1251 of file UT_SQL.h.

NO_DISCARD UT_StringHolder UT_SqlDatabase::errorMessage ( ) const
inline

Definition at line 1247 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 1219 of file UT_SQL.h.

NO_DISCARD int UT_SqlDatabase::extendedErrorCode ( ) const
inline

Definition at line 1255 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 1201 of file UT_SQL.h.

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

Definition at line 1273 of file UT_SQL.h.

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

Definition at line 1230 of file UT_SQL.h.

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

Definition at line 1172 of file UT_SQL.h.

NO_DISCARD bool UT_SqlDatabase::isValid ( ) const
inline

Check the underlying connection is valid and usable.

Definition at line 1168 of file UT_SQL.h.

NO_DISCARD void* UT_SqlDatabase::nativeAPI ( )
inline

Definition at line 1278 of file UT_SQL.h.

NO_DISCARD void* UT_SqlDatabase::nativeAPI ( ) const
inline

Definition at line 1279 of file UT_SQL.h.

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 1208 of file UT_SQL.h.

void UT_SqlDatabase::setConnectOptions ( const UT_Options options)
inline

Definition at line 1155 of file UT_SQL.h.

void UT_SqlDatabase::setDatabaseName ( const UT_StringRef db_name)
inline

Definition at line 1151 of file UT_SQL.h.

void UT_SqlDatabase::setHostName ( const UT_StringRef host)
inline

Definition at line 1135 of file UT_SQL.h.

void UT_SqlDatabase::setPassword ( const UT_StringRef password)
inline

Definition at line 1147 of file UT_SQL.h.

void UT_SqlDatabase::setPort ( int  port)
inline

Definition at line 1139 of file UT_SQL.h.

void UT_SqlDatabase::setUserName ( const UT_StringRef user)
inline

Definition at line 1143 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 1264 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 1225 of file UT_SQL.h.

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

Definition at line 1235 of file UT_SQL.h.

Member Data Documentation

UT_UniquePtr<UT_SqlBaseDriver> UT_SqlDatabase::myDriver
protected

Definition at line 1282 of file UT_SQL.h.


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