transactd 3.5.0-x64-mswin64-100 → 3.6.0-x64-mswin64-100

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,7 +21,7 @@
21
21
  require 'transactd'
22
22
  require 'thwait'
23
23
 
24
- Transactd::setRecordValueMode(Transactd::RECORD_KEYVALUE_FIELDVALUE)
24
+ Transactd::setFieldValueMode(Transactd::FIELD_VALUE_MODE_VALUE)
25
25
 
26
26
  def getEnv(valuename)
27
27
  return ENV[valuename] if ENV[valuename] != nil
@@ -46,10 +46,22 @@ BDFNAME = '?dbfile=' + SCHEMANAME + '.bdf'
46
46
  URL = PROTOCOL + '://' + USERPART + HOSTNAME + '/' + DBNAME + BDFNAME + PASSPART
47
47
  TABLENAME = 'user'
48
48
 
49
+ def getMode(mode)
50
+ mode += 128 if mode <= -128
51
+ mode += 64 if mode <= -64
52
+ mode += 32 if mode <= -32
53
+ mode += 16 if mode <= -16
54
+ return mode
55
+ end
56
+
49
57
  describe Transactd, 'pool' do
50
58
  it 'create ConnectParams' do
51
59
  cp = Transactd::ConnectParams.new(URL)
52
60
  expect(cp.uri()).to eq URL
61
+ cp.setMode(Transactd::TD_OPEN_NORMAL)
62
+ expect(getMode(cp.mode)).to eq Transactd::TD_OPEN_NORMAL
63
+ cp.setMode(Transactd::TD_OPEN_READONLY)
64
+ expect(getMode(cp.mode)).to eq Transactd::TD_OPEN_READONLY
53
65
  cp = Transactd::ConnectParams.new(PROTOCOL, HOSTNAME, DBNAME, SCHEMANAME, USERNAME, PASSWORD)
54
66
  expect(cp.uri()).to eq URL
55
67
  end
@@ -57,8 +69,11 @@ describe Transactd, 'pool' do
57
69
  it 'use connections' do
58
70
  Transactd::PooledDbManager::setMaxConnections(3)
59
71
  cp = Transactd::ConnectParams.new(URL)
72
+ cp.setMode(Transactd::TD_OPEN_READONLY)
73
+ expect(getMode(cp.mode)).to eq Transactd::TD_OPEN_READONLY
60
74
  expect(cp.uri()).to eq URL
61
75
  dbm1 = Transactd::PooledDbManager.new(cp)
76
+ expect(getMode(dbm1.mode)).to eq Transactd::TD_OPEN_READONLY
62
77
  dbm2 = Transactd::PooledDbManager.new(cp)
63
78
  dbm3 = Transactd::PooledDbManager.new(cp)
64
79
  dbm1.unUse()
@@ -73,13 +88,17 @@ describe Transactd, 'pool' do
73
88
  dbm3.unUse()
74
89
  dbm4.unUse()
75
90
  dbm5.unUse()
91
+ dbm1.reset(30)
76
92
  end
77
93
 
78
94
  it 'connect to table' do
79
95
  Transactd::PooledDbManager::setMaxConnections(3)
80
96
  cp = Transactd::ConnectParams.new(URL)
97
+ cp.setMode(Transactd::TD_OPEN_NORMAL)
98
+ expect(getMode(cp.mode)).to eq Transactd::TD_OPEN_NORMAL
81
99
  expect(cp.uri()).to eq URL
82
100
  dbm = Transactd::PooledDbManager.new(cp)
101
+ expect(getMode(dbm.mode)).to eq Transactd::TD_OPEN_NORMAL
83
102
  atu = Transactd::ActiveTable.new(dbm, 'user')
84
103
  q = Transactd::Query.new()
85
104
  atu.alias('名前', 'name')
@@ -93,6 +112,7 @@ describe Transactd, 'pool' do
93
112
  expect(rs[0][2]).to eq 1
