2012-03-18 17 views
-1

選択クエリを含むメソッドを実行していますが、コンパイルされた文が動作していないブレークポイントは宣言している行をスキップし、カーソルを置くと値が表示されません。コード私が使用しています:SQLiteでクエリが選択されていません

-(NSMutableArray *)GetAllPartsName 
{ 
    NSString *path = [self getDBPath]; 
    // Open the database from the users filessytem 

    NSMutableArray *Parts=[[[NSMutableArray alloc]init]autorelease ]; 
    if(sqlite3_open([path UTF8String], &database) == SQLITE_OK) { 
     // Setup the SQL Statement and compile it for faster access 

     NSString *sqlQuery = [NSString stringWithFormat:@"SELECT Parts_Name FROM Parts"]; 
     NSLog(@"%@",sqlQuery); 
     const char *sqlStatement = [sqlQuery UTF8String]; 
     //The break point skips the sqlite3_stmt. 
     sqlite3_stmt *compiledStatement; 
     //when i put the cursor over compiledStatement it shows no value 
     if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { 
      // Loop through the results and add them to the feeds array 
      while(sqlite3_step(compiledStatement) == SQLITE_ROW) { 
       // Read the data from the result row 
       NSMutableDictionary *PositionDict=[[NSMutableDictionary alloc]init]; 
       //setting the parts into dictionary 
       [PositionDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,0)] forKey:@"Parts_Name"]; 
       [Parts addObject:PositionDict]; 
       NSLog(@"%@",PositionDict); 
       [PositionDict release]; 
      } 
     } 
     // Release the compiled statement from memory 
     sqlite3_finalize(compiledStatement); 
    } 
    sqlite3_close(database); 
    return Parts; 
} 

答えて

0

てみFMDattabase(https://github.com/ccgus/fmdb)

BASIC:

FMDatabase *_db = [[FMDatabase databaseWithPath:[[self class] databaseFilePath]] retain]; 
    [_db open]; 

NSMutableArray *emails = [[NSMutableArray alloc] init]; 
NSString * query = [NSString stringWithFormat:@"SELECT `email` FROM `email`"]; 
FMResultSet * result = [_db executeQuery:query]; 
while ([result next]) 
{ 
    [emails addObject:[result stringForColumn:@"email"]]; 
} 
return [emails autorelease]; 
関連する問題