Hi guys I want to get Elephants list from database I am using this code but the query is wrong
when I run the same query MesaSQLite it is working please help me
-(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 ;
}
When I used ‘SELECT * From animals where name = “Elephant”;” in SQLite it is working
You are not enclosing Elephant in quotes in your code, try