如何从iphonesqlite数据库获取int数据
我从iphonesqlite获取的数据如下。表中有6条记录 “我的表”中有字段“响应\ Id”、“参与者\ Id”、“回答\选项”、“回答\文本”、“更新\日期\时间”,除响应\ Id和参与者\ Id外,所有字段均为varchar字段) 当我记录数据时,它不会显示任何东西 看看这个问题。查询的所有结果值都在此处定义。 您可以对整数使用如何从iphonesqlite数据库获取int数据,iphone,xcode,sqlite,Iphone,Xcode,Sqlite,我从iphonesqlite获取的数据如下。表中有6条记录 “我的表”中有字段“响应\ Id”、“参与者\ Id”、“回答\选项”、“回答\文本”、“更新\日期\时间”,除响应\ Id和参与者\ Id外,所有字段均为varchar字段) 当我记录数据时,它不会显示任何东西 看看这个问题。查询的所有结果值都在此处定义。 您可以对整数使用sqlite3\u column\u int,类似于对文本使用sqlite3\u column\u text。查询的所有结果值都在此处定义。 NSNumber *p
sqlite3\u column\u int
,类似于对文本使用sqlite3\u column\u text
。查询的所有结果值都在此处定义。
NSNumber *primaryKey = [NSNumber numberWithInt:(int)sqlite3_column_int(selectstmt, 0)];
您可以对与文本类似的整数使用
sqlite3\u column\u int
,sqlite3\u column\u text
是否显示计数为0?它是否向上显示log语句它是否显示count is=0?你能为这次行动详细说明一下吗?谢谢你能为这次行动详细说明一下吗?谢谢
NSNumber *primaryKey = [NSNumber numberWithInt:(int)sqlite3_column_int(selectstmt, 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......