A C-based function sqlite3_prepare_v2returns 1. I just want to know the error message in readable form and correct my code. I studied this as a tutorial from Raywinderlich blogs. I came across sqlite3_errmsgand I have no idea how to use the function sqlite3_errmsg.
Although the same question was asked here , unfortunately, it still remains unanswered.
I want to know that the error and correction will be highly appreciated. thank.
- (NSArray *)failedBankInfos {
NSMutableArray *retval = [[NSMutableArray alloc]init];
NSString *query = @"SELECT id, name, city, state FROM failed_banks ORDER BY close_date DESC";
sqlite3_stmt *statement;
int tmp = sqlite3_prepare_v2(_database, [query UTF8String], -1, &statement, nil);
NSLog(@"%i",tmp);
if (sqlite3_prepare_v2(_database, [query UTF8String], -1, &statement, nil)
== SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
int uniqueId = sqlite3_column_int(statement, 0);
char *nameChars = (char *) sqlite3_column_text(statement, 1);
char *cityChars = (char *) sqlite3_column_text(statement, 2);
char *stateChars = (char *) sqlite3_column_text(statement, 3);
NSString *name = [[NSString alloc] initWithUTF8String:nameChars];
NSString *city = [[NSString alloc] initWithUTF8String:cityChars];
NSString *state = [[NSString alloc] initWithUTF8String:stateChars];
NSLog(@"name is : %@",name);
NSLog(@"city is : %@",city);
FailedBankInfo *info = [[FailedBankInfo alloc]
initWithUniqueId:uniqueId name:name city:city state:state];
[retval addObject:info];
}
sqlite3_finalize(statement);
}
else
{
}
return retval;
}
user3721704
source
share