transactd 3.1.0 → 3.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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/bin/common/tdclc_32_3_2.dll +0 -0
  3. data/bin/common/{tdclc_64_3_1.dll → tdclc_64_3_2.dll} +0 -0
  4. data/build/swig/ruby/ruby.swg +3 -0
  5. data/build/swig/ruby/tdclrb_wrap.cpp +2413 -126
  6. data/build/swig/tdcl.i +120 -9
  7. data/build/tdclc/tdclc.cbproj +4 -1
  8. data/build/tdclc/tdclc.rc +4 -4
  9. data/build/tdclcpp/tdclcpp.rc +4 -4
  10. data/build/tdclcpp/tdclcpp_bc.cbproj +8 -1
  11. data/build/tdclrb/tdclrb.rc +4 -4
  12. data/source/bzs/db/engine/mysql/database.cpp +138 -130
  13. data/source/bzs/db/engine/mysql/database.h +43 -48
  14. data/source/bzs/db/engine/mysql/dbManager.cpp +81 -96
  15. data/source/bzs/db/engine/mysql/dbManager.h +13 -22
  16. data/source/bzs/db/engine/mysql/mysqlInternal.h +157 -291
  17. data/source/bzs/db/engine/mysql/mysqlProtocol.cpp +425 -0
  18. data/source/bzs/db/engine/mysql/mysqlProtocol.h +72 -0
  19. data/source/bzs/db/engine/mysql/mysqlThd.cpp +8 -6
  20. data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +7 -3
  21. data/source/bzs/db/protocol/hs/hsCommandExecuter.h +1 -0
  22. data/source/bzs/db/protocol/tdap/client/client.h +22 -8
  23. data/source/bzs/db/protocol/tdap/client/connMgr.cpp +225 -21
  24. data/source/bzs/db/protocol/tdap/client/connMgr.h +42 -16
  25. data/source/bzs/db/protocol/tdap/client/database.cpp +58 -15
  26. data/source/bzs/db/protocol/tdap/client/database.h +3 -3
  27. data/source/bzs/db/protocol/tdap/client/dbDef.cpp +93 -85
  28. data/source/bzs/db/protocol/tdap/client/dbDef.h +1 -2
  29. data/source/bzs/db/protocol/tdap/client/dllmain.cpp +9 -5
  30. data/source/bzs/db/protocol/tdap/client/filter.h +2 -2
  31. data/source/bzs/db/protocol/tdap/client/groupComp.h +2 -2
  32. data/source/bzs/db/protocol/tdap/client/memRecord.cpp +1 -1
  33. data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +71 -12
  34. data/source/bzs/db/protocol/tdap/client/nsDatabase.h +7 -1
  35. data/source/bzs/db/protocol/tdap/client/nsTable.cpp +35 -2
  36. data/source/bzs/db/protocol/tdap/client/nsTable.h +1 -0
  37. data/source/bzs/db/protocol/tdap/client/recordset.cpp +5 -1
  38. data/source/bzs/db/protocol/tdap/client/recordset.h +15 -0
  39. data/source/bzs/db/protocol/tdap/client/recordsetImple.h +21 -16
  40. data/source/bzs/db/protocol/tdap/client/serializer.cpp +32 -11
  41. data/source/bzs/db/protocol/tdap/client/serializer.h +4 -1
  42. data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +3 -2
  43. data/source/bzs/db/protocol/tdap/client/sqlBuilder.h +3 -0
  44. data/source/bzs/db/protocol/tdap/client/table.cpp +18 -14
  45. data/source/bzs/db/protocol/tdap/client/trdboostapi.h +8 -3
  46. data/source/bzs/db/protocol/tdap/mysql/characterset.cpp +1 -0
  47. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +83 -43
  48. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.h +3 -1
  49. data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +7 -7
  50. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +247 -137
  51. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +9 -9
  52. data/source/bzs/db/protocol/tdap/tdapSchema.cpp +1 -4
  53. data/source/bzs/db/protocol/tdap/tdapSchema.h +3 -7
  54. data/source/bzs/db/protocol/tdap/tdapcapi.h +23 -3
  55. data/source/bzs/db/protocol/tdap/uri.h +40 -0
  56. data/source/bzs/db/transactd/appModule.cpp +14 -5
  57. data/source/bzs/db/transactd/appModule.h +10 -1
  58. data/source/bzs/db/transactd/connManager.cpp +93 -48
  59. data/source/bzs/db/transactd/connManager.h +10 -7
  60. data/source/bzs/db/transactd/connectionRecord.h +114 -19
  61. data/source/bzs/env/tstring.h +2 -0
  62. data/source/bzs/example/changeSchema.cpp +1 -1
  63. data/source/bzs/example/changeSchema_c.cpp +1 -1
  64. data/source/bzs/example/insertRecords.cpp +2 -1
  65. data/source/bzs/example/insertRecords_c.cpp +2 -1
  66. data/source/bzs/example/queryData.cpp +5 -2
  67. data/source/bzs/netsvc/server/IAppModule.h +6 -0
  68. data/source/bzs/test/tdclatl/test_v3.js +75 -0
  69. data/source/bzs/test/tdclphp/transactd_v3_Test.php +104 -7
  70. data/source/bzs/test/tdclrb/transactd_v3_spec.rb +84 -0
  71. data/source/bzs/test/trdclengn/testField.h +66 -6
  72. data/source/bzs/test/trdclengn/test_tdclcpp_v3.cpp +10 -1
  73. data/source/bzs/test/trdclengn/test_trdclengn.cpp +85 -0
  74. data/source/bzs/test/trdclengn/testbase.h +1 -1
  75. data/source/global/tdclatl/BinlogPos.cpp +64 -0
  76. data/source/global/tdclatl/BinlogPos.h +84 -0
  77. data/source/global/tdclatl/ConnMgr.cpp +285 -0
  78. data/source/global/tdclatl/ConnMgr.h +83 -0
  79. data/source/global/tdclatl/ConnRecord.cpp +123 -0
  80. data/source/global/tdclatl/ConnRecord.h +69 -0
  81. data/source/global/tdclatl/ConnRecords.cpp +57 -0
  82. data/source/global/tdclatl/ConnRecords.h +55 -0
  83. data/source/global/tdclatl/Database.cpp +36 -0
  84. data/source/global/tdclatl/Database.h +4 -0
  85. data/source/global/tdclatl/Table.cpp +14 -1
  86. data/source/global/tdclatl/Table.h +1 -0
  87. data/source/global/tdclatl/resource.h +0 -0
  88. data/source/global/tdclatl/tdclatl.idl +148 -4
  89. metadata +14 -4
  90. data/bin/common/tdclc_32_3_1.dll +0 -0
