~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/test/src/NDBT_Tables.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include <NDBT.hpp>
 
17
#include <NDBT_Table.hpp>
 
18
#include <NDBT_Tables.hpp>
 
19
 
 
20
/* ******************************************************* */
 
21
//    Define Ndb standard tables 
 
22
//
 
23
//  USE ONLY UPPERLETTERS IN TAB AND COLUMN NAMES
 
24
/* ******************************************************* */
 
25
 
 
26
/*
 
27
 * These are our "official" test tables
 
28
 *
 
29
 */
 
30
/* T1 */
 
31
static
 
32
const
 
33
NDBT_Attribute T1Attribs[] = {
 
34
  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true), 
 
35
  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned),
 
36
  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
 
37
  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
 
38
  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned),
 
39
};
 
40
static
 
41
const
 
42
NDBT_Table T1("T1", sizeof(T1Attribs)/sizeof(NDBT_Attribute), T1Attribs);
 
43
 
 
44
/* T2 */
 
45
static
 
46
const
 
47
NDBT_Attribute T2Attribs[] = {
 
48
  NDBT_Attribute("KOL1", NdbDictionary::Column::Bigunsigned, 1, true), 
 
49
  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned),
 
50
  NDBT_Attribute("KOL3", NdbDictionary::Column::Bit, 23),
 
51
  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned, 
 
52
                 1, false, true), // Nullable 
 
53
  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned)
 
54
};
 
55
static
 
56
const
 
57
NDBT_Table T2("T2", sizeof(T2Attribs)/sizeof(NDBT_Attribute), T2Attribs);
 
58
 
 
59
/* T3 */
 
60
static
 
61
const
 
62
NDBT_Attribute T3Attribs[] = {
 
63
  NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, 1, true), 
 
64
  NDBT_Attribute("PERSNR", NdbDictionary::Column::Char, 10),
 
65
  NDBT_Attribute("NAME", NdbDictionary::Column::Char, 25),
 
66
  NDBT_Attribute("ADRESS", NdbDictionary::Column::Char, 50),
 
67
  NDBT_Attribute("ADRESS2", NdbDictionary::Column::Char, 
 
68
                 30, false, true), // Nullable
 
69
  NDBT_Attribute("Fļæ½DELSEļæ½R", NdbDictionary::Column::Unsigned)
 
70
};
 
71
static
 
72
const
 
73
NDBT_Table T3("T3", sizeof(T3Attribs)/sizeof(NDBT_Attribute), T3Attribs);
 
74
 
 
75
/* T4 */
 
76
static
 
77
const
 
78
NDBT_Attribute T4Attribs[] = {
 
79
  NDBT_Attribute("REGNR", NdbDictionary::Column::Char, 6, true), 
 
80
  NDBT_Attribute("YEAR", NdbDictionary::Column::Unsigned),
 
81
  NDBT_Attribute("OWNER", NdbDictionary::Column::Char, 25),
 
82
  NDBT_Attribute("ADRESS", NdbDictionary::Column::Char, 50),
 
83
  NDBT_Attribute("ADRESS2", NdbDictionary::Column::Char, 
 
84
                 30, false, true), // Nullable
 
85
  NDBT_Attribute("OWNERID", NdbDictionary::Column::Unsigned),
 
86
  NDBT_Attribute("CHECKDATE", NdbDictionary::Column::Unsigned)
 
87
};
 
88
static
 
89
const
 
90
NDBT_Table T4("T4", sizeof(T4Attribs)/sizeof(NDBT_Attribute), T4Attribs);
 
91
 
 
92
/* T5 */
 
93
static
 
94
const
 
95
NDBT_Attribute T5Attribs[] = {
 
96
  NDBT_Attribute("OWNERID", NdbDictionary::Column::Unsigned, 1, true), 
 
97
  NDBT_Attribute("REGNR", NdbDictionary::Column::Char, 6, true),
 
98
  NDBT_Attribute("CREATEDDATE", NdbDictionary::Column::Unsigned)
 
99
};
 
100
static
 
101
const
 
102
NDBT_Table T5("T5", sizeof(T5Attribs)/sizeof(NDBT_Attribute), T5Attribs);
 
103
 
 
104
/* T6 */
 
105
static
 
106
const
 
107
NDBT_Attribute T6Attribs[] = {
 
108
  NDBT_Attribute("PK1", NdbDictionary::Column::Unsigned, 1, true), 
 
109
  NDBT_Attribute("ATTR1", NdbDictionary::Column::Unsigned),
 
110
  NDBT_Attribute("ATTR2", NdbDictionary::Column::Unsigned),
 
111
  NDBT_Attribute("ATTR3", NdbDictionary::Column::Unsigned),
 
112
  NDBT_Attribute("ATTR4", NdbDictionary::Column::Char, 
 
113
                 47, false, true),// Nullable
 
114
  NDBT_Attribute("ATTR5", NdbDictionary::Column::Unsigned),
 
115
  NDBT_Attribute("ATTR6", NdbDictionary::Column::Unsigned),
 
116
  NDBT_Attribute("ATTR7", NdbDictionary::Column::Char, 
 
117
                 48, false, true),// Nullable
 
118
  NDBT_Attribute("ATTR8", NdbDictionary::Column::Char, 
 
119
                 50, false, true), // Nullable
 
120
  NDBT_Attribute("ATTR9", NdbDictionary::Column::Int),
 
121
  NDBT_Attribute("ATTR10", NdbDictionary::Column::Float),
 
122
  NDBT_Attribute("ATTR11", NdbDictionary::Column::Unsigned),
 
123
  NDBT_Attribute("ATTR12", NdbDictionary::Column::Char, 49),
 
124
  NDBT_Attribute("ATTR13", NdbDictionary::Column::Unsigned),
 
125
  NDBT_Attribute("ATTR14", NdbDictionary::Column::Char, 50),
 
126
  NDBT_Attribute("ATTR15", NdbDictionary::Column::Unsigned),
 
127
  NDBT_Attribute("ATTR16", NdbDictionary::Column::Unsigned),
 
128
  NDBT_Attribute("ATTR17", NdbDictionary::Column::Unsigned),
 
129
  NDBT_Attribute("ATTR18", NdbDictionary::Column::Char, 257),
 
130
  NDBT_Attribute("ATTR19", NdbDictionary::Column::Unsigned),
 
131
  NDBT_Attribute("ATTR20", NdbDictionary::Column::Unsigned),
 
132
};
 
133
static
 
134
const
 
135
NDBT_Table T6("T6", sizeof(T6Attribs)/sizeof(NDBT_Attribute), T6Attribs);
 
136
 
 
137
/* T7 */
 
138
static
 
139
const
 
