@@ -112,6 +112,40 @@ void test_insert_bind3() {
112
112
expect_eq (" 555-1234" , phone);
113
113
}
114
114
115
+ void test_insert_bind_null () {
116
+ auto db = contacts_db ();
117
+ sqlite3pp::command cmd (db, " INSERT INTO contacts (name, phone, address) VALUES (:user, :phone, :address)" );
118
+ cmd.bind (" :user" , " Mike" , sqlite3pp::nocopy);
119
+ cmd.bind (" :phone" , " 555-1234" , sqlite3pp::nocopy);
120
+ cmd.bind (" :address" );
121
+ expect_eq (0 , cmd.execute ());
122
+
123
+ sqlite3pp::query qry (db, " SELECT name, phone, address FROM contacts" );
124
+ auto iter = qry.begin ();
125
+ string name, phone;
126
+ const char * address = nullptr ;
127
+ (*iter).getter () >> name >> phone >> address;
128
+ expect_eq (" Mike" , name);
129
+ expect_eq (" 555-1234" , phone);
130
+ expect_eq (nullptr , address);
131
+ }
132
+
133
+ void test_insert_binder_null () {
134
+ auto db = contacts_db ();
135
+ sqlite3pp::command cmd (db, " INSERT INTO contacts (name, phone, address) VALUES (?, ?, ?)" );
136
+ cmd.binder () << " Mike" << " 555-1234" << nullptr ;
137
+ expect_eq (0 , cmd.execute ());
138
+
139
+ sqlite3pp::query qry (db, " SELECT name, phone, address FROM contacts" );
140
+ auto iter = qry.begin ();
141
+ string name, phone;
142
+ const char * address = nullptr ;
143
+ (*iter).getter () >> name >> phone >> address;
144
+ expect_eq (" Mike" , name);
145
+ expect_eq (" 555-1234" , phone);
146
+ expect_eq (nullptr , address);
147
+ }
148
+
115
149
void test_query_columns () {
116
150
auto db = contacts_db ();
117
151
expect_eq (0 , db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" ));
@@ -260,6 +294,8 @@ int main()
260
294
test_insert_bind1 ();
261
295
test_insert_bind2 ();
262
296
test_insert_bind3 ();
297
+ test_insert_bind_null ();
298
+ test_insert_binder_null ();
263
299
test_query_columns ();
264
300
test_query_get ();
265
301
test_query_tie ();
@@ -279,6 +315,7 @@ sqlite3pp::database contacts_db() {
279
315
id INTEGER PRIMARY KEY,
280
316
name TEXT NOT NULL,
281
317
phone TEXT NOT NULL,
318
+ address TEXT,
282
319
UNIQUE(name, phone)
283
320
);
284
321
)""" );
0 commit comments