查看db文件类型
~/Desktop/sqlite# file pkg.db
pkg.db: sqlite 3.x database
sqlite3 pkg.db
sqlite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter sql statements terminated with a ";"
sqlite>
查看所有数据库
sqlite>.database
查看所有表
查看表结构
sqlite> .schema package
CREATE TABLE package(
pkgname text not null,
version text,
depname text,
depversion text,
deplimit text
);
sqlite>select * from package;
代码:
//gcc readdb.c sqlite3.c -o read -lpthread -ldl int main( void ) { sqlite3 *db = NULL; char *errmsg = 0; int row = 0,column = 0; int i = 0; char **result; if(sqlITE_OK != sqlite3_open("pkg.db",&db)) { fprintf(stderr,"Can't open database: %s\n",sqlite3_errmsg(db)); sqlite3_close(db); return -1; } char *sql="select * from package"; sqlite3_get_table(db,sql,&result,&row,&column,&errmsg); printf("row:%d column:%d\n",row,column); for(i=0; i < (row + 1) * column; i++) { printf("%s\n",result[i]); } sqlite3_free_table(result); sqlite3_close(db); return 0; }原文链接:https://www.f2er.com/sqlite/199235.html