140
NDBT_Attribute T7Attribs[] = {
 
141
  NDBT_Attribute("PK1", NdbDictionary::Column::Unsigned, 1, true), 
 
142
  NDBT_Attribute("PK2", NdbDictionary::Column::Unsigned, 1, true), 
 
143
  NDBT_Attribute("PK3", NdbDictionary::Column::Unsigned, 1, true), 
 
144
  NDBT_Attribute("PK4", NdbDictionary::Column::Varbinary, 123, true), 
 
145
  NDBT_Attribute("ATTR1", NdbDictionary::Column::Unsigned),
 
146
  NDBT_Attribute("ATTR2", NdbDictionary::Column::Unsigned),
 
147
  NDBT_Attribute("ATTR3", NdbDictionary::Column::Unsigned),
 
148
  NDBT_Attribute("ATTR4", NdbDictionary::Column::Unsigned),
 
149
  NDBT_Attribute("ATTR5", NdbDictionary::Column::Unsigned),
 
150
  NDBT_Attribute("ATTR6", NdbDictionary::Column::Unsigned),
 
151
  NDBT_Attribute("ATTR7", NdbDictionary::Column::Unsigned),
 
152
  NDBT_Attribute("ATTR8", NdbDictionary::Column::Unsigned),
 
153
  NDBT_Attribute("ATTR9", NdbDictionary::Column::Unsigned),
 
154
  NDBT_Attribute("ATTR10", NdbDictionary::Column::Unsigned),
 
155
  NDBT_Attribute("ATTR11", NdbDictionary::Column::Unsigned),
 
156
  NDBT_Attribute("ATTR12", NdbDictionary::Column::Char, 259),
 
157
  NDBT_Attribute("ATTR13", NdbDictionary::Column::Unsigned),
 
158
  NDBT_Attribute("ATTR14", NdbDictionary::Column::Unsigned),
 
159
  NDBT_Attribute("ATTR15", NdbDictionary::Column::Unsigned),
 
160
  NDBT_Attribute("ATTR16", NdbDictionary::Column::Unsigned),
 
161
  NDBT_Attribute("ATTR17", NdbDictionary::Column::Unsigned),
 
162
  NDBT_Attribute("ATTR18", NdbDictionary::Column::Unsigned),
 
163
  NDBT_Attribute("ATTR19", NdbDictionary::Column::Unsigned),
 
164
  NDBT_Attribute("ATTR20", NdbDictionary::Column::Unsigned),
 
165
};
 
166
static
 
167
const
 
168
NDBT_Table T7("T7", sizeof(T7Attribs)/sizeof(NDBT_Attribute), T7Attribs);
 
169
 
 
170
/* T8 */
 
171
static
 
172
const
 
173
NDBT_Attribute T8Attribs[] = {
 
174
  NDBT_Attribute("PERSON_ID", NdbDictionary::Column::Unsigned, 1, true), 
 
175
  NDBT_Attribute("NAME", NdbDictionary::Column::Varbinary, 255),
 
176
  NDBT_Attribute("ADRESS", NdbDictionary::Column::Longvarbinary, 513),
 
177
  NDBT_Attribute("POSTADRESS", NdbDictionary::Column::Char, 1173),
 
178
  NDBT_Attribute("VALUE", NdbDictionary::Column::Unsigned),
 
179
  
 
180
};
 
181
static
 
182
const
 
183
NDBT_Table T8("T8", sizeof(T8Attribs)/sizeof(NDBT_Attribute), T8Attribs);
 
184
 
 
185
/* T9 */
 
186
static
 
187
const
 
188
NDBT_Attribute T9Attribs[] = {
 
189
  NDBT_Attribute("KF_SKAPAD", NdbDictionary::Column::Unsigned, 1, true), 
 
190
  NDBT_Attribute("PLATS_ID", NdbDictionary::Column::Char, 2, true),
 
191
  NDBT_Attribute("TNR_SKAPAD", NdbDictionary::Column::Char, 12, true),
 
192
  NDBT_Attribute("DELG_MOT", NdbDictionary::Column::Char, 1, true),
 
193
  NDBT_Attribute("VALUE", NdbDictionary::Column::Unsigned),
 
194
};
 
195
static
 
196
const
 
197
NDBT_Table T9("T9", sizeof(T9Attribs)/sizeof(NDBT_Attribute), T9Attribs);
 
198
 
 
199
/* T10 - Long key table */
 
200
static
 
201
const
 
202
NDBT_Attribute T10Attribs[] = {
 
203
  NDBT_Attribute("KOL1", NdbDictionary::Column::Char, 256, true), 
 
204
  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned),
 
205
  NDBT_Attribute("KOL3", NdbDictionary::Column::Char, 257),
 
206
  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
 
207
  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned),
 
208
};
 
209
static
 
210
const
 
211
NDBT_Table T10("T10", sizeof(T10Attribs)/sizeof(NDBT_Attribute), T10Attribs);
 
212
 
 
213
 
 
214
/* T11 - Primary key is not first attribute */
 
215
static
 
216
const
 
217
NDBT_Attribute T11Attribs[] = {
 
218
  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned),
 
219
  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, true), 
 
220
  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
 
221
  NDBT_Attribute("KOL4", NdbDictionary::Column::Char, 111),
 
222
  NDBT_Attribute("KOL5", NdbDictionary::Column::Char, 113)
 
223
};
 
224
 
 
225
static
 
226
const
 
227
NDBT_Table T11("T11", sizeof(T11Attribs)/sizeof(NDBT_Attribute), T11Attribs);
 
228
 
 
229
/* T12 - 16 primary keys */
 
230
static
 
231
const
 
232
NDBT_Attribute T12Attribs[] = {
 
233
  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true), 
 
234
  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, true), 
 
235
  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned, 1, true), 
 
236
  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned, 1, true), 
 
237
  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned, 1, true), 
 
238
  NDBT_Attribute("KOL6", NdbDictionary::Column::Unsigned, 1, true), 
 
239
  NDBT_Attribute("KOL7", NdbDictionary::Column::Unsigned, 1, true), 
 
240
  NDBT_Attribute("KOL8", NdbDictionary::Column::Unsigned, 1, true), 
 
241
  NDBT_Attribute("KOL9", NdbDictionary::Column::Unsigned, 1, true), 
 
242
  NDBT_Attribute("KOL10", NdbDictionary::Column::Unsigned, 1, true), 
 
243
  NDBT_Attribute("KOL11", NdbDictionary::Column::Unsigned, 1, true), 
 
244
  NDBT_Attribute("KOL12", NdbDictionary::Column::Unsigned, 1, true), 
 
245
  NDBT_Attribute("KOL13", NdbDictionary::Column::Unsigned, 1, true), 
 
