@@ -20,14 +20,14 @@ using namespace std;
20
20
if (!((arg1) == (arg2))) { \
21
21
std::cout << " Unexpected false at " \
22
22
<< __FILE__ << " , " << __LINE__ << " , " << __func__ << " : " \
23
- << #arg1 << " , " << #arg2 << " ( " << arg2 << " ) " << std::endl; } \
23
+ << #arg1 << " , " << #arg2 << std::endl; } \
24
24
} while (false );
25
25
26
26
sqlite3pp::database contacts_db ();
27
27
28
28
void test_insert_execute () {
29
29
auto db = contacts_db ();
30
- db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" );
30
+ expect_eq ( 0 , db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" ) );
31
31
32
32
sqlite3pp::query qry (db, " SELECT name, phone FROM contacts" );
33
33
auto iter = qry.begin ();
@@ -45,7 +45,7 @@ void test_insert_execute_all() {
45
45
" INSERT INTO contacts (name, phone) VALUES (:user, '555-1111');"
46
46
" INSERT INTO contacts (name, phone) VALUES (:user, '555-2222')" );
47
47
cmd.bind (" :user" , " Mike" , sqlite3pp::nocopy);
48
- cmd.execute_all ();
48
+ expect_eq ( 0 , cmd.execute_all () );
49
49
50
50
sqlite3pp::query qry (db, " SELECT COUNT(*) FROM contacts" );
51
51
auto iter = qry.begin ();
@@ -57,7 +57,7 @@ void test_insert_binder() {
57
57
auto db = contacts_db ();
58
58
sqlite3pp::command cmd (db, " INSERT INTO contacts (name, phone) VALUES (?, ?)" );
59
59
cmd.binder () << " Mike" << " 555-1234" ;
60
- cmd.execute ();
60
+ expect_eq ( 0 , cmd.execute () );
61
61
62
62
sqlite3pp::query qry (db, " SELECT name, phone FROM contacts" );
63
63
auto iter = qry.begin ();
@@ -72,7 +72,7 @@ void test_insert_bind1() {
72
72
sqlite3pp::command cmd (db, " INSERT INTO contacts (name, phone) VALUES (?, ?)" );
73
73
cmd.bind (1 , " Mike" , sqlite3pp::nocopy);
74
74
cmd.bind (2 , " 555-1234" , sqlite3pp::nocopy);
75
- cmd.execute ();
75
+ expect_eq ( 0 , cmd.execute () );
76
76
77
77
sqlite3pp::query qry (db, " SELECT name, phone FROM contacts" );
78
78
auto iter = qry.begin ();
@@ -87,7 +87,7 @@ void test_insert_bind2() {
87
87
sqlite3pp::command cmd (db, " INSERT INTO contacts (name, phone) VALUES (?100, ?101)" );
88
88
cmd.bind (100 , " Mike" , sqlite3pp::nocopy);
89
89
cmd.bind (101 , " 555-1234" , sqlite3pp::nocopy);
90
- cmd.execute ();
90
+ expect_eq ( 0 , cmd.execute () );
91
91
92
92
sqlite3pp::query qry (db, " SELECT name, phone FROM contacts" );
93
93
auto iter = qry.begin ();
@@ -102,7 +102,7 @@ void test_insert_bind3() {
102
102
sqlite3pp::command cmd (db, " INSERT INTO contacts (name, phone) VALUES (:user, :phone)" );
103
103
cmd.bind (" :user" , " Mike" , sqlite3pp::nocopy);
104
104
cmd.bind (" :phone" , " 555-1234" , sqlite3pp::nocopy);
105
- cmd.execute ();
105
+ expect_eq ( 0 , cmd.execute () );
106
106
107
107
sqlite3pp::query qry (db, " SELECT name, phone FROM contacts" );
108
108
auto iter = qry.begin ();
@@ -114,7 +114,7 @@ void test_insert_bind3() {
114
114
115
115
void test_query_columns () {
116
116
auto db = contacts_db ();
117
- db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" );
117
+ expect_eq ( 0 , db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" ) );
118
118
119
119
sqlite3pp::query qry (db, " SELECT id, name, phone FROM contacts" );
120
120
expect_eq (3 , qry.column_count ());
@@ -125,7 +125,7 @@ void test_query_columns() {
125
125
126
126
void test_query_get () {
127
127
auto db = contacts_db ();
128
- db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" );
128
+ expect_eq ( 0 , db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" ) );
129
129
130
130
sqlite3pp::query qry (db, " SELECT id, name, phone FROM contacts" );
131
131
auto iter = qry.begin ();
@@ -135,7 +135,7 @@ void test_query_get() {
135
135
136
136
void test_query_tie () {
137
137
auto db = contacts_db ();
138
- db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" );
138
+ expect_eq ( 0 , db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" ) );
139
139
140
140
sqlite3pp::query qry (db, " SELECT id, name, phone FROM contacts" );
141
141
auto iter = qry.begin ();
@@ -147,7 +147,7 @@ void test_query_tie() {
147
147
148
148
void test_query_getter () {
149
149
auto db = contacts_db ();
150
- db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" );
150
+ expect_eq ( 0 , db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" ) );
151
151
152
152
sqlite3pp::query qry (db, " SELECT id, name, phone FROM contacts" );
153
153
auto iter = qry.begin ();
@@ -159,7 +159,7 @@ void test_query_getter() {
159
159
160
160
void test_query_iterator () {
161
161
auto db = contacts_db ();
162
- db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" );
162
+ expect_eq ( 0 , db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" ) );
163
163
164
164
sqlite3pp::query qry (db, " SELECT id, name, phone FROM contacts" );
165
165
for (auto row : qry) {
@@ -173,7 +173,7 @@ void test_query_iterator() {
173
173
void test_function () {
174
174
auto db = contacts_db ();
175
175
sqlite3pp::ext::function func (db);
176
- func.create <int ()>(" test_fn" , []{return 100 ;});
176
+ expect_eq ( 0 , func.create <int ()>(" test_fn" , []{return 100 ;}) );
177
177
178
178
sqlite3pp::query qry (db, " SELECT test_fn()" );
179
179
auto iter = qry.begin ();
@@ -186,7 +186,7 @@ void test_function_args() {
186
186
sqlite3pp::ext::function func (db);
187
187
func.create <string (string)>(" test_fn" , [](const string& name){return " Hello " + name;});
188
188
189
- db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" );
189
+ expect_eq ( 0 , db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" ) );
190
190
191
191
sqlite3pp::query qry (db, " SELECT name, test_fn(name) FROM contacts" );
192
192
auto iter = qry.begin ();
@@ -212,8 +212,8 @@ void test_aggregate() {
212
212
sqlite3pp::ext::aggregate aggr (db);
213
213
aggr.create <strlen_aggr, string>(" strlen_aggr" );
214
214
215
- db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" );
216
- db.execute (" INSERT INTO contacts (name, phone) VALUES ('Janette', '555-4321')" );
215
+ expect_eq ( 0 , db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" ) );
216
+ expect_eq ( 0 , db.execute (" INSERT INTO contacts (name, phone) VALUES ('Janette', '555-4321')" ) );
217
217
218
218
sqlite3pp::query qry (db, " SELECT strlen_aggr(name), strlen_aggr(phone) FROM contacts" );
219
219
auto iter = qry.begin ();
@@ -230,6 +230,28 @@ void test_invalid_path() {
230
230
expect_true (false );
231
231
}
232
232
233
+ void test_reset () {
234
+ auto db = contacts_db ();
235
+ sqlite3pp::command cmd (db, " INSERT INTO contacts (name, phone) VALUES (:user, :phone)" );
236
+ cmd.bind (" :user" , " Mike" , sqlite3pp::nocopy);
237
+ cmd.bind (" :phone" , " 555-1234" , sqlite3pp::nocopy);
238
+ expect_eq (0 , cmd.execute ());
239
+
240
+ cmd.reset ();
241
+ cmd.bind (" :user" , " Janette" , sqlite3pp::nocopy);
242
+ expect_eq (0 , cmd.execute ());
243
+
244
+ sqlite3pp::query qry (db, " SELECT COUNT(*) FROM contacts" );
245
+ auto iter = qry.begin ();
246
+ int count = (*iter).get <int >(0 );
247
+ expect_eq (2 , count);
248
+
249
+ cmd.reset ();
250
+ cmd.clear_bindings ();
251
+ cmd.bind (" :user" , " Dave" , sqlite3pp::nocopy);
252
+ expect_eq (SQLITE_CONSTRAINT, cmd.execute ());
253
+ }
254
+
233
255
int main ()
234
256
{
235
257
test_insert_execute ();
@@ -247,6 +269,7 @@ int main()
247
269
test_function_args ();
248
270
test_aggregate ();
249
271
test_invalid_path ();
272
+ test_reset ();
250
273
}
251
274
252
275
sqlite3pp::database contacts_db () {
0 commit comments