-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathsimple_examples.cc
More file actions
36 lines (26 loc) · 893 Bytes
/
simple_examples.cc
File metadata and controls
36 lines (26 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <sqlite_modern_cpp.h>
#include <catch2/catch.hpp>
using namespace sqlite;
using namespace std;
TEST_CASE("simple examples", "[examples]") {
database db(":memory:");
db << "CREATE TABLE foo (a integer, b string);\n";
db << "INSERT INTO foo VALUES (?, ?)" << 1 << "hello";
db << "INSERT INTO foo VALUES (?, ?)" << 2 << "world";
string str;
db << "SELECT b from FOO where a=?;" << 2L >> str;
REQUIRE(str == "world");
std::string sql("select 1+1");
long test = 0;
db << sql >> test;
REQUIRE(test == 2);
db << "UPDATE foo SET b=? WHERE a=?;" << "hi" << 1L;
db << "SELECT b FROM foo WHERE a=?;" << 1L >> str;
REQUIRE(str == "hi");
REQUIRE(db.rows_modified() == 1);
db << "UPDATE foo SET b=?;" << "hello world";
REQUIRE(db.rows_modified() == 2);
}