246
  NDBT_Attribute("KOL14", NdbDictionary::Column::Unsigned, 1, true), 
 
247
  NDBT_Attribute("KOL15", NdbDictionary::Column::Unsigned, 1, true), 
 
248
  NDBT_Attribute("KOL16", NdbDictionary::Column::Unsigned, 1, true), 
 
249
  NDBT_Attribute("KOL20", NdbDictionary::Column::Unsigned),
 
250
  NDBT_Attribute("KOL30", NdbDictionary::Column::Unsigned),
 
251
  NDBT_Attribute("KOL40", NdbDictionary::Column::Unsigned),
 
252
  NDBT_Attribute("KOL50", NdbDictionary::Column::Unsigned)
 
253
};
 
254
 
 
255
static
 
256
const
 
257
NDBT_Table T12("T12", sizeof(T12Attribs)/sizeof(NDBT_Attribute), T12Attribs);
 
258
 
 
259
/* T13 - Long key table */
 
260
static
 
261
const
 
262
NDBT_Attribute T13Attribs[] = {
 
263
  NDBT_Attribute("KOL1", NdbDictionary::Column::Char, 257, true), 
 
264
  NDBT_Attribute("KOL2", NdbDictionary::Column::Char, 259, true),
 
265
  NDBT_Attribute("KOL3", NdbDictionary::Column::Char, 113, true),
 
266
  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
 
267
  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned, 1, true),
 
268
  NDBT_Attribute("KOL6", NdbDictionary::Column::Unsigned),
 
269
};
 
270
static
 
271
const
 
272
NDBT_Table T13("T13", sizeof(T13Attribs)/sizeof(NDBT_Attribute), T13Attribs);
 
273
 
 
274
/* T14 - 5 primary keys */
 
275
static
 
276
const
 
277
NDBT_Attribute T14Attribs[] = {
 
278
  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true), 
 
279
  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, true), 
 
280
  NDBT_Attribute("KOL3", NdbDictionary::Column::Char, 4, true), 
 
281
  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned, 1, true), 
 
282
  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned, 1, true), 
 
283
  NDBT_Attribute("KOL20", NdbDictionary::Column::Unsigned),
 
284
  NDBT_Attribute("KOL30", NdbDictionary::Column::Int),
 
285
  NDBT_Attribute("KOL40", NdbDictionary::Column::Float),
 
286
  NDBT_Attribute("KOL50", NdbDictionary::Column::Char, 200)
 
287
};
 
288
 
 
289
 
 
290
static
 
291
const
 
292
NDBT_Table T14("T14", sizeof(T14Attribs)/sizeof(NDBT_Attribute), T14Attribs);
 
293
 
 
294
/*
 
295
  C2 DHCP TABLES, MAYBE THESE SHOULD BE MOVED TO THE UTIL_TABLES?
 
296
*/
 
297
static 
 
298
const
 
299
NDBT_Attribute I1_Cols[] = {
 
300
  NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, true),
 
301
  NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16, true),
 
302
  NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16, true),
 
303
  NDBT_Attribute("POP", NdbDictionary::Column::Char, 64, true),
 
304
  NDBT_Attribute("VLAN", NdbDictionary::Column::Char, 16),
 
305
  NDBT_Attribute("COMMENT", NdbDictionary::Column::Char, 128),
 
306
  NDBT_Attribute("SNMPINDEX", NdbDictionary::Column::Int),
 
307
  NDBT_Attribute("PORTSTATE", NdbDictionary::Column::Int),
 
308
  NDBT_Attribute("UPDATES", NdbDictionary::Column::Unsigned)
 
309
};
 
310
 
 
311
static
 
312
const
 
313
char* I1_Indexes[] = {
 
314
  "UNIQUE", "ID", "PORT", "ACCESSNODE", "POP", "PORTSTATE", 0,
 
315
  0
 
316
};
 
317
 
 
318
static
 
319
NDBT_Table I1("I1", sizeof(I1_Cols)/sizeof(NDBT_Attribute), I1_Cols
 
320
              );// ,I1_Indexes);
 
321
 
 
322
static 
 
323
const
 
324
NDBT_Attribute I2_Cols[] = {
 
325
  NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, true),
 
326
  NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16, true),
 
327
  NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16, true),
 
328
  NDBT_Attribute("POP", NdbDictionary::Column::Char, 64, true),
 
329
  NDBT_Attribute("ACCESSTYPE", NdbDictionary::Column::Int, true),
 
330
  NDBT_Attribute("CUSTOMER_ID", NdbDictionary::Column::Int),
 
331
  NDBT_Attribute("PROVIDER", NdbDictionary::Column::Int),
 
332
  NDBT_Attribute("TEXPIRE", NdbDictionary::Column::Int),
 
333
  NDBT_Attribute("NUM_IP", NdbDictionary::Column::Int),
 
334
  NDBT_Attribute("LEASED_NUM_IP", NdbDictionary::Column::Int),
 
335
  NDBT_Attribute("LOCKED_IP", NdbDictionary::Column::Int),
 
336
  NDBT_Attribute("STATIC_DNS", NdbDictionary::Column::Int),
 
337
  NDBT_Attribute("SUSPENDED_SERVICES", NdbDictionary::Column::Int),
 
338
  NDBT_Attribute("UPDATES", NdbDictionary::Column::Unsigned)
 
339
};
 
340
 
 
341
const
 
342
char* I2_Indexes[] = {
 
343
  "ORDERED", "CUSTOMER_ID", 0,
 
344
  "ORDERED", "NUM_IP", 0,
 
345
  0
 
346
};
 
347
 
 
348
static
 
349
NDBT_Table I2("I2", sizeof(I2_Cols)/sizeof(NDBT_Attribute), I2_Cols
 
350
              );//, I2_Indexes);
 
351
 
 
352
static 
 
353
const
 
354
NDBT_Attribute I3_Cols[] = {
 
355
  NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, true),
 
356
  NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16), // SI2
 
357
  NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16), // SI2
 
358
  NDBT_Attribute("POP", NdbDictionary::Column::Char, 64), // SI2
 
359
  NDBT_Attribute("MAC", NdbDictionary::Column::Char, 12, true), 
 
360
  NDBT_Attribute("MAC_EXPIRE", NdbDictionary::Column::Int, 1),
 
361
  NDBT_Attribute("IIP", NdbDictionary::Column::Int), // SI1
 
362
  NDBT_Attribute("P_EXPIRE", NdbDictionary::Column::Int),
 
363
  NDBT_Attribute("HOSTNAME", NdbDictionary::Column::Char, 32),
 
364
  NDBT_Attribute("DETECTED", NdbDictionary::Column::Int),
 
