#include <sqldb.h>
Collaboration diagram for Dv::Sql::Command:
Public Member Functions | |
Command (Db &db, const char *text=0) | |
Constructor, text is initial text of command. | |
~Command () | |
Destructor also destroys any result data. | |
bool | ok () const |
Status of command. | |
operator bool () const | |
Same as Dv::Sql::Command::ok(). | |
std::string | err () const |
Error message. | |
bool | ran () const |
Return true iff the command has already been executed. | |
Db & | db () |
Return database connection with which this command is associated. | |
std::string | text () |
Return text of command. | |
const std::vector< Field > & | fields () |
Return field information for query result. | |
unsigned int | nrows () |
Return number of rows in query result. | |
unsigned int | ncols () |
Return number of columns in query result. | |
iterator | begin () |
Return logical pointer to first row of the result. | |
iterator | end () |
Return logical pointer to past the end of the query result. | |
bool | valid (int r) const |
Check whether a rowno r is valid, i.e. the r'th row is available. | |
Command & | operator<< (const std::string &) throw (Exception) |
Append a string to the command text; the string will be escaped and quoted. | |
Command & | operator<< (const char *) throw (Exception) |
Append a string to the command text. | |
Command & | operator<< (int) throw (Exception) |
Append an int to the command text. | |
Command & | operator<< (unsigned int) throw (Exception) |
Append an unsigned int to the command text. | |
Command & | operator<< (short) throw (Exception) |
Append a short to the command text. | |
Command & | operator<< (unsigned short) throw (Exception) |
Append an unsigned short to the command text. | |
Command & | operator<< (long) throw (Exception) |
Append a long to the command text. | |
Command & | operator<< (unsigned long) throw (Exception) |
Append an unsigned long to the command text. | |
Command & | operator<< (float) throw (Exception) |
Append a float to the command text. | |
Command & | operator<< (double) throw (Exception) |
Append a double to the command text. | |
bool | exec () |
Execute the query, status is determined by underlying DBMS. | |
unsigned int | insertid () const |
Return auto_increment id of last insert. | |
Private Member Functions | |
void | fetch (std::vector< std::string > &v, unsigned int r) throw (Exception) |
Retrieve the r'th row of the result ( 0<= r < nrows_ ). | |
void | fetch (std::string &s, unsigned int r, unsigned int c) throw (Exception) |
Retrieve the r'th row and c'th column of the result ( 0<= r < //nrows_ ). | |
Command (const Command &) | |
Cctor is forbidden. | |
Command & | operator= (const Command &) |
Assignment is forbidden. | |
void | nrows (unsigned int n) |
void | ncols (unsigned int n) |
void | run () |
void | err (const char *s) |
void | ok (bool b) |
Private Attributes | |
bool | ran_ |
std::string | err_ |
bool | ok_ |
std::ostringstream | text_ |
bool | frozen_ |
unsigned long | nrows_ |
Nrows_ is # of rows in query answer, only valid if ran() && ok(). | |
unsigned long | ncols_ |
Ncols_ is # of columns in query answer, only valid if ran() && ok(). | |
Command_ * | cmd_ |
Associated dbms-dependent object. | |
Friends | |
class | Db |
Friend. | |
class | iterator |
Friend. | |
class | Command_ |
Friend. |
Command is a dbms-independent proxy class for the dbms-dependent Command_. A Command object has a pointer to a companion Command_ object, which has been created using Dv::Sql::Db::command_().
This is an alternative for inheritance: instead of subclassing Command, the ``subclass part'' is available in *cmd_.
This has the advantage that only the definition of the database object ``db'' derived from Dv::Sql::Db depends on the actual DBMS used. All other database manipulatsions can be done through normal Dv::Sql::Command objects, which are initialized using a referrence to a Dv::Sql::Db. Consequently, applications are more independent of the actual underlying DBMS.
Example:
MySql::Db db(...); std::string name; Sql::Command query("select * from person where name = "); query << name; if (q.exec()) for (Sql::Command::iterator i=q.begin(); i!=q.end(); ++i) cout << i(0) << "\t" << i(1) << endl;
Definition at line 254 of file sqldb.h.
|
Constructor, text is initial text of command. Example Sql::Command q("insert into person values ("); // rest of command is inserted using operator<< |
|
Destructor also destroys any result data.
|
|
Cctor is forbidden.
|
|
Status of command.
Definition at line 279 of file sqldb.h. References ok_. |
|
Same as Dv::Sql::Command::ok().
Definition at line 281 of file sqldb.h. References ok_. |
|
Error message.
Definition at line 283 of file sqldb.h. References err_. |
|
Return true iff the command has already been executed. Calling Dv::Sql::Command::exec() twice is a noop. Definition at line 287 of file sqldb.h. References ran_. |
|
Return database connection with which this command is associated.
Definition at line 534 of file sqldb.h. References cmd_, and Dv::Sql::Command_::db(). |
|
Return text of command. Example std::string name("jane"); Sql::Command query("select * from person where name = "); query << name; cout << query.text(); select * from person where name = 'jane' |
|
Return field information for query result.
Definition at line 533 of file sqldb.h. References cmd_, and Dv::Sql::Command_::fields(). |
|
Return number of rows in query result.
Definition at line 308 of file sqldb.h. References nrows_. |
|
Return number of columns in query result.
Definition at line 310 of file sqldb.h. References ncols_. |
|
Return logical pointer to first row of the result.
|
|
Return logical pointer to past the end of the query result.
Definition at line 535 of file sqldb.h. References iterator. |
|
Check whether a rowno r is valid, i.e. the r'th row is available.
|
|
Append a string to the command text; the string will be escaped and quoted. E.g. after Db::Sql::Db& db; Dv::Sql::Command q(db,"select * from person"); q << "where name =" << std::string("joe's nightamere"); select * from person where name = 'joe\'s nightmare' Note that Dv::Sql::Command::operator<<(const char*) does not escape or quote. |
|
Append a string to the command text.
|
|
Append an int to the command text.
|
|
Append an unsigned int to the command text.
|
|
Append a short to the command text.
|
|
Append an unsigned short to the command text.
|
|
Append a long to the command text.
|
|
Append an unsigned long to the command text.
|
|
Append a float to the command text.
|
|
Append a double to the command text.
|
|
Execute the query, status is determined by underlying DBMS.
Definition at line 532 of file sqldb.h. References cmd_, and Dv::Sql::Command_::exec(). |
|
Return auto_increment id of last insert.
Definition at line 536 of file sqldb.h. References cmd_, and Dv::Sql::Command_::insertid(). |
|
Retrieve the r'th row of the result ( 0<= r < nrows_ ). Delegated to cmd_. Definition at line 523 of file sqldb.h. References cmd_, and Dv::Sql::Command_::fetch(). |
|
Retrieve the r'th row and c'th column of the result ( 0<= r < //nrows_ ). Delegated to cmd_. Definition at line 528 of file sqldb.h. References cmd_, and Dv::Sql::Command_::fetch(). |
|
Assignment is forbidden.
|
|
Definition at line 392 of file sqldb.h. References nrows_. |
|
Definition at line 393 of file sqldb.h. References ncols_. |
|
Definition at line 394 of file sqldb.h. References ran_. |
|
Definition at line 395 of file sqldb.h. References err_. |
|
Definition at line 396 of file sqldb.h. References ok_. |
|
Friend.
|
|
Friend.
Definition at line 262 of file sqldb.h. Referenced by end(). |
|
Friend.
|
|
|
|
Definition at line 361 of file sqldb.h. Referenced by err(). |
|
Definition at line 362 of file sqldb.h. Referenced by ok(), and operator bool(). |
|
Definition at line 363 of file sqldb.h. Referenced by text(). |
|
Definition at line 364 of file sqldb.h. Referenced by text(). |
|
Nrows_ is # of rows in query answer, only valid if ran() && ok().
Definition at line 368 of file sqldb.h. Referenced by nrows(). |
|
Ncols_ is # of columns in query answer, only valid if ran() && ok().
Definition at line 370 of file sqldb.h. Referenced by ncols(). |
|
Associated dbms-dependent object. Many functions such as Dv::Sql::Command::exec() are delegated to cmd_->exec(). Definition at line 377 of file sqldb.h. Referenced by db(), exec(), fetch(), fields(), and insertid(). |