// sqtr.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
//#include "sqtr.h"
#include "sqlite3/sqlite3.h"
#include <windows.h>
#include <stdio.h>
#include <list>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <iostream>
#include "SQLiteWrapper.h"
using namespace std;
//#include <boost/lambda/lambda.hpp>
//#include <iterator>
//#include <boost/thread.hpp>
typedef list<char*> List_Char;
int db_fun(sqlite3 *pDB , List_Char *slist)
{
int result = 0;
//sqlite3 *pDB = NULL;
char* err_msg = NULL;
char* databaseName="test2.db3";
/*int rc = sqlite3_open(databaseName, &pDB);
sqlite3_close(pDB);*/
//int rc = sqlite3_open(databaseName, &pDB);
// 执行SQL
__int64 t1, t2, tc;
QueryPerformanceCounter((LARGE_INTEGER *)&t1);
int rc = sqlite3_exec(pDB, "BEGIN;", 0, 0, &err_msg);
//添加10条记录
for (List_Char::iterator s = slist->begin(); s!=slist->end(); s++)
{
// 执行SQL
char *sql = *s;//"INSERT INTO test_for_cpp(id, name, age) VALUES(1, 'asdf', 25)";
if (sqlite3_exec(pDB, sql, NULL, NULL, &err_msg) != SQLITE_OK)
{
printf("操作失败,错误代码: %s", err_msg);
//删除出错行,重新commit此队列
rc = sqlite3_exec(pDB, "ROLLBACK;", 0, 0, &err_msg);
slist->remove(*s);
db_fun(pDB , slist);
break;
//return 0;
}
}
rc = sqlite3_exec(pDB, "COMMIT;", 0, 0, &err_msg);
QueryPerformanceCounter((LARGE_INTEGER *)&t2);
QueryPerformanceFrequency((LARGE_INTEGER *)&tc);
float diff = (t2 - t1) / tc;
printf("用时: %f", diff);
return result;
}
DWORD WINAPI Thread_WriteData(LPVOID lpParam)
{
//sqlite3 *pDB = (sqlite3*)lpParam;
int i = (int)lpParam;
char* db_name = "";
char tmp_arr[25];
//itoa(i,tmp_arr,10);
sprintf(tmp_arr,"%d.db3",i);
db_name = tmp_arr;
//strcpy(db_name, tmp_arr);
sqlite3 *pDB = NULL;
char* err_msg = NULL;
char* databaseName=db_name;
int rc = sqlite3_open(databaseName, &pDB);
/*char* sql = "CREATE TABLE test_for_cpp(id int, name varchar(20), age int)";
if (sqlite3_exec(pDB, sql, NULL, NULL, &err_msg) != SQLITE_OK)
{
printf("操作失败,错误代码: %s", err_msg);
return 0;
}*/
if (sqlite3_exec(pDB, "PRAGMA journal_mode=WAL;", NULL, NULL, &err_msg) != SQLITE_OK) {
printf("操作失败,错误代码: %s", err_msg);
return 0;
}
if (sqlite3_exec(pDB, "PRAGMA cache_size=5000;", NULL, NULL, &err_msg) != SQLITE_OK) {
printf("操作失败,错误代码: %s", err_msg);
return 0;
}
if (sqlite3_exec(pDB, "PRAGMA temp_store=MEMORY;", NULL, NULL, &err_msg) != SQLITE_OK) {
printf("操作失败,错误代码: %s", err_msg);
return 0;
}
//开启此参数能提高处理速度,但是系统意外断电时数据文件可能会损坏
/*if (sqlite3_exec(pDB, "PRAGMA synchronous = OFF;", NULL, NULL, &err_msg) != SQLITE_OK) {
printf("操作失败,错误代码: %s", err_msg);
return 0;
}*/
List_Char *slist = new List_Char;
for(int i=0;i<10000;i++)
{
char* sql = "INSERT INTO test_for_cpp(id, name, age) VALUES(1, 'asdf', 25)";
slist->push_back(sql);
if(i==8000)
{
char* sql = "INSERT INTO test_for_cpp2(id, name, age) VALUES(1, 'asdf', '25')";
slist->push_back(sql);
}
}
int rst = db_fun(pDB , slist);
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
/*SQLiteWrapper sqlite;
if (sqlite.Open("SQLiteWrapper.db")) {
std::cout << "SQLiteWrapper.db created or opened" << std::endl;
}
else {
std::cout << "couldn't open SQLiteWrapper.db" << std::endl;
}
if (sqlite.DirectStatement("create table foo (bar, baz)")) {
std::cout << "table foo created" << std::endl;
}
else {
std::cout << "Couldn't create table foo" << std::endl;
}
if (sqlite.Open("SQLiteWrapper.db3")) {
std::cout << "SQLiteWrapper.db3 created or opened" << std::endl;
}
else {
std::cout << "couldn't open SQLiteWrapper.db" << std::endl;
}*/
// __int64 t1, t2, tc;
// QueryPerformanceCounter((LARGE_INTEGER *)&t1);
// for(int i=0;i<100;i++)
// {
// SQLiteStatement* stmt = sqlite.Statement("insert into foo values (?, ?)");
// if (stmt->Bind(0, 3)) {
// std::cout << "value 3 successfully bound at pos 0" << std::endl;
// }
// else {
// std::cout << "value 3 NOT successfully bound at pos 0: " << sqlite.LastError() << std::endl;
// }
// if (stmt->Bind(1, 4)) {
// std::cout << "value 4 successfully bound at pos 1" << std::endl;
// }
// else {
// std::cout << "value 4 NOT successfully bound at pos 1:" << sqlite.LastError() << std::endl;
// }
// // ******************************** Executing 1st time
// if (stmt->Execute()) {
// std::cout << "statement executed" << std::endl;
// }
// else {
// std::cout << "error executing statement: " << sqlite.LastError() << std::endl;
// }
// if (stmt->Bind(0, 5)) {
// std::cout << "value 5 successfully bound at pos 0" << std::endl;
// }
// else {
// std::cout << "value 5 NOT successfully bound at pos 0" << std::endl;
// }
// if (stmt->Bind(1, 6)) {
// std::cout << "value 6 successfully bound at pos 1" << std::endl;
// }
// else {
// std::cout << "value 6 NOT successfully bound at pos 1" << std::endl;
// }
// // ******************************** Executing 2nd time
// if (stmt->Execute()) {
// std::cout << "statement executed" << std::endl;
// }
// else {
// std::cout << "error executing statement: " << sqlite.LastError() << std::endl;
// }
//}
//
//QueryPerformanceCounter((LARGE_INTEGER *)&t2);
//QueryPerformanceFrequency((LARGE_INTEGER *)&tc);
//float diff = (t2 - t1) / tc;
//printf("用时: %f", diff);
//int rst = db_fun();
//1处理多线程中的消息,消息为ftp到3,入队操作,返回消息;消息为comet到4,http操作,返回消息
//2打开文件 开辟5W长度的操作[写]队列 开启定时器 block队列
//3定时器时间满则做入库操作 release队列,若队列满后关闭文件,丢给执行文件上传线程,回到2,
//4Comet上传
//模拟测试
//DWORD ThreadID;
//for(int i=1; i < 3; i++ )
//{
// HANDLE h_thread = CreateThread(
// NULL, // default security attributes
// 0, // default stack size
// (LPTHREAD_START_ROUTINE) Thread_WriteData,
// (LPVOID)i, // no thread function arguments
// 0, // default creation flags
// &ThreadID); // receive thread identifier
// if( h_thread == NULL )
// {
// printf("CreateThread error: %d\n", GetLastError());
// return 1;
// }
//}
/*using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " " );*/
Sleep(5000);
//rc = sqlite3_close(pDB);
return 0;
}
分享到:
相关推荐
最全的sq1魔方公式,希望大家喜欢.大家互相多支持一下。
艾伦赫塞SQ系列调音台模拟软件,PC端控制软件,支持SQ5,SQ6,SQ7
SQ9910是高亮度通用LED驱动器。它是一款高效脉冲调光LED驱动控制集成电路。
一个替代MiniTab,JMP等专业统计软件的大部分功能的Excel统计插件! 它的特点小巧,易用,实用. 由鹰蛇工作室与6SQ.Net共同合作完成。 完全是国产的专业统计软件. 命名为"6SQ统计
web网页资源SQ_RENweb网页资源SQ_RENweb网页资源SQ_RENweb网页资源SQ_RENweb网页资源SQ_RENweb网页资源SQ_RENweb网页资源SQ_REN
SQ脚本
图形控件SQ_REN
台湾SQ公司的数字控制芯片,在数字图象控制方面有很强大的功能,这是SQ606的详细资料
芯圣SQ015L单片机的定时器中断程序,简单易懂,明了
广联达加密锁最终稳定版SQ1 7 rar 13 36MB
1. 项目简介 名称:简易QQ SQ 仿照QQ,完成一个简单的即时通讯系统. 使用技术: 1.数据库技术 2.windows Forms技术 3.网络通讯技术 TcpListener TcpClient 实现的功能:...
JSP网站开发SQ论文。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
pentaho 社区版的数据库在换到mysql以后,缺少sample data数据库的创建语句,这个sql就是用来做这件事的。
著名的SQ3R学习法,讲得非常清楚,帮助更好的学习新知识。
ApizzaSQ-v2.1.1 API接口本地测试,免费版支持2人协作
2020年3月A&H SQ-7调音台升级固件包,SQ-7具备同样强大的XCVI 96kHz FPGA引擎,并且添加了额外的控制和I/O,其体积更大,拥有33个推子、32个本地前置放大器、16个自定义软按键和8个用户可定义的软旋钮控制。
SQ.apk.1
2020年3月A&H SQ-6调音台升级固件包,SQ-6则提供24个前置放大器和25个推子,可以通过一系列远程扩展器扩展至48路输入,并都具备一个音频联网插槽,可插入Dante、Waves和其他协议的音频卡,便于进行系统集成、主扩/...
SAP-Query(SQ01SQ02SQ03)报表-业务顾问版.docx
sap中sq01的使用方法.docx