365
  NDBT_Attribute("STATUS", NdbDictionary::Column::Int),
 
366
  NDBT_Attribute("NUM_REQUESTS", NdbDictionary::Column::Int),
 
367
  NDBT_Attribute("ACCESSTYPE", NdbDictionary::Column::Int),
 
368
  NDBT_Attribute("OS_TYPE", NdbDictionary::Column::Int),
 
369
  NDBT_Attribute("GW", NdbDictionary::Column::Int),
 
370
  NDBT_Attribute("UPDATES", NdbDictionary::Column::Unsigned)
 
371
};
 
372
 
 
373
const
 
374
char* I3_Indexes[] = {
 
375
  "UNIQUE", "ID", 0,
 
376
  "ORDERED", "MAC", 0,
 
377
  "ORDERED", "GW", 0,
 
378
  0
 
379
};
 
380
 
 
381
static
 
382
NDBT_Table I3("I3", sizeof(I3_Cols)/sizeof(NDBT_Attribute), I3_Cols
 
383
              ); // ,I3_Indexes);
 
384
 
 
385
/* D1 */
 
386
static
 
387
const
 
388
NDBT_Attribute D1Attribs[] = {
 
389
  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true), 
 
390
  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, false, false, 0, NdbDictionary::Column::StorageTypeDisk),
 
391
  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
 
392
  NDBT_Attribute("KOL4", NdbDictionary::Column::Char, 233, false, true, 0, NdbDictionary::Column::StorageTypeDisk),
 
393
  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned),
 
394
};
 
395
static
 
396
const
 
397
NDBT_Table D1("D1", sizeof(D1Attribs)/sizeof(NDBT_Attribute), D1Attribs);
 
398
 
 
399
static
 
400
const
 
401
NDBT_Attribute D2Attribs[] = {
 
402
  NDBT_Attribute("KOL1", NdbDictionary::Column::Varbinary, 127, true), 
 
403
  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, false, false, 0, NdbDictionary::Column::StorageTypeDisk),
 
404
  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
 
405
  NDBT_Attribute("KOL4", NdbDictionary::Column::Varbinary, 133),
 
406
  NDBT_Attribute("KOL5", NdbDictionary::Column::Char, 199, false, true, 0, NdbDictionary::Column::StorageTypeDisk),
 
407
  NDBT_Attribute("KOL6", NdbDictionary::Column::Bit, 21, false, false, 0, NdbDictionary::Column::StorageTypeDisk),
 
408
};
 
409
static
 
410
const
 
411
NDBT_Table D2("D2", sizeof(D2Attribs)/sizeof(NDBT_Attribute), D2Attribs);
 
412
 
 
413
 
 
414
// Define array with pointer to all tables 
 
415
static
 
416
const
 
417
NDBT_Table *test_tables[]=
 
418
 
419
  &T1,
 
420
  &T2,
 
421
  &T3,
 
422
  &T4,
 
423
  &T5,
 
424
  &T6,
 
425
  &T7,
 
426
  &T8,
 
427
  &T9,
 
428
  &T10,
 
429
  &T11,
 
430
  &T12,
 
431
  &T13,
 
432
  &T14,
 
433
  &I1,
 
434
  &I2,
 
435
  &I3,
 
436
  &D1, &D2
 
437
};
 
438
 
 
439
struct NDBT_IndexList {
 
440
  const char * m_table;
 
441
  const char ** m_indexes;
 
442
};
 
443
 
 
444
static
 
445
const
 
446
NDBT_IndexList indexes[] = {
 
447
  "I1", I1_Indexes, 
 
448
  "I2", I2_Indexes, 
 
449
  "I3", I3_Indexes,
 
450
  0, 0
 
451
};
 
452
 
 
453
static
 
454
const
 
455
int numTestTables = sizeof(test_tables)/sizeof(NDBT_Table*);
 
456
 
 
457
 
 
458
/**
 
459
 * Define tables we should not be able to create
 
460
 */ 
 
461
 
 
462
/* F1 
 
463
 *
 
464
 * Error: PK and column with same name
 
465
 */
 
466
static
 
467
const
 
468
NDBT_Attribute F1Attribs[] = {
 
469
  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true), 
 
470
  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
 
471
  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
 
472
  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned),
 
473
  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned)
 
474
};
 
475
 
 
476
static
 
477
const
 
478
NDBT_Table F1("F1", sizeof(F1Attribs)/sizeof(NDBT_Attribute), F1Attribs);
 
479
 
 
480
/* F2
 
481
 *
 
482
 * Error: Two columns with same name
 
483
 */
 
484
static
 
485
const
 
486
NDBT_Attribute F2Attribs[] = {
 
487
  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true), 
 
488
  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned),
 
489
  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned),
 
490
  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
 
491
  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned)
 
492
};
 
493
 
 
494
static
 
495
const
 
496
NDBT_Table F2("F2", sizeof(F2Attribs)/sizeof(NDBT_Attribute), F2Attribs);
 
497
 
 
498
/* F3
 
499
 *
 
500
 * Error: Too many primary keys defined, 32 is max
 
501
 */
 
502
static
 
503
const
 
504
NDBT_Attribute F3Attribs[] = {
 
505
  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true), 
 
506
  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, true), 
 
507
  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned, 1, true), 
 
508
  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned, 1, true), 
 
509
  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned, 1, true), 
 
510
  NDBT_Attribute("KOL6", NdbDictionary::Column::Unsigned, 1, true), 
 
511
  NDBT_Attribute("KOL7", NdbDictionary::Column::Unsigned, 1, true), 
 
512
  NDBT_Attribute("KOL8", NdbDictionary::Column::Unsigned, 1, true), 
 
513
  NDBT_Attribute("KOL9", NdbDictionary::Column::Unsigned, 1, true), 
 
514
  NDBT_Attribute("KOL10", NdbDictionary::Column::Unsigned, 1, true), 
 
515
  NDBT_Attribute("KOL11", NdbDictionary::Column::Unsigned, 1, true), 
 
516
  NDBT_Attribute("KOL12", NdbDictionary::Column::Unsigned, 1, true), 
 
517
  NDBT_Attribute("KOL13", NdbDictionary::Column::Unsigned, 1, true), 
 
518
  NDBT_Attribute("KOL14", NdbDictionary::Column::Unsigned, 1, true), 
 
519
  NDBT_Attribute("KOL15", NdbDictionary::Column::Unsigned, 1, true), 
 
520
  NDBT_Attribute("KOL16", NdbDictionary::Column::Unsigned, 1, true), 
 
521
  NDBT_Attribute("KOL17", NdbDictionary::Column::Unsigned, 1, true), 
 
522
  NDBT_Attribute("KOL18", NdbDictionary::Column::Unsigned, 1, true), 
 
