CppDB
|
ODBC backend allows to connect to almost any existing SQL database via ODBC driver and provides much more convenient interface that ODBC C API.
Unlike other backends, this one is not loaded dynamically by default but rather linked directly to cppdb library.
The driver name is "odbc", but the cppdb::session::engine() returns "unknown" unless "@engine" property is specified.
Connection Properties are passed as is into ODBC connection string, so for example for connecting to some database you may just simply specify:
odbc:DSN=MySource;UID=myuser;PWD=secret
However there are several additional internal properties that define how cppdb treats the ODBC connection:
@engine
- the type of underlying database engine, it allows the backend to customise the behavior and provide support for features missing in ODBC API itself. @utf
- with options "narrow" - the default and "wide". This option specifies how to deal with Unicode. If the "narrow" option is used (default) it would pass strings as is to the backend assuming that is supports UTF-8 natively using so called "ANSI" API , otherwise, it would use so called "Wide" API and convert the strings to UTF-16 and use wide character functions. @sequence_last
- the SQL statement that is used for retrieving the last created id. You need to specify this if you 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. Both prepared statements use SQLPrepare API and unprepared statements use SQLExecDirect API. All data is fetched using SQLGetData in order to support variable text length.
Following statements are used for fetching last insert id:
sqlite3
- "select last_insert_rowid()"mysql
- "select last_insert_id()"postgresql
- "select currval(?)"mssql
- "select @@identity"If the engine is not one of the above and "@sequence_last" property is not defined the cppdb::not_supported_by_backend exception would be thrown.
cppdb::session::escape() functionality is not supported as actual escaping rules vary by the specific RDBMS and attempt to use them would cause cppdb::not_supported_by_backend exception.