Sharanya K M
Sharanya K M

Reputation: 1805

SQLITE ERROR IN iphone sdk (fmdb wrapper)

I have a problem in sqlite wrapper method.. i have defined the below functions and its showing error.. im not able to solve it. all im trying to do it swap rows in the database. it works fine in sqlite manager(firefox addon) with only sql statement. but here its showing an error so im assuming the way i have defined the functions might be wrong.. can someone put a little light on this issue so tat it helps??

THANKS in advance

// this is how i have defined the function in DB

-(NSMutableArray*)extractActivitytest:(int)pri
{
    [db beginTransaction];
NSString* tSqlString = [NSString stringWithFormat:@"select Activity_Name from Activity where Priority = %d", pri];
FMResultSet *tRecordSet = (FMResultSet*)[db executeQuery:tSqlString];
NSMutableArray *rowArray = [[NSMutableArray alloc] init];
   while ([tRecordSet next])
{

    [rowArray addObject:[tRecordSet stringForColumn:COLUMN_ACT]];

}
return [rowArray autorelease];
[db commit];

}

/// this is how i have called it

 [long1  setTitle:[[[DBManager getInstance]extractActivitytest:1] objectAtIndex:0]  forState:UIControlStateNormal];
[long2  setTitle:[[[DBManager getInstance]extractActivitytest:2] objectAtIndex:0]forState:UIControlStateNormal];
[long3  setTitle:[[[DBManager getInstance]extractActivitytest:3] objectAtIndex:0] forState:UIControlStateNormal];
[long4  setTitle:[[[DBManager getInstance]extractActivitytest:4] objectAtIndex:0]forState:UIControlStateNormal];
[long5  setTitle:[[[DBManager getInstance]extractActivitytest:5] objectAtIndex:0] forState:UIControlStateNormal];
[long6  setTitle:[[[DBManager getInstance]extractActivitytest:6] objectAtIndex:0] forState:UIControlStateNormal];

// this is the ERROR I'm getting

2012-01-06 14:03:20.387 MyDaily6[5657:207] Path= /Users/rega/Library/Application       Support/iPhone Simulator/4.3.2/Applications/5A554560-A01A-4F44-980E-CC200E037CFE/Documents/Goals.sqlite
2012-01-06 14:03:22.490 MyDaily6[5657:207] Error calling sqlite3_step (1: SQL logic error or missing database) SQLITE_ERROR
2012-01-06 14:03:22.491 MyDaily6[5657:207] DB Query: BEGIN EXCLUSIVE TRANSACTION;
2012-01-06 14:03:22.491 MyDaily6[5657:207] Error calling sqlite3_step (1: SQL logic     error or missing database) SQLITE_ERROR
2012-01-06 14:03:22.492 MyDaily6[5657:207] DB Query: BEGIN EXCLUSIVE TRANSACTION;
2012-01-06 14:03:22.492 MyDaily6[5657:207] Error calling sqlite3_step (1: SQL logic error or missing database) SQLITE_ERROR
2012-01-06 14:03:22.493 MyDaily6[5657:207] DB Query: BEGIN EXCLUSIVE TRANSACTION;
2012-01-06 14:03:22.493 MyDaily6[5657:207] Error calling sqlite3_step (1: SQL logic error or missing database) SQLITE_ERROR
2012-01-06 14:03:22.494 MyDaily6[5657:207] DB Query: BEGIN EXCLUSIVE TRANSACTION;
2012-01-06 14:03:22.494 MyDaily6[5657:207] Error calling sqlite3_step (1: SQL logic error or missing database) SQLITE_ERROR
2012-01-06 14:03:22.495 MyDaily6[5657:207] DB Query: BEGIN EXCLUSIVE TRANSACTION;

/// another similar function which is giving same error

-(void)moveupData:(int)value1:(int)value2
{
NSString *stringSQL = [NSString stringWithFormat:@" UPDATE Activity SET Priority = (CASE WHEN Priority = %d THEN %d WHEN Priority = %d THEN %d END) WHERE Priority IN (%d,%d)", value1, value2];
[db executeQuery:stringSQL];
[db commit];

} // this is how im calling

[[DBManager getInstance]moveupData:moveUp :moveDown];

// ERROR I'm getting

 MOVEDOWN = 42012-01-06 14:03:34.932 MyDaily6[5657:207] Error calling sqlite3_step (1: SQL logic error or missing database) SQLITE_ERROR
2012-01-06 14:03:34.933 MyDaily6[5657:207] DB Query: COMMIT TRANSACTION;

Upvotes: 0

Views: 2103

Answers (1)

superandrew
superandrew

Reputation: 1771

Are you sure your db is open? you should call

[db open]

And, for the second part, if you want to write to the db, you should use

[db executeUpdate:stringSQL];

Hope it helps!

Upvotes: 1

Related Questions