523
  NDBT_Attribute("KOL19", NdbDictionary::Column::Unsigned, 1, true), 
 
524
  NDBT_Attribute("KOL20", NdbDictionary::Column::Unsigned, 1, true), 
 
525
  NDBT_Attribute("KOL21", NdbDictionary::Column::Unsigned, 1, true), 
 
526
  NDBT_Attribute("KOL22", NdbDictionary::Column::Unsigned, 1, true), 
 
527
  NDBT_Attribute("KOL23", NdbDictionary::Column::Unsigned, 1, true), 
 
528
  NDBT_Attribute("KOL24", NdbDictionary::Column::Unsigned, 1, true), 
 
529
  NDBT_Attribute("KOL25", NdbDictionary::Column::Unsigned, 1, true), 
 
530
  NDBT_Attribute("KOL26", NdbDictionary::Column::Unsigned, 1, true), 
 
531
  NDBT_Attribute("KOL27", NdbDictionary::Column::Unsigned, 1, true), 
 
532
  NDBT_Attribute("KOL28", NdbDictionary::Column::Unsigned, 1, true), 
 
533
  NDBT_Attribute("KOL29", NdbDictionary::Column::Unsigned, 1, true), 
 
534
  NDBT_Attribute("KOL30", NdbDictionary::Column::Unsigned, 1, true), 
 
535
  NDBT_Attribute("KOL31", NdbDictionary::Column::Unsigned, 1, true), 
 
536
  NDBT_Attribute("KOL32", NdbDictionary::Column::Unsigned, 1, true), 
 
537
  NDBT_Attribute("KOL33", NdbDictionary::Column::Unsigned, 1, true), 
 
538
  NDBT_Attribute("KOL40", NdbDictionary::Column::Unsigned),
 
539
  NDBT_Attribute("KOL50", NdbDictionary::Column::Unsigned),
 
540
  NDBT_Attribute("KOL60", NdbDictionary::Column::Unsigned),
 
541
  NDBT_Attribute("KOL70", NdbDictionary::Column::Unsigned)
 
542
};
 
543
 
 
544
static
 
545
const
 
546
NDBT_Table F3("F3", sizeof(F3Attribs)/sizeof(NDBT_Attribute), F3Attribs);
 
547
 
 
548
/* F4
 
549
 *
 
550
 * Error: Too long key
 
551
 */
 
552
static
 
553
const
 
554
NDBT_Attribute F4Attribs[] = {
 
555
  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned),
 
556
  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 9999999, true), 
 
557
  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
 
558
  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
 
559
  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned)
 
560
};
 
561
 
 
562
static
 
563
const
 
564
NDBT_Table F4("F4", sizeof(F4Attribs)/sizeof(NDBT_Attribute), F4Attribs);
 
565
 
 
566
/* F5
 
567
 *
 
568
 * Error: Too long attr name
 
569
 */
 
570
static
 
571
const
 
572
NDBT_Attribute F5Attribs[] = {
 
573
  NDBT_Attribute("KOL1WITHVERRYLONGNAME_ISITTOLONG", NdbDictionary::Column::Unsigned, true),
 
574
  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
 
575
  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
 
576
  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned)
 
577
};
 
578
 
 
579
static
 
580
const
 
581
NDBT_Table F5("F5", sizeof(F5Attribs)/sizeof(NDBT_Attribute), F5Attribs);
 
582
 
 
583
/* F6
 
584
 *
 
585
 * Error: Zero length of pk attribute
 
586
 */
 
587
static
 
588
const
 
589
NDBT_Attribute F6Attribs[] = {
 
590
  NDBT_Attribute("KOL1", NdbDictionary::Column::Char, 0, true, false), 
 
591
  NDBT_Attribute("KOL2", NdbDictionary::Column::Char, 256),
 
592
};
 
593
 
 
594
static
 
595
const
 
596
NDBT_Table F6("F6", sizeof(F6Attribs)/sizeof(NDBT_Attribute), F6Attribs);
 
597
 
 
598
/* F7
 
599
 *
 
600
 * Error: Table without primary key
 
601
 */
 
602
static
 
603
const
 
604
NDBT_Attribute F7Attribs[] = {
 
605
  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
 
606
  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
 
607
  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned)
 
608
};
 
609
 
 
610
NDBT_Table F7("F7", sizeof(F7Attribs)/sizeof(NDBT_Attribute), F7Attribs);
 
611
 
 
612
/* F8
 
613
 *
 
614
 * Error: Table without nullable primary key
 
615
 */
 
616
static
 
617
const
 
618
NDBT_Attribute F8Attribs[] = {
 
619
  NDBT_Attribute("KOL3", NdbDictionary::Column::Int, 1, true, true),
 
620
  NDBT_Attribute("KOL4", NdbDictionary::Column::Int),
 
621
  NDBT_Attribute("KOL5", NdbDictionary::Column::Int)
 
622
};
 
623
 
 
624
NDBT_Table F8("F8", sizeof(F8Attribs)/sizeof(NDBT_Attribute), F8Attribs);
 
625
 
 
626
 
 
627
/* F15 - 2-node crash in v20x */
 
628
static
 
629
const
 
630
NDBT_Attribute F15Attribs[] = {
 
631
  NDBT_Attribute("KOL1", NdbDictionary::Column::Char, 40, true)
 
632
};
 
633
static
 
634
const
 
635
NDBT_Table F15("F15", sizeof(F15Attribs)/sizeof(NDBT_Attribute), F15Attribs);
 
636
 
 
637
// Define array with pointer to tables that we should not  be able to create
 
638
static
 
639
const
 
640
NDBT_Table *fail_tables[]=
 
641
 
642
  &F1,
 
643
  &F2,
 
644
  &F3,
 
645
  &F4,
 
646
  &F5,
 
647
  &F6,
 
648
  &F7,
 
649
  &F8,
 
650
  &F15
 
651
};
 
652
 
 
653
static
 
654
const
 
655
int numFailTables = sizeof(fail_tables)/sizeof(NDBT_Table*);
 
656
 
 
657
 
 
658
/**
 
659
 * Define util tables that we may create
 
660
 */ 
 
661
 
 
662
 
 
663
/* GL 
 
664
 * General ledger table for bank application
 
665
 */
 
666
static 
 
667
const
 
