transactd 3.5.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/common/{tdclc_32_3_5.dll → tdclc_32_3_6.dll} +0 -0
- data/bin/common/tdclc_64_3_6.dll +0 -0
- data/build/swig/ruby/tdclrb_wrap.cpp +12524 -24430
- data/build/swig/tdcl.i +5 -0
- data/build/tdclc/tdclc.cbproj +1 -1
- data/build/tdclc/tdclc.rc +4 -4
- data/build/tdclcpp/tdclcpp.rc +4 -4
- data/build/tdclcpp/tdclcpp_bc.cbproj +1 -1
- data/build/tdclrb/tdclrb.rc +4 -4
- data/source/bzs/db/engine/mysql/database.cpp +210 -184
- data/source/bzs/db/engine/mysql/database.h +276 -105
- data/source/bzs/db/engine/mysql/mysqlInternal.h +37 -0
- data/source/bzs/db/engine/mysql/mysqlProtocol.cpp +1 -0
- data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +4 -4
- data/source/bzs/db/protocol/tdap/client/activeTable.h +1 -1
- data/source/bzs/db/protocol/tdap/client/activeTableImple.h +1 -0
- data/source/bzs/db/protocol/tdap/client/connMgr.cpp +1 -1
- data/source/bzs/db/protocol/tdap/client/database.cpp +7 -4
- data/source/bzs/db/protocol/tdap/client/database.h +6 -1
- data/source/bzs/db/protocol/tdap/client/databaseManager.h +2 -2
- data/source/bzs/db/protocol/tdap/client/dbDef.cpp +21 -9
- data/source/bzs/db/protocol/tdap/client/dbDef.h +1 -1
- data/source/bzs/db/protocol/tdap/client/dllmain.cpp +10 -2
- data/source/bzs/db/protocol/tdap/client/field.cpp +29 -5
- data/source/bzs/db/protocol/tdap/client/field.h +3 -1
- data/source/bzs/db/protocol/tdap/client/fieldNameAlias.cpp +5 -0
- data/source/bzs/db/protocol/tdap/client/fieldNameAlias.h +1 -0
- data/source/bzs/db/protocol/tdap/client/fields.h +9 -2
- data/source/bzs/db/protocol/tdap/client/groupQuery.cpp +8 -4
- data/source/bzs/db/protocol/tdap/client/memRecord.cpp +18 -5
- data/source/bzs/db/protocol/tdap/client/memRecord.h +2 -2
- data/source/bzs/db/protocol/tdap/client/nsTable.cpp +46 -13
- data/source/bzs/db/protocol/tdap/client/nsTable.h +5 -0
- data/source/bzs/db/protocol/tdap/client/recordset.cpp +5 -0
- data/source/bzs/db/protocol/tdap/client/recordset.h +1 -0
- data/source/bzs/db/protocol/tdap/client/recordsetImple.h +6 -2
- data/source/bzs/db/protocol/tdap/client/request.h +46 -38
- data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +2 -3
- data/source/bzs/db/protocol/tdap/client/stringConverter.h +29 -13
- data/source/bzs/db/protocol/tdap/client/table.cpp +60 -10
- data/source/bzs/db/protocol/tdap/client/table.h +4 -1
- data/source/bzs/db/protocol/tdap/client/trdboostapi.h +18 -1
- data/source/bzs/db/protocol/tdap/client/trdormapi.h +10 -4
- data/source/bzs/db/protocol/tdap/fieldComp.h +1 -1
- data/source/bzs/db/protocol/tdap/mysql/characterset.h +1 -0
- data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +11 -4
- data/source/bzs/db/protocol/tdap/mysql/databaseSchema.h +2 -1
- data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +52 -94
- data/source/bzs/db/protocol/tdap/mysql/request.h +20 -13
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +92 -60
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +4 -4
- data/source/bzs/db/protocol/tdap/tdapRequest.h +11 -0
- data/source/bzs/db/protocol/tdap/tdapSchema.cpp +83 -34
- data/source/bzs/db/protocol/tdap/tdapSchema.h +5 -1
- data/source/bzs/db/protocol/tdap/tdapcapi.h +7 -3
- data/source/bzs/example/ormap_c.cpp +2 -2
- data/source/bzs/netsvc/server/serverPipe.cpp +35 -1
- data/source/bzs/test/tdclatl/test_v3.js +48 -1
- data/source/bzs/test/tdclphp/bench.php +89 -76
- data/source/bzs/test/tdclphp/transactd_Test.php +691 -687
- data/source/bzs/test/tdclphp/transactd_blob_Test.php +46 -43
- data/source/bzs/test/tdclphp/transactd_datetime_Test.php +46 -43
- data/source/bzs/test/tdclphp/transactd_kanjischema_Test.php +33 -33
- data/source/bzs/test/tdclphp/transactd_pool_Test.php +29 -25
- data/source/bzs/test/tdclphp/transactd_v3_Test.php +653 -183
- data/source/bzs/test/tdclrb/transactd_datetime_spec.rb +40 -4
- data/source/bzs/test/tdclrb/transactd_fetch_spec.rb +785 -0
- data/source/bzs/test/tdclrb/transactd_pool_spec.rb +21 -1
- data/source/bzs/test/tdclrb/transactd_setget_spec.rb +450 -0
- data/source/bzs/test/tdclrb/transactd_spec.rb +14 -2
- data/source/bzs/test/tdclrb/transactd_v3_spec.rb +1192 -11
- data/source/bzs/test/trdclengn/testField.h +522 -1
- data/source/bzs/test/trdclengn/test_tdclcpp_v3.cpp +37 -1
- data/source/bzs/test/trdclengn/test_trdclengn.cpp +62 -4
- data/source/global/tdclatl/RecordsetQuery.cpp +2 -1
- data/source/global/tdclatl/RecordsetQuery.h +1 -1
- data/source/global/tdclatl/Table.cpp +17 -0
- data/source/global/tdclatl/Table.h +3 -1
- data/source/global/tdclatl/tdclatl.idl +7 -2
- data/transactd.gemspec +1 -1
- metadata +7 -5
- data/bin/common/tdclc_64_3_5.dll +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
/* ================================================================
|
|
3
|
-
Copyright (C) 2015 BizStation Corp All rights reserved.
|
|
3
|
+
Copyright (C) 2015-2016 BizStation Corp All rights reserved.
|
|
4
4
|
|
|
5
5
|
This program is free software; you can redistribute it and/or
|
|
6
6
|
modify it under the terms of the GNU General Public License
|
|
@@ -13,29 +13,147 @@
|
|
|
13
13
|
GNU General Public License for more details.
|
|
14
14
|
|
|
15
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
|
|
16
|
+
along with this program; if not, write to the Free Software
|
|
17
|
+
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
18
18
|
02111-1307, USA.
|
|
19
19
|
================================================================ */
|
|
20
|
-
mb_internal_encoding('UTF-8');
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
require("transactd.php");
|
|
22
|
+
|
|
23
|
+
use BizStation\Transactd\Transactd;
|
|
24
|
+
use BizStation\Transactd\PooledDbManager;
|
|
25
|
+
use BizStation\Transactd\ConnectParams;
|
|
26
|
+
use BizStation\Transactd\Tabledef;
|
|
27
|
+
use BizStation\Transactd\Database;
|
|
28
|
+
use BizStation\Transactd\BtrVersions;
|
|
29
|
+
use BizStation\Transactd\Nstable;
|
|
30
|
+
use BizStation\Transactd\Table;
|
|
31
|
+
use BizStation\Transactd\Query;
|
|
32
|
+
use BizStation\Transactd\RecordsetQuery;
|
|
33
|
+
use BizStation\Transactd\ActiveTable;
|
|
34
|
+
use BizStation\Transactd\Bitset;
|
|
35
|
+
use BizStation\Transactd\ConnMgr;
|
|
36
|
+
use BizStation\Transactd\HaNameResolver;
|
|
24
37
|
|
|
25
38
|
function getHost()
|
|
26
39
|
{
|
|
27
40
|
$host = getenv('TRANSACTD_PHPUNIT_HOST');
|
|
28
|
-
if (strlen($host) == 0)
|
|
29
|
-
{
|
|
41
|
+
if (strlen($host) == 0) {
|
|
30
42
|
$host = '127.0.0.1/';
|
|
31
43
|
}
|
|
32
|
-
if ($host[strlen($host) - 1] != '/')
|
|
33
|
-
{
|
|
44
|
+
if ($host[strlen($host) - 1] != '/') {
|
|
34
45
|
$host = $host . '/';
|
|
35
46
|
}
|
|
36
47
|
return $host;
|
|
37
48
|
}
|
|
38
49
|
|
|
50
|
+
class Number
|
|
51
|
+
{
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
class Phone
|
|
57
|
+
{
|
|
58
|
+
protected $number;
|
|
59
|
+
protected $number2 = null; // Mapped object is null
|
|
60
|
+
public function __construct()
|
|
61
|
+
{
|
|
62
|
+
$this->number = new Number;
|
|
63
|
+
}
|
|
64
|
+
public function __get($name)
|
|
65
|
+
{
|
|
66
|
+
if ($name === 'number2') {
|
|
67
|
+
return $this->number2;
|
|
68
|
+
} elseif ($name === 'number') {
|
|
69
|
+
return $this->number;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
class UserT
|
|
75
|
+
{
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* @var array field name => property name of object. Do not use __get __set magic method
|
|
79
|
+
* The mapped variable is required. If the variable is null then field values are not read or write.
|
|
80
|
+
*/
|
|
81
|
+
static protected $transferMap = ['tel' => ['phone','number']];
|
|
82
|
+
protected $phone;
|
|
83
|
+
protected $phone2 = null;// Mapped object is null
|
|
84
|
+
|
|
85
|
+
public function __construct()
|
|
86
|
+
{
|
|
87
|
+
$this->phone = new Phone;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static public function setTransferMap($type)
|
|
91
|
+
{
|
|
92
|
+
if ($type === 0) {
|
|
93
|
+
self::$transferMap = ['tel' => ['phone','number']];
|
|
94
|
+
} elseif ($type === 1) {
|
|
95
|
+
self::$transferMap = ['tel' => ['phone2','number']];
|
|
96
|
+
} elseif ($type === 2) {
|
|
97
|
+
self::$transferMap = ['tel' => ['phone','number2']];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public function __get($name)
|
|
102
|
+
{
|
|
103
|
+
if ($name === 'phone2') {
|
|
104
|
+
return $this->phone2;
|
|
105
|
+
} elseif ($name === 'phone') {
|
|
106
|
+
return $this->phone;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
class User
|
|
112
|
+
{
|
|
113
|
+
public $a = "";
|
|
114
|
+
public $b = "";
|
|
115
|
+
public $c = "";
|
|
116
|
+
|
|
117
|
+
public function __construct($_a, $_b, $_c)
|
|
118
|
+
{
|
|
119
|
+
$this->a = $_a;
|
|
120
|
+
$this->b = $_b;
|
|
121
|
+
$this->c = $_c;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
class PropertyTest
|
|
126
|
+
{
|
|
127
|
+
private $tmp = 4;
|
|
128
|
+
private $private = 1;
|
|
129
|
+
protected $protected = 2 ;
|
|
130
|
+
public $public = 3;
|
|
131
|
+
private $duplicate = 5;
|
|
132
|
+
private $duplicateTmp = 6;
|
|
133
|
+
|
|
134
|
+
public function __get($var)
|
|
135
|
+
{
|
|
136
|
+
if ($var === 'magic') {
|
|
137
|
+
return $this->tmp;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public function __set($name, $value)
|
|
142
|
+
{
|
|
143
|
+
if ($name === 'magic') {
|
|
144
|
+
$this->tmp = $value;
|
|
145
|
+
} elseif ($name === 'duplicate') {
|
|
146
|
+
$this->duplicateTmp = $value;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public function __isset($name)
|
|
151
|
+
{
|
|
152
|
+
if ($name === 'magic') return true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
39
157
|
define("HOSTNAME", getHost());
|
|
40
158
|
define("USERNAME", getenv('TRANSACTD_PHPUNIT_USER'));
|
|
41
159
|
define("USERPART", strlen(USERNAME) == 0 ? '' : USERNAME . '@');
|
|
@@ -49,7 +167,7 @@ define("BDFNAME", "?dbfile=test.bdf");
|
|
|
49
167
|
define("URI", PROTOCOL . USERPART . HOSTNAME . DBNAME . BDFNAME . PASSPART);
|
|
50
168
|
|
|
51
169
|
// multi thread test if `php_pthreads` exists.
|
|
52
|
-
if(class_exists('Thread')){
|
|
170
|
+
if (class_exists('Thread')) {
|
|
53
171
|
class SeekLessThanWorker extends Thread
|
|
54
172
|
{
|
|
55
173
|
public function __construct()
|
|
@@ -58,10 +176,10 @@ if(class_exists('Thread')){
|
|
|
58
176
|
}
|
|
59
177
|
public function run()
|
|
60
178
|
{
|
|
61
|
-
$dbm = new
|
|
179
|
+
$dbm = new PooledDbManager(new ConnectParams(URI));
|
|
62
180
|
$tb = $dbm->table('user');
|
|
63
181
|
$tb->setFV(FDI_ID, 300000);
|
|
64
|
-
$tb->seekLessThan(false,
|
|
182
|
+
$tb->seekLessThan(false, Transactd::ROW_LOCK_X);
|
|
65
183
|
$this->value = $tb->getFVint(FDI_ID);
|
|
66
184
|
$tb->unlock();
|
|
67
185
|
$tb->close();
|
|
@@ -74,7 +192,7 @@ if(class_exists('Thread')){
|
|
|
74
192
|
}
|
|
75
193
|
}
|
|
76
194
|
|
|
77
|
-
class
|
|
195
|
+
class TransactdTest extends PHPUnit_Framework_TestCase
|
|
78
196
|
{
|
|
79
197
|
private function dropDatabase($db)
|
|
80
198
|
{
|
|
@@ -87,8 +205,7 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
87
205
|
private function createDatabase($db)
|
|
88
206
|
{
|
|
89
207
|
$db->create(URI);
|
|
90
|
-
if ($db->stat() ==
|
|
91
|
-
{
|
|
208
|
+
if ($db->stat() == Transactd::STATUS_TABLE_EXISTS_ERROR) {
|
|
92
209
|
$this->dropDatabase($db);
|
|
93
210
|
$db->create(URI);
|
|
94
211
|
}
|
|
@@ -96,46 +213,45 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
96
213
|
}
|
|
97
214
|
private function openDatabase($db)
|
|
98
215
|
{
|
|
99
|
-
return $db->open(URI,
|
|
216
|
+
return $db->open(URI, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL);
|
|
100
217
|
}
|
|
101
218
|
private function isMySQL5_5($db)
|
|
102
219
|
{
|
|
103
|
-
$vv = new
|
|
220
|
+
$vv = new BtrVersions();
|
|
104
221
|
$db->getBtrVersion($vv);
|
|
105
222
|
$server_ver = $vv->version(1);
|
|
106
|
-
return ($db->stat() == 0) &&
|
|
223
|
+
return ($db->stat() == 0) &&
|
|
107
224
|
((5 == $server_ver->majorVersion) &&
|
|
108
225
|
(5 == $server_ver->minorVersion));
|
|
109
226
|
}
|
|
110
227
|
private function isMariaDBWithGtid($db)
|
|
111
228
|
{
|
|
112
|
-
$vv = new
|
|
229
|
+
$vv = new BtrVersions();
|
|
113
230
|
$db->getBtrVersion($vv);
|
|
114
231
|
$server_ver = $vv->version(1);
|
|
115
|
-
return ($db->stat() == 0) &&
|
|
232
|
+
return ($db->stat() == 0) &&
|
|
116
233
|
(10 == $server_ver->majorVersion) &&
|
|
117
|
-
($server_ver->type ==
|
|
234
|
+
($server_ver->type == Transactd::MYSQL_TYPE_MARIA);
|
|
118
235
|
}
|
|
119
236
|
private function isLegacyTimeFormat($db)
|
|
120
237
|
{
|
|
121
|
-
$vv = new
|
|
238
|
+
$vv = new BtrVersions();
|
|
122
239
|
$db->getBtrVersion($vv);
|
|
123
240
|
$server_ver = $vv->version(1);
|
|
124
|
-
return ($db->stat() == 0) &&
|
|
241
|
+
return ($db->stat() == 0) &&
|
|
125
242
|
((5 == $server_ver->majorVersion) &&
|
|
126
243
|
(5 == $server_ver->minorVersion)) &&
|
|
127
|
-
($server_ver->type ==
|
|
244
|
+
($server_ver->type == Transactd::MYSQL_TYPE_MYSQL);
|
|
128
245
|
}
|
|
129
246
|
private function createUserTable($db)
|
|
130
247
|
{
|
|
131
|
-
|
|
132
248
|
$dbdef = $db->dbDef();
|
|
133
|
-
$this->assertNotEquals($dbdef,
|
|
134
|
-
$td = new
|
|
135
|
-
$td->schemaCodePage =
|
|
249
|
+
$this->assertNotEquals($dbdef, null);
|
|
250
|
+
$td = new Tabledef();
|
|
251
|
+
$td->schemaCodePage = Transactd::CP_UTF8;
|
|
136
252
|
$td->setTableName(TABLENAME);
|
|
137
253
|
$td->setFileName(TABLENAME . '.dat');
|
|
138
|
-
$td->charsetIndex =
|
|
254
|
+
$td->charsetIndex = Transactd::CHARSET_UTF8;
|
|
139
255
|
$tableid = 1;
|
|
140
256
|
$td->id = $tableid;
|
|
141
257
|
$td->pageSize = 2048;
|
|
@@ -145,12 +261,12 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
145
261
|
$fieldIndex = 0;
|
|
146
262
|
$fd = $dbdef->insertField($tableid, $fieldIndex);
|
|
147
263
|
$fd->setName('id');
|
|
148
|
-
$fd->type =
|
|
264
|
+
$fd->type = Transactd::ft_autoinc;
|
|
149
265
|
$fd->len = 4;
|
|
150
266
|
|
|
151
267
|
$fd = $dbdef->insertField($tableid, ++$fieldIndex);
|
|
152
268
|
$fd->setName('名前');
|
|
153
|
-
$fd->type =
|
|
269
|
+
$fd->type = Transactd::ft_myvarchar;
|
|
154
270
|
$fd->len = 2;
|
|
155
271
|
$this->assertEquals($fd->isValidCharNum(), false);
|
|
156
272
|
$fd->SetLenByCharnum(20);
|
|
@@ -161,38 +277,35 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
161
277
|
|
|
162
278
|
$fd = $dbdef->insertField($tableid, ++$fieldIndex);
|
|
163
279
|
$fd->setName('group');
|
|
164
|
-
$fd->type =
|
|
280
|
+
$fd->type = Transactd::ft_integer;
|
|
165
281
|
$fd->len = 4;
|
|
166
282
|
$fd->setNullable(true, false);
|
|
167
283
|
$fd->setDefaultValue(10);
|
|
168
284
|
|
|
169
285
|
$fd = $dbdef->insertField($tableid, ++$fieldIndex);
|
|
170
286
|
$fd->setName('tel');
|
|
171
|
-
$fd->type =
|
|
287
|
+
$fd->type = Transactd::ft_myvarchar;
|
|
172
288
|
$fd->len = 4;
|
|
173
289
|
$fd->setLenByCharnum(21);
|
|
174
290
|
$fd->setNullable(true);
|
|
175
291
|
|
|
176
292
|
$fd = $dbdef->insertField($tableid, ++$fieldIndex);
|
|
177
293
|
$fd->setName('update_datetime');
|
|
178
|
-
$fd->type =
|
|
294
|
+
$fd->type = Transactd::ft_mytimestamp;
|
|
179
295
|
$fd->len = 7;
|
|
180
|
-
$fd->setDefaultValue(
|
|
296
|
+
$fd->setDefaultValue(Transactd::DFV_TIMESTAMP_DEFAULT);
|
|
181
297
|
$fd->setTimeStampOnUpdate(true);
|
|
182
298
|
$this->assertEquals($fd->isTimeStampOnUpdate(), true);
|
|
183
299
|
|
|
184
300
|
$fd = $dbdef->insertField($tableid, ++$fieldIndex);
|
|
185
301
|
$fd->setName('create_datetime');
|
|
186
|
-
if ($this->isMySQL5_5($db))
|
|
187
|
-
|
|
188
|
-
$fd->type = bz\transactd::ft_mydatetime;
|
|
302
|
+
if ($this->isMySQL5_5($db)) {
|
|
303
|
+
$fd->type = Transactd::ft_mydatetime;
|
|
189
304
|
$fd->len = 8;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
{
|
|
193
|
-
$fd->type = bz\transactd::ft_mytimestamp;
|
|
305
|
+
} else {
|
|
306
|
+
$fd->type = Transactd::ft_mytimestamp;
|
|
194
307
|
$fd->len = 4;
|
|
195
|
-
$fd->setDefaultValue(
|
|
308
|
+
$fd->setDefaultValue(Transactd::DFV_TIMESTAMP_DEFAULT);
|
|
196
309
|
}
|
|
197
310
|
$fd->setTimeStampOnUpdate(false);
|
|
198
311
|
$this->assertEquals($fd->isTimeStampOnUpdate(), false);
|
|
@@ -222,13 +335,13 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
222
335
|
{
|
|
223
336
|
$this->openDatabase($db);
|
|
224
337
|
$dbdef = $db->dbDef();
|
|
225
|
-
$this->assertNotEquals($dbdef,
|
|
226
|
-
$td = new
|
|
338
|
+
$this->assertNotEquals($dbdef, null);
|
|
339
|
+
$td = new Tabledef();
|
|
227
340
|
|
|
228
|
-
$td->schemaCodePage =
|
|
341
|
+
$td->schemaCodePage = Transactd::CP_UTF8;
|
|
229
342
|
$td->setTableName("extention");
|
|
230
343
|
$td->setFileName("extention");
|
|
231
|
-
$td->charsetIndex =
|
|
344
|
+
$td->charsetIndex = Transactd::CHARSET_UTF8;
|
|
232
345
|
$tableid = 3;
|
|
233
346
|
$td->id = $tableid;
|
|
234
347
|
$dbdef->insertTable($td);
|
|
@@ -237,19 +350,19 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
237
350
|
$fieldIndex = 0;
|
|
238
351
|
$fd = $dbdef->insertField($tableid, $fieldIndex);
|
|
239
352
|
$fd->setName('id');
|
|
240
|
-
$fd->type =
|
|
353
|
+
$fd->type = Transactd::ft_integer;
|
|
241
354
|
$fd->len = 4;
|
|
242
355
|
|
|
243
356
|
$fd = $dbdef->insertField($tableid, ++$fieldIndex);
|
|
244
357
|
$fd->setName('comment');
|
|
245
|
-
$fd->type =
|
|
358
|
+
$fd->type = Transactd::ft_myvarchar;
|
|
246
359
|
$fd->SetLenByCharnum(60);
|
|
247
360
|
$fd->setNullable(true);
|
|
248
361
|
$this->assertEquals($fd->isDefaultNull(), true);
|
|
249
362
|
|
|
250
363
|
$fd = $dbdef->insertField($tableid, ++$fieldIndex);
|
|
251
364
|
$fd->setName('bits');
|
|
252
|
-
$fd->type =
|
|
365
|
+
$fd->type = Transactd::ft_integer;
|
|
253
366
|
$fd->len = 8;
|
|
254
367
|
$this->assertEquals($fd->isDefaultNull(), false);
|
|
255
368
|
|
|
@@ -268,15 +381,13 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
268
381
|
|
|
269
382
|
private function insertData($db)
|
|
270
383
|
{
|
|
271
|
-
$tb = $db->openTable("user",
|
|
272
|
-
$tb3 = $db->openTable("extention",
|
|
384
|
+
$tb = $db->openTable("user", Transactd::TD_OPEN_NORMAL);
|
|
385
|
+
$tb3 = $db->openTable("extention", Transactd::TD_OPEN_NORMAL);
|
|
273
386
|
|
|
274
|
-
try
|
|
275
|
-
{
|
|
387
|
+
try {
|
|
276
388
|
$db->beginTrn();
|
|
277
389
|
$tb->clearBuffer();
|
|
278
|
-
for ($i= 1;$i<= 1000;++$i)
|
|
279
|
-
{
|
|
390
|
+
for ($i= 1;$i<= 1000;++$i) {
|
|
280
391
|
$tb->setFV(0, $i);
|
|
281
392
|
$tb->setFV(1, $i." user");
|
|
282
393
|
$tb->setFV(2, (($i-1) % 5)+1);
|
|
@@ -284,16 +395,13 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
284
395
|
}
|
|
285
396
|
|
|
286
397
|
$tb3->clearBuffer();
|
|
287
|
-
for ($i= 1;$i<= 1000;++$i)
|
|
288
|
-
{
|
|
398
|
+
for ($i= 1;$i<= 1000;++$i) {
|
|
289
399
|
$tb3->setFV(0, $i);
|
|
290
400
|
$tb3->setFV(1, $i." comment");
|
|
291
401
|
$tb3->insert();
|
|
292
402
|
}
|
|
293
403
|
$db->endTrn();
|
|
294
|
-
}
|
|
295
|
-
catch(Exception $e)
|
|
296
|
-
{
|
|
404
|
+
} catch (Exception $e) {
|
|
297
405
|
$db->abortTrn();
|
|
298
406
|
$this->assertEquals(true, false);
|
|
299
407
|
}
|
|
@@ -312,7 +420,7 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
312
420
|
|
|
313
421
|
public function test()
|
|
314
422
|
{
|
|
315
|
-
$db = new
|
|
423
|
+
$db = new Database();
|
|
316
424
|
|
|
317
425
|
$this->createDatabase($db);
|
|
318
426
|
$this->openDatabase($db);
|
|
@@ -326,36 +434,43 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
326
434
|
$db->setAutoSchemaUseNullkey(false);
|
|
327
435
|
$this->assertEquals($db->autoSchemaUseNullkey(), false);
|
|
328
436
|
|
|
329
|
-
$this->assertEquals($db::compatibleMode(),
|
|
330
|
-
|
|
331
|
-
bz\database::setCompatibleMode(bz\database::CMP_MODE_OLD_NULL);
|
|
332
|
-
$this->assertEquals(bz\database::compatibleMode(), bz\database::CMP_MODE_OLD_NULL);
|
|
437
|
+
$this->assertEquals($db::compatibleMode(), Database::CMP_MODE_MYSQL_NULL);
|
|
333
438
|
|
|
334
|
-
|
|
335
|
-
$this->assertEquals(
|
|
439
|
+
Database::setCompatibleMode(Database::CMP_MODE_OLD_NULL);
|
|
440
|
+
$this->assertEquals(Database::compatibleMode(), Database::CMP_MODE_OLD_NULL);
|
|
441
|
+
|
|
442
|
+
Database::setCompatibleMode(Database::CMP_MODE_BINFD_DEFAULT_STR);
|
|
443
|
+
$this->assertEquals(Database::compatibleMode(), Database::CMP_MODE_BINFD_DEFAULT_STR);
|
|
336
444
|
|
|
445
|
+
Database::setCompatibleMode(Database::CMP_MODE_MYSQL_NULL);
|
|
446
|
+
$this->assertEquals(Database::compatibleMode(), Database::CMP_MODE_MYSQL_NULL);
|
|
447
|
+
|
|
337
448
|
$dbdef = $db->dbDef();
|
|
338
449
|
$td = $dbdef->tableDefs(1);
|
|
339
450
|
//isMysqlNullMode //size()
|
|
340
|
-
$this->assertEquals($td->isMysqlNullMode()
|
|
451
|
+
$this->assertEquals($td->isMysqlNullMode(), true);
|
|
341
452
|
|
|
342
453
|
//recordlen()
|
|
343
454
|
$len = 145;
|
|
344
|
-
if ($mysql_5_5)
|
|
345
|
-
|
|
346
|
-
|
|
455
|
+
if ($mysql_5_5) {
|
|
456
|
+
$len += 4;
|
|
457
|
+
}
|
|
458
|
+
if ($this->isLegacyTimeFormat($db)) {
|
|
459
|
+
$len -= 3;
|
|
460
|
+
}
|
|
461
|
+
$this->assertEquals($td->recordlen(), $len);
|
|
347
462
|
|
|
348
463
|
//size()
|
|
349
|
-
$this->assertEquals($td->size()
|
|
464
|
+
$this->assertEquals($td->size(), 1184);
|
|
350
465
|
|
|
351
466
|
//InUse
|
|
352
|
-
$this->assertEquals($td->inUse()
|
|
467
|
+
$this->assertEquals($td->inUse(), 0);
|
|
353
468
|
|
|
354
469
|
//nullfields
|
|
355
470
|
$this->assertEquals($td->nullfields(), 2);
|
|
356
471
|
|
|
357
472
|
//fieldNumByName
|
|
358
|
-
$this->assertEquals($td->fieldNumByName("tel")
|
|
473
|
+
$this->assertEquals($td->fieldNumByName("tel"), 3);
|
|
359
474
|
|
|
360
475
|
//default value
|
|
361
476
|
$fd = $td->fieldDef(1);
|
|
@@ -365,7 +480,7 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
365
480
|
$fd = $td->fieldDef(3);
|
|
366
481
|
$this->assertEquals($fd->isDefaultNull(), true);
|
|
367
482
|
$fd = $td->fieldDef(4);
|
|
368
|
-
$this->assertEquals($fd->defaultValue(),
|
|
483
|
+
$this->assertEquals($fd->defaultValue(), Transactd::DFV_TIMESTAMP_DEFAULT);
|
|
369
484
|
$this->assertEquals($fd->isTimeStampOnUpdate(), true);
|
|
370
485
|
$fd = $td->fieldDef(5);
|
|
371
486
|
$this->assertEquals($fd->isTimeStampOnUpdate(), false);
|
|
@@ -376,7 +491,7 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
376
491
|
|
|
377
492
|
$fd->setLenByCharnum(19);
|
|
378
493
|
$this->assertNotEquals($len, $fd->len);
|
|
379
|
-
$dbdef->synchronizeSeverSchema(1);
|
|
494
|
+
$dbdef->synchronizeSeverSchema(1);
|
|
380
495
|
$td = $dbdef->tableDefs(1);
|
|
381
496
|
$fd = $td->fieldDef(1);
|
|
382
497
|
$this->assertEquals($len, $fd->len);
|
|
@@ -400,15 +515,15 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
400
515
|
// getSqlStringForCreateTable
|
|
401
516
|
$sql = $db->getSqlStringForCreateTable("extention");
|
|
402
517
|
$this->assertEquals($db->stat(), 0);
|
|
403
|
-
$this->assertEquals($sql, 'CREATE TABLE `extention` (`id` INT NOT NULL ,`comment` VARCHAR(60) binary NULL DEFAULT NULL,`bits` BIGINT NOT NULL ,
|
|
518
|
+
$this->assertEquals($sql, 'CREATE TABLE `extention` (`id` INT NOT NULL ,`comment` VARCHAR(60) binary NULL DEFAULT NULL,`bits` BIGINT NOT NULL , PRIMARY KEY(`id`)) ENGINE=InnoDB default charset=utf8');
|
|
404
519
|
|
|
405
520
|
// setValidationTarget(bool isMariadb, uchar_td srvMinorVersion)
|
|
406
521
|
$td = $dbdef->tableDefs(1);
|
|
407
522
|
$td->setValidationTarget(true, 0);
|
|
408
523
|
|
|
409
524
|
|
|
410
|
-
$q = new
|
|
411
|
-
$atu = new
|
|
525
|
+
$q = new Query();
|
|
526
|
+
$atu = new ActiveTable($db, "user", Transactd::TD_OPEN_NORMAL);
|
|
412
527
|
|
|
413
528
|
// segmentsSizeForInValue
|
|
414
529
|
$this->assertEquals($q->segmentsForInValue(3)->getJoinKeySize(), 3);
|
|
@@ -423,12 +538,13 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
423
538
|
$this->assertEquals($tb1->getFVNull(2), false);
|
|
424
539
|
$atu->index(1)->keyValue(null);
|
|
425
540
|
$this->assertEquals($tb1->getFVNull(2), true);
|
|
426
|
-
|
|
541
|
+
|
|
427
542
|
// isNull setNull
|
|
428
543
|
$atu->alias("名前", "name");
|
|
429
544
|
|
|
430
545
|
$q->select("id", "name", "group", "tel")->where("id", "<=", 10);
|
|
431
546
|
$rs = $atu->index(0)->keyValue(1)->read($q);
|
|
547
|
+
$rs->fetchMode = Transactd::FETCH_RECORD_INTO;
|
|
432
548
|
$this->assertEquals($rs->count(), 10);
|
|
433
549
|
$rec = $rs->first();
|
|
434
550
|
$this->assertEquals($rec[3]->isNull(), true);
|
|
@@ -437,9 +553,9 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
437
553
|
|
|
438
554
|
//Join null
|
|
439
555
|
$q->reset();
|
|
440
|
-
$ate = new
|
|
556
|
+
$ate = new ActiveTable($db, "extention");
|
|
441
557
|
$last = $ate->index(0)->join($rs, $q->select("comment")
|
|
442
|
-
->optimize(
|
|
558
|
+
->optimize(Query::joinHasOneOrHasMany), "id")->reverse()->first();
|
|
443
559
|
$this->assertEquals($rs->count(), 10);
|
|
444
560
|
$this->assertEquals($last["id"]->i(), 10);
|
|
445
561
|
$this->assertEquals($last["id"]->i64(), 10);
|
|
@@ -509,7 +625,7 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
509
625
|
$this->assertEquals($rs->count(), 1000);
|
|
510
626
|
|
|
511
627
|
// recordset whenIsNull
|
|
512
|
-
$rq = new
|
|
628
|
+
$rq = new RecordsetQuery();
|
|
513
629
|
$rq->whenIsNull("tel");
|
|
514
630
|
$rs2 = clone $rs;
|
|
515
631
|
$rs2 = $rs2->matchBy($rq);
|
|
@@ -570,7 +686,7 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
570
686
|
$tb->clearBuffer();
|
|
571
687
|
$this->assertEquals($tb->getFVNull(3), true);
|
|
572
688
|
|
|
573
|
-
$tb->clearBuffer(
|
|
689
|
+
$tb->clearBuffer(Table::clearNull);
|
|
574
690
|
$this->assertEquals($tb->getFVNull(3), false);
|
|
575
691
|
|
|
576
692
|
// table NULL
|
|
@@ -591,38 +707,39 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
591
707
|
$this->assertEquals($tb->getFVNull("tel"), true);
|
|
592
708
|
|
|
593
709
|
//timestamp format
|
|
594
|
-
$date =
|
|
710
|
+
$date = Transactd::btrdtoa(Transactd::getNowDate(), true);
|
|
595
711
|
$this->assertEquals(mb_substr($tb->getFVstr("update_datetime"), 0, 10), $date);
|
|
596
|
-
if ($mysql_5_5 == false)
|
|
597
|
-
|
|
712
|
+
if ($mysql_5_5 == false) {
|
|
713
|
+
$this->assertEquals(mb_substr($tb->getFVstr("create_datetime"), 0, 10), $date);
|
|
714
|
+
}
|
|
598
715
|
|
|
599
716
|
// setTimestampMode
|
|
600
|
-
$tb->setTimestampMode(
|
|
601
|
-
$tb->setTimestampMode(
|
|
717
|
+
$tb->setTimestampMode(Transactd::TIMESTAMP_VALUE_CONTROL);
|
|
718
|
+
$tb->setTimestampMode(Transactd::TIMESTAMP_ALWAYS);
|
|
602
719
|
|
|
603
720
|
//isMysqlNullMode
|
|
604
721
|
$this->assertEquals($tb->tableDef()->isMysqlNullMode(), true);
|
|
605
|
-
$this->assertEquals($td->inUse()
|
|
722
|
+
$this->assertEquals($td->inUse(), 2);
|
|
606
723
|
|
|
607
724
|
unset($atu);
|
|
608
|
-
$this->assertEquals($td->inUse()
|
|
725
|
+
$this->assertEquals($td->inUse(), 1);
|
|
609
726
|
$tb->release();
|
|
610
|
-
$this->assertEquals($td->inUse()
|
|
727
|
+
$this->assertEquals($td->inUse(), 0);
|
|
611
728
|
|
|
612
729
|
$db->close();
|
|
613
730
|
}
|
|
614
731
|
|
|
615
|
-
public function
|
|
732
|
+
public function testBit()
|
|
616
733
|
{
|
|
617
|
-
$db = new
|
|
734
|
+
$db = new Database();
|
|
618
735
|
$this->openDatabase($db);
|
|
619
|
-
$tb = $db->openTable("extention");
|
|
736
|
+
$tb = $db->openTable("extention", Transactd::TD_OPEN_NORMAL);
|
|
620
737
|
$this->assertEquals($db->stat(), 0);
|
|
621
738
|
$tb->setKeyNum(0);
|
|
622
739
|
$tb->setFV('id', 1);
|
|
623
740
|
$tb->seek();
|
|
624
741
|
$this->assertEquals($tb->stat(), 0);
|
|
625
|
-
$bits = new
|
|
742
|
+
$bits = new Bitset();
|
|
626
743
|
/*
|
|
627
744
|
$bits->set(63, true);
|
|
628
745
|
$bits->set(2, true);
|
|
@@ -636,10 +753,11 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
636
753
|
$tb->update();
|
|
637
754
|
$this->assertEquals($tb->stat(), 0);
|
|
638
755
|
|
|
639
|
-
$q = new
|
|
640
|
-
$at = new
|
|
756
|
+
$q = new Query();
|
|
757
|
+
$at = new ActiveTable($db, "extention", Transactd::TD_OPEN_NORMAL);
|
|
641
758
|
$q->where('id', '=', 1);
|
|
642
759
|
$rs = $at->index(0)->keyValue(1)->read($q);
|
|
760
|
+
$rs->fetchMode = Transactd::FETCH_RECORD_INTO;
|
|
643
761
|
$this->assertEquals($rs->size(), 1);
|
|
644
762
|
$bits = $rs[0]['bits']->getBits();
|
|
645
763
|
|
|
@@ -677,14 +795,14 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
677
795
|
$this->assertEquals($tb->stat(), 0);
|
|
678
796
|
$bits = $tb->getFVbits('bits');
|
|
679
797
|
|
|
680
|
-
$this->assertEquals($bits->get(
|
|
681
|
-
$this->assertEquals($bits->get(
|
|
682
|
-
$this->assertEquals($bits->get(
|
|
683
|
-
$this->assertEquals($bits->get(
|
|
684
|
-
$this->assertEquals($bits->get(
|
|
685
|
-
$this->assertEquals($bits->get(
|
|
686
|
-
$this->assertEquals($bits->get(
|
|
687
|
-
$this->assertEquals($bits->get(
|
|
798
|
+
$this->assertEquals($bits->get(63), false);
|
|
799
|
+
$this->assertEquals($bits->get(2), true);
|
|
800
|
+
$this->assertEquals($bits->get(5), true);
|
|
801
|
+
$this->assertEquals($bits->get(12), true);
|
|
802
|
+
$this->assertEquals($bits->get(0), true);
|
|
803
|
+
$this->assertEquals($bits->get(62), true);
|
|
804
|
+
$this->assertEquals($bits->get(11), false);
|
|
805
|
+
$this->assertEquals($bits->get(13), false);
|
|
688
806
|
|
|
689
807
|
$this->assertEquals($bits[63], false);
|
|
690
808
|
$this->assertEquals($bits[2], true);
|
|
@@ -699,10 +817,10 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
699
817
|
$db->close();
|
|
700
818
|
}
|
|
701
819
|
|
|
702
|
-
public function
|
|
820
|
+
public function testBitset()
|
|
703
821
|
{
|
|
704
|
-
$bits1 = new
|
|
705
|
-
$bits2 = new
|
|
822
|
+
$bits1 = new Bitset();
|
|
823
|
+
$bits2 = new Bitset();
|
|
706
824
|
$bits1[0] = true;
|
|
707
825
|
$bits1[1] = true;
|
|
708
826
|
$bits1[63] = true;
|
|
@@ -719,18 +837,18 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
719
837
|
$this->assertEquals($bits2->contains($bits1, $all), true);
|
|
720
838
|
}
|
|
721
839
|
|
|
722
|
-
public function
|
|
840
|
+
public function testDecimal()
|
|
723
841
|
{
|
|
724
|
-
$db = new
|
|
842
|
+
$db = new Database();
|
|
725
843
|
$this->openDatabase($db);
|
|
726
844
|
$dbdef = $db->dbDef();
|
|
727
|
-
$this->assertNotEquals($dbdef,
|
|
728
|
-
$td = new
|
|
845
|
+
$this->assertNotEquals($dbdef, null);
|
|
846
|
+
$td = new Tabledef();
|
|
729
847
|
|
|
730
|
-
$td->schemaCodePage =
|
|
848
|
+
$td->schemaCodePage = Transactd::CP_UTF8;
|
|
731
849
|
$td->setTableName("decimal");
|
|
732
850
|
$td->setFileName("decimal");
|
|
733
|
-
$td->charsetIndex =
|
|
851
|
+
$td->charsetIndex = Transactd::CHARSET_UTF8;
|
|
734
852
|
$tableid = 10;
|
|
735
853
|
$td->id = $tableid;
|
|
736
854
|
$dbdef->insertTable($td);
|
|
@@ -739,48 +857,47 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
739
857
|
$fieldIndex = 0;
|
|
740
858
|
$fd = $dbdef->insertField($tableid, $fieldIndex);
|
|
741
859
|
$fd->setName('id');
|
|
742
|
-
$fd->type =
|
|
860
|
+
$fd->type = Transactd::ft_mydecimal;
|
|
743
861
|
$fd->setDecimalDigits(65, 30);
|
|
744
862
|
$this->assertEquals($fd->digits, 65);
|
|
745
863
|
$this->assertEquals($fd->decimals, 30);
|
|
746
864
|
$this->assertEquals($fd->isIntegerType(), false);
|
|
747
865
|
$this->assertEquals($fd->isNumericType(), true);
|
|
748
866
|
|
|
749
|
-
$bits1 = new
|
|
867
|
+
$bits1 = new Bitset();
|
|
750
868
|
$bits1[2] = true;
|
|
751
|
-
$fd->type =
|
|
869
|
+
$fd->type = Transactd::ft_integer;
|
|
752
870
|
$fd->len = 4;
|
|
753
871
|
$fd->setDefaultValue($bits1);
|
|
754
872
|
$this->assertEquals($fd->defaultValue(), '4');
|
|
755
873
|
$db->close();
|
|
756
874
|
}
|
|
757
|
-
public function
|
|
875
|
+
public function testSnapshot()
|
|
758
876
|
{
|
|
759
|
-
$db = new
|
|
877
|
+
$db = new Database();
|
|
760
878
|
$this->openDatabase($db);
|
|
761
|
-
$bpos = $db->beginSnapshot(
|
|
762
|
-
if ($this->isMariaDBWithGtid($db))
|
|
763
|
-
|
|
764
|
-
else
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
$this->assertEquals($ret , true);
|
|
879
|
+
$bpos = $db->beginSnapshot(Transactd::CONSISTENT_READ_WITH_BINLOG_POS);
|
|
880
|
+
if ($this->isMariaDBWithGtid($db)) {
|
|
881
|
+
$this->assertEquals($bpos->type, Transactd::REPL_POSTYPE_MARIA_GTID);
|
|
882
|
+
} else {
|
|
883
|
+
$ret = ($bpos->type == Transactd::REPL_POSTYPE_POS) || ($bpos->type == Transactd::REPL_POSTYPE_GTID);
|
|
884
|
+
$this->assertEquals($ret, true);
|
|
768
885
|
}
|
|
769
886
|
$this->assertNotEquals($bpos->pos, 0);
|
|
770
887
|
$this->assertNotEquals($bpos->filename, "");
|
|
771
888
|
echo PHP_EOL.'binlog pos = '.$bpos->filename.':'.$bpos->pos.PHP_EOL;
|
|
772
|
-
echo 'gtid (set)= '.$bpos->gtid.PHP_EOL
|
|
773
|
-
|
|
889
|
+
echo 'gtid (set)= '.$bpos->gtid.PHP_EOL;
|
|
890
|
+
|
|
774
891
|
//setGtid
|
|
775
892
|
$bpos->gtid = "ABCD";
|
|
776
|
-
$this->assertEquals($bpos->gtid
|
|
893
|
+
$this->assertEquals($bpos->gtid, "ABCD");
|
|
777
894
|
|
|
778
895
|
$db->endSnapshot();
|
|
779
896
|
$db->close();
|
|
780
897
|
}
|
|
781
|
-
public function
|
|
898
|
+
public function testGetSql()
|
|
782
899
|
{
|
|
783
|
-
$db = new
|
|
900
|
+
$db = new Database();
|
|
784
901
|
$this->openDatabase($db);
|
|
785
902
|
$db->execSql("create view idlessthan5 as select * from user where id < 5");
|
|
786
903
|
$view = $db->getCreateViewSql("idlessthan5");
|
|
@@ -796,9 +913,9 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
796
913
|
$tb->close();
|
|
797
914
|
$db->close();
|
|
798
915
|
}
|
|
799
|
-
public function
|
|
916
|
+
public function testCreateAssociate()
|
|
800
917
|
{
|
|
801
|
-
$db = new
|
|
918
|
+
$db = new Database();
|
|
802
919
|
$this->openDatabase($db);
|
|
803
920
|
$dba = $db->createAssociate();
|
|
804
921
|
$this->assertEquals($db->stat(), 0);
|
|
@@ -806,16 +923,16 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
806
923
|
$dba->close();
|
|
807
924
|
$db->close();
|
|
808
925
|
}
|
|
809
|
-
public function
|
|
926
|
+
public function testConnMgr()
|
|
810
927
|
{
|
|
811
928
|
// other database connection
|
|
812
|
-
$db_other = new
|
|
929
|
+
$db_other = new Database();
|
|
813
930
|
$this->openDatabase($db_other);
|
|
814
931
|
$tb_other = $db_other->openTable("user");
|
|
815
932
|
$this->assertEquals($db_other->stat(), 0);
|
|
816
933
|
// connMgr connection
|
|
817
|
-
$db = new
|
|
818
|
-
$mgr = new
|
|
934
|
+
$db = new Database();
|
|
935
|
+
$mgr = new ConnMgr($db);
|
|
819
936
|
$mgr->connect($db_other->uri());
|
|
820
937
|
$this->assertEquals($mgr->stat(), 0);
|
|
821
938
|
// connections
|
|
@@ -861,102 +978,455 @@ class transactdTest extends PHPUnit_Framework_TestCase
|
|
|
861
978
|
//sysvar
|
|
862
979
|
$recs = $mgr->sysvars();
|
|
863
980
|
$this->assertEquals($mgr->stat(), 0);
|
|
864
|
-
$this->assertEquals(
|
|
981
|
+
$this->assertEquals(ConnMgr::sysvarName(0), "database_version");
|
|
865
982
|
//statusvar
|
|
866
983
|
$recs = $mgr->statusvars();
|
|
867
984
|
$this->assertEquals($mgr->stat(), 0);
|
|
868
|
-
$this->assertEquals(
|
|
985
|
+
$this->assertEquals(ConnMgr::statusvarName(0), "tcp_connections");
|
|
869
986
|
//slaveStatus
|
|
870
987
|
$recs = $mgr->slaveStatus("");
|
|
871
988
|
$this->assertEquals($mgr->stat(), 0);
|
|
872
989
|
$this->assertEquals($mgr->slaveStatusName(0), "Slave_IO_State");
|
|
873
|
-
for ($i = 0; $i < $recs->size(); $i++)
|
|
874
|
-
{
|
|
990
|
+
for ($i = 0; $i < $recs->size(); $i++) {
|
|
875
991
|
echo(PHP_EOL . $mgr->slaveStatusName($i) . "\t:" . $recs[$i]->value);
|
|
876
992
|
}
|
|
877
993
|
|
|
878
994
|
//extendedvars
|
|
879
995
|
$recs = $mgr->extendedvars();
|
|
880
996
|
$this->assertEquals($recs->size(), 4);
|
|
881
|
-
$this->assertEquals($mgr->extendedVarName(0)
|
|
997
|
+
$this->assertEquals($mgr->extendedVarName(0), "MySQL_Gtid_Mode");
|
|
882
998
|
|
|
883
999
|
// record port
|
|
884
|
-
$this->assertEquals($recs[0]->port
|
|
1000
|
+
$this->assertEquals($recs[0]->port, 0);
|
|
885
1001
|
|
|
886
1002
|
//slaveHosts
|
|
887
1003
|
$recs = $mgr->slaveHosts();
|
|
888
|
-
$this->assertEquals($mgr->stat()
|
|
1004
|
+
$this->assertEquals($mgr->stat(), 0);
|
|
889
1005
|
//channels
|
|
890
1006
|
$recs = $mgr->channels();
|
|
891
|
-
$this->assertEquals($mgr->stat()
|
|
1007
|
+
$this->assertEquals($mgr->stat(), 0);
|
|
892
1008
|
//haLock
|
|
893
1009
|
$ret = $mgr->haLock();
|
|
894
|
-
$this->assertEquals($mgr->stat()
|
|
895
|
-
$this->assertEquals($ret
|
|
1010
|
+
$this->assertEquals($mgr->stat(), 0);
|
|
1011
|
+
$this->assertEquals($ret, true);
|
|
896
1012
|
//haUnlock
|
|
897
1013
|
$mgr->haUnlock();
|
|
898
|
-
$this->assertEquals($mgr->stat()
|
|
1014
|
+
$this->assertEquals($mgr->stat(), 0);
|
|
899
1015
|
//setRole
|
|
900
1016
|
$ret = $mgr->setRole(0);
|
|
901
|
-
$this->assertEquals($mgr->stat()
|
|
902
|
-
$this->assertEquals($ret
|
|
1017
|
+
$this->assertEquals($mgr->stat(), 0);
|
|
1018
|
+
$this->assertEquals($ret, true);
|
|
903
1019
|
$ret = $mgr->setRole(1);
|
|
904
|
-
$this->assertEquals($mgr->stat()
|
|
905
|
-
$this->assertEquals($ret
|
|
1020
|
+
$this->assertEquals($mgr->stat(), 0);
|
|
1021
|
+
$this->assertEquals($ret, true);
|
|
906
1022
|
//setEnableFailover
|
|
907
1023
|
$ret = $mgr->setEnableFailover(false);
|
|
908
|
-
$this->assertEquals($mgr->stat()
|
|
909
|
-
$this->assertEquals($ret
|
|
1024
|
+
$this->assertEquals($mgr->stat(), 0);
|
|
1025
|
+
$this->assertEquals($ret, true);
|
|
910
1026
|
$ret = $mgr->setEnableFailover(true);
|
|
911
|
-
$this->assertEquals($mgr->stat()
|
|
912
|
-
$this->assertEquals($ret
|
|
913
|
-
$this->assertEquals($mgr->isOpen()
|
|
1027
|
+
$this->assertEquals($mgr->stat(), 0);
|
|
1028
|
+
$this->assertEquals($ret, true);
|
|
1029
|
+
$this->assertEquals($mgr->isOpen(), true);
|
|
914
1030
|
//enableAutoReconnect
|
|
915
1031
|
$this->assertEquals($db->enableAutoReconnect(), false);
|
|
916
1032
|
$db->setenableAutoReconnect(true);
|
|
917
1033
|
$this->assertEquals($db->enableAutoReconnect(), true);
|
|
918
1034
|
$db->setenableAutoReconnect(false);
|
|
919
1035
|
$mgr->disconnect();
|
|
920
|
-
$this->assertEquals($mgr->stat()
|
|
1036
|
+
$this->assertEquals($mgr->stat(), 0);
|
|
921
1037
|
$this->assertEquals($mgr->isOpen(), false);
|
|
922
1038
|
//haNameReslover
|
|
923
1039
|
$host = "localhost";
|
|
924
1040
|
$user = "root";
|
|
925
1041
|
$pwd = "";
|
|
926
|
-
$ret =
|
|
927
|
-
$this->assertEquals($ret
|
|
1042
|
+
$ret = HaNameResolver::start("master123", "slave1, slave2", $host, 0, $user, $pwd);
|
|
1043
|
+
$this->assertEquals($ret, 1);
|
|
928
1044
|
//portMap
|
|
929
|
-
|
|
930
|
-
|
|
1045
|
+
HaNameResolver::addPortMap(3307, 8611);
|
|
1046
|
+
HaNameResolver::clearPortMap();
|
|
931
1047
|
//master slave name
|
|
932
|
-
$this->assertEquals(
|
|
933
|
-
$this->assertEquals(
|
|
1048
|
+
$this->assertEquals(HaNameResolver::master(), $host);
|
|
1049
|
+
$this->assertEquals(HaNameResolver::slave(), "-");
|
|
934
1050
|
//connect by master roll
|
|
935
1051
|
$mgr->connect("tdap://" . $user . "@master123/?pwd=" . $pwd);
|
|
936
|
-
$this->assertEquals($mgr->stat()
|
|
937
|
-
$this->assertEquals($mgr->isOpen()
|
|
1052
|
+
$this->assertEquals($mgr->stat(), 0);
|
|
1053
|
+
$this->assertEquals($mgr->isOpen(), true);
|
|
938
1054
|
$mgr->disconnect();
|
|
939
|
-
$this->assertEquals($mgr->isOpen()
|
|
940
|
-
//stop
|
|
941
|
-
|
|
1055
|
+
$this->assertEquals($mgr->isOpen(), false);
|
|
1056
|
+
//stop
|
|
1057
|
+
HaNameResolver::stop();
|
|
942
1058
|
$mgr->connect("tdap://" . $user . "@master123/?pwd=" . $pwd);
|
|
943
|
-
$this->assertEquals($mgr->stat()
|
|
1059
|
+
$this->assertEquals($mgr->stat(), ERROR_TD_HOSTNAME_NOT_FOUND);
|
|
944
1060
|
$tb_other->close();
|
|
945
1061
|
$db_other->close();
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
public function testV35Constant()
|
|
1065
|
+
{
|
|
1066
|
+
$this->assertEquals(Transactd::ERROR_TD_RECONNECTED_OFFSET, 1000);
|
|
1067
|
+
$this->assertEquals(Transactd::ERROR_TD_INVALID_SERVER_ROLE, 3812);
|
|
1068
|
+
$this->assertEquals(Transactd::ERROR_TD_RECONNECTED, 3900);
|
|
1069
|
+
$this->assertEquals(Transactd::MYSQL_ERROR_OFFSET, 25000);
|
|
1070
|
+
$this->assertEquals(Transactd::HA_ROLE_SLAVE, 0);
|
|
1071
|
+
$this->assertEquals(Transactd::HA_ROLE_MASTER, 1);
|
|
1072
|
+
$this->assertEquals(Transactd::HA_ROLE_NONE, 2);
|
|
1073
|
+
$this->assertEquals(Transactd::HA_RESTORE_ROLE, 4);
|
|
1074
|
+
$this->assertEquals(Transactd::HA_ENABLE_FAILOVER, 8);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
public function testFetchMode()
|
|
1078
|
+
{
|
|
1079
|
+
$db = new Database();
|
|
1080
|
+
$db->open(URI, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL);
|
|
1081
|
+
$tb = $db->openTable("user");
|
|
1082
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1083
|
+
$tb->seekFirst();
|
|
1084
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1085
|
+
|
|
1086
|
+
//test fetch field type
|
|
1087
|
+
Transactd::setFieldValueMode(Transactd::FIELD_VALUE_MODE_OBJECT);
|
|
1088
|
+
$tb->fetchMode = Transactd::FETCH_RECORD_INTO;
|
|
1089
|
+
$this->assertEquals($tb->fetchMode, Transactd::FETCH_RECORD_INTO);
|
|
1090
|
+
$rec = $tb->fields();
|
|
1091
|
+
$this->assertEquals($rec["id"]->i(), 1);
|
|
1092
|
+
|
|
1093
|
+
Transactd::setFieldValueMode(Transactd::FIELD_VALUE_MODE_VALUE);
|
|
1094
|
+
$this->assertEquals($rec["id"], 1);
|
|
1095
|
+
|
|
1096
|
+
$tb->fetchMode = Transactd::FETCH_VAL_NUM;
|
|
1097
|
+
$this->assertEquals($tb->fetchMode, Transactd::FETCH_VAL_NUM);
|
|
1098
|
+
$rec = $tb->fields();
|
|
1099
|
+
$this->assertEquals($rec[0], 1);
|
|
1100
|
+
|
|
1101
|
+
$tb->fetchMode = Transactd::FETCH_VAL_ASSOC;
|
|
1102
|
+
$this->assertEquals($tb->fetchMode, Transactd::FETCH_VAL_ASSOC);
|
|
1103
|
+
$rec = $tb->fields();
|
|
1104
|
+
$this->assertEquals($rec["id"], 1);
|
|
1105
|
+
|
|
1106
|
+
$tb->fetchMode = Transactd::FETCH_VAL_BOTH;
|
|
1107
|
+
$this->assertEquals($tb->fetchMode, Transactd::FETCH_VAL_BOTH);
|
|
1108
|
+
$rec = $tb->fields();
|
|
1109
|
+
$this->assertEquals($rec[0], 1);
|
|
1110
|
+
$this->assertEquals($rec["id"], 1);
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
$tb->fetchMode = Transactd::FETCH_OBJ;
|
|
1114
|
+
$this->assertEquals($tb->fetchMode, Transactd::FETCH_OBJ);
|
|
1115
|
+
$usr = $tb->fields();
|
|
1116
|
+
$this->assertEquals($usr->id, 1);
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
$tb->fetchMode = Transactd::FETCH_USR_CLASS;
|
|
1120
|
+
$tb->fetchClass = "User";
|
|
1121
|
+
$tb->ctorArgs = array("1","2","3");
|
|
1122
|
+
$this->assertEquals($tb->fetchMode, Transactd::FETCH_USR_CLASS);
|
|
1123
|
+
$usr = $tb->fields();
|
|
1124
|
+
$this->assertEquals($usr->id, 1);
|
|
1125
|
+
$this->assertEquals($usr->a, "1");
|
|
1126
|
+
$this->assertEquals($usr->b, "2");
|
|
1127
|
+
$this->assertEquals($usr->c, "3");
|
|
1128
|
+
$tb->close();
|
|
946
1129
|
|
|
1130
|
+
$at = new ActiveTable($db, "user");
|
|
1131
|
+
$q = new Query();
|
|
1132
|
+
$q->where("id", "<", 10);
|
|
1133
|
+
$rs = $at->index(0)->keyValue(0)->read($q);
|
|
1134
|
+
$rs->fetchMode = Transactd::FETCH_RECORD_INTO;
|
|
1135
|
+
$this->assertEquals($rs->fetchMode, Transactd::FETCH_RECORD_INTO);
|
|
1136
|
+
Transactd::setFieldValueMode(Transactd::FIELD_VALUE_MODE_OBJECT);
|
|
1137
|
+
$this->assertEquals($rs[0]["id"]->i(), 1);
|
|
1138
|
+
Transactd::setFieldValueMode(Transactd::FIELD_VALUE_MODE_VALUE);
|
|
1139
|
+
$this->assertEquals($rs[0]["id"], 1);
|
|
1140
|
+
$this->assertEquals($rs->size(), 9);
|
|
1141
|
+
|
|
1142
|
+
$rs->fetchMode = Transactd::FETCH_VAL_NUM;
|
|
1143
|
+
$this->assertEquals($rs->fetchMode, Transactd::FETCH_VAL_NUM);
|
|
1144
|
+
$this->assertEquals($rs[0][0], 1);
|
|
1145
|
+
$this->assertEquals(count($rs), 9);
|
|
1146
|
+
|
|
1147
|
+
$rs->fetchMode = Transactd::FETCH_VAL_ASSOC;
|
|
1148
|
+
$this->assertEquals($rs->fetchMode, Transactd::FETCH_VAL_ASSOC);
|
|
1149
|
+
$this->assertEquals($rs[0]["id"], 1);
|
|
1150
|
+
$this->assertEquals(count($rs), 9);
|
|
1151
|
+
|
|
1152
|
+
$rs->fetchMode = Transactd::FETCH_VAL_BOTH;
|
|
1153
|
+
$this->assertEquals($rs->fetchMode, Transactd::FETCH_VAL_BOTH);
|
|
1154
|
+
$this->assertEquals($rs[0][0], 1);
|
|
1155
|
+
$this->assertEquals($rs[0]["id"], 1);
|
|
1156
|
+
$this->assertEquals(count($rs), 9);
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
$rs->fetchMode = Transactd::FETCH_OBJ;
|
|
1160
|
+
$this->assertEquals($rs->fetchMode, Transactd::FETCH_OBJ);
|
|
1161
|
+
$this->assertEquals($rs[0]->id, 1);
|
|
1162
|
+
$this->assertEquals(count($rs), 9);
|
|
1163
|
+
|
|
1164
|
+
$rs->fetchMode = Transactd::FETCH_USR_CLASS;
|
|
1165
|
+
$rs->fetchClass = "User";
|
|
1166
|
+
$rs->ctorArgs = array("1","2","3");
|
|
1167
|
+
$this->assertEquals($rs->fetchMode, Transactd::FETCH_USR_CLASS);
|
|
1168
|
+
$this->assertEquals($rs[1]->id, 2);
|
|
1169
|
+
$this->assertEquals($rs[0]->a, "1");
|
|
1170
|
+
$this->assertEquals($rs[0]->b, "2");
|
|
1171
|
+
$this->assertEquals($rs[0]->c, "3");
|
|
1172
|
+
$this->assertEquals(count($rs), 9);
|
|
1173
|
+
|
|
1174
|
+
$db->close();
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
public function testSetAlias()
|
|
1178
|
+
{
|
|
1179
|
+
$db = new Database();
|
|
1180
|
+
$db->open(URI, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL);
|
|
1181
|
+
$tb = $db->openTable("user");
|
|
1182
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1183
|
+
$tb->setAlias("名前", "name");
|
|
1184
|
+
$tb->setAlias("id", "user_id");
|
|
1185
|
+
$this->assertEquals($tb->fieldNumByName("user_id"), 0);
|
|
1186
|
+
$tb->seekFirst();
|
|
1187
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1188
|
+
|
|
1189
|
+
$tb->fetchMode = Transactd::FETCH_USR_CLASS;
|
|
1190
|
+
$tb->fetchClass = "User";
|
|
1191
|
+
$tb->ctorArgs = array("1","2","3");
|
|
1192
|
+
$this->assertEquals($tb->fetchMode, Transactd::FETCH_USR_CLASS);
|
|
1193
|
+
$usr = $tb->fields();
|
|
1194
|
+
$this->assertEquals($usr->user_id, 1);
|
|
1195
|
+
$this->assertEquals($usr->name, "1 user");
|
|
1196
|
+
|
|
1197
|
+
$q = new Query();
|
|
1198
|
+
$q->select("name")->where("id", "<", 10);
|
|
1199
|
+
$tb->setQuery($q);
|
|
1200
|
+
$tb->clearBuffer();
|
|
1201
|
+
$users = $tb->findAll();
|
|
1202
|
+
$this->assertEquals(count($users), 9);
|
|
1203
|
+
$this->assertEquals($users[0]->name, "1 user");
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
public function testCURDByObject()
|
|
1207
|
+
{
|
|
1208
|
+
$db = new Database();
|
|
1209
|
+
$db->open(URI, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL);
|
|
1210
|
+
$tb = $db->openTable("user");
|
|
1211
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1212
|
+
$tb->setAlias("名前", "name");
|
|
1213
|
+
$tb->seekFirst();
|
|
1214
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1215
|
+
$tb->fetchMode = Transactd::FETCH_USR_CLASS;
|
|
1216
|
+
$tb->fetchClass = "User";
|
|
1217
|
+
$tb->ctorArgs = array("1","2","3");
|
|
1218
|
+
$this->assertEquals($tb->fetchMode, Transactd::FETCH_USR_CLASS);
|
|
1219
|
+
|
|
1220
|
+
//Insert
|
|
1221
|
+
$usr = $tb->fields();
|
|
1222
|
+
$usr->id = 0;
|
|
1223
|
+
$usr->name = 'test_insertObject';
|
|
1224
|
+
$this->assertEquals($tb->insertByObject($usr), true);
|
|
1225
|
+
$tb->seekLast();
|
|
1226
|
+
$usr = $tb->fields();
|
|
1227
|
+
$this->assertEquals($usr->name, 'test_insertObject');
|
|
1228
|
+
$this->assertEquals($usr->id, 1001);
|
|
1229
|
+
|
|
1230
|
+
//Update
|
|
1231
|
+
$usr->name = 'test_UpdateObject';
|
|
1232
|
+
$this->assertEquals($tb->updateByObject($usr), true);
|
|
1233
|
+
$usr->name = '';
|
|
1234
|
+
|
|
1235
|
+
//Read
|
|
1236
|
+
$this->assertEquals($tb->readByObject($usr), true);
|
|
1237
|
+
$this->assertEquals($usr->name, 'test_UpdateObject');
|
|
1238
|
+
$this->assertEquals($usr->id, 1001);
|
|
1239
|
+
|
|
1240
|
+
$row = $tb->getRecord();
|
|
1241
|
+
$row->setValueByObject($usr);
|
|
1242
|
+
$usr2 = $tb->fields();
|
|
1243
|
+
$this->assertEquals($usr2, $usr);
|
|
1244
|
+
|
|
1245
|
+
//Delete
|
|
1246
|
+
$this->assertEquals($tb->deleteByObject($usr), true);
|
|
1247
|
+
$tb->seekLast();
|
|
1248
|
+
$usr = $tb->fields();
|
|
1249
|
+
$this->assertEquals($usr->id, 1000);
|
|
947
1250
|
}
|
|
948
1251
|
|
|
949
|
-
public function
|
|
1252
|
+
public function testUTCC()
|
|
950
1253
|
{
|
|
951
|
-
$
|
|
952
|
-
$
|
|
953
|
-
$
|
|
954
|
-
$
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
$
|
|
958
|
-
$
|
|
959
|
-
$this->assertEquals(
|
|
1254
|
+
$db = new Database();
|
|
1255
|
+
$db->open(URI, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL);
|
|
1256
|
+
$tb = $db->openTable("user");
|
|
1257
|
+
$tb2 = $db->openTable("user");
|
|
1258
|
+
// test in changeCurrentCc or changeCurrentNcc
|
|
1259
|
+
|
|
1260
|
+
$db->beginTrn();
|
|
1261
|
+
$tb->seekFirst();
|
|
1262
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1263
|
+
$tb2->seekFirst();
|
|
1264
|
+
$this->assertEquals($tb2->stat(), 0);
|
|
1265
|
+
$tb->setFV("名前", 'John');
|
|
1266
|
+
$tb->update();
|
|
1267
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1268
|
+
$tb2->setFV("名前", 'mike');
|
|
1269
|
+
$tb2->setUpdateConflictCheck(true);
|
|
1270
|
+
$this->assertEquals($tb2->updateConflictCheck(), true);
|
|
1271
|
+
$tb2->update(Nstable::changeCurrentCc);
|
|
1272
|
+
$this->assertEquals($tb2->stat(), Transactd::STATUS_CHANGE_CONFLICT);
|
|
1273
|
+
$db->abortTrn();
|
|
1274
|
+
|
|
1275
|
+
$db->beginTrn();
|
|
1276
|
+
$tb->seekFirst();
|
|
1277
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1278
|
+
$tb2->seekFirst();
|
|
1279
|
+
$this->assertEquals($tb2->stat(), 0);
|
|
1280
|
+
$tb->setFV("名前", 'John');
|
|
1281
|
+
$tb->update();
|
|
1282
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1283
|
+
$tb2->setFV("名前", 'mike');
|
|
1284
|
+
$tb2->setUpdateConflictCheck(false);
|
|
1285
|
+
$this->assertEquals($tb2->updateConflictCheck(), false);
|
|
1286
|
+
$tb2->update(Nstable::changeCurrentCc);
|
|
1287
|
+
$this->assertEquals($tb2->stat(), 0);
|
|
1288
|
+
$db->abortTrn();
|
|
1289
|
+
|
|
1290
|
+
$db->beginTrn();
|
|
1291
|
+
$tb->seekFirst();
|
|
1292
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1293
|
+
$tb2->seekFirst();
|
|
1294
|
+
$this->assertEquals($tb2->stat(), 0);
|
|
1295
|
+
$tb->setFV("名前", 'John');
|
|
1296
|
+
$tb->update();
|
|
1297
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1298
|
+
$tb2->setFV("名前", 'mike');
|
|
1299
|
+
// test in changeInKey
|
|
1300
|
+
$tb2->setUpdateConflictCheck(true);
|
|
1301
|
+
$tb2->update(Nstable::changeInKey);
|
|
1302
|
+
$this->assertEquals($tb2->stat(), Transactd::STATUS_CHANGE_CONFLICT);
|
|
1303
|
+
$db->abortTrn();
|
|
1304
|
+
|
|
1305
|
+
$db->beginTrn();
|
|
1306
|
+
$tb->seekFirst();
|
|
1307
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1308
|
+
$tb2->seekFirst();
|
|
1309
|
+
$this->assertEquals($tb2->stat(), 0);
|
|
1310
|
+
$tb->setFV("名前", 'John');
|
|
1311
|
+
$tb->update();
|
|
1312
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1313
|
+
$tb2->setFV("名前", 'mike');
|
|
1314
|
+
$tb2->setUpdateConflictCheck(false);
|
|
1315
|
+
$tb2->update(Nstable::changeInKey);
|
|
1316
|
+
$this->assertEquals($tb2->stat(), 0);
|
|
1317
|
+
$db->abortTrn();
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
const PROP_TEST_HAS = 1;
|
|
1321
|
+
const PROP_TEST_READ= 2;
|
|
1322
|
+
const PROP_TEST_WRITELONG= 3;
|
|
1323
|
+
|
|
1324
|
+
public function testPropertyAccess()
|
|
1325
|
+
{
|
|
1326
|
+
/* To orm user
|
|
1327
|
+
To orm user,
|
|
1328
|
+
If you nothing to declared the private variable for a property,
|
|
1329
|
+
and defined the __set and the __get magic method,
|
|
1330
|
+
The extension is used __set magic method in read from database.
|
|
1331
|
+
But the extension is not used __get magic method in write to database.
|
|
1332
|
+
You need prepared variable of field name for write operation.
|
|
1333
|
+
Even if you declrare both the private variable and __set methods,
|
|
1334
|
+
the extension read or write private variable directly.
|
|
1335
|
+
*/
|
|
1336
|
+
$p = new PropertyTest();
|
|
1337
|
+
$this->assertEquals(test_property($p, 'private', self::PROP_TEST_HAS), true);
|
|
1338
|
+
$this->assertEquals(test_property($p, 'protected', self::PROP_TEST_HAS), true);
|
|
1339
|
+
$this->assertEquals(test_property($p, 'public', self::PROP_TEST_HAS), true);
|
|
1340
|
+
|
|
1341
|
+
// Whne read data from object, use hasProperty function first.
|
|
1342
|
+
// If hasProperty returns false, skip read this field.
|
|
1343
|
+
$this->assertEquals(test_property($p, 'magic', self::PROP_TEST_HAS), false);// Important
|
|
1344
|
+
|
|
1345
|
+
$this->assertEquals(test_property($p, 'private', self::PROP_TEST_READ), 1);
|
|
1346
|
+
$this->assertEquals(test_property($p, 'protected', self::PROP_TEST_READ), 2);
|
|
1347
|
+
$this->assertEquals(test_property($p, 'public', self::PROP_TEST_READ), 3);
|
|
1348
|
+
$this->assertEquals(test_property($p, 'magic', self::PROP_TEST_READ), 4);
|
|
1349
|
+
|
|
1350
|
+
test_property($p, 'private', self::PROP_TEST_WRITELONG, 2);
|
|
1351
|
+
test_property($p, 'protected', self::PROP_TEST_WRITELONG, 3);
|
|
1352
|
+
test_property($p, 'public', self::PROP_TEST_WRITELONG, 4);
|
|
1353
|
+
test_property($p, 'magic', self::PROP_TEST_WRITELONG, 5);
|
|
1354
|
+
|
|
1355
|
+
$this->assertEquals(test_property($p, 'private', self::PROP_TEST_READ), 2);
|
|
1356
|
+
$this->assertEquals(test_property($p, 'protected', self::PROP_TEST_READ), 3);
|
|
1357
|
+
$this->assertEquals(test_property($p, 'public', self::PROP_TEST_READ), 4);
|
|
1358
|
+
$this->assertEquals(test_property($p, 'magic', self::PROP_TEST_READ), 5);
|
|
1359
|
+
|
|
1360
|
+
// write private variable directly.
|
|
1361
|
+
test_property($p, 'duplicate', self::PROP_TEST_WRITELONG, 8);
|
|
1362
|
+
$this->assertEquals(test_property($p, 'duplicate', self::PROP_TEST_READ), 8);
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
public function testTransfer()
|
|
1366
|
+
{
|
|
1367
|
+
$db = new Database();
|
|
1368
|
+
$db->open(URI, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL);
|
|
1369
|
+
$tb = $db->openTable("user");
|
|
1370
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1371
|
+
$tb->seekFirst();
|
|
1372
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1373
|
+
|
|
1374
|
+
$tb->setAlias("名前", "name");
|
|
1375
|
+
$usr = new UserT();
|
|
1376
|
+
$usr->id = 5;
|
|
1377
|
+
$this->assertEquals($tb->readByObject($usr), true);
|
|
1378
|
+
$this->assertEquals($usr->id, 5);
|
|
1379
|
+
$this->assertEquals($usr->phone->number->tel, '0236-99-9999');
|
|
1380
|
+
UserT::setTransferMap(1);
|
|
1381
|
+
$usr->id = 5;
|
|
1382
|
+
$this->assertEquals($tb->readByObject($usr), true);// No error
|
|
1383
|
+
$this->assertEquals($usr->id, 5);
|
|
1384
|
+
$this->assertEquals($usr->phone2, null);
|
|
1385
|
+
|
|
1386
|
+
UserT::setTransferMap(2);
|
|
1387
|
+
$usr->id = 5;
|
|
1388
|
+
$this->assertEquals($tb->readByObject($usr), true);// No error
|
|
1389
|
+
$this->assertEquals($usr->id, 5);
|
|
1390
|
+
$this->assertEquals($usr->phone->number2, null);
|
|
960
1391
|
}
|
|
1392
|
+
|
|
1393
|
+
public function testByObjectOption()
|
|
1394
|
+
{
|
|
1395
|
+
$db = new Database();
|
|
1396
|
+
$db->open(URI, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL);
|
|
1397
|
+
$tb = $db->openTable("user");
|
|
1398
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1399
|
+
$tb->setAlias("名前", "name");
|
|
1400
|
+
$usr = new UserT();
|
|
1401
|
+
|
|
1402
|
+
// read option (key number)
|
|
1403
|
+
$tb->setKeyNum(0);
|
|
1404
|
+
$usr->id = 5;
|
|
1405
|
+
$this->assertEquals($tb->readByObject($usr, 2), false);
|
|
1406
|
+
$this->assertEquals($tb->keyNum(), 2);
|
|
961
1407
|
|
|
1408
|
+
$this->assertEquals($tb->readByObject($usr), true);
|
|
1409
|
+
$this->assertEquals($tb->keyNum(), 0);
|
|
1410
|
+
|
|
1411
|
+
//update option (eUpdateType)
|
|
1412
|
+
$this->assertEquals($tb->readByObject($usr, 2), false); // No currency
|
|
1413
|
+
$this->assertEquals($tb->updateByObject($usr, Nstable::changeCurrentCc), false);
|
|
1414
|
+
$this->assertEquals($tb->updateByObject($usr), true); //default value Nstable::changeInKey
|
|
1415
|
+
|
|
1416
|
+
//delete option
|
|
1417
|
+
$usr->id = 0;
|
|
1418
|
+
$this->assertEquals($tb->insertByObject($usr), true); //Insert id = 1001
|
|
1419
|
+
$tb->fetchMode = Transactd::FETCH_USR_CLASS;
|
|
1420
|
+
$tb->fetchClass = "UserT";
|
|
1421
|
+
$tb->seekLast();
|
|
1422
|
+
$this->assertEquals($tb->stat(), 0);
|
|
1423
|
+
$usr = $tb->getRow();
|
|
1424
|
+
$id = $usr->id;
|
|
1425
|
+
$usr->id = 1005;
|
|
1426
|
+
$this->assertEquals($tb->readByObject($usr), false); // No currency
|
|
1427
|
+
$usr->id = $id;
|
|
1428
|
+
$tb->setKeyNum(2);
|
|
1429
|
+
$this->assertEquals($tb->deleteByObject($usr, false/*inKey*/), false);
|
|
1430
|
+
$this->assertEquals($tb->deleteByObject($usr), true); //default value true
|
|
1431
|
+
}
|
|
962
1432
|
}
|