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
SQLite.cpp 6.41 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
/********************************************************************
filename: SQLite.cpp
created: 2015年6月01日
author: poisson
purpose: SQLite数据库操作类
*********************************************************************/
#include "../stdafx.h"
#include "SQLite.h"
const char* WcharToUtf8(const wchar_t *pwStr)
{
if (pwStr == NULL)
{
return NULL;
}
int len = WideCharToMultiByte(CP_UTF8, 0, pwStr, -1, NULL, 0, NULL, NULL);
if (len <= 0)
{
return NULL;
}
char *pStr = new char[len];
WideCharToMultiByte(CP_UTF8, 0, pwStr, -1, pStr, len, NULL, NULL);
return pStr;
}
const wchar_t* Utf8ToWchar(const char *pStr)
{
if (pStr == NULL)
{
return NULL;
}
int len = MultiByteToWideChar(CP_UTF8, 0, pStr, -1, NULL, 0);
if (len <= 0)
{
return NULL;
}
wchar_t *pwStr = new wchar_t[len];
MultiByteToWideChar(CP_UTF8, 0, pStr, -1, pwStr, len);
return pwStr;
}
SQLite::SQLite(void):
m_db(NULL)
{
}
SQLite::~SQLite(void)
{
Close();
}
BOOL SQLite::Open(LPCTSTR lpDbFlie)
{
if(lpDbFlie == NULL)
{
return FALSE;
}
#ifdef UNICODE
if(sqlite3_open16(lpDbFlie,&m_db) != SQLITE_OK)
#else
if(sqlite3_open(lpDbFlie,&m_db) != SQLITE_OK)
#endif
{
return FALSE;
}
return TRUE;
}
void SQLite::Close()
{
if(m_db)
{
sqlite3_close(m_db);
m_db = NULL;
}
}
BOOL SQLite::ExcuteNonQuery(LPCTSTR lpSql)
{
if(lpSql == NULL)
{
return FALSE;
}
sqlite3_stmt* stmt;
#ifdef UNICODE
if(sqlite3_prepare16_v2(m_db, lpSql, -1, &stmt, NULL) != SQLITE_OK)
#else
if(sqlite3_prepare_v2(m_db, lpSql, -1, &stmt, NULL) != SQLITE_OK)
#endif
{
return FALSE;
}
sqlite3_step(stmt);
return (sqlite3_finalize(stmt) == SQLITE_OK) ? TRUE : FALSE ;
}
BOOL SQLite::ExcuteNonQuery(SQLiteCommand* pCmd)
{
if(pCmd == NULL)
{
return FALSE;
}
return pCmd->Excute();
}
// 查询(回调方式)
BOOL SQLite::ExcuteQuery(LPCTSTR lpSql,QueryCallback pCallBack)
{
if(lpSql == NULL || pCallBack == NULL)
{
return FALSE;
}
char *errmsg = NULL;
#ifdef UNICODE
const char *szSql = WcharToUtf8(lpSql);
if(sqlite3_exec(m_db, szSql, pCallBack, NULL, &errmsg) != SQLITE_OK)
{
delete[] szSql;
return FALSE;
}
delete[] szSql;
#else
if(sqlite3_exec(m_db, lpSql, pCallBack, NULL, &errmsg) != SQLITE_OK)
{
return FALSE;
}
#endif
return TRUE;
}
// 查询
SQLiteDataReader SQLite::ExcuteQuery(LPCTSTR lpSql)
{
if(lpSql == NULL)
{
return FALSE;
}
sqlite3_stmt* stmt;
#ifdef UNICODE
if(sqlite3_prepare16_v2(m_db, lpSql, -1, &stmt, NULL) != SQLITE_OK)
#else
if(sqlite3_prepare_v2(m_db, lpSql, -1, &stmt, NULL) != SQLITE_OK)
#endif
{
return FALSE;
}
return SQLiteDataReader(stmt);
}
// 开始事务
BOOL SQLite::BeginTransaction()
{
char * errmsg = NULL;
if(sqlite3_exec(m_db,"BEGIN TRANSACTION;",NULL,NULL,&errmsg) != SQLITE_OK)
{
return FALSE;
}
return TRUE;
}
// 提交事务
BOOL SQLite::CommitTransaction()
{
char * errmsg = NULL;
if(sqlite3_exec(m_db,"COMMIT TRANSACTION;;",NULL,NULL,&errmsg) != SQLITE_OK)
{
return FALSE;
}
return TRUE;
}
// 回滚事务
BOOL SQLite::RollbackTransaction()
{
char * errmsg = NULL;
if(sqlite3_exec(m_db,"ROLLBACK TRANSACTION;",NULL,NULL,&errmsg) != SQLITE_OK)
{
return FALSE;
}
return TRUE;
}
// 获取上一条错误信息
LPCTSTR SQLite::GetLastErrorMsg()
{
#ifdef UNICODE
return (LPCTSTR)sqlite3_errmsg16(m_db);
#else
return sqlite3_errmsg(m_db);
#endif
}
SQLiteDataReader::SQLiteDataReader(sqlite3_stmt *pStmt):
m_pStmt(pStmt)
{
}
SQLiteDataReader::~SQLiteDataReader()
{
Close();
}
// 读取一行数据
BOOL SQLiteDataReader::Read()
{
if(m_pStmt == NULL)
{
return FALSE;
}
if(sqlite3_step(m_pStmt) != SQLITE_ROW)
{
return FALSE;
}
return TRUE;
}
// 关闭Reader,读取结束后调用
void SQLiteDataReader::Close()
{
if(m_pStmt)
{
sqlite3_finalize(m_pStmt);
m_pStmt = NULL;
}
}
// 总的列数
int SQLiteDataReader::ColumnCount(void)
{
return sqlite3_column_count(m_pStmt);
}
// 获取某列的名称
LPCTSTR SQLiteDataReader::GetName(int nCol)
{
#ifdef UNICODE
return (LPCTSTR)sqlite3_column_name16(m_pStmt, nCol);
#else
return (LPCTSTR)sqlite3_column_name(m_pStmt, nCol);
#endif
}
// 获取某列的数据类型
SQLITE_DATATYPE SQLiteDataReader::GetDataType(int nCol)
{
return (SQLITE_DATATYPE)sqlite3_column_type(m_pStmt, nCol);
}
// 获取某列的值(字符串)
LPCTSTR SQLiteDataReader::GetStringValue(int nCol)
{
#ifdef UNICODE
return (LPCTSTR)sqlite3_column_text16(m_pStmt, nCol);
#else
return (LPCTSTR)sqlite3_column_text(m_pStmt, nCol);
#endif
}
// 获取某列的值(整形)
int SQLiteDataReader::GetIntValue(int nCol)
{
return sqlite3_column_int(m_pStmt, nCol);
}
// 获取某列的值(长整形)
long SQLiteDataReader::GetInt64Value(int nCol)
{
return (long)sqlite3_column_int64(m_pStmt, nCol);
}
// 获取某列的值(浮点形)
double SQLiteDataReader::GetFloatValue(int nCol)
{
return sqlite3_column_double(m_pStmt, nCol);
}
// 获取某列的值(二进制数据)
const BYTE* SQLiteDataReader::GetBlobValue(int nCol, int &nLen)
{
nLen = sqlite3_column_bytes(m_pStmt, nCol);
return (const BYTE*)sqlite3_column_blob(m_pStmt, nCol);
}
SQLiteCommand::SQLiteCommand(SQLite* pSqlite):
m_pSqlite(pSqlite),
m_pStmt(NULL)
{
}
SQLiteCommand::SQLiteCommand(SQLite* pSqlite,LPCTSTR lpSql):
m_pSqlite(pSqlite),
m_pStmt(NULL)
{
SetCommandText(lpSql);
}
SQLiteCommand::~SQLiteCommand()
{
}
BOOL SQLiteCommand::SetCommandText(LPCTSTR lpSql)
{
#ifdef UNICODE
if(sqlite3_prepare16_v2(m_pSqlite->m_db, lpSql, -1, &m_pStmt, NULL) != SQLITE_OK)
#else
if(sqlite3_prepare_v2(m_pSqlite->m_db, lpSql, -1, &m_pStmt, NULL) != SQLITE_OK)
#endif
{
return FALSE;
}
return TRUE;
}
BOOL SQLiteCommand::BindParam(int index, LPCTSTR szValue)
{
#ifdef UNICODE
if(sqlite3_bind_text16(m_pStmt, index, szValue, -1, SQLITE_TRANSIENT) != SQLITE_OK)
#else
if(sqlite3_bind_text(m_pStmt, index, szValue,-1, SQLITE_TRANSIENT) != SQLITE_OK)
#endif
{
return FALSE;
}
return TRUE;
}
BOOL SQLiteCommand::BindParam(int index, const int nValue)
{
if(sqlite3_bind_int(m_pStmt, index, nValue) != SQLITE_OK)
{
return FALSE;
}
return TRUE;
}
BOOL SQLiteCommand::BindParam(int index, const double dValue)
{
if(sqlite3_bind_double(m_pStmt, index, dValue) != SQLITE_OK)
{
return FALSE;
}
return TRUE;
}
BOOL SQLiteCommand::BindParam(int index, const unsigned char* blobBuf, int nLen)
{
if(sqlite3_bind_blob(m_pStmt, index, blobBuf,nLen,NULL) != SQLITE_OK)
{
return FALSE;
}
return TRUE;
}
BOOL SQLiteCommand::Excute()
{
sqlite3_step(m_pStmt);
return (sqlite3_reset(m_pStmt) == SQLITE_OK) ? TRUE : FALSE ;
}
void SQLiteCommand::Clear()
{
if(m_pStmt)
{
sqlite3_finalize(m_pStmt);
}
}
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 によって変換されたページ (->オリジナル) /