668
NDBT_Attribute GL_Attribs[] = {
 
669
  NDBT_Attribute("TIME", NdbDictionary::Column::Bigunsigned, 1, true), 
 
670
  NDBT_Attribute("ACCOUNT_TYPE", NdbDictionary::Column::Unsigned, 1, true), 
 
671
  NDBT_Attribute("BALANCE", NdbDictionary::Column::Unsigned),
 
672
  NDBT_Attribute("DEPOSIT_COUNT", NdbDictionary::Column::Unsigned),
 
673
  NDBT_Attribute("DEPOSIT_SUM", NdbDictionary::Column::Unsigned),
 
674
  NDBT_Attribute("WITHDRAWAL_COUNT", NdbDictionary::Column::Unsigned),
 
675
  NDBT_Attribute("WITHDRAWAL_SUM", NdbDictionary::Column::Unsigned),
 
676
  NDBT_Attribute("PURGED", NdbDictionary::Column::Unsigned)
 
677
};
 
678
 
 
679
static
 
680
NDBT_Table GL("GL", sizeof(GL_Attribs)/sizeof(NDBT_Attribute), GL_Attribs);
 
681
 
 
682
/* ACCOUNT
 
683
 * Account table for bank application
 
684
 */
 
685
static 
 
686
const
 
687
NDBT_Attribute ACCOUNT_Attribs[] = {
 
688
  NDBT_Attribute("ACCOUNT_ID", NdbDictionary::Column::Unsigned, 1, true), 
 
689
  NDBT_Attribute("OWNER", NdbDictionary::Column::Unsigned),
 
690
  NDBT_Attribute("BALANCE", NdbDictionary::Column::Unsigned),
 
691
  NDBT_Attribute("ACCOUNT_TYPE", NdbDictionary::Column::Unsigned),
 
692
};
 
693
 
 
694
static
 
695
NDBT_Table ACCOUNT("ACCOUNT", sizeof(ACCOUNT_Attribs)/sizeof(NDBT_Attribute), ACCOUNT_Attribs);
 
696
 
 
697
/* TRANSACTION
 
698
 * Transaction table for bank application
 
699
 */
 
700
static 
 
701
const
 
702
NDBT_Attribute TRANSACTION_Attribs[] = {
 
703
  NDBT_Attribute("TRANSACTION_ID", NdbDictionary::Column::Bigunsigned, 1, true),
 
704
  NDBT_Attribute("ACCOUNT", NdbDictionary::Column::Unsigned, 1, true), 
 
705
  NDBT_Attribute("ACCOUNT_TYPE", NdbDictionary::Column::Unsigned), 
 
706
  NDBT_Attribute("OTHER_ACCOUNT", NdbDictionary::Column::Unsigned),
 
707
  NDBT_Attribute("TRANSACTION_TYPE", NdbDictionary::Column::Unsigned),
 
708
  NDBT_Attribute("TIME", NdbDictionary::Column::Bigunsigned),
 
709
  NDBT_Attribute("AMOUNT", NdbDictionary::Column::Unsigned),
 
710
};
 
711
 
 
712
static
 
713
NDBT_Table TRANSACTION("TRANSACTION", sizeof(TRANSACTION_Attribs)/sizeof(NDBT_Attribute), TRANSACTION_Attribs);
 
714
 
 
715
/* SYSTEM_VALUES
 
716
 * System values table for bank application
 
717
 */
 
718
static 
 
719
const
 
720
NDBT_Attribute SYSTEM_VALUES_Attribs[] = {
 
721
  NDBT_Attribute("SYSTEM_VALUES_ID", NdbDictionary::Column::Unsigned, 1, true),
 
722
  NDBT_Attribute("VALUE", NdbDictionary::Column::Bigunsigned)
 
723
};
 
724
 
 
725
static
 
726
NDBT_Table SYSTEM_VALUES("SYSTEM_VALUES", sizeof(SYSTEM_VALUES_Attribs)/sizeof(NDBT_Attribute), SYSTEM_VALUES_Attribs);
 
727
 
 
728
/* ACCOUNT_TYPES
 
729
 * Account types table for bank application
 
730
 */
 
731
static 
 
732
const
 
733
NDBT_Attribute ACCOUNT_TYPES_Attribs[] = {
 
734
  NDBT_Attribute("ACCOUNT_TYPE_ID", NdbDictionary::Column::Unsigned, 1, true),
 
735
  NDBT_Attribute("DESCRIPTION", NdbDictionary::Column::Char, 64, false, false, &my_charset_latin1_bin)
 
736
};
 
737
 
 
738
static
 
739
NDBT_Table ACCOUNT_TYPES("ACCOUNT_TYPE", sizeof(ACCOUNT_TYPES_Attribs)/sizeof(NDBT_Attribute), ACCOUNT_TYPES_Attribs);
 
740
 
 
741
 
 
742
// Define array with pointer to util tables 
 
743
static
 
744
const
 
745
NDBT_Table *util_tables[]=
 
746
 
747
  &GL,
 
748
  &ACCOUNT,
 
749
  &TRANSACTION,
 
750
  &SYSTEM_VALUES,
 
751
  &ACCOUNT_TYPES
 
752
};
 
753
 
 
754
static
 
755
const
 
756
int numUtilTables = sizeof(util_tables)/sizeof(NDBT_Table*);
 
757
 
 
758
 
 
759
const
 
760
NdbDictionary::Table*
 
761
NDBT_Tables::getTable(const char* _nam){
 
762
  // Search tables list to find a table
 
763
  NDBT_Table* tab = NULL;
 
764
  int i;
 
765
  for (i=0; i<numTestTables; i++){
 
766
    if (strcmp(test_tables[i]->getName(), _nam) == 0){
 
767
      return test_tables[i];
 
768
    }
 
769
  }
 
770
  for (i=0; i<numFailTables; i++){
 
771
    if (strcmp(fail_tables[i]->getName(), _nam) == 0){
 
772
      return fail_tables[i];
 
773
    }
 
774
  }
 
775
  for (i=0; i<numUtilTables; i++){
 
776
    if (strcmp(util_tables[i]->getName(), _nam) == 0){
 
777
      return util_tables[i];
 
778
    }
 
779
  }
 
780
  // TPK_no tables
 
781
  // Dynamcially create table vith primary key size
 
782
  // set to no
 
783
  // Useful for testing key sizes 1 - max
 
784
  int pkSizeOfTable;
 
785
  if(sscanf(_nam, "TPK_%d", &pkSizeOfTable) == 1){   
 
786
    return tableWithPkSize(_nam, pkSizeOfTable);
 
787
  }
 
788
  return tab;
 
789
}
 
790
 
 
791
const NdbDictionary::Table*
 