@@ -1,7 +1,7 @@
1
1
  #ifndef BZS_DB_TRANSACTD_CONNECTIONRECORD_H
2
2
  #define BZS_DB_TRANSACTD_CONNECTIONRECORD_H
3
3
  /*=================================================================
4
- Copyright (C) 2013 BizStation Corp All rights reserved.
4
+ Copyright (C) 2013 2016 BizStation Corp All rights reserved.
5
5
 
6
6
  This program is free software; you can redistribute it and/or
7
7
  modify it under the terms of the GNU General Public License
@@ -20,9 +20,10 @@
20
20
  =================================================================*/
21
21
  #include <bzs/env/compiler.h>
22
22
  #include <bzs/env/crosscompile.h>
23
+ #include <vector>
23
24
 
24
25
  #pragma pack(push, 1)
25
- pragma_pack1;
26
+ pragma_pack1
26
27
 
27
28
  namespace bzs
28
29
  {
@@ -32,29 +33,117 @@ namespace transactd
32
33
  {
33
34
  namespace connection
34
35
  {
36
+
37
+ /* Slave status row(field) index
38
+ record::type data type
39
+ 0 longlong to longValue
40
+ 1 string to value
41
+ */
42
+ #define SLAVE_STATUS_IO_STATE 0
43
+ #define SLAVE_STATUS_MASTER_HOST 1
44
+ #define SLAVE_STATUS_MASTER_USER 2
45
+ #define SLAVE_STATUS_MASTER_PORT 3
46
+ #define SLAVE_STATUS_CONNECT_RETRY 4
47
+ #define SLAVE_STATUS_MASTER_LOG_FILE 5
48
+ #define SLAVE_STATUS_READ_MASTER_LOG_POS 6
49
+ #define SLAVE_STATUS_RELAY_LOG_FILE 7
50
+ #define SLAVE_STATUS_RELAY_LOG_POS 8
51
+ #define SLAVE_STATUS_RELAY_MASTER_LOG_FILE 9
52
+ #define SLAVE_STATUS_SLAVE_IO_RUNNING 10
53
+ #define SLAVE_STATUS_SLAVE_SQL_RUNNING 11
54
+ #define SLAVE_STATUS_REPLICATE_DO_DB 12
55
+ #define SLAVE_STATUS_REPLICATE_IGNORE_DB 13
56
+ #define SLAVE_STATUS_REPLICATE_DO_TABLE 14
57
+ #define SLAVE_STATUS_REPLICATE_IGNORE_TABLE 15
58
+ #define SLAVE_STATUS_REPLICATE_WILD_DO_TABLE 16
59
+ #define SLAVE_STATUS_REPLICATE_WILD_IGNORE_TABLE 17
60
+ #define SLAVE_STATUS_LAST_ERRNO 18
61
+ #define SLAVE_STATUS_LAST_ERROR 19
62
+ #define SLAVE_STATUS_SKIP_COUNER 20
63
+ #define SLAVE_STATUS_EXEC_MASTER_LOG_POS 21
64
+ #define SLAVE_STATUS_RELAY_LOG_SPACE 22
65
+ #define SLAVE_STATUS_UNTIL_CONDITION 23
66
+ #define SLAVE_STATUS_UNTIL_LOG_FILE 24
67
+ #define SLAVE_STATUS_UNTIL_LOG_POS 25
68
+ #define SLAVE_STATUS_MASTER_SSL_ALLOWED 26
69
+ #define SLAVE_STATUS_MASTER_SSL_CA_FILE 27
70
+ #define SLAVE_STATUS_MASTER_SSL_CA_PATH 28
71
+ #define SLAVE_STATUS_MASTER_SSL_CERT 29
72
+ #define SLAVE_STATUS_MASTER_SSL_CIPHER 30
73
+ #define SLAVE_STATUS_MASTER_SSL_KEY 31
74
+ #define SLAVE_STATUS_SECONDS_BEHIND_MASTER 32
75
+ #define SLAVE_STATUS_MASTER_SSL_VERIFY_SERVER_CERT 33
76
+ #define SLAVE_STATUS_LAST_IO_ERRNO 34
77
+ #define SLAVE_STATUS_LAST_IO_ERROR 35
78
+ #define SLAVE_STATUS_LAST_SQL_ERRNO 36
79
+ #define SLAVE_STATUS_LAST_SQL_ERROR 37
80
+ #define SLAVE_STATUS_REPLICATE_IGNORE_SERVER_IDS 38
81
+ #define SLAVE_STATUS_MASTER_SERVER_ID 39
82
+ #define SLAVE_STATUS_DEFAULT_SIZE 40
83
+
84
+ #ifdef MARIADB_BASE_VERSION
85
+ # define SLAVE_STATUS_MASTER_SSL_CRL 40
86
+ # define SLAVE_STATUS_MASTER_SSL_CRLPATH 41
87
+ # define SLAVE_STATUS_USING_GTID 42
88
+ # define SLAVE_STATUS_GTID_IO_POS 43
89
+ # define SLAVE_STATUS_SIZE 44
90
+ #else
91
+ # define SLAVE_STATUS_MASTER_UUID 40
92
+ # define SLAVE_STATUS_MASTER_INFO_FILE 41
93
+ # define SLAVE_STATUS_SQL_DELAY 42
94
+ # define SLAVE_STATUS_SQL_REMAINING_DELAY 43
95
+ # define SLAVE_STATUS_SQL_RUNNING_STATE 44
96
+ # define SLAVE_STATUS_MASTER_RETRY_COUNT 45
97
+ # define SLAVE_STATUS_MASTER_BIND 46
98
+ # define SLAVE_STATUS_LAST_IO_ERROR_TIMESTAMP 47
99
+ # define SLAVE_STATUS_LAST_SQL_ERROR_TIMESTAMP 48
100
+ # define SLAVE_STATUS_MASTER_SSL_CRL 49
101
+ # define SLAVE_STATUS_MASTER_SSL_CRLPATH 50
102
+ # define SLAVE_STATUS_RETRIEVED_GTID_SET 51
103
+ # define SLAVE_STATUS_EXECUTED_GTID_SET 52
104
+ # define SLAVE_STATUS_AUTO_POSITION 53
105
+ # define SLAVE_STATUS_SIZE 54
106
+
107
+ #endif
108
+
109
+ #define CON_REC_VALUE_SIZE 67
110
+
35
111
  struct record
36
112
  {
37
- record() : conId(0), cid(0), dbid(0), trnType(0), status(0), readCount(0),
38
- updCount(0), delCount(0), insCount(0)
113
+ record() : conId(0), id(0), db(0), updCount(0), status(0)
39
114
  {
40
115
  name[0] = 0x00;
41
116
  }
42
- __int64 conId;
43
117
  union
44
118
  {
45
- unsigned int cid;
46
- unsigned int value_id;
119
+ __int64 conId; // 8 byte
120
+ __int64 longValue;
121
+ struct
122
+ {
123
+ unsigned int delCount;
124
+ unsigned int insCount;
125
+ };
47
126
  };
48
- unsigned short dbid;
49
- short trnType;
50
- union
127
+ unsigned int id; // 4 byte
128
+ union
51
129
  {
52
- char name[67];
53
- char value[67];
130
+ unsigned int db;
131
+ unsigned int readCount; // 4 byte
54
132
  };
55
133
  union
56
134
  {
57
- char status;
135
+ unsigned int updCount; // 4 byte
136
+ unsigned int type;
137
+ };
138
+
139
+ union // 67 byte
140
+ {
141
+ char name[CON_REC_VALUE_SIZE];
142
+ char value[CON_REC_VALUE_SIZE];
143
+ };
144
+ union
145
+ {
146
+ char status; // 1 byte
58
147
  struct
59
148
  {
60
149
  char inTransaction : 1;
@@ -66,11 +155,17 @@ struct record
66
155
  char dummy : 2;
67
156
  };
68
157
  };
69
- unsigned int readCount;
70
- unsigned int updCount;
71
- unsigned int delCount;
72
- unsigned int insCount;
73
- };
158
+
159
+
160
+ #ifdef _UNICODE
161
+ inline _TCHAR* nameW(_TCHAR* buf, int size)
162
+ {
163
+ MultiByteToWideChar(CP_UTF8, 0, name, -1, buf, size);
164
+ return buf;
165
+ }
166
+ #endif
167
+ }; // 20 + 68 = 88
168
+ typedef std::vector<record> records;
74
169
 
75
170
  } // connection
76
171
  } // transactd