94
113
  atu.release()
95
114
  dbm.unUse()
115
+ dbm.reset(30)
96
116
  end
97
117
 
98
118
  it 'can be used in MultiThreads' do
@@ -0,0 +1,450 @@
1
+ # coding : utf-8
2
+ =begin ============================================================
3
+ Copyright (C) 2015 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
+ def getEnv(valuename)
24
+ return ENV[valuename] if ENV[valuename] != nil
25
+ return ''
26
+ end
27
+
28
+ def getHost()
29
+ hostname = getEnv('TRANSACTD_RSPEC_HOST')
30
+ hostname = '127.0.0.1/' if hostname == ''
31
+ hostname = hostname + '/' unless (hostname =~ /\/$/)
32
+ return hostname
33
+ end
34
+
35
+ INT_VALUE = 10
36
+ INT_VALUE_AS_DBL = 10.0
37
+ INT_VALUE_AS_STR = '10'
38
+ INT_NULL = 0
39
+ INT_NULL_AS_DBL = 0.0
40
+ INT_NULL_AS_STR = '0'
41
+
42
+ STR_VALUE = 'テスト'
43
+ STR_NULL = ''
44
+ STR_VALUE_AS_BIN = ["e38386e382b9e38388"].pack('H*')
45
+
46
+ BIN_VALUE = ["e38386e382b900e38388"].pack('H*')
47
+ BIN_VALUE_AS_STR = 'テス' # cut off after 0x00
48
+ BIN_NULL = ''
49
+
50
+ SJIS_VALUE = STR_VALUE.encode("Shift_JIS")
51
+ SJIS_NULL = STR_NULL.encode("Shift_JIS")
52
+
53
+ SJIS_BIN_VALUE = ["83658358008367"].pack('H*')
54
+ SJIS_BIN_VALUE_AS_STR = BIN_VALUE_AS_STR.encode("Shift_JIS") # cut off after 0x00
55
+ SJIS_BIN_NULL = BIN_NULL.encode("Shift_JIS")
56
+
57
+ FI_numNotNull = 1
58
+ FI_numNullable = 2
59
+ FI_strNotNull = 3
60
+ FI_strNullable = 4
61
+ FI_binNotNull = 5
62
+ FI_binNullable = 6
63
+ FI_binSJISNotNull = 7
64
+ FI_binSJISNullable = 8
65
+
66
+ HOSTNAME = getHost()
67
+ USERNAME = getEnv('TRANSACTD_RSPEC_USER')
68
+ USERPART = USERNAME == '' ? '' : USERNAME + '@'
69
+ PASSWORD = getEnv('TRANSACTD_RSPEC_PASS')
70
+ PASSPART = PASSWORD == '' ? '' : '&pwd=' + PASSWORD
71
+ DBNAME = 'testsetget'
72
+ TABLENAME = 'setget'
73
+ URL = 'tdap://' + USERPART + HOSTNAME + DBNAME + '?dbfile=transactd_schema' + PASSPART
74
+
75
+ def createTable(db)
76
+ dbdef = db.dbDef()
77
+ td = Transactd::Tabledef.new()
78
+ td.charsetIndex = Transactd::CHARSET_UTF8
79
+ td.setTableName(TABLENAME)
80
+ td.setFileName(TABLENAME + '.dat')
81
+ table_id = 1
82
+ td.id = table_id
83
+ td.pageSize = 2048
84
+ dbdef.insertTable(td)
85
+ expect(dbdef.stat()).to eq 0
86
+ # 0: id
87
+ fd = dbdef.insertField(table_id, 0)
88
+ fd.setName('id')
89
+ fd.type = Transactd::Ft_autoinc
90
+ fd.len = 4
91
+ fd.setNullable(false)
92
+ # 1: numNotNull
93
+ fd = dbdef.insertField(table_id, FI_numNotNull)
94
+ fd.setName('numNotNull')
95
+ fd.type = Transactd::Ft_integer
96
+ fd.len = 1
97
+ fd.setNullable(false)
98
+ # 2: numNullable
99
+ fd = dbdef.insertField(table_id, FI_numNullable)
100
+ fd.setName('numNullable')
101
+ fd.type = Transactd::Ft_integer
102
+ fd.len = 1
103
+ fd.setNullable(true)
104
+ # 3: strNotNull
105
+ fd = dbdef.insertField(table_id, FI_strNotNull)
106
+ fd.setName('strNotNull')
107
+ fd.type = Transactd::Ft_myvarchar
108
+ fd.setLenByCharnum(40)
109
+ fd.setNullable(false)
110
+ # 4: strNullable
111
+ fd = dbdef.insertField(table_id, FI_strNullable)
112
+ fd.setName('strNullable')
113
+ fd.type = Transactd::Ft_myvarchar
114
+ fd.setLenByCharnum(40)
115
+ fd.setNullable(true)
116
+ # 5: binNotNull
117
+ fd = dbdef.insertField(table_id, FI_binNotNull)
118
+ fd.setName('binNotNull')
119
+ fd.type = Transactd::Ft_myblob
120
+ fd.len = 9
121
+ fd.setNullable(false)
122
+ fd.setCharsetIndex(Transactd::charsetIndex("binary"))
123
+ # 6: binNullable
124
+ fd = dbdef.insertField(table_id, FI_binNullable)
125
+ fd.setName('binNullable')
126
+ fd.type = Transactd::Ft_myblob
127
+ fd.len = 9
128
+ fd.setNullable(true)
129
+ fd.setCharsetIndex(Transactd::charsetIndex("binary"))
130
+ # 7: binSJISNotNull
131
+ fd = dbdef.insertField(table_id, FI_binSJISNotNull)
132
+ fd.setName('binSJISNotNull')
133
+ fd.type = Transactd::Ft_myblob
134
+ fd.len = 9
135
+ fd.setNullable(false)
136
+ fd.setCharsetIndex(Transactd::charsetIndex("cp932"))
137
+ # 8: binSJISNullable
138
+ fd = dbdef.insertField(table_id, FI_binSJISNullable)
139
+ fd.setName('binSJISNullable')
140
+ fd.type = Transactd::Ft_myblob
141
+ fd.len = 9
142
+ fd.setNullable(true)
143
+ fd.setCharsetIndex(Transactd::charsetIndex("cp932"))
144
+ # primary key
145
+ kd = dbdef.insertKey(table_id, 0)
146
+ kd.segment(0).fieldNum = 0
147
+ kd.segment(0).flags.bit8 = 1
148
+ kd.segment(0).flags.bit1 = 1
149
+ kd.segmentCount = 1
150
+ td.primaryKeyNum = 0
151
+ # save schema
152
+ dbdef.updateTableDef(table_id)
153
+ expect(dbdef.stat()).to eq 0
154
+ # open table
155
+ tb = db.openTable(TABLENAME)
156
+ # insert test data
157
+ # id:1
158
+ tb.clearBuffer()
159
+ tb.setFV(FI_numNotNull, INT_VALUE)
160
+ tb.setFV(FI_strNotNull, STR_VALUE)
161
+ tb.setFV(FI_binNotNull, BIN_VALUE, BIN_VALUE.length)
162
+ tb.setFV(FI_binSJISNotNull, STR_VALUE)
163
+ tb.insert()
164
+ expect(tb.stat()).to eq 0
165
+ # id:2
166
+ tb.clearBuffer()
167
+ tb.setFV(FI_numNotNull, INT_VALUE)
168
+ tb.setFV(FI_numNullable, INT_VALUE)
169
+ tb.setFV(FI_strNotNull, STR_VALUE)
170
+ tb.setFV(FI_strNullable, BIN_VALUE)
171
+ tb.setFV(FI_binNotNull, STR_VALUE)
172
+ tb.setFV(FI_binNullable, BIN_VALUE, BIN_VALUE.length)
173
+ tb.setFV(FI_binSJISNotNull, STR_VALUE)
174
+ tb.setFV(FI_binSJISNullable, SJIS_BIN_VALUE, SJIS_BIN_VALUE.length)
175
+ tb.insert()
176
+ expect(tb.stat()).to eq 0
177
+ tb.close
178
+ end
179
+
180
+ def createDatabase
181
+ db = Transactd::Database.new()
182
+ db.open(URL, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL)
183
+ if db.stat() != Transactd::ERROR_NO_DATABASE
184
+ expect(db.stat()).to eq 0
185
+ db.drop()
186
+ expect(db.stat()).to eq 0
187
+ end
188
+ db.create(URL)
189
+ expect(db.stat()).to eq 0
190
+ db.open(URL, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL)
191
+ expect(db.stat()).to eq 0
192
+ createTable(db)
193
+ db.close
194
+ end
195
+
196
+ def testTableGetFVX(tb)
197
+ tb.seekFirst()
198
+ expect(tb.stat()).to eq 0
199
+ # numNotNull
200
+ expect(tb.getFVNull(FI_numNotNull)).to be false
201
+ expect( tb.getFVint(FI_numNotNull)).to eq INT_VALUE
202
+ expect( tb.getFV64(FI_numNotNull)).to eq INT_VALUE
203
+ expect( tb.getFVdbl(FI_numNotNull)).to eq INT_VALUE_AS_DBL
204
+ expect( tb.getFVstr(FI_numNotNull)).to eq INT_VALUE_AS_STR
205
+ # numNullable
206
+ expect(tb.getFVNull(FI_numNullable)).to be true
207
+ expect( tb.getFVint(FI_numNullable)).to eq INT_NULL
208
+ expect( tb.getFV64(FI_numNullable)).to eq INT_NULL
209
+ expect( tb.getFVdbl(FI_numNullable)).to eq INT_NULL_AS_DBL
210
+ expect( tb.getFVstr(FI_numNullable)).to eq INT_NULL_AS_STR
211
+ # strNotNull
212
+ expect(tb.getFVNull(FI_strNotNull)).to be false
213
+ expect( tb.getFVstr(FI_strNotNull)).to eq STR_VALUE
214
+ bin = tb.getFVbin(FI_strNotNull)
215
+ expect(bin.encoding).to eq Encoding::ASCII_8BIT
216
+ expect(bin.force_encoding("utf-8")).to eq STR_VALUE
217
+ # strNullable
218
+ expect(tb.getFVNull(FI_strNullable)).to be true
219
+ expect( tb.getFVstr(FI_strNullable)).to eq STR_NULL
220
+ bin = tb.getFVbin(FI_strNullable)
221
+ expect(bin.encoding).to eq Encoding::ASCII_8BIT
222
+ expect(bin.force_encoding("utf-8")).to eq STR_NULL
223
+ # binNotNull
224
+ expect(tb.getFVNull(FI_binNotNull)).to be false
225
+ expect( tb.getFVstr(FI_binNotNull)).to eq BIN_VALUE_AS_STR
226
+ bin = tb.getFVbin(FI_binNotNull)
227
+ expect(bin.encoding).to eq Encoding::ASCII_8BIT
228
+ expect(bin).to eq BIN_VALUE
229
+ # binNullable
230
+ expect(tb.getFVNull(FI_binNullable)).to be true
231
+ expect( tb.getFVstr(FI_binNullable)).to eq BIN_NULL
232
+ bin = tb.getFVbin(FI_binNullable)
233
+ expect(bin.encoding).to eq Encoding::ASCII_8BIT
234
+ expect(bin).to eq BIN_NULL
235
+ # binSJISNotNull
236
+ expect(tb.getFVNull(FI_binSJISNotNull)).to be false
237
+ expect( tb.getFVstr(FI_binSJISNotNull)).to eq STR_VALUE # getFVstr converts value to utf_8 from shift_jis.
238
+ bin = tb.getFVbin(FI_binSJISNotNull) # getFVbin does not convert encoding.
239
+ expect(bin.encoding).to eq Encoding::ASCII_8BIT
240
+ expect(bin.force_encoding("Shift_JIS")).to eq SJIS_VALUE
241
+ # binSJISNotNull
242
+ expect(tb.getFVNull(FI_binSJISNullable)).to be true
243
+ expect( tb.getFVstr(FI_binSJISNullable)).to eq STR_NULL
244
+ bin = tb.getFVbin(FI_binSJISNullable)
245
+ expect(bin.encoding).to eq Encoding::ASCII_8BIT
246
+ expect(bin.force_encoding("Shift_JIS")).to eq STR_NULL
247
+ end
248
+
249
+ def testTableSetFV(tb)
250
+ tb.seekFirst()
251
+ expect(tb.stat()).to eq 0
252
+ # SET VALUE AS BINARY
253
+ # setFV does not convert the values if length parameter is passed.
254
+ tb.setFV(FI_binSJISNotNull, SJIS_BIN_VALUE, SJIS_BIN_VALUE.length) # SJIS_BIN_VALUE will not be converted.
255
+ str = tb.getFVstr(FI_binSJISNotNull) # getFVstr converts value to utf_8 from shift_jis.
256
+ expect(str.encoding).to eq Encoding::UTF_8
257
+ expect(str).to eq BIN_VALUE_AS_STR # the string value will end with null (0x00) character.
258
+ bin = tb.getFVbin(FI_binSJISNotNull) # getFVbin does not convert encoding.
259
+ expect(bin.encoding).to eq Encoding::ASCII_8BIT
260
+ expect(bin).to eq SJIS_BIN_VALUE # the binary value can contain null (0x00) characters.
261
+ # SET VALUE AS STRING
262
+ # setFV converts the values if length parameter is not passed.
263
+ tb.setFV(FI_binSJISNotNull, BIN_VALUE) # BIN_VALUE will be converted to Shift_JIS from utf_8.
264
+ str = tb.getFVstr(FI_binSJISNotNull) # getFVstr converts value to utf_8 from shift_jis.
265
+ expect(str.encoding).to eq Encoding::UTF_8
266
+ expect(str).to eq BIN_VALUE_AS_STR # the string value will end with null (0x00) character.
267
+ bin = tb.getFVbin(FI_binSJISNotNull) # getFVbin does not convert encoding.
268
+ expect(bin.encoding).to eq Encoding::ASCII_8BIT
269
+ expect(bin.force_encoding("Shift_JIS")).to eq SJIS_BIN_VALUE_AS_STR
270
+ # the value end with null (0x00) character on setFV (because it regarded as string).
271
+ end
272
+
273
+ def testTableGetMethods_CheckArrayValue(arr)
274
+ # string values
275
+ expect(arr[FI_strNotNull].encoding).to eq Encoding::UTF_8
276
+ expect(arr[FI_strNotNull]).to eq STR_VALUE
277
+ expect(arr[FI_strNullable].encoding).to eq Encoding::UTF_8
278
+ expect(arr[FI_strNullable]).to eq BIN_VALUE_AS_STR # cut by null
279
+ # binary values
280
+ expect(arr[FI_binNotNull].encoding).to eq Encoding::ASCII_8BIT
281
+ expect(arr[FI_binNotNull]).to eq STR_VALUE_AS_BIN
282
+ expect(arr[FI_binNullable].encoding).to eq Encoding::ASCII_8BIT
283
+ expect(arr[FI_binNullable]).to eq BIN_VALUE
284
+ # shift_jis string in binary field (automatically converted into utf_8)
285
+ expect(arr[FI_binSJISNotNull].encoding).to eq Encoding::UTF_8
286
+ expect(arr[FI_binSJISNotNull]).to eq STR_VALUE
287
+ expect(arr[FI_binSJISNullable].encoding).to eq Encoding::UTF_8
288
+ expect(arr[FI_binSJISNullable]).to eq BIN_VALUE_AS_STR # cut by null
289
+ end
290
+
291
+ def testTableGetMethods_CheckObjValue(obj)
292
+ # string values
293
+ expect(obj.strNotNull.encoding).to eq Encoding::UTF_8
294
+ expect(obj.strNotNull).to eq STR_VALUE
295
+ expect(obj.strNullable.encoding).to eq Encoding::UTF_8
296
+ expect(obj.strNullable).to eq BIN_VALUE_AS_STR # cut by null
297
+ # binary values
298
+ expect(obj.binNotNull.encoding).to eq Encoding::ASCII_8BIT
299
+ expect(obj.binNotNull).to eq STR_VALUE_AS_BIN
300
+ expect(obj.binNullable.encoding).to eq Encoding::ASCII_8BIT
301
+ expect(obj.binNullable).to eq BIN_VALUE
302
+ # shift_jis string in binary field (automatically converted into utf_8)
303
+ expect(obj.binSJISNotNull.encoding).to eq Encoding::UTF_8
304
+ expect(obj.binSJISNotNull).to eq STR_VALUE
305
+ expect(obj.binSJISNullable.encoding).to eq Encoding::UTF_8
306
+ expect(obj.binSJISNullable).to eq BIN_VALUE_AS_STR # cut by null
307
+ end
308
+
309
+ def testTableGetMethods(tb)
310
+ tb.setKeyNum(0)
311
+ expect(tb.stat()).to eq 0
312
+ tb.seekFirst()
313
+ expect(tb.stat()).to eq 0
314
+ tb.seekNext()
315
+ expect(tb.stat()).to eq 0
316
+ Transactd::set_field_value_mode(Transactd::FIELD_VALUE_MODE_VALUE)
317
+ # get values as array
318
+ tb.fetchMode = Transactd::FETCH_VAL_NUM
319
+ testTableGetMethods_CheckArrayValue(tb.fields)
320
+ # get values as obj
321
+ tb.fetchMode = Transactd::FETCH_OBJ
322
+ testTableGetMethods_CheckObjValue(tb.fields)
323
+ # findAll
324
+ q = Transactd::Query.new()
325
+ tb.clearBuffer()
326
+ expect(tb.stat()).to eq 0
327
+ tb.setQuery(q)
328
+ expect(tb.stat()).to eq 0
329
+ # get values as array
330
+ tb.seekFirst()
331
+ expect(tb.stat()).to eq 0
332
+ tb.fetchMode = Transactd::FETCH_VAL_NUM
333
+ arr = tb.findAll
334
+ expect(arr.length).to eq 2
335
+ testTableGetMethods_CheckArrayValue(arr[1])
336
+ # get values as obj
337
+ tb.seekFirst()
338
+ expect(tb.stat()).to eq 0
339
+ tb.fetchMode = Transactd::FETCH_OBJ
340
+ arr = tb.findAll
341
+ expect(arr.length).to eq 2
342
+ testTableGetMethods_CheckObjValue(arr[1])
343
+ end
344
+
345
+ def testField(tb)
346
+ tb.setKeyNum(0)
347
+ expect(tb.stat()).to eq 0
348
+ tb.seekFirst()
349
+ expect(tb.stat()).to eq 0
350
+ tb.seekNext()
351
+ expect(tb.stat()).to eq 0
352
+ Transactd::field_value_mode = Transactd::FIELD_VALUE_MODE_VALUE
353
+ tb.fetchMode = Transactd::FETCH_RECORD_INTO
354
+ rec = tb.fields
355
+ # get with []
356
+ testTableGetMethods_CheckArrayValue(rec)
357
+ # set with []=
358
+ rec[FI_strNotNull] = STR_VALUE
359
+ expect(rec[FI_strNotNull].encoding).to eq Encoding::UTF_8
360
+ expect(rec[FI_strNotNull]).to eq STR_VALUE
361
+ rec[FI_strNullable] = STR_VALUE_AS_BIN
362
+ expect(rec[FI_strNullable].encoding).to eq Encoding::UTF_8
363
+ expect(rec[FI_strNullable]).to eq STR_VALUE
364
+ rec[FI_binNotNull] = BIN_VALUE
365
+ expect(rec[FI_binNotNull].encoding).to eq Encoding::ASCII_8BIT
366
+ expect(rec[FI_binNotNull]).to eq BIN_VALUE
367
+ rec[FI_binNullable] = STR_VALUE
368
+ expect(rec[FI_binNullable].encoding).to eq Encoding::ASCII_8BIT
369
+ expect(rec[FI_binNullable]).to eq STR_VALUE_AS_BIN
370
+ rec[FI_binSJISNotNull] = STR_VALUE
371
+ expect(rec[FI_binSJISNotNull].encoding).to eq Encoding::UTF_8
372
+ expect(rec[FI_binSJISNotNull]).to eq STR_VALUE
373
+ rec[FI_binSJISNullable] = STR_VALUE
374
+ expect(rec[FI_binSJISNullable].encoding).to eq Encoding::UTF_8
375
+ expect(rec[FI_binSJISNullable]).to eq STR_VALUE
376
+ # set with set_value_by_object(obj)
377
+ tb.fetchMode = Transactd::FETCH_OBJ
378
+ obj = tb.fields
379
+ obj.strNotNull = STR_VALUE
380
+ obj.strNullable = BIN_VALUE
381
+ obj.binNotNull = STR_VALUE
382
+ obj.binNullable = BIN_VALUE
383
+ obj.binSJISNotNull = STR_VALUE
384
+ obj.binSJISNullable = BIN_VALUE
385
+ tb.clearBuffer
386
+ rec.set_value_by_object(obj)
387
+ testTableGetMethods_CheckArrayValue(rec)
388
+ end
389
+
390
+ def testRecordset(rs)
391
+ expect(rs.size).to eq 2
392
+ # get with [] as array
393
+ rs.fetchMode = Transactd::FETCH_VAL_NUM
394
+ testTableGetMethods_CheckArrayValue(rs[1])
395
+ # get with [] as obj
396
+ rs.fetchMode = Transactd::FETCH_OBJ
397
+ testTableGetMethods_CheckObjValue(rs[1])
398
+ # get with to_a as array
399
+ rs.fetchMode = Transactd::FETCH_VAL_NUM
400
+ arr = rs.to_a
401
+ expect(arr.length).to eq 2
402
+ testTableGetMethods_CheckArrayValue(arr[1])
403
+ # get with to_a as obj
404
+ rs.fetchMode = Transactd::FETCH_OBJ
405
+ arr = rs.to_a
406
+ expect(arr.length).to eq 2
407
+ testTableGetMethods_CheckObjValue(arr[1])
408
+ end
409
+
410
+ describe Transactd, 'set get values' do
411
+ it 'prepare database and table' do
412
+ createDatabase
413
+ end
414
+
415
+ it 'get values from table' do
416
+ db = Transactd::Database.new()
417
+ db.open(URL, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL)
418
+ expect(db.stat()).to eq 0
419
+ tb = db.openTable(TABLENAME)
420
+ expect(db.stat()).to eq 0
421
+ testTableGetFVX(tb)
422
+ testTableSetFV(tb)
423
+ testTableGetMethods(tb)
424
+ tb.close
425
+ db.close
426
+ end
427
+
428
+ it 'get/set values from/to record' do
429
+ db = Transactd::Database.new()
430
+ db.open(URL, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL)
431
+ expect(db.stat()).to eq 0
432
+ tb = db.openTable(TABLENAME)
433
+ expect(db.stat()).to eq 0
434
+ testField(tb)
435
+ tb.close
436
+ db.close
437
+ end
438
+
439
+ it 'get values from recordset' do
440
+ db = Transactd::Database.new()
441
+ db.open(URL, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL)
442
+ expect(db.stat()).to eq 0
443
+ at = Transactd::ActiveTable.new(db, TABLENAME)
444
+ q = Transactd::Query.new()
445
+ rs = at.index(0).keyValue(1).read(q)
446
+ at.release
447
+ testRecordset(rs)
448
+ db.close
449
+ end
450
+ end
@@ -23,7 +23,7 @@ require 'transactd'
23
23
  require 'rbconfig'
