
try-catch-finally (sqlite3)
By: a guest on
Apr 28th, 2012 | syntax:
Objective C | size: 1.23 KB | hits: 19 | expires: Never
sqlite3_stmt *statement = nil;
@try {
sqlite3_open([databasePath UTF8String], &database);
@try {
NSString *queryStatement = @"INSERT INTO People (ID_Organization, Name, EMail) VALUES (?, ?, ?);";
sqlite3_prepare_v2(database, [queryStatement UTF8String], -1, &statement, NULL);
@try {
sqlite3_bind_int(statement, aPerson.organizationID, 1);
sqlite3_bind_text(statement, 2, [aPerson.name UTF8String], -1, NULL);
sqlite3_bind_text(statement, 3, [aPerson.eMail UTF8String], -1, NULL);
sqlite3_step(statement);
NSLog(@"Person inserted.");
aPerson.ID = sqlite3_last_insert_rowid(database);
return TRUE;
}
@catch (NSException *exception) {
NSLog(@"%s", sqlite3_errmsg(database));
return FALSE;
}
}
@catch (NSException *exception) {
NSLog(@"%s", sqlite3_errmsg(database));
return FALSE;
}
@finally {
sqlite3_reset(statement);
}
}
@catch (NSException *exception) {
NSLog(@"%s", sqlite3_errmsg(database));
return FALSE;
}
@finally {
sqlite3_close(database);
}