C++DB is the database layer that was designed to work with C++CMS. This customized version is used within Ye Ol' Pi Shack.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

202 lines
8.1 KiB

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