-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleDatabase_IDCard.cpp
More file actions
399 lines (377 loc) · 12.3 KB
/
ModuleDatabase_IDCard.cpp
File metadata and controls
399 lines (377 loc) · 12.3 KB
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
388
389
390
391
392
393
394
395
396
397
398
399
#include "pch.h"
#include "ModuleDatabase_IDCard.h"
/********************************************************************
// Created: 2022/03/04 14:24:12
// File Name: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleDatabase\ModuleDatabase_IDCard\ModuleDatabase_IDCard.cpp
// File Path: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleDatabase\ModuleDatabase_IDCard
// File Base: ModuleDatabase_IDCard
// File Ext: cpp
// Project: XEngine(网络通信引擎)
// Author: qyt
// Purpose: 身份证信息数据库操作
// History:
*********************************************************************/
CModuleDatabase_IDCard::CModuleDatabase_IDCard()
{
}
CModuleDatabase_IDCard::~CModuleDatabase_IDCard()
{
}
//////////////////////////////////////////////////////////////////////////
// 公有函数
//////////////////////////////////////////////////////////////////////////
/********************************************************************
函数名称:ModuleDatabase_IDCard_Init
函数功能:初始化SQLITE文件系统
参数.一:lpszSQLFile
In/Out:In
类型:常量字符指针
可空:N
意思:输入要操作的SQL文件
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CModuleDatabase_IDCard::ModuleDatabase_IDCard_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector)
{
DBModule_IsErrorOccur = false;
if (NULL == pSt_DBConnector)
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = ERROR_APISERVICE_MODULE_DATABASE_PARAMENT;
return false;
}
//连接数据库
_tcsxcpy(pSt_DBConnector->tszDBName, _X("XEngine_APIInfo"));
if (!DataBase_MySQL_Connect(&xhDBSQL, pSt_DBConnector))
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = DataBase_GetLastError();
return false;
}
return true;
}
/********************************************************************
函数名称:ModuleDatabase_IDCard_Destory
函数功能:销毁
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CModuleDatabase_IDCard::ModuleDatabase_IDCard_Destory()
{
DBModule_IsErrorOccur = false;
DataBase_MySQL_Close(xhDBSQL);
return true;
}
/********************************************************************
函数名称:ModuleDatabase_IDCard_QueryRegion
函数功能:查询身份证位置信息
参数.一:pSt_IDRegion
In/Out:Out
类型:数据结构指针
可空:N
意思:输出查询到的位置信息
参数.二:pSt_IDInfo
In/Out:In
类型:数据结构指针
可空:N
意思:输入要查询的信息
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CModuleDatabase_IDCard::ModuleDatabase_IDCard_QueryRegion(XENGINE_IDREGION* pSt_IDRegion, XENGINE_IDCARDINFO* pSt_IDInfo)
{
DBModule_IsErrorOccur = false;
ModuleDatabase_IDCard_QueryProvincer(pSt_IDRegion, pSt_IDInfo);
ModuleDatabase_IDCard_QueryCity(pSt_IDRegion, pSt_IDInfo);
ModuleDatabase_IDCard_QueryCounty(pSt_IDRegion, pSt_IDInfo);
return true;
}
/********************************************************************
函数名称:ModuleDatabase_IDCard_QueryByAddr
函数功能:查询地址对应的区域ID
参数.一:pSt_IDRegion
In/Out:Out
类型:数据结构指针
可空:N
意思:输出查询到的位置信息
参数.二:pInt_IDNumber
In/Out:Out
类型:整数型指针
可空:N
意思:输出对应ID
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CModuleDatabase_IDCard::ModuleDatabase_IDCard_QueryByAddr(XENGINE_IDREGION* pSt_IDRegion, int* pInt_IDNumber)
{
DBModule_IsErrorOccur = false;
// 参数检查:区域信息与输出ID指针都必须有效。
if ((NULL == pSt_IDRegion) || (NULL == pInt_IDNumber))
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = ERROR_APISERVICE_MODULE_DATABASE_PARAMENT;
return false;
}
// 查询过程中的通用变量:
// nLine/nRow 为结果集规模,nProvincer/nCity/nCounty 用于拼装最终行政区划ID。
__int64u nLine = 0;
__int64u nRow = 0;
int nProvincer = 0;
int nCity = 0;
int nCounty = 0;
XNETHANDLE xhTable = 0;
XCHAR tszSQLStatement[1024];
// 第一步:根据省级名称查询对应编码。
memset(tszSQLStatement, '\0', sizeof(tszSQLStatement));
_xstprintf(tszSQLStatement, _X("SELECT * FROM `RegionID` WHERE name = '%s'"), pSt_IDRegion->tszProvincer);
#ifdef _MSC_BUILD
XCHAR tszUTFBuffer[1024] = {};
int nULen = _tcsxlen(tszSQLStatement);
BaseLib_Charset_AnsiToUTF(tszSQLStatement, tszUTFBuffer, &nULen);
if (!DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszUTFBuffer, &nLine, &nRow))
#else
if (!DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszSQLStatement, &nLine, &nRow))
#endif
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = DataBase_GetLastError();
return false;
}
if (nLine <= 0)
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = ERROR_APISERVICE_MODULE_DATABASE_NOTFOUND;
return false;
}
XCHAR** pptszResult = DataBase_MySQL_GetResult(xhDBSQL, xhTable);
nProvincer = _ttxoi(pptszResult[0]);
DataBase_MySQL_FreeResult(xhDBSQL, xhTable);
if (_tcsxlen(pSt_IDRegion->tszCity) > 0)
{
memset(tszSQLStatement, '\0', sizeof(tszSQLStatement));
_xstprintf(tszSQLStatement, _X("SELECT * FROM `RegionID` WHERE name = '%s' AND parentCode = %d"), pSt_IDRegion->tszCity, nProvincer);
#ifdef _MSC_BUILD
XCHAR tszUTFBuffer[1024] = {};
int nULen = _tcsxlen(tszSQLStatement);
BaseLib_Charset_AnsiToUTF(tszSQLStatement, tszUTFBuffer, &nULen);
if (!DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszUTFBuffer, &nLine, &nRow))
#else
if (!DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszSQLStatement, &nLine, &nRow))
#endif
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = DataBase_GetLastError();
return false;
}
if (nLine <= 0)
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = ERROR_APISERVICE_MODULE_DATABASE_NOTFOUND;
return false;
}
XCHAR** pptszResult = DataBase_MySQL_GetResult(xhDBSQL, xhTable);
nCity = _ttxoi(pptszResult[0]);
DataBase_MySQL_FreeResult(xhDBSQL, xhTable);
}
if (_tcsxlen(pSt_IDRegion->tszCounty) > 0)
{
memset(tszSQLStatement, '\0', sizeof(tszSQLStatement));
_xstprintf(tszSQLStatement, _X("SELECT * FROM `RegionID` WHERE name = '%s' AND parentCode = %d"), pSt_IDRegion->tszCounty, nCity);
#ifdef _MSC_BUILD
XCHAR tszUTFBuffer[1024] = {};
int nULen = _tcsxlen(tszSQLStatement);
BaseLib_Charset_AnsiToUTF(tszSQLStatement, tszUTFBuffer, &nULen);
if (!DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszUTFBuffer, &nLine, &nRow))
#else
if (!DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszSQLStatement, &nLine, &nRow))
#endif
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = DataBase_GetLastError();
return false;
}
if (nLine <= 0)
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = ERROR_APISERVICE_MODULE_DATABASE_NOTFOUND;
return false;
}
XCHAR** pptszResult = DataBase_MySQL_GetResult(xhDBSQL, xhTable);
nCounty = _ttxoi(pptszResult[0]);
DataBase_MySQL_FreeResult(xhDBSQL, xhTable);
}
if (0 == nCounty && 0 == nCity)
{
*pInt_IDNumber = nProvincer;
}
else if (0 == nCounty && 0 != nCity)
{
*pInt_IDNumber = nCity;
}
else
{
*pInt_IDNumber = nCounty;
}
return true;
}
/********************************************************************
函数名称:ModuleDatabase_IDCard_QueryProvincer
函数功能:查询省份信息
参数.一:pSt_IDRegion
In/Out:Out
类型:数据结构指针
可空:N
意思:输出所属省份
参数.二:pSt_IDInfo
In/Out:In
类型:数据结构指针
可空:N
意思:输入要查询的信息
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CModuleDatabase_IDCard::ModuleDatabase_IDCard_QueryProvincer(XENGINE_IDREGION* pSt_IDRegion, XENGINE_IDCARDINFO* pSt_IDInfo)
{
DBModule_IsErrorOccur = false;
if ((NULL == pSt_IDRegion) || (NULL == pSt_IDInfo))
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = ERROR_APISERVICE_MODULE_DATABASE_PARAMENT;
return false;
}
//查询
__int64u nLine = 0;
__int64u nRow = 0;
XNETHANDLE xhTable = 0;
XCHAR tszSQLStatement[1024];
memset(tszSQLStatement, '\0', sizeof(tszSQLStatement));
_xstprintf(tszSQLStatement, _X("SELECT * FROM `RegionID` WHERE code = '%02d0000'"), pSt_IDInfo->nIDProvince);
if (!DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszSQLStatement, &nLine, &nRow))
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = DataBase_GetLastError();
return false;
}
if (nLine <= 0)
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = ERROR_APISERVICE_MODULE_DATABASE_NOTFOUND;
return false;
}
XCHAR** pptszResult = DataBase_MySQL_GetResult(xhDBSQL, xhTable);
_tcsxcpy(pSt_IDRegion->tszProvincer, pptszResult[1]);
DataBase_MySQL_FreeResult(xhDBSQL, xhTable);
return true;
}
/********************************************************************
函数名称:ModuleDatabase_IDCard_QueryCity
函数功能:查询市信息
参数.一:pSt_IDRegion
In/Out:Out
类型:数据结构指针
可空:N
意思:输出所属市
参数.二:pSt_IDInfo
In/Out:In
类型:数据结构指针
可空:N
意思:输入要查询的信息
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CModuleDatabase_IDCard::ModuleDatabase_IDCard_QueryCity(XENGINE_IDREGION* pSt_IDRegion, XENGINE_IDCARDINFO* pSt_IDInfo)
{
DBModule_IsErrorOccur = false;
if ((NULL == pSt_IDRegion) || (NULL == pSt_IDInfo))
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = ERROR_APISERVICE_MODULE_DATABASE_PARAMENT;
return false;
}
//查询
__int64u nLine = 0;
__int64u nRow = 0;
XNETHANDLE xhTable = 0;
XCHAR tszSQLStatement[1024];
memset(tszSQLStatement, '\0', sizeof(tszSQLStatement));
_xstprintf(tszSQLStatement, _X("SELECT * FROM `RegionID` WHERE code = '%02d%02d00'"), pSt_IDInfo->nIDProvince, pSt_IDInfo->nIDCity);
if (!DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszSQLStatement, &nLine, &nRow))
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = DataBase_GetLastError();
return false;
}
if (nLine <= 0)
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = ERROR_APISERVICE_MODULE_DATABASE_NOTFOUND;
return false;
}
XCHAR** pptszResult = DataBase_MySQL_GetResult(xhDBSQL, xhTable);
_tcsxcpy(pSt_IDRegion->tszCity, pptszResult[1]);
DataBase_MySQL_FreeResult(xhDBSQL, xhTable);
return true;
}
/********************************************************************
函数名称:ModuleDatabase_IDCard_QueryCounty
函数功能:查询县区信息
参数.一:pSt_IDRegion
In/Out:Out
类型:数据结构指针
可空:N
意思:输出所属县区
参数.二:pSt_IDInfo
In/Out:In
类型:数据结构指针
可空:N
意思:输入要查询的信息
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CModuleDatabase_IDCard::ModuleDatabase_IDCard_QueryCounty(XENGINE_IDREGION* pSt_IDRegion, XENGINE_IDCARDINFO* pSt_IDInfo)
{
DBModule_IsErrorOccur = false;
if ((NULL == pSt_IDRegion) || (NULL == pSt_IDInfo))
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = ERROR_APISERVICE_MODULE_DATABASE_PARAMENT;
return false;
}
//查询
__int64u nLine = 0;
__int64u nRow = 0;
XNETHANDLE xhTable = 0;
XCHAR tszSQLStatement[1024];
memset(tszSQLStatement, '\0', sizeof(tszSQLStatement));
_xstprintf(tszSQLStatement, _X("SELECT * FROM `RegionID` WHERE code = '%02d%02d%02d'"), pSt_IDInfo->nIDProvince, pSt_IDInfo->nIDCity, pSt_IDInfo->nIDCounty);
if (!DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszSQLStatement, &nLine, &nRow))
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = DataBase_GetLastError();
return false;
}
if (nLine <= 0)
{
DBModule_IsErrorOccur = true;
DBModule_dwErrorCode = ERROR_APISERVICE_MODULE_DATABASE_NOTFOUND;
return false;
}
XCHAR** pptszResult = DataBase_MySQL_GetResult(xhDBSQL, xhTable);
_tcsxcpy(pSt_IDRegion->tszCounty, pptszResult[1]);
DataBase_MySQL_FreeResult(xhDBSQL, xhTable);
return true;
}