@@ -112,6 +112,40 @@ void test_insert_bind3() {
112112 expect_eq (" 555-1234" , phone);
113113}
114114
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+
115149void test_query_columns () {
116150 auto db = contacts_db ();
117151 expect_eq (0 , db.execute (" INSERT INTO contacts (name, phone) VALUES ('Mike', '555-1234')" ));
@@ -260,6 +294,8 @@ int main()
260294 test_insert_bind1 ();
261295 test_insert_bind2 ();
262296 test_insert_bind3 ();
297+ test_insert_bind_null ();
298+ test_insert_binder_null ();
263299 test_query_columns ();
264300 test_query_get ();
265301 test_query_tie ();
@@ -279,6 +315,7 @@ sqlite3pp::database contacts_db() {
279315 id INTEGER PRIMARY KEY,
280316 name TEXT NOT NULL,
281317 phone TEXT NOT NULL,
318+ address TEXT,
282319 UNIQUE(name, phone)
283320 );
284321 )""" );
0 commit comments