24
24
  IS_WINDOWS = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
25
25
 
26
- Transactd::setRecordValueMode(Transactd::RECORD_KEYVALUE_FIELDVALUE)
26
+ Transactd::setFieldValueMode(Transactd::FIELD_VALUE_MODE_VALUE)
27
27
 
28
28
  def getEnv(valuename)
29
29
  return ENV[valuename] if ENV[valuename] != nil
@@ -84,18 +84,27 @@ def testCreateDatabase(db)
84
84
  expect(db.stat()).to eq 0
85
85
  end
86
86
 
87
+ def getMode(mode)
88
+ mode += 128 if mode <= -128
89
+ mode += 64 if mode <= -64
90
+ mode += 32 if mode <= -32
91
+ mode += 16 if mode <= -16
92
+ return mode
93
+ end
94
+
87
95
  def testOpenDatabase(db)
88
96
  db.open(URL, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_NORMAL)
89
97
  expect(db.stat()).to eq 0
98
+ expect(getMode(db.mode)).to eq Transactd::TD_OPEN_NORMAL
90
99
  # test statMsg
91
100
  msg = db.statMsg()
92
101
  expect(msg).to eq ''
93
-
94
102
  end
95
103
 
96
104
  def testCreateTable(db)
97
105
  testOpenDatabase(db)
