ios - Adding NULL Values to SQLite Database with FMDB and NSDictionary -


i have run bit of catch 22. using fmdb's fancy withparameterdictionary method insert data sqlite database this:

nsdictionary *aircraftdict = [nsdictionary dictionarywithobjectsandkeys:                               self.aircraftidtextfield.text, @"aircraft_id",                               self.makemodeltextfield.text, @"make_model",                               self.categoryclasstextfield.text, @"category_class",                                                                 @yes, @"updated_flag",                                                                nil];  nsstring *addaircraftquery = @"insert aircrafts (aircraft_id, make_model, category_class, updated_flag) values (:aircraft_id, :make_model, :category_class, :updated_flag)";  [db executeupdate:addaircraftquery withparameterdictionary:aircraftdict]; 

the problem when 1 of text fields blank, truncates nsdictionary since nil value tells dictionary has arrived @ end of list of values.

i can work around issue fine making sure have blank object each value in dictionary (e.g. string @"").

but values arrive in sqlite database "blank" value instead of null. may not big deal, i've heard using null take less space in database.

how can insert null database without prematurely truncating nsdictionary?

you can not using "fancy" withparameterdictionary method, , instead using boring executeupdate this:

nsstring *addaircraftquery = @"insert aircrafts (aircraft_id, make_model, category_class, updated_flag) values (?, ?, ?, ?)";  [db executeupdate:addaircraftquery, self.aircraftdict, self.makemodeltextfield.text, self.categoryclasstextfield.text, @yes]; 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -