transactd 1.1.2 → 1.2.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.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CMakeLists.txt +37 -4
  3. data/bin/common/tdclc_32_1_2.dll +0 -0
  4. data/bin/common/tdclc_64_1_2.dll +0 -0
  5. data/build/common/transactd_cl_common.cmake +0 -1
  6. data/build/common/transactd_common.cmake +26 -6
  7. data/build/swig/php/generate.cmake.in +58 -0
  8. data/build/swig/php/generate.cmd.in +41 -0
  9. data/build/swig/php/php.swg +155 -0
  10. data/build/swig/ruby/ruby.swg +38 -0
  11. data/build/swig/tdcl.i +133 -3
  12. data/build/tdclc/CMakeLists.txt +4 -1
  13. data/build/tdclc/tdclc_32.cbproj +1 -1
  14. data/build/tdclc/tdclc_64.cbproj +1 -1
  15. data/build/tdclcpp/CMakeLists.txt +1 -1
  16. data/build/tdclcpp/tdclcpp_bcb_32.cbproj +1 -4
  17. data/build/tdclcpp/tdclcpp_bcb_64.cbproj +0 -3
  18. data/build/tdclrb/CMakeLists.txt +1 -1
  19. data/build/tdclrb/GEM_VERSION +2 -2
  20. data/source/bzs/db/engine/mysql/IReadRecords.h +1 -1
  21. data/source/bzs/db/engine/mysql/bookmark.h +3 -3
  22. data/source/bzs/db/engine/mysql/database.cpp +95 -19
  23. data/source/bzs/db/engine/mysql/database.h +6 -6
  24. data/source/bzs/db/engine/mysql/mysqlInternal.h +43 -1
  25. data/source/bzs/db/engine/mysql/mysqlThd.cpp +10 -8
  26. data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +1 -1
  27. data/source/bzs/db/protocol/tdap/btrDate.h +2 -2
  28. data/source/bzs/db/protocol/tdap/client/dbDef.cpp +15 -8
  29. data/source/bzs/db/protocol/tdap/client/dbDef.h +2 -2
  30. data/source/bzs/db/protocol/tdap/client/dllmain.cpp +4 -0
  31. data/source/bzs/db/protocol/tdap/client/fieldDDF.cpp +0 -5
  32. data/source/bzs/db/protocol/tdap/client/fileDDF.cpp +0 -4
  33. data/source/bzs/db/protocol/tdap/client/filter.cpp +0 -484
  34. data/source/bzs/db/protocol/tdap/client/filter.h +696 -84
  35. data/source/bzs/db/protocol/tdap/client/nsTable.cpp +13 -3
  36. data/source/bzs/db/protocol/tdap/client/nsTable.h +12 -6
  37. data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +2 -1
  38. data/source/bzs/db/protocol/tdap/client/stringConverter.h +1 -0
  39. data/source/bzs/db/protocol/tdap/client/table.cpp +519 -75
  40. data/source/bzs/db/protocol/tdap/client/table.h +49 -7
  41. data/source/bzs/db/protocol/tdap/client/trdboostapi.h +145 -124
  42. data/source/bzs/db/protocol/tdap/client/trdboostapiInternal.h +39 -0
  43. data/source/bzs/db/protocol/tdap/client/trdormapi.h +872 -0
  44. data/source/bzs/db/protocol/tdap/myDateTime.cpp +8 -8
  45. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +7 -9
  46. data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +406 -195
  47. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +64 -13
  48. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +2 -1
  49. data/source/bzs/db/protocol/tdap/tdapSchema.cpp +35 -3
  50. data/source/bzs/db/protocol/tdap/tdapSchema.h +11 -3
  51. data/source/bzs/db/protocol/tdap/tdapcapi.h +63 -53
  52. data/source/bzs/env/crosscompile.h +8 -3
  53. data/source/bzs/example/connection_pool_c.cpp +1 -7
  54. data/source/bzs/example/useORM.cpp +585 -0
  55. data/source/bzs/rtl/exception.h +6 -0
  56. data/source/bzs/test/tdclatl/bench_tdclatl.js +12 -7
  57. data/source/bzs/test/tdclphp/transactd_Test.php +1845 -0
  58. data/source/bzs/test/tdclphp/transactd_blob_Test.php +325 -0
  59. data/source/bzs/test/tdclphp/transactd_datetime_Test.php +183 -0
  60. data/source/bzs/test/tdclphp/transactd_kanjischema_Test.php +212 -0
  61. data/source/bzs/test/tdclrb/transactd_blob_spec.rb +332 -0
  62. data/source/bzs/test/tdclrb/transactd_spec.rb +256 -1
  63. data/source/bzs/test/trdclengn/test_blob.cpp +327 -0
  64. data/source/bzs/test/trdclengn/test_trdclengn.cpp +485 -5
  65. data/source/global/tdclatl/QueryBase.cpp +231 -0
  66. data/source/global/tdclatl/QueryBase.h +96 -0
  67. data/source/global/tdclatl/Table.cpp +24 -0
  68. data/source/global/tdclatl/Table.h +2 -1
  69. data/source/global/tdclatl/resource.h +0 -0
  70. data/source/global/tdclatl/tdclatl.idl +88 -2
  71. metadata +16 -3
  72. data/bin/common/tdclc_32_1_1.dll +0 -0
  73. data/bin/common/tdclc_64_1_1.dll +0 -0
