Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
UppHub
Status & Roadmap
FAQ
Authors & License
Forums
Funding U++
Search on this site











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

Sql

 

class Sql

This class  represents a SQL execution context. It is associated with SqlSession; several Sql contexts can be associated with single session. As there is usually single default SqlSession per process (or per thread), when session is not specified with constructor, this default session is used.

 

 

Public Method List

 

String Compile(const SqlStatement& s)

Compiles SqlExp based statement s for SQL dialect associated with the session of this Sql.

 


 

void Clear()

Clears the current SQL statement.

 


 

void SetParam(int i, const Value& val)

Sets the positional parameter i to val. Positional parameters are expressed as '?' in the statement.

 


 

void SetStatement(const String& s)

Assigns SQL statement s.

 


 

void SetStatement(const SqlStatement& s)

Assingle SqlExp statement.

 


 

bool Execute()

Executes Sql statement assigned by SetStatement. Note that with some databases, prepared statements are used and if statement has not changed, Execute runs previously prepared statement.

 


 

bool Run()

Same as Execute().

 


 

bool Execute(const String& s)

Same as SetStatement(s); return Execute().

 


 

bool Execute(const SqlStatement& s)

Same as SetStatement(s); return Execute().

 


 

bool Run(const Value& v1 [, const Value& v2 ...])

Runs current statment with set of positional parameters. This is especially useful for (re)executing prepared statements.

 


 

bool Execute(const String& s, const Value& v1 [, const Value& v2 ...])

Assigns a new statement and executes it with a set of position parameters.

 


 

bool Fetch()

Attempts to fetch a new row from database (assumes that the previous statement executes was select or some other statement with result set). If the row was fetched, returns true.

 


 

bool Fetch(Ref v1 [, Ref v2 ...])

Performs Fetch and then assigns fetched values into referenced variables.

 


 

bool Fetch(Vector<Value>& row)

Performs Fetch and assigns fetched values into row.

 


 

bool Fetch(ValueMap& row)

Performs Fetch and assigns fetched values into row.

 


 

bool Fetch(Fields fields)

Performs Fetch and assigns fetched values into fields. Fields usually represent some S_* table row structure based on .sch file.

 


 

int GetRowsProcessed() const

After update statement, this returns a number of rows that have been affected. Note that for some databases, this is the number of rows that really changed, for others, this is the number of rows that match where.

After insert statement, this returns a number of rows deleted.

 


 

int GetColumns() const

int GetColumnCount() const

Returns the number of columns of resultset after executing select statement.

 


 