@@ -78,6 +173,6 @@ struct record
78
173
  } // bzs
79
174
 
80
175
  #pragma pack(pop)
81
- pragma_pop;
176
+ pragma_pop
82
177
 
83
178
  #endif // BZS_DB_TRANSACTD_CONNECTIONRECORD_H
@@ -50,9 +50,11 @@ typedef stringstream _tstringstream;
50
50
  #ifdef _UNICODE
51
51
  #define tPos Pos
52
52
  #define tcout wcout
53
+ #define tostream wostream
53
54
  #else
54
55
  #define tPos AnsiPos
55
56
  #define tcout cout
57
+ #define tostream ostream
56
58
  #endif
57
59
 
58
60
  #ifdef _UNICODE
@@ -69,7 +69,7 @@ bool openDbExclusive(database* db, const _TCHAR* uri)
69
69
  }
70
70
 
71
71
  void __STDCALL
72
- onCopyData(database* db, int recordCount, int count, bool& cancel)
72
+ onCopyData(database* db, table* tb, int recordCount, int count, bool& cancel)
73
73
  {
74
74
  if (count == 0)
75
75
  _tprintf(_T("\n"));
@@ -36,7 +36,7 @@ void changeUserTable(dbdef* def)
36
36
  }
37
37
 
38
38
  void __STDCALL
