2014-09-01 43 views
0

餘米試圖存儲在數據庫中的兩個值,但我m到處語法錯誤 這裏我的代碼在sqlite3中獲取語法錯誤?

- (IBAction)LogIn:(id)sender { 
sqlite3 *dbConnection; 
sqlite3_stmt *statement = Nil; 
if (sqlite3_open([[sharedobj getSandboxPath] UTF8String], &dbConnection) == SQLITE_OK) { 
NSString *insertQuery = [NSString stringWithFormat:@"INSERT INTO LOGINVALUES ('%@','%@')",self.userNameField.text,self.passwordField.text]; 

    if (sqlite3_prepare_v2(dbConnection, [insertQuery UTF8String], -1, &statement, NULL) == SQLITE_OK) { 
     sqlite3_bind_text(statement, 1, [self.userNameField.text UTF8String], -1, NULL); 
     sqlite3_bind_text(statement, 2, [self.passwordField.text UTF8String], -1, NULL); 

    } 

    if (sqlite3_step(statement) == SQLITE_DONE) { 
     NSLog(@"successfully inserted a record in table"); 
    } 
    else{ 
     NSLog(@"error is %s",sqlite3_errmsg(dbConnection)); 
    } 
} 
sqlite3_finalize(statement); 
sqlite3_close(dbConnection); 

} 但我m到處

error is near ")": syntax error 

如何解決這個問題? 在此先感謝。

回答

1

假設LOGIN是您的表名,則需要LOGINVALUES之間的空格。

截至目前爲止,LOGINVALUES被視爲表名和要插入的圓括號列表列名。然後,SQL輸入結束而不強制INSERT查詢,例如, VALUES (...)部分。

另外,在末尾添加分號;

+0

其作品感謝拉爾託 – user3585325 2014-09-01 10:39:14

相關問題