- <一> 表的检测,创建,删除。
-
- #include <stdio.h>
- #include <stdbool.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sqlite3.h>
-
- bool db_tableExists(sqlite3 *db, const char *tbname)
- {
- int nRet;
- const char *szTail;
- sqlite3_stmt *pvm;
- char sql[1024];
- sprintf(sql, "select count(*) from sqlite_master where type="table" and name="%s"", tbname);
-
- szTail=0;
-
- nRet = sqlite3_prepare(db, sql, -1, &pvm, &szTail);
-
- //printf("nRet=%d SQLITE_OK=%d SQLITE_DONE=%d SQLITE_ROW=%d
", nRet, SQLITE_OK, SQLITE_DONE,SQLITE_ROW);
-
- if (nRet==SQLITE_OK)
- {
- nRet=sqlite3_step(pvm);
-
- //printf("nRet=%d SQLITE_OK=%d SQLITE_DONE=%d SQLITE_ROW=%d
", nRet, SQLITE_OK, SQLITE_DONE,SQLITE_ROW);
-
- if (nRet==SQLITE_ROW)
- {
- int nCols = sqlite3_column_count(pvm);
- //printf("nCols:%d
", nCols);
- if (nCols>=1)
- {
- return sqlite3_column_int(pvm,0)!=0;
- }
- }
- }
-
- return false;
- }
-
- int db_exeDML(sqlite3 *db, const char *sql)
- {
- char* szError=0;
- int nRet = sqlite3_exec(db, sql, 0, 0, &szError);
- if (nRet == SQLITE_OK)
- {
- return sqlite3_changes(db);
- }
- return SQLITE_ERROR;
- }
-
-
- int main(int argc, char **argv)
- {
-
- sqlite3 *db=0;
- int nRet = sqlite3_open("temp.db",&db);
-
- if (nRet)
- {
- fprintf(stderr,"can"t open database: %s
",sqlite3_errmsg(db));
- sqlite3_close(db);
- exit(1);
- }else{
- printf("open database ok.
");
- }
-
- if (!db_tableExists(db,"tmp"))
- {
- printf("create "tmp" table
");
- nRet=db_exeDML(db,"CREATE TABLE tmp( IP TEXT, VER TEXT, UID TEXT, FILE TEXT)");
- printf("nRet=%d
", nRet);
- }else{
- nRet=db_exeDML(db,"delete from tmp");
- printf("nRet=%d
", nRet);
- }
-
- sqlite3_close(db);
-
- return 0;
- }
Oracle基础教程之安装Oracle 11g软件及示例方案Linux 下的 SQLite3 的安装相关资讯 sqlite
- Ubuntu 16.04 安装可视化数据库浏 (05月20日)
- iOS 数据库比较:SQLite vs. Core (03月01日)
- 如何在 Ubuntu 15.04 上安装带 (02月09日)
| - 微软推荐通用 Windows 应用开发者 (05月04日)
- SQLite 3.11.0 发布下载 (02月17日)
- SQLite 3.10.2 发布下载 (01月29日)
|
本文评论 查看全部评论 (0)