39
- onCopyData(database* db, int recordCount, int count, bool& cancel)
39
+ onCopyData(database* db, table* tb, int recordCount, int count, bool& cancel)
40
40
  {
41
41
  if (count == 0)
42
42
  std::cout << std::endl;
@@ -72,7 +72,8 @@ bool insertUser(table* tb, int id, const _TCHAR* name, int groupid,
72
72
  tb->setFV(fieldnum_id, id);
73
73
  tb->setFV(fieldnum_name, name);
74
74
  tb->setFV(fieldnum_group, groupid);
75
- tb->setFV(fieldnum_tel, tel);
75
+ if (tb->tableDef()->fieldCount == 4)
76
+ tb->setFV(fieldnum_tel, tel);
76
77
  tb->insert();
77
78
  if (tb->stat() != 0)
78
79
  showError(_T("insert user record"), tb->tableDef()->tableName(),
@@ -60,7 +60,8 @@ void insertUser(fields& fds, int id, const _TCHAR* name, int groupid,
60
60
  fds[fieldnum_id] = id;
61
61
  fds[fieldnum_name] = name;
62
62
  fds[fieldnum_group] = groupid;
63
- fds[fieldnum_tel] = tel;
63
+ if ((int)fds.size() > fieldnum_tel)
64
+ fds[fieldnum_tel] = tel;
64
65
 
65
66
  insertRecord(fds);
66
67
  }
@@ -111,6 +111,7 @@ bool createUserTable(dbdef* def)
111
111
  fd->setName(_T("tel"));
112
112
  fd->type = USER_STRING_TYPE;
113
113
  fd->setLenByCharnum(21);
114
+ fd->setNullable(true, true);
114
115
 
115
116
  char keyNum = 0;
116
117
  keydef* kd = def->insertKey(tableid, keyNum);
@@ -212,6 +213,7 @@ bool createUserExtTable(dbdef* def)
212
213
  fd = def->insertField(tableid, filedIndex);
213
214
  fd->setName(_T("blob"));
214
215
  fd->type = BLOB_TYPE;
216
+ fd->setNullable(true, true);
215
217
  #ifndef USE_PSQL_DATABASE
216
218
  fd->len = 10;
217
219
  ++filedIndex;
@@ -446,10 +448,11 @@ bool checkVersion(database_ptr db)
446
448
  if (td->fieldCount == 4)
447
449
  {
448
450
  table_ptr tb = openTable(db, _T("extention"));
449
- return (tb->recordCount(false) == 20000);
451
+ if (tb->recordCount(false) == 20000)
452
+ return td->fieldDefs[2].isNullable() == true;
453
+ return false;
450
454
  }
451
455
  }
452
- td = def->tableDefs(1);
453
456
  }
454
457
  return false;
455
458
  }
