C++ 操作sqlite3数据库
来源:互联网 发布:吉视传媒网络宽带连接 编辑:程序博客网 时间:2024/06/05 07:41
C++ 操作sqlite3数据库
参考:
http://www.cnblogs.com/BoyXiao/archive/2012/03/31/2426495.html
http://blog.csdn.net/harry_lyc/article/details/6663176
http://www.sqlite.org/download.html
http://www.th7.cn/Program/cp/201209/91677.shtml
参考:
http://www.cnblogs.com/BoyXiao/archive/2012/03/31/2426495.html
http://blog.csdn.net/harry_lyc/article/details/6663176
http://www.sqlite.org/download.html
http://www.th7.cn/Program/cp/201209/91677.shtml
#include "stdafx.h"#include "sqlite3.h" #include <iostream> #include <sstream> using namespace std; sqlite3 * pDB; int createTable() { char* errMsg; std::string dropTab = "drop table test_tab;"; string strSQL= "create table test_tab (f1 int, f2 long);"; int res= sqlite3_exec(pDB , dropTab.c_str() , 0 , 0 , &errMsg); if (res != SQLITE_OK) { std::cout << "执行SQL 出错." << errMsg << std::endl; return -1; } res = sqlite3_exec(pDB , strSQL.c_str() ,0 ,0, &errMsg); if (res != SQLITE_OK) { std::cout << "执行创建table的SQL 出错." << errMsg << std::endl; return -1; } else { std::cout << "创建table的SQL成功执行."<< std::endl; } return 0; } int insert1() { char* errMsg; int res = sqlite3_exec(pDB,"begin transaction;",0,0, &errMsg); for (int i= 1; i < 10; ++i) { std::stringstream strsql; strsql << "insert into test_tab values("; strsql << i << ","<< (i+10) << ");"; std::string str = strsql.str(); res = sqlite3_exec(pDB,str.c_str(),0,0, &errMsg); if (res != SQLITE_OK) { std::cout << "执行插入SQL 出错." << errMsg << std::endl; return -1; } } res = sqlite3_exec(pDB,"commit transaction;",0,0, &errMsg); std::cout << "插入SQL成功执行."<< std::endl; return 0; } static int callback(void *NotUsed, int argc, char **argv, char **azColName) { for(int i = 0 ; i < argc ; i++) { std::cout << azColName[i] << " = " << (argv[i] ? argv[i] : "NULL") << ", " ; } std::cout<< "\n"; return 0; } int select1() { char* errMsg; string strSQL= "select * from test_tab;"; int res = sqlite3_exec(pDB, strSQL.c_str(), callback , 0 , &errMsg); if (res != SQLITE_OK) { std::cout << "执行查询SQL 出错." << errMsg << std::endl; return -1; } else { std::cout << "SQL查询成功执行."<< std::endl; } return 0; } int main() { int res = sqlite3_open("D:\\sql.db", &pDB); if( res ){ std::cout << "Can't open database: "<< sqlite3_errmsg(pDB); sqlite3_close(pDB); return -1; } res = createTable(); if (res != 0) { return 0; } res = insert1(); if (res != 0) { return 0; } select1(); return 0; }
- object-c操作数据库sqlite3
- SQLite3 数据库基本操作
- sqlite3数据库操作
- SQLite3数据库操作语法
- sqlite3 数据库命令操作
- sqlite3操作数据库
- iOS sqlite3 数据库操作
- SQLite3数据库的操作
- sqlite3数据库命令操作
- SQLITE3数据库操作
- C++ 操作sqlite3数据库
- sqlite3 数据库命令操作
- sqlite3 数据库命令操作
- QSqlDatabase操作数据库sqlite3
- sqlite3数据库操作小记
- sqlite3数据库操作
- SQLite3数据库操作入门
- SQLite3数据库操作
- 大数n的阶乘
- Ubuntu下android开发之配置USB设备
- Sqlserver表类型和表变量
- SQL_Server_2005_日期和时间函数(描述及实例) (转)
- Visual Studio 无法输入中文
- C++ 操作sqlite3数据库
- 动态分配和释放二维数组
- hdu-1013-Digital Roots
- C#调用非托管C++DLL中的函数
- nginx location常用语法
- UIApplication sharedApplication详细解释-IOS
- jquery 查询元素技巧
- Google中国2014校园招聘笔试Round A China New Grad Test Problem B. Rational Number Tree
- dwr框架报SecurityException异常的一个可能原因:类加载问题