Warning, /sdk/codevis/thirdparty/soci/docs/backends/sqlite3.md is written in an unsupported language. File is not indexed.
0001 # SQLite3 Backend Reference 0002 0003 SOCI backend for accessing SQLite 3 database. 0004 0005 ## Prerequisites 0006 0007 ### Supported Versions 0008 0009 The SOCI SQLite3 backend is supported for use with SQLite3 >= 3.1 0010 0011 ### Tested Platforms 0012 0013 |SQLite3|OS|Compiler| 0014 |--- |--- |--- | 0015 |3.12.1|Windows Server 2016|MSVC++ 14.1| 0016 |3.12.1|Windows Server 2012 R2|MSVC++ 14.0| 0017 |3.12.1|Windows Server 2012 R2|MSVC++ 12.0| 0018 |3.12.1|Windows Server 2012 R2|MSVC++ 11.0| 0019 |3.12.1|Windows Server 2012 R2|Mingw-w64/GCC 4.8| 0020 |3.7.9|Ubuntu 12.04|g++ 4.6.3| 0021 |3.4.0|Windows XP|(cygwin) g++ 3.4.4| 0022 |3.4.0|Windows XP|Visual C++ 2005 Express Edition| 0023 |3.3.8|Windows XP|Visual C++ 2005 Professional| 0024 |3.5.2|Mac OS X 10.5|g++ 4.0.1| 0025 |3.3.4|Ubuntu 5.1|g++ 4.0.2| 0026 |3.3.4|Windows XP|(cygwin) g++ 3.3.4| 0027 |3.3.4|Windows XP|Visual C++ 2005 Express Edition| 0028 |3.2.1|Linux i686 2.6.10-gentoo-r6|g++ 3.4.5| 0029 |3.1.3|Mac OS X 10.4|g++ 4.0.1| 0030 |3.24.0|macOS High Sierra 10.13.5|AppleClang 9.1.0.9020039| 0031 0032 ### Required Client Libraries 0033 0034 The SOCI SQLite3 backend requires SQLite3's `libsqlite3` client library. 0035 0036 ### Connecting to the Database 0037 0038 To establish a connection to the SQLite3 database, create a Session object using the `SQLite3` backend factory together with the database file name: 0039 0040 ```cpp 0041 session sql(sqlite3, "database_filename"); 0042 0043 // or: 0044 0045 session sql("sqlite3", "db=db.sqlite timeout=2 shared_cache=true"); 0046 ``` 0047 0048 The set of parameters used in the connection string for SQLite is: 0049 0050 * `dbname` or `db` 0051 * `timeout` - set sqlite busy timeout (in seconds) ([link](http://www.sqlite.org/c3ref/busy_timeout.html)) 0052 * `readonly` - open database in read-only mode instead of the default read-write (note that the database file must already exist in this case, see [the documentation](https://www.sqlite.org/c3ref/open.html)) 0053 * `nocreate` - open an existing database without creating a new one if it doesn't already exist (by default, a new database file is created). 0054 * `synchronous` - set the pragma synchronous flag ([link](http://www.sqlite.org/pragma.html#pragma_synchronous)) 0055 * `shared_cache` - should be `true` ([link](http://www.sqlite.org/c3ref/enable_shared_cache.html)) 0056 * `vfs` - set the SQLite VFS used to as OS interface. The VFS should be registered before opening the connection, see [the documenation](https://www.sqlite.org/vfs.html) 0057 * `foreign_keys` - set the pragma foreign_keys flag ([link](https://www.sqlite.org/pragma.html#pragma_foreign_keys)). 0058 0059 Once you have created a `session` object as shown above, you can use it to access the database, for example: 0060 0061 ```cpp 0062 int count; 0063 sql << "select count(*) from invoices", into(count); 0064 ``` 0065 0066 (See the [connection](../connections.md) and [data binding](../binding.md) documentation for general information on using the `session` class.) 0067 0068 ## SOCI Feature Support 0069 0070 ### Dynamic Binding 0071 0072 The SQLite3 backend supports the use of the SOCI `row` class, which facilitates retrieval of data whose type is not known at compile time. 0073 0074 When calling `row::get<T>()`, the type you should pass as T depends upon the underlying database type. 0075 0076 For the SQLite3 backend, this type mapping is complicated by the fact the SQLite3 does not enforce [types][INTEGER_PRIMARY_KEY] and makes no attempt to validate the type names used in table creation or alteration statements. SQLite3 will return the type as a string, SOCI will recognize the following strings and match them the corresponding SOCI types: 0077 0078 |SQLite3 Data Type|SOCI Data Type|`row::get<T>` specializations| 0079 |--- |--- |--- | 0080 |*float*, *double*|dt_double|double| 0081 |*int8*, *bigint*|dt_long_long|long long| 0082 |*unsigned big int*|dt_unsigned_long_long|unsigned long long| 0083 |*int*, *boolean*|dt_integer|int| 0084 |*text, *char*|dt_string|std::string| 0085 |*date*, *time*|dt_date|std::tm| 0086 0087 [INTEGER_PRIMARY_KEY] : There is one case where SQLite3 enforces type. If a column is declared as "integer primary key", then SQLite3 uses that as an alias to the internal ROWID column that exists for every table. Only integers are allowed in this column. 0088 0089 (See the [dynamic resultset binding](../types.md#dynamic-binding) documentation for general information on using the `row` class.) 0090 0091 ### Binding by Name 0092 0093 In addition to [binding by position](../binding.md#binding-by-position), the SQLite3 backend supports [binding by name](../binding.md#binding-by-name), via an overload of the `use()` function: 0094 0095 ```cpp 0096 int id = 7; 0097 sql << "select name from person where id = :id", use(id, "id") 0098 ``` 0099 0100 The backend also supports the SQLite3 native numbered syntax, "one or more literals can be replace by a parameter "?" or ":AAA" or "@AAA" or "$VVV" where AAA is an alphanumeric identifier and VVV is a variable name according to the syntax rules of the TCL programming language." [[1]](http://www.sqlite.org/capi3ref.html#sqlite3_bind_int): 0101 0102 ```cpp 0103 int i = 7; 0104 int j = 8; 0105 sql << "insert into t(x, y) values(?, ?)", use(i), use(j); 0106 ``` 0107 0108 ### Bulk Operations 0109 0110 The SQLite3 backend has full support for SOCI's [bulk operations](../binding.md#bulk-operations) interface. However, this support is emulated and is not native. 0111 0112 ### Transactions 0113 0114 [Transactions](../transactions.md) are also fully supported by the SQLite3 backend. 0115 0116 ### BLOB Data Type 0117 0118 The SQLite3 backend supports working with data stored in columns of type Blob, via SOCI's [BLOB](../lobs.md) class. Because of SQLite3 general typelessness the column does not have to be declared any particular type. 0119 0120 ### RowID Data Type 0121 0122 In SQLite3 RowID is an integer. "Each entry in an SQLite table has a unique integer key called the "rowid". The rowid is always available as an undeclared column named ROWID, OID, or _ROWID_. If the table has a column of type INTEGER PRIMARY KEY then that column is another an alias for the rowid."[[2]](http://www.sqlite.org/capi3ref.html#sqlite3_last_insert_rowid) 0123 0124 ### Nested Statements 0125 0126 Nested statements are not supported by SQLite3 backend. 0127 0128 ### Stored Procedures 0129 0130 Stored procedures are not supported by SQLite3 backend 0131 0132 ## Native API Access 0133 0134 SOCI provides access to underlying datbabase APIs via several `get_backend()` functions, as described in the [beyond SOCI](../beyond.md) documentation. 0135 0136 The SQLite3 backend provides the following concrete classes for navite API access: 0137 0138 |Accessor Function|Concrete Class| 0139 |--- |--- | 0140 |session_backend* session::get_backend()|sqlie3_session_backend| 0141 |statement_backend* statement::get_backend()|sqlite3_statement_backend| 0142 |rowid_backend* rowid::get_backend()|sqlite3_rowid_backend| 0143 0144 ## Backend-specific extensions 0145 0146 ### SQLite3 result code support 0147 0148 SQLite3 result code is provided via the backend specific `sqlite3_soci_error` class. Catching the backend specific error yields the value of SQLite3 result code via the `result()` method. 0149 0150 ## Configuration options 0151 0152 None