├── test.cpp ├── README.md ├── sqlitepp.h └── thirdparty └── sqlite3ext.h /test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mpaland/sqlitepp/HEAD/test.cpp -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sqlitepp 2 | sqlitepp is a C++ and STL orientated single header wrapper around the fantastic SQLite3 library. 3 | It simplyfies the C API by using BLOBs as vectors and TEXT as strings and makes accessing result objects easy. 4 | To provide a single versioned library the SQLite3 is included in the SQLite3 folder and updated when necessary. 5 | 6 | Design goals: 7 | - very easy to use, just a single header 8 | - LINT and compiler L4 warning free, clean code 9 | - usage of C++ and STL (vector, string) 10 | - MIT license 11 | 12 | 13 | ## Usage 14 | Here are some examples how to use sqlitepp: 15 | 16 | Create and open the database by its filename: 17 | ```c++ 18 | sqlitepp::db db("D:/test.sqlite"); 19 | assert(db.is_open()); 20 | ``` 21 | The following code assumes the `db` object created above. 22 | 23 | Create a query and set the command in the ctor: 24 | ```c++ 25 | sqlitepp::query q(db, "DROP TABLE test;"); 26 | int err = q.exec(); 27 | ``` 28 | 29 | Create a query and set the command in exec: 30 | ```c++ 31 | sqlitepp::query q(db, "THIS QUERY IS DISCARDED"); 32 | int err = q.exec("CREATE TABLE test (id INTEGER PRIMARY KEY NOT NULL, num INTEGER, name VARCHAR(20), flo FLOAT, data BLOB, comment TEXT);"); 33 | ``` 34 | 35 | Insert a BLOB via explicit binding: 36 | ```c++ 37 | std::vector blob(30U); 38 | sqlitepp::query q(db); 39 | q.bind(1, blob); 40 | int err = q.exec("INSERT INTO test (data) VALUES (?1)"); 41 | int id = q.insert_id(); 42 | ``` 43 | 44 | Insert a TEXT using the alpha (@) index, build the query via the `<<` operator: 45 | ```c++ 46 | std::string text("Test"); 47 | sqlitepp::query q(db); 48 | q << "INSERT INTO test (comment) VALUES (@com)"; 49 | q.bind("@com", text); // bind the TEXT 50 | int err = q.exec(); 51 | ``` 52 | 53 | Bind multiple values via auto index (?): 54 | ```c++ 55 | sqlitepp::query q(db); 56 | q << "INSERT INTO test(name, data, comment) VALUES ('Test',?,?)"; 57 | std::vector v(10U, 0x55U); 58 | std::string t("A test text"); 59 | q.bind(1, v); 60 | q.bind(2, t); 61 | int err = q.exec(); 62 | ``` 63 | 64 | Insert discret values via the `<<` operator: 65 | ```c++ 66 | sqlitepp::query q(db); 67 | q << "INSERT INTO test (num, flo) VALUES(" << 1000 << "," << 3.1415F << ")"; 68 | int err = q.exec(); 69 | ``` 70 | 71 | All text and string values need to be in UTF-8 format in SQLite3. 72 | Storing a string in UTF-8 - here on a Windows platform - with ATL conversion: 73 | ```c++ 74 | sqlitepp::query q(db); 75 | q << "INSERT INTO test(id, name) VALUES (13,'" << ATL::CT2CA(L"Schöne Grüße", CP_UTF8) << "')"; 76 | int err = q.exec(); 77 | ``` 78 | 79 | Assembling a query out of different fragments via the `<<` operator: 80 | ```c++ 81 | sqlitepp::query q(db); 82 | q << "UPDATE test SET num="; 83 | q << 10; 84 | q << " WHERE id=2"; 85 | int err = q.exec(); 86 | ``` 87 | 88 | Sometime after excessive delete and insert operations, it's useful to defragment/compact the database, which is done by the `vacuum()` command. 89 | ```c++ 90 | // database defragmentation (e.g. after exessive deletes etc.) 91 | int err = db.vacuum(); 92 | ``` 93 | 94 | Get a complete result set: 95 | ```c++ 96 | sqlitepp::query q(db, "SELECT * FROM test"); 97 | sqlitepp::result res = q.store(); 98 | ``` 99 | Access single fields of the result set: 100 | ```c++ 101 | std::vector blob; 102 | std::string text; 103 | int a = res[1]["num"]; // get data of num of row 1 104 | double d = res[0]["flo"]; // get data of flo of row 0 105 | bool null = res[0]["num"].is_null(); // test if field num of row 0 is NULL 106 | blob = res[0][4]; // get blob data of row 0 107 | text = res[2]["comment"]; // get text as string 108 | ``` 109 | 110 | Show all results which are not NULL: 111 | ```c++ 112 | for (sqlitepp::result::size_type r = 0; r < res.num_rows(); ++r) { 113 | for (sqlitepp::row::size_type c = 0; c < res[r].num_fields(); ++c) { 114 | if (!res[r][c].is_null()) { 115 | std::cout << res[r][c].str() << " |"; 116 | } 117 | } 118 | std::cout << std::endl; 119 | } 120 | ``` 121 | 122 | Show all results, but access the result row by row. 123 | This can be used if the result set is too big to be loaded entirely at once: 124 | ```c++ 125 | sqlitepp::query q(db, "SELECT * FROM test"); 126 | sqlitepp::row _row = q.use(); 127 | while (!_row.empty()) { 128 | for (sqlitepp::row::size_type c = 0; c < _row.num_fields(); ++c) { 129 | if (!_row[c].is_null()) { 130 | std::cout << _row[c].str() << " |"; 131 | } 132 | } 133 | std::cout << std::endl; 134 | // get next row 135 | _row = q.use_next(); 136 | } 137 | ``` 138 | 139 | Access the result row by row, but abort after the first row. You **MUST** call `use_abort()`. 140 | This can be used if the result set is too big to be loaded entirely at once. 141 | ```c++ 142 | sqlitepp::query q(db, "SELECT * FROM test"); 143 | sqlitepp::row _row = q.use(); 144 | while (!_row.empty()) { 145 | for (sqlitepp::row::size_type c = 0; c < _row.num_fields(); ++c) { 146 | if (!_row[c].is_null()) { 147 | std::cout << _row[c].str() << " |"; 148 | } 149 | } 150 | std::cout << std::endl; 151 | // abort here 152 | q.use_abort(); 153 | break; 154 | } 155 | ``` 156 | 157 | Evaluate the first row only: 158 | ```c++ 159 | sqlitepp::query q(db, "SELECT * FROM test"); 160 | sqlitepp::row _row = q.use(); 161 | (void)q.use_abort(); // this is important - don't forget! 162 | ``` 163 | 164 | Start a transaction, `begin()` is called by the ctor: 165 | ```c++ 166 | sqlitepp::transaction tr(db); 167 | q.exec("INSERT INTO test(name) VALUES ('Marco')"); 168 | // commit 169 | tr.commit(); 170 | ``` 171 | 172 | Rolling back: 173 | ```c++ 174 | tr.begin(); // begin a new transaction 175 | q.exec("INSERT INTO test(name) VALUES ('I'm not stored')"); 176 | // rollback 177 | tr.rollback(); 178 | ``` 179 | 180 | Auto rollback when the transaction goes out scope: 181 | ```c++ 182 | { 183 | sqlitepp::transaction tr(db); // implicit begin 184 | q.exec("INSERT INTO test(name) VALUES ('I'm not stored')"); 185 | // implicit rollback when tr goes out of scope here 186 | } 187 | ``` 188 | 189 | 190 | ## Classes 191 | 192 | ### field_type 193 | This class represents a singe result field (column field of a row). 194 | 195 | SQLite has 5 data types: 196 | 197 | | SQLite3 type | sqlitepp type | 198 | |--------------|---------------| 199 | | INTEGER | `std::int64_t` | 200 | | FLOAT | `double` | 201 | | TEXT | `std::string` | 202 | | BLOB | `std::vector` | 203 | | NULL | internally handled, checked by `is_null()` | 204 | 205 | Use these sqlitepp types when accessing result fields. 206 | There is an automatic type conversion/cast: 207 | ```c++ 208 | int i = row["num"]; // get data of num field (INTEGER) as integer 209 | std::string s = row["num"]; // get data of num field (INTEGER) as string 210 | double d = row["flo"]; // get data of flo field (FLOAT) as double 211 | // CAUTION: 212 | int f = row["flo"]; // ERROR: integer result flo field (FLOAT) is not defined/set! 213 | ``` 214 | 215 | Methods of `field_type` are: 216 | 217 | `name()` 218 | Returns the name of the field column. 219 | 220 | `type()` 221 | Returns the field type as sqlite3 type definition (SQLITE_INTEGER, SQLITE_TEXT etc.) 222 | 223 | `is_null()` 224 | Returns true if the field is NULL. 225 | 226 | 227 | ### row 228 | This class represents a single result row. 229 | Fields can be accessed via the `[]` operator by their numeric column index or by their column name. 230 | Access by name is slower, because of the name lookup. 231 | All std::vector operations are valid, because `row` is a std::vector of `field_type`. 232 | 233 | Methods of `row` are: 234 | 235 | `operator[](size_type idx)` 236 | Access the field by its index position in the row. 237 | 238 | `operator[](const char* colname)` 239 | Access the field by its column name. 240 | 241 | `num_fields()` 242 | Returns the field count of the row. (A wrapper for size()) 243 | 244 | 245 | ### result 246 | This class is a std::vector of `row`. It represents a complete result set. 247 | 248 | Methods of `result` are: 249 | 250 | `num_rows()` 251 | Returns the number of rows of the result. (A wrapper for size()) 252 | 253 | 254 | ### db 255 | Main class that holds the sqlite3 object, which can be accessed via `get()` or, even shorter, via the `()` operator. 256 | 257 | Methods of `db` are: 258 | 259 | `db(name, initial_open = true, flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)` 260 | Ctor which creates and optionally opens the database. 261 | 262 | `open(flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)` 263 | Opens the database with the apropriate access flags. 264 | 265 | `close()` 266 | Closes the db. The db is automatically closed when db goes out of scope. 267 | 268 | `version()` 269 | Returns the version of the SQLite3 database as string. 270 | 271 | `vacuum()` 272 | Executes the SQLite VACUUM command for database defragmentation. 273 | 274 | 275 | ### query 276 | Class for query assembly and execution. 277 | The `<<` operator can add query parts or bind BLOB and TEXT data. 278 | 279 | `exec()` 280 | Executes the query and returns only the execution status. This can be used for commands like UPDATE or DELETE. 281 | 282 | `use()` 283 | Executes the query and returns the first row of the result set. This can be uses if only one row is needed or to get the result set row by row. 284 | Repeatly call `use_next()` until `use_next()` returns an empty row or call `use_abort()` before. 285 | 286 | `use_next()` 287 | Returns the next row of the `use()` function. 288 | An empty row is returned if no further rows exist. 289 | 290 | `use_abort()` 291 | Aborts `use()`/`use_next()` sequence before `use_next()` finished (returned an empty row). 292 | This is a **MANDATORY** call if `use()`/`use_next()` need to be aborted. 293 | 294 | `store()` 295 | Executes the query and returns the complete result as result object. 296 | 297 | `bind()` 298 | Binds the given vector or string to the according params. 299 | CAUTION: The vector or string must be constant until end of query execution! 300 | The vector/string is internally not copied! 301 | 302 | 303 | ### transaction 304 | The `transaction` class simplifies begin, commit and rollback of transactions. 305 | `begin()` is called by class ctor, so an explicit `begin()` isn't necessary. 306 | 307 | Methods are: 308 | 309 | `begin()` 310 | Begin the transaction with the according level flags. Default is deferred. 311 | 312 | `commit()` 313 | Commit the transaction. 314 | 315 | `rollback()` 316 | Rollback the transaction. Rollback is called by the dtor when transaction object goes out of scope. 317 | 318 | 319 | ## License 320 | sqlitepp is **MIT** 321 | SQLite3 is **public domain** 322 | -------------------------------------------------------------------------------- /sqlitepp.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | /// \author (c) Marco Paland (marco@paland.com) 3 | /// 2014, PALANDesign Hannover, Germany 4 | /// 5 | /// \license The MIT License (MIT) 6 | /// Permission is hereby granted, free of charge, to any person obtaining a copy 7 | /// of this software and associated documentation files (the "Software"), to deal 8 | /// in the Software without restriction, including without limitation the rights 9 | /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | /// copies of the Software, and to permit persons to whom the Software is 11 | /// furnished to do so, subject to the following conditions: 12 | /// 13 | /// The above copyright notice and this permission notice shall be included in 14 | /// all copies or substantial portions of the Software. 15 | /// 16 | /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | /// THE SOFTWARE. 23 | /// 24 | /// 25 | /// \brief sqlitepp classes 26 | /// sqlitepp is a single header C++ wrapper for the SQLite3 db 27 | /// 28 | /// \changelog 29 | /// 1.6.1 Changed license to MIT 30 | /// 31 | /// 1.6.0 Removed str() function, it's implicit now via conversion operator 32 | /// 33 | /// 1.5.0 Added 'invalid' type (-1) for field_type 34 | /// row [""] operator can return invalid ref as invalid field_type now 35 | /// 36 | /// 1.4.1 Fixed support for binding empty vectors and strings 37 | /// 38 | /// 1.4.0 Added query operator<< for TEXT 39 | /// 40 | /// 1.3.0 Added 'vacuum' function for db defragmentation 41 | /// Minor bugfixes 42 | /// 43 | /// 1.2.1 Minor cleanups and fixes 44 | /// 45 | /// 1.2.0 Added 'str' function on field_type to stringify fields 46 | /// Added 'use_abort' function 47 | /// 48 | /// 1.1.0 First inital release 49 | /// Added some enhancements for field_type access 50 | /// 51 | /// 1.0.0 All ideas coded, first tests okay 52 | /// 53 | /////////////////////////////////////////////////////////////////////////////// 54 | 55 | #ifndef _SQLITEPP_H_ 56 | #define _SQLITEPP_H_ 57 | 58 | #define SQLITEPP_VERSION "1.6.1" // X.Y.Z 59 | #define SQLITEPP_VERSION_NUMBER 1006001 // X*1000000 + Y*1000 + Z 60 | 61 | #include "thirdparty/sqlite3.h" 62 | 63 | #include 64 | #include 65 | #include 66 | #include 67 | 68 | 69 | namespace sqlitepp { 70 | 71 | /* 72 | * Representation of a single result field 73 | */ 74 | struct field_type 75 | { 76 | // ctors 77 | field_type() 78 | : type_(-1) { } 79 | field_type(std::string const& name) 80 | : name_(name), type_(SQLITE_NULL) { int_ = 0; } 81 | field_type(int i, std::string const& name) 82 | : name_(name), type_(SQLITE_INTEGER) { int_ = i; } 83 | field_type(::sqlite3_int64 i64, std::string const& name) 84 | : name_(name), type_(SQLITE_INTEGER) { int_ = i64; } 85 | field_type(double d, std::string const& name) 86 | : name_(name), type_(SQLITE_FLOAT) { float_ = d; } 87 | field_type(std::string s, std::string const& name) 88 | : name_(name), type_(SQLITE_TEXT) { str_ = s; } 89 | field_type(std::vector v, std::string const& name) 90 | : name_(name), type_(SQLITE_BLOB) { vec_ = v; } 91 | 92 | // access field value 93 | operator int() const { return static_cast(int_); } 94 | operator ::sqlite_int64() const { return int_; } 95 | operator double() const { return float_; } 96 | operator std::string() const { 97 | switch (type_) { 98 | case SQLITE_TEXT : return str_; 99 | case SQLITE_INTEGER : { std::stringstream s; s << int_; return s.str(); } 100 | case SQLITE_FLOAT : { std::stringstream s; s << float_; return s.str(); } 101 | case SQLITE_BLOB : return "BLOB"; 102 | case SQLITE_NULL : return "NULL"; 103 | case -1 : return "invalid"; 104 | default : return ""; 105 | } 106 | } 107 | operator std::vector() const { return vec_; } 108 | 109 | // get field (column) name 110 | inline std::string name() const { return name_; } 111 | 112 | // get field (column) type 113 | inline int type() const { return type_; } 114 | 115 | // returns true if field is NULL 116 | inline bool is_null() const { return type_ == SQLITE_NULL; } 117 | 118 | private: 119 | std::int64_t int_; // int data 120 | double float_; // float data 121 | std::vector vec_; // vector (blob) data 122 | std::string str_; // string (text) data 123 | std::string name_; // field (col) name 124 | int type_; // sqlte type 125 | }; 126 | 127 | 128 | /* 129 | * Representation of a result row 130 | */ 131 | class row : public std::vector 132 | { 133 | public: 134 | // access field by index 135 | const_reference operator[](size_type idx) const { 136 | return at(idx); 137 | } 138 | 139 | // access field by name 140 | const_reference operator[](const char* colname) const { 141 | const static field_type invalid_ref; 142 | for (row::const_iterator it = begin(); it != end(); ++it) { 143 | if (it->name() == colname) { 144 | return *it; 145 | } 146 | } 147 | return invalid_ref; // no match - invalid answer 148 | } 149 | 150 | // return the number of fields in this row 151 | size_type num_fields() const { return size(); } 152 | }; 153 | 154 | 155 | /* 156 | * Representation of a complete result set (all columns and rows) 157 | */ 158 | class result : public std::vector 159 | { 160 | public: 161 | // default ctor 162 | result() { }; 163 | 164 | // destroy result set 165 | ~result() { } 166 | 167 | // return the number of rows in this result set 168 | size_type num_rows() const { return size(); } 169 | }; 170 | 171 | 172 | /* 173 | * Database class 174 | */ 175 | class db 176 | { 177 | public: 178 | db(std::string name, bool initial_open = true, int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE) 179 | : name_(name) 180 | , open_(false) 181 | , db_(nullptr) 182 | { 183 | if (initial_open) { 184 | // inital connect 185 | (void)open(flags); 186 | } 187 | } 188 | 189 | ~db() 190 | { 191 | // close the db 192 | (void)close(); 193 | } 194 | 195 | // open (connect) the database 196 | int open(int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE) 197 | { 198 | int err = ::sqlite3_open_v2(name_.c_str(), &db_, flags, nullptr); 199 | open_ = !err; 200 | return err; 201 | } 202 | 203 | // close the database 204 | int close() 205 | { 206 | int err = ::sqlite3_close_v2(db_); 207 | open_ = false; 208 | db_ = nullptr; 209 | return err; 210 | } 211 | 212 | // returns true if the database is open 213 | inline bool is_open() const { return open_; } 214 | 215 | // SQLite3 access 216 | inline ::sqlite3* get() const { return db_; } 217 | inline ::sqlite3* operator()() const { return db_; } 218 | 219 | // SQLite version 220 | inline std::string version() { return std::string(SQLITE_VERSION); } 221 | 222 | // database defragmentation 223 | int vacuum() 224 | { 225 | return ::sqlite3_exec(db_, "VACUUM;", nullptr, nullptr, nullptr); 226 | } 227 | 228 | private: 229 | db& operator=(const db&) { } // no assignment 230 | 231 | private: 232 | ::sqlite3* db_; // associated db 233 | const std::string name_; // db filename 234 | bool open_; // db open status 235 | }; 236 | 237 | 238 | /* 239 | * Representation of a query 240 | */ 241 | class query 242 | { 243 | public: 244 | query(const db& db, const std::string& query = "") 245 | : db_(db) 246 | , query_(query) { } 247 | 248 | ~query() { } 249 | 250 | // << operator for query assembly 251 | // CAUTION: Be aware of SQL injection when directly passing user input in the query. Better use explicit binding. 252 | template 253 | inline query& operator<< (const T& value) 254 | { 255 | query_ << value; 256 | return *this; 257 | } 258 | 259 | // specialized << operator to bind blobs 260 | inline query& operator<< (std::vector const& blob) 261 | { 262 | bind_type b(bind_.size() + 1U, &blob); 263 | bind_.push_back(b); 264 | return *this; 265 | } 266 | 267 | // specialized << operator to bind TEXT 268 | inline query& operator<< (std::string const& text) 269 | { 270 | bind_type b(bind_.size() + 1U, &text); 271 | bind_.push_back(b); 272 | return *this; 273 | } 274 | 275 | // use "exec()" if you don't expect a result set, like a DELETE or UPDATE statement 276 | int exec(const char* query = "") { 277 | int err = ::sqlite3_prepare_v2(db_(), *query ? query : query_.str().c_str(), -1, &stmt_, nullptr); 278 | query_.str(""); 279 | if (err != SQLITE_OK) { (void)::sqlite3_finalize(stmt_); return err; } 280 | err = do_bind(); 281 | if (err != SQLITE_OK) { (void)::sqlite3_finalize(stmt_); return err; } 282 | err = ::sqlite3_step(stmt_); 283 | if (err != SQLITE_DONE) { (void)::sqlite3_finalize(stmt_); return err; } 284 | return ::sqlite3_finalize(stmt_); 285 | } 286 | 287 | // use "use()" to get a single row. You MUST call use_next() or use_abort() after! 288 | row use(const char* query = "") { 289 | int err = ::sqlite3_prepare_v2(db_(), *query ? query : query_.str().c_str(), -1, &stmt_, nullptr); 290 | query_.str(""); 291 | if (err != SQLITE_OK) { (void)::sqlite3_finalize(stmt_); return row(); } 292 | err = do_bind(); 293 | if (err != SQLITE_OK) { (void)::sqlite3_finalize(stmt_); return row(); } 294 | return use_next(); 295 | } 296 | 297 | // use "use_next()" to get the next row after use()/use_next() 298 | // call use_next() until it returns an empty row or call use_abort() to finish prematurely 299 | row use_next() { 300 | row _row; 301 | if (::sqlite3_step(stmt_) == SQLITE_ROW) { 302 | for (int i = 0; i < sqlite3_column_count(stmt_); ++i) { 303 | switch (::sqlite3_column_type(stmt_, i)) 304 | { 305 | case SQLITE_INTEGER: 306 | _row.push_back(field_type(sqlite3_column_int(stmt_, i), ::sqlite3_column_name(stmt_, i))); 307 | break; 308 | case SQLITE_FLOAT: 309 | _row.push_back(field_type(sqlite3_column_double(stmt_, i), ::sqlite3_column_name(stmt_, i))); 310 | break; 311 | case SQLITE_BLOB: 312 | { 313 | const std::uint8_t* blob = reinterpret_cast(::sqlite3_column_blob(stmt_, i)); 314 | std::vector v(&blob[0], &blob[::sqlite3_column_bytes(stmt_, i)]); 315 | _row.push_back(field_type(v, ::sqlite3_column_name(stmt_, i))); 316 | } 317 | break; 318 | case SQLITE_TEXT: 319 | { 320 | std::string text(reinterpret_cast(::sqlite3_column_text(stmt_, i))); 321 | _row.push_back(field_type(text, ::sqlite3_column_name(stmt_, i))); 322 | } 323 | break; 324 | case SQLITE_NULL: 325 | _row.push_back(field_type(::sqlite3_column_name(stmt_, i))); 326 | break; 327 | default: 328 | _row.push_back(field_type(0, ::sqlite3_column_name(stmt_, i))); 329 | break; 330 | } 331 | } 332 | } 333 | else { 334 | // finalize statement 335 | (void)::sqlite3_finalize(stmt_); 336 | } 337 | return _row; 338 | } 339 | 340 | // call this if use()/use_next() should be aborted before use_next() finished (returned an empty row) 341 | // this is a mandatory call! 342 | int use_abort() { 343 | return ::sqlite3_finalize(stmt_); 344 | } 345 | 346 | // use "store()" if you want to get the complete result in memory 347 | result store(const char* query = "") { 348 | result _res; 349 | row _row = use(query); 350 | while (!_row.empty()) { 351 | _res.push_back(_row); 352 | _row = use_next(); 353 | } 354 | return _res; 355 | } 356 | 357 | // return the last inserted rowid 358 | inline std::int64_t insert_id() const { return ::sqlite3_last_insert_rowid(db_()); } 359 | 360 | // return count of affected rows of the last statement (like in DELETE/UPDATE) 361 | inline std::int64_t affected_rows() const { return ::sqlite3_changes(db_()); } 362 | 363 | // bind a BLOB or TEXT to query 364 | // CAUTION: vector and string MUST BE constant until end of query execution of exec()/use()/store() 365 | void bind(int param, std::vector const& blob) { 366 | bind_type b(param, &blob); 367 | bind_.push_back(b); 368 | } 369 | void bind(int param, std::string const& text) { 370 | bind_type t(param, &text); 371 | bind_.push_back(t); 372 | } 373 | void bind(const char* param, std::vector const& blob) { 374 | bind_type b(param, &blob); 375 | bind_.push_back(b); 376 | } 377 | void bind(const char* param, std::string const& text) { 378 | bind_type t(param, &text); 379 | bind_.push_back(t); 380 | } 381 | 382 | private: 383 | int do_bind() { 384 | int err = SQLITE_OK; 385 | for (std::vector::const_iterator it = bind_.begin(); it != bind_.end(); ++it) { 386 | if (it->type_== SQLITE_BLOB) { 387 | const std::vector* v = static_cast*>(it->ptr_); 388 | err = ::sqlite3_bind_blob(stmt_, !it->param_str_ ? it->param_num_ : ::sqlite3_bind_parameter_index(stmt_, it->param_str_), v->size() ? (const void*)&(*v)[0] : nullptr, (int)v->size(), SQLITE_STATIC); 389 | if (err != SQLITE_OK) break; 390 | } 391 | if (it->type_ == SQLITE_TEXT) { 392 | const std::string* s = static_cast(it->ptr_); 393 | err = ::sqlite3_bind_text(stmt_, !it->param_str_ ? it->param_num_ : ::sqlite3_bind_parameter_index(stmt_, it->param_str_), s->size() ? s->c_str() : nullptr, (int)s->size(), SQLITE_STATIC); 394 | if (err != SQLITE_OK) break; 395 | } 396 | if (it->type_ == SQLITE_NULL) { 397 | err = ::sqlite3_bind_null(stmt_, !it->param_str_ ? it->param_num_ : ::sqlite3_bind_parameter_index(stmt_, it->param_str_)); 398 | if (err != SQLITE_OK) break; 399 | } 400 | } 401 | bind_.clear(); // clear bindings 402 | return err; 403 | } 404 | 405 | private: 406 | const db& db_; // associated db 407 | ::sqlite3_stmt* stmt_; // statement 408 | std::stringstream query_; // query 409 | 410 | typedef struct struct_bind_type { 411 | const void* ptr_; 412 | const char* param_str_; 413 | int param_num_; 414 | int type_; 415 | struct_bind_type(int param, const std::vector* blob) : param_num_(param), param_str_(nullptr), ptr_(blob), type_(SQLITE_BLOB) { }; 416 | struct_bind_type(int param, const std::string* text) : param_num_(param), param_str_(nullptr), ptr_(text), type_(SQLITE_TEXT) { }; 417 | struct_bind_type(const char* param, const std::vector* blob) : param_num_(0), param_str_(param), ptr_(blob), type_(SQLITE_BLOB) { }; 418 | struct_bind_type(const char* param, const std::string* text) : param_num_(0), param_str_(param), ptr_(text), type_(SQLITE_TEXT) { }; 419 | } bind_type; 420 | std::vector bind_; 421 | }; 422 | 423 | 424 | /* 425 | * Representation of a transaction 426 | */ 427 | class transaction 428 | { 429 | public: 430 | // isolation levels - see SQLite3 documentation 431 | enum level_type { 432 | deferred, 433 | immediate, 434 | exclusve 435 | }; 436 | 437 | transaction(const db& db, level_type level = deferred) 438 | : db_(db) 439 | , finished_(true) // don't bother rolling it back if ctor fails 440 | { 441 | (void)begin(level); 442 | } 443 | 444 | ~transaction() { 445 | if (!finished_) { rollback(); } 446 | } 447 | 448 | // start transaction 449 | int begin(level_type level = deferred) { 450 | int err = ::sqlite3_exec(db_(), level == deferred ? "BEGIN TRANSACTION;" : (level == immediate ? "BEGIN IMMEDIATE TRANSACTION;" : "BEGIN EXCLUSIVE TRANSACTION;"), nullptr, nullptr, nullptr); 451 | finished_ = (err != SQLITE_OK); 452 | return err; 453 | } 454 | 455 | // commit transaction 456 | int commit() { 457 | int err = ::sqlite3_exec(db_(), "COMMIT;", nullptr, nullptr, nullptr); 458 | finished_ = true; 459 | return err; 460 | } 461 | 462 | // rollback transaction 463 | int rollback() { 464 | int err = ::sqlite3_exec(db_(), "ROLLBACK;", nullptr, nullptr, nullptr); 465 | finished_ = true; 466 | return err; 467 | } 468 | 469 | private: 470 | transaction& operator=(const transaction&) { } // no assignment 471 | 472 | private: 473 | const db& db_; 474 | bool finished_; 475 | }; 476 | 477 | } // namespace sqlitepp 478 | 479 | #endif // _SQLITEPP_H_ 480 | -------------------------------------------------------------------------------- /thirdparty/sqlite3ext.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2006 June 7 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This header file defines the SQLite interface for use by 13 | ** shared libraries that want to be imported as extensions into 14 | ** an SQLite instance. Shared libraries that intend to be loaded 15 | ** as extensions by SQLite should #include this file instead of 16 | ** sqlite3.h. 17 | */ 18 | #ifndef _SQLITE3EXT_H_ 19 | #define _SQLITE3EXT_H_ 20 | #include "sqlite3.h" 21 | 22 | typedef struct sqlite3_api_routines sqlite3_api_routines; 23 | 24 | /* 25 | ** The following structure holds pointers to all of the SQLite API 26 | ** routines. 27 | ** 28 | ** WARNING: In order to maintain backwards compatibility, add new 29 | ** interfaces to the end of this structure only. If you insert new 30 | ** interfaces in the middle of this structure, then older different 31 | ** versions of SQLite will not be able to load each others' shared 32 | ** libraries! 33 | */ 34 | struct sqlite3_api_routines { 35 | void * (*aggregate_context)(sqlite3_context*,int nBytes); 36 | int (*aggregate_count)(sqlite3_context*); 37 | int (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*)); 38 | int (*bind_double)(sqlite3_stmt*,int,double); 39 | int (*bind_int)(sqlite3_stmt*,int,int); 40 | int (*bind_int64)(sqlite3_stmt*,int,sqlite_int64); 41 | int (*bind_null)(sqlite3_stmt*,int); 42 | int (*bind_parameter_count)(sqlite3_stmt*); 43 | int (*bind_parameter_index)(sqlite3_stmt*,const char*zName); 44 | const char * (*bind_parameter_name)(sqlite3_stmt*,int); 45 | int (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*)); 46 | int (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*)); 47 | int (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*); 48 | int (*busy_handler)(sqlite3*,int(*)(void*,int),void*); 49 | int (*busy_timeout)(sqlite3*,int ms); 50 | int (*changes)(sqlite3*); 51 | int (*close)(sqlite3*); 52 | int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*, 53 | int eTextRep,const char*)); 54 | int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*, 55 | int eTextRep,const void*)); 56 | const void * (*column_blob)(sqlite3_stmt*,int iCol); 57 | int (*column_bytes)(sqlite3_stmt*,int iCol); 58 | int (*column_bytes16)(sqlite3_stmt*,int iCol); 59 | int (*column_count)(sqlite3_stmt*pStmt); 60 | const char * (*column_database_name)(sqlite3_stmt*,int); 61 | const void * (*column_database_name16)(sqlite3_stmt*,int); 62 | const char * (*column_decltype)(sqlite3_stmt*,int i); 63 | const void * (*column_decltype16)(sqlite3_stmt*,int); 64 | double (*column_double)(sqlite3_stmt*,int iCol); 65 | int (*column_int)(sqlite3_stmt*,int iCol); 66 | sqlite_int64 (*column_int64)(sqlite3_stmt*,int iCol); 67 | const char * (*column_name)(sqlite3_stmt*,int); 68 | const void * (*column_name16)(sqlite3_stmt*,int); 69 | const char * (*column_origin_name)(sqlite3_stmt*,int); 70 | const void * (*column_origin_name16)(sqlite3_stmt*,int); 71 | const char * (*column_table_name)(sqlite3_stmt*,int); 72 | const void * (*column_table_name16)(sqlite3_stmt*,int); 73 | const unsigned char * (*column_text)(sqlite3_stmt*,int iCol); 74 | const void * (*column_text16)(sqlite3_stmt*,int iCol); 75 | int (*column_type)(sqlite3_stmt*,int iCol); 76 | sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol); 77 | void * (*commit_hook)(sqlite3*,int(*)(void*),void*); 78 | int (*complete)(const char*sql); 79 | int (*complete16)(const void*sql); 80 | int (*create_collation)(sqlite3*,const char*,int,void*, 81 | int(*)(void*,int,const void*,int,const void*)); 82 | int (*create_collation16)(sqlite3*,const void*,int,void*, 83 | int(*)(void*,int,const void*,int,const void*)); 84 | int (*create_function)(sqlite3*,const char*,int,int,void*, 85 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 86 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), 87 | void (*xFinal)(sqlite3_context*)); 88 | int (*create_function16)(sqlite3*,const void*,int,int,void*, 89 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 90 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), 91 | void (*xFinal)(sqlite3_context*)); 92 | int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*); 93 | int (*data_count)(sqlite3_stmt*pStmt); 94 | sqlite3 * (*db_handle)(sqlite3_stmt*); 95 | int (*declare_vtab)(sqlite3*,const char*); 96 | int (*enable_shared_cache)(int); 97 | int (*errcode)(sqlite3*db); 98 | const char * (*errmsg)(sqlite3*); 99 | const void * (*errmsg16)(sqlite3*); 100 | int (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**); 101 | int (*expired)(sqlite3_stmt*); 102 | int (*finalize)(sqlite3_stmt*pStmt); 103 | void (*free)(void*); 104 | void (*free_table)(char**result); 105 | int (*get_autocommit)(sqlite3*); 106 | void * (*get_auxdata)(sqlite3_context*,int); 107 | int (*get_table)(sqlite3*,const char*,char***,int*,int*,char**); 108 | int (*global_recover)(void); 109 | void (*interruptx)(sqlite3*); 110 | sqlite_int64 (*last_insert_rowid)(sqlite3*); 111 | const char * (*libversion)(void); 112 | int (*libversion_number)(void); 113 | void *(*malloc)(int); 114 | char * (*mprintf)(const char*,...); 115 | int (*open)(const char*,sqlite3**); 116 | int (*open16)(const void*,sqlite3**); 117 | int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); 118 | int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); 119 | void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*); 120 | void (*progress_handler)(sqlite3*,int,int(*)(void*),void*); 121 | void *(*realloc)(void*,int); 122 | int (*reset)(sqlite3_stmt*pStmt); 123 | void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*)); 124 | void (*result_double)(sqlite3_context*,double); 125 | void (*result_error)(sqlite3_context*,const char*,int); 126 | void (*result_error16)(sqlite3_context*,const void*,int); 127 | void (*result_int)(sqlite3_context*,int); 128 | void (*result_int64)(sqlite3_context*,sqlite_int64); 129 | void (*result_null)(sqlite3_context*); 130 | void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*)); 131 | void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*)); 132 | void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*)); 133 | void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*)); 134 | void (*result_value)(sqlite3_context*,sqlite3_value*); 135 | void * (*rollback_hook)(sqlite3*,void(*)(void*),void*); 136 | int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*, 137 | const char*,const char*),void*); 138 | void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*)); 139 | char * (*snprintf)(int,char*,const char*,...); 140 | int (*step)(sqlite3_stmt*); 141 | int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*, 142 | char const**,char const**,int*,int*,int*); 143 | void (*thread_cleanup)(void); 144 | int (*total_changes)(sqlite3*); 145 | void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*); 146 | int (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*); 147 | void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*, 148 | sqlite_int64),void*); 149 | void * (*user_data)(sqlite3_context*); 150 | const void * (*value_blob)(sqlite3_value*); 151 | int (*value_bytes)(sqlite3_value*); 152 | int (*value_bytes16)(sqlite3_value*); 153 | double (*value_double)(sqlite3_value*); 154 | int (*value_int)(sqlite3_value*); 155 | sqlite_int64 (*value_int64)(sqlite3_value*); 156 | int (*value_numeric_type)(sqlite3_value*); 157 | const unsigned char * (*value_text)(sqlite3_value*); 158 | const void * (*value_text16)(sqlite3_value*); 159 | const void * (*value_text16be)(sqlite3_value*); 160 | const void * (*value_text16le)(sqlite3_value*); 161 | int (*value_type)(sqlite3_value*); 162 | char *(*vmprintf)(const char*,va_list); 163 | /* Added ??? */ 164 | int (*overload_function)(sqlite3*, const char *zFuncName, int nArg); 165 | /* Added by 3.3.13 */ 166 | int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); 167 | int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); 168 | int (*clear_bindings)(sqlite3_stmt*); 169 | /* Added by 3.4.1 */ 170 | int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*, 171 | void (*xDestroy)(void *)); 172 | /* Added by 3.5.0 */ 173 | int (*bind_zeroblob)(sqlite3_stmt*,int,int); 174 | int (*blob_bytes)(sqlite3_blob*); 175 | int (*blob_close)(sqlite3_blob*); 176 | int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64, 177 | int,sqlite3_blob**); 178 | int (*blob_read)(sqlite3_blob*,void*,int,int); 179 | int (*blob_write)(sqlite3_blob*,const void*,int,int); 180 | int (*create_collation_v2)(sqlite3*,const char*,int,void*, 181 | int(*)(void*,int,const void*,int,const void*), 182 | void(*)(void*)); 183 | int (*file_control)(sqlite3*,const char*,int,void*); 184 | sqlite3_int64 (*memory_highwater)(int); 185 | sqlite3_int64 (*memory_used)(void); 186 | sqlite3_mutex *(*mutex_alloc)(int); 187 | void (*mutex_enter)(sqlite3_mutex*); 188 | void (*mutex_free)(sqlite3_mutex*); 189 | void (*mutex_leave)(sqlite3_mutex*); 190 | int (*mutex_try)(sqlite3_mutex*); 191 | int (*open_v2)(const char*,sqlite3**,int,const char*); 192 | int (*release_memory)(int); 193 | void (*result_error_nomem)(sqlite3_context*); 194 | void (*result_error_toobig)(sqlite3_context*); 195 | int (*sleep)(int); 196 | void (*soft_heap_limit)(int); 197 | sqlite3_vfs *(*vfs_find)(const char*); 198 | int (*vfs_register)(sqlite3_vfs*,int); 199 | int (*vfs_unregister)(sqlite3_vfs*); 200 | int (*xthreadsafe)(void); 201 | void (*result_zeroblob)(sqlite3_context*,int); 202 | void (*result_error_code)(sqlite3_context*,int); 203 | int (*test_control)(int, ...); 204 | void (*randomness)(int,void*); 205 | sqlite3 *(*context_db_handle)(sqlite3_context*); 206 | int (*extended_result_codes)(sqlite3*,int); 207 | int (*limit)(sqlite3*,int,int); 208 | sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*); 209 | const char *(*sql)(sqlite3_stmt*); 210 | int (*status)(int,int*,int*,int); 211 | int (*backup_finish)(sqlite3_backup*); 212 | sqlite3_backup *(*backup_init)(sqlite3*,const char*,sqlite3*,const char*); 213 | int (*backup_pagecount)(sqlite3_backup*); 214 | int (*backup_remaining)(sqlite3_backup*); 215 | int (*backup_step)(sqlite3_backup*,int); 216 | const char *(*compileoption_get)(int); 217 | int (*compileoption_used)(const char*); 218 | int (*create_function_v2)(sqlite3*,const char*,int,int,void*, 219 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 220 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), 221 | void (*xFinal)(sqlite3_context*), 222 | void(*xDestroy)(void*)); 223 | int (*db_config)(sqlite3*,int,...); 224 | sqlite3_mutex *(*db_mutex)(sqlite3*); 225 | int (*db_status)(sqlite3*,int,int*,int*,int); 226 | int (*extended_errcode)(sqlite3*); 227 | void (*log)(int,const char*,...); 228 | sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64); 229 | const char *(*sourceid)(void); 230 | int (*stmt_status)(sqlite3_stmt*,int,int); 231 | int (*strnicmp)(const char*,const char*,int); 232 | int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*); 233 | int (*wal_autocheckpoint)(sqlite3*,int); 234 | int (*wal_checkpoint)(sqlite3*,const char*); 235 | void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*); 236 | int (*blob_reopen)(sqlite3_blob*,sqlite3_int64); 237 | int (*vtab_config)(sqlite3*,int op,...); 238 | int (*vtab_on_conflict)(sqlite3*); 239 | /* Version 3.7.16 and later */ 240 | int (*close_v2)(sqlite3*); 241 | const char *(*db_filename)(sqlite3*,const char*); 242 | int (*db_readonly)(sqlite3*,const char*); 243 | int (*db_release_memory)(sqlite3*); 244 | const char *(*errstr)(int); 245 | int (*stmt_busy)(sqlite3_stmt*); 246 | int (*stmt_readonly)(sqlite3_stmt*); 247 | int (*stricmp)(const char*,const char*); 248 | int (*uri_boolean)(const char*,const char*,int); 249 | sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64); 250 | const char *(*uri_parameter)(const char*,const char*); 251 | char *(*vsnprintf)(int,char*,const char*,va_list); 252 | int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*); 253 | }; 254 | 255 | /* 256 | ** The following macros redefine the API routines so that they are 257 | ** redirected throught the global sqlite3_api structure. 258 | ** 259 | ** This header file is also used by the loadext.c source file 260 | ** (part of the main SQLite library - not an extension) so that 261 | ** it can get access to the sqlite3_api_routines structure 262 | ** definition. But the main library does not want to redefine 263 | ** the API. So the redefinition macros are only valid if the 264 | ** SQLITE_CORE macros is undefined. 265 | */ 266 | #ifndef SQLITE_CORE 267 | #define sqlite3_aggregate_context sqlite3_api->aggregate_context 268 | #ifndef SQLITE_OMIT_DEPRECATED 269 | #define sqlite3_aggregate_count sqlite3_api->aggregate_count 270 | #endif 271 | #define sqlite3_bind_blob sqlite3_api->bind_blob 272 | #define sqlite3_bind_double sqlite3_api->bind_double 273 | #define sqlite3_bind_int sqlite3_api->bind_int 274 | #define sqlite3_bind_int64 sqlite3_api->bind_int64 275 | #define sqlite3_bind_null sqlite3_api->bind_null 276 | #define sqlite3_bind_parameter_count sqlite3_api->bind_parameter_count 277 | #define sqlite3_bind_parameter_index sqlite3_api->bind_parameter_index 278 | #define sqlite3_bind_parameter_name sqlite3_api->bind_parameter_name 279 | #define sqlite3_bind_text sqlite3_api->bind_text 280 | #define sqlite3_bind_text16 sqlite3_api->bind_text16 281 | #define sqlite3_bind_value sqlite3_api->bind_value 282 | #define sqlite3_busy_handler sqlite3_api->busy_handler 283 | #define sqlite3_busy_timeout sqlite3_api->busy_timeout 284 | #define sqlite3_changes sqlite3_api->changes 285 | #define sqlite3_close sqlite3_api->close 286 | #define sqlite3_collation_needed sqlite3_api->collation_needed 287 | #define sqlite3_collation_needed16 sqlite3_api->collation_needed16 288 | #define sqlite3_column_blob sqlite3_api->column_blob 289 | #define sqlite3_column_bytes sqlite3_api->column_bytes 290 | #define sqlite3_column_bytes16 sqlite3_api->column_bytes16 291 | #define sqlite3_column_count sqlite3_api->column_count 292 | #define sqlite3_column_database_name sqlite3_api->column_database_name 293 | #define sqlite3_column_database_name16 sqlite3_api->column_database_name16 294 | #define sqlite3_column_decltype sqlite3_api->column_decltype 295 | #define sqlite3_column_decltype16 sqlite3_api->column_decltype16 296 | #define sqlite3_column_double sqlite3_api->column_double 297 | #define sqlite3_column_int sqlite3_api->column_int 298 | #define sqlite3_column_int64 sqlite3_api->column_int64 299 | #define sqlite3_column_name sqlite3_api->column_name 300 | #define sqlite3_column_name16 sqlite3_api->column_name16 301 | #define sqlite3_column_origin_name sqlite3_api->column_origin_name 302 | #define sqlite3_column_origin_name16 sqlite3_api->column_origin_name16 303 | #define sqlite3_column_table_name sqlite3_api->column_table_name 304 | #define sqlite3_column_table_name16 sqlite3_api->column_table_name16 305 | #define sqlite3_column_text sqlite3_api->column_text 306 | #define sqlite3_column_text16 sqlite3_api->column_text16 307 | #define sqlite3_column_type sqlite3_api->column_type 308 | #define sqlite3_column_value sqlite3_api->column_value 309 | #define sqlite3_commit_hook sqlite3_api->commit_hook 310 | #define sqlite3_complete sqlite3_api->complete 311 | #define sqlite3_complete16 sqlite3_api->complete16 312 | #define sqlite3_create_collation sqlite3_api->create_collation 313 | #define sqlite3_create_collation16 sqlite3_api->create_collation16 314 | #define sqlite3_create_function sqlite3_api->create_function 315 | #define sqlite3_create_function16 sqlite3_api->create_function16 316 | #define sqlite3_create_module sqlite3_api->create_module 317 | #define sqlite3_create_module_v2 sqlite3_api->create_module_v2 318 | #define sqlite3_data_count sqlite3_api->data_count 319 | #define sqlite3_db_handle sqlite3_api->db_handle 320 | #define sqlite3_declare_vtab sqlite3_api->declare_vtab 321 | #define sqlite3_enable_shared_cache sqlite3_api->enable_shared_cache 322 | #define sqlite3_errcode sqlite3_api->errcode 323 | #define sqlite3_errmsg sqlite3_api->errmsg 324 | #define sqlite3_errmsg16 sqlite3_api->errmsg16 325 | #define sqlite3_exec sqlite3_api->exec 326 | #ifndef SQLITE_OMIT_DEPRECATED 327 | #define sqlite3_expired sqlite3_api->expired 328 | #endif 329 | #define sqlite3_finalize sqlite3_api->finalize 330 | #define sqlite3_free sqlite3_api->free 331 | #define sqlite3_free_table sqlite3_api->free_table 332 | #define sqlite3_get_autocommit sqlite3_api->get_autocommit 333 | #define sqlite3_get_auxdata sqlite3_api->get_auxdata 334 | #define sqlite3_get_table sqlite3_api->get_table 335 | #ifndef SQLITE_OMIT_DEPRECATED 336 | #define sqlite3_global_recover sqlite3_api->global_recover 337 | #endif 338 | #define sqlite3_interrupt sqlite3_api->interruptx 339 | #define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid 340 | #define sqlite3_libversion sqlite3_api->libversion 341 | #define sqlite3_libversion_number sqlite3_api->libversion_number 342 | #define sqlite3_malloc sqlite3_api->malloc 343 | #define sqlite3_mprintf sqlite3_api->mprintf 344 | #define sqlite3_open sqlite3_api->open 345 | #define sqlite3_open16 sqlite3_api->open16 346 | #define sqlite3_prepare sqlite3_api->prepare 347 | #define sqlite3_prepare16 sqlite3_api->prepare16 348 | #define sqlite3_prepare_v2 sqlite3_api->prepare_v2 349 | #define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 350 | #define sqlite3_profile sqlite3_api->profile 351 | #define sqlite3_progress_handler sqlite3_api->progress_handler 352 | #define sqlite3_realloc sqlite3_api->realloc 353 | #define sqlite3_reset sqlite3_api->reset 354 | #define sqlite3_result_blob sqlite3_api->result_blob 355 | #define sqlite3_result_double sqlite3_api->result_double 356 | #define sqlite3_result_error sqlite3_api->result_error 357 | #define sqlite3_result_error16 sqlite3_api->result_error16 358 | #define sqlite3_result_int sqlite3_api->result_int 359 | #define sqlite3_result_int64 sqlite3_api->result_int64 360 | #define sqlite3_result_null sqlite3_api->result_null 361 | #define sqlite3_result_text sqlite3_api->result_text 362 | #define sqlite3_result_text16 sqlite3_api->result_text16 363 | #define sqlite3_result_text16be sqlite3_api->result_text16be 364 | #define sqlite3_result_text16le sqlite3_api->result_text16le 365 | #define sqlite3_result_value sqlite3_api->result_value 366 | #define sqlite3_rollback_hook sqlite3_api->rollback_hook 367 | #define sqlite3_set_authorizer sqlite3_api->set_authorizer 368 | #define sqlite3_set_auxdata sqlite3_api->set_auxdata 369 | #define sqlite3_snprintf sqlite3_api->snprintf 370 | #define sqlite3_step sqlite3_api->step 371 | #define sqlite3_table_column_metadata sqlite3_api->table_column_metadata 372 | #define sqlite3_thread_cleanup sqlite3_api->thread_cleanup 373 | #define sqlite3_total_changes sqlite3_api->total_changes 374 | #define sqlite3_trace sqlite3_api->trace 375 | #ifndef SQLITE_OMIT_DEPRECATED 376 | #define sqlite3_transfer_bindings sqlite3_api->transfer_bindings 377 | #endif 378 | #define sqlite3_update_hook sqlite3_api->update_hook 379 | #define sqlite3_user_data sqlite3_api->user_data 380 | #define sqlite3_value_blob sqlite3_api->value_blob 381 | #define sqlite3_value_bytes sqlite3_api->value_bytes 382 | #define sqlite3_value_bytes16 sqlite3_api->value_bytes16 383 | #define sqlite3_value_double sqlite3_api->value_double 384 | #define sqlite3_value_int sqlite3_api->value_int 385 | #define sqlite3_value_int64 sqlite3_api->value_int64 386 | #define sqlite3_value_numeric_type sqlite3_api->value_numeric_type 387 | #define sqlite3_value_text sqlite3_api->value_text 388 | #define sqlite3_value_text16 sqlite3_api->value_text16 389 | #define sqlite3_value_text16be sqlite3_api->value_text16be 390 | #define sqlite3_value_text16le sqlite3_api->value_text16le 391 | #define sqlite3_value_type sqlite3_api->value_type 392 | #define sqlite3_vmprintf sqlite3_api->vmprintf 393 | #define sqlite3_overload_function sqlite3_api->overload_function 394 | #define sqlite3_prepare_v2 sqlite3_api->prepare_v2 395 | #define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 396 | #define sqlite3_clear_bindings sqlite3_api->clear_bindings 397 | #define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob 398 | #define sqlite3_blob_bytes sqlite3_api->blob_bytes 399 | #define sqlite3_blob_close sqlite3_api->blob_close 400 | #define sqlite3_blob_open sqlite3_api->blob_open 401 | #define sqlite3_blob_read sqlite3_api->blob_read 402 | #define sqlite3_blob_write sqlite3_api->blob_write 403 | #define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2 404 | #define sqlite3_file_control sqlite3_api->file_control 405 | #define sqlite3_memory_highwater sqlite3_api->memory_highwater 406 | #define sqlite3_memory_used sqlite3_api->memory_used 407 | #define sqlite3_mutex_alloc sqlite3_api->mutex_alloc 408 | #define sqlite3_mutex_enter sqlite3_api->mutex_enter 409 | #define sqlite3_mutex_free sqlite3_api->mutex_free 410 | #define sqlite3_mutex_leave sqlite3_api->mutex_leave 411 | #define sqlite3_mutex_try sqlite3_api->mutex_try 412 | #define sqlite3_open_v2 sqlite3_api->open_v2 413 | #define sqlite3_release_memory sqlite3_api->release_memory 414 | #define sqlite3_result_error_nomem sqlite3_api->result_error_nomem 415 | #define sqlite3_result_error_toobig sqlite3_api->result_error_toobig 416 | #define sqlite3_sleep sqlite3_api->sleep 417 | #define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit 418 | #define sqlite3_vfs_find sqlite3_api->vfs_find 419 | #define sqlite3_vfs_register sqlite3_api->vfs_register 420 | #define sqlite3_vfs_unregister sqlite3_api->vfs_unregister 421 | #define sqlite3_threadsafe sqlite3_api->xthreadsafe 422 | #define sqlite3_result_zeroblob sqlite3_api->result_zeroblob 423 | #define sqlite3_result_error_code sqlite3_api->result_error_code 424 | #define sqlite3_test_control sqlite3_api->test_control 425 | #define sqlite3_randomness sqlite3_api->randomness 426 | #define sqlite3_context_db_handle sqlite3_api->context_db_handle 427 | #define sqlite3_extended_result_codes sqlite3_api->extended_result_codes 428 | #define sqlite3_limit sqlite3_api->limit 429 | #define sqlite3_next_stmt sqlite3_api->next_stmt 430 | #define sqlite3_sql sqlite3_api->sql 431 | #define sqlite3_status sqlite3_api->status 432 | #define sqlite3_backup_finish sqlite3_api->backup_finish 433 | #define sqlite3_backup_init sqlite3_api->backup_init 434 | #define sqlite3_backup_pagecount sqlite3_api->backup_pagecount 435 | #define sqlite3_backup_remaining sqlite3_api->backup_remaining 436 | #define sqlite3_backup_step sqlite3_api->backup_step 437 | #define sqlite3_compileoption_get sqlite3_api->compileoption_get 438 | #define sqlite3_compileoption_used sqlite3_api->compileoption_used 439 | #define sqlite3_create_function_v2 sqlite3_api->create_function_v2 440 | #define sqlite3_db_config sqlite3_api->db_config 441 | #define sqlite3_db_mutex sqlite3_api->db_mutex 442 | #define sqlite3_db_status sqlite3_api->db_status 443 | #define sqlite3_extended_errcode sqlite3_api->extended_errcode 444 | #define sqlite3_log sqlite3_api->log 445 | #define sqlite3_soft_heap_limit64 sqlite3_api->soft_heap_limit64 446 | #define sqlite3_sourceid sqlite3_api->sourceid 447 | #define sqlite3_stmt_status sqlite3_api->stmt_status 448 | #define sqlite3_strnicmp sqlite3_api->strnicmp 449 | #define sqlite3_unlock_notify sqlite3_api->unlock_notify 450 | #define sqlite3_wal_autocheckpoint sqlite3_api->wal_autocheckpoint 451 | #define sqlite3_wal_checkpoint sqlite3_api->wal_checkpoint 452 | #define sqlite3_wal_hook sqlite3_api->wal_hook 453 | #define sqlite3_blob_reopen sqlite3_api->blob_reopen 454 | #define sqlite3_vtab_config sqlite3_api->vtab_config 455 | #define sqlite3_vtab_on_conflict sqlite3_api->vtab_on_conflict 456 | /* Version 3.7.16 and later */ 457 | #define sqlite3_close_v2 sqlite3_api->close_v2 458 | #define sqlite3_db_filename sqlite3_api->db_filename 459 | #define sqlite3_db_readonly sqlite3_api->db_readonly 460 | #define sqlite3_db_release_memory sqlite3_api->db_release_memory 461 | #define sqlite3_errstr sqlite3_api->errstr 462 | #define sqlite3_stmt_busy sqlite3_api->stmt_busy 463 | #define sqlite3_stmt_readonly sqlite3_api->stmt_readonly 464 | #define sqlite3_stricmp sqlite3_api->stricmp 465 | #define sqlite3_uri_boolean sqlite3_api->uri_boolean 466 | #define sqlite3_uri_int64 sqlite3_api->uri_int64 467 | #define sqlite3_uri_parameter sqlite3_api->uri_parameter 468 | #define sqlite3_uri_vsnprintf sqlite3_api->vsnprintf 469 | #define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2 470 | #endif /* SQLITE_CORE */ 471 | 472 | #ifndef SQLITE_CORE 473 | /* This case when the file really is being compiled as a loadable 474 | ** extension */ 475 | # define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0; 476 | # define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v; 477 | # define SQLITE_EXTENSION_INIT3 \ 478 | extern const sqlite3_api_routines *sqlite3_api; 479 | #else 480 | /* This case when the file is being statically linked into the 481 | ** application */ 482 | # define SQLITE_EXTENSION_INIT1 /*no-op*/ 483 | # define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */ 484 | # define SQLITE_EXTENSION_INIT3 /*no-op*/ 485 | #endif 486 | 487 | #endif /* _SQLITE3EXT_H_ */ 488 | --------------------------------------------------------------------------------