Warning, /sdk/codevis/thirdparty/soci/docs/api/client.md is written in an unsupported language. File is not indexed.
0001 # API Reference 0002 0003 The core client interface is a set of classes and free functions declared in the `soci.h` header file. 0004 All names are dbeclared in the `soci` namespace. 0005 0006 There are also additional names declared in the `soci::details` namespace, but they are not supposed to be directly used by the users of the library and are therefore not documented here. 0007 When such types are used in the declarations that are part of the "public" interface, they are replaced by "IT", which means "internal type". 0008 Types related to the backend interface are named here. 0009 0010 ## Commonly used types 0011 0012 The following types are commonly used in the rest of the interface: 0013 0014 ```cpp 0015 // data types, as seen by the user 0016 enum data_type { dt_string, dt_date, dt_double, dt_integer, dt_long_long, dt_unsigned_long_long }; 0017 0018 // the enum type for indicator variables 0019 enum indicator { i_ok, i_null, i_truncated }; 0020 0021 // the type used for reporting exceptions 0022 class soci_error : public std::runtime_error { /* ... */ }; 0023 ``` 0024 0025 The `data_type` type defines the basic SOCI data types. User provided data types need to be associated with one of these basic types. 0026 0027 The `indicator` type defines the possible states of data. 0028 0029 The `soci_error` type is used for error reporting. 0030 0031 ## class session 0032 0033 The `session` class encapsulates the connection to the database. 0034 0035 ```cpp 0036 class session 0037 { 0038 public: 0039 session(); 0040 explicit session(connection_parameters const & parameters); 0041 session(backend_factory const & factory, std::string const & connectString); 0042 session(std::string const & backendName, std::string const & connectString); 0043 explicit session(std::string const & connectString); 0044 explicit session(connection_pool & pool); 0045 0046 ~session(); 0047 0048 void open(backend_factory const & factory, std::string const & connectString); 0049 void open(std::string const & backendName, std::string const & connectString); 0050 void open(std::string const & connectString); 0051 void close(); 0052 void reconnect(); 0053 0054 bool is_connected() const; 0055 0056 void begin(); 0057 void commit(); 0058 void rollback(); 0059 0060 *IT* once; 0061 *IT* prepare; 0062 0063 template <typename T> *IT* operator<<(T const & t); 0064 0065 bool got_data() const; 0066 0067 bool get_next_sequence_value(std::string const & sequence, long long & value); 0068 bool get_last_insert_id(std::string const & table, long long & value); 0069 0070 std::ostringstream & get_query_stream(); 0071 0072 void set_log_stream(std::ostream * s); 0073 std::ostream * get_log_stream() const; 0074 0075 std::string get_last_query() const; 0076 0077 void uppercase_column_names(bool forceToUpper); 0078 0079 std::string get_dummy_from_table() const; 0080 std::string get_dummy_from_clause() const; 0081 0082 details::session_backend * get_backend(); 0083 0084 std::string get_backend_name() const; 0085 }; 0086 ``` 0087 0088 This class contains the following members: 0089 0090 * Various constructors. The default one creates the session in the disconnected state. The others expect the backend factory object, or the backend name, or the URL-like composed connection string or the special parameters object containing both the backend and the connection string as well as possibly other connection options. The last constructor creates a session proxy associated with the session that is available in the given pool and releases it back to the pool when its lifetime ends. Example: 0091 0092 ```cpp 0093 session sql(postgresql, "dbname=mydb"); 0094 session sql("postgresql", "dbname=mydb"); 0095 session sql("postgresql://dbname=mydb"); 0096 ``` 0097 0098 * The constructors that take backend name as string load the shared library (if not yet loaded) with name computed as `libsoci_ABC.so` (or `libsoci_ABC.dll` on Windows) where `ABC` is the given backend name. 0099 * `open`, `close` and `reconnect` functions for reusing the same session object many times; the `reconnect` function attempts to establish the connection with the same parameters as most recently used with constructor or `open`. The arguments for `open` are treated in the same way as for constructors. `is_connected` can be used to check if there is an existing usable connection. 0100 * `begin`, `commit` and `rollback` functions for transaction control. 0101 * `once` member, which is used for performing *instant* queries that do not need to be separately prepared. Example: 0102 0103 ```cpp 0104 sql.once << "drop table persons"; 0105 ``` 0106 0107 * `prepare` member, which is used for statement preparation - the result of the statement preparation must be provided to the constructor of the `statement` class. Example: 0108 0109 ```cpp 0110 int i; 0111 statement st = (sql.prepare << 0112 "insert into numbers(value) values(:val)", use(i)); 0113 ``` 0114 0115 * `operator<<` that is a shortcut forwarder to the equivalent operator of the `once` member. Example: 0116 0117 ```cpp 0118 sql << "drop table persons"; 0119 ``` 0120 0121 * `got_data` returns true if the last executed query had non-empty result. 0122 * `get_next_sequence_value` returns true if the next value of the sequence with the specified name was generated and returned in its second argument. Unless you can be sure that your program will use only databases that support sequences, consider using this method in conjunction with `get_last_insert_id()` as explained in ["Working with sequences"](../beyond.md#sequences) section. 0123 * `get_last_insert_id` returns true if it could retrieve the last value automatically generated by the database for an auto-incremented field. Notice that although this method takes the table name, for some databases, such as Microsoft SQL Server and SQLite, this value is actually global, so you should attempt to retrieve it immediately after performing an insertion. 0124 * `get_query_stream` provides direct access to the stream object that is used to accumulate the query text and exists in particular to allow the user to imbue specific locale to this stream. 0125 * `set_log_stream` and `get_log_stream` functions for setting and getting the current stream object used for basic query logging. By default, it is `NULL`, which means no logging The string value that is actually logged into the stream is one-line verbatim copy of the query string provided by the user, without including any data from the `use` elements. The query is logged exactly once, before the preparation step. 0126 * `get_last_query` retrieves the text of the last used query. 0127 * `uppercase_column_names` allows to force all column names to uppercase in dynamic row description; this function is particularly useful for portability, since various database servers report column names differently (some preserve case, some change it). 0128 * `get_dummy_from_table` and `get_dummy_from_clause()`: helpers for writing portable DML statements, see [DML helpers](../utilities.md#dml) for more details. 0129 * `get_backend` returns the internal pointer to the concrete backend implementation of the session. This is provided for advanced users that need access to the functionality that is not otherwise available. 0130 * `get_backend_name` is a convenience forwarder to the same function of the backend object. 0131 0132 See [connection](../connections.md) and [queries](../queries.md) for more examples. 0133 0134 ## class connection_parameters 0135 0136 The `connection_parameters` class is a simple container for the backend pointer, connection string and any other connection options. It is used together with `session` constructor and `open()` method. 0137 0138 ```cpp 0139 class connection_parameters 0140 { 0141 public: 0142 connection_parameters(); 0143 connection_parameters(backend_factory const & factory, std::string const & connectString); 0144 connection_parameters(std::string const & backendName, std::string const & connectString); 0145 explicit connection_parameters(std::string const & fullConnectString); 0146 0147 void set_option(const char * name, std::string const & value); 0148 bool get_option(const char * name, std::string & value) const; 0149 0150 bool is_option_on(const char * name) const; 0151 }; 0152 ``` 0153 0154 The methods of this class are: 0155 0156 * Default constructor is rarely used as it creates an uninitialized object and the only way to initialize it later is to assign another, valid, connection_parameters object to this one. 0157 * The other constructors correspond to the similar constructors of the `session` class and specify both the backend, either as a pointer to it or by name, and the connection string. 0158 * `set_option` can be used to set the value of an option with the given name. Currently all option values are strings, so if you need to set a numeric option you need to convert it to a string first. If an option with the given name had been already set before, its old value is overwritten. 0159 * `get_option` can be used to query the value of an option and returns `false` if there is no such option, while `is_option_on` simply checks if the option is specified with the value `soci::option_true` (which is a symbolic constant standing for the string `"1"`). 0160 0161 ## class connection_pool 0162 0163 The `connection_pool` class encapsulates the thread-safe pool of connections and ensures that only one thread at a time has access to any connection that it manages. 0164 0165 ```cpp 0166 class connection_pool 0167 { 0168 public: 0169 explicit connection_pool(std::size_t size); 0170 ~connection_pool(); 0171 0172 session & at(std::size_t pos); 0173 0174 std::size_t lease(); 0175 bool try_lease(std::size_t & pos, int timeout); 0176 void give_back(std::size_t pos); 0177 }; 0178 ``` 0179 0180 The operations of the pool are: 0181 0182 * Constructor that takes the intended size of the pool. After construction, the pool contains regular `session` objects in disconnected state. 0183 * `at` function that provides direct access to any given entryin the pool. This function is *non-synchronized*. 0184 * `lease` function waits until some entry is available (which means that it is not used) and returns the position of that entry in the pool, marking it as *locked*. 0185 * `try_lease` acts like `lease`, but allows to set up a time-out (relative, in milliseconds) on waiting. Negative time-out value means no time-out. Returns `true` if the entry was obtained, in which case its position is written to the `pos` parametr, and `false` if no entry was available before the time-out. 0186 * `give_back` should be called when the entry on the given position is no longer in use and can be passed to other requesting thread. 0187 0188 ## class transaction 0189 0190 The class `transaction` can be used for associating the transaction with some code scope. It is a RAII wrapper for regular transaction operations that automatically rolls back in its destructor *if* the transaction was not explicitly committed before. 0191 0192 ```cpp 0193 class transaction 0194 { 0195 public: 0196 explicit transaction(session & sql); 0197 0198 ~transaction(); 0199 0200 void commit(); 0201 void rollback(); 0202 0203 private: 0204 // ... 0205 }; 0206 ``` 0207 0208 Note that objects of this class are not notified of other transaction related operations that might be executed by user code explicitly or hidden inside SQL queries. It is not recommended to mix different ways of managing transactions. 0209 0210 ## function into 0211 0212 The function `into` is used for binding local output data (in other words, it defines where the results of the query are stored). 0213 0214 ```cpp 0215 template <typename T> 0216 IT into(T & t); 0217 0218 template <typename T, typename T1> 0219 IT into(T & t, T1 p1); 0220 0221 template <typename T> 0222 IT into(T & t, indicator & ind); 0223 0224 template <typename T, typename T1> 0225 IT into(T & t, indicator & ind, T1 p1); 0226 0227 template <typename T> 0228 IT into(T & t, std::vector<indicator> & ind); 0229 ``` 0230 0231 Example: 0232 0233 ```cpp 0234 int count; 0235 sql << "select count(*) from person", into(count); 0236 ``` 0237 0238 See [Binding output data](../binding.md#binding-output-data-into) for more examples 0239 0240 ## function use 0241 0242 The function `use` is used for binding local input data (in other words, it defines where the parameters of the query come from). 0243 0244 ```cpp 0245 template <typename T> 0246 *IT* use(T & t); 0247 0248 template <typename T, typename T1> 0249 *IT* use(T & t, T1 p1); 0250 0251 template <typename T> 0252 *IT* use(T & t, indicator & ind); 0253 0254 template <typename T, typename T1> 0255 *IT* use(T & t, indicator & ind, T1 p1); 0256 0257 template <typename T> 0258 *IT* use(T & t, std::vector<indicator> const & ind); 0259 0260 template <typename T, typename T1> 0261 *IT* use(T & t, std::vector<indicator> const & ind, T1 p1); 0262 ``` 0263 0264 Example: 0265 0266 ```cpp 0267 int val = 7; 0268 sql << "insert into numbers(val) values(:val)", use(val); 0269 ``` 0270 0271 See [Binding input data](../binding.md#binding-input-data-use) for more examples. 0272 0273 ## class statement 0274 0275 The `statement` class encapsulates the prepared statement. 0276 0277 ```cpp 0278 class statement 0279 { 0280 public: 0281 statement(session & s); 0282 statement(*IT* const & prep); 0283 ~statement(); 0284 0285 statement(statement const & other); 0286 void operator=(statement const & other); 0287 0288 void alloc(); 0289 void bind(values & v); 0290 void exchange(*IT* const & i); 0291 void exchange(*IT* const & u); 0292 void clean_up(); 0293 void bind_clean_up(); 0294 0295 void prepare(std::string const & query); 0296 void define_and_bind(); 0297 0298 bool execute(bool withDataExchange = false); 0299 long long get_affected_rows(); 0300 bool fetch(); 0301 0302 bool got_data() const; 0303 0304 void describe(); 0305 void set_row(row * r); 0306 void exchange_for_rowset(*IT* const & i); 0307 0308 details::statement_backend * get_backend(); 0309 }; 0310 ``` 0311 0312 This class contains the following members: 0313 0314 * Constructor accepting the `session` object. This can be used for later query preparation. Example: 0315 0316 ```cpp 0317 statement stmt(sql); 0318 ``` 0319 0320 * Constructor accepting the result of using `prepare` on the `session` object, see example provided above for the `session` class. 0321 * Copy operations. 0322 * `alloc` function, which allocates necessary internal resources. 0323 * `bind` function, which is used to bind the `values` object - this is used in the object-relational mapping and normally called automatically. 0324 * exchange functions for registering the binding of local data - they expect the result of calling the `into` or `use` functions and are normally invoked automatically. 0325 * `clean_up` function for cleaning up resources, normally called automatically. 0326 * `bind_clean_up` function for cleaning up any bound references. It allows to keep statement in cache and reuse it later with new references by calling `exchange` for each new bind variable. 0327 * `prepare` function for preparing the statement for repeated execution. 0328 * `define_and_bind` function for actually executing the registered bindings, normally called automatically. 0329 * `execute` function for executing the statement. If its parameter is `false` then there is no data exchange with locally bound variables (this form should be used if later `fetch` of multiple rows is foreseen). Returns `true` if there was at least one row of data returned. 0330 * `get_affected_rows` function returns the number of rows affected by the last statement. Returns `-1` if it's not implemented by the backend being used. 0331 * `fetch` function for retrieving the next portion of the result. Returns `true` if there was new data. 0332 * `got_data` return `true` if the most recent execution returned any rows. 0333 * `describe` function for extracting the type information for the result (**Note:** no data is exchanged). This is normally called automatically and only when dynamic resultset binding is used. 0334 * `set_row` function for associating the `statement` and `row` objects, normally called automatically. 0335 * `exchange_for_rowset` as a special case for binding `rowset` objects. 0336 * `get_backend` function that returns the internal pointer to the concrete backend implementation of the statement object. This is provided for advanced users that need access to the functionality that is not otherwise available. 0337 0338 See [Statement preparation and repeated execution](../statements.md) for example uses. 0339 0340 Most of the functions from the `statement` class interface are called automatically, but can be also used explicitly. See [Interfaces](../interfaces.md) for the description of various way to use this interface. 0341 0342 ## class procedure 0343 0344 The `procedure` class encapsulates the call to the stored procedure and is aimed for higher portability of the client code. 0345 0346 ```cpp 0347 class procedure 0348 { 0349 public: 0350 procedure(*IT* const & prep); 0351 0352 bool execute(bool withDataExchange = false); 0353 bool fetch(); 0354 bool got_data() const; 0355 }; 0356 ``` 0357 0358 The constructor expects the result of using `prepare` on the `session` object. 0359 0360 See [Stored procedures](../procedures.md) for examples. 0361 0362 ## class type_conversion 0363 0364 The `type_conversion` class is a traits class that is supposed to be provided (specialized) by the user for defining conversions to and from one of the basic SOCI types. 0365 0366 ```cpp 0367 template <typename T> 0368 struct type_conversion 0369 { 0370 typedef T base_type; 0371 0372 static void from_base(base_type const & in, indicator ind, T & out); 0373 0374 static void to_base(T const & in, base_type & out, indicator & ind); 0375 }; 0376 ``` 0377 0378 Users are supposed to properly implement the `from_base` and `to_base` functions in their specializations of this template class. 0379 0380 See [Extending SOCI to support custom (user-defined) C++ types](../types.md#user-defined-c-types). 0381 0382 ## class row 0383 0384 The `row` class encapsulates the data and type information retrieved for the single row when the dynamic rowset binding is used. 0385 0386 ```cpp 0387 class row 0388 { 0389 public: 0390 row(); 0391 ~row(); 0392 0393 void uppercase_column_names(bool forceToUpper); 0394 0395 std::size_t size() const; 0396 0397 indicator get_indicator(std::size_t pos) const; 0398 indicator get_indicator(std::string const & name) const; 0399 0400 column_properties const & get_properties (std::size_t pos) const; 0401 column_properties const & get_properties (std::string const & name) const; 0402 0403 template <typename T> 0404 T get(std::size_t pos) const; 0405 0406 template <typename T> 0407 T get(std::size_t pos, T const & nullValue) const; 0408 0409 template <typename T> 0410 T get(std::string const & name) const; 0411 0412 template <typename T> 0413 T get(std::string const & name, T const & nullValue) const; 0414 0415 template <typename T> 0416 row const & operator>>(T & value) const; 0417 0418 void skip(std::size_t num = 1) const; 0419 0420 void reset_get_counter() const 0421 }; 0422 ``` 0423 0424 This class contains the following members: 0425 0426 * Default constructor that allows to declare a `row` variable. 0427 * `uppercase_column_names` - see the same function in the `session` class. 0428 * `size` function that returns the number of columns in the row. 0429 * `get_indicator` function that returns the indicator value for the given column (column is specified by position - starting from 0 - or by name). 0430 * `get_properties` function that returns the properties of the column given by position (starting from 0) or by name. 0431 * `get` functions that return the value of the column given by position or name. If the column contains null, then these functions either return the provided "default" `nullValue` or throw an exception. 0432 * `operator>>` for convenience stream-like extraction interface. Subsequent calls to this function are equivalent to calling `get` with increasing position parameter, starting from the beginning. 0433 * `skip` and `reset_get_counter` allow to change the order of data extraction for the above operator. 0434 0435 See [Dynamic resultset binding](../types.md#dynamic-binding) for examples. 0436 0437 ## class column_properties 0438 0439 The `column_properties` class provides the type and name information about the particular column in a rowset. 0440 0441 ```cpp 0442 class column_properties 0443 { 0444 public: 0445 std::string get_name() const; 0446 data_type get_data_type() const; 0447 }; 0448 ``` 0449 0450 This class contains the following members: 0451 0452 * `get_name` function that returns the name of the column. 0453 * `get_data_type` that returns the type of the column. 0454 0455 See [Dynamic resultset binding](../types.md#dynamic-binding) for examples. 0456 0457 ## class values 0458 0459 The `values` class encapsulates the data and type information and is used for object-relational mapping. 0460 0461 ```cpp 0462 class values 0463 { 0464 public: 0465 values(); 0466 0467 void uppercase_column_names(bool forceToUpper); 0468 0469 indicator get_indicator(std::size_t pos) const; 0470 indicator get_indicator(std::string const & name) const; 0471 0472 template <typename T> 0473 T get(std::size_t pos) const; 0474 0475 template <typename T> 0476 T get(std::size_t pos, T const & nullValue) const; 0477 0478 template <typename T> 0479 T get(std::string const & name) const; 0480 0481 template <typename T> 0482 T get(std::string const & name, T const & nullValue) const; 0483 0484 template <typename T> 0485 values const & operator>>(T & value) const; 0486 0487 void skip(std::size_t num = 1) const; 0488 void reset_get_counter() const; 0489 0490 template <typename T> 0491 void set(std::string const & name, T const & value, indicator indic = i_ok); 0492 0493 template <typename T> 0494 void set(const T & value, indicator indic = i_ok); 0495 0496 template <typename T> 0497 values & operator<<(T const & value); 0498 }; 0499 ``` 0500 0501 This class contains the same members as the `row` class (with the same meaning) plus: 0502 0503 * `set` function for storing values in named columns or in subsequent positions. 0504 * `operator<<` for convenience. 0505 0506 See [Object-relational mapping](../types.md#object-relational-mapping) for examples. 0507 0508 ## class blob 0509 0510 The `blob` class encapsulates the "large object" functionality. 0511 0512 ```cpp 0513 class blob 0514 { 0515 public: 0516 explicit blob(session & s); 0517 ~blob(); 0518 0519 std::size_t getLen(); 0520 std::size_t read(std::size_t offset, char * buf, std::size_t toRead); 0521 std::size_t write(std::size_t offset, char const * buf, std::size_t toWrite); 0522 std::size_t append(char const * buf, std::size_t toWrite); 0523 void trim(std::size_t newLen); 0524 0525 details::blob_backend * get_backend(); 0526 }; 0527 ``` 0528 0529 This class contains the following members: 0530 0531 * Constructor associating the `blob` object with the `session` object. 0532 * `get_len` function that returns the size of the BLOB object. 0533 * `read` function that reads the BLOB data into provided buffer. 0534 * `write` function that writes the BLOB data from provided buffer. 0535 * `append` function that appends to the existing BLOB data. 0536 * `trim` function that truncates the existing data to the new length. 0537 * `get_backend` function that returns the internal pointer to the concrete backend implementation of the BLOB object. This is provided for advanced users that need access to the functionality that is not otherwise available. 0538 0539 See [Large objects (BLOBs)](../lobs.md) for more discussion. 0540 0541 ## class rowid 0542 0543 The `rowid` class encapsulates the "row identifier" object. 0544 0545 ```cpp 0546 class rowid 0547 { 0548 public: 0549 explicit rowid(Session & s); 0550 ~rowid(); 0551 0552 details::rowid_backend * get_backend(); 0553 }; 0554 ``` 0555 0556 This class contains the following members: 0557 0558 * Constructor associating the `rowid` object with the `session` object. 0559 * `get_backend` function that returns the internal pointer to the concrete backend implementation of the `rowid` object. 0560 0561 ## class backend_factory 0562 0563 The `backend_factory` class provides the abstract interface for concrete backend factories. 0564 0565 ```cpp 0566 struct backend_factory 0567 { 0568 virtual details::session_backend * make_session( 0569 std::string const & connectString) const = 0; 0570 }; 0571 ``` 0572 0573 The only member of this class is the `make_session` function that is supposed to create concrete backend implementation of the session object. 0574 0575 Objects of this type are declared by each backend and should be provided to the constructor of the `session` class. In simple programs users do not need to use this class directly, but the example use is: 0576 0577 ```cpp 0578 backend_factory & factory = postgresql; 0579 std::string connectionParameters = "dbname=mydb"; 0580 0581 session sql(factory, parameters); 0582 ``` 0583 0584 ## Simple Client Interface 0585 0586 The simple client interface is provided with other languages in mind, to allow easy integration of the SOCI library with script interpreters and those languages that have the ability to link directly with object files using the "C" calling convention. 0587 0588 The functionality of this interface is limited and in particular the dynamic rowset description and type conversions are not supported in this release. On the other hand, the important feature of this interface is that it does not require passing pointers to data managed by the user, because all data is handled at the SOCI side. This should make it easier to integrate SOCI with languages that have constrained ability to understand the C type system. 0589 0590 Users of this interface need to explicitly `#include <soci-simple.h>`. 0591 0592 ```c 0593 typedef void * session_handle; 0594 session_handle soci_create_session(char const * connectionString); 0595 void soci_destroy_session(session_handle s); 0596 0597 void soci_begin(session_handle s); 0598 void soci_commit(session_handle s); 0599 void soci_rollback(session_handle s); 0600 0601 int soci_session_state(session_handle s); 0602 char const * soci_session_error_message(session_handle s); 0603 ``` 0604 0605 The functions above provide the *session* abstraction with the help of opaque handle. The `soci_session_state` function returns `1` if there was no error during the most recently executed function and `0` otherwise, in which case the `soci_session_error_message` can be used to obtain a human-readable error description. 0606 0607 Note that the only function that cannot report all errors this way is `soci_create_session`, which returns `NULL` if it was not possible to create an internal object representing the session. However, if the proxy object was created, but the connection could not be established for whatever reason, the error message can be obtained in the regular way. 0608 0609 ```c 0610 typedef void *blob_handle; 0611 blob_handle soci_create_blob(session_handle s); 0612 void soci_destroy_blob(blob_handle b); 0613 0614 int soci_blob_get_len(blob_handle b); 0615 int soci_blob_read(blob_handle b, int offset, char *buf, int toRead); 0616 int soci_blob_write(blob_handle b, int offset, char const *buf, int toWrite); 0617 int soci_blob_append(blob_handle b, char const *buf, int toWrite); 0618 int soci_blob_trim(blob_handle b, int newLen); 0619 0620 int soci_blob_state(blob_handle b); 0621 char const * soci_blob_error_message(blob_handle b); 0622 ``` 0623 0624 The functions above provide the *blob* abstraction with the help of opaque handle. The `soci_blob_state` function returns `1` if there was no error during the most recently executed function and `0` otherwise, in which case the `soci_session_error_message` can be used to obtain a human-readable error description. 0625 0626 For easy error testing, functions `soci_blob_read`, `soci_blob_write`, `soci_blob_append`, and `soci_blob_trim` return `-1` in case of error and `soci_session_error_message` can be used to obtain a human-readable error description. 0627 0628 Note that the only function that cannot report all errors this way is `soci_create_blob`, which returns `NULL` if it was not possible to create an internal object representing the blob. 0629 0630 ```c 0631 typedef void * statement_handle; 0632 statement_handle soci_create_statement(session_handle s); 0633 void soci_destroy_statement(statement_handle st); 0634 0635 int soci_statement_state(statement_handle s); 0636 char const * soci_statement_error_message(statement_handle s); 0637 ``` 0638 0639 The functions above create and destroy the statement object. If the statement cannot be created by the `soci_create_statement` function, the error condition is set up in the related session object; for all other functions the error condition is set in the statement object itself. 0640 0641 ```c 0642 int soci_into_string (statement_handle st); 0643 int soci_into_int (statement_handle st); 0644 int soci_into_long_long(statement_handle st); 0645 int soci_into_double (statement_handle st); 0646 int soci_into_date (statement_handle st); 0647 int soci_into_blob (statement_handle st); 0648 0649 int soci_into_string_v (statement_handle st); 0650 int soci_into_int_v (statement_handle st); 0651 int soci_into_long_long_v(statement_handle st); 0652 int soci_into_double_v (statement_handle st); 0653 int soci_into_date_v (statement_handle st); 0654 ``` 0655 0656 These functions create new data items for storing query results (*into elements*). These elements can be later identified by their position, which is counted from 0. For convenience, these function return the position of the currently added element. In case of error, `-1` is returned and the error condition is set in the statement object. 0657 0658 The `_v` versions create a `vector` into elements, which can be used 0659 to retrieve whole arrays of results. 0660 0661 ```c 0662 int soci_get_into_state(statement_handle st, int position); 0663 int soci_get_into_state_v(statement_handle st, int position, int index); 0664 ``` 0665 0666 This function returns `1` if the into element at the given position has non-null value and `0` otherwise. The `_v` version works with `vector` elements and expects an array index. 0667 0668 ```c 0669 char const * soci_get_into_string (statement_handle st, int position); 0670 int soci_get_into_int (statement_handle st, int position); 0671 long long soci_get_into_long_long(statement_handle st, int position); 0672 double soci_get_into_double (statement_handle st, int position); 0673 char const * soci_get_into_date (statement_handle st, int position); 0674 blob_handle soci_get_into_blob (statement_handle st, int position); 0675 0676 char const * soci_get_into_string_v (statement_handle st, int position, int index); 0677 int soci_get_into_int_v (statement_handle st, int position, int index); 0678 long long soci_get_into_long_long_v(statement_handle st, int position, int index); 0679 double soci_get_into_double_v (statement_handle st, int position, int index); 0680 char const * soci_get_into_date_v (statement_handle st, int position, int index); 0681 ``` 0682 0683 The functions above allow to retrieve the current value of the given into element. 0684 0685 **Note:** The `date` function returns the date value in the "`YYYY MM DD HH mm ss`" string format. 0686 0687 ```c 0688 void soci_use_string (statement_handle st, char const * name); 0689 void soci_use_int (statement_handle st, char const * name); 0690 void soci_use_long_long(statement_handle st, char const * name); 0691 void soci_use_double (statement_handle st, char const * name); 0692 void soci_use_date (statement_handle st, char const * name); 0693 void soci_use_blob (statement_handle st, char const * name); 0694 0695 void soci_use_string_v (statement_handle st, char const * name); 0696 void soci_use_int_v (statement_handle st, char const * name); 0697 void soci_use_long_long_v(statement_handle st, char const * name); 0698 void soci_use_double_v (statement_handle st, char const * name); 0699 void soci_use_date_v (statement_handle st, char const * name); 0700 ``` 0701 0702 The functions above allow to create new data elements that will be used to provide data to the query (*use elements*). The new elements can be later identified by given name, which must be unique for the given statement. 0703 0704 ```c 0705 void soci_set_use_state(statement_handle st, char const * name, int state); 0706 ``` 0707 0708 The `soci_set_use_state` function allows to set the state of the given use element. If the `state` parameter is set to non-zero the use element is considered non-null (which is also the default state after creating the use element). 0709 0710 ```c 0711 int soci_use_get_size_v(statement_handle st); 0712 void soci_use_resize_v (statement_handle st, int new_size); 0713 ``` 0714 0715 These functions get and set the size of vector use elements (see comments for vector into elements above). 0716 0717 ```c 0718 void soci_set_use_string (statement_handle st, char const * name, char const * val); 0719 void soci_set_use_int (statement_handle st, char const * name, int val); 0720 void soci_set_use_long_long(statement_handle st, char const * name, long long val); 0721 void soci_set_use_double (statement_handle st, char const * name, double val); 0722 void soci_set_use_date (statement_handle st, char const * name, char const * val); 0723 void soci_set_use_blob (statement_handle st, char const * name, blob_handle blob); 0724 0725 void soci_set_use_state_v (statement_handle st, char const * name, int index, int state); 0726 void soci_set_use_string_v (statement_handle st, char const * name, int index, char const * val); 0727 void soci_set_use_int_v (statement_handle st, char const * name, int index, int val); 0728 void soci_set_use_long_long_v(statement_handle st, char const * name, int index, long long val); 0729 void soci_set_use_double_v (statement_handle st, char const * name, int index, double val); 0730 void soci_set_use_date_v (statement_handle st, char const * name, int index, char const * val); 0731 ``` 0732 0733 The functions above set the value of the given use element, for both single and vector elements. 0734 0735 **Note:** The expected format for the data values is "`YYYY MM DD HH mm ss`". 0736 0737 ```c 0738 int soci_get_use_state (statement_handle st, char const * name); 0739 char const * soci_get_use_string (statement_handle st, char const * name); 0740 int soci_get_use_int (statement_handle st, char const * name); 0741 long long soci_get_use_long_long(statement_handle st, char const * name); 0742 double soci_get_use_double (statement_handle st, char const * name); 0743 char const * soci_get_use_date (statement_handle st, char const * name); 0744 blob_handle soci_get_use_blob (statement_handle st, char const * name); 0745 ``` 0746 0747 These functions allow to inspect the state and value of named use elements. 0748 0749 ***Note:*** these functions are provide only for single use elements, not for vectors; the rationale for this is that modifiable use elements are not supported for bulk operations. 0750 0751 ```c 0752 void soci_prepare(statement_handle st, char const * query); 0753 int soci_execute(statement_handle st, int withDataExchange); 0754 int soci_fetch(statement_handle st); 0755 int soci_got_data(statement_handle st); 0756 ``` 0757 0758 The functions above provide the core execution functionality for the statement object and their meaning is equivalent to the respective functions in the core C++ interface described above.