scclib-sqlite
Stable Cloud Computing Sqlite Library
Public Member Functions | List of all members
scc::sqld::Req Class Reference

Database request. More...

#include <sqld.h>

Public Member Functions

 Req (Conn &)
 
void clear ()
 Clear the request and the sql() stream. More...
 
void reset ()
 Reset the request without clearing the sql() stream. More...
 
int exec_select ()
 Executes in select mode. More...
 
int next_row ()
 Get the next row. More...
 
void exec ()
 Execute all statements, ignoring all row data.
 
std::string col_name (int)
 Return column name. More...
 
void col_name (int, std::string &)
 Return column name. More...
 
std::string col_text (int)
 Return UTF-8 TEXT. More...
 
void col_text (int, std::string &)
 Return UTF-8 TEXT. More...
 
int col_int (int)
 Return 32-bit INTEGER. More...
 
int64_t col_int64 (int)
 Return 64-bit INTEGER. More...
 
double col_real (int)
 Return 64-bit REAL. More...
 
void col_blob (int, std::vector< char > &)
 Return BLOB unstructured data. More...
 
std::ostringstream & sql ()
 Sql streamer. More...
 

Detailed Description

Database request.

Sqlite data types are more flexible than standard databases, in general the types are automatically detected.

Information on the recent STRICT table option is here.

UTF-16 values are not implemented.

Examples
unittest/sqld.cc.

Definition at line 128 of file sqld.h.

Member Function Documentation

◆ clear()

void Req::clear ( )

Clear the request and the sql() stream.

After this call, the sql() stream is set empty, and the request is initialized.

Definition at line 146 of file sqld.cc.

◆ col_blob()

void Req::col_blob ( int  col,
std::vector< char > &  str 
)

Return BLOB unstructured data.

Parameters
colzero-indexed column

Definition at line 405 of file sqld.cc.

◆ col_int()

int Req::col_int ( int  col)

Return 32-bit INTEGER.

Parameters
colzero-indexed column

Definition at line 351 of file sqld.cc.

◆ col_int64()

int64_t Req::col_int64 ( int  col)

Return 64-bit INTEGER.

Parameters
colzero-indexed column

Definition at line 369 of file sqld.cc.

◆ col_name() [1/2]

std::string Req::col_name ( int  col)

Return column name.

Parameters
colzero-indexed column

Definition at line 279 of file sqld.cc.

◆ col_name() [2/2]

void Req::col_name ( int  col,
std::string &  str 
)

Return column name.

Parameters
colzero-indexed column

Definition at line 297 of file sqld.cc.

◆ col_real()

double Req::col_real ( int  col)

Return 64-bit REAL.

Parameters
colzero-indexed column

Definition at line 387 of file sqld.cc.

◆ col_text() [1/2]

std::string Req::col_text ( int  col)

Return UTF-8 TEXT.

Parameters
colzero-indexed column

Definition at line 315 of file sqld.cc.

◆ col_text() [2/2]

void Req::col_text ( int  col,
std::string &  str 
)

Return UTF-8 TEXT.

Parameters
colzero-indexed column

Definition at line 333 of file sqld.cc.

◆ exec_select()

int Req::exec_select ( )

Executes in select mode.

Executes statements in sql() stream, until either row data is available, or there are no more statements to process.

If row data is returned, the caller must call next_row() until all rows are retrieved (or clear the request).

Returns
Number of columns in the current row, or 0 if no row data.

Definition at line 192 of file sqld.cc.

◆ next_row()

int Req::next_row ( )

Get the next row.

If there are multiple select-type statements in the sql() stream, exec_select() may need to be called again after next_row() returns 0.

Returns
Number of columns in the current row, or 0 if no row data.

Definition at line 252 of file sqld.cc.

◆ reset()

void Req::reset ( )

Reset the request without clearing the sql() stream.

After this call, the sql() stream is unchanged, and the request is initialized to start of stream. The sql stream can then be executed again.

Definition at line 155 of file sqld.cc.

◆ sql()

std::ostringstream& scc::sqld::Req::sql ( )
inline

Sql streamer.

Adds to the request, for example:

req.sql()
  << "create table t(one int, two int);"
  << "insert into t values(1, 2);"
  << "select * from t;";

Definition at line 230 of file sqld.h.


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