0

Below is the code i am using:

FMDatabaseQueue *queue = [[DataBaseHelper sharedManager] queue];
[queue inDatabase:^(FMDatabase *db) {

FMResultSet *results = [db executeQuery:@"select * from EVENT where ESTATUS='unread' and HIT_ATTEMPTS < 5 "];

if([results next])
{
   [results close];

   @try {
           BOOL success=FALSE;
           NSString *query=[NSString stringWithFormat:@"insert into EVENT (EDATA, ESTATUS ,EUSER) values('%@','%@','%@')",@"google.com",@"unread",@"xyz"];

           success = [db executeUpdate:query];
           NSLog(@"create edata row, %d:%@", [db lastErrorCode], [db lastErrorMessage]);
        }

   @catch (NSException *exception) {
        NSLog(@"Exception");
   }

In the above code success = [db executeUpdate:query]; is not working. I have tried placing breakpoints. After this line of code all exits. None of the logs get printed.

TechFanatic
  • 1,218
  • 4
  • 13
  • 31

1 Answers1

0

I am not sure why you are using a try and Catch, anywayz follow the steps it will surely work

Creating A Database

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *path = [docsPath stringByAppendingPathComponent:@"database.sqlite"];

FMDatabase *database = [FMDatabase databaseWithPath:path];

Opening The Database And Creating Tables(optional)

[database open];
//optional
[database executeUpdate:@"create table user(name text primary key, age int)"]; 

Querying The Database

FMResultSet *results = [database executeQuery:@"select * from user"];
while([results next]) {
    NSString *name = [results stringForColumn:@"name"];
    NSInteger age  = [results intForColumn:@"age"];        
    NSLog(@"User: %@ - %d",name, age);
}
[database close];
Vizllx
  • 9,135
  • 1
  • 41
  • 79