2011-12-27 1 views
1

SELECT 문이 올바르게 작동하지 않는 이유가 매우 혼란 스럽습니다. 그것은 나에게 어떤 오류도주지 않고 그냥 null을 반환합니다. 나는 그것이 정확하게 문자열을 쓰고 있고 올바른 문자열이 있다는 것을 알고있다, 그것은 정확하게 그것을 정확하게 읽지 않는다. 내가 아는 한 모든 것은 정확하다. 왜냐하면 나는 이것과 비슷한 많은 다른 메소드/함수에 대해 같은 SQLstmt "메소드"를 사용하기 때문이다. 이것은 왜 작동하지 않아야하는지에 대해 이해하지 못합니다.iOS sqlite는 SELECT 문을 사용할 때 NULL을 반환합니다.

- (NSString *)returnNote { 
    selStmt=nil; 

    NSLog(@"Reading note"); 

    NSString *SQLstmt = [NSString stringWithFormat:@"SELECT 'Notes' FROM '%@' WHERE Exercises = '%@';", currentRoutine, currentExercise]; 

    // Build select statements 
    const char *sql = [SQLstmt UTF8String]; 

    if (sqlite3_prepare_v2(database, sql, -1, &selStmt, NULL) != SQLITE_OK) { 
     selStmt = nil; 
    } 

    // Building select statement failed 
    if (!selStmt) { 
     NSAssert1(0, @"Can't build SQL to read Exercises [%s]", sqlite3_errmsg(database)); 
    } 

    NSString *note = [NSString stringWithFormat:@"%s", sqlite3_column_text(selStmt, 0)]; 

    sqlite3_reset(selStmt); // reset (unbind) statement 

    return note; 
} 

답변

1

sqlite3_step을 호출하지 않았습니다. 명령문이 실행되지 않습니다.

+0

SQLite C/C++ [소개] (http://www.sqlite.org/cintro.html)는 읽을 가치가 있습니다. –

+0

ty는 매력처럼 작동합니다. 실제로는 붙여 넣기를 복사 할 때 일어나는 현상입니다. SQLite relaly가 어떻게 작동하는지 x_x 슬픈 부분은 이전에도 단계 함수를 사용했기 때문입니다. – kgaidis

0
NSString *querySQLS1 = [NSString stringWithFormat: @"SELECT Notes FROM \"%@\" where Exercises=\"%@\"", currentRoutine, currentExercise]; 
    sqlite3_stmt *statements; 
    const char *query_stmts1 = [querySQLS1 UTF8String]; 

    if(sqlite3_prepare_v2(UsersDB, query_stmts1, -1, &statement, NULL) == SQLITE_OK) 
    { 
     NSLog(@"in prepare"); 
     if (sqlite3_step(statement) == SQLITE_ROW) 
     { 
      NSLog(@"Query executed"); 

     } 
     else { 
      NSLog(@"in else"); 
     } 

     sqlite3_finalize(statement); 
    } 
관련 문제