objective c - Deep Trouble with values not inserting to sqlite database -iPhone -
i have multiple view controllers, registrationviewcontroller , contactsviewcontroller , addnewcontactsviewcontroller, etc.
i have below code in registrationviewcontroller
databasecrud *database = [[databasecrud alloc] init]; nsmutablestring *registrationquery=[nsmutablestring stringwithformat:@"insert barvalues values ('%@','%@','%@','%@','%@','%@')",[name text],[emailaddress text],[mobilenumber text],[password text],[country text],@"0"]; nslog(@"registrationquery %@",registrationquery); [database updatenewregistration:registrationquery]; [database release]; databasecrud *database1 = [[databasecrud alloc] init]; nsmutablestring *registrationquery1=[nsmutablestring stringwithformat:@"insert contacts values ('1234','1234')"]; nslog(@"registrationquery %@",registrationquery1); [database1 updatenewregistration:registrationquery1]; [database1 release]; databasecrud *database2 = [[databasecrud alloc] init]; nsmutablestring *registrationquery2=[nsmutablestring stringwithformat:@"insert contacts values ('abcd','abcd')"]; nslog(@"registrationquery %@",registrationquery2); [database2 addcontacts:registrationquery2]; [database2 release];
the above code works fine . inserts values sqlite database. here problem , have same code in different viewcontroller(contacts, addcontacts) , values dont inserted sqlite database.here code.
databasecrud *database = [[databasecrud alloc] init]; nsmutablestring *registrationquery=[nsmutablestring stringwithformat:@"insert contacts values ('raja','shekar')"]; nslog(@"registrationquery %@",registrationquery); [database updatenewregistration:registrationquery]; [database release]; databasecrud *database1 = [[databasecrud alloc] init]; nsmutablestring *registrationquery1=[nsmutablestring stringwithformat:@"insert contacts values ('rajesh','neelam')"]; nslog(@"registrationquery %@",registrationquery1); [database1 addcontacts:registrationquery1]; [database1 release];
i dont see reason why database object insertin in 1 viewcontroller , doesnt in other viewcontroller. appreciated. have tried figure error day long , dont want waste anymore time. please????
i put breakpoints @ every method of database object see if inserting, there no error @ . seems passing through sqlstatment, no insertion happens. here code of saving values in databasehere code database insertion.
-(void) addcontacts :(nsstring *)query { if(sqlite3_open([databasepath utf8string], &database) == sqlite_ok) { nslog(@"query %@",query); sqlstatement=[query cstringusingencoding:nsasciistringencoding]; if(sqlite3_prepare_v2(database, sqlstatement, -1, &compiledstatement, null) == sqlite_ok) { while(sqlite3_step(compiledstatement) == sqlite_row) { nslog(@"new contact updated"); } sqlite3_finalize(compiledstatement); } sqlite3_close(database); } }
this somewhere between answer , comment - interpret necessary.
i assume insert statements return error code, correct? values? send long ways towards solution.
Comments
Post a Comment