sqlite获取数据库总行数
static char *table_report = "db_report";
char sql[MAX_CHAR_REPORT_LEN];
int rows = 0;
int ret = 0;
sqlite3 *con;
if(access(table_report, 0) == -1)
{
return -1;
}
ret = sqlite3_open (table_report, &con);
if (ret != SQLITE_OK)
{
sqlite3_close (con);
return -1;
}
sprintf(sql, "select count(*) from %s", table_report);
sqlite3_stmt *countstmt;
if(sqlite3_prepare_v2(con, sql, -1, &countstmt, NULL) == SQLITE_OK) {
while (sqlite3_step(countstmt)==SQLITE_ROW) {
rows = sqlite3_column_int(countstmt,0);
sqlite3_finalize(countstmt);
sqlite3_close(con);
return rows;
}
}