2014-07-25 4 views
0

sqlite에서 데이터를 검색하려고합니다. 불행히도 테이블은 null 값으로 채워집니다. 콘솔에 FIRST ID RECUPERÉ : (null)이 표시됩니다. 당신의 의견을 좀주세요. tableauMsgReceivednil 경우 NSLog 문이 코드 주어진 결과입니다 줄 것이다sqlite에서 데이터 가져 오기

NSString * statementID = [NSString stringWithFormat:@"SELECT id_message FROM messages;"]; 
const char * sql_stmt_id = [statementID UTF8String]; 


sqlite3_stmt *compiledStatement; 

    if(sqlite3_prepare_v2(contactDB, sql_stmt_id, -1, &compiledStatement, NULL) == SQLITE_OK) 
    { 
     [tableauMsgReceived removeAllObjects]; 

     while(sqlite3_step(compiledStatement) == SQLITE_ROW) 
     { 
      [tableauMsgReceived addObject:[NSString stringWithFormat:@"%s",(char *) sqlite3_column_text(compiledStatement, 0)]]; 
      NSLog(@"First ID : %@", [tableauMsgReceived objectAtIndex:0]); 
     } 
    } 
    sqlite3_finalize(compiledStatement); 
} 
sqlite3_close(contactDB); 
+0

실행중인 SQL 문은 무엇입니까? 첫번째 신분증의 NSLog가 널을 출력한다고 말하는 겁니까? –

+0

자세한 내용을 입력해야합니다. 이 코드를 실행하면 실제로 어떻게됩니까? – rmaddy

+0

우리에게 sql_stmt_id를 보여주십시오. –

답변

0

유일한 방법 :

는 코드입니다. 데이터베이스가 성공적으로

if (sqlite3_open([YourDBPath UTF8String], &yourDatabase) == SQLITE_OK){} 

마지막 개방 여부를 모든

tableauMsgReceived = [[NSMutableArray alloc] init]; 
+0

당신 말이 맞아요. 그게 지금 작동합니다, 많이 감사합니다 – user3866054

+0

답변을 수락하는 것을 잊지 마십시오. – rmaddy

0

먼저, 그 다음

tableauMsgReceived = [[NSMutableArray alloc] init]; 

처럼 당신이했던 일을 확인 :

어딘가에 당신이 할 필요가 너 시도해 볼 수도있어

[tableauMsgReceived addObject:[NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, 0)]];