Reputation: 4974
I have this code, (which I did not write):
- (BOOL)execute:(NSString *)sqlCommand error:(NSError **)error
{
const char *sql = [sqlCommand UTF8String];
char *errorPointer;
if (sqlite3_exec(database, sql, NULL, NULL, &errorPointer) != SQLITE_OK)
{
if (error)
{
NSString *errMsg = [NSString stringWithCString:errorPointer encoding:NSUTF8StringEncoding];
NSString *description = @"An error occurred executing the SQL statement";
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:description, NSLocalizedDescriptionKey, errMsg, NSLocalizedFailureReasonErrorKey, nil];
*error = [[[NSError alloc] initWithDomain:SQLCipherManagerErrorDomain code:ERR_SQLCIPHER_COMMAND_FAILED userInfo:userInfo] autorelease];
sqlite3_free(error);
}
return NO;
}
return YES;
}
I also have a method without the "error" parameter, which I would call using something like this: [dm execute:insertCommand];
My question is: what is the format of the call I would use for the method with the "error" parameter, so I can see any errors back from the call?
Upvotes: 0
Views: 80
Reputation: 8614
like that:
NSError* error = nil;
BOOL success = [dm execute:insertCommand error:&error];
if (success == NO)
{
// do whatever if failed
}
see also "Handling Error Objects Returned From Methods" from cocoa documentation.
Upvotes: 3
Reputation: 410662
You'd have to declare an NSError
object outside of the call to the code, and pass in the address:
NSError *error;
BOOL success = [whateverObj execute:theSqlStmt error:&error];
if (!success) {
// Handle error
}
Upvotes: 0
Reputation: 57179
NSError *error = nil; //your error
if(![dm execute:sqlCommand error:&error])
{ //Pass the address to your pointer ^^
//Since you passed the address of your error pointer
//your execute command was able to set it to an
//NSError if one occurrs
}
Upvotes: 2