Objective c 数据库连接代码错误,Xcode 4&;Sqlite3
我不断收到一个错误,上面写着“被调用的NSString类型不是函数或函数指针。我已经尝试了好几天了。我知道我的问题出在哪里了吗Objective c 数据库连接代码错误,Xcode 4&;Sqlite3,objective-c,xcode4,sqlite,Objective C,Xcode4,Sqlite,我不断收到一个错误,上面写着“被调用的NSString类型不是函数或函数指针。我已经尝试了好几天了。我知道我的问题出在哪里了吗 - (void)saveData { sqlite3_stmt *statement; const char *dbpath = [databasePath UTF8String]; if (sqlite3_open(dbpath, &testdb1) == SQLITE_OK) { NSString
- (void)saveData
{
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &testdb1) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO TESTDB1"
(email, username, password, age) VALUES (\"%@\", \"%@\", \"%@\", \"%@\")",
email.text, username.text, password.text, age.integer];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(testdb1, insert_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
status.text = @"User added";
email.text = @"";
username.text = @"";
password.text = @"";
age.text = @"";
} else {
status.text = @"Failed to add user";
}
sqlite3_finalize(statement);
sqlite3_close(testdb1);
}
}
您过早地结束引号;如果仔细观察表达式,您会注意到
@"INSERT INTO TESTDB" (email, username, password, age)
因此,编译器会看到您试图将NSString作为函数调用
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO TESTDB1 (email, username, password, age) VALUES (\"%@\", \"%@\", \"%@\", \"%@\")",
email.text, username.text, password.text, age.integer];
你应该可以走了
附言:在发布您的问题之前,一定要看一看预览版——它的格式非常糟糕。您在stringWithFormat调用的第二行开头缺少一个引号
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO TESTDB1 (email, username, password, age) VALUES (\"%@\", \"%@\", \"%@\", \"%@\")",
email.text, username.text, password.text, age.integer];