0

I've made an app in which im using an sqlite database with fmdb wrapper for inserting and consulting data, the data is displayed into a table view, the problem is that when i run the app on an iphone 4 everything works well, but when i do it on an iphone 4s it doesn't..could someone please help me fix this issue.
Here are parts of my code:

Loading DB:

    aPools = [[NSMutableArray alloc] init];

NSString *path = [[NSBundle mainBundle] pathForResource:@"poolsDB" ofType:@"sqlite"];

mainDB = [[FMDatabase alloc] initWithPath:path];
[mainDB open];

FMResultSet *fResult = [ mainDB executeQuery:@"SELECT * FROM poolsData"];

while ([fResult next]) {
    poolsData = [fResult stringForColumn:@"Name"];
    [aPools addObject:poolsData];  
}

[mainDB close];

Saving :

-(void) saveIntoDB:(NSString *)name withVolume:(float)volume type:(NSString *)type andDesc:(NSString *)desc {

 [mainDB open];

[mainDB executeUpdate:@"INSERT INTO poolsData (Name,Volume,Type,Desc) values (?,?,?,?)",name,
 [NSNumber numberWithFloat: volume] ,type,desc, nil];

[mainDB close];

}

Could it be that the table view works in diferent ways beetwen devices?

  • Your going to have to be more specific. What exactly is not working well, and how does the manifest? – Cliff Ribaudo Jul 11 '12 at 22:44
  • Sorry, ok the issue is that when i try to save a new record into the database in both iphone 4 and iphone 4s everything goes normal, both even say that the record has been made correctly, right after, the app reloads the tableview and the information of the database should be displayed in it, the 4 do it without problems, the 4s doesn't, it shows no changes to the tableview. Sorry for my bad english, hope this can help, or do you need code? – Cazz Brunestud Jul 11 '12 at 22:54
  • Your code should work identically between the iPhone 4 and 4s. Have you tried fully deleting (hold down and tap 'x') each app and re-installing on the devices? This problem may be from leftover resources from an earlier build. – mopsled Jul 12 '12 at 01:21
  • I fully agree to "mopsled". Another cause could be a different iOS version (however, this is also very very unlikely). – Sebastian Hojas Aug 07 '12 at 19:29

1 Answers1

0

Try the following code:

for LOADING:

aPools = [[NSMutableArray alloc] init];
NSString *path = [[NSBundle mainBundle] pathForResource:@"poolsDB" ofType:@"sqlite"];

FMDatabase* mainDB = [FMDatabase databaseWithPath:path];
if(![mainDB open])
{
  return NO; //since the error in opening database
}
FMResultSet *fResult = [ mainDB executeQuery:@"SELECT * FROM poolsData"];
while ([fResult next]) {
   poolsData = [fResult stringForColumn:@"Name"];
   [aPools addObject:poolsData];  
}
[mainDB close];

code for SAVING:

-(void) saveIntoDB:(NSString *)name withVolume:(float)volume type:(NSString *)type  
  andDesc:(NSString *)desc {

  FMDatabase* mainDB = [FMDatabase databaseWithPath:path];
  if(![mainDB open])
  {
   return; //since the error in opening database
  }
  [mainDB beginTransaction];

  [mainDB executeUpdate:@"INSERT INTO poolsData (Name,Volume,Type,Desc) VALUES  
  (?,?,?,?)",name,
  [NSNumber numberWithFloat: volume] ,type,desc];

  [mainDB commit];
  [mainDB close];
 }
Ravi Raman
  • 1,070
  • 9
  • 16