transactd 1.0.1-x86-mswin32-100
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 +7 -0
- data/BUILD_UNIX-JA +174 -0
- data/BUILD_WIN-JA +256 -0
- data/CMakeLists.txt +96 -0
- data/COPYING +339 -0
- data/README +406 -0
- data/README-JA +424 -0
- data/bin/1.9/transactd.so +0 -0
- data/bin/2.0/transactd.so +0 -0
- data/bin/common/tdclc_32_1_0.dll +0 -0
- data/bin/common/tdclcpp_vc100_32m_1_1.dll +0 -0
- data/build/common/copyifgreater.cmd +30 -0
- data/build/common/copyifgreater.js +290 -0
- data/build/common/system.cmake +122 -0
- data/build/tdclrb/bldgem/extconf.rb +123 -0
- data/build/tdclrb/gem/INSTALLLOG.win32 +9 -0
- data/build/tdclrb/gem/Makefile.win32-VS +65 -0
- data/build/tdclrb/gem/Makefile.win32-prebuilt +48 -0
- data/build/tdclrb/gem/detect.rb +31 -0
- data/build/tdclrb/gem/helper.rb +113 -0
- data/build/tdclrb/gem/transactd.rb +22 -0
- data/source/bzs/test/tdclrb/bench_tdclcpp.rb +375 -0
- data/source/bzs/test/tdclrb/prepare.rb +226 -0
- data/source/bzs/test/tdclrb/transactd_datetime_spec.rb +172 -0
- data/source/bzs/test/tdclrb/transactd_kanjischema_spec.rb +208 -0
- data/source/bzs/test/tdclrb/transactd_spec.rb +1536 -0
- data/transactd.gemspec +97 -0
- metadata +76 -0
@@ -0,0 +1,226 @@
|
|
1
|
+
# coding : utf-8
|
2
|
+
=begin =============================================================
|
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
|
+
=end
|
21
|
+
require 'transactd'
|
22
|
+
|
23
|
+
FN_ID = 0
|
24
|
+
FN_NAME = 1
|
25
|
+
|
26
|
+
TYPE_SCHEMA_BDF = 0
|
27
|
+
PARALLEL_TRN = 1000
|
28
|
+
LOCK_SINGLE_NOWAIT = 200
|
29
|
+
TRANS_BIAS = PARALLEL_TRN + LOCK_SINGLE_NOWAIT
|
30
|
+
|
31
|
+
def createTable(db)
|
32
|
+
dbdef = db.dbDef()
|
33
|
+
td = Transactd::Tabledef.new()
|
34
|
+
td.setTableName('user')
|
35
|
+
td.setFileName('user.dat')
|
36
|
+
td.id = 1
|
37
|
+
td.pageSize = 2048
|
38
|
+
dbdef.insertTable(td)
|
39
|
+
td = dbdef.tableDefs(td.id)
|
40
|
+
|
41
|
+
fd = dbdef.insertField(td.id, 0)
|
42
|
+
fd.setName('id')
|
43
|
+
fd.type = Transactd::Ft_integer
|
44
|
+
fd.len = 4
|
45
|
+
dbdef.updateTableDef(1)
|
46
|
+
|
47
|
+
fd = dbdef.insertField(td.id, 1)
|
48
|
+
fd.setName('name')
|
49
|
+
fd.type = Transactd::Ft_myvarchar
|
50
|
+
fd.len = 100
|
51
|
+
dbdef.updateTableDef(td.id)
|
52
|
+
|
53
|
+
kd = dbdef.insertKey(td.id, 0)
|
54
|
+
kd.segment(0).fieldNum = 0
|
55
|
+
kd.segment(0).flags.bit8 = 1 # extend key type
|
56
|
+
kd.segment(0).flags.bit1 = 1 # changeable
|
57
|
+
kd.segmentCount = 1
|
58
|
+
|
59
|
+
td.primaryKeyNum = 0
|
60
|
+
dbdef.updateTableDef(td.id)
|
61
|
+
end
|
62
|
+
|
63
|
+
## --------------------------------------------------------------------------------
|
64
|
+
def printUsage()
|
65
|
+
puts("usage: ruby prepare.rb databaseUri functionNumber rangeStart rangeEnd gap")
|
66
|
+
puts("\t --- functionNumber list ---")
|
67
|
+
puts("\t 0: only create database and table")
|
68
|
+
puts("\t 1: delete records from rangeStart to rangeEnd with gap")
|
69
|
+
puts("\t 2: set records from rangeStart to rangeEnd with gap")
|
70
|
+
puts("\t 3: check records from rangeStart to rangeEnd with gap")
|
71
|
+
puts("example : ruby prepare.rb \"tdap://localhost/test?dbfile=test.bdf\" 1 1 1000 1")
|
72
|
+
end
|
73
|
+
|
74
|
+
## --------------------------------------------------------------------------------
|
75
|
+
def main(argv)
|
76
|
+
if (argv.length < 3)
|
77
|
+
printUsage()
|
78
|
+
return
|
79
|
+
end
|
80
|
+
uri = argv[1]
|
81
|
+
functionNumber = Integer(argv[2])
|
82
|
+
if !([0,1,2,3].include?(functionNumber))
|
83
|
+
printUsage()
|
84
|
+
return
|
85
|
+
end
|
86
|
+
rangeStart = 0
|
87
|
+
rangeEnd = 0
|
88
|
+
gap = 0
|
89
|
+
if functionNumber > 0
|
90
|
+
if argv.length < 5
|
91
|
+
printUsage()
|
92
|
+
return
|
93
|
+
end
|
94
|
+
rangeStart = Integer(argv[3])
|
95
|
+
rangeEnd = Integer(argv[4])
|
96
|
+
if rangeStart < 0 || rangeEnd < 0
|
97
|
+
printUsage()
|
98
|
+
return
|
99
|
+
end
|
100
|
+
if rangeStart > rangeEnd
|
101
|
+
tmp = rangeStart
|
102
|
+
rangeStart = rangeEnd
|
103
|
+
rangeEnd = tmp
|
104
|
+
end
|
105
|
+
if argv.length >= 6
|
106
|
+
gap = Integer(argv[5])
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
db = Transactd::Database.createObject()
|
111
|
+
|
112
|
+
if !db.open(uri, TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL, '', '')
|
113
|
+
db.create(uri)
|
114
|
+
if db.stat() != 0
|
115
|
+
puts("create database error No #{db.stat()}")
|
116
|
+
db.close()
|
117
|
+
return
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
if !db.open(uri, TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL, '', '')
|
122
|
+
puts("open table erorr No #{db.stat().to_s}")
|
123
|
+
db.close()
|
124
|
+
return
|
125
|
+
end
|
126
|
+
|
127
|
+
tb = db.openTable('user', Transactd::TD_OPEN_NORMAL, true)
|
128
|
+
if db.stat() == Transactd::STATUS_TABLE_EXISTS_ERROR || tb == nil
|
129
|
+
createTable(db)
|
130
|
+
tb = db.openTable('user', Transactd::TD_OPEN_NORMAL, true)
|
131
|
+
end
|
132
|
+
|
133
|
+
if functionNumber == 1
|
134
|
+
db.beginTrn(TRANS_BIAS)
|
135
|
+
tb.clearBuffer()
|
136
|
+
for i in rangeStart..rangeEnd do
|
137
|
+
tb.setFV(FN_ID, i)
|
138
|
+
tb.seek()
|
139
|
+
if tb.stat() == 0
|
140
|
+
tb.del()
|
141
|
+
if tb.stat() != 0
|
142
|
+
puts("delete erorr No #{tb.stat().to_s}")
|
143
|
+
db.endTrn()
|
144
|
+
tb.close()
|
145
|
+
db.close()
|
146
|
+
return false
|
147
|
+
end
|
148
|
+
elsif tb.stat() != 4
|
149
|
+
puts("delete erorr No #{tb.stat().to_s}")
|
150
|
+
db.endTrn()
|
151
|
+
tb.close()
|
152
|
+
db.close()
|
153
|
+
return false
|
154
|
+
end
|
155
|
+
end
|
156
|
+
db.endTrn()
|
157
|
+
end
|
158
|
+
|
159
|
+
if functionNumber == 2
|
160
|
+
db.beginTrn(TRANS_BIAS)
|
161
|
+
tb.clearBuffer()
|
162
|
+
for i in rangeStart..rangeEnd do
|
163
|
+
tb.setFV(FN_ID, i)
|
164
|
+
tb.seek()
|
165
|
+
if (tb.stat() == 0)
|
166
|
+
tb.setFV(FN_NAME, "#{i + gap}")
|
167
|
+
tb.update()
|
168
|
+
if (tb.stat() != 0)
|
169
|
+
puts("set erorr No #{tb.stat().to_s}")
|
170
|
+
db.endTrn()
|
171
|
+
tb.close()
|
172
|
+
db.close()
|
173
|
+
return false
|
174
|
+
end
|
175
|
+
else
|
176
|
+
tb.clearBuffer()
|
177
|
+
tb.setFV(FN_ID, i)
|
178
|
+
tb.setFV(FN_NAME, i + gap)
|
179
|
+
tb.insert()
|
180
|
+
if (tb.stat() != 0)
|
181
|
+
puts("set erorr No #{tb.stat().to_s}")
|
182
|
+
db.endTrn()
|
183
|
+
tb.close()
|
184
|
+
db.close()
|
185
|
+
return false
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
db.endTrn()
|
190
|
+
end
|
191
|
+
|
192
|
+
if functionNumber == 3
|
193
|
+
tb.clearBuffer()
|
194
|
+
tb.setFV(FN_ID, rangeStart)
|
195
|
+
tb.seekGreater(true)
|
196
|
+
for i in rangeStart..rangeEnd do
|
197
|
+
if (tb.stat() != 0)
|
198
|
+
puts("check error stat=#{tb.stat()} Expected ID #{i}")
|
199
|
+
tb.close()
|
200
|
+
db.close()
|
201
|
+
return false
|
202
|
+
end
|
203
|
+
if (tb.getFVlng(FN_ID) != i)
|
204
|
+
puts("check error stat=#{tb.stat()} Expected ID #{i} but ID #{tb.getFVlng(FN_ID)}")
|
205
|
+
tb.close()
|
206
|
+
db.close()
|
207
|
+
return false
|
208
|
+
end
|
209
|
+
if (tb.getFVstr(FN_NAME).to_s != "#{i + gap}")
|
210
|
+
puts("check error stat=#{tb.stat()} Expected Name #{i + gap} but Name #{tb.getFVstr(FN_NAME)}")
|
211
|
+
tb.close()
|
212
|
+
db.close()
|
213
|
+
return false
|
214
|
+
end
|
215
|
+
tb.seekNext()
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
tb.close()
|
220
|
+
db.close()
|
221
|
+
return
|
222
|
+
end
|
223
|
+
|
224
|
+
args = ARGV
|
225
|
+
args.unshift(__FILE__)
|
226
|
+
main(args)
|
@@ -0,0 +1,172 @@
|
|
1
|
+
# coding : utf-8
|
2
|
+
=begin ============================================================
|
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
|
+
=end
|
21
|
+
require 'transactd'
|
22
|
+
|
23
|
+
describe Transactd, 'datetime' do
|
24
|
+
it 'get BtrDate' do
|
25
|
+
i_nowdate = Transactd::getNowDate() # get today as integer
|
26
|
+
s_i_nowdate = Transactd::btrdtoa(i_nowdate)
|
27
|
+
s_i_nowdate2 = Transactd::btrdtoa(i_nowdate, true)
|
28
|
+
#p i_nowdate
|
29
|
+
#p s_i_nowdate + ' ' + s_i_nowdate.encoding.to_s
|
30
|
+
#p s_i_nowdate2 + ' ' + s_i_nowdate2.encoding.to_s
|
31
|
+
nowdate = Transactd::BtrDate.new()
|
32
|
+
nowdate.i = i_nowdate # get today as BtrDate
|
33
|
+
s_nowdate = Transactd::btrdtoa(nowdate)
|
34
|
+
s_nowdate2 = Transactd::btrdtoa(nowdate, true)
|
35
|
+
cs_nowdate = Transactd::c_str(nowdate)
|
36
|
+
#p nowdate
|
37
|
+
#p s_nowdate + ' ' + s_nowdate.encoding.to_s
|
38
|
+
#p s_nowdate2 + ' ' + s_nowdate2.encoding.to_s
|
39
|
+
#p cs_nowdate + ' ' + cs_nowdate.encoding.to_s
|
40
|
+
expect(s_i_nowdate).to eq s_nowdate
|
41
|
+
expect(s_i_nowdate2).to eq s_nowdate2
|
42
|
+
expect(cs_nowdate).to eq s_nowdate
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'get BtrTime' do
|
46
|
+
i_nowtime = Transactd::getNowTime() # get now time as integer
|
47
|
+
s_i_nowtime = Transactd::btrttoa(i_nowtime)
|
48
|
+
s_i_nowtime2 = Transactd::btrttoa(i_nowtime, true)
|
49
|
+
#p i_nowtime
|
50
|
+
#p s_i_nowtime + ' ' + s_i_nowtime.encoding.to_s
|
51
|
+
#p s_i_nowtime2 + ' ' + s_i_nowtime2.encoding.to_s
|
52
|
+
nowtime = Transactd::BtrTime.new()
|
53
|
+
nowtime.i = i_nowtime # get now time as BtrTime
|
54
|
+
s_nowtime = Transactd::btrttoa(nowtime)
|
55
|
+
s_nowtime2 = Transactd::btrttoa(nowtime, true)
|
56
|
+
cs_nowtime = Transactd::c_str(nowtime)
|
57
|
+
#p nowtime
|
58
|
+
#p s_nowtime + ' ' + s_nowtime.encoding.to_s
|
59
|
+
#p s_nowtime2 + ' ' + s_nowtime2.encoding.to_s
|
60
|
+
#p cs_nowtime + ' ' + cs_nowtime.encoding.to_s
|
61
|
+
expect(s_i_nowtime).to eq s_nowtime
|
62
|
+
expect(s_i_nowtime2).to eq s_nowtime2
|
63
|
+
expect(cs_nowtime).to eq s_nowtime
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'get BtrDateTime' do
|
67
|
+
date = Transactd::atobtrd('2012-08-22')
|
68
|
+
s_date = Transactd::btrdtoa(date)
|
69
|
+
expect(s_date).to eq '2012/08/22'
|
70
|
+
#p date
|
71
|
+
#p s_date + ' ' + s_date.encoding.to_s
|
72
|
+
time = Transactd::atobtrt('15:37:00')
|
73
|
+
s_time = Transactd::btrttoa(time)
|
74
|
+
expect(s_time).to eq '15:37:00'
|
75
|
+
#p time
|
76
|
+
#p s_time + ' ' + s_time.encoding.to_s
|
77
|
+
datetime = Transactd::atobtrs('2012-08-22 15:37:00')
|
78
|
+
s_datetime = Transactd::btrstoa(datetime)
|
79
|
+
s_datetime2 = Transactd::btrstoa(datetime, true)
|
80
|
+
expect(s_datetime).to eq '2012/08/22 15:37:00'
|
81
|
+
expect(s_datetime2).to eq '2012-08-22T15:37:00'
|
82
|
+
#p datetime
|
83
|
+
#p s_datetime + ' ' + s_datetime.encoding.to_s
|
84
|
+
#p s_datetime2 + ' ' + s_datetime2.encoding.to_s
|
85
|
+
s_datetime_d = Transactd::btrdtoa(datetime.date)
|
86
|
+
s_datetime_t = Transactd::btrttoa(datetime.time)
|
87
|
+
expect(s_datetime_d + ' ' + s_datetime_t).to eq '2012/08/22 15:37:00'
|
88
|
+
#p s_datetime_d + ' ' + s_datetime_t
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'get Bdate' do
|
92
|
+
date = Transactd::atobtrd('2012-08-22')
|
93
|
+
bdate = Transactd::Bdate.new(date.i)
|
94
|
+
bdate2 = Transactd::Bdate.new(Transactd::btrdtoa(date))
|
95
|
+
#p bdate,bdate2
|
96
|
+
btrdate = bdate.btr_date()
|
97
|
+
btrdate2 = bdate2.btr_date()
|
98
|
+
#p btrdate, btrdate2
|
99
|
+
s_bdate = bdate.c_str()
|
100
|
+
s_bdate2 = bdate2.c_str()
|
101
|
+
expect(s_bdate).to eq s_bdate2
|
102
|
+
#p s_bdate + ' ' + s_bdate.encoding.to_s
|
103
|
+
#p s_bdate2 + ' ' + s_bdate2.encoding.to_s
|
104
|
+
expect(bdate.year()).to eq 2012
|
105
|
+
expect(bdate.month()).to eq 8
|
106
|
+
expect(bdate.date()).to eq 22
|
107
|
+
expect(bdate.year_str()).to eq '2012'
|
108
|
+
expect(bdate.month_str()).to eq '8'
|
109
|
+
expect(bdate.date_str()).to eq '22'
|
110
|
+
#p bdate.year(), bdate.month(), bdate.date()
|
111
|
+
#p bdate.year_str(), bdate.month_str(), bdate.date_str()
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'get BtrTimeStamp from string' do
|
115
|
+
date = Transactd::atobtrd('2012-08-22')
|
116
|
+
time = Transactd::atobtrt('15:37:00')
|
117
|
+
btrts = Transactd::BtrTimeStamp.new('2012-08-22 15:37:00')
|
118
|
+
btrts2 = Transactd::BtrTimeStamp.new(date, time)
|
119
|
+
s_btrts = btrts.toString()
|
120
|
+
s_btrts2 = btrts2.toString()
|
121
|
+
#p btrts, btrts2
|
122
|
+
#p s_btrts, s_btrts2
|
123
|
+
expect(s_btrts).to eq s_btrts2
|
124
|
+
expect(s_btrts).to eq '2012/08/22 15:37:00'
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'get BtrTimeStamp from BtrDate and BtrTime' do
|
128
|
+
i_nowdate = Transactd::getNowDate()
|
129
|
+
nowdate = Transactd::BtrDate.new()
|
130
|
+
nowdate.i = i_nowdate
|
131
|
+
i_nowtime = Transactd::getNowTime()
|
132
|
+
nowtime = Transactd::BtrTime.new()
|
133
|
+
nowtime.i = i_nowtime
|
134
|
+
nowdatetime = Transactd::BtrTimeStamp.new(nowdate, nowtime)
|
135
|
+
s_nowdate = Transactd::btrdtoa(nowdate)
|
136
|
+
s_nowtime = Transactd::btrttoa(nowtime)
|
137
|
+
s_nowdatetime = nowdatetime.toString()
|
138
|
+
expect(s_nowdatetime).to eq s_nowdate + ' ' + s_nowtime
|
139
|
+
#p nowdatetime
|
140
|
+
#p s_nowdatetime + ' ' + s_nowdatetime.encoding.to_s()
|
141
|
+
#p s_nowdate + ' ' + s_nowtime
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'get last year' do
|
145
|
+
i_nowdate = Transactd::getNowDate()
|
146
|
+
nowdate = Transactd::BtrDate.new()
|
147
|
+
nowdate.i = i_nowdate
|
148
|
+
nowyear_yy = nowdate.yy
|
149
|
+
i_nowtime = Transactd::getNowTime()
|
150
|
+
nowtime = Transactd::BtrTime.new()
|
151
|
+
nowtime.i = i_nowtime
|
152
|
+
nowdatetime = Transactd::BtrTimeStamp.new(nowdate, nowtime)
|
153
|
+
s_nowdatetime = nowdatetime.toString()
|
154
|
+
lastyear = nowdate
|
155
|
+
lastyear.yy = lastyear.yy - 1
|
156
|
+
lastyear_yy = lastyear.yy
|
157
|
+
s_lastyear = Transactd::btrdtoa(lastyear)
|
158
|
+
lastyeardatetime = Transactd::BtrTimeStamp.new(lastyear, nowtime)
|
159
|
+
s_lastyeardatetime = lastyeardatetime.toString()
|
160
|
+
expect(nowyear_yy - 1).to eq lastyear_yy
|
161
|
+
expect(s_nowdatetime.sub(nowyear_yy.to_s, lastyear_yy.to_s)).to eq s_lastyeardatetime
|
162
|
+
#p lastyeardatetime
|
163
|
+
#p s_lastyear + ' ' + s_lastyear.encoding.to_s()
|
164
|
+
#p s_lastyeardatetime + ' ' + s_lastyeardatetime.encoding.to_s()
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'get typename' do
|
168
|
+
typename = Transactd::getTypeName(Transactd::Ft_integer)
|
169
|
+
#p typename + ' ' + typename.encoding.to_s
|
170
|
+
expect(typename).to eq 'Integer'
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
# coding : utf-8
|
2
|
+
=begin ============================================================
|
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
|
+
=end
|
21
|
+
require 'transactd'
|
22
|
+
|
23
|
+
require 'rbconfig'
|
24
|
+
IS_WINDOWS = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
|
25
|
+
|
26
|
+
def getHost()
|
27
|
+
hostname = '127.0.0.1/'
|
28
|
+
if (ENV['TRANSACTD_RSPEC_HOST'] != nil && ENV['TRANSACTD_RSPEC_HOST'] != '')
|
29
|
+
hostname = ENV['TRANSACTD_RSPEC_HOST']
|
30
|
+
end
|
31
|
+
hostname = hostname + '/' unless (hostname =~ /\/$/)
|
32
|
+
return hostname
|
33
|
+
end
|
34
|
+
|
35
|
+
HOSTNAME = getHost()
|
36
|
+
URL = 'tdap://' + HOSTNAME + 'test?dbfile=test.bdf'
|
37
|
+
URL_KANJI = 'tdap://' + HOSTNAME + 'テスト?dbfile=構成.bdf'
|
38
|
+
FDI_ID = 0
|
39
|
+
FDN_ID = '番号'.encode('UTF-8')
|
40
|
+
FDI_NAME = 1
|
41
|
+
FDN_NAME = '名前'.encode('UTF-8')
|
42
|
+
|
43
|
+
|
44
|
+
TYPE_SCHEMA_BDF = 0
|
45
|
+
|
46
|
+
def testDropDatabase(db, url)
|
47
|
+
db.open(url)
|
48
|
+
expect(db.stat()).to eq 0
|
49
|
+
db.drop()
|
50
|
+
expect(db.stat()).to eq 0
|
51
|
+
end
|
52
|
+
|
53
|
+
def testCreateDatabase(db, url)
|
54
|
+
db.create(url)
|
55
|
+
if db.stat() == Transactd::STATUS_TABLE_EXISTS_ERROR
|
56
|
+
testDropDatabase(db, url)
|
57
|
+
db.create(url)
|
58
|
+
end
|
59
|
+
expect(db.stat()).to eq 0
|
60
|
+
end
|
61
|
+
|
62
|
+
def testOpenDatabase(db, url)
|
63
|
+
db.open(url, TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL)
|
64
|
+
expect(db.stat()).to eq 0
|
65
|
+
end
|
66
|
+
|
67
|
+
def testCreateTable(db, tableid, tablename)
|
68
|
+
dbdef = db.dbDef()
|
69
|
+
expect(dbdef).not_to be nil
|
70
|
+
td = Transactd::Tabledef.new()
|
71
|
+
### Set table schema codepage to UTF-8
|
72
|
+
# - codepage for field NAME and tableNAME
|
73
|
+
td.schemaCodePage = Transactd::CP_UTF8
|
74
|
+
td.setTableName(tablename.encode('UTF-8'))
|
75
|
+
td.setFileName((tablename + '.dat').encode('UTF-8'))
|
76
|
+
### Set table default charaset index
|
77
|
+
# - default charset for field VALUE
|
78
|
+
td.charsetIndex = Transactd::charsetIndex(Transactd::CP_UTF8)
|
79
|
+
###
|
80
|
+
td.id = tableid
|
81
|
+
td.pageSize = 2048
|
82
|
+
dbdef.insertTable(td)
|
83
|
+
expect(dbdef.stat()).to eq 0
|
84
|
+
fd = dbdef.insertField(tableid, FDI_ID)
|
85
|
+
fd.setName(FDN_ID)
|
86
|
+
fd.type = Transactd::Ft_integer
|
87
|
+
fd.len = 4
|
88
|
+
dbdef.updateTableDef(tableid)
|
89
|
+
expect(dbdef.stat()).to eq 0
|
90
|
+
fd = dbdef.insertField(tableid, FDI_NAME)
|
91
|
+
fd.setName(FDN_NAME)
|
92
|
+
fd.type = Transactd::Ft_zstring
|
93
|
+
fd.len = 33
|
94
|
+
### Set field charset index
|
95
|
+
# - charset for each field VALUE
|
96
|
+
# fd.setCharsetIndex(Transactd::charsetIndex(Transactd::CP_UTF8))
|
97
|
+
dbdef.updateTableDef(tableid)
|
98
|
+
expect(dbdef.stat()).to eq 0
|
99
|
+
kd = dbdef.insertKey(tableid, 0)
|
100
|
+
kd.segment(0).fieldNum = 0
|
101
|
+
kd.segment(0).flags.bit8 = 1
|
102
|
+
kd.segment(0).flags.bit1 = 1
|
103
|
+
kd.segmentCount = 1
|
104
|
+
dbdef.updateTableDef(tableid)
|
105
|
+
expect(dbdef.stat()).to eq 0
|
106
|
+
end
|
107
|
+
|
108
|
+
def testOpenTable(db, tablename)
|
109
|
+
tb = db.openTable(tablename.encode('UTF-8'))
|
110
|
+
expect(db.stat()).to eq 0
|
111
|
+
return tb
|
112
|
+
end
|
113
|
+
|
114
|
+
def testInsert(db, tablename)
|
115
|
+
tb = testOpenTable(db, tablename)
|
116
|
+
expect(tb).not_to be nil
|
117
|
+
tb.clearBuffer()
|
118
|
+
tb.setFV(FDN_ID, 1)
|
119
|
+
tb.setFV(FDN_NAME, '小坂'.encode('UTF-8'))
|
120
|
+
tb.insert()
|
121
|
+
expect(tb.stat()).to eq 0
|
122
|
+
tb.clearBuffer()
|
123
|
+
tb.setFV(FDN_ID, 2)
|
124
|
+
tb.setFV(FDN_NAME, '矢口'.encode('UTF-8'))
|
125
|
+
tb.insert()
|
126
|
+
expect(tb.stat()).to eq 0
|
127
|
+
tb.clearBuffer()
|
128
|
+
tb.setFV(FDN_ID, 3)
|
129
|
+
tb.setFV(FDN_NAME, 'ビズステーション'.encode('UTF-8'))
|
130
|
+
tb.insert()
|
131
|
+
expect(tb.stat()).to eq 0
|
132
|
+
tb.close()
|
133
|
+
end
|
134
|
+
|
135
|
+
def testGetEqual(db, tablename)
|
136
|
+
tb = testOpenTable(db, tablename)
|
137
|
+
expect(tb).not_to be nil
|
138
|
+
tb.clearBuffer()
|
139
|
+
tb.setFV(FDN_ID, 1)
|
140
|
+
tb.seek()
|
141
|
+
expect(tb.getFVstr(FDN_NAME)).to eq '小坂'.encode('UTF-8')
|
142
|
+
tb.close()
|
143
|
+
end
|
144
|
+
|
145
|
+
def testFind(db, tablename)
|
146
|
+
tb = testOpenTable(db, tablename)
|
147
|
+
expect(tb).not_to be nil
|
148
|
+
tb.setKeyNum(0)
|
149
|
+
tb.clearBuffer()
|
150
|
+
tb.setFilter('番号 >= 1 and 番号 < 3'.encode('UTF-8'), 1, 0)
|
151
|
+
tb.setFV(FDN_ID, 1)
|
152
|
+
tb.find(Transactd::Table::FindForword)
|
153
|
+
expect(tb.stat()).to eq 0
|
154
|
+
expect(tb.getFVint(FDN_ID)).to eq 1
|
155
|
+
expect(tb.getFVstr(FDN_NAME)).to eq '小坂'.encode('UTF-8')
|
156
|
+
tb.findNext(true)
|
157
|
+
expect(tb.stat()).to eq 0
|
158
|
+
expect(tb.getFVint(FDN_ID)).to eq 2
|
159
|
+
expect(tb.getFVstr(FDN_NAME)).to eq '矢口'.encode('UTF-8')
|
160
|
+
tb.findNext(true)
|
161
|
+
expect(tb.stat()).to eq Transactd::STATUS_EOF
|
162
|
+
tb.close()
|
163
|
+
end
|
164
|
+
|
165
|
+
def testWhole(db, tableid, tablename, url)
|
166
|
+
tablename = tablename.encode('UTF-8') # table name must be UTF-8
|
167
|
+
testOpenDatabase(db, url)
|
168
|
+
testCreateTable(db, tableid, tablename)
|
169
|
+
testOpenTable(db, tablename)
|
170
|
+
testInsert(db, tablename)
|
171
|
+
testGetEqual(db, tablename)
|
172
|
+
testFind(db, tablename)
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
describe Transactd do
|
177
|
+
before :each do
|
178
|
+
@db = Transactd::Database.createObject()
|
179
|
+
end
|
180
|
+
after :each do
|
181
|
+
@db.close()
|
182
|
+
@db = nil
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'create database' do
|
186
|
+
testCreateDatabase(@db, URL.encode('UTF-8'))
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'table which has kanji-named field' do
|
190
|
+
testWhole(@db, 1, 'kanji-field', URL.encode('UTF-8'))
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'kanji-named table' do
|
194
|
+
testWhole(@db, 2, '漢字テーブル', URL)
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'create kanji-named database' do
|
198
|
+
testCreateDatabase(@db, URL_KANJI.encode('UTF-8')) # URL must be UTF-8
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'table which has kanji-named field' do
|
202
|
+
testWhole(@db, 1, 'kanji-field', URL_KANJI.encode('UTF-8'))
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'kanji-named table' do
|
206
|
+
testWhole(@db, 2, '漢字テーブル', URL_KANJI.encode('UTF-8'))
|
207
|
+
end
|
208
|
+
end
|