@@ -82,6 +82,12 @@ public:
82
82
  virtual bool isShutDown() = 0;
83
83
  virtual bool checkHost(const char* hostCheckname, /*out*/char* hostName, int size) = 0;
84
84
  virtual void cleanup() = 0;
85
+ virtual const char* user() const = 0;
86
+ virtual const char* host() const = 0;
87
+ virtual void setUser(const char* v) = 0;
88
+ virtual void setHost(const char* v) = 0;
89
+ virtual void skipGrants(bool v) = 0;
90
+ virtual bool isSkipGrants() const = 0;
85
91
  };
86
92
 
87
93
  // Defines at Implementing of IAppModule , two variables below.
@@ -703,6 +703,64 @@ function testBinlogPos(db)
703
703
  db.endSnapshot();
704
704
  }
705
705
 
706
+ function testConnMgr(uri)
707
+ {
708
+ var mgr = new ActiveXObject('transactd.connMgr');
709
+ var db = createDatabaseObject();
710
+ mgr.setDatabase(db);
711
+ mgr.connect(uri);
712
+ checkEqual(db.stat , 0, "mgr.connect");
713
+
714
+ //connections
715
+ var recs = mgr.Connections();
716
+ checkEqual(mgr.stat , 0, "mgr.Connections");
717
+ //InUseDatabases
718
+ var recs1 = mgr.InUseDatabases(recs(0).conid);
719
+ checkEqual(mgr.stat , 0, "mgr.InUseDatabases");
720
+ //InUseTables
721
+ var recs2 = mgr.InUseTables(recs(0).conid, recs(0).db);
722
+ checkEqual(mgr.stat , 0, "mgr.InUseTables");
723
+
724
+ checkEqual(recs.size , 1, "mgr.Connections.size");
725
+ checkEqual(recs1.size , 1, "mgr.InUseDatabases.size");
726
+ checkEqual(recs2.size , 4, "mgr.InUseTables.size");
727
+
728
+ //tables
729
+ recs = mgr.tables("test_v3");
730
+ checkEqual(mgr.stat , 0, "mgr.tables");
731
+ checkEqual(recs.size , 3, "mgr.tables.size");
732
+
733
+ //views
734
+ recs = mgr.views("test_v3");
735
+ checkEqual(mgr.stat , 0, "mgr.views");
736
+ checkEqual(recs.size , 1, "mgr.views.size");
737
+ checkEqual(recs(0).name , "idlessthan5");
738
+
739
+ //schemaTables
740
+ recs = mgr.schemaTables("test_v3");
741
+ checkEqual(mgr.stat , 0, "mgr.schemaTables");
742
+ checkEqual(recs.size , 1, "mgr.schemaTables.size");
743
+ checkEqual(recs(0).name , "test");
744
+
745
+ //databases
746
+ recs = mgr.databases();
747
+ checkEqual(mgr.stat , 0, "mgr.databases");
748
+ var size = recs.size;
749
+ mgr.RemoveSystemDb(recs);
750
+ checkNotEqual(size , recs.size, "RemoveSystemDb recs");
751
+
752
+ //slaveStatus
753
+ recs = mgr.slaveStatus();
754
+ checkEqual(mgr.stat , 0, "mgr.slaveStatus");
755
+ var status = "";
756
+ /*for (var i = 0; i<recs.size; ++i)
757
+ status += (mgr.SlaveStatusName(i) + "\t:" + recs(i).value + "\n");
758
+ */
759
+ mgr.disconnect();
760
+ checkEqual(mgr.stat , 0, "mgr.disconnect");
761
+ WScript.Echo("\n\n" + status);
762
+ }
763
+
706
764
 