792
NDBT_Tables::tableWithPkSize(const char* _nam, Uint32 pkSize){
 
793
  NdbDictionary::Table* tab = new NdbDictionary::Table(_nam);
 
794
 
 
795
  // Add one PK of the desired length
 
796
  tab->addColumn(NDBT_Attribute("PK1",
 
797
                                NdbDictionary::Column::Char,
 
798
                                pkSize,
 
799
                                true));
 
800
  
 
801
  // Add 4 attributes
 
802
  tab->addColumn(NDBT_Attribute("ATTR1",
 
803
                                NdbDictionary::Column::Char,
 
804
                                21));
 
805
  
 
806
  tab->addColumn(NDBT_Attribute("ATTR2",
 
807
                                NdbDictionary::Column::Char,
 
808
                                124));
 
809
  
 
810
  tab->addColumn(NDBT_Attribute("ATTR3",
 
811
                                NdbDictionary::Column::Unsigned));
 
812
  
 
813
  tab->addColumn(NDBT_Attribute("ATTR4",
 
814
                                NdbDictionary::Column::Unsigned));
 
815
  
 
816
  return tab;
 
817
}
 
818
 
 
819
const NdbDictionary::Table* 
 
820
NDBT_Tables::getTable(int _num){
 
821
  // Get table at pos _num
 
822
  assert(_num < numTestTables);
 
823
  return test_tables[_num];
 
824
}
 
825
 
 
826
int
 
827
NDBT_Tables::getNumTables(){
 
828
  return numTestTables;
 
829
}
 
830
 
 
831
const char**
 
832
NDBT_Tables::getIndexes(const char* table)
 
833
{
 
834
  Uint32 i = 0;
 
835
  for (i = 0; indexes[i].m_table != 0; i++) {
 
836
    if (strcmp(indexes[i].m_table, table) == 0)
 
837
      return indexes[i].m_indexes;
 
838
  }
 
839
  return 0;
 
840
}
 
841
 
 
842
int
 
843
NDBT_Tables::createAllTables(Ndb* pNdb, bool _temp, bool existsOk){
 
844
  
 
845
  for (int i=0; i < NDBT_Tables::getNumTables(); i++){
 
846
    pNdb->getDictionary()->dropTable(NDBT_Tables::getTable(i)->getName());
 
847
    int ret= createTable(pNdb, 
 
848
                         NDBT_Tables::getTable(i)->getName(), _temp, existsOk);
 
849
    if(ret){
 
850
      return ret;
 
851
    }
 
852
  }
 
853
  return NDBT_OK;
 
854
}
 
855
 
 
856
int
 
857
NDBT_Tables::createAllTables(Ndb* pNdb){
 
858
  return createAllTables(pNdb, false);
 
859
}
 
860
 
 
861
int
 
862
NDBT_Tables::create_default_tablespace(Ndb* pNdb)
 
863
{
 
864
  NdbDictionary::Dictionary* pDict = pNdb->getDictionary();
 
865
 
 
866
  int res;
 
867
  NdbDictionary::LogfileGroup lg = pDict->getLogfileGroup("DEFAULT-LG");
 
868
  if (strcmp(lg.getName(), "DEFAULT-LG") != 0)
 
869
  {
 
870
    lg.setName("DEFAULT-LG");
 
871
    lg.setUndoBufferSize(8*1024*1024);
 
872
    res = pDict->createLogfileGroup(lg);
 
873
    if(res != 0){
 
874
      g_err << "Failed to create logfilegroup:"
 
875
            << endl << pDict->getNdbError() << endl;
 
876
      return NDBT_FAILED;
 
877
    }
 
878
  }
 
879
  {
 
880
    NdbDictionary::Undofile uf = pDict->getUndofile(0, "undofile01.dat");
 
881
    if (strcmp(uf.getPath(), "undofile01.dat") != 0)
 
882
    {
 
883
      uf.setPath("undofile01.dat");
 
884
      uf.setSize(32*1024*1024);
 
885
      uf.setLogfileGroup("DEFAULT-LG");
 
886
      
 
887
      res = pDict->createUndofile(uf, true);
 
888
      if(res != 0){
 
889
        g_err << "Failed to create undofile:"
 
890
              << endl << pDict->getNdbError() << endl;
 
891
        return NDBT_FAILED;
 
892
      }
 
893
    }
 
894
  }
 
895
  {
 
896
    NdbDictionary::Undofile uf = pDict->getUndofile(0, "undofile02.dat");
 
897
    if (strcmp(uf.getPath(), "undofile02.dat") != 0)
 
898
    {
 
899
      uf.setPath("undofile02.dat");
 
900
      uf.setSize(32*1024*1024);
 
901
      uf.setLogfileGroup("DEFAULT-LG");
 
902
      
 
903
      res = pDict->createUndofile(uf, true);
 
904
      if(res != 0){
 
905
        g_err << "Failed to create undofile:"
 
906
              << endl << pDict->getNdbError() << endl;
 
907
        return NDBT_FAILED;
 
908
      }
 
909
    }
 
910
  }
 
911
  NdbDictionary::Tablespace ts = pDict->getTablespace("DEFAULT-TS");
 
912
  if (strcmp(ts.getName(), "DEFAULT-TS") != 0)
 
913
  {
 
914
    ts.setName("DEFAULT-TS");
 
915
    ts.setExtentSize(1024*1024);
 
916
    ts.setDefaultLogfileGroup("DEFAULT-LG");
 
917
    
 
918
    res = pDict->createTablespace(ts);
 
919
    if(res != 0){
 
920
      g_err << "Failed to create tablespace:"
 
921
            << endl << pDict->getNdbError() << endl;
 
922
      return NDBT_FAILED;
 
923
    }
 
924
  }
 
925
  
 
926
  {
 
927
    NdbDictionary::Datafile df = pDict->getDatafile(0, "datafile01.dat");
 
928
    if (strcmp(df.getPath(), "datafile01.dat") != 0)
 
929
    {
 
930
      df.setPath("datafile01.dat");
 
931
      df.setSize(64*1024*1024);
 
932
      df.setTablespace("DEFAULT-TS");
 
933
      
 
934
      res = pDict->createDatafile(df, true);
 
935
      if(res != 0){
 
936
        g_err << "Failed to create datafile:"
 
937
              << endl << pDict->getNdbError() << endl;
 
938
        return NDBT_FAILED;
 
939
      }
 
940
    }
 
941
  }
 
942
 
 
943
  {
 
944
    NdbDictionary::Datafile df = pDict->getDatafile(0, "datafile02.dat");
 
945
    if (strcmp(df.getPath(), "datafile02.dat") != 0)
 
946
    {
 
947
      df.setPath("datafile02.dat");
 
948
      df.setSize(64*1024*1024);
 
949
      df.setTablespace("DEFAULT-TS");
 
950
      
 
951
      res = pDict->createDatafile(df, true);
 
952
      if(res != 0){
 
953
        g_err << "Failed to create datafile:"
 
954
              << endl << pDict->getNdbError() << endl;
 
955
        return NDBT_FAILED;
 
956
      }
 
957
    }
 
958
  }
 
959
  
 
960
  return NDBT_OK;
 
961
}
 
