如果sqlite数据库中有任何数据,如何签入iphone应用程序
如何在应用程序启动时检查sqlite中是否有数据如果数据库中有数据,则应上传其他信息以正常工作应用程序 我将使用post和php上传这些数据到服务器如果sqlite数据库中有任何数据,如何签入iphone应用程序,iphone,xcode,web-services,Iphone,Xcode,Web Services,如何在应用程序启动时检查sqlite中是否有数据如果数据库中有数据,则应上传其他信息以正常工作应用程序 我将使用post和php上传这些数据到服务器 + (void) getInitialDataToDisplay:(NSString *)dbPath { CereniaAppDelegate *appDelegate = (CereniaAppDelegate *)[[UIApplication sharedApplication] delegate]; if (sqlite3_
+ (void) getInitialDataToDisplay:(NSString *)dbPath {
CereniaAppDelegate *appDelegate = (CereniaAppDelegate *)[[UIApplication sharedApplication] delegate];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
const char *sql = "select response_Id,question_id,answer_option,answer_text,update_date_time 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.question_Id = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
coffeeObj.answer_text = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
coffeeObj.answer_option = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,3)];
coffeeObj.update_date_time = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 4)];
int count=[appDelegate.coffeeArray count];
NSLog(@"count is beofore getting values %d",count);
[appDelegate.coffeeArray addObject:coffeeObj];
int countone=[appDelegate.coffeeArray count];
NSLog(@"count is after getting values %d",countone);
[coffeeObj release];
}
}
}
else
sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
}
您可以通过以下方式获取数据库中的行数:
SELECT COUNT(*) FROM table;
如果返回0,则表为空
//更新
const char *sqlQuery="Select count(*)from yourTable";
if(sqlite3_prepare_v2(database, sqlQuery, -1, &queryStatement, NULL)==SQLITE_OK)
{
while (sqlite3_step(queryStatement)==SQLITE_ROW)
{
const char *count=(const char *)sqlite3_column_text(queryStatement, 0);
NSString *rowCount=[NSString stringWithCString:count encoding:NSASCIIStringEncoding];
//here you will get the number of rows in string format;
}
}
您可以启动Select*查询并检查数据是否存在……这意味着我必须用其他方法编写此查询我在发布之前已经测试了此代码。请显示您的NSLog语句。为什么要将计数作为字符串而不是整数?此外,您也不会清理语句对象。