707
765
  /*--------------------------------------------------------------------------------*/
708
766
  function test(atu, ate, db)
@@ -994,6 +1052,23 @@ function test(atu, ate, db)
994
1052
  //binlogPos
995
1053
  testBinlogPos(db);
996
1054
 
1055
+ //getCreateViewSql
1056
+ db.createTable("create view idlessthan5 as select * from user where id < 5");
1057
+ var view = db.getCreateViewSql("idlessthan5");
1058
+ checkNotEqual(view.indexOf("idlessthan5") , -1, "getCreateViewSql");
1059
+ checkNotEqual(view.indexOf("���O") , -1, "getCreateViewSql 2");
1060
+ //getCreateSql2
1061
+ var sql = tb.getCreateSql();
1062
+ checkNotEqual(sql.indexOf("CREATE TABLE") , -1, "getCreateSql");
1063
+ checkNotEqual(view.indexOf("���O") , -1, "getCreateSql 2");
1064
+
1065
+ //createAssociate()
1066
+ var dba = db.createAssociate();
1067
+ checkEqual(db.stat , 0, "createAssociate");
1068
+ checkEqual(dba.IsAssociate , true, "IsAssociate");
1069
+ // connMgr
1070
+ testConnMgr(db.uri);
1071
+
997
1072
  //WScript.Echo(" -- End Test -- ");
998
1073
  }
999
1074
  /*--------------------------------------------------------------------------------*/
@@ -297,6 +297,8 @@ class transactdTest extends PHPUnit_Framework_TestCase
297
297
  $db->abortTrn();
298
298
  $this->assertEquals(true, false);
299
299
  }
300
+ $tb->close();
301
+ $tb3->close();
300
302
  }
301
303
  private function openTable($db)
302
304
  {
@@ -311,14 +313,14 @@ class transactdTest extends PHPUnit_Framework_TestCase
311
313
  public function test()
312
314
  {
313
315
  $db = new bz\database();
314
-
316
+
315
317
  $this->createDatabase($db);
316
318
  $this->openDatabase($db);
317
319
  $this->createUserTable($db);
318
320
  $this->createUserExtTable($db);
319
321
  $this->insertData($db);
320
322
  $mysql_5_5 = $this->isMySQL5_5($db);
321
-
323
+
322
324
  $db->setAutoSchemaUseNullkey(true);
323
325
  $this->assertEquals($db->autoSchemaUseNullkey(), true);
324
326
  $db->setAutoSchemaUseNullkey(false);
@@ -345,15 +347,13 @@ class transactdTest extends PHPUnit_Framework_TestCase
345
347
 
346
348
  //size()
347
349
  $this->assertEquals($td->size() , 1184);
348
-
350
+
349
351
  //InUse
350
352
  $this->assertEquals($td->inUse() , 0);
351
353
 
352
354
  //nullfields
353
355
  $this->assertEquals($td->nullfields(), 2);
354
-
355
356
 
356
-
357
357
  //fieldNumByName
358
358
  $this->assertEquals($td->fieldNumByName("tel") , 3);
359
359
 
@@ -609,6 +609,7 @@ class transactdTest extends PHPUnit_Framework_TestCase
609
609
  $tb->release();
610
610
  $this->assertEquals($td->inUse() , 0);
611
611
 
612
+ $db->close();
612
613
  }
613
614
 
614
615
  public function test_bit()
@@ -693,7 +694,9 @@ class transactdTest extends PHPUnit_Framework_TestCase
693
694
  $this->assertEquals($bits[62], true);
694
695
  $this->assertEquals($bits[11], false);
695
696
  $this->assertEquals($bits[13], false);
696
-
697
+
698
+ $tb->close();
699
+ $db->close();
697
700
  }
698
701
 
699
702
  public function test_bitset()
@@ -749,6 +752,7 @@ class transactdTest extends PHPUnit_Framework_TestCase
749
752
  $fd->len = 4;
750
753
  $fd->setDefaultValue($bits1);
751
754
  $this->assertEquals($fd->defaultValue(), '4');
755
+ $db->close();
752
756
  }
753
757
  public function test_snapshot()
