gpt4 book ai didi

ios - Sqlite_prepare_v2返回SQLite_ERROR

转载 作者:行者123 更新时间:2023-12-03 08:12:13 24 4
gpt4 key购买 nike

我必须从具有一些空字段的SQLite数据库中打开一个表,因此,在给出要打开的表的名称和documents文件夹中的数据库地址(好的)之后,我设置了查询,然后使用了函数sqlite_prepare_v2函数准备提取数据,但返回值1(SQLite_ERROR)并给出语法错误。为什么?我写了正确的字段名称。

-(NSMutableArray*)loadDatiFromTable:(NSString*) nameTable {

NSString *query =[NSString stringWithFormat:@"SELECT id,title, ifnull(IMAGES,''),ifnull(text, ''), ifnull(NUMBER, ''),ifnull(CAP, 0) FROM %@ order by ID", nameTable];
sqlite3_stmt *statement;
int sqlResult = sqlite3_prepare_v2(database, [query UTF8String], -1, &statement,nil);
NSLog(@"The value is %d", sqlResult); // here sqlResult is 1

if (sqlResult == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
//......
}
sqlite3_finalize(statement);
} else {
NSLog(@"Failed from sqlite3_step(statement). Error is: %s", sqlite3_errmsg(database) );
// here return: "Failed from sqlite3_step(statement). Error is: near "NUMBER": syntax error"
sqlite3_close(database);
}

return self.tableArray;
}


-(id) initWithTable:(NSString*)nomeTabella withDbPath: (NSString *)dbPath {
self = [super init];
if (self) {
if (sqlite3_open([dbPath UTF8String], &database) != SQLITE_OK) {
NSLog(@"Failed open database");
} else {
NSLog(@"OPEN DATABASE");
[self loadDatiFromTable:nomeTabella ];
}

return self;
}
}

错误消息是:
    "Failed from sqlite3_step(statement). Error is:  near "NUMBER": syntax error"

最佳答案

使用"NUMBER"而不是NUMBER来确保不将该单词解释为SQL关键字。

关于ios - Sqlite_prepare_v2返回SQLite_ERROR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13007202/

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