gpt4 book ai didi

objective-c - 数据库连接代码,Xcode 4和Sqlite3中的错误

转载 作者:行者123 更新时间:2023-12-03 18:38:37 25 4
gpt4 key购买 nike

我不断收到一个错误消息,说“被称为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);
}

}

最佳答案

NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO TESTDB1"
(email, username, password, age)


您太早关闭引号了;如果您仔细看一下表达式,您会注意到

@"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];


而且你应该没事了。

P. s .:在发布您的问题之前,请先查看预览-它的格式非常糟糕。

关于objective-c - 数据库连接代码,Xcode 4和Sqlite3中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12761684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com