754
758
  {
@@ -761,7 +765,100 @@ class transactdTest extends PHPUnit_Framework_TestCase
761
765
  $this->assertEquals($bpos->type, bz\transactd::REPL_POSTYPE_POS);
762
766
  $this->assertNotEquals($bpos->pos, 0);
763
767
  $this->assertNotEquals($bpos->filename, "");
764
- echo PHP_EOL.'binlog pos = '.$bpos->filename.':'.$bpos->pos.PHP_EOL;
768
+ //echo PHP_EOL.'binlog pos = '.$bpos->filename.':'.$bpos->pos.PHP_EOL;
765
769
  $db->endSnapshot();
770
+ $db->close();
771
+ }
772
+ public function test_getSql()
773
+ {
774
+ $db = new bz\database();
775
+ $this->openDatabase($db);
776
+ $db->createTable("create view idlessthan5 as select * from user where id < 5");
777
+ $view = $db->getCreateViewSql("idlessthan5");
778
+ $this->assertEquals((strpos($view, "idlessthan5") !== false), true);
779
+ $this->assertEquals((strpos($view, "名前") !== false), true);
780
+ //echo($view);
781
+ $tb = $db->openTable("user");
782
+ $this->assertEquals($db->stat(), 0);
783
+ $sql = $tb->getCreateSql();
784
+ //echo($sql);
785
+ $this->assertEquals((strpos($sql, "CREATE TABLE") !== false), true);
786
+ $this->assertEquals((strpos($sql, "名前") !== false), true);
787
+ $tb->close();
788
+ $db->close();
789
+ }
790
+ public function test_createAssociate()
791
+ {
792
+ $db = new bz\database();
793
+ $this->openDatabase($db);
794
+ $dba = $db->createAssociate();
795
+ $this->assertEquals($db->stat(), 0);
796
+ $this->assertEquals($dba->isAssociate(), true);
797
+ $dba->close();
798
+ $db->close();
799
+ }
800
+ public function test_ConnMgr()
801
+ {
802
+ // other database connection
803
+ $db_other = new bz\database();
804
+ $this->openDatabase($db_other);
805
+ $tb_other = $db_other->openTable("user");
806
+ $this->assertEquals($db_other->stat(), 0);
807
+ // connMgr connection
808
+ $db = new bz\database();
809
+ $mgr = new bz\connMgr($db);
810
+ $mgr->connect($db_other->uri());
811
+ $this->assertEquals($mgr->stat(), 0);
812
+ // connections
813
+ $recs = $mgr->connections();
814
+ $this->assertEquals($mgr->stat(), 0);
815
+ $this->assertEquals($recs->size(), count($recs));
816
+ $this->assertEquals($recs->size(), 1);
817
+ // InUseDatabases
818
+ $recs = $mgr->inUseDatabases($recs[0]->conId);
819
+ $this->assertEquals($mgr->stat(), 0);
820
+ $this->assertEquals($recs->size(), count($recs));
821
+ $this->assertEquals($recs->size(), 1);
822
+ // InUseTables
823
+ $recs = $mgr->inUseTables($recs[0]->conId, $recs[0]->db);
824
+ $this->assertEquals($mgr->stat(), 0);
825
+ $this->assertEquals($recs->size(), count($recs));
826
+ $this->assertEquals($recs->size(), 2);
827
+ // tables, views
828
+ $recs = $mgr->tables("test_v3");
829
+ $this->assertEquals($mgr->stat(), 0);
830
+ $recs1 = $mgr->views("test_v3");
831
+ $this->assertEquals($mgr->stat(), 0);
832
+ $this->assertEquals($recs->size(), count($recs));
833
+ $this->assertEquals($recs->size(), 3);
834
+ $this->assertEquals($recs1->size(), count($recs1));
835
+ $this->assertEquals($recs1->size(), 1);
836
+ $this->assertEquals($recs1[0]->name, "idlessthan5");
837
+ // schemaTables
838
+ $recs = $mgr->schemaTables("test_v3");
839
+ $this->assertEquals($mgr->stat(), 0);
840
+ $this->assertEquals($recs->size(), count($recs));
841
+ $this->assertEquals($recs->size(), 1);
842
+ $this->assertEquals($recs[0]->name, "test");
843
+ // databases
844
+ $recs = $mgr->databases();
845
+ $this->assertEquals($mgr->stat(), 0);
846
+ $this->assertEquals($recs->size(), count($recs));
847
+ $size = $recs->size();
848
+ $mgr->RemoveSystemDb($recs);
849
+ $this->assertEquals($mgr->stat(), 0);
850
+ $this->assertEquals($recs->size(), count($recs));
851
+ $this->assertNotEquals($recs->size(), $size);
852
+ // slaveStatus
853
+ $recs = $mgr->slaveStatus();
854
+ $this->assertEquals($mgr->stat(), 0);
855
+ for ($i = 0; $i < $recs->size(); $i++)
856
+ {
857
+ echo(PHP_EOL . $mgr->slaveStatusName($i) . "\t:" . $recs[$i]->value);
858
+ }
859
+ $mgr->disconnect();
860
+ $this->assertEquals($mgr->stat(), 0);
861
+ $tb_other->close();
862
+ $db_other->close();
766
863
  }
