database - Xcode: SQLite in embedded method -
I'm working here with a new problem I started with the following code:
< Code> - (IBAction) Login: (ID) Sender {const char * dbpath = [databasePath UTF8String]; Sqlite3_stmt * statement; If (sqlite3_open (dbpath, and contactDB) == SQLITE_OK) {NSString * querySQL = [NSString stringWithFormat: @ "where contacts SELECT * login = (\"% @ \ ") and p = (\"% @ \ " ) ", Login. Text, password. Text]; Const char * query_stmt = [querySQL UTF 8 string]; If (sqlite3_prepare_v2 (contact DB, Kweri_stimti, -1, and statements, zero) == SQLITE_OK) {if (sqlite3_step (Statement) == SQLITE_ROW) {// store '1' when a user wants to log in to be in the ** If (LogSwitch.on) {[auto aStayLogged]; } And {[a resale ged]; } ** Model * Model = [Model Sharing Model]; Model.paramLogged = Login.Text; // [self disclosedsection view: zero]; } Else {status.text = @ "Login failed: Please check your ID and password"; } Sqlite3_finalize (statement); } Sqlite3_close (Contact DB); }} - (zero) aStayLogged {sqlite3_stmt * statement; Const char * dbpath = [databasePath UTF8String]; If (Sqlite3_open (Dbpath, and contactDB) == SQLITE_OK) {NSString * updateSQL = [NSString stringWithFormat: @ "Update contacts logged off = '1' where login = (\"% @ \ ")", English . Text] ; Const char * update_stmt = [updateSQL UTF 8 string]; Sqlite3_prepare_v2 (contactDB, update_stmt, -1, and statement, NULL); Full success = sqlite3_step (statement); If (success == SQLITE_ERROR) {// NSAssert1 (0, @ "error: message failed to enter database with '% s.), Sqlite3_errmsg (contactDB)); status.text = @" Update failed " ;} Else {** Status.text = @ "OK Stay"; **} // sqlite3_bind_text (Statement, 1, [Cofinam UTF-8 string], -1, Skyueltiutiaraansaiaisaiti); // sqlite3_bind_int (details, 2, Cofiaidi) ; Sqlite3_finalize;} Sqlite3_close (Contact DB);}This is a deal: If I link to 'aStayLogged' method as IBAction for a button, then update Is done properly But when I embed this method in the 'method' method, then nothing happens!
I check it by law:
- (IBAction) Check {sqlite3_stmt * statement; Const char * dbpath = [databasePath UTF8String]; if (sqlite3_open (dbpath, and contactDB) == SQLITE_OK) {NSString * querySQL = [NSString stringWithFormat: @ "log where these contacts = '1' "]; Const char * query_stmt = [querySQL UTF 8 string]; Sqlite3_prepare_v2 (contactDB, query_stmt, -1, and statement, NULL); If (Sqlite3_step (statement) == SQLITE_ROW) {NSString * logField = [[NSString alloc] initWithUTF8 string (Const char *) sqlite3_column_text (say, 0)]; Status.text = loggedField; [Logfile release]; } Else {status.text = @ "Update failed"; } Sqlite3_finalize (statement); } Sqlite3_close (Contact DB); }
This funny thing is that the situation changes in "stay fit" which is a confirmation that he should have worked! Does anyone know what can be the reason for this? Sorry for a long time - I have to ask stupid questions, but this time I do not really see it ...
hm, I think that you have mis-used to check with SQLITE_ERROR because many other status codes which do not meet, you are checking on better SQLITE_OK or SQLITE_ROW, and if you want to do this The status code you have is' rectified.
If you are mistaken then there is an error compared to using
sqlite3_errmsg to find out I think maybe there is something with SQLITE_BUSY or lock
Comments
Post a Comment