NSString *sql2 = SELECT COUNT(*) FROM `myTable`;
結果が 0 の場合、テーブルが空であることを意味します。
if (sqlite3_open([self.dataBasePath UTF8String], &articlesDB) == SQLITE_OK)
{
const char* sqlStatement = "SELECT COUNT(*) FROM MYTABLE";
sqlite3_stmt *statement;
if( sqlite3_prepare_v2(articlesDB, sqlStatement, -1, &statement, NULL) == SQLITE_OK )
{
//Loop through all the returned rows (should be just one)
while( sqlite3_step(statement) == SQLITE_ROW )
{
NSInteger count = sqlite3_column_int(statement, 0);
NSLog(@"Rowcount is %d",count);
}
}
else
{
NSLog( @"Failed from sqlite3_prepare_v2. Error is: %s", sqlite3_errmsg(articlesDB) );
}
// Finalize and close database.
sqlite3_finalize(statement);
sqlite3_close(articlesDB);
}