Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 1 Fork 2

柏松/vc下的线程池

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
ThreadPooller
/
SQLiteOp
/
SQLite
/
SQLiteOp.cpp
ThreadPooller
/
SQLiteOp
/
SQLite
/
SQLiteOp.cpp
SQLiteOp.cpp 8.69 KB
Copy Edit Raw Blame History
柏松 authored 2018年01月04日 18:58 +08:00 . sqlite
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
// DBOp.cpp : 定义 DLL 应用程序的导出函数。
//
#include "../stdafx.h"
#include "SqliteOp.h"
#include <sstream>
#include "../BasicTool/CFileMgr.h"
#include "../BasicTool/cchinesecode.h"
// 这是已导出类的构造函数。
// 有关类定义的信息,请参阅 DBOp.h
CSqliteOp::CSqliteOp(std::string path)
{
m_path=path;
m_db=NULL;
}
bool CSqliteOp::IsIniDB()
{
if(m_path.length()<2)
return false;
return true;
}
sqlite3 *CSqliteOp::OpenSqlite()
{
sqlite3 *db=NULL;
sqlite3_open16(m_path.c_str(),&db);
return db;
}
void CSqliteOp::CloseSqlite(sqlite3 *db)
{
sqlite3_close(db);
}
CSqliteOp::~CSqliteOp(void)
{
}
//初始化DB
int CSqliteOp::InitDB(std::string &path)
{
int len=256;
wchar_t *pathstr=new wchar_t[len];
memset(pathstr,0,len);
CChineseCode::charTowchar(path.c_str(),pathstr,len);
// return 1;
CFileMgr mgr;
if(!mgr.IsExist((LPCTSTR)pathstr))
{
std::wstring patj(pathstr);
int ll=patj.find_last_of(_T("\\"));
if(ll>0)
patj=patj.substr(0,ll);
mgr.CreateDirectory((LPCTSTR)patj.c_str());
}
m_path=path;
sqlite3_open16(pathstr,&m_db);
delete pathstr;
// 打开或创建数据库
if(m_db==NULL)
{
return 0;
}
{
if(!IsTableExt(std::string("FileDownUpManage")))
{
std::stringstream bbcc;
bbcc<<"CREATE table FileDownUpManage(Id TEXT NOT NULL, Path TEXT,";
bbcc<<"FileSize NUMERIC,";
bbcc<<"DownUpSize NUMERIC,";
bbcc<<"DownUpType NUMERIC NOT NULL,";
bbcc<<"Finish NUMERIC,";
bbcc<<"StartTime NUMERIC,";
bbcc<<"EndTime NUMERIC,";
bbcc<<"Remark TEXT,primary key(Id,DownUpType))";
std::string sql=bbcc.str();
CreateTable(m_db,sql);
}
if(!IsTableExt(std::string("VidoFileMap")))
{
std::stringstream bbcc;
bbcc<<"CREATE table VidoFileMap(Path TEXT NOT NULL, AliasName TEXT,";
bbcc<<"id TEXT,";
bbcc<<"classId TEXT,";
bbcc<<"courseId TEXT,";
bbcc<<"courseUid TEXT,";
bbcc<<"courseName TEXT,";
bbcc<<"lecturer TEXT,";
bbcc<<"lecturerUid TEXT,";
bbcc<<"phase TEXT,";
bbcc<<"description TEXT,";
bbcc<<"grade NUMERIC,";
bbcc<<"subjectCode NUMERIC,";
bbcc<<"subjectName TEXT,";
bbcc<<"startTime TEXT,";
bbcc<<"endTime TEXT,";
bbcc<<"uid TEXT,";
bbcc<<"ctime TEXT,";
bbcc<<"type NUMERIC default 1,";
bbcc<<"strPhase TEXT,";
bbcc<<"strGrade TEXT,";
bbcc<<"strSubJect TEXT,";
bbcc<<"strbookVersion TEXT,";
bbcc<<"strUnit TEXT,";
bbcc<<"strLesson TEXT,";
bbcc<<"strPhaseName TEXT,";
bbcc<<"strGradeName TEXT,";
bbcc<<"strSubJectName TEXT,";
bbcc<<"strbookVersionName TEXT,";
bbcc<<"strUnitName TEXT,";
bbcc<<"strLessonName TEXT,";
bbcc<<"strBookId TEXT,";
bbcc<<"MD5 TEXT,";
//打算将来把主键改成MD5
//bbcc<<"primary key(MD5))";
bbcc<<"primary key(Path))";
std::string sql=bbcc.str();
CreateTable(m_db,sql);
}
}
return 1;
}
int CSqliteOp::IsTableExt(std::string &name)
{
IsIniDB();
sqlite3 *db=NULL;
sqlite3_open16(m_path.c_str(),&db);
// 打开或创建数据库
if(db==NULL)
{
return -1;
}
std::string sqltxt=std::string("SELECT count(*) as num FROM sqlite_master WHERE type='table' AND name='")+name+std::string("' ");
char** pResult=NULL;
int nRow=-1;
int nColumn=-1;
sqlite3_get_table(
db, /* An open database */
sqltxt.c_str() , /* SQL to be evaluated */
&pResult, /* Results of the query */
&nRow, /* Number of result rows written here */
&nColumn, /* Number of result columns written here */
NULL /* Error msg written here */
);
std::string strOut="";
int nIndex = nColumn;
if(nRow>-1&&nColumn>-1&&pResult!=NULL)
{
strOut+= pResult[nColumn];
}
sqlite3_free_table(pResult);
pResult=NULL;
int Ok=atoi(strOut.c_str());
//如果表不存在则创建
if(Ok<1)
{
return 0;
}
return 1;
}
int CSqliteOp::CreateTable(sqlite3 *db,std::string &sqltxt)
{
const char *sqlstr=sqltxt.c_str();
char errstr[256]={};
char *perrstr=errstr;
int result= sqlite3_exec(
db, /* An open database */
sqlstr,
NULL,
NULL,
&perrstr
);
if(SQLITE_OK!=result)
{
//输出sqlite3错误信息
//TRACE0(perrstr);
}
return result;
}
//执行sql操作
int CSqliteOp::SelectSql(sqlite3 *db,std::string &sqltxt,Json::Value &JsonResult)
{
JsonResult.clear();
std::string abc=sqltxt;
const char *sqlstr=abc.c_str();
std::map<int,std::string> strFiedType;
char** pResult;
int nRow=-1;
int nColumn=-1;
std::string strOut="";
int nIndex = nColumn;
//分析sql语句
sqlite3_stmt* stmt2 = NULL;
if (sqlite3_prepare_v2(db,sqlstr,strlen(sqlstr),&stmt2,NULL) != SQLITE_OK) {
if (stmt2)
sqlite3_finalize(stmt2);
return -1;
}
//7. 遍历结果集中每个字段meta信息,并获取其声明时的类型。
int fieldCount = sqlite3_column_count(stmt2);
for (int i = 0; i < fieldCount; ++i) {
//由于此时Table中并不存在数据,再有就是SQLite中的数据类型本身是动态的,所以在没有数据时
//无法通过sqlite3_column_type函数获取,此时sqlite3_column_type只会返回SQLITE_NULL,
//直到有数据时才能返回具体的类型,因此这里使用了sqlite3_column_decltype函数来获取表声
//明时给出的声明类型。
std::string stype = sqlite3_column_decltype(stmt2,i);
stype = strlwr((char*)stype.c_str());
//下面的解析规则见该系列的"数据类型-->1. 决定字段亲缘性的规则"部分,其链接如下:
//http://www.cnblogs.com/stephen-liu74/archive/2012/01/18/2325258.html
if (stype.find("numeric") != std::string::npos)
{
strFiedType.insert(std::pair<int,std::string>(i,"int"));
} else
if ( stype.find("char") != std::string::npos
|| stype.find("text") != std::string::npos)
{
strFiedType.insert(std::pair<int,std::string>(i,"string"));
} else
if (stype.find("real") != std::string::npos
|| stype.find("floa") != std::string::npos
|| stype.find("doub") != std::string::npos )
{
strFiedType.insert(std::pair<int,std::string>(i,"double"));
}else{
strFiedType.insert(std::pair<int,std::string>(i,"string"));
}
}
int result= sqlite3_get_table(
db, /* An open database */
sqlstr, /* SQL to be evaluated */
&pResult, /* Results of the query */
&nRow, /* Number of result rows written here */
&nColumn, /* Number of result columns written here */
NULL /* Error msg written here */
);
//读出sqlite数据
nIndex = nColumn;
for(int i=0;i<nRow;i++)
{
Json::Value JsonValue;
for(int j=0;j<nColumn;j++)
{
std::string stype=strFiedType[j];
if(stype.find("int") != std::string::npos)
{
char * ppp=pResult[j];
char * ppp2=pResult[nIndex];
if(ppp2==NULL)
ppp2="-1";
JsonValue[ppp]=atoi(ppp2);
//JsonValue[pResult[j]]=atoi(pResult[nIndex]);
}
if(stype.find("string") != std::string::npos)
{
char * ppp=pResult[j];
char * ppp2=pResult[nIndex];
if(ppp2==NULL)
ppp2="";
JsonValue[ppp]=ppp2;
}
if(stype.find("double") != std::string::npos)
{
JsonValue[pResult[j]]=atof(pResult[nIndex]);
}
++nIndex;
}
JsonResult.append(JsonValue);
}
sqlite3_free_table(pResult);
if (stmt2)
sqlite3_finalize(stmt2);
return 0;
}
int CSqliteOp::NoSelectSql(sqlite3 *db,std::string &sqltxt)
{
char** pResult;
int nRow=-1;
int nColumn=-1;
std::string strOut="";
int nIndex = nColumn;
const char *sqlstr=sqltxt.c_str();
//sqlite3_free_table()
int result= sqlite3_get_table(
db, /* An open database */
sqlstr, /* SQL to be evaluated */
&pResult, /* Results of the query */
&nRow, /* Number of result rows written here */
&nColumn, /* Number of result columns written here */
NULL /* Error msg written here */
);
//result != SQLITE_OK
return result;
}
// 开始事务
bool CSqliteOp::BeginTransaction(sqlite3 *db)
{
char * errmsg = NULL;
if(sqlite3_exec(db,"BEGIN TRANSACTION;",NULL,NULL,&errmsg) != SQLITE_OK)
{
return FALSE;
}
return TRUE;
}
// 提交事务
bool CSqliteOp::CommitTransaction(sqlite3 *db)
{
char * errmsg = NULL;
if(sqlite3_exec(db,"COMMIT TRANSACTION;;",NULL,NULL,&errmsg) != SQLITE_OK)
{
return FALSE;
}
return TRUE;
}
// 回滚事务
bool CSqliteOp::RollbackTransaction(sqlite3 *db)
{
char * errmsg = NULL;
if(sqlite3_exec(db,"ROLLBACK TRANSACTION;",NULL,NULL,&errmsg) != SQLITE_OK)
{
return FALSE;
}
return TRUE;
}
bool CSqliteOp::ExcuteNonQuery16(sqlite3 *db,wchar_t *lpSql)
{
if(lpSql == NULL)
{
return FALSE;
}
sqlite3_stmt* stmt;
if(sqlite3_prepare16_v2(db,(void*) lpSql, -1, &stmt, NULL) != SQLITE_OK)
{
return FALSE;
}
sqlite3_step(stmt);
return (sqlite3_finalize(stmt) == SQLITE_OK) ? TRUE : FALSE ;
}
bool CSqliteOp::ExcuteNonQuery(sqlite3 *db,char* lpSql)
{
if(lpSql == NULL)
{
return FALSE;
}
sqlite3_stmt* stmt;
if(sqlite3_prepare_v2(db, lpSql, -1, &stmt, NULL) != SQLITE_OK)
{
return FALSE;
}
sqlite3_step(stmt);
return (sqlite3_finalize(stmt) == SQLITE_OK) ? TRUE : FALSE ;
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/poisson/ThreadPooller.git
git@gitee.com:poisson/ThreadPooller.git
poisson
ThreadPooller
vc下的线程池
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /