gpt4 book ai didi

objective-c - 如何从数据库中获取列表,其中 name = "Elephant"in ios

转载 作者:行者123 更新时间:2023-11-28 20:37:42 27 4
gpt4 key购买 nike

大家好我想从数据库中获取大象列表我正在使用这段代码但是查询是错误的 当我运行相同的查询 MesaSQLite 它正在工作时请帮助我

-(NSMutableArray*)getAnimalsList
{
[animalsList removeAllObjects];

sqlite3_stmt* statement;
const char *sql;
sql = "select * from animals where name = Elephant";

if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) != SQLITE_OK)
{
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}


while (sqlite3_step(statement) == SQLITE_ROW)
{

NSInteger primaryKey = sqlite3_column_int(statement,0);
Animal *animalObject = [[Animal alloc] initWithPrimaryKey:primaryKey database:database];
[animalsList addObject:animalObject];
[animalObject release];
animalObject = nil;

}
sqlite3_finalize(statement);

printf("\n The animals list count is :%d",[animalsList count]);
return animalsList ;

}

当我在 SQLite 中使用 'SELECT * From animals where name = "Elephant";"时它正在工作

最佳答案

您没有在代码中将 Elephant 括在引号中,尝试

sql =  "select * from animals where name = 'Elephant'";

关于objective-c - 如何从数据库中获取列表,其中 name = "Elephant"in ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9802910/

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