gpt4 book ai didi

iphone - 如何从iPhone sqlite数据库获取int数据

转载 作者:行者123 更新时间:2023-12-03 18:27:00 25 4
gpt4 key购买 nike

我从这样的iPhone sqlite获取数据。我在表中有6条记录。

我的表中包含字段response_Id,participant_Id,answer_option,answer_text,update_date_time,但所有字段均为varchar字段,responsing_Id和participant_Id除外)

    + (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数据时,它什么也没有显示。

最佳答案

查看SQLite Documentation。查询的所有结果值均在此处定义。
您可以将sqlite3_column_int用于整数,类似于sqlite3_column_text用于文本

关于iphone - 如何从iPhone sqlite数据库获取int数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12275965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com