http://hi.baidu.com/%C2%B7%C8%CB%BB%A8%D0%A1%B0%D7/blog/item/87cb6deed924581ffdfa3c3c.html
基本模式:
sqlite3 *db=NULL;
char *zErrMsg = NULL;
int rc;
rc = sqlite3_open(data_path, &db);
if( rc )
{
fprintf(stderr, "Can't open database: %s/n", sqlite3_errmsg(db));
sqlite3_close(db);
return NULL;
}
char *sql = " CREATE TABLE PageData(/
id INTEGER PRIMARY KEY,/
addr TEXT,/
title TEXT,/
time INTEGER,/
view_times INTEGER/
);" ;
sqlite3_exec( db , sql , 0 , 0 , &zErrMsg );
int nrow = 0, ncolumn = 0;
char **azResult; //二维数组存放结果
char *sqlcmd = "SELECT addr FROM PageData ORDER BY view_times DESC, time DESC";
rc = sqlite3_get_table( db , sqlcmd , &azResult , &nrow , &ncolumn , &zErrMsg );
if( rc!=SQLITE_OK )
{
fprintf(stderr, "SQL error: %s/n", zErrMsg);
sqlite3_free(zErrMsg);
}
sqlite3_free_table( azResult );
sqlite3_close(db);