@@ -0,0 +1,1845 @@
1
+ <?php
2
+ /* ================================================================
3
+ Copyright (C) 2013 BizStation Corp All rights reserved.
4
+
5
+ This program is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU General Public License
7
+ as published by the Free Software Foundation; either version 2
8
+ of the License, or (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program; if not, write to the Free Software
17
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18
+ 02111-1307, USA.
19
+ ================================================================ */
20
+ mb_internal_encoding('UTF-8');
21
+
22
+ require_once("transactd.php");
23
+
24
+ define("HOSTNAME", "localhost/");
25
+ define("DBNAME", "test");
26
+ define("DBNAME_VAR", "testvar");
27
+ define("DBNAME_SF", "testString");
28
+ define("TABLENAME", "user");
29
+ define("PROTOCOL", "tdap://");
30
+ define("BDFNAME", "?dbfile=test.bdf");
31
+ define("URL", PROTOCOL . HOSTNAME . DBNAME . BDFNAME);
32
+ define("URL_VAR", PROTOCOL . HOSTNAME . DBNAME_VAR . BDFNAME);
33
+ define("URL_SF", PROTOCOL . HOSTNAME . DBNAME_SF . BDFNAME);
34
+ define("FDI_ID", 0);
35
+ define("FDI_NAME", 1);
36
+ define("FDI_GROUP", 2);
37
+ define("FDI_NAMEW", 2);
38
+
39
+ define("BULKBUFSIZE", 65535 - 1000);
40
+ define("TEST_COUNT", 20000);
41
+ define("FIVE_PERCENT_OF_TEST_COUNT", TEST_COUNT / 20);
42
+
43
+ define("TYPE_SCHEMA_BDF", 0);
44
+
45
+ define("ISOLATION_READ_COMMITTED", true);
46
+ define("ISOLATION_REPEATABLE_READ", false);
47
+
48
+ class transactdTest extends PHPUnit_Framework_TestCase
49
+ {
50
+ private function getDbObj()
51
+ {
52
+ return database::createObject();
53
+ }
54
+ private function deleteDbObj($db)
55
+ {
56
+ $db->close();
57
+ $db = NULL;
58
+ }
59
+ private function dropDatabase($db)
60
+ {
61
+ $db->open(URL);
62
+ $this->assertEquals($db->stat(), 0);
63
+ $db->drop();
64
+ $this->assertEquals($db->stat(), 0);
65
+ }
66
+ private function createDatabase($db)
67
+ {
68
+ $db->create(URL);
69
+ if ($db->stat() == transactd::STATUS_TABLE_EXISTS_ERROR)
70
+ {
71
+ $this->dropDatabase($db);
72
+ $db->create(URL);
73
+ }
74
+ $this->assertEquals($db->stat(), 0);
75
+ }
76
+ private function openDatabase($db)
77
+ {
78
+ $db->open(URL, TYPE_SCHEMA_BDF, transactd::TD_OPEN_NORMAL);
79
+ $this->assertEquals($db->stat(), 0);
80
+ }
81
+ private function createTable($db)
82
+ {
83
+ $this->openDatabase($db);
84
+ $dbdef = $db->dbDef();
85
+ $this->assertNotEquals($dbdef, NULL);
86
+ $td = new tabledef();
87
+ // Set table schema codepage to UTF-8
88
+ // - codepage for field NAME and tableNAME
89
+ $td->schemaCodePage = transactd::CP_UTF8;
90
+ $td->setTableName(TABLENAME);
91
+ $td->setFileName(TABLENAME . '.dat');
92
+ // Set table default charaset index
93
+ // - default charset for field VALUE
94
+ $td->charsetIndex = transactd::charsetIndex(transactd::CP_UTF8);
95
+ //
96
+ $tableid = 1;
97
+ $td->id = $tableid;
98
+ $td->pageSize = 2048;
99
+ $dbdef->insertTable($td);
100
+ $this->assertEquals($dbdef->stat(), 0);
101
+
102
+ $fd = $dbdef->insertField($tableid, 0);
103
+ $fd->setName("id");
104
+ $fd->type = transactd::ft_integer;
105
+ $fd->len = 4;
106
+ $dbdef->updateTableDef($tableid);
107
+ $this->assertEquals($dbdef->stat(), 0);
108
+
109
+ $fd = $dbdef->insertField($tableid, 1);
110
+ $fd->setName("name");
111
+ $fd->type = transactd::ft_zstring;
112
+ $fd->len = 33;
113
+ $dbdef->updateTableDef($tableid);
114
+ $this->assertEquals($dbdef->stat(), 0);
115
+ // Set field charset index
116
+ // - charset for each field VALUE
117
+ // $fd->setCharsetIndex(transactd::charsetIndex(transactd::CP_UTF8))
118
+
119
+ $fd = $dbdef->insertField($tableid, 2);
120
+ $fd->setName("select");
121
+ $fd->type = transactd::ft_integer;
122
+ $fd->len = 4;
123
+ $dbdef->updateTableDef($tableid);
124
+ $this->assertEquals($dbdef->stat(), 0);
125
+
126
+ $fd = $dbdef->insertField($tableid, 3);
127
+ $fd->setName("in");
128
+ $fd->type = transactd::ft_integer;
129
+ $fd->len = 4;
130
+ $dbdef->updateTableDef($tableid);
131
+ $this->assertEquals($dbdef->stat(), 0);
132
+
133
+ $kd = $dbdef->insertKey($tableid, 0);
134
+ $kd->segment(0)->fieldNum = 0;
135
+ $kd->segment(0)->flags->bit8 = 1;
136
+ $kd->segment(0)->flags->bit1 = 1;
137
+ $kd->segmentCount = 1;
138
+ $dbdef->updateTableDef($tableid);
139
+ $this->assertEquals($dbdef->stat(), 0);
140
+ }
141
+ private function openTable($db)
142
+ {
143
+ $this->openDatabase($db);
144
+ $tb = $db->openTable(TABLENAME);
145
+ $this->assertEquals($db->stat(), 0);
146
+ return $tb;
147
+ }
148
+
149
+ public function testCreateDatabase()
150
+ {
151
+ $db = $this->getDbObj();
152
+ $this->createDatabase($db);
153
+ $this->deleteDbObj($db);
154
+ }
155
+ public function testCreateTable()
156
+ {
157
+ $db = $this->getDbObj();
158
+ $this->createTable($db);
159
+ $this->deleteDbObj($db);
160
+ }
161
+ public function testOpenTable()
162
+ {
163
+ $db = $this->getDbObj();
164
+ $tb = $this->openTable($db);
165
+ $tb->close();
166
+ $this->deleteDbObj($db);
167
+ }
168
+ public function testVersion()
169
+ {
170
+ $db = $this->getDbObj();
171
+ $db->connect(PROTOCOL . HOSTNAME);
172
+ $this->assertEquals($db->stat(), 0);
173
+ $vv = new btrVersions();
174
+ $db->getBtrVersion($vv);
175
+ $this->assertEquals($db->stat(), 0);
176
+ $client_ver = $vv->version(0);
177
+ $server_ver = $vv->version(1);
178
+ $engine_ver = $vv->version(2);
179
+ $this->assertEquals($client_ver->majorVersion, transactd::CPP_INTERFACE_VER_MAJOR);
180
+ $this->assertEquals($client_ver->minorVersion, transactd::CPP_INTERFACE_VER_MINOR);
181
+ $this->assertEquals(chr($client_ver->type), 'N');
182
+ $this->assertTrue($server_ver->majorVersion >= 5);
183
+ $this->assertTrue($server_ver->majorVersion != 5 || $server_ver->minorVersion >= 5);
184
+ $this->assertEquals(chr($server_ver->type), 'M');
185
+ $this->assertEquals($engine_ver->majorVersion, transactd::TRANSACTD_VER_MAJOR);
186
+ $this->assertEquals($engine_ver->minorVersion, transactd::TRANSACTD_VER_MINOR);
187
+ $this->assertEquals(chr($engine_ver->type), 'T');
188
+ }
189
+ public function testInsert()
190
+ {
191
+ $db = $this->getDbObj();
192
+ $tb = $this->openTable($db);
193
+ $this->assertNotEquals($tb, NULL);
194
+ $this->assertEquals($tb->recordCount(), 0);
195
+ $tb->clearBuffer();
196
+ $tb->setFV(FDI_ID, 1);
197
+ $tb->setFV(FDI_NAME, 'kosaka');
198
+ $tb->insert();
199
+ $this->assertEquals($tb->stat(), 0);
200
+ $db->beginTrn();
201
+ $n = 1;
202
+ $tb->seekLast();
203
+ if ($tb->stat() == 0)
204
+ {
205
+ $n = $tb->getFVint(FDI_ID) + 1;
206
+ }
207
+ $tb->beginBulkInsert(BULKBUFSIZE);
208
+ for ($i = $n; $i <= (TEST_COUNT + $n); $i++)
209
+ {
210
+ $tb->clearBuffer();
211
+ $tb->setFV(FDI_ID, $i);
212
+ $tb->setFV(FDI_NAME, "" . $i);
213
+ $tb->insert();
214
+ }
215
+ $tb->commitBulkInsert();
216
+ $this->assertEquals($tb->stat(), 0);
217
+ $db->endTrn();
218
+ $tb->close();
219
+ $this->deleteDbObj($db);
220
+ }
221
+ public function testFind()
222
+ {
223
+ $db = $this->getDbObj();
224
+ $tb = $this->openTable($db);
225
+ $this->assertNotEquals($tb, NULL);
226
+ $tb->setKeyNum(0);
227
+ $tb->clearBuffer();
228
+ $tb->setFilter('id >= 10 and id < ' . TEST_COUNT, 1, 0);
229
+ $v = 10;
230
+ $tb->setFV(FDI_ID, $v);
231
+ $tb->find(table::findForword);
232
+ $i = $v;
233
+ while ($i < TEST_COUNT)
234
+ {
235
+ $this->assertEquals($tb->stat(), 0);
236
+ $this->assertEquals($tb->getFVint(FDI_ID), $i);
237
+ $tb->findNext(true); // 11 - 19
238
+ $i = $i + 1;
239
+ }
240
+ // backforword
241
+ $tb->clearBuffer();
242
+ $v = TEST_COUNT - 1;
243
+ $tb->setFV(FDI_ID, $v);
244
+ $tb->find(table::findBackForword);
245
+ $i = $v;
246
+ while ($i >= 10)
247
+ {
248
+ $this->assertEquals($tb->stat(), 0);
249
+ $this->assertEquals($tb->getFVint(FDI_ID), $i);
250
+ $tb->findPrev(true); // 11 - 19
251
+ $i = $i - 1;
252
+ }
253
+ // out of filter range (EOF)
254
+ $tb->clearBuffer();
255
+ $v = TEST_COUNT;
256
+ $tb->setFV(FDI_ID, $v);
257
+ $tb->find(table::findForword);
258
+ $this->assertEquals($tb->stat(), transactd::STATUS_EOF);
259
+ $tb->close();
260
+ $this->deleteDbObj($db);
261
+ }
262
+ public function testFindNext()
263
+ {
264
+ $db = $this->getDbObj();
265
+ $tb = $this->openTable($db);
266
+ $this->assertNotEquals($tb, NULL);
267
+ $tb->setKeyNum(0);
268
+ $tb->clearBuffer();
269
+ $tb->setFilter('id >= 10 and id < ' . TEST_COUNT, 1, 0);
270
+ $v = 10;
271
+ $tb->setFV(FDI_ID, $v);
272
+ $tb->seekGreater(true);
273
+ $this->assertEquals($tb->getFVint(FDI_ID), $v);
274
+ for ($i = $v + 1; $i <= (TEST_COUNT - 1); $i++)
275
+ {
276
+ $tb->findNext(true); // 11 - 19
277
+ $this->assertEquals($tb->stat(), 0);
278
+ $this->assertEquals($tb->getFVint(FDI_ID), $i);
279
+ }
280
+ $tb->close();
281
+ $this->deleteDbObj($db);
282
+ }
283
+ public function testFindIn()
284
+ {
285
+ $db = $this->getDbObj();
286
+ $tb = $this->openTable($db);
287
+ $this->assertNotEquals($tb, NULL);
288
+ $tb->setKeyNum(0);
289
+ $tb->clearBuffer();
290
+ $q = new queryBase();
291
+ $q->addInValue('10', true);
292
+ $q->addInValue('300000');
293
+ $q->addInValue('50');
294
+ $q->addInValue('-1');
295
+ $q->addInValue('80');
296
+ $q->addInValue('5000');
297
+
298
+ $tb->setQuery($q);
299
+ $this->assertEquals($tb->stat(), 0);
300
+ $tb->find();
301
+ $this->assertEquals($tb->stat(), 0);
302
+ $this->assertEquals($tb->getFVint(FDI_ID), 10);
303
+ $tb->findNext();
304
+ $this->assertEquals($tb->stat(), transactd::STATUS_NOT_FOUND_TI);
305
+
306
+ $msg = $tb->keyValueDescription();
307
+ $this->assertEquals($msg, "table:user\nstat:4\nid = 300000\n");
308
+
309
+ $tb->findNext();
310
+ $this->assertEquals($tb->getFVint(FDI_ID), 50);
311
+ $tb->findNext();
312
+ $this->assertEquals($tb->stat(), transactd::STATUS_NOT_FOUND_TI);
313
+
314
+ $msg = $tb->keyValueDescription();
315
+ $this->assertEquals($msg, "table:user\nstat:4\nid = -1\n");
316
+
317
+ $tb->findNext();
318
+ $this->assertEquals($tb->getFVint(FDI_ID), 80);
319
+ $tb->findNext();
320
+ $this->assertEquals($tb->getFVint(FDI_ID), 5000);
321
+ $tb->findNext();
322
+ $this->assertEquals($tb->stat(), transactd::STATUS_EOF);
323
+
324
+ // Many params
325
+ $q->addInValue('1', true);
326
+ for($i = 2; $i <= 10000; $i++)
327
+ {
328
+ $q->addInValue(strval($i));
329
+ }
330
+ $tb->setQuery($q);
331
+ $this->assertEquals($tb->stat(), 0);
332
+
333
+ $tb->find();
334
+ $i = 0;
335
+ while($tb->stat() == 0)
336
+ {
337
+ $i++;
338
+ $this->assertEquals($tb->getFVint(FDI_ID), $i);
339
+ $tb->findNext(true);
340
+ }
341
+ $this->assertEquals($tb->stat(), transactd::STATUS_EOF);
342
+ $this->assertEquals($i, 10000);
343
+
344
+ //LogicalCountLimit
345
+ $q->select('id');
346
+ $tb->setQuery($q);
347
+
348
+ $tb->find();
349
+ $i = 0;
350
+ while ($tb->stat() == 0)
351
+ {
352
+ $i++;
353
+ $this->assertEquals($tb->getFVint(FDI_ID), $i);
354
+ $tb->findNext(true);
355
+ }
356
+ $this->assertEquals($tb->stat(), transactd::STATUS_EOF);
357
+ $this->assertEquals($i, 10000);
358
+
359
+ $tb->close();
360
+ $this->deleteDbObj($db);
361
+ }
362
+ public function testGetPercentage()
363
+ {
364
+ $db = $this->getDbObj();
365
+ $tb = $this->openTable($db);
366
+ $this->assertNotEquals($tb, NULL);
367
+ $tb->clearBuffer();
368
+ $vv = TEST_COUNT / 2 + 1;
369
+ $tb->setFV(FDI_ID, $vv);
370
+ $tb->seek();
371
+ $this->assertEquals($tb->stat(), 0);
372
+ $per = $tb->getPercentage();
373
+ $this->assertTrue(abs(5000 - $per) < 500); // 500 = 5%
374
+ $tb->close();
375
+ $this->deleteDbObj($db);
376
+ }
377
+ public function testMovePercentage()
378
+ {
379
+ $db = $this->getDbObj();
380
+ $tb = $this->openTable($db);
381
+ $this->assertNotEquals($tb, NULL);
382
+ $tb->clearBuffer();
383
+ $tb->seekByPercentage(5000); // 50%
384
+ $this->assertEquals($tb->stat(), 0);
385
+ $v = $tb->getFVint(FDI_ID);
386
+ $this->assertEquals($tb->stat(), 0);
387
+ $this->assertTrue(abs(TEST_COUNT / 2 + 1 - $v) < FIVE_PERCENT_OF_TEST_COUNT);
388
+ $tb->close();
389
+ $this->deleteDbObj($db);
390
+ }
391
+ public function testGetEqual()
392
+ {
393
+ $db = $this->getDbObj();
394
+ $tb = $this->openTable($db);
395
+ $this->assertNotEquals($tb, NULL);
396
+ $db->beginSnapshot();
397
+ for ($i = 2; $i <= (TEST_COUNT + 1); $i++)
398
+ {
399
+ $tb->clearBuffer();
400
+ $tb->setFV(FDI_ID, $i);
401
+ $tb->seek();
402
+ $this->assertEquals($tb->getFVint(FDI_ID), $i);
403
+ }
404
+ $db->endSnapshot();
405
+ $tb->close();
406
+ $this->deleteDbObj($db);
407
+ }
408
+ public function testGetNext()
409
+ {
410
+ $db = $this->getDbObj();
411
+ $tb = $this->openTable($db);
412
+ $this->assertNotEquals($tb, NULL);
413
+ $db->beginSnapshot();
414
+ $vv = 2;
415
+ $tb->clearBuffer();
416
+ $tb->setFV(FDI_ID, $vv);
417
+ $tb->seek();
418
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv);
419
+ for ($i = 3; $i <= (TEST_COUNT + 1); $i++)
420
+ {
421
+ $tb->seekNext();
422
+ $this->assertEquals($tb->getFVint(FDI_ID), $i);
423
+ }
424
+ $db->endSnapshot();
425
+ $tb->close();
426
+ $this->deleteDbObj($db);
427
+ }
428
+ public function testGetPrevious()
429
+ {
430
+ $db = $this->getDbObj();
431
+ $tb = $this->openTable($db);
432
+ $this->assertNotEquals($tb, NULL);
433
+ $db->beginSnapshot();
434
+ $vv = TEST_COUNT + 1;
435
+ $tb->clearBuffer();
436
+ $tb->setFV(FDI_ID, $vv);
437
+ $tb->seek();
438
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv);
439
+ for ($i = TEST_COUNT; $i >= 2; $i--)
440
+ {
441
+ $tb->seekPrev();
442
+ $this->assertEquals($tb->getFVint(FDI_ID), $i);
443
+ }
444
+ $tb->seekPrev();
445
+ $this->assertEquals($tb->getFVstr(FDI_NAME), 'kosaka');
446
+ $db->endSnapshot();
447
+ $tb->close();
448
+ $this->deleteDbObj($db);
449
+ }
450
+ public function testGetGreater()
451
+ {
452
+ $db = $this->getDbObj();
453
+ $tb = $this->openTable($db);
454
+ $this->assertNotEquals($tb, NULL);
455
+ $vv = TEST_COUNT * 3 / 4;
456
+ $tb->clearBuffer();
457
+ $tb->setFV(FDI_ID, $vv);
458
+ $tb->seekGreater(true);
459
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv);
460
+ $tb->seekNext();
461
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv + 1);
462
+ $vv = $vv - FIVE_PERCENT_OF_TEST_COUNT;
463
+ $tb->clearBuffer();
464
+ $tb->setFV(FDI_ID, $vv);
465
+ $tb->seekGreater(false);
466
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv + 1);
467
+ $tb->seekPrev();
468
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv);
469
+ $tb->close();
470
+ $this->deleteDbObj($db);
471
+ }
472
+ public function testGetLessThan()
473
+ {
474
+ $db = $this->getDbObj();
475
+ $tb = $this->openTable($db);
476
+ $this->assertNotEquals($tb, NULL);
477
+ $vv = TEST_COUNT * 3 / 4;
478
+ $tb->clearBuffer();
479
+ $tb->setFV(FDI_ID, $vv);
480
+ $tb->seekLessThan(true);
481
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv);
482
+ $tb->seekNext();
483
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv + 1);
484
+ $vv = $vv - FIVE_PERCENT_OF_TEST_COUNT;
485
+ $tb->clearBuffer();
486
+ $tb->setFV(FDI_ID, $vv);
487
+ $tb->seekLessThan(false);
488
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv - 1);
489
+ $tb->seekPrev();
490
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv - 2);
491
+ $tb->close();
492
+ $this->deleteDbObj($db);
493
+ }
494
+ public function testGetFirst()
495
+ {
496
+ $db = $this->getDbObj();
497
+ $tb = $this->openTable($db);
498
+ $this->assertNotEquals($tb, NULL);
499
+ $tb->clearBuffer();
500
+ $tb->seekFirst();
501
+ $this->assertEquals($tb->getFVstr(FDI_NAME), 'kosaka');
502
+ $tb->close();
503
+ $this->deleteDbObj($db);
504
+ }
505
+ public function testGetLast()
506
+ {
507
+ $db = $this->getDbObj();
508
+ $tb = $this->openTable($db);
509
+ $this->assertNotEquals($tb, NULL);
510
+ $tb->clearBuffer();
511
+ $tb->seekLast();
512
+ $this->assertEquals($tb->getFVstr(FDI_NAME), '' . (TEST_COUNT + 2));
513
+ $tb->close();
514
+ $this->deleteDbObj($db);
515
+ }
516
+ public function testMovePosition()
517
+ {
518
+ $db = $this->getDbObj();
519
+ $tb = $this->openTable($db);
520
+ $this->assertNotEquals($tb, NULL);
521
+ $vv = TEST_COUNT * 3 / 4;
522
+ $tb->clearBuffer();
523
+ $tb->setFV(FDI_ID, $vv);
524
+ $tb->seekLessThan(true);
525
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv);
526
+ $ps = $tb->bookmark();
527
+ $ps_vv = $vv;
528
+ $this->assertEquals($tb->stat(), 0);
529
+ $vv = $vv - FIVE_PERCENT_OF_TEST_COUNT;
530
+ $tb->clearBuffer();
531
+ $tb->setFV(FDI_ID, $vv);
532
+ $tb->seekLessThan(false);
533
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv - 1);
534
+ $tb->seekPrev();
535
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv - 2);
536
+ $tb->seekByBookmark($ps);
537
+ $this->assertEquals($tb->getFVint(FDI_ID), $ps_vv);
538
+ $tb->close();
539
+ $this->deleteDbObj($db);
540
+ }
541
+ public function testUpdate()
542
+ {
543
+ $db = $this->getDbObj();
544
+ $tb = $this->openTable($db);
545
+ $this->assertNotEquals($tb, NULL);
546
+ $db->beginTrn();
547
+ // test of ncc
548
+ $v = 5;
549
+ $tb->clearBuffer();
550
+ $tb->setFV(FDI_ID, $v);
551
+ $tb->seek();
552
+ $this->assertEquals($tb->stat(), 0);
553
+ $v = TEST_COUNT + TEST_COUNT / 2;
554
+ $tb->setFV(FDI_ID, $v);
555
+ $tb->update(table::changeCurrentNcc); // 5 . 30000 cur 5
556
+ $this->assertEquals($tb->stat(), 0);
557
+ $tb->seekNext(); // next 5
558
+ $this->assertEquals($tb->getFVint(FDI_ID), 6);
559
+ $v = TEST_COUNT - 1;
560
+ $tb->setFV(FDI_ID, $v);
561
+ $tb->seek();
562
+ $this->assertEquals($tb->getFVint(FDI_ID), $v);
563
+ $v = 5;
564
+ $tb->setFV(FDI_ID, $v);
565
+ $tb->update(table::changeCurrentCc); // 19999 . 5 cur 5
566
+ $this->assertEquals($tb->stat(), 0);
567
+ $tb->seekNext();
568
+ $this->assertEquals($tb->stat(), 0);
569
+ $this->assertEquals($tb->getFVint(FDI_ID), 6);
570
+ $v = TEST_COUNT - 1;
571
+ $tb->setFV(FDI_ID, $v);
572
+ $tb->update(table::changeCurrentCc); // 6 . 19999 cur 19999
573
+ $tb->seekPrev(); // prev 19999
574
+ $this->assertEquals($tb->getFVint(FDI_ID), $v -1);
575
+ $v = 10;
576
+ $tb->clearBuffer();
577
+ $tb->setFV(FDI_ID, $v);
578
+ $tb->seek();
579
+ $this->assertEquals($tb->stat(), 0);
580
+ $tb->seekNext();
581
+ $this->assertEquals($tb->getFVint(FDI_ID), 11);
582
+ for ($i = 10; $i <= (TEST_COUNT - 2); $i++)
583
+ {
584
+ $tb->clearBuffer();
585
+ $tb->setFV(FDI_ID, $i);
586
+ $tb->seek();
587
+ $this->assertEquals($tb->stat(), 0);
588
+ $v = $i + 1;
589
+ $tb->setFV(FDI_NAME, $v);
590
+ $tb->update();
591
+ $this->assertEquals($tb->stat(), 0);
592
+ }
593
+ $db->endTrn();
594
+ // check update in key;
595
+ $v = 8;
596
+ $tb->setFV(FDI_ID, $v);
597
+ $tb->setFV(FDI_NAME, 'ABC');
598
+ $tb->update(table::changeInKey);
599
+ $this->assertEquals($tb->stat(), 0);
600
+ $tb->clearBuffer();
601
+ $tb->setFV(FDI_ID, $v);
602
+ $tb->seek();
603
+ $this->assertEquals($tb->getFVstr(FDI_NAME), 'ABC');
604
+ $tb->close();
605
+ $this->deleteDbObj($db);
606
+ }
607
+ public function testSnapShot()
608
+ {
609
+ $db = $this->getDbObj();
610
+ $db2 = $this->getDbObj();
611
+ $db2->connect(PROTOCOL . HOSTNAME . DBNAME, true);
612
+ $this->assertEquals($db2->stat(), 0);
613
+ $tb = $this->openTable($db);
614
+ $this->assertNotEquals($tb, NULL);
615
+ $tb2 = $this->openTable($db2);
616
+ $this->assertNotEquals($tb2, NULL);
617
+ $db->beginSnapshot();
618
+ $this->assertEquals($db->stat(), 0);
619
+ $tb->setKeyNum(0);
620
+ $tb->seekFirst();
621
+ $this->assertEquals($tb->stat(), 0);
622
+ $firstValue = $tb->getFVstr(FDI_NAME);
623
+ $tb->seekNext();
624
+ // ----------------------------------------------------
625
+ // Change data by another connection
626
+ $tb2->setKeyNum(0);
627
+ $tb2->seekFirst();
628
+ $this->assertEquals($tb2->stat(), 0);
629
+ $tb2->setFV(FDI_NAME, $tb2->getFVint(FDI_ID) + 1);
630
+ $tb2->update();
631
+ if (ISOLATION_READ_COMMITTED)
632
+ $this->assertEquals($tb2->stat(), 0);
633
+ elseif (ISOLATION_REPEATABLE_READ)
634
+ $this->assertEquals($tb2->stat(), transactd::STATUS_LOCK_ERROR);
635
+ // ----------------------------------------------------
636
+ $tb->seekFirst();
637
+ $secondValue = $tb->getFVstr(FDI_NAME);
638
+ $this->assertEquals($tb->stat(), 0);
639
+ $db->endSnapshot();
640
+ $this->assertEquals($tb->stat(), 0);
641
+ if (ISOLATION_READ_COMMITTED)
642
+ $this->assertNotEquals($secondValue, $firstValue);
643
+ else
644
+ $this->assertEquals($secondValue, $firstValue);
645
+ // ----------------------------------------------------
646
+ $tb->close();
647
+ $tb2->close();
648
+ $this->deleteDbObj($db);
649
+ $this->deleteDbObj($db2);
650
+ }
651
+ public function testTransactionLock()
652
+ {
653
+ $db = $this->getDbObj();
654
+ $db2 = $this->getDbObj();
655
+ $db2->connect(PROTOCOL . HOSTNAME . DBNAME, true);
656
+ $this->assertEquals($db2->stat(), 0);
657
+ $tb = $this->openTable($db);
658
+ $this->assertNotEquals($tb, NULL);
659
+ $tb2 = $this->openTable($db2);
660
+ $this->assertNotEquals($tb2, NULL);
661
+ // ----------------------------------------------------
662
+ // Read test that single record lock with read
663
+ // ----------------------------------------------------
664
+ $db->beginTrn(transactd::LOCK_SINGLE_NOWAIT);
665
+ $tb->setKeyNum(0);
666
+ $tb->seekFirst();
667
+ $this->assertEquals($tb->stat(), 0);
668
+ // unlock first record
669
+ $tb->seekNext();
670
+ $tb2->seekFirst();
671
+ $this->assertEquals($tb2->stat(), 0);
672
+ $db2->beginTrn();
673
+ $tb2->setKeyNum(0);
674
+ $tb2->seekFirst();
675
+ $this->assertEquals($tb2->stat(), 0);
676
+ $db2->endTrn();
677
+ $db->endTrn();
678
+ // ----------------------------------------------------
679
+ // Can't read test that multi record lock with read
680
+ // ----------------------------------------------------
681
+ $db->beginTrn(transactd::LOCK_MULTI_NOWAIT);
682
+ $tb->setKeyNum(0);
683
+ $tb->seekFirst();
684
+ $this->assertEquals($tb->stat(), 0);
685
+ // move from first record.
686
+ $tb->seekNext();
687
+ // not transactional user can not read
688
+ $tb2->seekFirst();
689
+ $this->assertEquals($tb2->stat(), transactd::STATUS_LOCK_ERROR);
690
+ // The second transactional user can not lock same record
691
+ $db2->beginTrn();
692
+ $tb2->setKeyNum(0);
693
+ $tb2->seekFirst();
694
+ $this->assertEquals($tb2->stat(), transactd::STATUS_LOCK_ERROR);
695
+ $db2->endTrn();
696
+ $db->endTrn();
697
+ // ----------------------------------------------------
698
+ // Can't read test that single record lock with change
699
+ // ----------------------------------------------------
700
+ $db->beginTrn(transactd::LOCK_SINGLE_NOWAIT);
701
+ $tb->setKeyNum(0);
702
+ $tb->seekFirst();
703
+ $this->assertEquals($tb->stat(), 0);
704
+ $tb->setFV(FDI_NAME, 'ABC');
705
+ $tb->update();
706
+ $this->assertEquals($tb->stat(), 0);
707
+ // move from first record.
708
+ $tb->seekNext();
709
+ $tb2->seekFirst();
710
+ $this->assertEquals($tb2->stat(), transactd::STATUS_LOCK_ERROR);
711
+ $db2->beginTrn();
712
+ $tb2->setKeyNum(0);
713
+ $tb2->seekFirst();
714
+ $this->assertEquals($tb2->stat(), transactd::STATUS_LOCK_ERROR);
715
+ $db2->endTrn();
716
+ $db->endTrn();
717
+ // ----------------------------------------------------
718
+ // Abort test that Single record lock transaction
719
+ // ----------------------------------------------------
720
+ $db->beginTrn(transactd::LOCK_SINGLE_NOWAIT);
721
+ $tb->setKeyNum(0);
722
+ $tb->seekFirst();
723
+ $this->assertEquals($tb->stat(), 0);
724
+ $tb->setFV(FDI_NAME, 'EFG');
725
+ $tb->update();
726
+ $this->assertEquals($tb->stat(), 0);
727
+ // move from first record.
728
+ $tb->seekNext();
729
+ $db->abortTrn();
730
+ $tb2->setKeyNum(0);
731
+ $tb2->seekFirst();
732
+ $this->assertEquals($tb2->getFVstr(FDI_NAME), 'ABC');
733
+ $tb->close();
734
+ $tb2->close();
735
+ $this->deleteDbObj($db);
736
+ $this->deleteDbObj($db2);
737
+ }
738
+ public function testConflict()
739
+ {
740
+ $db = $this->getDbObj();
741
+ $db2 = $this->getDbObj();
742
+ $db2->connect(PROTOCOL . HOSTNAME . DBNAME, true);
743
+ $this->assertEquals($db2->stat(), 0);
744
+ $tb = $this->openTable($db);
745
+ $this->assertNotEquals($tb, NULL);
746
+ $tb2 = $this->openTable($db2);
747
+ $this->assertNotEquals($tb2, NULL);
748
+ $tb->setKeyNum(0);
749
+ $tb->seekFirst();
750
+ $this->assertEquals($tb->stat(), 0);
751
+ // ----------------------------------------------------
752
+ // Change Index field
753
+ // ----------------------------------------------------
754
+ // Change data by another connection
755
+ $tb2->setKeyNum(0);
756
+ $tb2->seekFirst();
757
+ $this->assertEquals($tb2->stat(), 0);
758
+ $tb2->setFV(FDI_ID, $tb2->getFVint(FDI_ID) - 10);
759
+ $tb2->update();
760
+ $this->assertEquals($tb2->stat(), 0);
761
+ // ----------------------------------------------------
762
+ // Change same record data by original connection
763
+ $tb->setFV(FDI_ID, $tb->getFVint(FDI_ID) - 8);
764
+ $tb->update();
765
+ $this->assertEquals($tb->stat(), transactd::STATUS_CHANGE_CONFLICT);
766
+ // ----------------------------------------------------
767
+ // Change Non index field
768
+ // ----------------------------------------------------
769
+ // Change data by another connection
770
+ $tb->seekFirst();
771
+ $this->assertEquals($tb->stat(), 0);
772
+ $tb2->seekFirst();
773
+ $this->assertEquals($tb2->stat(), 0);
774
+ $tb2->setFV(FDI_NAME, $tb2->getFVint(FDI_ID) - 10);
775
+ $tb2->update();
776
+ $this->assertEquals($tb2->stat(), 0);
777
+ // ----------------------------------------------------
778
+ // Change same record data by original connection
779
+ $tb->setFV(FDI_NAME, $tb->getFVint(FDI_NAME) - 8);
780
+ $tb->update();
781
+ $this->assertEquals($tb->stat(), transactd::STATUS_CHANGE_CONFLICT);
782
+ // ----------------------------------------------------
783
+ $tb->close();
784
+ $tb2->close();
785
+ $this->deleteDbObj($db);
786
+ $this->deleteDbObj($db2);
787
+ }
788
+ public function testInsert2()
789
+ {
790
+ $db = $this->getDbObj();
791
+ $tb = $this->openTable($db);
792
+ $this->assertNotEquals($tb, NULL);
793
+ $v = TEST_COUNT * 2;
794
+ $db->beginTrn();
795
+ $tb->clearBuffer();
796
+ $tb->setFV(FDI_ID, $v);
797
+ $tb->insert();
798
+ $this->assertEquals($tb->stat(), 0);
799
+ $v = 10;
800
+ $tb->clearBuffer();
801
+ $tb->setFV(FDI_ID, $v);
802
+ $tb->seek();
803
+ $this->assertEquals($tb->stat(), 0);
804
+ $tb->seekNext();
805
+ $this->assertEquals($tb->getFVint(FDI_ID), 11);
806
+ $db->endTrn();
807
+ $tb->close();
808
+ $this->deleteDbObj($db);
809
+ }
810
+ public function testDelete()
811
+ {
812
+ $db = $this->getDbObj();
813
+ $tb = $this->openTable($db);
814
+ $this->assertNotEquals($tb, NULL);
815
+ // estimate count
816
+ $count = $tb->recordCount(true);
817
+ $is_valid_count = (abs($count - TEST_COUNT - 3) < FIVE_PERCENT_OF_TEST_COUNT);
818
+ $this->assertTrue($is_valid_count);
819
+ if (! $is_valid_count)
820
+ print("true record count = " . (TEST_COUNT + 3) . " and estimate recordCount count = " . $count);
821
+ $this->assertEquals($tb->recordCount(false), TEST_COUNT + 3); // true count
822
+ $vv = TEST_COUNT * 3 / 4 + 1;
823
+ $tb->clearBuffer();
824
+ $tb->setFV(FDI_ID, $vv);
825
+ $tb->seek();
826
+ $this->assertEquals($tb->getFVint(FDI_ID), $vv);
827
+ $tb->del();
828
+ $this->assertEquals($tb->stat(), 0);
829
+ $tb->setFV(FDI_ID, $vv);
830
+ $tb->seek();
831
+ $this->assertEquals($tb->stat(), 4);
832
+ // check update in key
833
+ $vv = 8;
834
+ $tb->setFV(FDI_ID, $vv);
835
+ $tb->del(true);
836
+ $this->assertEquals($tb->stat(), 0);
837
+ $tb->clearBuffer();
838
+ $tb->setFV(FDI_ID, $vv);
839
+ $tb->seek();
840
+ $this->assertEquals($tb->stat(), transactd::STATUS_NOT_FOUND_TI);
841
+ $db->beginTrn();
842
+ $tb->stepFirst();
843
+ while ($tb->stat() == 0)
844
+ {
845
+ $tb->del();
846
+ $this->assertEquals($tb->stat(), 0);
847
+ $tb->stepNext();
848
+ }
849
+ $this->assertEquals($tb->stat(), 9);
850
+ $db->endTrn();
851
+ $this->assertEquals($tb->recordCount(false), 0);
852
+ $tb->close();
853
+ $this->deleteDbObj($db);
854
+ }
855
+ public function testSetOwner()
856
+ {
857
+ $db = $this->getDbObj();
858
+ $tb = $this->openTable($db);
859
+ $this->assertNotEquals($tb, NULL);
860
+ $tb->setOwnerName("ABCDEFG");
861
+ $this->assertEquals($tb->stat(), 0);
862
+ $tb->clearOwnerName();
863
+ $this->assertEquals($tb->stat(), 0);
864
+ $tb->close();
865
+ $this->deleteDbObj($db);
866
+ }
867
+ public function testDropIndex()
868
+ {
869
+ $db = $this->getDbObj();
870
+ $tb = $this->openTable($db);
871
+ $this->assertNotEquals($tb, NULL);
872
+ $tb->dropIndex(false);
873
+ $this->assertEquals($tb->stat(), 0);
874
+ $tb->close();
875
+ $this->deleteDbObj($db);
876
+ }
877
+ public function testDropDatabase()
878
+ {
879
+ $db = $this->getDbObj();
880
+ $this->dropDatabase($db);
881
+ $this->deleteDbObj($db);
882
+ }
883
+ public function testLogin()
884
+ {
885
+ $db = $this->getDbObj();
886
+ $db->connect(PROTOCOL . HOSTNAME);
887
+ $this->assertEquals($db->stat(), 0);
888
+ if ($db->stat() == 0)
889
+ {
890
+ // second connection
891
+ $db2 = $this->getDbObj();
892
+ $db2->connect(PROTOCOL . HOSTNAME . DBNAME, true);
893
+ $this->assertEquals($db->stat(), 0);
894
+ $this->deleteDbObj($db2);
895
+ $db->disconnect(PROTOCOL . HOSTNAME);
896
+ $this->assertEquals($db->stat(), 0);
897
+ }
898
+ // invalid host name
899
+ $db->connect(PROTOCOL . 'localhost123/');
900
+ $is_valid_stat = ($db->stat() == transactd::ERROR_TD_INVALID_CLINETHOST) ||
901
+ ($db->stat() == transactd::ERROR_TD_HOSTNAME_NOT_FOUND);
902
+ $this->assertTrue($is_valid_stat);
903
+ if (! $is_valid_stat)
904
+ print('bad host $db->stat() = ' . $db->stat());
905
+ $this->createDatabase($db);
906
+ $this->createTable($db);
907
+ $db->disconnect(PROTOCOL . HOSTNAME . DBNAME);
908
+ $this->assertEquals($db->stat(), 0);
909
+ // true database name
910
+ $db->connect(PROTOCOL . HOSTNAME . DBNAME);
911
+ $this->assertEquals($db->stat(), 0);
912
+ if ($db->stat() == 0)
913
+ {
914
+ $db->disconnect(PROTOCOL . HOSTNAME . DBNAME);
915
+ $this->assertEquals($db->stat(), 0);
916
+ }
917
+ // invalid database name
918
+ $this->dropDatabase($db);
919
+ $db->disconnect(PROTOCOL . HOSTNAME . DBNAME);
920
+ $this->assertEquals($db->stat(), 0);
921
+ $db->connect(PROTOCOL . HOSTNAME . DBNAME);
922
+ $this->assertEquals($db->stat(), 25000 + 1049);
923
+ $db->disconnect(PROTOCOL . HOSTNAME . DBNAME);
924
+ $this->assertEquals($db->stat(), 0);
925
+ $this->deleteDbObj($db);
926
+ }
927
+
928
+ /* -----------------------------------------------------
929
+ transactd var tables
930
+ ----------------------------------------------------- */
931
+
932
+ private function isWindows()
933
+ {
934
+ return (strtolower(substr(PHP_OS, 0, 3)) == 'win');
935
+ }
936
+ private function isUtf16leSupport($db)
937
+ {
938
+ // CHARSET_UTF16LE supported on MySQL 5.6 or later
939
+ $vv = new btrVersions();
940
+ $db->getBtrVersion($vv);
941
+ $server_ver = $vv->version(1);
942
+ if ('M' == chr($server_ver->type))
943
+ {
944
+ if ($server_ver->majorVersion <= 4)
945
+ return false;
946
+ elseif ($server_ver->majorVersion == 5 && $server_ver->minorVersion <= 5)
947
+ return false;
948
+ return true;
949
+ }
950
+ return false;
951
+ }
952
+ private function createVarTable($db, $id, $name, $fieldType, $charset)
953
+ {
954
+ // create table
955
+ $dbdef = $db->dbDef();
956
+ $this->assertNotEquals($dbdef, NULL);
957
+ $td = new tabledef();
958
+ $td->setTableName($name);
959
+ $td->setFileName($name . '.dat');
960
+ $td->id = $id;
961
+ $td->keyCount = 0;
962
+ $td->fieldCount = 0;
963
+ $td->flags->all = 0;
964
+ $td->pageSize = 2048;
965
+ $td->charsetIndex = $charset;
966
+ $dbdef->insertTable($td);
967
+ $this->assertEquals($dbdef->stat(), 0);
968
+ // id
969
+ $fd = $dbdef->insertField($id, 0);
970
+ $fd->setName('id');
971
+ $fd->type = transactd::ft_integer;
972
+ $fd->len = 4;
973
+ $dbdef->updateTableDef($id);
974
+ $this->assertEquals($dbdef->stat(), 0);
975
+ // name
976
+ $fd = $dbdef->insertField($id, 1);
977
+ $fd->setName('name');
978
+ $fd->type = $fieldType;
979
+ if ($fieldType == transactd::ft_mywvarchar)
980
+ $fd->len = 1 + transactd::charsize(transactd::CHARSET_UTF16LE) * 3; // max 3 char len byte
981
+ elseif ($fieldType == transactd::ft_mywvarbinary)
982
+ $fd->len = 1 + transactd::charsize(transactd::CHARSET_UTF16LE) * 3; // max 6 char len byte
983
+ elseif ($fieldType == transactd::ft_myvarchar)
984
+ {
985
+ if ($charset == transactd::CHARSET_CP932)
986
+ $fd->len = 1 + transactd::charsize(transactd::CHARSET_CP932) * 3; // max 6 char len byte
987
+ elseif($charset == transactd::CHARSET_UTF8B4)
988
+ $fd->len = 1 + transactd::charsize(transactd::CHARSET_UTF8B4) * 3; // max 6 char len byte
989
+ }
990
+ else
991
+ $fd->len = 7; // max 6 char len byte
992
+ $dbdef->updateTableDef($id);
993
+ $this->assertEquals($dbdef->stat(), 0);
994
+ // groupid
995
+ $fd = $dbdef->insertField($id, 2);
996
+ $fd->setName('groupid');
997
+ $fd->type = transactd::ft_integer;
998
+ $fd->len = 4;
999
+ $dbdef->updateTableDef($id);
1000
+ $this->assertEquals($dbdef->stat(), 0);
1001
+ // key 1
1002
+ $kd = $dbdef->insertKey($id, 0);
1003
+ $kd->segment(0)->fieldNum = 0;
1004
+ $kd->segment(0)->flags->bit8 = 1; // extended key type
1005
+ $kd->segment(0)->flags->bit1 = 1; // changeable
1006
+ $kd->segmentCount = 1;
1007
+ $dbdef->updateTableDef($id);
1008
+ $this->assertEquals($dbdef->stat(), 0);
1009
+ // key 2
1010
+ $kd = $dbdef->insertKey($id, 1);
1011
+ $kd->segment(0)->fieldNum = 1;
1012
+ $kd->segment(0)->flags->bit8 = 1; // extended key type
1013
+ $kd->segment(0)->flags->bit1 = 1; // changeable
1014
+ $kd->segment(0)->flags->bit0 = 1; // duplicateable
1015
+ $kd->segment(0)->flags->bit4 = 1; // not last segmnet
1016
+ $kd->segment(1)->fieldNum = 2;
1017
+ $kd->segment(1)->flags->bit8 = 1; // extended key type
1018
+ $kd->segment(1)->flags->bit1 = 1; // changeable
1019
+ $kd->segment(1)->flags->bit0 = 1; // duplicateable
1020
+ $kd->segmentCount = 2;
1021
+ $dbdef->updateTableDef($id);
1022
+ $this->assertEquals($dbdef->stat(), 0);
1023
+ // open
1024
+ $tb = $db->openTable($id);
1025
+ $this->assertEquals($db->stat(), 0);
1026
+ $tb->close();
1027
+ }
1028
+
1029
+ public function testCreateDatabaseVar()
1030
+ {
1031
+ $db = $this->getDbObj();
1032
+ $db->create(URL_VAR);
1033
+ if ($db->stat() == transactd::STATUS_TABLE_EXISTS_ERROR)
1034
+ {
1035
+ $this->testDropDatabaseVar();
1036
+ $db->create(URL_VAR);
1037
+ }
1038
+ $this->assertEquals($db->stat(), 0);
1039
+ if (0 == $db->stat())
1040
+ {
1041
+ $db->open(URL_VAR, 0, 0);
1042
+ $this->assertEquals($db->stat(), 0);
1043
+ }
1044
+ if (0 == $db->stat())
1045
+ {
1046
+ $this->createVarTable($db, 1, 'user1', transactd::ft_myvarchar, transactd::CHARSET_CP932);
1047
+ $this->createVarTable($db, 2, 'user2', transactd::ft_myvarbinary, transactd::CHARSET_CP932);
1048
+ if ($this->isUtf16leSupport($db))
1049
+ $this->createVarTable($db, 3, 'user3', transactd::ft_mywvarchar, transactd::CHARSET_CP932);
1050
+ $this->createVarTable($db, 4, 'user4', transactd::ft_mywvarbinary, transactd::CHARSET_CP932);
1051
+ $this->createVarTable($db, 5, 'user5', transactd::ft_myvarchar, transactd::CHARSET_UTF8B4);
1052
+ $db->close();
1053
+ $db->open(URL_VAR);
1054
+ $this->assertEquals($db->stat(), 0);
1055
+ }
1056
+ $this->deleteDbObj($db);
1057
+ }
1058
+ private function setGetVar($tb, $unicodeField, $varCharField)
1059
+ {
1060
+ //// Set Wide Get Wide
1061
+ //if ($this->isWindows())
1062
+ //{
1063
+ // $tb->setFVW(FDI_GROUP, '68');
1064
+ // $this->assertEquals($tb->getFVWstr(FDI_GROUP), '68');
1065
+ //}
1066
+ //else
1067
+ //{
1068
+ $tb->setFV(FDI_GROUP, '68');
1069
+ $this->assertEquals($tb->getFVstr(FDI_GROUP), '68');
1070
+ //}
1071
+ //if ($this->isWindows())
1072
+ //{
1073
+ // // too long string
1074
+ // $tb->setFVW(FDI_NAME, '1234567');
1075
+ // if ($varCharField)
1076
+ // {
1077
+ // $this->assertEquals($tb->getFVWstr(FDI_NAME), '123');
1078
+ // if ($tb->getFVWstr(FDI_NAME) != '123')
1079
+ // print_r($tb->getFVWstr(FDI_NAME));
1080
+ // }
1081
+ // else
1082
+ // {
1083
+ // $this->assertEquals($tb->getFVWstr(FDI_NAME), '123456');
1084
+ // }
1085
+ // $this->assertEquals($tb->getFVWstr(FDI_GROUP), '68');
1086
+ // // short string;
1087
+ // $tb->setFVW(FDI_NAME, '12 ');
1088
+ // $this->assertEquals($tb->getFVWstr(FDI_NAME), '12 ');
1089
+ // $this->assertEquals($tb->getFVWstr(FDI_GROUP), '68');
1090
+ // // too long kanji;
1091
+ // if ($unicodeField)
1092
+ // {
1093
+ // $tb->setFVW(FDI_NAME, 'あいうえお𩸽'); // hiragana 'aiueo' + kanji 'hokke'
1094
+ // if ($varCharField)
1095
+ // $this->assertEquals($tb->getFVWstr(FDI_NAME), 'あいう');
1096
+ // else
1097
+ // $this->assertEquals($tb->getFVWstr(FDI_NAME), 'あいうえお');
1098
+ // }
1099
+ // else
1100
+ // {
1101
+ // $tb->setFVW(FDI_NAME, '0松本市'); // numeric '0' kanji 'matumostoshi'
1102
+ // $this->assertEquals($tb->getFVWstr(FDI_NAME), '0松本');
1103
+ // }
1104
+ // $this->assertEquals($tb->getFVWstr(FDI_GROUP), '68');
1105
+ //}
1106
+ // Set Ansi Get Wide
1107
+ // too long string
1108
+ $tb->setFVA(FDI_NAME, '1234567');
1109
+ if ($varCharField)
1110
+ $this->assertEquals($tb->getFVAstr(FDI_NAME), '123');
1111
+ else
1112
+ $this->assertEquals($tb->getFVAstr(FDI_NAME), '123456');
1113
+ //if ($this->isWindows())
1114
+ // $this->assertEquals($tb->getFVWstr(FDI_GROUP), '68');
1115
+ //else
1116
+ $this->assertEquals($tb->getFVAstr(FDI_GROUP), '68');
1117
+ // short string
1118
+ $tb->setFVA(FDI_NAME, '13 ');
1119
+ $this->assertEquals($tb->getFVAstr(FDI_NAME), '13 ');
1120
+ //if ($this->isWindows())
1121
+ // $this->assertEquals($tb->getFVWstr(FDI_GROUP), '68');
1122
+ //else
1123
+ $this->assertEquals($tb->getFVAstr(FDI_GROUP), '68');
1124
+ // too long kanji
1125
+ if ($unicodeField)
1126
+ {
1127
+ if ($this->isWindows())
1128
+ {
1129
+ $tb->setFVA(FDI_NAME, 'あいうえお𩸽'); // hiragana 'aiueo' kanji 'hokke'
1130
+ if ($varCharField)
1131
+ $this->assertEquals($tb->getFVAstr(FDI_NAME), 'あいう');
1132
+ else
1133
+ $this->assertEquals($tb->getFVAstr(FDI_NAME), 'あいうえお');
1134
+ }
1135
+ }
1136
+ else
1137
+ {
1138
+ $tb->setFVA(FDI_NAME, '0松本市'); // numeric '0' kanji 'matumostoshi'
1139
+ $is_valid_value = ($tb->getFVAstr(FDI_NAME) == '0松本');
1140
+ $this->assertTrue($is_valid_value);
1141
+ if (! $is_valid_value)
1142
+ print_r($tb->getFVAstr(FDI_NAME));
1143
+ }
1144
+ $this->assertEquals($tb->getFVAstr(FDI_GROUP), '68');
1145
+ //// Set Wide Get Ansi
1146
+ //if ($this->isWindows())
1147
+ //{
1148
+ // // too long string
1149
+ // $tb->setFVW(FDI_NAME, '1234567');
1150
+ // if ($varCharField)
1151
+ // $this->assertEquals($tb->getFVAstr(FDI_NAME), '123');
1152
+ // else
1153
+ // $this->assertEquals($tb->getFVAstr(FDI_NAME), '123456');
1154
+ // $this->assertEquals($tb->getFVWstr(FDI_GROUP), '68');
1155
+ // // short string
1156
+ // $tb->setFVW(1, '23 ');
1157
+ // $this->assertEquals($tb->getFVAstr(FDI_NAME), '23 ');
1158
+ // $this->assertEquals($tb->getFVWstr(FDI_GROUP), '68');
1159
+ // // too long kanji
1160
+ // if ($unicodeField)
1161
+ // {
1162
+ // $tb->setFVW(FDI_NAME, 'あいうえお𩸽'); // hiragana 'aiueo' kanji 'hokke'
1163
+ // if ($varCharField)
1164
+ // $this->assertEquals($tb->getFVAstr(FDI_NAME), 'あいう');
1165
+ // else
1166
+ // $this->assertEquals($tb->getFVAstr(FDI_NAME), 'あいうえお');
1167
+ // }
1168
+ // else
1169
+ // {
1170
+ // $tb->setFVW(FDI_NAME, '0松本市'); // numeric '0' kanji 'matumostoshi'
1171
+ // $this->assertEquals($tb->getFVAstr(FDI_NAME), '0松本');
1172
+ // }
1173
+ // $this->assertEquals($tb->getFVWstr(FDI_GROUP), '68');
1174
+ //}
1175
+ // Set Ansi Get Ansi
1176
+ // too long string
1177
+ $tb->setFVA(FDI_NAME, '1234567');
1178
+ if ($varCharField)
1179
+ $this->assertEquals($tb->getFVAstr(FDI_NAME), '123');
1180
+ else
1181
+ $this->assertEquals($tb->getFVAstr(FDI_NAME), '123456');
1182
+ $this->assertEquals($tb->getFVAstr(FDI_GROUP), '68');
1183
+ // short string
1184
+ $tb->setFVA(FDI_NAME, '13 ');
1185
+ $this->assertEquals($tb->getFVAstr(FDI_NAME), '13 ');
1186
+ $this->assertEquals($tb->getFVAstr(FDI_GROUP), '68');
1187
+ // too long lanji
1188
+ if ($unicodeField)
1189
+ {
1190
+ if ($this->isWindows())
1191
+ {
1192
+ $tb->setFVA(FDI_NAME, 'あいうえお𩸽'); // hiragana 'aiueo' kanji 'hokke'
1193
+ if ($varCharField)
1194
+ $this->assertEquals($tb->getFVAstr(FDI_NAME), 'あいう');
1195
+ else
1196
+ $this->assertEquals($tb->getFVAstr(FDI_NAME), 'あいうえお');
1197
+ }
1198
+ }
1199
+ else
1200
+ {
1201
+ $tb->setFVA(FDI_NAME, '0松本市'); // numeric '0' kanji 'matumostoshi'
1202
+ $this->assertEquals($tb->getFVAstr(FDI_NAME), '0松本');
1203
+ }
1204
+ $this->assertEquals($tb->getFVAstr(FDI_GROUP), '68');
1205
+ }
1206
+ public function testVarField()
1207
+ {
1208
+ $db = $this->getDbObj();
1209
+ $db->open(URL_VAR);
1210
+ $this->assertEquals($db->stat(), 0);
1211
+ $tb = $db->openTable('user1');
1212
+ $this->assertEquals($db->stat(), 0);
1213
+ // acp varchar
1214
+ $this->setGetVar($tb, false, true);
1215
+ $tb->close();
1216
+ $tb = $db->openTable('user2');
1217
+ $this->assertEquals($db->stat(), 0);
1218
+ // acp varbinary
1219
+ $this->setGetVar($tb, false, false);
1220
+ $tb->close();
1221
+ if ($this->isUtf16leSupport($db))
1222
+ {
1223
+ $tb = $db->openTable('user3');
1224
+ $this->assertEquals($db->stat(), 0);
1225
+ // unicode varchar
1226
+ $this->setGetVar($tb, true, true);
1227
+ $tb->close();
1228
+ }
1229
+ $tb = $db->openTable('user4');
1230
+ $this->assertEquals($db->stat(), 0);
1231
+ // unicode varbinary
1232
+ $this->setGetVar($tb, true, false);
1233
+ $tb->close();
1234
+ $tb = $db->openTable('user5');
1235
+ $this->assertEquals($db->stat(), 0);
1236
+ // utf8 varchar
1237
+ $this->setGetVar($tb, true, true);
1238
+ $tb->close();
1239
+ $this->deleteDbObj($db);
1240
+ }
1241
+ private function doVarInsert($db, $name, $codePage, $str, $startid, $endid, $bulk)
1242
+ {
1243
+ $tb = $db->openTable($name);
1244
+ $this->assertEquals($db->stat(), 0);
1245
+ if ($bulk)
1246
+ $tb->beginBulkInsert(BULKBUFSIZE);
1247
+ for ($i = $startid; $i <= $endid; $i++)
1248
+ {
1249
+ $tb->clearBuffer();
1250
+ $tb->setFV(FDI_ID, $i);
1251
+ $tb->setFV(FDI_NAME, $str . $i);
1252
+ $tb->setFV(FDI_GROUP, "" . ($i + 10));
1253
+ $tb->insert();
1254
+ }
1255
+ if ($bulk)
1256
+ $tb->commitBulkInsert();
1257
+ $this->assertEquals($tb->stat(), 0);
1258
+ $tb->close();
1259
+ }
1260
+ public function testVarInsert()
1261
+ {
1262
+ $db = $this->getDbObj();
1263
+ $startid = 1;
1264
+ $bulk = false;
1265
+ $str = '漢字文字のテスト'; // too long kanji
1266
+ $str2 = '123';
1267
+ $db->open(URL_VAR);
1268
+ $this->assertEquals($db->stat(), 0);
1269
+ if (0 == $db->stat())
1270
+ {
1271
+ $utf16leSupport = $this->isUtf16leSupport($db);
1272
+ $this->doVarInsert($db, 'user1', transactd::CP_ACP, $str, $startid, $startid, $bulk);
1273
+ $this->doVarInsert($db, 'user2', transactd::CP_ACP, $str, $startid, $startid, $bulk);
1274
+ if ($utf16leSupport)
1275
+ $this->doVarInsert($db, 'user3', transactd::CP_ACP, $str, $startid, $startid, $bulk);
1276
+ $this->doVarInsert($db, 'user4', transactd::CP_ACP, $str, $startid, $startid, $bulk);
1277
+ $this->doVarInsert($db, 'user5', transactd::CP_UTF8, $str, $startid, $startid, $bulk);
1278
+ $startid = $startid + 1;
1279
+ $this->doVarInsert($db, 'user1', transactd::CP_ACP, $str2, $startid, $startid, $bulk);
1280
+ $this->doVarInsert($db, 'user2', transactd::CP_ACP, $str2, $startid, $startid, $bulk);
1281
+ if ($utf16leSupport)
1282
+ $this->doVarInsert($db, 'user3', transactd::CP_ACP, $str2, $startid, $startid, $bulk);
1283
+ $this->doVarInsert($db, 'user4', transactd::CP_ACP, $str2, $startid, $startid, $bulk);
1284
+ $this->doVarInsert($db, 'user5', transactd::CP_UTF8, $str2, $startid, $startid, $bulk);
1285
+ $startid = $startid + 1;
1286
+ $bulk = true;
1287
+ $endid = 1000;
1288
+ $this->doVarInsert($db, 'user1', transactd::CP_ACP, '', $startid, $endid, $bulk);
1289
+ $this->doVarInsert($db, 'user2', transactd::CP_ACP, '', $startid, $endid, $bulk);
1290
+ if ($utf16leSupport)
1291
+ $this->doVarInsert($db, 'user3', transactd::CP_ACP, '', $startid, $endid, $bulk);
1292
+ $this->doVarInsert($db, 'user4', transactd::CP_ACP, '', $startid, $endid, $bulk);
1293
+ $this->doVarInsert($db, 'user5', transactd::CP_UTF8, '', $startid, $endid, $bulk);
1294
+ }
1295
+ $this->deleteDbObj($db);
1296
+ }
1297
+ private function doVarRead($db, $name, $codePage, $str, $num, $ky)
1298
+ {
1299
+ $tb = $db->openTable($name);
1300
+ $this->assertEquals($db->stat(), 0);
1301
+ $tb->clearBuffer();
1302
+ $tb->setKeyNum($ky);
1303
+ if ($ky == 0)
1304
+ {
1305
+ $tb->setFV(FDI_ID, $num);
1306
+ }
1307
+ else
1308
+ {
1309
+ $v = $num + 10;
1310
+ $tb->setFV(FDI_NAME, $str);
1311
+ $tb->setFV(FDI_GROUP, $v);
1312
+ }
1313
+ $tb->seek();
1314
+ $this->assertEquals($tb->stat(), 0);
1315
+ // test read of var field
1316
+ $is_valid_value = ($str == $tb->getFVstr(FDI_NAME));
1317
+ $this->assertTrue($is_valid_value);
1318
+ // test read of second field
1319
+ $this->assertEquals($tb->getFVint(FDI_GROUP), ($num + 10));
1320
+ $tb->close();
1321
+ }
1322
+ public function testVarRead()
1323
+ {
1324
+ $db = $this->getDbObj();
1325
+ $str = '漢字文';
1326
+ $str3 = '漢字文字のテ';
1327
+ $str2 ='123';
1328
+ $str4 ='1232';
1329
+ $db->open(URL_VAR);
1330
+ $this->assertEquals($db->stat(), 0);
1331
+ if (0 == $db->stat())
1332
+ {
1333
+ $utf16leSupport = $this->isUtf16leSupport($db);
1334
+ $num = 1;
1335
+ $ky = 0;
1336
+ // too long string
1337
+ $this->doVarRead($db, 'user1', transactd::CP_ACP, $str, $num, $ky);
1338
+ $this->doVarRead($db, 'user2', transactd::CP_ACP, $str, $num, $ky);
1339
+ if ($utf16leSupport)
1340
+ $this->doVarRead($db, 'user3', transactd::CP_ACP, $str, $num, $ky);
1341
+ $this->doVarRead($db, 'user4', transactd::CP_ACP, $str3, $num, $ky);
1342
+ $this->doVarRead($db, 'user5', transactd::CP_UTF8, $str, $num, $ky);
1343
+ // short string
1344
+ $num = $num + 1;
1345
+ $this->doVarRead($db, 'user1', transactd::CP_ACP, $str2, $num, $ky);
1346
+ $this->doVarRead($db, 'user2', transactd::CP_ACP, $str4, $num, $ky);
1347
+ if ($utf16leSupport)
1348
+ $this->doVarRead($db, 'user3', transactd::CP_ACP, $str2, $num, $ky);
1349
+ $this->doVarRead($db, 'user4', transactd::CP_ACP, $str4, $num, $ky);
1350
+ $this->doVarRead($db, 'user5', transactd::CP_UTF8, $str2, $num, $ky);
1351
+ $ky = 1;
1352
+ $this->doVarRead($db, 'user1', transactd::CP_ACP, '120', 120, $ky);
1353
+ $this->doVarRead($db, 'user2', transactd::CP_ACP, '120', 120, $ky);
1354
+ if ($utf16leSupport)
1355
+ $this->doVarRead($db, 'user3', transactd::CP_ACP, '120', 120, $ky);
1356
+ $this->doVarRead($db, 'user4', transactd::CP_ACP, '120', 120, $ky);
1357
+ $this->doVarRead($db, 'user5', transactd::CP_UTF8, '120', 120, $ky);
1358
+ }
1359
+ $this->deleteDbObj($db);
1360
+ }
1361
+ private function doVarFilter($db, $name, $codePage, $str, $num, $ky)
1362
+ {
1363
+ $tb = $db->openTable($name);
1364
+ $this->assertEquals($db->stat(), 0);
1365
+ $tb->clearBuffer();
1366
+ $tb->setKeyNum($ky);
1367
+ if ($ky == 0)
1368
+ {
1369
+ $buf = 'id > ' . $num . ' and id <= ' . ($num + 10);
1370
+ $tb->setFilter($buf, 0, 10);
1371
+ // find forword
1372
+ $tb->setFV(FDI_ID, $num);
1373
+ $tb->seekGreater(true);
1374
+ $this->assertEquals($tb->stat(), 0);
1375
+ for ($i = ($num + 1); $i <= ($num + 10); $i++)
1376
+ {
1377
+ $tb->findNext();
1378
+ $this->assertEquals($tb->stat(), 0);
1379
+ // test read of var field
1380
+ $this->assertEquals($tb->getFVint(FDI_NAME), $i);
1381
+ // test read of second field
1382
+ $this->assertEquals($tb->getFVint(FDI_GROUP), $i + 10);
1383
+ }
1384
+ // find previous
1385
+ $v = $num + 10;
1386
+ $tb->setFilter($buf, 0, 10);
1387
+ $tb->setFV(FDI_ID, $v);
1388
+ $tb->seekLessThan(true);
1389
+ $this->assertEquals($tb->stat(), 0);
1390
+ $this->assertEquals($tb->getFVint(FDI_ID), $v);
1391
+ for ($i = $num + 10; $i <= $num + 1; $i--)
1392
+ {
1393
+ $tb->findPrev(false);
1394
+ $this->assertEquals($tb->stat(), 0);
1395
+ // test read of var field
1396
+ $this->assertEquals($tb->getFVint(FDI_NAME), $i);
1397
+ // test read of second field
1398
+ $this->assertEquals($tb->getFVint(FDI_GROUP), $i + 10);
1399
+ }
1400
+ // test record count
1401
+ $this->assertEquals($tb->recordCount(), 10);
1402
+ }
1403
+ else
1404
+ {
1405
+ $v = $num + 10;
1406
+ $tb->setFV(FDI_NAME, $str);
1407
+ $tb->setFV(FDI_GROUP, $v);
1408
+ }
1409
+ $tb->close();
1410
+ }
1411
+ public function testFilterVar()
1412
+ {
1413
+ $db = $this->getDbObj();
1414
+ $db->open(URL_VAR);
1415
+ $this->assertEquals($db->stat(), 0);
1416
+ if (0 == $db->stat())
1417
+ {
1418
+ $str = '漢字文';
1419
+ $str3 = '漢字文字のテ';
1420
+ $str2 = '123';
1421
+ $str4 = '1232';
1422
+ $utf16leSupport = $this->isUtf16leSupport($db);
1423
+ $num = 10;
1424
+ $ky = 0;
1425
+ $this->doVarFilter($db, 'user1', transactd::CP_ACP, $str, $num, $ky);
1426
+ $this->doVarFilter($db, 'user2', transactd::CP_ACP, $str, $num, $ky);
1427
+ if ($utf16leSupport)
1428
+ $this->doVarFilter($db, 'user3', transactd::CP_ACP, $str, $num, $ky);
1429
+ $this->doVarFilter($db, 'user4', transactd::CP_ACP, $str3, $num, $ky);
1430
+ $this->doVarFilter($db, 'user5', transactd::CP_UTF8, $str, $num, $ky);
1431
+ //if (UNICODE)
1432
+ //{
1433
+ // // short string
1434
+ // $num = $num + 1;
1435
+ // $this->doVarFilter($db, 'user1', transactd::CP_ACP, $str2, $num, $ky);
1436
+ // $this->doVarFilter($db, 'user2', transactd::CP_ACP, $str4, $num, $ky);
1437
+ // if ($utf16leSupport)
1438
+ // $this->doVarFilter($db, 'user3', transactd::CP_ACP, $str2, $num, $ky);
1439
+ // $this->doVarFilter($db, 'user4', transactd::CP_ACP, $str4, $num, $ky);
1440
+ // $this->doVarFilter($db, 'user5', transactd::CP_UTF8, $str2, $num, $ky);
1441
+ //}
1442
+ $ky = 1;
1443
+ $this->doVarFilter($db, 'user1', transactd::CP_ACP, '120', 120, $ky);
1444
+ $this->doVarFilter($db, 'user2', transactd::CP_ACP, '120', 120, $ky);
1445
+ if ($utf16leSupport)
1446
+ $this->doVarFilter($db, 'user3', transactd::CP_ACP, '120', 120, $ky);
1447
+ $this->doVarFilter($db, 'user4', transactd::CP_ACP, '120', 120, $ky);
1448
+ $this->doVarFilter($db, 'user5', transactd::CP_UTF8, '120', 120, $ky);
1449
+ }
1450
+ $this->deleteDbObj($db);
1451
+ }
1452
+ public function testDropDatabaseVar()
1453
+ {
1454
+ $db = $this->getDbObj();
1455
+ $db->open(URL_VAR);
1456
+ $this->assertEquals($db->stat(), 0);
1457
+ $db->drop();
1458
+ $this->assertEquals($db->stat(), 0);
1459
+ $this->deleteDbObj($db);
1460
+ }
1461
+
1462
+ /* -----------------------------------------------------
1463
+ transactd StringFilter
1464
+ ----------------------------------------------------- */
1465
+
1466
+ private function createTableStringFilter($db, $id, $name, $type, $type2)
1467
+ {
1468
+ // create table
1469
+ $dbdef = $db->dbDef();
1470
+ $td = new tabledef();
1471
+ $td->setTableName($name);
1472
+ $td->setFileName($name . '.dat');
1473
+ $td->id = $id;
1474
+ $td->pageSize = 2048;
1475
+ $td->charsetIndex = transactd::CHARSET_UTF8B4;
1476
+ // $td->charsetIndex = transactd::CHARSET_CP932;
1477
+ $dbdef->insertTable($td);
1478
+ $this->assertEquals($dbdef->stat(), 0);
1479
+ $fd = $dbdef->insertField($id, 0);
1480
+ $fd->setName('id');
1481
+ $fd->type = transactd::ft_integer;
1482
+ $fd->len = 4;
1483
+ $dbdef->updateTableDef($id);
1484
+ $this->assertEquals($dbdef->stat(), 0);
1485
+ $fd = $dbdef->insertField($id, 1);
1486
+ $fd->setName('name');
1487
+ $fd->type = $type;
1488
+ $fd->len = 44;
1489
+ if ($fd->varLenBytes() != 0)
1490
+ {
1491
+ $fd->len = $fd->varLenBytes() + 44;
1492
+ $fd->keylen = $fd->len;
1493
+ }
1494
+ if ($fd->blobLenBytes() != 0)
1495
+ $fd->len = 12; // 8+4
1496
+ $fd->keylen = $fd->len;
1497
+ $dbdef->updateTableDef($id);
1498
+ $this->assertEquals($dbdef->stat(), 0);
1499
+ $fd = $dbdef->insertField($id, 2);
1500
+ $fd->setName('namew');
1501
+ $fd->type = $type2;
1502
+ $fd->len = 44;
1503
+ if ($fd->varLenBytes() != 0)
1504
+ {
1505
+ $fd->len = $fd->varLenBytes() + 44;
1506
+ $fd->keylen = $fd->len;
1507
+ }
1508
+ if ($fd->blobLenBytes() != 0)
1509
+ $fd->len = 12; // 8+4
1510
+ $fd->keylen = $fd->len;
1511
+ $dbdef->updateTableDef($id);
1512
+ $this->assertEquals($dbdef->stat(), 0);
1513
+ $kd = $dbdef->insertKey($id, 0);
1514
+ $kd->segment(0)->fieldNum = 0;
1515
+ $kd->segment(0)->flags->bit8 = 1; // extended key type
1516
+ $kd->segment(0)->flags->bit1 = 1; // changeable
1517
+ $kd->segmentCount = 1;
1518
+ $dbdef->updateTableDef($id);
1519
+ $this->assertEquals($dbdef->stat(), 0);
1520
+ $kd = $dbdef->insertKey($id, 1);
1521
+ $kd->segment(0)->fieldNum = 1;
1522
+ $kd->segment(0)->flags->bit8 = 1; // extended key type
1523
+ $kd->segment(0)->flags->bit1 = 1; // changeable
1524
+ $kd->segment(0)->flags->bit0 = 1; // duplicateable
1525
+ $kd->segmentCount = 1;
1526
+ $dbdef->updateTableDef($id);
1527
+ $this->assertEquals($dbdef->stat(), 0);
1528
+ $kd = $dbdef->insertKey($id, 2);
1529
+ $kd->segment(0)->fieldNum = 2;
1530
+ $kd->segment(0)->flags->bit8 = 1; // extended key type
1531
+ $kd->segment(0)->flags->bit1 = 1; // changeable
1532
+ $kd->segment(0)->flags->bit0 = 1; // duplicateable
1533
+ $kd->segmentCount = 1;
1534
+ $dbdef->updateTableDef($id);
1535
+ $this->assertEquals($dbdef->stat(), 0);
1536
+ }
1537
+ private function doTestInsertStringFilter($tb)
1538
+ {
1539
+ $tb->beginBulkInsert(BULKBUFSIZE);
1540
+ $tb->clearBuffer();
1541
+ $id = 1;
1542
+ $tb->setFV('id', $id);
1543
+ $tb->setFV('name', 'あいうえおかきくこ');
1544
+ $tb->setFV('namew', 'あいうえおかきくこ');
1545
+ $tb->insert();
1546
+ $tb->clearBuffer();
1547
+ $id = 2;
1548
+ $tb->setFV('id', $id);
1549
+ $tb->setFV('name', 'A123456');
1550
+ $tb->setFV('namew', 'A123456');
1551
+ $tb->insert();
1552
+ $tb->clearBuffer();
1553
+ $id = 3;
1554
+ $tb->setFV('id', $id);
1555
+ $tb->setFV('name', 'あいがあればOKです');
1556
+ $tb->setFV('namew', 'あいがあればOKです');
1557
+ $tb->insert();
1558
+ $tb->clearBuffer();
1559
+ $id = 4;
1560
+ $tb->setFV('id', $id);
1561
+ $tb->setFV('name', 'おはようございます');
1562
+ $tb->setFV('namew', 'おはようございます');
1563
+ $tb->insert();
1564
+ $tb->clearBuffer();
1565
+ $id = 5;
1566
+ $tb->setFV('id', $id);
1567
+ $tb->setFV('name', 'おめでとうございます。');
1568
+ $tb->setFV('namew', 'おめでとうございます。');
1569
+ $tb->insert();
1570
+ $tb->commitBulkInsert();
1571
+ }
1572
+ private function doTestReadStringFilter($tb)
1573
+ {
1574
+ $tb->setKeyNum(0);
1575
+ $tb->clearBuffer();
1576
+ $id = 1;
1577
+ $tb->setFV('id', $id);
1578
+ $tb->seek();
1579
+ $this->assertEquals($tb->stat(), 0);
1580
+ $this->assertEquals($tb->getFVstr(FDI_NAME), 'あいうえおかきくこ');
1581
+ $id =3;
1582
+ $tb->setFV('id', $id);
1583
+ $tb->seek();
1584
+ $this->assertEquals($tb->stat(), 0);
1585
+ $this->assertEquals($tb->getFVstr(FDI_NAME), 'あいがあればOKです');
1586
+ $tb->setKeyNum(1);
1587
+ $tb->clearBuffer();
1588
+ $tb->setFV('name', 'A123456');
1589
+ $tb->seek();
1590
+ $this->assertEquals($tb->stat(), 0);
1591
+ $this->assertEquals($tb->getFVstr(FDI_NAME), 'A123456');
1592
+ $tb->setKeyNum(2);
1593
+ $tb->clearBuffer();
1594
+ $tb->setFV('namew', 'A123456');
1595
+ $tb->seek();
1596
+ $this->assertEquals($tb->stat(), 0);
1597
+ $this->assertEquals($tb->getFVstr(FDI_NAMEW), 'A123456');
1598
+ }
1599
+ private function doTestSetStringFilter($tb)
1600
+ {
1601
+ $tb->setKeyNum(0);
1602
+ $tb->clearBuffer();
1603
+
1604
+ $tb->setFilter("name = 'あい*'", 0, 10);
1605
+ $this->assertEquals($tb->stat(), 0);
1606
+ $tb->seekFirst();
1607
+ $this->assertEquals($tb->stat(), 0);
1608
+ $tb->findNext(false);
1609
+ $this->assertEquals($tb->stat(), 0);
1610
+ $this->assertEquals($tb->getFVstr(FDI_NAME), 'あいうえおかきくこ');
1611
+ $this->assertEquals($tb->recordCount(), 2);
1612
+
1613
+ $tb->setFilter("name <> 'あい*'", 0, 10);
1614
+ $this->assertEquals($tb->recordCount(), 3);
1615
+ $tb->clearBuffer();
1616
+ $tb->seekFirst();
1617
+ $this->assertEquals($tb->stat(), 0);
1618
+ $tb->findNext(false);
1619
+ $this->assertEquals($tb->stat(), 0);
1620
+ $this->assertEquals($tb->getFVstr(FDI_NAMEW), 'A123456');
1621
+
1622
+ $tb->findNext();
1623
+ $this->assertEquals($tb->stat(), 0);
1624
+ $this->assertEquals($tb->getFVstr(FDI_NAMEW), 'おはようございます');
1625
+
1626
+ $tb->findNext();
1627
+ $this->assertEquals($tb->stat(), 0);
1628
+ $this->assertEquals($tb->getFVstr(FDI_NAMEW), 'おめでとうございます。');
1629
+
1630
+ $tb->findNext();
1631
+ $this->assertEquals($tb->stat(), transactd::STATUS_EOF);
1632
+
1633
+ $tb->clearBuffer();
1634
+ $tb->seekLast();
1635
+ $tb->findPrev(false);
1636
+ $this->assertEquals($tb->stat(), 0);
1637
+ $this->assertEquals($tb->getFVstr(FDI_NAMEW), 'おめでとうございます。');
1638
+
1639
+ $tb->findPrev();
1640
+ $this->assertEquals($tb->stat(), 0);
1641
+ $this->assertEquals($tb->getFVstr(FDI_NAMEW), 'おはようございます');
1642
+
1643
+ $tb->findPrev(false);
1644
+ $this->assertEquals($tb->stat(), 0);
1645
+ $this->assertEquals($tb->getFVstr(FDI_NAMEW), 'A123456');
1646
+
1647
+ $tb->findPrev();
1648
+ $this->assertEquals($tb->stat(), transactd::STATUS_EOF);
1649
+
1650
+ $tb->setFilter("name = 'あい'", 0, 10);
1651
+ $this->assertEquals($tb->recordCount(), 0);
1652
+
1653
+ $tb->setFilter("name <> ''", 0, 10);
1654
+ $this->assertEquals($tb->recordCount(), 5);
1655
+
1656
+ // testing that setFilter don't change field value
1657
+ $tb->clearBuffer();
1658
+ $tb->setFV('name', 'ABCDE');
1659
+ $tb->setFilter("name = 'あい'", 0, 10);
1660
+ $this->assertEquals($tb->getFVstr(FDI_NAME), 'ABCDE');
1661
+ }
1662
+ private function doTestUpdateStringFilter($tb)
1663
+ {
1664
+ $tb->setKeyNum(0);
1665
+ $tb->clearBuffer();
1666
+ $tb->seekFirst();
1667
+ $this->assertEquals($tb->stat(), 0);
1668
+ $tb->setFV('name', 'ABCDE');
1669
+ $tb->setFV('namew', 'ABCDEW');
1670
+ $tb->update();
1671
+ $this->assertEquals($tb->stat(), 0);
1672
+ $tb->seekNext();
1673
+ $this->assertEquals($tb->stat(), 0);
1674
+
1675
+ $tb->setFV('name', 'ABCDE2');
1676
+ $tb->setFV('namew', 'ABCDEW2');
1677
+ $tb->update();
1678
+ $this->assertEquals($tb->stat(), 0);
1679
+
1680
+ $tb->seekFirst();
1681
+ $this->assertEquals($tb->stat(), 0);
1682
+ $this->assertEquals($tb->getFVstr(FDI_NAME), 'ABCDE');
1683
+ $this->assertEquals($tb->getFVstr(FDI_NAMEW), 'ABCDEW');
1684
+ $tb->seekNext();
1685
+ $this->assertEquals($tb->stat(), 0);
1686
+ $this->assertEquals($tb->getFVstr(FDI_NAME), 'ABCDE2');
1687
+ $this->assertEquals($tb->getFVstr(FDI_NAMEW), 'ABCDEW2');
1688
+ }
1689
+ private function doTestStringFilter($db, $id, $name, $type, $type2)
1690
+ {
1691
+ $this->createTableStringFilter($db, $id, $name, $type, $type2);
1692
+ $tb = $db->openTable($id);
1693
+ $this->assertEquals($db->stat(), 0);
1694
+ $this->doTestInsertStringFilter($tb);
1695
+ $this->doTestReadStringFilter($tb);
1696
+ $this->doTestSetStringFilter($tb);
1697
+ $this->doTestUpdateStringFilter($tb);
1698
+ $tb->close();
1699
+ }
1700
+
1701
+ public function testStringFilter()
1702
+ {
1703
+ $db = $this->getDbObj();
1704
+ $db->create(URL_SF);
1705
+ if ($db->stat() == transactd::STATUS_TABLE_EXISTS_ERROR)
1706
+ {
1707
+ $this->testDropDatabaseStringFilter();
1708
+ $db->create(URL_SF);
1709
+ }
1710
+ $this->assertEquals($db->stat(), 0);
1711
+ $db->open(URL_SF, 0, 0);
1712
+ $this->assertEquals($db->stat(), 0);
1713
+ $this->doTestStringFilter($db, 1, 'zstring', transactd::ft_zstring, transactd::ft_wzstring);
1714
+ if ($this->isUtf16leSupport($db))
1715
+ $this->doTestStringFilter($db, 2, 'myvarchar', transactd::ft_myvarchar, transactd::ft_mywvarchar);
1716
+ else
1717
+ $this->doTestStringFilter($db, 2, 'myvarchar', transactd::ft_myvarchar, transactd::ft_myvarchar);
1718
+ $this->doTestStringFilter($db, 3, 'mytext', transactd::ft_mytext, transactd::ft_myblob);
1719
+ $this->deleteDbObj($db);
1720
+ }
1721
+
1722
+ public function testDropDatabaseStringFilter()
1723
+ {
1724
+ $db = $this->getDbObj();
1725
+ $db->open(URL_SF);
1726
+ $this->assertEquals($db->stat(), 0);
1727
+ $db->drop();
1728
+ $this->assertEquals($db->stat(), 0);
1729
+ $this->deleteDbObj($db);
1730
+ }
1731
+
1732
+ public function testQuery()
1733
+ {
1734
+ $q = new queryBase();
1735
+ $q->queryString("id = 0 and name = 'Abc efg'");
1736
+ $this->assertEquals($q->toString(), "id = '0' and name = 'Abc efg'");
1737
+
1738
+ $q->queryString('');
1739
+ $q->where('id', '=', '0')->andWhere('name', '=', 'Abc efg');
1740
+ $this->assertEquals($q->toString(), "id = '0' and name = 'Abc efg'");
1741
+
1742
+ $q->queryString("select id,name id = 0 AND name = 'Abc&' efg'");
1743
+ $this->assertEquals($q->toString(), "select id,name id = '0' AND name = 'Abc&' efg'");
1744
+
1745
+ $q->queryString('');
1746
+ $q->select('id', 'name')->where('id', '=', '0')->andWhere('name', '=', "Abc' efg");
1747
+ $this->assertEquals($q->toString(), "select id,name id = '0' and name = 'Abc&' efg'");
1748
+
1749
+ $q->queryString("select id,name id = 0 AND name = 'Abc&& efg'");
1750
+ $this->assertEquals($q->toString(), "select id,name id = '0' AND name = 'Abc&& efg'");
1751
+
1752
+ $q->queryString('');
1753
+ $q->select('id', 'name')->where('id', '=', '0')->andWhere('name', '=', 'Abc& efg');
1754
+ $this->assertEquals($q->toString(), "select id,name id = '0' and name = 'Abc&& efg'");
1755
+
1756
+ $q->queryString('*');
1757
+ $this->assertEquals($q->toString(), '*');
1758
+
1759
+ $q->all();
1760
+ $this->assertEquals($q->toString(), '*');
1761
+
1762
+ $q->queryString('Select id,name id = 2');
1763
+ $this->assertEquals($q->toString(), "select id,name id = '2'");
1764
+
1765
+ $q->queryString('');
1766
+ $q->select('id', 'name')->where('id', '=', '2');
1767
+ $this->assertEquals($q->toString(), "select id,name id = '2'");
1768
+
1769
+ $q->queryString('SELECT id,name,fc id = 2');
1770
+ $this->assertEquals($q->toString(), "select id,name,fc id = '2'");
1771
+
1772
+ $q->queryString('');
1773
+ $q->select('id', 'name', 'fc')->where('id', '=', '2');
1774
+ $this->assertEquals($q->toString(), "select id,name,fc id = '2'");
1775
+
1776
+ $q->queryString("select id,name,fc id = 2 and name = '3'");
1777
+ $this->assertEquals($q->toString(), "select id,name,fc id = '2' and name = '3'");
1778
+
1779
+ $q->queryString('');
1780
+ $q->select('id', 'name', 'fc')->where('id', '=', '2')->andWhere('name', '=', '3');
1781
+ $this->assertEquals($q->toString(), "select id,name,fc id = '2' and name = '3'");
1782
+
1783
+ // IN include
1784
+ $q->queryString("select id,name,fc IN '1','2','3'");
1785
+ $this->assertEquals($q->toString(), "select id,name,fc in '1','2','3'");
1786
+
1787
+ $q->queryString('');
1788
+ $q->select('id', 'name', 'fc')->In('1', '2', '3');
1789
+ $this->assertEquals($q->toString(), "select id,name,fc in '1','2','3'");
1790
+
1791
+ $q->queryString("IN '1','2','3'");
1792
+ $this->assertEquals($q->toString(), "in '1','2','3'");
1793
+
1794
+ $q->queryString('IN 1,2,3');
1795
+ $this->assertEquals($q->toString(), "in '1','2','3'");
1796
+
1797
+ $q->queryString('');
1798
+ $q->In('1', '2', '3');
1799
+ $this->assertEquals($q->toString(), "in '1','2','3'");
1800
+
1801
+ //special field name
1802
+ $q->queryString('select = 1');
1803
+ $this->assertEquals($q->toString(), "select = '1'");
1804
+
1805
+ $q->queryString('');
1806
+ $q->where('select', '=', '1');
1807
+ $this->assertEquals($q->toString(), "select = '1'");
1808
+
1809
+ $q->queryString('in <> 1');
1810
+ $this->assertEquals($q->toString(), "in <> '1'");
1811
+
1812
+ $q->queryString('');
1813
+ $q->where('in', '<>', '1');
1814
+ $this->assertEquals($q->toString(), "in <> '1'");
1815
+ }
1816
+
1817
+ /* -----------------------------------------------------
1818
+ transactd convert
1819
+ ----------------------------------------------------- */
1820
+
1821
+ public function testConvert()
1822
+ {
1823
+ if (! $this->isWindows())
1824
+ {
1825
+ $enc_u8 = 'UTF-8';
1826
+
1827
+ $u8 = mb_convert_encoding('123', $enc_u8);
1828
+ $ret = transactd::u8tombc($u8, -1, '', 256);
1829
+ $this->assertEquals($u8, $ret);
1830
+
1831
+ $mbcKanji = [0x8A, 0xBF, 0x8E, 0x9A, 0x00];
1832
+ $u8 = mb_convert_encoding('漢字', $enc_u8);
1833
+ $ret = transactd::u8tombc($u8, -1, '', 256);
1834
+ for ($i = 0; $i < strlen($ret); $i++)
1835
+ $this->assertEquals(hexdec(bin2hex($ret{$i})), $mbcKanji[$i]);
1836
+
1837
+ $mbc = $ret;
1838
+ $u8Kanji = [0xe6 ,0xbc ,0xa2 ,0xe5 ,0xad ,0x97];
1839
+ $ret = transactd::mbctou8($mbc, -1, '', 256);
1840
+ for ($i = 0; $i < strlen($ret); $i++)
1841
+ $this->assertEquals(hexdec(bin2hex($ret{$i})), $u8Kanji[$i]);
1842
+ }
1843
+ }
1844
+
1845
+ }