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?

4

1 に答える 1

0

次のコードを試してください。

読み込み用:

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];

保存のコード:

-(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];
 }
于 2012-08-27T13:27:21.720 に答える