| 1 |
|
| 2 |
/*! \page backendref Backends Reference |
| 3 |
|
| 4 |
CppDB provides following SQL backends support |
| 5 |
|
| 6 |
- \subpage mysql |
| 7 |
- \subpage postgresql |
| 8 |
- \subpage sqlite3 |
| 9 |
- \subpage odbc |
| 10 |
|
| 11 |
*/ |
| 12 |
|
| 13 |
//--------------------------- |
| 14 |
|
| 15 |
/*! \page mysql MySQL Backend - "mysql" |
| 16 |
|
| 17 |
MySQL backend allows to connect to MySQL database. It uses native MySQL C client API. |
| 18 |
|
| 19 |
|
| 20 |
\section conn Connection String |
| 21 |
|
| 22 |
The driver name is "mysql", cppdb::session::engine() returns "mysql" |
| 23 |
|
| 24 |
Connection Properties are: |
| 25 |
|
| 26 |
- \c host - the remote database host to connect. Default is local host. |
| 27 |
- \c user - the user name to login |
| 28 |
- \c password - the password to login |
| 29 |
- \c database - the name of the database to use - default unspecified |
| 30 |
- \c port - the port to connect - default unspecified |
| 31 |
- \c unix_socket - the socket to connect - default unspecified |
| 32 |
|
| 33 |
Additionaly you can customize the connection with MySQL option parameters. |
| 34 |
Current list of options is specified in http://dev.mysql.com/doc/refman/5.5/en/mysql-options.html . |
| 35 |
In CppDB, they are specified in lower case letters with \c mysql_ prefix removed. |
| 36 |
Boolean values should be given as either 0 or 1. Options which take no arguments (e.g. opt_compress) |
| 37 |
should be passed as a boolean with the value of 1. Example option string: |
| 38 |
|
| 39 |
\verbatim |
| 40 |
mysql:user=test;password=test;opt_reconnect=1;opt_read_timeout=10;opt_compress=1 |
| 41 |
\endverbatim |
| 42 |
|
| 43 |
\section impl Implementation Details |
| 44 |
|
| 45 |
Prepared statements are implemented using mysql_stmt_* family API, while unprepared statements |
| 46 |
use mysql_real_query API and explicit escaping using mysql_real_escape_string instead of parameter binding. |
| 47 |
|
| 48 |
Because MySQL caches query results, it sometimes more efficient to use unprepared statements |
| 49 |
rather then using prepared one that their results are not cached |
| 50 |
|
| 51 |
Last insert row id is fetched using mysql_insert_id() and mysql_stmt_insert_id() API, the |
| 52 |
name of the sequence is ignored. |
| 53 |
|
| 54 |
|
| 55 |
*/ |
| 56 |
|
| 57 |
//--------------------------- |
| 58 |
|
| 59 |
/*! \page postgresql PostgreSQL Backend - "postgresql" |
| 60 |
|
| 61 |
PostgreSQL backend allows to connect to PostgreSQL database. It uses libpq C client API. |
| 62 |
|
| 63 |
|
| 64 |
\section conn Connection String |
| 65 |
|
| 66 |
The driver name is "postgresql", cppdb::session::engine() returns "posgresql" |
| 67 |
|
| 68 |
PostgreSQL connection properties are passed as it to libpq. So for full list you should refer to |
| 69 |
the <a href="http://www.postgresql.org/docs/8.3/static/libpq-connect.html">libpq manual</a> |
| 70 |
|
| 71 |
The most used properties are: |
| 72 |
|
| 73 |
- \c host - the remote database host to connect. Default is local host. |
| 74 |
- \c user - the user name to login |
| 75 |
- \c password - the password to login |
| 76 |
- \c dbname - the name of the database to use - default unspecified |
| 77 |
- \c port - the port to connect - default unspecified |
| 78 |
|
| 79 |
\subsection connspec Special Properties |
| 80 |
|
| 81 |
PostgreSQL backend has additional internal property that define how to treat |
| 82 |
blob objects: "@blob" |
| 83 |
|
| 84 |
The possible values are: |
| 85 |
|
| 86 |
- \c lo use large object API to store Blobs. This is the default.it adds a restriction to accessing large objects only withing transaction and handing their lifetime using <a href="http://www.postgresql.org/docs/8.3/static/lo.html">lo module</a>. This option has an advantage of small memory footprint when dealing with large objects as it does not require storing full object in memory. |
| 87 |
- \c bytea - treat Blobs as bytea columns. This is simpler method but it is applicable only for objects that can fit to memory. |
| 88 |
|
| 89 |
|
| 90 |
\section impl Implementation Details |
| 91 |
|
| 92 |
Prepared statements are implemented using PQexecPrepared API, while unprepared statements |
| 93 |
use PQexecParams API. |
| 94 |
|
| 95 |
When using PostgreSQL large objects "@blob=lo" - the default - you should access them only during transaction, otherwise |
| 96 |
the operations would fail. It is very good idea to use <a href="http://www.postgresql.org/docs/8.3/static/lo.html">lo module</a> |
| 97 |
that helps handing object lifetime as cppdb backend is not aware of statement type you use and it can't decide whether |
| 98 |
new object should be created in insert statement or same object should be updated. So "lo" module is your friend. |
| 99 |
|
| 100 |
You may also use bytea if want to have a semantics similar to other RDBMSs Blobs. |
| 101 |
|
| 102 |
Fetching last insert id should be done using non-empty sequence name, i.e. using cppdb::statement::sequence_last() and |
| 103 |
it is fetched using "SELECT currval(?)" statement. |
| 104 |
|
| 105 |
|
| 106 |
*/ |
| 107 |
|
| 108 |
|
| 109 |
//--------------------------- |
| 110 |
|
| 111 |
/*! \page sqlite3 SQlite3 Backend - "sqlite3" |
| 112 |
|
| 113 |
SQlite3 backend allows to connect to SQlite3 database. It uses native SQlite3 C client API. |
| 114 |
|
| 115 |
|
| 116 |
\section conn Connection String |
| 117 |
|
| 118 |
The driver name is "sqlite3", cppdb::session::engine() returns "sqlite3" |
| 119 |
|
| 120 |
Connection Properties are: |
| 121 |
|
| 122 |
- \c db - the path to sqlite3 database file, special name ":memory:" can be used as well. |
| 123 |
- \c mode - the mode to open connection with, one of "create", "readonly" and "readwrite", default is "create". The difference between |
| 124 |
"readwrite" and "create" that if the database does not exist the connection fails. |
| 125 |
- \c busy_timeout - the equivalent of \c sqlite3_busy_timeout function. Specifies the minimal number of milliseconds |
| 126 |
to wait before returning a error if the database is locked by another process. |
| 127 |
- \c vfs - the name of vfs to use |
| 128 |
|
| 129 |
\section impl Implementation Details |
| 130 |
|
| 131 |
Both prepared and not prepared statements are implemented using sqlite3_ API, |
| 132 |
while unprepared statements just not getting cached unlike prepared ones. |
| 133 |
|
| 134 |
Last insert row id is fetched using sqlite3_last_insert_rowid(), the |
| 135 |
name of the sequence is ignored. |
| 136 |
|
| 137 |
|
| 138 |
*/ |
| 139 |
|
| 140 |
//--------------------------- |
| 141 |
|
| 142 |
/*! \page odbc CppDB - ODBC bridge - "odbc" |
| 143 |
|
| 144 |
ODBC backend allows to connect to almost any existing SQL database via ODBC driver and |
| 145 |
provides much more convenient interface that ODBC C API. |
| 146 |
|
| 147 |
Unlike other backends, this one is not loaded dynamically by default but rather linked directly |
| 148 |
to cppdb library. |
| 149 |
|
| 150 |
\section conn Connection String |
| 151 |
|
| 152 |
The driver name is "odbc", but the cppdb::session::engine() returns "unknown" unless "@engine" property is specified. |
| 153 |
|
| 154 |
Connection Properties are passed as is into ODBC connection string, so for example for connecting to some database |
| 155 |
you may just simply specify: |
| 156 |
|
| 157 |
\verbatim |
| 158 |
odbc:DSN=MySource;UID=myuser;PWD=secret |
| 159 |
\endverbatim |
| 160 |
|
| 161 |
However there are several additional internal properties that define how cppdb treats the ODBC connection: |
| 162 |
|
| 163 |
- \c \@engine - the type of underlying database engine, it allows the backend to customise the behavior and |
| 164 |
provide support for features missing in ODBC API itself. |
| 165 |
\n |
| 166 |
Currently following engine names provide additional values: "mysql", "sqlite3", "postgresql", "mssql". It allows |
| 167 |
the driver to support cppdb::statement::sequence_last() or cppdb::statement::last_insert_id() functionality. |
| 168 |
- \c \@utf - with options "narrow" - the default and "wide". This option specifies how to deal with Unicode. If the "narrow" |
| 169 |
option is used (default) it would pass strings as is to the backend assuming that is supports UTF-8 natively using so |
| 170 |
called "ANSI" API , otherwise, it would use so called "Wide" API and convert the strings to UTF-16 and use wide character |
| 171 |
functions. |
| 172 |
\n |
| 173 |
\note you should almost always use narrow option as most ODBC drivers support UTF-8 happily, however when you |
| 174 |
work with MS SQL under windows you would probably want to use wide API for operation on strings. |
| 175 |
- \c \@sequence_last - the SQL statement that is used for retrieving the last created id. You need to specify this if you |
| 176 |
want to use cppdb::statement::sequence_last() or cppdb::statement::last_insert_id() and the engine is not one of mysql sqlite3, postgresql or mssql. |
| 177 |
\n If the statement contains "?" mark the parameter of cppdb::statement::sequence_last() would be binded to it, otherwise the parameter is ignored. |
| 178 |
|
| 179 |
|
| 180 |
\section impl Implementation Details |
| 181 |
|
| 182 |
Both prepared statements use SQLPrepare API and unprepared statements use SQLExecDirect API. All data |
| 183 |
is fetched using SQLGetData in order to support variable text length. |
| 184 |
|
| 185 |
Following statements are used for fetching last insert id: |
| 186 |
|
| 187 |
- \c sqlite3 - "select last_insert_rowid()" |
| 188 |
- \c mysql - "select last_insert_id()" |
| 189 |
- \c postgresql - "select currval(?)" |
| 190 |
- \c mssql - "select @@identity" |
| 191 |
|
| 192 |
If the engine is not one of the above and "@sequence_last" property is not defined the cppdb::not_supported_by_backend exception |
| 193 |
would be thrown. |
| 194 |
|
| 195 |
cppdb::session::escape() functionality is not supported as actual escaping rules vary by the specific RDBMS and attempt |
| 196 |
to use them would cause cppdb::not_supported_by_backend exception. |
| 197 |
|
| 198 |
|
| 199 |
*/ |
| 200 |
|
| 201 |
|