void GetColumn(int i, Ref rconst

Sets value referenced by r to the fetched value at column i. Only valid after successfull Fetch and if there exists column i in the resultset.

 


 

void GetColumn(SqlId colid, Ref rconst

Sets value referenced by r to the fetched value at column with name colid (match is case insensitive). Only valid after successfull Fetch and if there exists column colid in the resultset.

 


 

Value operator[](int iconst

Returns the fetched value at column i. Only valid after successfull Fetch and if there exists column i in the resultset.

 


 

Value operator[](SqlId colidconst

Returns the fetched value at column with name colid (match is case insensitive). Only valid after successfull Fetch and if there exists column colid in the resultset.

 


 

const SqlColumnInfo& GetColumnInfo(int iconst

Returns the information about column i after executing select statement.

 


 

Vector<ValueGetRow() const

Returns the whole fetched row. Only valid after successfull Fetch.

 


 

ValueMap GetRowMap() const

ValueMap operator~() const

Returns the whole fetched row, keys of ValueMap are names of columns. Only valid after successfull Fetch.

 


 

operator Vector<Value>() const

Returns GetRow(). Only valid after successfull Fetch.

 


 

void Get(Fields fields)

Retrieves fetched row as fields. Fields usually represent some S_* table row structure based on .sch file. Only valid after successfull Fetch.

 


 

void Cancel()

Cancels the current statement. This in practice means that the rest of resultset is released.

 


 

bool Insert(Fields nf)

Executes insert statement that inserts Fields nf into database. Fields usually represent some S_* table row structure based on .sch file.

 


 

bool Insert(Fields nf, const char *table)

bool Insert(Fields nf, SqlId table)

Executes insert statement that inserts Fields nf columns into database, but uses different table as target. Fields usually represent some S_* table row structure based on .sch file.

 


 

bool InsertNoKey(Fields nf)

Executes insert statement that inserts Fields nf into database, first column of nf is not used (this column usually contains key). Fields usually represent some S_* table row structure based on .sch file.

 


 

bool InsertNoKey(Fields nf, const char *table)

bool InsertNoKey(Fields nf, SqlId table)

Executes insert statement that inserts Fields nf columns into database, but uses different table as target. First column of nf is not used (this column usually contains primary key). Fields usually represent some S_* table row structure based on .sch file.

 


 

bool InsertNoNulls(Fields nf)

Executes insert statement that inserts Fields nf into database, columns that are null are not used. Fields usually represent some S_* table row structure based on .sch file.

 


 

bool InsertNoNulls(Fields nf, const char *table)

bool InsertNoNulls(Fields nf, SqlId table)

Executes insert statement that inserts Fields nf columns into database, but uses different table as target. Columns that are null are not used. Fields usually represent some S_* table row structure based on .sch file.

 


 

bool Update(Fields nf)

Executes update statement that updates a table row in the database. First column of nf is used as primary key (for where part of statement). Fields usually represent some S_* table row structure based on .sch file.

 


 

bool Update(Fields nf, const char *table)

bool Update(Fields nf, SqlId table)

Executes update statement that updates a table row in the database, but uses different table as target. First column of nf is used as primary key (for where part of statement). Fields usually represent some S_* table row structure based on .sch file.

 


 

bool Delete(const char *table, const char *key, const Value& keyval)

bool Delete(SqlId table, SqlId key, const Value& keyval)

Removes a table row from the databases. This is sort of deprecated in favor of SqlExp Delete.

 


 

String ToString() const

Returns the current SQL statement.

 


 

bool operator*(const SqlStatement& q)

Same as Execute(Compile(q)).

 


 

Value operator%(const SqlStatement& q)

Executes a query, fetches a single row and returns the value of first column. If there is no row in resultset, returns Null. In case of error, returns ErrorValue (which is also interpreted as Null).

 


 

ValueMap operator^(const SqlStatement& q)

Executes a query, fetches a single row and returns this row as ValueMap where keys are names of columns. If there is no row in resultset or in case of error returns empty ValueMap.

 


 

ValueArray operator/(const SqlStatement& q)

Executes a query and returns the resultset as ValueArray of ValueMaps (keys are column names). If there is no row in resultset or in case of error returns empty ValueArray.

 


 

SqlSession& GetSession() const

Returns the associated SqlSession.

 


 

int GetDialect() const

Returns the SQL dialect of associated SqlSession.

 


 

Value GetInsertedId() const

For databases with auto-increment options of primary keys, returns the last value of primary key inserted. (Note that for PGSQL, it is required that the auto-increment primary key is named "ID").


 

bool IsOpen()

Returns true there is associated SqlSession this this instance and the SqlSession is connected to database.

 


 

Sql(SqlSource& src)

Creates Sql instance associated with session src. (SqlSession is derived from SqlSource, which serves some special internal purposes).

 


 

Sql()

Creates Sql instance associated with default session.

 


 

Sql(const char *stmt)

Creates Sql instance associated with default session and assigns it a statement.

 


 

Sql(const SqlStatement& s)

Creates Sql instance associated with default session and assigns it a SqlExp statement.

 


 

Sql(const char *stmt, SqlSource& session)

Creates Sql instance associated with session and assigns it a statement.

 


 

Sql(const SqlStatement& s, SqlSource& session)

Creates Sql instance associated with session and assigns it a SqlExp statement.

 


 

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).

 

 

Do you want to contribute?