| 6 | using namespace sqlite; |
| 7 | |
| 8 | int main() { |
| 9 | |
| 10 | try { |
| 11 | database db(":memory:"); |
| 12 | db << "CREATE TABLE tbl (id integer,age integer, name string, img blob);"; |
| 13 | db << "INSERT INTO tbl VALUES (?, ?, ?, ?);" << 1 << 24 << "bob" << vector<int> { 1, 2 , 3}; |
| 14 | unique_ptr<string> ptr_null; |
| 15 | db << "INSERT INTO tbl VALUES (?, ?, ?, ?);" << 2 << nullptr << ptr_null << nullptr; |
| 16 | |
| 17 | db << "select age,name,img from tbl where id = 1" >> [](unique_ptr<int> age_p, unique_ptr<string> name_p, unique_ptr<vector<int>> img_p) { |
| 18 | if(age_p == nullptr || name_p == nullptr || img_p == nullptr) { |
| 19 | cerr << "ERROR: values should not be null" << std::endl; |
| 20 | exit(EXIT_FAILURE); |
| 21 | } |
| 22 | |
| 23 | cout << "age:" << *age_p << " name:" << *name_p << " img:"; |
| 24 | for(auto i : *img_p) |
| 25 | cout << i << ","; |
| 26 | cout << endl; |
| 27 | }; |
| 28 | |
| 29 | db << "select age,name,img from tbl where id = 2" >> [](unique_ptr<int> age_p, unique_ptr<string> name_p, unique_ptr<vector<int>> img_p) { |
| 30 | if(age_p != nullptr || name_p != nullptr || img_p != nullptr) { |
| 31 | cerr << "ERROR: values should be nullptr" << std::endl; |
| 32 | exit(EXIT_FAILURE); |
| 33 | } |
| 34 | |
| 35 | cout << "OK all three values are nullptr" << endl; |
| 36 | }; |
| 37 | |
| 38 | } catch(sqlite_exception e) { |
| 39 | cout << "Sqlite error " << e.what() << endl; |
| 40 | exit(EXIT_FAILURE); |
| 41 | } catch(...) { |
| 42 | cout << "Unknown error\n"; |
| 43 | exit(EXIT_FAILURE); |
| 44 | } |
| 45 | |
| 46 | cout << "OK\n"; |
| 47 | exit(EXIT_SUCCESS); |
| 48 | return 0; |
| 49 | } |
nothing calls this directly
no outgoing calls
no test coverage detected