1

私はこのようなiphonesqliteからデータを取得しています。テーブルに6つのレコードがあります。

私のテーブルには、responses_Id、participant_Id、answer_option、answer_text、update_date_timeのフィールドがあり、responses_Idとparticipant_Idを除くすべてがvarcharフィールドです)

    + (void) getInitialDataToDisplay:(NSString *)dbPath {

CereniaAppDelegate *appDelegate = (CereniaAppDelegate *)[[UIApplication sharedApplication] delegate];

if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {

    const char *sql = "select * from survey_question_responses";
    sqlite3_stmt *selectstmt;
    if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {

        while(sqlite3_step(selectstmt) == SQLITE_ROW) {

            NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
            Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:primaryKey];
                            coffeeObj.participant_Id=(This is integerin table)
            coffeeObj.answer_option = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
            coffeeObj.answer_option = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)];
            coffeeObj.answer_option = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 4)];
            coffeeObj.answer_option = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 5)];

            NSString*test=coffeeObj.answer_option;



            [appDelegate.coffeeArray addObject:coffeeObj];

            int count=[appDelegate.coffeeArray count];

            NSLog(test);
            NSLog(@"count is %d",count);


            [coffeeObj release];
        }
    }
    }
else
    sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
  }

データをNSlogすると、何も表示されません。

4

3 に答える 3

3

SQLite ドキュメントを参照してください。クエリからのすべての結果値はそこで定義されます。テキストsqlite3_column_intと同様に整数に使用できますsqlite3_column_text

于 2012-09-05T06:58:30.173 に答える
2
NSNumber *primaryKey = [NSNumber numberWithInt:(int)sqlite3_column_int(selectstmt, 0)];
于 2012-09-05T07:01:55.250 に答える
0
while(sqlite3_step(selectAllStmt) == SQLITE_ROW)
        {
            NSLog(@"record found");
            char *temp = (char *)sqlite3_column_text(selectAllStmt, 0);
            if (temp!=nil) {
                intId=[[NSString stringWithUTF8String:temp] intValue];
            }
            temp =NULL;
            // [pool release];
        }

+ (void) getInitialDataToDisplay:(NSString *)dbPath {

CereniaAppDelegate *appDelegate = (CereniaAppDelegate *)[[UIApplication sharedApplication] delegate];

if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {

    const char *sql = "select * from survey_question_responses";
    sqlite3_stmt *selectstmt;
    if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {

        while(sqlite3_step(selectstmt) == SQLITE_ROW) {
    NSInteger primaryKey;
NSInteger intparticipant_Id;


            char *temp = (char *)sqlite3_column_text(selectstmt, 0);
            if (temp!=nil) {
                primaryKey=[[NSString stringWithUTF8String:temp] intValue];
            }
            temp =NULL;
            Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:primaryKey];


temp = (char *)sqlite3_column_text(selectstmt, 1);
            if (temp!=nil) {
                intparticipant_Id=[[NSString stringWithUTF8String:temp] intValue];
            }
            temp =NULL;
                            coffeeObj.participant_Id=intparticipant_Id;

            coffeeObj.answer_option = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
            coffeeObj.answer_option = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)];
            coffeeObj.answer_option = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 4)];
            coffeeObj.answer_option = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 5)];

            NSString*test=coffeeObj.answer_option;



            [appDelegate.coffeeArray addObject:coffeeObj];

            int count=[appDelegate.coffeeArray count];

            NSLog(test);
            NSLog(@"count is %d",count);


            [coffeeObj release];
        }
    }
    }
else
    sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
  }


Note:- char *temp = (char *)sqlite3_column_text(selectAllStmt, 0);
            if(temp != NULL)
                str = [NSString stringWithUTF8String:temp];
            else
                str = @"";
            temp =NULL;

If you want to take integer then you can do type casting "str = [NSString stringWithUTF8String:temp];" here......
于 2012-09-05T07:38:19.807 に答える