transactd 2.4.5 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CMakeLists.txt +1 -1
- data/README-JA.md +52 -529
- data/README.md +52 -523
- data/bin/common/tdclc_32_3_0.dll +0 -0
- data/bin/common/tdclc_64_3_0.dll +0 -0
- data/build/common/system.cmake +2 -1
- data/build/common/transactd_cl_common.cmake +3 -6
- data/build/swig/ruby/ruby.swg +85 -28
- data/build/swig/ruby/tdclrb_wrap.cpp +3195 -1578
- data/build/swig/tdcl.i +161 -5
- data/build/tdclc/CMakeLists.txt +1 -0
- data/build/tdclc/tdclc.cbproj +7 -1
- data/build/tdclc/tdclc.rc +4 -4
- data/build/tdclcpp/tdclcpp.rc +4 -4
- data/build/tdclcpp/tdclcpp_bc.cbproj +2 -5
- data/build/tdclrb/tdclrb.rc +4 -4
- data/source/bzs/db/blobStructs.h +1 -1
- data/source/bzs/db/engine/mysql/database.cpp +199 -74
- data/source/bzs/db/engine/mysql/database.h +47 -18
- data/source/bzs/db/engine/mysql/dbManager.cpp +1 -0
- data/source/bzs/db/engine/mysql/mysqlInternal.h +32 -8
- data/source/bzs/db/protocol/tdap/btrDate.cpp +110 -75
- data/source/bzs/db/protocol/tdap/btrDate.h +46 -21
- data/source/bzs/db/protocol/tdap/client/activeTable.cpp +18 -18
- data/source/bzs/db/protocol/tdap/client/activeTable.h +25 -25
- data/source/bzs/db/protocol/tdap/client/activeTableImple.h +10 -4
- data/source/bzs/db/protocol/tdap/client/client.cpp +6 -5
- data/source/bzs/db/protocol/tdap/client/client.h +82 -15
- data/source/bzs/db/protocol/tdap/client/database.cpp +531 -142
- data/source/bzs/db/protocol/tdap/client/database.h +19 -6
- data/source/bzs/db/protocol/tdap/client/dbDef.cpp +461 -408
- data/source/bzs/db/protocol/tdap/client/dbDef.h +11 -17
- data/source/bzs/db/protocol/tdap/client/dllmain.cpp +61 -13
- data/source/bzs/db/protocol/tdap/client/field.cpp +1592 -1398
- data/source/bzs/db/protocol/tdap/client/field.h +110 -121
- data/source/bzs/db/protocol/tdap/client/fields.h +40 -10
- data/source/bzs/db/protocol/tdap/client/filter.h +69 -55
- data/source/bzs/db/protocol/tdap/client/groupQuery.cpp +296 -164
- data/source/bzs/db/protocol/tdap/client/groupQuery.h +77 -25
- data/source/bzs/db/protocol/tdap/client/memRecord.cpp +31 -13
- data/source/bzs/db/protocol/tdap/client/memRecord.h +31 -21
- data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +1 -1
- data/source/bzs/db/protocol/tdap/client/nsDatabase.h +4 -1
- data/source/bzs/db/protocol/tdap/client/nsTable.cpp +69 -24
- data/source/bzs/db/protocol/tdap/client/nsTable.h +3 -1
- data/source/bzs/db/protocol/tdap/client/recordset.cpp +1 -0
- data/source/bzs/db/protocol/tdap/client/recordsetImple.h +46 -27
- data/source/bzs/db/protocol/tdap/client/request.h +2 -1
- data/source/bzs/db/protocol/tdap/client/serializer.cpp +44 -9
- data/source/bzs/db/protocol/tdap/client/serializer.h +1 -1
- data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +182 -76
- data/source/bzs/db/protocol/tdap/client/sqlBuilder.h +23 -12
- data/source/bzs/db/protocol/tdap/client/stringConverter.h +8 -10
- data/source/bzs/db/protocol/tdap/client/table.cpp +172 -93
- data/source/bzs/db/protocol/tdap/client/table.h +112 -37
- data/source/bzs/db/protocol/tdap/client/trdboostapi.h +17 -0
- data/source/bzs/db/protocol/tdap/client/trdboostapiInternal.h +0 -1
- data/source/bzs/db/protocol/tdap/client/trdclcppautolink.h +0 -2
- data/source/bzs/db/protocol/tdap/client/trdormapi.h +1 -1
- data/source/bzs/db/protocol/tdap/fieldComp.h +698 -14
- data/source/bzs/db/protocol/tdap/myDateTime.cpp +723 -307
- data/source/bzs/db/protocol/tdap/myDateTime.h +294 -0
- data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +164 -54
- data/source/bzs/db/protocol/tdap/mysql/databaseSchema.h +6 -3
- data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +133 -550
- data/source/bzs/db/protocol/tdap/mysql/request.h +6 -5
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +217 -82
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +1 -1
- data/source/bzs/db/protocol/tdap/tdapRequest.h +4 -9
- data/source/bzs/db/protocol/tdap/tdapSchema.cpp +808 -17
- data/source/bzs/db/protocol/tdap/tdapSchema.h +656 -164
- data/source/bzs/db/protocol/tdap/tdapcapi.h +130 -28
- data/source/bzs/db/protocol/tdap/uri.h +40 -32
- data/source/bzs/db/transactd/connManager.cpp +1 -1
- data/source/bzs/db/transactd/transactd.cpp +7 -0
- data/source/bzs/env/compiler.h +107 -94
- data/source/bzs/env/crosscompile.cpp +24 -12
- data/source/bzs/env/crosscompile.h +75 -6
- data/source/bzs/env/mbcswchrLinux.cpp +2 -2
- data/source/bzs/env/tcharMinGW.h +4 -0
- data/source/bzs/example/changeSchema.cpp +22 -17
- data/source/bzs/example/queryData.cpp +4 -0
- data/source/bzs/netsvc/client/iconnection.h +3 -1
- data/source/bzs/netsvc/client/tcpClient.h +10 -3
- data/source/bzs/rtl/stringBuffers.cpp +7 -0
- data/source/bzs/test/tdclatl/bench_query_atl.js +6 -0
- data/source/bzs/test/tdclatl/bench_tdclatl.js +8 -1
- data/source/bzs/test/tdclatl/test_query_atl.js +22 -2
- data/source/bzs/test/tdclatl/test_v3.js +1017 -0
- data/source/bzs/test/tdclphp/transactd_Test.php +55 -21
- data/source/bzs/test/tdclphp/transactd_datetime_Test.php +0 -5
- data/source/bzs/test/tdclphp/transactd_pool_Test.php +2 -0
- data/source/bzs/test/tdclphp/transactd_v3_Test.php +743 -0
- data/source/bzs/test/tdclrb/transactd_datetime_spec.rb +0 -5
- data/source/bzs/test/tdclrb/transactd_pool_spec.rb +2 -0
- data/source/bzs/test/tdclrb/transactd_spec.rb +39 -16
- data/source/bzs/test/tdclrb/transactd_v3_spec.rb +748 -0
- data/source/bzs/test/transactdBench/transactdBench.cpp +55 -58
- data/source/bzs/test/transactdBench/transactdBench2.cpp +1 -3
- data/source/bzs/test/trdclengn/testField.h +3305 -0
- data/source/bzs/test/trdclengn/test_tdclcpp_v3.cpp +1050 -0
- data/source/bzs/test/trdclengn/test_trdclengn.cpp +112 -190
- data/source/bzs/test/trdclengn/testbase.h +137 -0
- data/source/global/ormsrcgen/srcgen.cpp +23 -12
- data/source/global/ormsrcgen/template/ormDataClass_template.h +2 -0
- data/source/global/querystmts/querystmts.cpp +2 -3
- data/source/global/tdclatl/Bitset.cpp +38 -0
- data/source/global/tdclatl/Bitset.h +63 -0
- data/source/global/tdclatl/Database.cpp +59 -18
- data/source/global/tdclatl/Database.h +7 -4
- data/source/global/tdclatl/DbDef.cpp +6 -6
- data/source/global/tdclatl/DbDef.h +2 -1
- data/source/global/tdclatl/Field.cpp +112 -0
- data/source/global/tdclatl/Field.h +19 -5
- data/source/global/tdclatl/FieldDef.cpp +137 -16
- data/source/global/tdclatl/FieldDef.h +18 -2
- data/source/global/tdclatl/FieldDefs.cpp +54 -1
- data/source/global/tdclatl/FieldDefs.h +3 -0
- data/source/global/tdclatl/GroupQuery.cpp +8 -8
- data/source/global/tdclatl/QueryBase.cpp +65 -0
- data/source/global/tdclatl/QueryBase.h +10 -0
- data/source/global/tdclatl/Record.cpp +33 -2
- data/source/global/tdclatl/Record.h +3 -1
- data/source/global/tdclatl/RecordsetQuery.cpp +42 -0
- data/source/global/tdclatl/RecordsetQuery.h +8 -0
- data/source/global/tdclatl/Table.cpp +127 -3
- data/source/global/tdclatl/Table.h +10 -1
- data/source/global/tdclatl/TableDef.cpp +41 -8
- data/source/global/tdclatl/TableDef.h +7 -2
- data/source/global/tdclatl/activeTable.cpp +40 -71
- data/source/global/tdclatl/resource.h +0 -0
- data/source/global/tdclatl/tdclatl.idl +222 -28
- data/source/linux/tchar.h +100 -96
- data/transactd.gemspec +2 -2
- metadata +13 -11
- data/BUILD_UNIX-JA.md +0 -161
- data/BUILD_WIN-JA.md +0 -326
- data/README_ORMSRCGEN-JA.md +0 -115
- data/README_ORMSRCGEN.md +0 -118
- data/RELEASE_NOTE-JA.md +0 -356
- data/RELEASE_NOTE.md +0 -360
- data/bin/common/tdclc_32_2_4.dll +0 -0
- data/bin/common/tdclc_64_2_4.dll +0 -0
- data/source/bzs/test/trdclengn/test_blob.cpp +0 -375
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
================================================================= */
|
|
19
19
|
#include "dbDef.h"
|
|
20
20
|
#include "database.h"
|
|
21
|
+
#include <bzs/db/protocol/tdap/uri.h>
|
|
21
22
|
#include <bzs/rtl/strtrim.h>
|
|
22
23
|
#include <limits.h>
|
|
23
24
|
#include <stdio.h>
|
|
@@ -39,14 +40,12 @@ namespace tdap
|
|
|
39
40
|
namespace client
|
|
40
41
|
{
|
|
41
42
|
|
|
42
|
-
#define FORMAT_VERSON_BTRV_DEF 0
|
|
43
|
-
#define FORMAT_VERSON_CURRENT 1
|
|
44
43
|
|
|
45
44
|
/* BDFFORMAT_VERSION used in the databaseSchema.cpp listSchemaTable() */
|
|
46
45
|
static const _TCHAR BDFFORMAT_VERSION[] = _T("2.000.00");
|
|
47
46
|
static const _TCHAR ow0[11] = { 46, 46, 83, 67, 46, 46, 46, 46, 93, 4, 0 };
|
|
48
47
|
static const _TCHAR ow1[11] = { 46, 46, 83, 67, 46, 46, 46, 46, 66, 5, 0 };
|
|
49
|
-
static const _TCHAR ow2[11] = { 46, 46, 83, 67, 46, 46, 46, 46, -44, 5, 0 };
|
|
48
|
+
static const _TCHAR ow2[11] = { 46, 46, 83, 67, 46, 46, 46, 46, (_TCHAR)-44, 5, 0 };
|
|
50
49
|
using namespace bzs::rtl;
|
|
51
50
|
|
|
52
51
|
class ownerNameSetter : public nstable
|
|
@@ -59,8 +58,8 @@ public:
|
|
|
59
58
|
using nstable::open;
|
|
60
59
|
};
|
|
61
60
|
|
|
62
|
-
static const int
|
|
63
|
-
|
|
61
|
+
static const int BDFMAXBUFFER_BTRV = 32384;
|
|
62
|
+
static const int BDFMAXBUFFER = MAX_SCHEMASIZE + 0xFFFF;
|
|
64
63
|
struct dbdimple
|
|
65
64
|
{
|
|
66
65
|
tabledef* tableDefs[TABLE_NUM_TMP + 1];
|
|
@@ -72,7 +71,7 @@ struct dbdimple
|
|
|
72
71
|
short openMode;
|
|
73
72
|
short deftype;
|
|
74
73
|
_TCHAR userName[20];
|
|
75
|
-
|
|
74
|
+
uint_td bdfLen;
|
|
76
75
|
_TCHAR version[9];
|
|
77
76
|
bool noWriteMode;
|
|
78
77
|
|
|
@@ -83,71 +82,80 @@ struct dbdimple
|
|
|
83
82
|
memset(tableDefs, 0, (TABLE_NUM_TMP + 1) * sizeof(tabledef*));
|
|
84
83
|
_tcscpy(version, (const _TCHAR*)BDFFORMAT_VERSION);
|
|
85
84
|
}
|
|
85
|
+
|
|
86
|
+
~dbdimple()
|
|
87
|
+
{
|
|
88
|
+
for (int i = 0; i <= tableCount; i++)
|
|
89
|
+
{
|
|
90
|
+
tabledef* td = tableDefs[i];
|
|
91
|
+
if (td && (td != (tabledef*)-1) && (td != bdf))
|
|
92
|
+
{
|
|
93
|
+
if (td->defaultImage)
|
|
94
|
+
free(td->defaultImage);
|
|
95
|
+
free(td);
|
|
96
|
+
tableDefs[i] = NULL;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (bdf)
|
|
100
|
+
free(bdf);
|
|
101
|
+
if (tableDefs[TABLE_NUM_TMP])
|
|
102
|
+
free(tableDefs[TABLE_NUM_TMP]);
|
|
103
|
+
if (relateData)
|
|
104
|
+
free(relateData);
|
|
105
|
+
}
|
|
86
106
|
};
|
|
87
107
|
|
|
88
108
|
dbdef::dbdef(nsdatabase* pbe, short DefType) : nstable(pbe)
|
|
89
109
|
{
|
|
90
|
-
|
|
91
|
-
|
|
110
|
+
m_dimpl = new dbdimple();
|
|
111
|
+
m_dimpl->deftype = DefType;
|
|
92
112
|
m_keybuflen = 128;
|
|
93
|
-
m_keybuf = &
|
|
113
|
+
m_keybuf = &m_dimpl->keybuf[0];
|
|
94
114
|
setShared();
|
|
95
115
|
}
|
|
96
116
|
|
|
97
117
|
dbdef::~dbdef()
|
|
98
118
|
{
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
for (int i = 0; i <= m_impl->tableCount; i++)
|
|
103
|
-
{
|
|
104
|
-
if (m_impl->tableDefs[i] && (m_impl->tableDefs[i] != (tabledef*)-1) &&
|
|
105
|
-
(m_impl->tableDefs[i] != m_impl->bdf))
|
|
106
|
-
free(m_impl->tableDefs[i]);
|
|
107
|
-
}
|
|
108
|
-
if (m_impl->tableDefs[TABLE_NUM_TMP])
|
|
109
|
-
free(m_impl->tableDefs[TABLE_NUM_TMP]);
|
|
110
|
-
if (m_impl->relateData)
|
|
111
|
-
free(m_impl->relateData);
|
|
112
|
-
delete m_impl;
|
|
119
|
+
delete m_dimpl;
|
|
120
|
+
m_dimpl = NULL;
|
|
113
121
|
}
|
|
114
122
|
|
|
115
123
|
void dbdef::setDefType(short defType)
|
|
116
124
|
{
|
|
117
|
-
|
|
125
|
+
m_dimpl->deftype = defType;
|
|
118
126
|
}
|
|
119
127
|
|
|
120
128
|
short dbdef::tableCount() const
|
|
121
129
|
{
|
|
122
|
-
return
|
|
130
|
+
return m_dimpl->tableCount;
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
void* dbdef::relateData() const
|
|
126
134
|
{
|
|
127
|
-
return
|
|
135
|
+
return m_dimpl->relateData;
|
|
128
136
|
}
|
|
129
137
|
|
|
130
138
|
short dbdef::openMode() const
|
|
131
139
|
{
|
|
132
|
-
return
|
|
140
|
+
return m_dimpl->openMode;
|
|
133
141
|
}
|
|
134
142
|
|
|
135
143
|
int dbdef::version() const
|
|
136
144
|
{
|
|
137
|
-
return
|
|
145
|
+
return m_dimpl->version[7] - '0';
|
|
138
146
|
};
|
|
139
147
|
|
|
140
148
|
void dbdef::setVersion(int v)
|
|
141
149
|
{
|
|
142
|
-
|
|
150
|
+
m_dimpl->version[7] = (char)v;
|
|
143
151
|
}
|
|
144
152
|
|
|
145
153
|
void* dbdef::allocRelateData(int size)
|
|
146
154
|
{
|
|
147
|
-
if (
|
|
148
|
-
free(
|
|
149
|
-
|
|
150
|
-
return
|
|
155
|
+
if (m_dimpl->relateData)
|
|
156
|
+
free(m_dimpl->relateData);
|
|
157
|
+
m_dimpl->relateData = malloc(size);
|
|
158
|
+
return m_dimpl->relateData;
|
|
151
159
|
}
|
|
152
160
|
keylen_td dbdef::writeKeyData()
|
|
153
161
|
{
|
|
@@ -157,97 +165,107 @@ void dbdef::moveById(short id)
|
|
|
157
165
|
{
|
|
158
166
|
while (1)
|
|
159
167
|
{
|
|
160
|
-
m_pdata =
|
|
161
|
-
m_buflen =
|
|
168
|
+
m_pdata = m_dimpl->bdf;
|
|
169
|
+
m_buflen = m_dimpl->bdfLen;
|
|
162
170
|
memcpy(m_keybuf, &id, 2);
|
|
163
171
|
seek();
|
|
164
172
|
if (m_stat == STATUS_BUFFERTOOSMALL)
|
|
165
|
-
|
|
166
|
-
if (!resizeReadBuf())
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
173
|
+
return;
|
|
169
174
|
else
|
|
170
175
|
break;
|
|
171
176
|
}
|
|
172
177
|
}
|
|
173
178
|
|
|
174
|
-
|
|
179
|
+
void* dbdef::getBufferPtr(uint_td& size)
|
|
175
180
|
{
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (m_impl->bdf == NULL)
|
|
179
|
-
{
|
|
180
|
-
m_stat = STATUS_CANT_ALLOC_MEMORY;
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
m_impl->bdfLen += BDFMAXBUFFER;
|
|
184
|
-
return true;
|
|
181
|
+
size = m_dimpl->bdfLen;
|
|
182
|
+
return m_dimpl->bdf;
|
|
185
183
|
}
|
|
186
184
|
|
|
187
|
-
|
|
185
|
+
bool dbdef::setDefaultImage(short tableIndex, const uchar_td* p, ushort_td size)
|
|
188
186
|
{
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
187
|
+
tabledef* td = m_dimpl->tableDefs[tableIndex];
|
|
188
|
+
if (td)
|
|
189
|
+
{
|
|
190
|
+
if (td->defaultImage)
|
|
191
|
+
{
|
|
192
|
+
free(td->defaultImage);
|
|
193
|
+
td->defaultImage = NULL;
|
|
194
|
+
}
|
|
195
|
+
if (!p || size == 0)
|
|
196
|
+
return true;
|
|
197
|
+
|
|
198
|
+
td->defaultImage = malloc(size);
|
|
199
|
+
if (td->defaultImage)
|
|
200
|
+
{
|
|
201
|
+
memcpy(td->defaultImage, p, size);
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
192
206
|
}
|
|
193
207
|
|
|
194
|
-
|
|
208
|
+
bool dbdef::addSchemaImage(const tabledef* p, ushort_td size, short& tableIndex)
|
|
195
209
|
{
|
|
196
|
-
|
|
197
|
-
|
|
210
|
+
tableIndex = ++m_dimpl->tableCount;
|
|
211
|
+
initReadAfter(tableIndex, p, size);
|
|
212
|
+
return true;
|
|
198
213
|
}
|
|
199
214
|
|
|
200
|
-
void dbdef::
|
|
215
|
+
void dbdef::allocDatabuffer()
|
|
201
216
|
{
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
217
|
+
m_stat = 0;
|
|
218
|
+
if (m_dimpl->bdf == NULL)
|
|
219
|
+
{
|
|
220
|
+
if (!nsdb()->isUseTransactd())
|
|
221
|
+
m_dimpl->bdfLen = BDFMAXBUFFER_BTRV;
|
|
222
|
+
m_dimpl->bdf =
|
|
223
|
+
(tabledef*)malloc(m_dimpl->bdfLen);
|
|
224
|
+
if (m_dimpl->bdf == NULL)
|
|
225
|
+
m_stat = STATUS_CANT_ALLOC_MEMORY;
|
|
226
|
+
}
|
|
208
227
|
}
|
|
209
228
|
|
|
210
|
-
|
|
229
|
+
bool dbdef::testTablePtr(tabledef* td)
|
|
211
230
|
{
|
|
212
|
-
if (td
|
|
213
|
-
td->charsetIndex = mysql::charsetIndex(GetACP());
|
|
214
|
-
|
|
215
|
-
for (short i = 0; i < td->fieldCount; i++)
|
|
231
|
+
if (td == NULL)
|
|
216
232
|
{
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
fd.setCharsetIndex(td->charsetIndex);
|
|
220
|
-
fd.setSchemaCodePage(td->schemaCodePage);
|
|
233
|
+
m_stat = STATUS_INVALID_TABLE_IDX;
|
|
234
|
+
return false;
|
|
221
235
|
}
|
|
236
|
+
return true;
|
|
222
237
|
}
|
|
223
238
|
|
|
224
239
|
short dbdef::validateTableDef(short TableIndex)
|
|
225
240
|
{
|
|
226
241
|
m_stat = STATUS_SUCCESS;
|
|
227
242
|
tabledef* td = tableDefs(TableIndex);
|
|
243
|
+
if (!testTablePtr(td)) return m_stat;
|
|
228
244
|
|
|
229
245
|
td->optionFlags.bitA = false; // reset valiable type
|
|
230
246
|
td->optionFlags.bitB = false;
|
|
231
247
|
for (short i = 0; i < td->fieldCount; ++i)
|
|
232
248
|
{
|
|
233
|
-
|
|
249
|
+
const fielddef& fd = td->fieldDefs[i];
|
|
250
|
+
short ret = fieldNumByName(TableIndex, fd.name());
|
|
234
251
|
if ((ret != -1) && (ret != i))
|
|
235
252
|
{
|
|
236
253
|
m_stat = STATUS_DUPLICATE_FIELDNAME;
|
|
237
254
|
return m_stat;
|
|
238
255
|
}
|
|
239
256
|
// Check field length.
|
|
240
|
-
uchar_td type =
|
|
257
|
+
uchar_td type = fd.type;
|
|
241
258
|
|
|
242
259
|
// reset update indicator
|
|
243
|
-
|
|
260
|
+
const_cast<fielddef&>(fd).enableFlags.bitE = false;
|
|
244
261
|
|
|
245
|
-
ret = validLen(type,
|
|
246
|
-
if (!ret)
|
|
262
|
+
ret = validLen(type, fd.len);
|
|
263
|
+
if (!ret || !fd.isValidCharNum())
|
|
247
264
|
{
|
|
248
265
|
m_stat = STATUS_INVALID_FIELDLENGTH;
|
|
249
266
|
return m_stat;
|
|
250
267
|
}
|
|
268
|
+
|
|
251
269
|
// Note or Lvar type must be the last of fields.
|
|
252
270
|
if ((type == ft_note) || (type == ft_lvar))
|
|
253
271
|
{
|
|
@@ -270,8 +288,42 @@ short dbdef::validateTableDef(short TableIndex)
|
|
|
270
288
|
(type == ft_myvarbinary) || (type == ft_mywvarbinary) ||
|
|
271
289
|
(type == ft_myfixedbinary))
|
|
272
290
|
td->optionFlags.bitA = true;
|
|
273
|
-
if ((type == ft_myblob) || (type == ft_mytext))
|
|
291
|
+
if ((type == ft_myblob) || (type == ft_mytext) || (type == ft_mygeometry)
|
|
292
|
+
|| (type == ft_myjson))
|
|
274
293
|
td->optionFlags.bitB = true;
|
|
294
|
+
if (type == ft_myfixedbinary)
|
|
295
|
+
td->optionFlags.bitC = true;
|
|
296
|
+
//force use pad char
|
|
297
|
+
if ((type == ft_mychar) || (type == ft_mywchar))
|
|
298
|
+
td->fieldDefs[i].m_padCharOptions |= USE_PAD_CHAR;
|
|
299
|
+
|
|
300
|
+
if (type == ft_mytimestamp && (fd.decimals != 0))
|
|
301
|
+
{
|
|
302
|
+
int dec = (fd.len - 4) * 2;
|
|
303
|
+
if (fd.decimals > dec || fd.decimals < dec -1)
|
|
304
|
+
{
|
|
305
|
+
m_stat = STATUS_INVALID_FIELDLENGTH;
|
|
306
|
+
return m_stat;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (type == ft_mytime && (fd.decimals != 0))
|
|
310
|
+
{
|
|
311
|
+
int dec = (fd.len - 3) * 2;
|
|
312
|
+
if (fd.decimals > dec || fd.decimals < dec -1)
|
|
313
|
+
{
|
|
314
|
+
m_stat = STATUS_INVALID_FIELDLENGTH;
|
|
315
|
+
return m_stat;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (type == ft_mydatetime && (fd.decimals != 0))
|
|
319
|
+
{
|
|
320
|
+
int dec = (fd.len - 5) * 2;
|
|
321
|
+
if (fd.decimals > dec || fd.decimals < dec -1)
|
|
322
|
+
{
|
|
323
|
+
m_stat = STATUS_INVALID_FIELDLENGTH;
|
|
324
|
+
return m_stat;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
275
327
|
}
|
|
276
328
|
|
|
277
329
|
// Check invalid key type
|
|
@@ -290,10 +342,11 @@ short dbdef::validateTableDef(short TableIndex)
|
|
|
290
342
|
}
|
|
291
343
|
|
|
292
344
|
// Chack duplicate table name.
|
|
293
|
-
for (short i = 1; i <
|
|
345
|
+
for (short i = 1; i < m_dimpl->tableCount; i++)
|
|
294
346
|
{
|
|
295
347
|
if ((tableDefs(i)) && (i != TableIndex))
|
|
296
348
|
{
|
|
349
|
+
m_stat = 0;
|
|
297
350
|
if (strcmp(tableDefs(i)->tableNameA(), td->tableNameA()) == 0)
|
|
298
351
|
{
|
|
299
352
|
m_stat = STATUS_DUPPLICATE_KEYVALUE;
|
|
@@ -301,8 +354,8 @@ short dbdef::validateTableDef(short TableIndex)
|
|
|
301
354
|
}
|
|
302
355
|
}
|
|
303
356
|
}
|
|
304
|
-
|
|
305
|
-
|
|
357
|
+
if (td->inUse() == 0)
|
|
358
|
+
td->calcReclordlen();
|
|
306
359
|
return m_stat;
|
|
307
360
|
}
|
|
308
361
|
|
|
@@ -312,13 +365,14 @@ void dbdef::updateTableDef(short TableIndex, bool forPsqlDdf)
|
|
|
312
365
|
return;
|
|
313
366
|
|
|
314
367
|
tabledef* td = tableDefs(TableIndex);
|
|
368
|
+
if (!testTablePtr(td)) return;
|
|
315
369
|
|
|
316
|
-
if (
|
|
370
|
+
if (m_dimpl->noWriteMode)
|
|
317
371
|
{
|
|
318
372
|
m_stat = STATUS_ACCESS_DENIED;
|
|
319
373
|
return;
|
|
320
374
|
}
|
|
321
|
-
if (
|
|
375
|
+
if (m_dimpl->deftype == TYPE_SCHEMA_DDF)
|
|
322
376
|
saveDDF(TableIndex, 3, forPsqlDdf);
|
|
323
377
|
else
|
|
324
378
|
{
|
|
@@ -326,44 +380,45 @@ void dbdef::updateTableDef(short TableIndex, bool forPsqlDdf)
|
|
|
326
380
|
if (m_stat == STATUS_SUCCESS)
|
|
327
381
|
{
|
|
328
382
|
m_pdata = td;
|
|
329
|
-
m_buflen =
|
|
330
|
-
cacheFieldPos(td);
|
|
383
|
+
m_buflen = td->size();
|
|
331
384
|
td->formatVersion = FORMAT_VERSON_CURRENT;
|
|
332
385
|
update();
|
|
333
|
-
m_pdata =
|
|
334
|
-
m_buflen =
|
|
386
|
+
m_pdata = m_dimpl->bdf;
|
|
387
|
+
m_buflen = m_dimpl->bdfLen;
|
|
388
|
+
if (m_stat == STATUS_SUCCESS)
|
|
389
|
+
setDefaultImage(TableIndex, NULL, 0);
|
|
335
390
|
}
|
|
336
391
|
}
|
|
337
392
|
}
|
|
338
393
|
|
|
339
394
|
void dbdef::deleteTable(short TableIndex)
|
|
340
395
|
{
|
|
341
|
-
|
|
342
|
-
if (
|
|
343
|
-
{
|
|
344
|
-
free(tableDefs(TableIndex));
|
|
345
|
-
m_impl->tableDefs[TableIndex] = NULL;
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
396
|
+
tabledef* td = tableDefs(TableIndex);
|
|
397
|
+
if (!testTablePtr(td)) return;
|
|
348
398
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
else
|
|
399
|
+
m_stat = STATUS_SUCCESS;
|
|
400
|
+
if (m_dimpl->noWriteMode == false)
|
|
352
401
|
{
|
|
353
|
-
|
|
354
|
-
|
|
402
|
+
if (m_dimpl->deftype == TYPE_SCHEMA_DDF)
|
|
403
|
+
saveDDF(TableIndex, 4);
|
|
404
|
+
else
|
|
355
405
|
{
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
406
|
+
moveById(td->id);
|
|
407
|
+
if (m_stat == STATUS_SUCCESS)
|
|
408
|
+
{
|
|
409
|
+
m_pdata = td;
|
|
410
|
+
m_buflen = td->size();
|
|
411
|
+
del();
|
|
412
|
+
m_pdata = m_dimpl->bdf;
|
|
413
|
+
m_buflen = m_dimpl->bdfLen;
|
|
414
|
+
}
|
|
361
415
|
}
|
|
362
416
|
}
|
|
363
417
|
if (m_stat == STATUS_SUCCESS)
|
|
364
418
|
{
|
|
365
|
-
|
|
366
|
-
|
|
419
|
+
setDefaultImage(TableIndex, NULL, 0);
|
|
420
|
+
free(td);
|
|
421
|
+
m_dimpl->tableDefs[TableIndex] = NULL;
|
|
367
422
|
}
|
|
368
423
|
}
|
|
369
424
|
|
|
@@ -372,9 +427,12 @@ void dbdef::renumberFieldNum(short TableIndex, short Index, short op)
|
|
|
372
427
|
int i, j;
|
|
373
428
|
keydef* KeyDef;
|
|
374
429
|
|
|
375
|
-
|
|
430
|
+
tabledef* td = tableDefs(TableIndex);
|
|
431
|
+
if (!testTablePtr(td)) return;
|
|
432
|
+
|
|
433
|
+
for (i = 0; i < td->keyCount; i++)
|
|
376
434
|
{
|
|
377
|
-
KeyDef = &(
|
|
435
|
+
KeyDef = &(td->keyDefs[i]);
|
|
378
436
|
|
|
379
437
|
for (j = 0; j < KeyDef->segmentCount; j++)
|
|
380
438
|
{
|
|
@@ -397,10 +455,12 @@ bool dbdef::isUsedField(short TableIndex, short DeleteIndex)
|
|
|
397
455
|
{
|
|
398
456
|
int i, j;
|
|
399
457
|
keydef* KeyDef;
|
|
458
|
+
tabledef* td = tableDefs(TableIndex);
|
|
459
|
+
if (!testTablePtr(td)) return false;
|
|
400
460
|
|
|
401
|
-
for (i = 0; i <
|
|
461
|
+
for (i = 0; i < td->keyCount; i++)
|
|
402
462
|
{
|
|
403
|
-
KeyDef = &(
|
|
463
|
+
KeyDef = &(td->keyDefs[i]);
|
|
404
464
|
for (j = 0; j < KeyDef->segmentCount; j++)
|
|
405
465
|
{
|
|
406
466
|
if (KeyDef->segments[j].fieldNum == DeleteIndex)
|
|
@@ -426,11 +486,11 @@ void dbdef::deleteField(short TableIndex, short DeleteIndex)
|
|
|
426
486
|
else
|
|
427
487
|
{
|
|
428
488
|
memmove(&td->fieldDefs[DeleteIndex], &td->fieldDefs[DeleteIndex + 1],
|
|
429
|
-
|
|
489
|
+
td->size() + (char*)td -
|
|
430
490
|
(char*)&(td->fieldDefs[DeleteIndex + 1]));
|
|
431
491
|
}
|
|
432
492
|
td->fieldCount--;
|
|
433
|
-
td->
|
|
493
|
+
td->setKeydefsPtr();
|
|
434
494
|
updateTableDef(TableIndex);
|
|
435
495
|
}
|
|
436
496
|
|
|
@@ -438,10 +498,11 @@ void dbdef::deleteKey(short TableIndex, short DeleteIndex)
|
|
|
438
498
|
{
|
|
439
499
|
m_stat = STATUS_SUCCESS;
|
|
440
500
|
tabledef* td = tableDefs(TableIndex);
|
|
501
|
+
if (!testTablePtr(td)) return ;
|
|
441
502
|
if (DeleteIndex != td->keyCount - 1)
|
|
442
503
|
{
|
|
443
504
|
memmove(&td->keyDefs[DeleteIndex], &td->keyDefs[DeleteIndex + 1],
|
|
444
|
-
|
|
505
|
+
td->size() + (char*)td -
|
|
445
506
|
(char*)&(td->keyDefs[DeleteIndex + 1]));
|
|
446
507
|
}
|
|
447
508
|
td->keyCount--;
|
|
@@ -458,76 +519,78 @@ void dbdef::deleteKey(short TableIndex, short DeleteIndex)
|
|
|
458
519
|
updateTableDef(TableIndex);
|
|
459
520
|
}
|
|
460
521
|
|
|
461
|
-
void dbdef::insertTable(tabledef*
|
|
522
|
+
void dbdef::insertTable(tabledef* td)
|
|
462
523
|
{
|
|
463
524
|
m_stat = STATUS_SUCCESS;
|
|
464
|
-
if (
|
|
525
|
+
if (td->id > TABLE_NUM_TMP)
|
|
465
526
|
{
|
|
466
527
|
m_stat = STATUS_TOO_MANY_TABLES;
|
|
467
528
|
return;
|
|
468
529
|
}
|
|
469
|
-
if (tableDefs(
|
|
530
|
+
if (tableDefs(td->id) != NULL)
|
|
470
531
|
{
|
|
471
532
|
m_stat = STATUS_DUPPLICATE_KEYVALUE;
|
|
472
533
|
return;
|
|
473
534
|
}
|
|
474
535
|
|
|
475
|
-
if (tableNumByName(
|
|
536
|
+
if (tableNumByName(td->tableName()) != -1)
|
|
476
537
|
{
|
|
477
538
|
m_stat = STATUS_DUPPLICATE_KEYVALUE;
|
|
478
539
|
return;
|
|
479
540
|
}
|
|
480
|
-
if (
|
|
541
|
+
if (td->fieldCount > 512)
|
|
481
542
|
{
|
|
482
543
|
m_stat = STATUS_TOO_MANY_FIELDS;
|
|
483
544
|
return;
|
|
484
545
|
}
|
|
485
|
-
|
|
546
|
+
|
|
547
|
+
m_dimpl->tableDefs[td->id] =
|
|
486
548
|
(tabledef*)malloc(USHRT_MAX /* sizeof(tabledef) */);
|
|
487
|
-
if (
|
|
549
|
+
if (m_dimpl->tableDefs[td->id] == NULL)
|
|
488
550
|
{
|
|
489
551
|
m_stat = STATUS_CANT_ALLOC_MEMORY;
|
|
490
552
|
return;
|
|
491
553
|
}
|
|
492
|
-
if ((
|
|
493
|
-
|
|
494
|
-
memcpy(
|
|
495
|
-
if (
|
|
554
|
+
if ((td->ddfid == 0) && (m_dimpl->deftype == TYPE_SCHEMA_DDF))
|
|
555
|
+
td->ddfid = getDDFNewTableIndex();
|
|
556
|
+
memcpy(m_dimpl->tableDefs[td->id], td, sizeof(tabledef));
|
|
557
|
+
if (m_dimpl->noWriteMode)
|
|
496
558
|
{
|
|
497
|
-
if (
|
|
498
|
-
|
|
559
|
+
if (m_dimpl->tableCount < td->id)
|
|
560
|
+
m_dimpl->tableCount = td->id;
|
|
499
561
|
return;
|
|
500
562
|
}
|
|
501
|
-
|
|
502
|
-
if (
|
|
503
|
-
saveDDF(
|
|
563
|
+
td->formatVersion = FORMAT_VERSON_CURRENT;
|
|
564
|
+
if (m_dimpl->deftype == TYPE_SCHEMA_DDF)
|
|
565
|
+
saveDDF(td->id, 2);
|
|
504
566
|
else
|
|
505
567
|
{
|
|
506
|
-
memcpy(
|
|
507
|
-
m_pdata =
|
|
568
|
+
memcpy(m_dimpl->bdf, td, sizeof(tabledef));
|
|
569
|
+
m_pdata = m_dimpl->bdf;
|
|
508
570
|
|
|
509
|
-
memcpy(m_keybuf, &
|
|
571
|
+
memcpy(m_keybuf, &td->id, 2);
|
|
510
572
|
m_buflen = sizeof(tabledef);
|
|
511
|
-
if (isUseTransactd())
|
|
512
|
-
m_impl->bdf->varSize = m_buflen - 4;
|
|
513
573
|
insert();
|
|
514
|
-
m_pdata =
|
|
515
|
-
m_buflen =
|
|
574
|
+
m_pdata = m_dimpl->bdf;
|
|
575
|
+
m_buflen = m_dimpl->bdfLen;
|
|
516
576
|
}
|
|
517
577
|
if (m_stat != 0)
|
|
518
578
|
{
|
|
519
|
-
free(
|
|
520
|
-
|
|
579
|
+
free(m_dimpl->tableDefs[td->id]);
|
|
580
|
+
m_dimpl->tableDefs[td->id] = NULL;
|
|
521
581
|
}
|
|
522
582
|
else
|
|
523
583
|
{
|
|
524
|
-
if (
|
|
525
|
-
|
|
584
|
+
if (m_dimpl->tableCount < td->id)
|
|
585
|
+
m_dimpl->tableCount = td->id;
|
|
526
586
|
}
|
|
527
587
|
}
|
|
528
588
|
|
|
529
589
|
bool dbdef::resizeAt(short TableIndex, bool key)
|
|
530
590
|
{
|
|
591
|
+
tabledef* def = m_dimpl->tableDefs[TableIndex];
|
|
592
|
+
if (!key && def->m_inUse != 0) return false;
|
|
593
|
+
|
|
531
594
|
uint_td addsize;
|
|
532
595
|
|
|
533
596
|
if (key == true)
|
|
@@ -535,47 +598,43 @@ bool dbdef::resizeAt(short TableIndex, bool key)
|
|
|
535
598
|
else
|
|
536
599
|
addsize = sizeof(fielddef);
|
|
537
600
|
|
|
538
|
-
uint_td size =
|
|
539
|
-
|
|
601
|
+
uint_td size = def->size() + addsize;
|
|
602
|
+
|
|
540
603
|
void* p = malloc(size);
|
|
541
604
|
if (p)
|
|
542
605
|
{
|
|
543
|
-
memcpy(p, def,
|
|
606
|
+
memcpy(p, def, def->size());
|
|
544
607
|
free(def);
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
return false;
|
|
608
|
+
m_dimpl->tableDefs[TableIndex] = def = (tabledef*)p;
|
|
609
|
+
// init for memcpy
|
|
610
|
+
def->setFielddefsPtr();
|
|
611
|
+
def->setKeydefsPtr();
|
|
612
|
+
return true;
|
|
551
613
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
def->keyDefs = getKeyDef(def);
|
|
555
|
-
return true;
|
|
614
|
+
m_stat = STATUS_CANT_ALLOC_MEMORY;
|
|
615
|
+
return false;
|
|
556
616
|
}
|
|
557
617
|
|
|
558
618
|
keydef* dbdef::insertKey(short TableIndex, short InsertIndex)
|
|
559
619
|
{
|
|
560
|
-
|
|
561
620
|
if (resizeAt(TableIndex, true) == false)
|
|
562
621
|
return NULL;
|
|
563
622
|
|
|
623
|
+
tabledef* td = m_dimpl->tableDefs[TableIndex];
|
|
564
624
|
if (InsertIndex < tableDefs(TableIndex)->keyCount)
|
|
565
625
|
{
|
|
566
|
-
memmove(&
|
|
567
|
-
&
|
|
568
|
-
|
|
569
|
-
(char*)&(tableDefs(TableIndex)->keyDefs[InsertIndex]));
|
|
626
|
+
memmove(&td->keyDefs[InsertIndex + 1],
|
|
627
|
+
&td->keyDefs[InsertIndex],
|
|
628
|
+
td->size() + (char*)td - (char*)&(td->keyDefs[InsertIndex]));
|
|
570
629
|
}
|
|
571
|
-
|
|
572
|
-
memset(&(
|
|
630
|
+
td->keyCount++;
|
|
631
|
+
memset(&(td->keyDefs[InsertIndex]), 0, sizeof(keydef));
|
|
573
632
|
|
|
574
|
-
if ((!
|
|
633
|
+
if ((!m_dimpl->noWriteMode) && (m_dimpl->deftype != TYPE_SCHEMA_DDF))
|
|
575
634
|
updateTableDef(TableIndex);
|
|
576
635
|
else
|
|
577
|
-
|
|
578
|
-
return &(
|
|
636
|
+
td->calcReclordlen();
|
|
637
|
+
return &(td->keyDefs[InsertIndex]);
|
|
579
638
|
}
|
|
580
639
|
|
|
581
640
|
fielddef* dbdef::insertField(short TableIndex, short InsertIndex)
|
|
@@ -589,14 +648,13 @@ fielddef* dbdef::insertField(short TableIndex, short InsertIndex)
|
|
|
589
648
|
|
|
590
649
|
memmove(&(td->fieldDefs[InsertIndex + 1]),
|
|
591
650
|
&(td->fieldDefs[InsertIndex]),
|
|
592
|
-
|
|
651
|
+
td->size() + (char*)td -
|
|
593
652
|
(char*)&(td->fieldDefs[InsertIndex]));
|
|
594
653
|
}
|
|
595
654
|
td->fieldCount++;
|
|
596
|
-
td->
|
|
655
|
+
td->setKeydefsPtr();
|
|
597
656
|
renumberFieldNum(TableIndex, InsertIndex, 2);
|
|
598
657
|
memset(&(td->fieldDefs[InsertIndex]), 0, sizeof(fielddef));
|
|
599
|
-
setRecordLen(TableIndex);
|
|
600
658
|
fielddef* fd = &(td->fieldDefs[InsertIndex]);
|
|
601
659
|
fd->setCharsetIndex(td->charsetIndex);
|
|
602
660
|
fd->setSchemaCodePage(td->schemaCodePage);
|
|
@@ -604,16 +662,6 @@ fielddef* dbdef::insertField(short TableIndex, short InsertIndex)
|
|
|
604
662
|
return fd;
|
|
605
663
|
}
|
|
606
664
|
|
|
607
|
-
int dbdef::totalDefLength(short TableIndex)
|
|
608
|
-
{
|
|
609
|
-
tabledef* td = tableDefs(TableIndex);
|
|
610
|
-
int len = (int)(sizeof(tabledef) + (sizeof(fielddef) * td->fieldCount) +
|
|
611
|
-
(sizeof(keydef) * td->keyCount));
|
|
612
|
-
if (isUseTransactd())
|
|
613
|
-
td->varSize = len - 4;
|
|
614
|
-
return len;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
665
|
inline fielddef_t_my& dbdef::convert(fielddef_t_my& fd_my,
|
|
618
666
|
const fielddef_t_pv& fd_pv)
|
|
619
667
|
{
|
|
@@ -626,11 +674,11 @@ inline fielddef_t_my& dbdef::convert(fielddef_t_my& fd_my,
|
|
|
626
674
|
return fd_my;
|
|
627
675
|
}
|
|
628
676
|
|
|
629
|
-
inline int fixVariableLenBug(bool isUseTransactd, tabledef* src, size_t size)
|
|
677
|
+
inline int fixVariableLenBug(bool isUseTransactd, const tabledef* src, size_t size)
|
|
630
678
|
{
|
|
631
679
|
if (isUseTransactd)
|
|
632
680
|
{ // A Transactd server format changed to nosupport FIXED_PLUS_VARIABLELEN
|
|
633
|
-
if (src->
|
|
681
|
+
if (src->varSize + 4 == (int)size)
|
|
634
682
|
{ // This is a chagned server
|
|
635
683
|
if (src->preAlloc &&
|
|
636
684
|
((src->preAlloc % 512 == 0) || (src->fieldCount > 255) ||
|
|
@@ -645,22 +693,21 @@ inline int fixVariableLenBug(bool isUseTransactd, tabledef* src, size_t size)
|
|
|
645
693
|
return (int)size;
|
|
646
694
|
}
|
|
647
695
|
|
|
648
|
-
size_t getNewVersionSize(tabledef* src)
|
|
696
|
+
size_t getNewVersionSize(const tabledef* src)
|
|
649
697
|
{
|
|
650
698
|
return src->fieldCount * sizeof(fielddef) + sizeof(tabledef) +
|
|
651
699
|
src->keyCount * sizeof(keydef) + 1;
|
|
652
700
|
}
|
|
653
701
|
|
|
654
|
-
void dbdef::tableDefCopy(tabledef* dest, tabledef* src, size_t size)
|
|
702
|
+
void dbdef::tableDefCopy(tabledef* dest, const tabledef* src, size_t size)
|
|
655
703
|
{
|
|
656
|
-
|
|
657
704
|
if (src->formatVersion == FORMAT_VERSON_BTRV_DEF)
|
|
658
705
|
{
|
|
659
706
|
size_t len = 0;
|
|
660
707
|
memcpy(dest, src, sizeof(tabledef));
|
|
661
708
|
len += sizeof(tabledef);
|
|
662
|
-
fielddef_t_my* fd = (fielddef_t_my*)
|
|
663
|
-
fielddef_t_pv* src_fd = (fielddef_t_pv*)
|
|
709
|
+
fielddef_t_my* fd = (fielddef_t_my*)dest->setFielddefsPtr();
|
|
710
|
+
fielddef_t_pv* src_fd = (fielddef_t_pv*)const_cast<tabledef*>(src)->setFielddefsPtr();
|
|
664
711
|
for (int i = 0; i < dest->fieldCount; ++i)
|
|
665
712
|
{
|
|
666
713
|
convert(*fd, *src_fd);
|
|
@@ -678,7 +725,31 @@ void dbdef::tableDefCopy(tabledef* dest, tabledef* src, size_t size)
|
|
|
678
725
|
tabledef** dbdef::tableDefPtr(int index)
|
|
679
726
|
{
|
|
680
727
|
tableDefs(index);
|
|
681
|
-
return &
|
|
728
|
+
return &m_dimpl->tableDefs[index];
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
tabledef* dbdef::initReadAfter(short tableIndex, const tabledef* data, uint_td datalen)
|
|
732
|
+
{
|
|
733
|
+
m_datalen = fixVariableLenBug(isUseTransactd(), data, datalen);
|
|
734
|
+
size_t size = getNewVersionSize(data);
|
|
735
|
+
tabledef* td = (tabledef*)malloc(size + 10);
|
|
736
|
+
if (td == NULL)
|
|
737
|
+
{
|
|
738
|
+
m_stat = STATUS_CANT_ALLOC_MEMORY;
|
|
739
|
+
return NULL;
|
|
740
|
+
}
|
|
741
|
+
m_dimpl->tableDefs[tableIndex] = td;
|
|
742
|
+
tableDefCopy(td, data, min<size_t>(m_datalen, size));
|
|
743
|
+
td->setFielddefsPtr();
|
|
744
|
+
td->setKeydefsPtr();
|
|
745
|
+
td->autoIncExSpace = ((database*)nsdb())->defaultAutoIncSpace();
|
|
746
|
+
//Fix:Bug of maxRecordLen is mistake value saved, recalculate maxRecordLen.
|
|
747
|
+
td->calcReclordlen();
|
|
748
|
+
if (td->fieldDefs[td->fieldCount -1].type == ft_myfixedbinary)
|
|
749
|
+
td->optionFlags.bitC = true;
|
|
750
|
+
td->id = tableIndex;
|
|
751
|
+
td->defaultImage = NULL;
|
|
752
|
+
return td;
|
|
682
753
|
}
|
|
683
754
|
|
|
684
755
|
#pragma warn -8004
|
|
@@ -686,28 +757,25 @@ tabledef* dbdef::tableDefs(int index)
|
|
|
686
757
|
{
|
|
687
758
|
if (index > TABLE_NUM_TMP)
|
|
688
759
|
return NULL;
|
|
689
|
-
tabledef*
|
|
760
|
+
tabledef* td = m_dimpl->tableDefs[index];
|
|
690
761
|
|
|
691
762
|
if (index == TABLE_NUM_TMP)
|
|
692
|
-
return
|
|
693
|
-
if (
|
|
763
|
+
return td;
|
|
764
|
+
if (m_dimpl->tableCount < index)
|
|
694
765
|
return NULL;
|
|
695
|
-
if (
|
|
766
|
+
if (td == NULL)
|
|
696
767
|
{
|
|
697
|
-
if (
|
|
768
|
+
if (m_dimpl->deftype == TYPE_SCHEMA_DDF)
|
|
698
769
|
return NULL;
|
|
699
770
|
while (1)
|
|
700
771
|
{
|
|
701
|
-
m_pdata =
|
|
702
|
-
m_buflen =
|
|
703
|
-
|
|
704
|
-
memcpy(m_keybuf, &
|
|
772
|
+
m_pdata = m_dimpl->bdf;
|
|
773
|
+
m_buflen = m_dimpl->bdfLen;
|
|
774
|
+
m_dimpl->bdf->id = (short)index;
|
|
775
|
+
memcpy(m_keybuf, &m_dimpl->bdf->id, 2);
|
|
705
776
|
seek();
|
|
706
777
|
if (m_stat == STATUS_BUFFERTOOSMALL)
|
|
707
|
-
|
|
708
|
-
if (!resizeReadBuf())
|
|
709
|
-
return NULL;
|
|
710
|
-
}
|
|
778
|
+
return NULL;
|
|
711
779
|
else
|
|
712
780
|
break;
|
|
713
781
|
}
|
|
@@ -717,97 +785,78 @@ tabledef* dbdef::tableDefs(int index)
|
|
|
717
785
|
}
|
|
718
786
|
if (m_stat)
|
|
719
787
|
{
|
|
720
|
-
|
|
788
|
+
td = (tabledef*)-1;
|
|
721
789
|
m_stat = 0;
|
|
722
790
|
return NULL;
|
|
723
791
|
}
|
|
724
|
-
|
|
725
|
-
fixVariableLenBug(isUseTransactd(), (tabledef*)m_pdata, m_datalen);
|
|
726
|
-
size_t size = getNewVersionSize((tabledef*)m_pdata);
|
|
727
|
-
def = (tabledef*)malloc(size);
|
|
728
|
-
m_impl->tableDefs[index] = def;
|
|
729
|
-
if (def == NULL)
|
|
730
|
-
{
|
|
731
|
-
m_stat = STATUS_CANT_ALLOC_MEMORY;
|
|
732
|
-
return NULL;
|
|
733
|
-
}
|
|
734
|
-
tableDefCopy(def, (tabledef*)m_pdata, m_datalen);
|
|
735
|
-
def->fieldDefs = getFieldDef(def);
|
|
736
|
-
def->keyDefs = getKeyDef(def);
|
|
737
|
-
def->autoIncExSpace = ((database*)nsdb())->defaultAutoIncSpace();
|
|
738
|
-
|
|
739
|
-
setCodePage(def);
|
|
740
|
-
//Fix:Bug of maxRecordLen is mistake value saved, recalculate maxRecordLen.
|
|
741
|
-
setRecordLen(index);
|
|
792
|
+
td = initReadAfter(index, (tabledef*)m_pdata, m_datalen);
|
|
742
793
|
}
|
|
743
|
-
else if (
|
|
794
|
+
else if (td == (tabledef*)-1)
|
|
744
795
|
return NULL;
|
|
745
796
|
|
|
746
|
-
return
|
|
797
|
+
return td;
|
|
747
798
|
}
|
|
748
799
|
#pragma warn .8004
|
|
749
800
|
|
|
750
|
-
void dbdef::doOpen(const _TCHAR*
|
|
801
|
+
void dbdef::doOpen(const _TCHAR* uri, char_td mode, const _TCHAR* onerName)
|
|
751
802
|
{
|
|
752
|
-
|
|
803
|
+
m_dimpl->noWriteMode = true;
|
|
753
804
|
|
|
754
|
-
if (
|
|
805
|
+
if (m_dimpl->deftype == TYPE_SCHEMA_DDF)
|
|
755
806
|
{
|
|
756
807
|
|
|
757
|
-
openDdf(((database*)nsdb())->rootDir(), mode,
|
|
808
|
+
openDdf(((database*)nsdb())->rootDir(), mode, onerName); // DDF
|
|
758
809
|
if (mode != TD_OPEN_READONLY)
|
|
759
|
-
|
|
810
|
+
m_dimpl->noWriteMode = false;
|
|
760
811
|
return;
|
|
761
812
|
}
|
|
762
813
|
|
|
763
814
|
// version check
|
|
764
|
-
|
|
765
|
-
nstable::doOpen(
|
|
815
|
+
m_dimpl->version[7] = '0';
|
|
816
|
+
nstable::doOpen(uri, mode, m_dimpl->version);
|
|
766
817
|
if (m_stat == STATUS_INVALID_OWNERNAME)
|
|
767
818
|
{
|
|
768
819
|
while (m_stat == STATUS_INVALID_OWNERNAME)
|
|
769
820
|
{
|
|
770
|
-
|
|
771
|
-
nstable::doOpen(
|
|
772
|
-
if (
|
|
821
|
+
m_dimpl->version[7]++;
|
|
822
|
+
nstable::doOpen(uri, mode, m_dimpl->version);
|
|
823
|
+
if (m_dimpl->version[7] > '9')
|
|
773
824
|
return;
|
|
774
825
|
}
|
|
775
826
|
}
|
|
776
|
-
if (m_stat)
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
m_buflen =
|
|
827
|
+
if (m_stat) return;
|
|
828
|
+
|
|
829
|
+
if (m_dimpl->bdf == NULL)
|
|
830
|
+
allocDatabuffer();
|
|
831
|
+
if (m_stat) return;
|
|
832
|
+
|
|
833
|
+
m_pdata = m_dimpl->bdf;
|
|
834
|
+
m_buflen = m_dimpl->bdfLen;
|
|
784
835
|
m_keynum = 0;
|
|
785
|
-
|
|
786
836
|
seekLast();
|
|
787
837
|
if (m_stat == STATUS_SUCCESS)
|
|
788
|
-
|
|
838
|
+
m_dimpl->tableCount = m_dimpl->bdf->id;
|
|
789
839
|
if (m_stat == STATUS_EOF)
|
|
790
840
|
m_stat = STATUS_SUCCESS;
|
|
791
841
|
if (mode != TD_OPEN_READONLY)
|
|
792
|
-
|
|
793
|
-
|
|
842
|
+
m_dimpl->noWriteMode = false;
|
|
843
|
+
m_dimpl->openMode = mode;
|
|
794
844
|
}
|
|
795
845
|
|
|
796
846
|
void dbdef::doClose()
|
|
797
847
|
{
|
|
798
848
|
nstable::doClose();
|
|
799
|
-
if (
|
|
849
|
+
if (m_dimpl->bdf)
|
|
800
850
|
{
|
|
801
|
-
free(
|
|
802
|
-
|
|
851
|
+
free(m_dimpl->bdf);
|
|
852
|
+
m_dimpl->bdf = NULL;
|
|
803
853
|
}
|
|
804
|
-
|
|
854
|
+
m_dimpl->openMode = 1;
|
|
805
855
|
}
|
|
806
856
|
|
|
807
857
|
void dbdef::create(const _TCHAR* fullpath)
|
|
808
858
|
{
|
|
809
|
-
|
|
810
|
-
if (m_impl->deftype == TYPE_SCHEMA_DDF)
|
|
859
|
+
if (m_dimpl->deftype == TYPE_SCHEMA_DDF)
|
|
811
860
|
{
|
|
812
861
|
createDDF(fullpath);
|
|
813
862
|
return;
|
|
@@ -845,25 +894,6 @@ void dbdef::drop()
|
|
|
845
894
|
m_stat = nsdb()->stat();
|
|
846
895
|
}
|
|
847
896
|
|
|
848
|
-
ushort_td dbdef::getRecordLen(short TableIndex)
|
|
849
|
-
{
|
|
850
|
-
ushort_td ret = 0;
|
|
851
|
-
short i;
|
|
852
|
-
tabledef* td = tableDefs(TableIndex);
|
|
853
|
-
for (i = 0; i < td->fieldCount; i++)
|
|
854
|
-
ret += td->fieldDefs[i].len/* + td->fieldDefs[i].varLenBytes()*/;
|
|
855
|
-
return ret;
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
ushort_td dbdef::getFieldPosition(tabledef* TableDef, short FieldNum)
|
|
859
|
-
{
|
|
860
|
-
short i;
|
|
861
|
-
ushort_td pos = 1;
|
|
862
|
-
for (i = 0; i < FieldNum; i++)
|
|
863
|
-
pos += TableDef->fieldDefs[i].len;
|
|
864
|
-
return pos;
|
|
865
|
-
}
|
|
866
|
-
|
|
867
897
|
void dbdef::getFileSpec(fileSpec* fs, short TableIndex)
|
|
868
898
|
{
|
|
869
899
|
keySpec* ks;
|
|
@@ -887,7 +917,7 @@ void dbdef::getFileSpec(fileSpec* fs, short TableIndex)
|
|
|
887
917
|
{
|
|
888
918
|
FieldNum = KeyDef->segments[j].fieldNum;
|
|
889
919
|
ks = &(fs->keySpecs[k]);
|
|
890
|
-
ks->keyPos =
|
|
920
|
+
ks->keyPos = TableDef->fieldDefs[FieldNum].pos;
|
|
891
921
|
ks->keyLen = TableDef->fieldDefs[FieldNum].len;
|
|
892
922
|
ks->keyFlag.all = KeyDef->segments[j].flags.all;
|
|
893
923
|
ks->keyCount = 0;
|
|
@@ -919,83 +949,72 @@ void dbdef::renumberTable(short OldIndex, short NewIndex)
|
|
|
919
949
|
m_stat = STATUS_TOO_MANY_TABLES;
|
|
920
950
|
return;
|
|
921
951
|
}
|
|
922
|
-
|
|
952
|
+
tabledef* td = tableDefs(OldIndex);
|
|
953
|
+
if (m_dimpl->noWriteMode)
|
|
923
954
|
{
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
if (NewIndex >
|
|
928
|
-
|
|
955
|
+
td->id = NewIndex;
|
|
956
|
+
m_dimpl->tableDefs[NewIndex] = td;
|
|
957
|
+
m_dimpl->tableDefs[OldIndex] = NULL;
|
|
958
|
+
if (NewIndex > m_dimpl->tableCount)
|
|
959
|
+
m_dimpl->tableCount = NewIndex;
|
|
929
960
|
return;
|
|
930
961
|
}
|
|
931
|
-
moveById(
|
|
962
|
+
moveById(td->id);
|
|
932
963
|
if (m_stat == STATUS_SUCCESS)
|
|
933
964
|
{
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
965
|
+
|
|
966
|
+
m_pdata = td;
|
|
967
|
+
m_buflen = td->size();
|
|
968
|
+
td->id = NewIndex;
|
|
937
969
|
update();
|
|
938
|
-
m_pdata =
|
|
939
|
-
m_buflen =
|
|
970
|
+
m_pdata = m_dimpl->bdf;
|
|
971
|
+
m_buflen = m_dimpl->bdfLen;
|
|
940
972
|
|
|
941
973
|
if (m_stat == STATUS_SUCCESS)
|
|
942
974
|
{
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
if (NewIndex >
|
|
946
|
-
|
|
975
|
+
m_dimpl->tableDefs[NewIndex] = td;
|
|
976
|
+
m_dimpl->tableDefs[OldIndex] = NULL;
|
|
977
|
+
if (NewIndex > m_dimpl->tableCount)
|
|
978
|
+
m_dimpl->tableCount = NewIndex;
|
|
947
979
|
}
|
|
948
980
|
else
|
|
949
|
-
|
|
981
|
+
td->id = OldIndex;
|
|
950
982
|
}
|
|
951
983
|
}
|
|
952
984
|
|
|
953
|
-
void dbdef::cacheFieldPos(tabledef* TableDef)
|
|
954
|
-
{
|
|
955
|
-
|
|
956
|
-
short i;
|
|
957
|
-
for (i = 0; i < TableDef->fieldCount; i++)
|
|
958
|
-
TableDef->fieldDefs[i].pos =
|
|
959
|
-
(ushort_td)(getFieldPosition(TableDef, i) - 1);
|
|
960
|
-
}
|
|
961
|
-
|
|
962
985
|
short dbdef::fieldNumByViewNum(short TableIndex, short index)
|
|
963
986
|
{
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
for (i = 0; i < TableDef->fieldCount; i++)
|
|
987
|
+
tabledef* td = tableDefs(TableIndex);
|
|
988
|
+
if (td)
|
|
967
989
|
{
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
990
|
+
for (short i = 0; i < td->fieldCount; i++)
|
|
991
|
+
{
|
|
992
|
+
if ((td->fieldDefs[i].viewNum == index) &&
|
|
993
|
+
(td->fieldDefs[i].enableFlags.bit0))
|
|
994
|
+
return i;
|
|
995
|
+
}
|
|
971
996
|
}
|
|
972
997
|
return -1;
|
|
973
998
|
}
|
|
974
999
|
|
|
975
1000
|
short dbdef::findKeynumByFieldNum(short TableIndex, short index)
|
|
976
1001
|
{
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
for (i = 0; i < TableDef->keyCount; i++)
|
|
981
|
-
{
|
|
982
|
-
if (TableDef->keyDefs[i].segments[0].fieldNum == index)
|
|
983
|
-
return i;
|
|
984
|
-
}
|
|
1002
|
+
tabledef* td = tableDefs(TableIndex);
|
|
1003
|
+
if (td)
|
|
1004
|
+
return td->findKeynumByFieldNum(index);
|
|
985
1005
|
return -1;
|
|
986
1006
|
}
|
|
987
1007
|
|
|
988
1008
|
short dbdef::tableNumByName(const _TCHAR* tableName)
|
|
989
1009
|
{
|
|
990
|
-
short i;
|
|
991
1010
|
char buf[74];
|
|
992
|
-
|
|
993
|
-
for (i = 1; i <= m_impl->tableCount; i++)
|
|
1011
|
+
for (short i = 1; i <= m_dimpl->tableCount; i++)
|
|
994
1012
|
{
|
|
995
|
-
|
|
1013
|
+
tabledef* td = tableDefs(i);
|
|
1014
|
+
if (td)
|
|
996
1015
|
{
|
|
997
|
-
const char* p =
|
|
998
|
-
if (strcmp(
|
|
1016
|
+
const char* p = td->toChar(buf, tableName, 74);
|
|
1017
|
+
if (strcmp(td->tableNameA(), p) == 0)
|
|
999
1018
|
return i;
|
|
1000
1019
|
}
|
|
1001
1020
|
}
|
|
@@ -1004,14 +1023,9 @@ short dbdef::tableNumByName(const _TCHAR* tableName)
|
|
|
1004
1023
|
|
|
1005
1024
|
short dbdef::fieldNumByName(short TableIndex, const _TCHAR* name)
|
|
1006
1025
|
{
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
for (i = 0; i < tableDefs(TableIndex)->fieldCount; i++)
|
|
1011
|
-
{
|
|
1012
|
-
if (strcmp(tableDefs(TableIndex)->fieldDefs[i].nameA(), p) == 0)
|
|
1013
|
-
return i;
|
|
1014
|
-
}
|
|
1026
|
+
tabledef* td = tableDefs(TableIndex);
|
|
1027
|
+
if (td)
|
|
1028
|
+
return td->fieldNumByName(name);
|
|
1015
1029
|
return -1;
|
|
1016
1030
|
}
|
|
1017
1031
|
|
|
@@ -1046,7 +1060,13 @@ uint_td dbdef::fieldValidLength(eFieldQuery query, uchar_td FieldType)
|
|
|
1046
1060
|
case ft_mytext:
|
|
1047
1061
|
minlen = 9;
|
|
1048
1062
|
maxlen = 12;
|
|
1049
|
-
defaultlen =
|
|
1063
|
+
defaultlen = 9;
|
|
1064
|
+
break;
|
|
1065
|
+
case ft_mygeometry:
|
|
1066
|
+
case ft_myjson:
|
|
1067
|
+
minlen = 12;
|
|
1068
|
+
maxlen = 12;
|
|
1069
|
+
defaultlen = 12;
|
|
1050
1070
|
break;
|
|
1051
1071
|
case ft_mywchar:
|
|
1052
1072
|
case ft_wstring:
|
|
@@ -1070,6 +1090,11 @@ uint_td dbdef::fieldValidLength(eFieldQuery query, uchar_td FieldType)
|
|
|
1070
1090
|
maxlen = 60000;
|
|
1071
1091
|
defaultlen = 1024;
|
|
1072
1092
|
break;
|
|
1093
|
+
case ft_myyear:
|
|
1094
|
+
minlen = 1;
|
|
1095
|
+
maxlen = 1;
|
|
1096
|
+
defaultlen = 1;
|
|
1097
|
+
break;
|
|
1073
1098
|
case ft_mydate:
|
|
1074
1099
|
minlen = 3;
|
|
1075
1100
|
maxlen = 3;
|
|
@@ -1122,7 +1147,12 @@ uint_td dbdef::fieldValidLength(eFieldQuery query, uchar_td FieldType)
|
|
|
1122
1147
|
if (FieldType == 17)
|
|
1123
1148
|
minlen = 2;
|
|
1124
1149
|
break;
|
|
1125
|
-
|
|
1150
|
+
case ft_mydecimal:
|
|
1151
|
+
minlen = 1;
|
|
1152
|
+
maxlen = 32;
|
|
1153
|
+
defaultlen = 5;
|
|
1154
|
+
dec = 0;
|
|
1155
|
+
break;
|
|
1126
1156
|
case ft_note:
|
|
1127
1157
|
minlen = 2;
|
|
1128
1158
|
maxlen = 32761;
|
|
@@ -1145,8 +1175,14 @@ uint_td dbdef::fieldValidLength(eFieldQuery query, uchar_td FieldType)
|
|
|
1145
1175
|
defaultlen = 4;
|
|
1146
1176
|
break;
|
|
1147
1177
|
case ft_bit:
|
|
1178
|
+
case ft_set:
|
|
1148
1179
|
minlen = 1;
|
|
1149
|
-
maxlen =
|
|
1180
|
+
maxlen = 8;
|
|
1181
|
+
defaultlen = 1;
|
|
1182
|
+
break;
|
|
1183
|
+
case ft_enum:
|
|
1184
|
+
minlen = 1;
|
|
1185
|
+
maxlen = 2;
|
|
1150
1186
|
defaultlen = 1;
|
|
1151
1187
|
break;
|
|
1152
1188
|
case ft_timestamp:
|
|
@@ -1165,7 +1201,6 @@ uint_td dbdef::fieldValidLength(eFieldQuery query, uchar_td FieldType)
|
|
|
1165
1201
|
maxlen = 8;
|
|
1166
1202
|
defaultlen = 5;
|
|
1167
1203
|
break;
|
|
1168
|
-
|
|
1169
1204
|
case ft_nullindicator:
|
|
1170
1205
|
minlen = 0;
|
|
1171
1206
|
maxlen = 0;
|
|
@@ -1192,7 +1227,7 @@ bool dbdef::validLen(uchar_td FieldType, uint_td FieldLen)
|
|
|
1192
1227
|
{
|
|
1193
1228
|
if ((FieldType == ft_integer) || (FieldType == ft_uinteger))
|
|
1194
1229
|
{
|
|
1195
|
-
if ((FieldLen == 1) || (FieldLen == 2) || (FieldLen == 4) ||
|
|
1230
|
+
if ((FieldLen == 1) || (FieldLen == 2) || (FieldLen == 3) || (FieldLen == 4) ||
|
|
1196
1231
|
(FieldLen == 8))
|
|
1197
1232
|
return true;
|
|
1198
1233
|
else
|
|
@@ -1200,7 +1235,7 @@ bool dbdef::validLen(uchar_td FieldType, uint_td FieldLen)
|
|
|
1200
1235
|
}
|
|
1201
1236
|
else if ((FieldType == ft_autoinc) || (FieldType == ft_autoIncUnsigned))
|
|
1202
1237
|
{
|
|
1203
|
-
if ((FieldLen == 2) || (FieldLen == 4) || (FieldLen == 8))
|
|
1238
|
+
if ((FieldLen == 2) || (FieldLen == 3) || (FieldLen == 4) || (FieldLen == 8))
|
|
1204
1239
|
return true;
|
|
1205
1240
|
else
|
|
1206
1241
|
return false;
|
|
@@ -1220,43 +1255,12 @@ bool dbdef::validLen(uchar_td FieldType, uint_td FieldLen)
|
|
|
1220
1255
|
|
|
1221
1256
|
bool dbdef::isPassKey(uchar_td FieldType)
|
|
1222
1257
|
{
|
|
1223
|
-
if (FieldType == ft_autoIncUnsigned)
|
|
1224
|
-
return true;
|
|
1225
|
-
if (FieldType == ft_wstring)
|
|
1226
|
-
return true;
|
|
1227
|
-
if (FieldType == ft_wzstring)
|
|
1228
|
-
return true;
|
|
1229
|
-
if (FieldType == ft_myvarchar)
|
|
1230
|
-
return true;
|
|
1231
|
-
if (FieldType == ft_myvarbinary)
|
|
1232
|
-
return true;
|
|
1233
|
-
if (FieldType == ft_mywvarchar)
|
|
1234
|
-
return true;
|
|
1235
|
-
if (FieldType == ft_mywvarbinary)
|
|
1236
|
-
return true;
|
|
1237
|
-
if (FieldType == ft_mychar)
|
|
1238
|
-
return true;
|
|
1239
|
-
if (FieldType == ft_mywchar)
|
|
1240
|
-
return true;
|
|
1241
|
-
|
|
1242
|
-
if (FieldType == ft_mytext)
|
|
1243
|
-
return true;
|
|
1244
|
-
if (FieldType == ft_myblob)
|
|
1245
|
-
return true;
|
|
1246
|
-
|
|
1247
|
-
if (FieldType == ft_mydate)
|
|
1248
|
-
return true;
|
|
1249
|
-
if (FieldType == ft_mytime)
|
|
1250
|
-
return true;
|
|
1251
|
-
if (FieldType == ft_mydatetime)
|
|
1252
|
-
return true;
|
|
1253
1258
|
if (FieldType == ft_myfixedbinary)
|
|
1254
1259
|
return false;
|
|
1255
|
-
|
|
1256
1260
|
if (FieldType == ft_bit)
|
|
1257
1261
|
return false;
|
|
1258
|
-
if (FieldType > ft_numericsts)
|
|
1259
|
-
|
|
1262
|
+
//if (FieldType > ft_numericsts)
|
|
1263
|
+
// return false;
|
|
1260
1264
|
if (FieldType == ft_note)
|
|
1261
1265
|
return false;
|
|
1262
1266
|
if (FieldType == ft_lvar)
|
|
@@ -1264,8 +1268,9 @@ bool dbdef::isPassKey(uchar_td FieldType)
|
|
|
1264
1268
|
return true;
|
|
1265
1269
|
}
|
|
1266
1270
|
|
|
1267
|
-
void dbdef::autoMakeSchema()
|
|
1271
|
+
void dbdef::autoMakeSchema(bool nouseNullkey)
|
|
1268
1272
|
{
|
|
1273
|
+
m_keynum = (int)nouseNullkey;
|
|
1269
1274
|
tdap(TD_AUTOMEKE_SCHEMA);
|
|
1270
1275
|
}
|
|
1271
1276
|
|
|
@@ -1327,11 +1332,11 @@ void dbdef::saveDDF(short TableIndex, short opration, bool forPsqlDdf)
|
|
|
1327
1332
|
|
|
1328
1333
|
if ((tb) && (fd) && (id))
|
|
1329
1334
|
{
|
|
1330
|
-
if (
|
|
1335
|
+
if (m_dimpl->userName[0] != 0x00)
|
|
1331
1336
|
{
|
|
1332
|
-
own[0] = (const _TCHAR*)
|
|
1333
|
-
own[1] = (const _TCHAR*)
|
|
1334
|
-
own[2] = (const _TCHAR*)
|
|
1337
|
+
own[0] = (const _TCHAR*)m_dimpl->userName;
|
|
1338
|
+
own[1] = (const _TCHAR*)m_dimpl->userName;
|
|
1339
|
+
own[2] = (const _TCHAR*)m_dimpl->userName;
|
|
1335
1340
|
}
|
|
1336
1341
|
else
|
|
1337
1342
|
{
|
|
@@ -1491,14 +1496,14 @@ void dbdef::openDdf(const _TCHAR* dir, short Mode, const _TCHAR* OwnerName)
|
|
|
1491
1496
|
own[0] = OwnerName;
|
|
1492
1497
|
own[1] = OwnerName;
|
|
1493
1498
|
own[2] = OwnerName;
|
|
1494
|
-
_tcscpy(
|
|
1499
|
+
_tcscpy(m_dimpl->userName, OwnerName);
|
|
1495
1500
|
}
|
|
1496
1501
|
else
|
|
1497
1502
|
{
|
|
1498
1503
|
own[0] = (_TCHAR*)ow0;
|
|
1499
1504
|
own[1] = (_TCHAR*)ow1;
|
|
1500
1505
|
own[2] = (_TCHAR*)ow2;
|
|
1501
|
-
|
|
1506
|
+
m_dimpl->userName[0] = 0x00;
|
|
1502
1507
|
}
|
|
1503
1508
|
|
|
1504
1509
|
tb->open(dir, (char_td)Mode, own[0]);
|
|
@@ -1595,9 +1600,9 @@ void dbdef::openDdf(const _TCHAR* dir, short Mode, const _TCHAR* OwnerName)
|
|
|
1595
1600
|
fd->seekNext();
|
|
1596
1601
|
}
|
|
1597
1602
|
|
|
1598
|
-
tableDefs(tbid)->
|
|
1603
|
+
tableDefs(tbid)->calcReclordlen();
|
|
1599
1604
|
|
|
1600
|
-
tableDefs(tbid)->fixedRecordLen = tableDefs(tbid)->
|
|
1605
|
+
tableDefs(tbid)->fixedRecordLen = tableDefs(tbid)->recordlen();
|
|
1601
1606
|
tableDefs(tbid)->parentKeyNum = -1;
|
|
1602
1607
|
tableDefs(tbid)->replicaKeyNum = -1;
|
|
1603
1608
|
tableDefs(tbid)->primaryKeyNum = -1;
|
|
@@ -1653,7 +1658,7 @@ ushort_td dbdef::getDDFNewTableIndex()
|
|
|
1653
1658
|
{
|
|
1654
1659
|
int i;
|
|
1655
1660
|
int max_id = 0;
|
|
1656
|
-
for (i = 0; i <=
|
|
1661
|
+
for (i = 0; i <= m_dimpl->tableCount; i++)
|
|
1657
1662
|
{
|
|
1658
1663
|
if (tableDefs(i) != NULL)
|
|
1659
1664
|
{
|
|
@@ -1668,22 +1673,22 @@ ushort_td dbdef::getDDFNewTableIndex()
|
|
|
1668
1673
|
ushort_td dbdef::getDDFNewFieldIndex()
|
|
1669
1674
|
{
|
|
1670
1675
|
int i, j;
|
|
1671
|
-
if (
|
|
1676
|
+
if (m_dimpl->maxid == 0)
|
|
1672
1677
|
{
|
|
1673
|
-
for (i = 0; i <=
|
|
1678
|
+
for (i = 0; i <= m_dimpl->tableCount; i++)
|
|
1674
1679
|
{
|
|
1675
1680
|
if (tableDefs(i) != NULL)
|
|
1676
1681
|
{
|
|
1677
1682
|
for (j = 0; j < tableDefs(i)->fieldCount; j++)
|
|
1678
1683
|
{
|
|
1679
|
-
if (tableDefs(i)->fieldDefs[j].ddfid >
|
|
1680
|
-
|
|
1684
|
+
if (tableDefs(i)->fieldDefs[j].ddfid > m_dimpl->maxid)
|
|
1685
|
+
m_dimpl->maxid = tableDefs(i)->fieldDefs[j].ddfid;
|
|
1681
1686
|
}
|
|
1682
1687
|
}
|
|
1683
1688
|
}
|
|
1684
1689
|
}
|
|
1685
|
-
|
|
1686
|
-
return (ushort_td)
|
|
1690
|
+
m_dimpl->maxid++;
|
|
1691
|
+
return (ushort_td)m_dimpl->maxid;
|
|
1687
1692
|
}
|
|
1688
1693
|
|
|
1689
1694
|
void setFieldsCharsetIndex(tabledef* def)
|
|
@@ -1698,68 +1703,76 @@ void setFieldsCharsetIndex(tabledef* def)
|
|
|
1698
1703
|
}
|
|
1699
1704
|
}
|
|
1700
1705
|
|
|
1701
|
-
void dbdef::pushBackup(short
|
|
1706
|
+
void dbdef::pushBackup(short tableIndex)
|
|
1702
1707
|
{
|
|
1703
1708
|
int blen;
|
|
1704
|
-
|
|
1705
|
-
|
|
1709
|
+
tabledef* td = tableDefs(tableIndex);
|
|
1710
|
+
if (!td)
|
|
1711
|
+
{
|
|
1712
|
+
m_stat = STATUS_INVALID_TABLE_IDX;
|
|
1713
|
+
return;
|
|
1714
|
+
}
|
|
1715
|
+
blen = td->size();
|
|
1706
1716
|
if (!tableDefs(TABLE_NUM_TMP))
|
|
1707
|
-
|
|
1717
|
+
m_dimpl->tableDefs[TABLE_NUM_TMP] = (tabledef*)malloc(blen);
|
|
1708
1718
|
else
|
|
1709
|
-
|
|
1719
|
+
m_dimpl->tableDefs[TABLE_NUM_TMP] =
|
|
1710
1720
|
(tabledef*)realloc(tableDefs(TABLE_NUM_TMP), blen);
|
|
1711
|
-
|
|
1721
|
+
|
|
1722
|
+
tabledef* tdt = m_dimpl->tableDefs[TABLE_NUM_TMP];
|
|
1723
|
+
if (!tdt)
|
|
1712
1724
|
{
|
|
1713
1725
|
m_stat = STATUS_CANT_ALLOC_MEMORY;
|
|
1714
1726
|
return;
|
|
1715
1727
|
}
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
td->keyDefs = getKeyDef(td);
|
|
1728
|
+
setFieldsCharsetIndex(td);
|
|
1729
|
+
memcpy(tdt, td, blen);
|
|
1730
|
+
tdt->m_inUse = 0;
|
|
1731
|
+
tdt->setFielddefsPtr();
|
|
1732
|
+
tdt->setKeydefsPtr();
|
|
1722
1733
|
|
|
1723
1734
|
}
|
|
1724
1735
|
|
|
1725
|
-
bool dbdef::compAsBackup(short
|
|
1736
|
+
bool dbdef::compAsBackup(short tableIndex)
|
|
1726
1737
|
{
|
|
1727
|
-
if (
|
|
1738
|
+
if (m_dimpl->tableCount < tableIndex)
|
|
1728
1739
|
return false;
|
|
1729
1740
|
|
|
1730
|
-
|
|
1731
|
-
int len2 = totalDefLength(TableIndex);
|
|
1732
|
-
if (len != len2)
|
|
1733
|
-
return true;
|
|
1734
|
-
tabledef* tds = tableDefs(TableIndex);
|
|
1741
|
+
tabledef* tds = tableDefs(tableIndex);
|
|
1735
1742
|
tabledef* tdo = tableDefs(TABLE_NUM_TMP);
|
|
1736
1743
|
|
|
1737
|
-
if (
|
|
1744
|
+
if (tds->size() != tdo->size())
|
|
1738
1745
|
return true;
|
|
1739
1746
|
|
|
1747
|
+
//tabledef
|
|
1748
|
+
bool isSame = (*tds == *tdo);
|
|
1749
|
+
if (!isSame) return true;
|
|
1750
|
+
|
|
1740
1751
|
for (int i = 0; i < tds->fieldCount; i++)
|
|
1741
1752
|
{
|
|
1742
|
-
|
|
1743
|
-
|
|
1753
|
+
isSame = (tds->fieldDefs[i] == tdo->fieldDefs[i]);
|
|
1754
|
+
if (!isSame) return true;
|
|
1744
1755
|
}
|
|
1745
1756
|
for (int i = 0; i < tds->keyCount; i++)
|
|
1746
1757
|
{
|
|
1747
|
-
|
|
1748
|
-
|
|
1758
|
+
isSame = (tds->keyDefs[i] == tdo->keyDefs[i]);
|
|
1759
|
+
if (!isSame) return true;
|
|
1749
1760
|
}
|
|
1750
1761
|
return false;
|
|
1751
1762
|
}
|
|
1752
1763
|
|
|
1753
|
-
void dbdef::popBackup(short
|
|
1764
|
+
void dbdef::popBackup(short tableIndex)
|
|
1754
1765
|
{
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1766
|
+
tabledef* tdt = tableDefs(TABLE_NUM_TMP);
|
|
1767
|
+
tabledef* td = m_dimpl->tableDefs[tableIndex];
|
|
1768
|
+
if (tdt && td)
|
|
1769
|
+
{
|
|
1770
|
+
m_dimpl->tableDefs[tableIndex] = td = (tabledef*)realloc(td, tdt->size());
|
|
1771
|
+
memcpy(td, tdt, tdt->size());
|
|
1772
|
+
td->setFielddefsPtr();
|
|
1773
|
+
td->setKeydefsPtr();
|
|
1774
|
+
updateTableDef(tableIndex);
|
|
1775
|
+
}
|
|
1763
1776
|
}
|
|
1764
1777
|
|
|
1765
1778
|
void dbdef::reopen(char_td mode)
|
|
@@ -1768,6 +1781,46 @@ void dbdef::reopen(char_td mode)
|
|
|
1768
1781
|
open(uri(), mode, NULL);
|
|
1769
1782
|
}
|
|
1770
1783
|
|
|
1784
|
+
void dbdef::synchronizeSeverSchema(short tableIndex)
|
|
1785
|
+
{
|
|
1786
|
+
if (!isUseTransactd()) return;
|
|
1787
|
+
|
|
1788
|
+
tabledef* tdold = tableDefs(tableIndex);
|
|
1789
|
+
if (!tdold) return;
|
|
1790
|
+
|
|
1791
|
+
void* tmp = m_keybuf;
|
|
1792
|
+
|
|
1793
|
+
_TCHAR dummyUrl[MAX_PATH] = _T("tdap://srv/db?dbfile=");
|
|
1794
|
+
_tcscat(dummyUrl, tdold->fileName());
|
|
1795
|
+
|
|
1796
|
+
char tmpName[MAX_PATH] = { 0x00 };
|
|
1797
|
+
const char* p = nsdatabase::toServerUri(tmpName, MAX_PATH, dummyUrl, true);
|
|
1798
|
+
m_keybuf = (void*)p;
|
|
1799
|
+
m_keylen = (keylen_td)strlen(p) + 1;
|
|
1800
|
+
m_pdata = m_dimpl->bdf;
|
|
1801
|
+
m_buflen = m_datalen = m_dimpl->bdfLen;
|
|
1802
|
+
m_dimpl->bdf->id = tableIndex;
|
|
1803
|
+
tdap((ushort_td)TD_GET_SCHEMA);
|
|
1804
|
+
if (m_stat == STATUS_SUCCESS)
|
|
1805
|
+
{
|
|
1806
|
+
if (m_datalen == 0)
|
|
1807
|
+
{
|
|
1808
|
+
m_stat = STATUS_NOSUPPORT_OP;
|
|
1809
|
+
m_keybuf = tmp;
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1812
|
+
tabledef* td = (tabledef*)m_pdata;
|
|
1813
|
+
td->m_mysqlNullMode = tdold->isMysqlNullMode();
|
|
1814
|
+
td = initReadAfter(tableIndex, td, m_datalen);
|
|
1815
|
+
if (td)
|
|
1816
|
+
{
|
|
1817
|
+
m_stat = td->synchronize(tdold);
|
|
1818
|
+
delete tdold;
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
m_keybuf = tmp;
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1771
1824
|
} // namespace client
|
|
1772
1825
|
} // namespace tdap
|
|
1773
1826
|
} // namespace protocol
|