-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDBTest.cpp
More file actions
247 lines (238 loc) · 6.25 KB
/
DBTest.cpp
File metadata and controls
247 lines (238 loc) · 6.25 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
#include "stdafx.h"
#include "DBTest.h"
#include "EditArea.h"
#include "QU_Manager.h"
#include "SYS_Manager.h"
#include <direct.h>
#include <iostream>
#include <conio.h>
//update by zjh 20191224 解决GetNextRec前未申请空间问题
int TableTest(char tabname[][20], int *tabnum, char colname[][20][20], int colnum[], AttrType coltype[][20], int collength[][20], int coloffset[][20], int iscolindex[][20], char indexname[][20][20], char *temppath)
{
RM_FileHandle fileHandle, colfilehandle;
fileHandle.bOpen = 0;
colfilehandle.bOpen = 0;
RM_FileScan FileScan1, FileScan2;
FileScan1.bOpen = 0;
FileScan2.bOpen = 0;
RM_Record rec1, rec2;
Con condition;
RC rc;
CString t, table, column;//test
int i = 0, j = 0;
DWORD cchCurDir = BUFFER;
LPTSTR lpszCurDir;
TCHAR tchBuffer[BUFFER];
lpszCurDir = tchBuffer;
GetCurrentDirectory(cchCurDir, lpszCurDir);
if (!strcmp(temppath, "")) {
CString Path = lpszCurDir;
table = Path + "\\SYSTABLES";
column = Path + "\\SYSCOLUMNS";
}
else {
CString Path = temppath;
table = Path + "\\SYSTABLES";
column = Path + "\\SYSCOLUMNS";
}
rc = RM_OpenFile((LPSTR)(LPCTSTR)table, &fileHandle);//去SYSTABLES表中获取表名
if (rc != SUCCESS) {
// AfxMessageBox("打开系统表文件失败");
return -1;
}
rc = RM_OpenFile((LPSTR)(LPCTSTR)column, &colfilehandle);//去SYSCOLUMNS表中获取列名
if (rc != SUCCESS) {
// AfxMessageBox("打开系统列文件失败");
return -1;
}
rc = OpenScan(&FileScan1, &fileHandle, 0, NULL);
if (rc != SUCCESS) {
// AfxMessageBox("初始化表文件扫描失败");
return -1;
}
rec1.pData = new char[25];//25=SIZE_SYS_TABLE
memset(rec1.pData, 0, 25);
rec2.pData = new char[76];//76=SIZE_SYS_COLUMNS
memset(rec2.pData, 0, 76);
while (GetNextRec(&FileScan1, &rec1) == SUCCESS)
{
strcpy(tabname[i], rec1.pData);
condition.bLhsIsAttr = 1;
condition.bRhsIsAttr = 0;
condition.LattrLength = strlen(tabname[i]);
condition.RattrLength = strlen(tabname[i]);
condition.LattrOffset = 0;
condition.attrType = chars;
condition.compOp = EQual;
condition.Rvalue = tabname[i];
rc = OpenScan(&FileScan2, &colfilehandle, 1, &condition);
if (rc != SUCCESS) {
// AfxMessageBox("初始化列文件扫描失败");
return -1;
}
RC rc;
while ((rc = GetNextRec(&FileScan2, &rec2)) == SUCCESS)
{
strcpy(colname[i][j], rec2.pData + 21);
memcpy(&coltype[i][j], rec2.pData + 42, sizeof(AttrType));
memcpy(&collength[i][j], rec2.pData + 46, sizeof(int));
memcpy(&coloffset[i][j], rec2.pData + 50, sizeof(int));
if (*(rec2.pData + 54) == '1') {
iscolindex[i][j] = 1;
strcpy(indexname[i][j], rec2.pData + 55);
}
else {
iscolindex[i][j] = 0;
strcpy(indexname[i][j], "\0");
}
j++;
}
colnum[i] = j;
j = 0;
i++;
FileScan2.bOpen = 0;
}
*tabnum = i;
rc = RM_CloseFile(&fileHandle);
if (rc != SUCCESS) {
// AfxMessageBox("关闭系统表文件失败");
return -1;
}
rc = RM_CloseFile(&colfilehandle);
if (rc != SUCCESS) {
// AfxMessageBox("关闭系统列文件失败");
return -1;
}
return 1;
}
//update by zjh 20191224 解决GetNextRec前未申请空间、colType应提前初始化问题
int TableContent(int *colNum, int *rowNum, AttrType colType[20], char unit[][20][100], char *dbname, char *tablename)
{
RM_FileHandle fileHandle;
fileHandle.bOpen = 0;
RC rc;
RM_Record rec;
RM_FileScan FileScan;
FileScan.bOpen = 0;
Con condition;
*rowNum = 0;
char tabname[20][20];
char colname[20][20][20];
AttrType coltype[20][20];
int tabnum, colnum[20];
int collength[20][20];
int coloffset[20][20];
int iscolix[20][20];
char indexname[20][20][20];
int i, j, k = 0;
CString path;
CString t;
DWORD cchCurDir = BUFFER;
LPTSTR lpszCurDir;
TCHAR tchBuffer[BUFFER];
// lpszCurDir = tchBuffer;
// GetCurrentDirectory(cchCurDir, lpszCurDir);
// path=lpszCurDir;
CString cspath = dbname;
path = cspath + "\\SYSTABLES";
char cpath[100];
strcpy(cpath, cspath);
rc = RM_OpenFile((LPSTR)(LPCTSTR)path, &fileHandle);//去SYSTABLES表中获取表名
if (rc != SUCCESS)
{
// AfxMessageBox("打开系统表文件失败");
return -1;
}
condition.bLhsIsAttr = 1;
condition.bRhsIsAttr = 0;
condition.LattrOffset = 0;
condition.LattrLength = 20;
condition.RattrLength = 20;
condition.attrType = chars;
condition.compOp = EQual;
condition.Rvalue = (LPSTR)(LPCTSTR)tablename;
rc = OpenScan(&FileScan, &fileHandle, 1, &condition);
if (rc != SUCCESS) {
//AfxMessageBox("初始化文件扫描失败");
return -1;
}
rec.pData = new char[76];//76=SIZE_SYS_COLUMNS
rc = GetNextRec(&FileScan, &rec);
if (rc != SUCCESS)//点击的不是表名,不做显示处理
{
rc = RM_CloseFile(&fileHandle);
if (rc != SUCCESS)
// AfxMessageBox("系统表文件关闭失败");
return -1;
}
rc = RM_CloseFile(&fileHandle);
if (rc != SUCCESS) {
// AfxMessageBox("表系统文件关闭失败");
return -1;
}
int rc1 = TableTest(tabname, &tabnum, colname, colnum, coltype, collength, coloffset, iscolix, indexname, cpath);
for (i = 0; i < tabnum; i++)
{
if (strcmp((LPSTR)(LPCTSTR)tablename, tabname[i]) == 0)
break;
}
fileHandle.bOpen = 0;
char temp1[100];
strcpy(temp1, dbname);
strcat(temp1, "\\");
strcat(temp1, tablename);
rc = RM_OpenFile((LPSTR)(LPCTSTR)temp1, &fileHandle);
if (rc != SUCCESS) {
// AfxMessageBox("数据表文件打开失败");
return -1;
}
FileScan.bOpen = 0;
rc = OpenScan(&FileScan, &fileHandle, 0, NULL);
if (rc != SUCCESS) {
//AfxMessageBox("初始化文件扫描失败");
return -1;
}
if (!rec.pData) {
rec.pData = new char[76];//76=SIZE_SYS_COLUMNS
}
*colNum = colnum[i];
for (j = 0; j < colnum[i]; j++)
{
//memcpy(&colType[j],&(coltype[i][j]),sizeof(AttrType));
colType[j] = coltype[i][j];
}
while (GetNextRec(&FileScan, &rec) == SUCCESS)
{
for (j = 0; j < colnum[i]; j++)
{
if (coltype[i][j] == chars)
{
char temp[21];
memcpy(temp, rec.pData + coloffset[i][j], collength[i][j]);
t = temp;
strcpy((unit)[*rowNum][j], t);
}
else if (coltype[i][j] == ints)
{
int temp;
memcpy(&temp, rec.pData + coloffset[i][j], sizeof(int));
t.Format("%d", temp);
strcpy((unit)[*rowNum][j], t);
}
else if (coltype[i][j] == floats)
{
float temp;
memcpy(&temp, rec.pData + coloffset[i][j], sizeof(float));
t.Format("%f", temp);
strcpy((unit)[*rowNum][j], t);
}
}
(*rowNum)++;
}
rc = RM_CloseFile(&fileHandle);
if (rc != SUCCESS) {
//AfxMessageBox("关闭数据表文件失败");
return -1;
}
return 1;
}