767
864
  }
@@ -689,6 +689,8 @@ describe Transactd, 'V3Features' do
689
689
  expect(bits[62]).to eq true
690
690
  expect(bits[11]).to eq false
691
691
  expect(bits[13]).to eq false
692
+ tb.close()
693
+ db.close()
692
694
  end
693
695
 
694
696
  it 'bitset' do
@@ -754,6 +756,8 @@ describe Transactd, 'V3Features' do
754
756
  expect(rs[3]['bit32'].isNull()).to eq true
755
757
  expect(rs[3]['bit64'].isNull()).to eq true
756
758
  ats.release()
759
+ db.dropTable(SEB_TABLENAME);
760
+ expect(db.stat()).to eq 0
757
761
  db.close()
758
762
  end
759
763
  it 'snapshot' do
@@ -771,4 +775,84 @@ describe Transactd, 'V3Features' do
771
775
  db.endSnapshot();
772
776
  db.close()
773
777
  end
778
+ it 'get sql' do
779
+ db = Transactd::Database.new()
780
+ openDatabase(db)
781
+ db.createTable("create view idlessthan5 as select * from user where id < 5")
782
+ view = db.getCreateViewSql("idlessthan5")
783
+ expect(view.include?("idlessthan5")).to eq true
784
+ expect(view.include?("名前")).to eq true
785
+ #puts("view" + view)
786
+ tb = db.openTable("user")
787
+ expect(db.stat()).to eq 0
788
+ sql = tb.getCreateSql()
789
+ #puts("sql" + sql)
790
+ expect(sql.include?("CREATE TABLE")).to eq true
791
+ expect(sql.include?("名前")).to eq true
792
+ tb.close()
793
+ db.close()
794
+ end
795
+ it 'create associate' do
796
+ db = Transactd::Database.new()
797
+ openDatabase(db)
798
+ dba = db.createAssociate()
799
+ expect(db.stat()).to eq 0
800
+ expect(dba.isAssociate()).to eq true
801
+ dba.close()
802
+ db.close()
803
+ end
804
+ it 'connMgr' do
805
+ # other database connection
806
+ db_other = Transactd::Database.new()
807
+ openDatabase(db_other)
808
+ tb_other = db_other.openTable("user")
809
+ expect(db_other.stat()).to eq 0
810
+ # connMgr connection
811
+ db = Transactd::Database.new()
812
+ mgr = Transactd::ConnMgr.new(db)
813
+ mgr.connect(db_other.uri())
814
+ expect(mgr.stat()).to eq 0
815
+ # connections
816
+ recs = mgr.connections()
817
+ expect(mgr.stat()).to eq 0
818
+ expect(recs.size()).to eq 1
819
+ # inUseDatabases
820
+ recs = mgr.inUseDatabases(recs[0].conId)
821
+ expect(mgr.stat()).to eq 0
822
+ expect(recs.size()).to eq 1
823
+ # inUseTables
824
+ recs = mgr.inUseTables(recs[0].conId, recs[0].db)
825
+ expect(mgr.stat()).to eq 0
826
+ expect(recs.size()).to eq 2
827
+ # tables, views
828
+ recs = mgr.tables("test_v3")
829
+ expect(mgr.stat()).to eq 0
830
+ recs1 = mgr.views("test_v3")
831
+ expect(mgr.stat()).to eq 0
832
+ expect(recs.size()).to eq 3
833
+ expect(recs1.size()).to eq 1
834
+ expect(recs1[0].name).to eq "idlessthan5"
835
+ # schemaTables
836
+ recs = mgr.schemaTables("test_v3")
837
+ expect(mgr.stat()).to eq 0
838
+ expect(recs.size()).to eq 1
839
+ expect(recs[0].name).to eq "test"
840
+ # databases
841
+ recs = mgr.databases()
842
+ expect(mgr.stat()).to eq 0
843
+ size = recs.size()
844
+ Transactd::ConnMgr::removeSystemDb(recs)
845
+ expect(mgr.stat()).to eq 0
846
+ expect(recs.size()).not_to eq size
847
+ # slaveStatus
848
+ recs = mgr.slaveStatus()
849
+ expect(mgr.stat()).to eq 0
850
+ for i in 0...recs.size() do
851
+ puts (Transactd::ConnMgr::slaveStatusName(i) + "\t" + recs[i].value)
852
+ end
853
+ mgr.disconnect()
854
+ expect(mgr.stat()).to eq 0
855
+ tb_other.close()
856
+ db_other.close()
857
+ end
774
858
  end