Iphone 当使用SELECT语句时,iOS sqlite将返回NULL
我很困惑SELECT语句为什么不能正常工作。它没有给我任何错误,只是返回null。我知道它写的字符串是正确的,正确的字符串就在那里,只是读得不正确。据我所知,一切都是正确的,因为我对许多其他类似的方法/函数使用相同的SQLstmt“方法”。这一条根本不理解为什么它不应该起作用Iphone 当使用SELECT语句时,iOS sqlite将返回NULL,iphone,ios,xcode,sqlite,select,Iphone,Ios,Xcode,Sqlite,Select,我很困惑SELECT语句为什么不能正常工作。它没有给我任何错误,只是返回null。我知道它写的字符串是正确的,正确的字符串就在那里,只是读得不正确。据我所知,一切都是正确的,因为我对许多其他类似的方法/函数使用相同的SQLstmt“方法”。这一条根本不理解为什么它不应该起作用 - (NSString *)returnNote { selStmt=nil; NSLog(@"Reading note"); NSString *SQLstmt = [NSString str
- (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;
}
你没打电话。该语句从未执行。您没有呼叫。该语句从未执行。SQLite C/C++可能值得一读。ty就像一个符咒一样工作,是的,当你主要复制粘贴时会发生这种情况-你不知道SQLite是如何工作的x_x不幸的是,我以前也使用过step函数。SQLite C/C++可能值得一读。ty就像一个符咒一样工作,是的,这就是当你主要复制粘贴时会发生的事情——你不知道SQLite是如何工作的,可悲的是我以前也使用过step函数。
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);
}