ios sqlite行与?不读
我已经建立了sqlite数据库,并在应用程序启动时进行复制。之后,我当然会运行查询,只需选择语句。到目前为止,除了一个查询外,所有查询都有效。经过一些调查,看起来像是带有空格的字符名。怎么会这样呢?在空格所在的位置添加。所以我用的不是Hello world,而是Hello?world。出于什么原因,这似乎使my字符串等于nullios sqlite行与?不读,ios,sqlite,Ios,Sqlite,我已经建立了sqlite数据库,并在应用程序启动时进行复制。之后,我当然会运行查询,只需选择语句。到目前为止,除了一个查询外,所有查询都有效。经过一些调查,看起来像是带有空格的字符名。怎么会这样呢?在空格所在的位置添加。所以我用的不是Hello world,而是Hello?world。出于什么原因,这似乎使my字符串等于null NSString *querySQL = [NSString stringWithFormat: @"select moveName, moveCommand
NSString *querySQL = [NSString stringWithFormat: @"select moveName, moveCommand, moveStance, moveHits, moveType, moveDmg, moveHitRange, moveEscape, moveProperties from Moves where charName='%@' and moveCatagory = '%@';",charName, catName];
NSLog(@"move SQL query: %@",querySQL);
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(myDB, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
const char* moveName = (const char*)sqlite3_column_text(statement, 0);
const char* moveCommand = (const char*)sqlite3_column_text(statement, 1);
const char* moveStance = (const char*)sqlite3_column_text(statement, 2);
const char* moveHits = (const char*)sqlite3_column_text(statement, 3);
const char* moveType = (const char*)sqlite3_column_text(statement, 4);
const char* moveDmg = (const char*)sqlite3_column_text(statement, 5);
const char* moveHitRange = (const char*)sqlite3_column_text(statement, 6);
const char* moveEscape = (const char*)sqlite3_column_text(statement, 7);
const char* moveProperties = (const char*)sqlite3_column_text(statement, 8);
Move * move = [[Move alloc]init];
if (moveName != nil) {
move.moveName = [[NSString alloc] initWithUTF8String:moveName];
NSLog(@"moveName %@",move.moveName);
}
等等。。。已为每个查询字段复制
这将适用于除moveName之外的所有查询字段。这些移动行中的每一行都有一个标题字段,通常没有空格,该标题每次都会显示出来,但其余的行都有空格,这些标题字段显示为null
控制台的输出:
2012-05-04 10:35:11.886我的移动列表[2938:f803]移动名称戳
2012-05-04 10:35:11.891我的移动列表[2938:f803]移动名称为空
2012-05-04 10:35:11.895我的移动列表[2938:f803]移动名称空
终端sqlite3的输出:
刺拳1 | | | | | 8 | h||
向前?猛击f+1 | | | | | 8 | h||
向下?垂直方向+1 | RC | | | 6 | s||
仅供参考:为了简单起见,我省略了其他字段,因为它们似乎工作正常。就像我说的,我认为它必须处理那些似乎只在name字段中的空格。您看到的是糟糕的数据。这个实际上是� 或者?½,您应该能够通过replace函数在SQL中将其替换到您想要的正常空间中。null可能是字符与UTF8不兼容的结果
有关更多信息,请参阅此或此� 是替换空格的字符。然而,SQLRepace函数从未起到替换它的作用。最后,我在TextWrangler中打开了文件,并用一个普通的“空间”查找并替换了所有文件。现在一切正常,谢谢。