98
106
  dbdef = db.dbDef()
107
+ expect(getMode(dbdef.mode)).to eq Transactd::TD_OPEN_NORMAL
99
108
  expect(dbdef).not_to be nil
100
109
  td = Transactd::Tabledef.new()
101
110
  td.setTableName(TABLENAME)
@@ -192,6 +201,7 @@ def testOpenTable(db)
192
201
  testOpenDatabase(db)
193
202
  tb = db.openTable(TABLENAME)
194
203
  expect(db.stat()).to eq 0
204
+ expect(getMode(tb.mode)).to eq Transactd::TD_OPEN_NORMAL
195
205
  return tb
196
206
  end
197
207
 
@@ -1505,6 +1515,7 @@ def testExclusive()
1505
1515
  # ------------------------------------------------------
1506
1516
  db.open(URL, Transactd::TYPE_SCHEMA_BDF, Transactd::TD_OPEN_EXCLUSIVE)
1507
1517
  expect(db.stat()).to eq 0
1518
+ expect(getMode(db.mode)).to eq Transactd::TD_OPEN_EXCLUSIVE
1508
1519
  tb = db.openTable(TABLENAME)
1509
1520
  expect(db.stat()).to eq 0
1510
1521
 
@@ -1516,6 +1527,7 @@ def testExclusive()
1516
1527
  # database open error. Check database::stat()
1517
1528
  expect(db2.stat()).to eq Transactd::STATUS_CANNOT_LOCK_TABLE
1518
1529
  dd = db.dbDef()
1530
+ expect(getMode(dd.mode)).to eq Transactd::TD_OPEN_EXCLUSIVE
1519
1531
  td = dd.tableDefs(1)
1520
1532
  dd.updateTableDef(1)
1521
1533
  expect(dd.stat()).to eq 0