0

I have my sqlite database already built and is copied on application startup. After that I of course run queries (just select statements). So far all but one query works. After some investigation it seems like charNames with spaces some how got "?" added where the spaces are. So instead of "Hello world" I have "Hello?World". for what ever reason this seems to make the my string equal to null.

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);
                }

ETC... COPIED FOR EACH OF THE QUERIED FIELD

This will work with all queried fields except moveName. Each of these move rows has a title field (usually without a space) and that title comes through everytime but the rest of the rows have spaces and those come through as null.

output from console:

2012-05-04 10:35:11.886 my Movelist[2938:f803] moveName Jab

2012-05-04 10:35:11.891 my Movelist[2938:f803] moveName (null)

2012-05-04 10:35:11.895 my Movelist[2938:f803] moveName (null)

output from terminal sqlite3:

Jab|1||||8|h||

Forward?Jab|f+1||||8|h||

Down?Jab|d/b+1|RC|||6|s||

FYI: for simplicity sake I left out the other fields because they seem to work fine. Like I said I think it has todo with the spaces that seem to only be in the name field.

Community
  • 1
  • 1
owen gerig
  • 6,165
  • 6
  • 52
  • 91

1 Answers1

0

You are looking at bad data. The ? is actually � or � Which you should be able to replace in your SQL via REPLACE function into the normal space that you intended it to be. null is probably the result of the character not UTF8 compatible.

Please refer to this link or this post for more information.

Community
  • 1
  • 1
Byte
  • 2,920
  • 3
  • 33
  • 55
  • � was the character that replaced the spaces. however sql REPACE function never worked to replace it. I ended up opening the file in TextWrangler and doing a find and replace all with just a normal 'space.' everything works now, thank you. – owen gerig May 14 '12 at 20:01