Je reçois l'erreur suivante:problème sqlite3_prepare_v2
* Mettre fin application en raison d'exception uncaught 'NSInvalidArgumentException', raison: '* + [NSString stringWithUTF8String:]: NULL CSTRING'
sur la ligne de code ci-dessous:
NSString *aName = [NSString stringWithUTF8String(char*)sqlite3_column_text(compiledStatement, 1)];
Je ne sais pas ce qui se passe ici, la colonne I référencé dans mon instruction SQL contient des données. Code complet ci-dessous.
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select ZROUTE_NAME from ZROUTE";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
// Loop through the results and add them to the Route Name array
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{
// Read the data from the result row
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
// Add the animal object to the animals Array
//[list addObject:animal];
[list addObject:aName];
//[animal release];
}
}
else
{
NSLog(@"Error: failed to select details from database with message '%s'.", sqlite3_errmsg(database));
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
Cela a exactement le même problème. Vous ne devriez pas vérifier le 'NSString', mais la chaîne C brute. – Joost
Ouais, mon erreur. Maintenant corrigé. Merci JoostK. – Jim
Merci Jim et JoostK, j'ai changé mon code comme ci-dessus. S'il vous plaît noter, je devais changer sqlite3_column_text (compiledStatement, 1) en sqlite3_column_text (compiledStatement, 0), pas tout à fait sûr pourquoi, mais son fonctionnement maintenant. – Stephen