b2855dc Merge pull request #378 from ravselj/sqlite_memory_leak bf5dad9 Memory leak fix in sqlite3_session_backend. 165737c Fix incorrect pointer instead pointee comparison. 625db74 Merge pull request #376 from ravselj/cmake_debug_postfix2 f3a1055 Added proper support for SOCI_DEBUG_POSTFIX by changing backend-loader macro. If debug postfix is specified in CMake then it is passed forward to soci-core backend loader which then combines proper name based on build configuration. 3459d7d Minor CMake fix that checks if shared mode is set before adding shared test(s). 66d407a Merge pull request #373 from musopr/ambiguous_session 9070742 Merge pull request #372 from musopr/clang_cxx_c11 7b08ec7 Fixed ambiguous 'session' reference e9748de Include SOCI_CXX_VERSION_FLAGS when compiling Clang abd6775 Merge pull request #368 from ravselj/cmake_debug_postfix cae0086 Added CMAKE_DEBUG_POSTFIX to SOCI_LIB_SUFFIX. This fixes backend loading when CMAKE_DEBUG_POSTFIX is used. 3dd4726 Enable MSVC multi process compiling by setting /MP flag.( VS2005+ ) e5f577f Merge pull request #365 from ravselj/sqlite_msvc_fixes c4dde08 Some trivial fixes in code to resolve MSVC warnings in SQLite back-end 330f0e0 Merge pull request #364 from ravselj/connection_pars b78c8ef Merge pull request #358 from ArnaudD-FR/bind_clean_up 9f415ee Merge pull request #362 from ArnaudD-FR/sqlite3_optim_split f1f0162 sqlite3 backend optimizations 0b1a835 Include soci-platform.h because of snprintf ac65d58 Merge pull request #361 from ArnaudD-FR/blob 24c8383 Bug fix - std::map with key type of const char* is replaced with std::string 3e02a54 Changes due to compiler warnings. 0c88f8c New data_type dt_blob and simple-interface support 403b8de Fix bind_clean_up when using 'row' 92ada95 Merge pull request #363 from ravselj/oracle_win_fix d1ad52f Add a unit test for CHAR(N) fields padding behaviour. 274d08a Explicitly set character set in Firebird unit tests for CHAR(N). 7623f76 More and better MSVC warnings fixes. caa2370 Removed dummy and not compilable operator<<(boost::optional). c025cc8 Fix inserting strings longer than 8000 bytes with ODBC/MS SQL. d8d765f Update documentations b5d6507 - oracle cmake Windows fix - test oracle compilation error fix a6b3514 Split Statement::clean_up into bind_clean_up and clean_up ba453c7 Make SQL state in ODBC backend error messages more clear. a374e54 Make ODBC backend error messages more homogeneous. c4255c9 Delete old /docs folder. 0d3b6b9 Merge pull request #344 from OniDaito/markdown_doc 04f9461 Merge pull request #352 from ravselj/cmake_bug_shared 955a915 - CMake bug fix when building MSVC with SHARED option enabled f7be373 Merge pull request #348 from msobczak/classic-makefiles 36f373f Added classic Makefile for PostgreSQL test. 615cb94 Updated classic Makefile for PostgreSQL backend. 821092c Don't use both -ansi and -std=gnu++98 flags with g++. 07543f5 Merge pull request #346 from msobczak/classic-makefiles 291fbe7 Merge pull request #347 from jsonn/master a87776e Make it easier to override SOCI_LIBDIR. 96e66f5 Corrected handling of generated file with backend search path. 0b26c32 Updated classic Makefiles for Oracle Express 11.2. 15a3705 Removed all the crap debian packaging threw in 6db2a65 Merge pull request #343 from OniDaito/master cf11404 Added Markdown docs ffbfdc0 Inlined the pragmas for the C++11 tests ae3ac9d Mistake with CXX11 pragma fixed in session.h 303a966 Merge pull request #341 from mloskot/issues/340 7d7516d Add more qualifications uses of session class with namespace soci::session. caa3e2b Merge pull request #335 from mloskot/issues/258 1e89d43 Fully qualify uses of session class with namespace soci::session. 1ed81ca Restore setting session with query transformation 84d29e2 Merge branch 'pull/336' 949924a Cope with GNU <=4.6 warning about the #pragma 3494b2b Wrap stream operator for boost::optional<int> with HAVE_BOOST af4b1a3 Report SOCI_CXX_C11 in CMake output 5744a16 Merge branch 'master' of https://github.com/OniDaito/soci into pull/336 0ab7b37 Remove old build .tcl scripts. 8f2195a Check Postgression availability before proceeding with build. cd3af53 Remove #include "error.h" of non-existent header 48a8bfa Added the C++11 changes back in 1aee2d1 Add -Wl,-flat_namespace -Wl,-undefined -Wl,suppress to LINK_FLAGS on Apple/OSX 2bf3aa7 Disable test of set_query_transformation with C++ lambda 1d26033 CMake should not terminate on unknown toolset d8b64cb Remove SociSystemInfo.cmake modul as redundant. fc3391f List Boost.DateTime in core dependencies f4ff281 Indicate Travis CI builds Oracle WITH_BOOST=OFF 4863376 Merge pull request #326 from mloskot/issues/224 0c18240 Restore Oracle build with tests on Travis CI. bc4abd7 Throw instead of truncating VARCHAR columns in Firebird backend. 4c612af No changes, just small code simplification in Firebird backend. ba206ed Extract common part of MySQL and ODBC MySQL tests in a header. a0fd859 Remove asserts from the SOCI headers and code. b36944c Check vector indices instead of asserting that they are valid. 75ef8d8 Handle dt_unsigned_long_long in the "simple" SOCI layer. 2e2f60b Remove asserts on unknown type from the "simple" SOCI layer. e21aef7 Throw instead of asserting if connection_pool::lease() fails. 4b4cecb Replace left over asserts with CATCH CHECK in the tests code. 388a8d3 Use compile-time asserts to check SQLINTEGER size. af80fd8 Use SQLT_BDOUBLE instead of SQLT_FLT in Oracle backend. c74132b Fix warning about pointer-to-int conversion in Firebird backend. 4916551 Reorganize more unit tests to use CATCH sections. 787b428 Fix duplicate test name in Oracle unit tests. 7f65799 Avoid warnings about int-to-pointer conversions in DB2 backend. 7e80c68 Use parameter names from the query, if given, in error messages. 8b0c372 Don't clean up SQLite3 statement prematurely. 9119ed8 Rename db2_statement_backend::names field to names_. f5c86b7 Make SOCI_NORETURN public and use it in declaration. 62c17b2 Add mktime_from_ymdhms() helper. ee0b9e4 Fix a clash between CATCH test cases defined in different files. 60a33f4 Reorganize "Use and into" unit test to use CATCH sections. db59a48 Merge pull request #314 from rpiotaix/release/3.2 82ea95f Don't add DB2_INCLUDE_DIR to global include directories. 4f570d7 Restore Travis CI builds for other databases 71edca9 Merge pull request #306 from mloskot/postgression 1e4b365 Add a Travis build using PostgreSQL server at Postgression. 6abb7e1 Typo 1ccff47 Replace raw & with & entity. 56d3aa6 No real changes, just remove trailing whitespace. ef6d90d Fix previous attempt to correct include of SQLite3 backend header 31a22a1 Include SQLite3 backend public headers using soci/ prefix. e4376ed Merge branch 'master' into develop-3.2.3 111b50a Merge branch 'hotfix/3.2.3' 0ef4912 Add 3.2.3 release notes 8da98b2 Add new contributors ee7e155 Bump version number in docs 30c02f3 Merge branch 'master' of git://github.com/Alex-Vol/soci into hotfix/3.2.3-PR263 5577606 Improve readability of ODBC error message Closes #229 8e14c5b Improve error message when an odbc error occurs 8a50af6 Merge branch 'hotfix/3.2.3' of https://github.com/SOCI/soci into hotfix/3.2.3 a948ab3 Remove unused HAVE_XXX defines 2c85be1 Fix missing strtoll on Cygwin and MinGW d9c059e Clarify documenation and examples on bulk operations. a08d750 [travis] Disable Oracle build 70e67aa Replace prefix underscore with suffix in private member names c799e4f Append each member of tuple/fusion instead of adding tuple/fusion 645e7a2 Merge github.com:pacocamberos/soci into pacocamberos-branch-mysql-blob e96bc2b Ignore CMakeLists.txt.user created by Qt Creator IDE f694e30 Bump library version number to 3.2.3 5ecebe9 fixed link error for msvc 64 bit 3278579 Fix email notifications for Travis CI builds. ad9075c Configure Travis CI to fail the build a.s.a.p. 7481868 Explicitly set extra_float_digits when using PostgreSQL in ODBC. 83bbbd4 update sqlite3 backend documentation 57530a1 Merge pull request #302 from vadz/rich-exceptions 5cda82a Avoid throwing from soci_error copy ctor and assignment operator. 8bb6610 Provide context of the error in soci_error when possible. a8ba1cb Add use_type_base::dump_value() for richer diagnostics. 76b3089 Add soci_error::get_error_message() method. e8e5978 No real changes, just remove trailing whitespace. a90018b Merge catch-tests branch. 7b8b37b Use REQUIRE() and not CHECK() for a test that can't be allowed to fail. c9dbe19 Move all tests from tests/assert to tests directory itself. 246f657 Convert the tests to use CATCH testing framework. b2060fb Add single header version of CATCH testing framework. b87407e Add values::get_number_of_columns() accessor. 9628081 Define SOCI_NORETURN: a portable __attribute__((noreturn)) equivalent. 6ebcbcd Remove the never used details::statement_impl::namedUses_. 0f1f295 Add helper exchange_type_cast<>() template function. 02207fc Rename "version" class in the ODBC test to "odbc_version". 42549d0 Merge pull request #297 from nbougalis/unshadow 7d5eb2d Use a base-class member instead of shadowing it. 37fbe8f Don't always disable ODBC MS SQL test under Unix, just when using Travis. ed37399 Fix ODBC backend get_affected_rows() when using FreeTDS driver. f212ca9 Skip test which fails when using ODBC with MS SQL Server. 629386f Merge pull request #294 from denisarnaud/develop 294becb Fix for the issue #169: cleaner way to include headers. 120b88c Accept oraocci12 as a possible Oracle library name too. 8e1ddcd Merge pull request #213 from ayllon/develop 6552eb1 No real changes, just simplify Firebird backend code a little. 34be702 Test exact round trip for NUMERIC values for all backends. 24c0539 Fix rounding error in Firebird NUMERIC/DECIMAL conversions. 69352bc Speculatively enable exact floating point comparisons for all backends. f497fb8 Disable exact floating point when using PostgreSQL ODBC driver. 6f9dd54 No changes, just fix a repetitive typo in "assert" in comments. 02f0a69 No changes, just remove annoying "EXECEPTION" typo. 4bf2d3c Explicitly disable exact floating point comparison in MySQL test. 1f3dd92 Replace accidental assignment with a comparison in Firebird unit test. c3cd309 Make text-to-double conversion exact in PostgreSQL backend. ff9146a Explicitly disable exact floating point comparison in SQLite test. 7039d00 Compare floating point values exactly in tests whenever possible. 53cd24e Don't start implicit transaction too eagerly in Firebird backend. 66f0d82 Add possibility to build Firebird using embedded library. 1489811 Update version to 4.0.0 in cmake too. 5838cc6 Reenable building, if not testing, Oracle backend. dc4fb73 Move ORACLE_HOME to Oracle-specific script. f9167a1 Avoid many warnings about floating point values comparison. c85744b Define GCC_WARNING_SUPPRESS and GCC_WARNING_RESTORE macros. ef7e9a9 Avoid warning about set but unused variable in Oracle backend. 86a4598 Avoid g++ warnings about casting away const with C-style casts. 2c887b3 Ignore CMake-generated files. f61d7f5 Add missing include for std::max 21824a1 fixed deadlock in soci::connection_pool::try_lease 6e6bd46 Documentation for SQLite3 result code support. 97cbb0a Update PostgreSQL backend documentation for UUID type support. 5448cf1 Spelling fix in an error message: s/Commiting/Committing/. 5b073e3 Remove the unnecessary "error.h" inclusion from PostgreSQL code. 5776dd4 Introduced sqlite3_soci_error exception as subclass of soci_error. This new exception exposes the SQLite3 result code returned when any failure happens. Using this method is preferable to scrubbing string error messages in soci_error exceptions. Useful when there needs to be a distinction between general errors and database constraint errors. Unit test added to prove the funtionality does what is expected. 6d766e7 Introduced support for UUID column type in PostgreSQL statement.cpp. Unit test added for UUID column support testing all supported kinds of UUID formatted strings on input and standardized UUID formatted strings on output. e106dc0 Optionally use the environment locale in the tests. 1b65061 Make sqlite3 and mysql backends work with any locale too. 8548642 Use locale-independent function for converting doubles to strings. 1260d4f Reimplement cstring_to_double() without using C++ standard library. bc884fe Remove unused HAVE_XXX defines 4ffb21b Fix missing strtoll on Cygwin and MinGW 7bd4991 Clarify documenation and examples on bulk operations. 4d0785e Temporarily disable using Oracle backend on Travis. da7e42c Merge pull request #242 from vadz/pgsql8-bytea 070b278 Merge branch 'fix_odbc_msvc_x86_64' of github.com:snikulov/soci into snikulov-fix_odbc_msvc_x86_64 fce8560 [travis] Disable Oracle build 0ff0e01 Replace prefix underscore with suffix in private member names 65a5ee3 Append each member of tuple/fusion instead of adding tuple/fusion 8e9fb42 Merge github.com:pacocamberos/soci into pacocamberos-branch-mysql-blob 3dca4e3 Ignore CMakeLists.txt.user created by Qt Creator IDE de7e6f0 Bump library version number to 3.2.3 946dd5a Fix PostgreSQL unit test to pass with PostgreSQL < 9.0. 0a47eaf vs2013 got strtoll/strtoull 58d31f9 Update version to 4.0.0. 89df841 Merge pull request #239 from vadz/soci-headers-prefix 417ef5c Include all public headers using "soci/" prefix inside SOCI itself. 5a99a15 Merge pull request #238 from vadz/cstrtod 0585bb1 Merge pull request #237 from vadz/odbc-header-fix 6f4162c Add helper cstring_to_double() and use it in PostgreSQL backend. 73119cb Fix compilation of ODBC-specific SOCI header with new include paths. d877390 Delete obsolete src/<backend>/test directories 06a970f Revert CMake setup for ODBC DB2 test f04147a Move ODBC test DSN files to new tests location 0219c43 Fix paths to ODBC test DSN files 928174c Fix Firebird includes of private headers bc171b6 Fix copy-n-paste error in CMake macro parameter name 1f4d6ef Fix includes to point to backend headers in subdirectories 552e81c Enable other tests in tests/assert 7a018a3 Move tests/assert into separate subdirectories e2ec7ff Ignore Qt Creator and Eclipse files 5d527ec Fix windows.h case for cross-compilation 024ccc8 Firebird: fix harmless warning in 64 bit builds. 802f78e Merge pull request #216 from dgrambow/develop 32c5f88 Add get_last_insert_id tests for sqlite3 and mysql backends ccd4c0d Add get_last_insert_id for sqlite3 and mysql backends Update docs/beyond.html accordingly 42aec23 Fix in soci::oracle to allow spaces in the params b2ea9f7 fixed link error for msvc 64 bit ef69fa9 [travis] Disable building tests due to #199 09acb8c [travis] Fix bash script syntax error cba671f [travis] Disable ctest run due to #199 d8f7d9d [travis] Restore soci-devel notifications 22257b3 [cmake] Remove unused log message 0cffb8a CMake 2.8.7 have problems with per target includes b430cb0 Attempt to correct -I paths for backend test 6c0721d Attempt to correct -I paths for backend folders 69d70c5 [travis] Disable tempoarily soci-devel notifications f4802f1 [travis] Log build script name 8890aea [travis] Set CMAKE_VERBOSE_MAKEFILE=ON 717c38a [travis] Remove superfluos ] from make invocation 843a43c Fix travis-ci to run CMake from root directory 9e43795 Update copyright year da025df Merge branch 'feature/125-new-layout' into develop 04a34f2 Link presentation from London C++ Meeting 11ef1fa Fix doc/index.html menu links 5393ee5 Merge branch 'hotfix/3.2.2' into develop b6d97ff Implement new source tree layout #125 git-subtree-dir: src/soci git-subtree-split: b2855dce54340522f149221c6ebe2d14fd1129ba
16 KiB
Backends reference
This part of the documentation is provided for those who want towrite (and contribute!) their own backends. It is anyway recommendedthat authors of new backend see the code of some existing backend forhints on how things are really done.
The backend interface is a set of base classes that the actual backendsare supposed to specialize. The main SOCI interface uses only theinterface and respecting the protocol (for example, the order offunction calls) described here. Note that both the interface and theprotocol were initially designed with the Oracle database in mind, which means that whereas it is quite natural with respect to the way Oracle API (OCI) works, it might impose some implementation burden on otherbackends, where things are done differently and therefore have to beadjusted, cached, converted, etc.
The interface to the common SOCI interface is defined in the core/soci-backend.h header file. This file is dissected below.
All names are defined in either soci or soci::details namespace.
// data types, as seen by the user
enum data_type
{
dt_string, dt_date, dt_double, dt_integer, dt_long_long, dt_unsigned_long_long
};
// the enum type for indicator variables
enum indicator { i_ok, i_null, i_truncated };
// data types, as used to describe exchange format
enum exchange_type
{
x_char,
x_stdstring,
x_short,
x_integer,
x_long_long,
x_unsigned_long_long,
x_double,
x_stdtm,
x_statement,
x_rowid,
x_blob
};
struct cstring_descriptor
{
cstring_descriptor(char * str, std::size_t bufSize)
: str_(str), bufSize_(bufSize) {}
char * str_;
std::size_t bufSize_;
};
// actually in error.h:
class soci_error : public std::runtime_error
{
public:
soci_error(std::string const & msg);
};
The data_type enumeration type defines all types that form the core type support for SOCI. The enum itself can be used by clients when dealing with dynamic rowset description.
The indicator enumeration type defines all recognized states of data. The i_truncated state is provided for the case where the string is retrieved from the database into the char buffer that is not long enough to hold the whole value.
The exchange_type enumeration type defines all possible types that can be used with the into and use elements.
The cstring_descriptor is a helper class that allows to store the address of char buffer together with its size. The objects of this class are passed to the backend when the x_cstring type is involved.
The soci_error class is an exception type used for database-related (and also usage-related) errors. The backends should throw exceptions of this or derived type only.
class standard_into_type_backend
{
public:
standard_into_type_backend() {}
virtual ~standard_into_type_backend() {}
virtual void define_by_pos(int& position, void* data, exchange_type type) = 0;
virtual void pre_fetch() = 0;
virtual void post_fetch(bool gotData, bool calledFromFetch, indicator* ind) = 0;
virtual void clean_up() = 0;
};
The standard_into_type_back_end class implements the dynamic interactions with the simple (non-bulk) into elements. The objects of this class (or, rather, of the derived class implemented by the actual backend) are created by the statement object when the into element is bound - in terms of lifetime management, statement is the master of this class.
define_by_pos- Called when theintoelement is bound, once and before the statement is executed. Thedatapointer points to the variable used forintoelement (or to thecstring_descriptorobject, which is artificially created when the plaincharbuffer is used for data exchange). Thepositionparameter is a "column number", assigned by the library. The backend should increase this parameter, according to the number of fields actually taken (usually 1).pre_fetch- Called before each row is fetched.post_fetch- Called after each row is fetched. ThegotDataparameter istrueif the fetch operation really retrievedsome data andfalseotherwise;calledFromFetchistruewhen the call is from the fetch operation andfalseif it is from the execute operation (this is also the case for simple, one-time queries). In particular,(calledFromFetch && !gotData)indicates that there is an end-of-rowset condition.indpoints to the indicator provided by the user, or isNULL, if there is no indicator.clean_up- Called once when the statement is destroyed.
The intended use of pre_fetch and post_fetch functions is to manage any internal buffer and/or data conversion foreach value retrieved from the database. If the given server supportsbinary data transmission and the data format for the given type agreeswith what is used on the client machine, then these two functions neednot do anything; otherwise buffer management and data conversionsshould go there.
class vector_into_type_backend
{
public:
vector_into_type_backend() {}
virtual ~vector_into_type_backend() {}
virtual void define_by_pos(int& position, void* data, exchange_type type) = 0;
virtual void pre_fetch() = 0;
virtual void post_fetch(bool gotData, indicator* ind) = 0;
virtual void resize(std::size_t sz) = 0;
virtual std::size_t size() = 0;
virtual void clean_up() = 0;
};
The vector_into_type_back_end has similar structure and purpose as the previous one, but is used for vectors (bulk data retrieval).
The data pointer points to the variable of type std::vector<T>; (and not to its internal buffer), resize is supposed to really resize the user-provided vector and size
is supposed to return the current size of this vector. The important difference with regard to the previous class is that ind points (if not NULL) to the beginning of the array of indicators. The backend should fill this array according to the actual state of the retrieved data.
bind_by_pos- Called for eachuseelement, once and before the statement is executed - for thoseuseelements that do not provide explicit names for parameter binding. The meaning of parameters is same as in previous classes.bind_by_name- Called for thoseuseelements that provide the explicit name.pre_use- Called before the data is transmitted to the server (this means before the statement is executed, which can happen many times for the prepared statement).indpoints to the indicator provided by the user (or isNULL).post_use- Called after statement execution.gotDataandindhave the same meaning as instandard_into_type_back_end::post_fetch, and this can be used by those backends whose respective servers support two-way data exchange (like in/out parameters in stored procedures).
The intended use for pre_use and post_use methods is to manage any internal buffers and/or data conversion. They can be called many times with the same statement.
class vector_use_type_backend
{
public:
virtual ~vector_use_type_backend() {}
virtual void bind_by_pos(int& position,
void* data, exchange_type type) = 0;
virtual void bind_by_name(std::string const& name,
void* data, exchange_type type) = 0;
virtual void pre_use(indicator const* ind) = 0;
virtual std::size_t size() = 0;
virtual void clean_up() = 0;
};
Objects of this type (or rather of type derived from this one) are used to implement interactions with user-provided vector (bulk) use elements and are managed by the statement object. The data pointer points to the whole vector object provided by the user (and not to its internal buffer); ind points to the beginning of the array of indicators (or is NULL). The meaning of this
interface is analogous to those presented above.
class statement_backend
{
public:
statement_backend() {}
virtual ~statement_backend() {}
virtual void alloc() = 0;
virtual void clean_up() = 0;
virtual void prepare(std::string const& query, statement_type eType) = 0;
enum exec_fetch_result
{
ef_success,
ef_no_data
};
virtual exec_fetch_result execute(int number) = 0;
virtual exec_fetch_result fetch(int number) = 0;
virtual long long get_affected_rows() = 0;
virtual int get_number_of_rows() = 0;
virtual std::string rewrite_for_procedure_call(std::string const& query) = 0;
virtual int prepare_for_describe() = 0;
virtual void describe_column(int colNum, data_type& dtype,
std::string& column_name) = 0;
virtual standard_into_type_backend* make_into_type_backend() = 0;
virtual standard_use_type_backend* make_use_type_backend() = 0;
virtual vector_into_type_backend* make_vector_into_type_backend() = 0;
virtual vector_use_type_backend* make_vector_use_type_backend() = 0;
};
The statement_backend type implements the internals of the statement objects. The objects of this class are created by the session object.
alloc- Called once to allocate everything that is needed for the statement to work correctly.clean_up- Supposed to clean up the resources, called once.prepare- Called once with the text of the SQL query. For servers that support explicit query preparation, this is the place to do it.execute- Called to execute the query; if number is zero, the intent is not to exchange data with the user-provided objects (intoanduseelements); positive values mean the number of rows to exchange (more than 1 is used only for bulk operations).fetch- Called to fetch next bunch of rows; number is positive and determines the requested number of rows (more than 1 is used only for bulk operations).get_affected_rows- Called to determine the actual number of rows affected by data modifying statement.get_number_of_rows- Called to determine the actual number of rows retrieved by the previous call toexecuteorfetch.rewrite_for_procedure_call- Used when theprocedureis used instead ofstatement, to call the stored procedure. This function should rewrite the SQL query (if necessary) to the form that will allow to execute the given procedure.prepare_for_describe- Called once when theintoelement is used with therowtype, which means that dynamic rowset description should be performed. It is supposed to do whatever is needed to later describe the column properties and should return the number of columns.describe_column- Called once for each column (column numbers -colNum- start from 1), should fill its parameters according to the column properties.make_into_type_backend,make_use_type_backend,make_vector_into_type_backend,make_vector_use_type_backend- Called once for eachintooruseelement, to create the objects of appropriate classes (described above).
Notes
-
Whether the query is executed using the simple one-time syntax or is prepared, the
alloc,prepareandexecutefunctions are always called, in this order. -
All
intoanduseelements are bound (theirdefine_by_posorbind_by_pos/bind_by_namefunctions are called) between statement preparation and execution.class rowid_backend { public: virtual ~rowid_backend() {} };
The rowid_backend class is a hook for the backends to provide their own state for the row identifier. It has no functions, since the only portable interaction with the row identifier object is to use it with into and use elements.
class blob_backend
{
public:
virtual ~blob_backend() {}
virtual std::size_t get_len() = 0;
virtual std::size_t read(std::size_t offset, char * buf,
std::size_t toRead) = 0;
virtual std::size_t write(std::size_t offset, char const * buf,
std::size_t toWrite) = 0;
virtual std::size_t append(char const * buf, std::size_t toWrite) = 0;
virtual void trim(std::size_t newLen) = 0;
};
The blob_backend interface provides the entry points for the blob methods.
class session_backend
{
public:
virtual ~session_backend() {}
virtual void begin() = 0;
virtual void commit() = 0;
virtual void rollback() = 0;
virtual bool get_next_sequence_value(session&, std::string const&, long&);
virtual bool get_last_insert_id(session&, std::string const&, long&);
virtual std::string get_backend_name() const = 0;
virtual statement_backend * make_statement_backend() = 0;
virtual rowid_backend * make_rowid_backend() = 0;
virtual blob_backend * make_blob_backend() = 0;
};
The object of the class derived from session_backend implements the internals of the session object.
-
begin,commit,rollback- Forward-called when the same functions ofsessionare called by user. -
get_next_sequence_value,get_last_insert_id- Called to retrieve sequences or auto-generated values and every backend should define at least one of them to allow the code using auto-generated values to work. -
make_statement_backend,make_rowid_backend,make_blob_backend- Called to create respective implementations for thestatement,rowidandblobclasses.struct backend_factory { virtual ~backend_factory() {}
virtual details::session_backend * make_session( std::string const& connectString) const = 0;};
The backend_factory is a base class for backend-provided factory class that is able to create valid sessions. The connectString parameter passed to make_session is provided here by the session constructor and contains only the backend-related parameters, without the backend name (if the dynamic backend loading is used).
The actual backend factory object is supposed to be provided by the backend implementation and declared in its header file. In addition to this, the factory_ABC function with the "C" calling convention and returning the pointer to concrete factory object should be provided, where ABC is the backend name.
The following example is taken from soci-postgresql.h, which declares entities of the PostgreSQL backend:
struct postgresql_backend_factory : backend_factory
{
virtual postgresql_session_backend* make_session(
std::string const& connectString) const;
};
extern postgresql_backend_factory const postgresql;
extern "C"
{
// for dynamic backend loading
backend_factory const * factory_postgresql();
} // extern "C"
With the above declarations, it is enough to pass the postgresql factory name to the constructor of the session object, which will use this factory to create concrete implementations for any other objects that are needed, with the help of appropriate make_XYZ functions. Alternatively, the factory_postgresql function will be called automatically by the backend loader if the backend name is provided at run-time instead.
Note that the backend source code is placed in the backends/*name* directory (for example, backends/oracle) and the test driver is in backends/*name*/test. There is also backends/empty directory provided as a skeleton for development of new backends and their tests. It is recommended that all backends respect naming conventions by just appending their name to the base-class names. The backend name used for the global factory object should clearly identify the given database engine, like oracle, postgresql, mysql, and so on.