class SqlSession : public SqlSource
SqlSesion represents single database session. SqlSession has ability to start (Begin) and finish (Commit or Rollback) transactions; when no transaction is started, each SQL statement is treated as single transaction. SqlSession is used as constructor parameter for Sql context. As most application usually work with single default session, or alternatively read/write sessions, this is reflected by existence of default sessions represented by global pseodovariables SQL and SQLR.
SqlSesion serves as base class for database specific session classes, which provide their unique methods for connection and other tasks.
virtual void Begin()
Starts a transaction.
virtual void Commit()
Commits transaction.
virtual void Rollback()
Rollbacks transaction.
virtual int GetTransactionLevel() const
Returns 0 if there is no transaction or 1 if transaciton is active. (Originally, U++ allowed nested transaction, this is now deprecated).
virtual bool IsOpen() const
Returns true if session is connected and ready to recieve statements.
virtual Vector<String> EnumUsers()
Enumerates users of database. Exact function depends on database.
virtual Vector<String> EnumDatabases()
Enumaretes all databases. Exact function depends on database.
virtual Vector<String> EnumTables(String database)
Enumerates all tables of database. Exact function depends on database.
virtual Vector<String> EnumViews(String database)
Enumerates all views of database. Exact function depends on database.
virtual Vector<String> EnumSequences(String database)
Enumerates all sequences of database. Exact function depends on database.
virtual Vector<SqlColumnInfo> EnumColumns(String database, String table)
Enumerates all columns of database table. Exact function depends on database.
virtual Vector<String> EnumPrimaryKey(String database, String table)
Enumerates all primary keys of database table. Exact function depends on database.
int GetDialect() const
Returns SQL dialect of session (ORACLE, SQLITE3, MY_SQL, MSSQL, PGSQL).
void SetTrace(Stream& s = VppLog())
Activates tracing of SQL statements issued on this session and SQL errors to the stream s.
Stream *GetTrace() const
Returns current trace stream or NULL if not active.
void KillTrace()
Deactivates tracing.
void LogErrors(Stream& s = VppLog())
Activates tracing SQL errors only to the stream s.
void LogErrors(bool b)
If b is true, same as LogErrors(), if false, deactivates tracing of SQL errors.
void TraceTime(bool b = true)
Adds execution times to commands traced.
bool IsTraceTime() const
Returns TraceTime mode status.
SqlSession& TraceSlow(int ms = 5000)
Activates tracing SQL statements longer than ms as errors.
SqlSession& ThrowOnError(bool b = true)
If this mode is active, SqlExc is throwed each time when SQL error happens.
bool IsThrowOnError() const
Returns true if ThrowOnError is active.
bool WasError() const
Returns true if there was error since the start of session or since ClearError.
void SetError(String error, String stmt, int code = 0, const char * scode = NULL, Sql::ERRORCLASS clss = Sql::ERROR_UNSPECIFIED)
Externally sets session to error state.
String GetLastError() const
Returns the description of last error.
String GetErrorStatement() const
Returns the statement that caused the last error.
int GetErrorCode() const
Returns the error-code of last error.
String GetErrorCodeString() const
Returns the error-code text.
Sql::ERRORCLASS GetErrorClass() const
Returns the class of error. Can be ERROR_UNSPECIFIED or CONNECTION_BROKEN.
void ClearError()
Clears the last error. This should be called as part of error handling.
void InstallErrorHandler(bool (*handler)(String error, String stmt, int code, const char *scode, Sql::ERRORCLASS clss))
Installs alternate error handler which is invoked on error.
operator bool() const
Same as IsOpen().
static void PerThread(bool b = true)
In multithreded mode, activates mode where each thread has assigned unique per-thread default session (otherwise default session is shared).
|