0

我制作了一个应用程序,其中我使用带有 fmdb 包装器的 sqlite 数据库来插入和咨询数据,数据显示在表格视图中,问题是当我在 iphone 4 上运行应用程序时一切正常,但是当我是在 iphone 4s 上做的,它没有......有人可以帮我解决这个问题。
以下是我的部分代码:

加载数据库:

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

保存:

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

}

可能是表格视图以不同的方式工作 beetwen 设备?

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 回答