-2

アプリの開始時にsqliteにデータがあるかどうかを確認する方法データがデータベースにある場合は、アップロードする必要があります。そうでなければ、アプリケーションは正常に動作します

このデータを post を使用してアップロードし、php for を使用してデータをサーバーにアップロードします。

     + (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.
       }
4

1 に答える 1

0

次の方法で、データベースに存在する行数を取得できます。

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;


        }

    }
于 2012-09-05T10:27:50.520 に答える