2012-11-14 77 views
0

我在一个表格中存储了一个包含多个不同类型列的值集合,并且当我在iPhone模拟器上运行该应用程序时插入和选择工作正常。但是,在真实设备上运行并选择数据时,它看起来似乎无法获取表格的某些文本列(其余列似乎被正确检索)。在哪里我应该显示一个字符串对话框,我不是,我得到一个空的对话框,而与字符串对话框正确地显示在模拟器上。SQLite3的选择在模拟器上,但它不在设备上

这是插入的代码片段:

if(sqlite3_prepare_v2(database, sqlStatement, 
          -1, &compiledStatement, NULL) == SQLITE_OK) 
    { 
     sqlite3_bind_int(compiledStatement, 1, userData.ID); 
     sqlite3_bind_double(compiledStatement, 2, userData.Location.Lat); 
     sqlite3_bind_double(compiledStatement, 3, userData.Location.Lon); 
     sqlite3_bind_text(compiledStatement, 4, [userData.Name UTF8String], -1, SQLITE_TRANSIENT); 
     sqlite3_bind_text(compiledStatement, 5, [userData.Surname UTF8String], -1, SQLITE_TRANSIENT); 
    } 

    if(sqlite3_step(compiledStatement) == SQLITE_DONE) { 
     sqlite3_finalize(compiledStatement); 
    } 
    else { 
     NSLog(@"%d",sqlite3_step(compiledStatement)); 
    } 
} 
sqlite3_close(database); 

这是选择:

if (sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { 
     while(sqlite3_step(compiledStatement) == SQLITE_ROW) { 
      UserData *userData = [[UserData alloc] init]; 

      userData.ID = sqlite3_column_int(compiledStatement, 0); 

      char *name = sqlite3_column_text(compiledStatement, 1); 
      if (name == nil) 
       userData.Name = @""; 
      else 
       userData.Name = [NSString stringWithUTF8String: name]; 

      [list addObject:userData]; 
     } 
    } 
    sqlite3_finalize(compiledStatement); 
} 
sqlite3_close(database); 

我完全不知道为什么数据库的数据管理在模拟器表现好(我有SQLite管理器插件和数据被正确存储和检索),但它不在真正的iPhone中。我如何检查设备上发生了什么?有人经历过类似的事吗?

谢谢!

+0

显示你的SQL请求 – Oleg

+0

那的代码片断第二有两个开放的大括号“{”和三贴近“}”,所以我不知道这是怎么回事连接。无论如何,这里是我的代码片段,工作正常。 char * localityChars =(char *)sqlite3_column_text(statement,1); if(localityChars == NULL)返回FALSE; ,至于绑定文本,你做它不同于我的应用程序这样做:sqlite3_bind_text(stmt,4,[myString UTF8String],-1,NULL); – Chris

回答

0

我终于得到了它的工作,下面所有的建议,我觉得有什么解决的最后的问题是区分大小写的事情。感谢ü所有

+0

我很高兴听到我说得对,我正在等待投票..甚至:) – TonyMkenu

0

我认为这个问题可能是由空记录引起你的if nil没有帮助,尝试NULL代替:

if ((char *)sqlite3_column_text(compiledStatement, 1) == NULL) 
userData.Name = @""; 
+1

奇怪,怪异..尝试删除/重新安装设备中的应用程序,再次检查表名称和字段名称(在设备上区分大小写)。让我们知道..进展。祝你好运! – TonyMkenu

相关问题