962
 
 
963
int
 
964
NDBT_Tables::createTable(Ndb* pNdb, const char* _name, bool _temp, 
 
965
                         bool existsOk, NDBT_CreateTableHook f, void* arg)
 
966
{
 
967
  const NdbDictionary::Table* tab = NDBT_Tables::getTable(_name);
 
968
  if (tab == NULL){
 
969
    ndbout << "Could not create table " << _name 
 
970
           << ", it doesn't exist in list of tables "\
 
971
      "that NDBT_Tables can create!" << endl;
 
972
    return NDBT_WRONGARGS;
 
973
  }
 
974
 
 
975
  Uint32 sum = 0;
 
976
  for (Uint32 i = 0; i<strlen(_name); i++)
 
977
    sum += 33 * sum + (Uint32)_name[i];
 
978
  
 
979
  bool forceVarPart = (sum & 1);
 
980
  
 
981
  int r = 0;
 
982
  do {
 
983
    NdbDictionary::Table tmpTab(* tab);
 
984
    tmpTab.setStoredTable(_temp ? 0 : 1);
 
985
    tmpTab.setForceVarPart(forceVarPart);
 
986
 
 
987
    {
 
988
      NdbError error;
 
989
      int ret = tmpTab.validate(error);
 
990
      assert(ret == 0);
 
991
    }
 
992
    if(f != 0 && f(pNdb, tmpTab, 0, arg))
 
993
    {
 
994
      ndbout << "Failed to create table" << endl;
 
995
      return NDBT_FAILED;
 
996
    }   
 
997
loop:   
 
998
    r = pNdb->getDictionary()->createTable(tmpTab);
 
999
    if(r == -1){
 
1000
      if(pNdb->getDictionary()->getNdbError().code == 755)
 
1001
      {
 
1002
        if (create_default_tablespace(pNdb) == 0)
 
1003
        {
 
1004
          goto loop;
 
1005
        }
 
1006
      }
 
1007
      if(!existsOk){
 
1008
        ndbout << "Error0: " << pNdb->getDictionary()->getNdbError() << endl;
 
1009
        
 
1010
        break;
 
1011
      }
 
1012
      if(pNdb->getDictionary()->getNdbError().code != 721){
 
1013
        ndbout << "Error: " << pNdb->getDictionary()->getNdbError() << endl;
 
1014
        break;
 
1015
      }
 
1016
      
 
1017
      r = 0;
 
1018
    }
 
1019
    
 
1020
    Uint32 i = 0;
 
1021
    for(i = 0; indexes[i].m_table != 0; i++){
 
1022
      if(strcmp(indexes[i].m_table, _name) != 0)
 
1023
        continue;
 
1024
      Uint32 j = 0;
 
1025
      while(indexes[i].m_indexes[j] != 0){
 
1026
        NdbDictionary::Index tmpIndx;
 
1027
        BaseString name;
 
1028
        name.assfmt("%s$NDBT_IDX%d", _name, j);
 
1029
        tmpIndx.setName(name.c_str());
 
1030
        tmpIndx.setTable(_name);
 
1031
        bool logging = !_temp;
 
1032
        if(strcmp(indexes[i].m_indexes[j], "ORDERED") == 0){
 
1033
          logging = false;
 
1034
          tmpIndx.setType(NdbDictionary::Index::OrderedIndex);
 
1035
        } else if(strcmp(indexes[i].m_indexes[j], "UNIQUE") == 0){
 
1036
          tmpIndx.setType(NdbDictionary::Index::UniqueHashIndex);
 
1037
        } else {
 
1038
          ndbout << "Unknown index type";
 
1039
          abort();
 
1040
        }
 
1041
        tmpIndx.setLogging(logging);
 
1042
        
 
1043
        j++;
 
1044
        while(indexes[i].m_indexes[j] != 0){
 
1045
          tmpIndx.addIndexColumn(indexes[i].m_indexes[j]);
 
1046
          j++;
 
1047
        }
 
1048
        j++;
 
1049
        if (tmpTab.getTemporary())
 
1050
        {
 
1051
          tmpIndx.setTemporary(true);
 
1052
          tmpIndx.setLogging(false);
 
1053
        }
 
1054
        if(pNdb->getDictionary()->createIndex(tmpIndx) != 0){
 
1055
          ndbout << pNdb->getDictionary()->getNdbError() << endl;
 
1056
          return NDBT_FAILED;
 
1057
        }
 
1058
      }
 
1059
    }
 
1060
    if(f != 0 && f(pNdb, tmpTab, 1, arg))
 
1061
    {
 
1062
      ndbout << "Failed to create table" << endl;
 
1063
      return NDBT_FAILED;
 
1064
    }      
 
1065
  } while(false);
 
1066
  
 
1067
  return r;
 
1068
}
 
1069
 
 
1070
int
 
1071
NDBT_Tables::dropAllTables(Ndb* pNdb){
 
1072
 
 
1073
  for (int i=0; i < NDBT_Tables::getNumTables(); i++){
 
1074
 
 
1075
    const NdbDictionary::Table* tab = NDBT_Tables::getTable(i);
 
1076
    if (tab == NULL){
 
1077
      return NDBT_ProgramExit(NDBT_FAILED);
 
1078
    }
 
1079
    
 
1080
    if(pNdb->getDictionary()->dropTable(tab->getName()) == -1){
 
1081
      return NDBT_FAILED;
 
1082
    }
 
1083
  }
 
1084
  return NDBT_OK;
 
1085
}
 
1086
 
 
1087
 
 
1088
int
 
1089
NDBT_Tables::print(const char * _name){
 
1090
  
 
1091
  const NDBT_Table * tab = (const NDBT_Table*)NDBT_Tables::getTable(_name);
 
1092
  if (tab == NULL){
 
1093
    ndbout << "Could not print table " << _name 
 
1094
           << ", it doesn't exist in list of tables "
 
1095
           << "that NDBT_Tables can create!" << endl;
 
1096
    return NDBT_WRONGARGS;
 
1097
  }
 
1098
  ndbout << (* tab) << endl;
 
1099
  return NDBT_OK;
 
1100
}
 
1101
 
 
1102
int
 
1103
NDBT_Tables::printAll(){
 
1104
 
 
1105
  for (int i=0; i < getNumTables(); i++){
 
1106
    
 
1107
    const NdbDictionary::Table* tab = getTable(i);
 
1108
    if (tab == NULL){
 
1109
      abort();
 
1110
    }
 
1111
    ndbout << (* (NDBT_Table*)tab) << endl;
 
1112
  }
 
1113
  
 
1114
  return NDBT_OK;
 
1115
}