fireruby 0.4.1-mswin32 → 0.4.2-mswin32
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.
- data/doc/README +456 -456
- data/doc/license.txt +411 -411
- data/examples/example01.rb +65 -65
- data/lib/SQLType.rb +223 -227
- data/lib/fireruby.rb +22 -22
- data/lib/fr_lib.so +0 -0
- data/lib/mkdoc +1 -1
- data/lib/src.rb +1795 -1795
- data/test/AddRemoveUserTest.rb +56 -55
- data/test/BackupRestoreTest.rb +99 -99
- data/test/BlobTest.rb +57 -0
- data/test/CharacterSetTest.rb +63 -63
- data/test/ConnectionTest.rb +111 -111
- data/test/DDLTest.rb +54 -54
- data/test/DatabaseTest.rb +83 -83
- data/test/GeneratorTest.rb +50 -50
- data/test/KeyTest.rb +140 -140
- data/test/ResultSetTest.rb +162 -162
- data/test/RoleTest.rb +73 -0
- data/test/RowCountTest.rb +65 -65
- data/test/RowTest.rb +203 -203
- data/test/SQLTest.rb +182 -182
- data/test/SQLTypeTest.rb +101 -101
- data/test/ServiceManagerTest.rb +29 -29
- data/test/StatementTest.rb +135 -135
- data/test/TestSetup.rb +11 -11
- data/test/TransactionTest.rb +112 -112
- data/test/TypeTest.rb +92 -92
- data/test/UnitTest.rb +65 -64
- metadata +49 -110
- data/doc/CVS/Entries +0 -3
- data/doc/CVS/Entries.Log +0 -2
- data/doc/CVS/Repository +0 -1
- data/doc/CVS/Root +0 -1
- data/doc/classes/CVS/Entries +0 -1
- data/doc/classes/CVS/Entries.Log +0 -1
- data/doc/classes/CVS/Repository +0 -1
- data/doc/classes/CVS/Root +0 -1
- data/doc/classes/FireRuby/CVS/Entries +0 -1
- data/doc/classes/FireRuby/CVS/Entries.Log +0 -7
- data/doc/classes/FireRuby/CVS/Repository +0 -1
- data/doc/classes/FireRuby/CVS/Root +0 -1
- data/doc/classes/FireRuby/Connection.src/CVS/Entries +0 -1
- data/doc/classes/FireRuby/Connection.src/CVS/Repository +0 -1
- data/doc/classes/FireRuby/Connection.src/CVS/Root +0 -1
- data/doc/classes/FireRuby/Database.src/CVS/Entries +0 -1
- data/doc/classes/FireRuby/Database.src/CVS/Repository +0 -1
- data/doc/classes/FireRuby/Database.src/CVS/Root +0 -1
- data/doc/classes/FireRuby/FireRubyError.src/CVS/Entries +0 -1
- data/doc/classes/FireRuby/FireRubyError.src/CVS/Repository +0 -1
- data/doc/classes/FireRuby/FireRubyError.src/CVS/Root +0 -1
- data/doc/classes/FireRuby/Generator.src/CVS/Entries +0 -1
- data/doc/classes/FireRuby/Generator.src/CVS/Repository +0 -1
- data/doc/classes/FireRuby/Generator.src/CVS/Root +0 -1
- data/doc/classes/FireRuby/ResultSet.src/CVS/Entries +0 -1
- data/doc/classes/FireRuby/ResultSet.src/CVS/Repository +0 -1
- data/doc/classes/FireRuby/ResultSet.src/CVS/Root +0 -1
- data/doc/classes/FireRuby/Statement.src/CVS/Entries +0 -1
- data/doc/classes/FireRuby/Statement.src/CVS/Repository +0 -1
- data/doc/classes/FireRuby/Statement.src/CVS/Root +0 -1
- data/doc/classes/FireRuby/Transaction.src/CVS/Entries +0 -1
- data/doc/classes/FireRuby/Transaction.src/CVS/Repository +0 -1
- data/doc/classes/FireRuby/Transaction.src/CVS/Root +0 -1
- data/doc/files/CVS/Entries +0 -1
- data/doc/files/CVS/Repository +0 -1
- data/doc/files/CVS/Root +0 -1
- data/examples/CVS/Entries +0 -2
- data/examples/CVS/Repository +0 -1
- data/examples/CVS/Root +0 -1
- data/lib/CVS/Entries +0 -6
- data/lib/CVS/Repository +0 -1
- data/lib/CVS/Root +0 -1
- data/test/CVS/Entries +0 -20
- data/test/CVS/Repository +0 -1
- data/test/CVS/Root +0 -1
data/test/RoleTest.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'fireruby'
|
7
|
+
|
8
|
+
include FireRuby
|
9
|
+
|
10
|
+
class RoleTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}role_unit_test.fdb"
|
13
|
+
|
14
|
+
def setup
|
15
|
+
puts "#{self.class.name} started." if TEST_LOGGING
|
16
|
+
# Remove existing database files.
|
17
|
+
@database = Database.new(DB_FILE)
|
18
|
+
if File.exist?(DB_FILE)
|
19
|
+
@database.drop(DB_USER_NAME, DB_PASSWORD)
|
20
|
+
end
|
21
|
+
Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
22
|
+
|
23
|
+
@sm = ServiceManager.new('localhost')
|
24
|
+
@sm.connect(DB_USER_NAME, DB_PASSWORD)
|
25
|
+
|
26
|
+
au = AddUser.new('user1', 'password', 'first', 'middle', 'last')
|
27
|
+
au.execute(@sm)
|
28
|
+
sleep(3)
|
29
|
+
end
|
30
|
+
|
31
|
+
def teardown
|
32
|
+
ru = RemoveUser.new('user1')
|
33
|
+
ru.execute(@sm)
|
34
|
+
sleep(3)
|
35
|
+
|
36
|
+
@sm.disconnect
|
37
|
+
|
38
|
+
# Remove existing database files.
|
39
|
+
if File.exist?(DB_FILE)
|
40
|
+
@database.drop(DB_USER_NAME, DB_PASSWORD)
|
41
|
+
end
|
42
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
43
|
+
end
|
44
|
+
|
45
|
+
def test01
|
46
|
+
cxn = @database.connect(DB_USER_NAME, DB_PASSWORD)
|
47
|
+
cxn.execute_immediate('CREATE TABLE TEST (field1 INTEGER)')
|
48
|
+
cxn.execute_immediate('CREATE role myrole')
|
49
|
+
cxn.execute_immediate('GRANT myrole to user1')
|
50
|
+
cxn.execute_immediate('GRANT ALL on TEST to myrole')
|
51
|
+
cxn.close
|
52
|
+
|
53
|
+
cxn = @database.connect('user1', 'password')
|
54
|
+
assert_raise FireRubyException do
|
55
|
+
t1 = cxn.start_transaction
|
56
|
+
r = ResultSet.new(cxn, t1, "select * from test", 3, nil)
|
57
|
+
r.fetch
|
58
|
+
r.close
|
59
|
+
t1.commit
|
60
|
+
end
|
61
|
+
cxn.close
|
62
|
+
|
63
|
+
cxn = @database.connect('user1', 'password', {Connection::SQL_ROLE_NAME => "myrole"})
|
64
|
+
assert_nothing_raised do
|
65
|
+
t1 = cxn.start_transaction
|
66
|
+
r = ResultSet.new(cxn, t1, "select * from test", 3, nil)
|
67
|
+
r.fetch
|
68
|
+
r.close
|
69
|
+
t1.commit
|
70
|
+
end
|
71
|
+
cxn.close
|
72
|
+
end
|
73
|
+
end
|
data/test/RowCountTest.rb
CHANGED
@@ -1,65 +1,65 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'TestSetup'
|
4
|
-
require 'test/unit'
|
5
|
-
require 'rubygems'
|
6
|
-
require 'fireruby'
|
7
|
-
|
8
|
-
include FireRuby
|
9
|
-
|
10
|
-
class RowCountTest < Test::Unit::TestCase
|
11
|
-
CURDIR = "#{Dir.getwd}"
|
12
|
-
DB_FILE = "#{CURDIR}#{File::SEPARATOR}row_count_test.fdb"
|
13
|
-
|
14
|
-
def setup
|
15
|
-
puts "#{self.class.name} started." if TEST_LOGGING
|
16
|
-
# Create the database for use in testing.
|
17
|
-
if File.exist?(DB_FILE)
|
18
|
-
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
19
|
-
end
|
20
|
-
@database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
21
|
-
|
22
|
-
# Create the test table.
|
23
|
-
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
24
|
-
cxn.execute_immediate('create table test(id integer)')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
def teardown
|
30
|
-
if File.exist?(DB_FILE)
|
31
|
-
@database.drop(DB_USER_NAME, DB_PASSWORD)
|
32
|
-
end
|
33
|
-
puts "#{self.class.name} finished." if TEST_LOGGING
|
34
|
-
end
|
35
|
-
|
36
|
-
def test01
|
37
|
-
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
38
|
-
cxn.start_transaction do |tx|
|
39
|
-
assert(cxn.execute_immediate('insert into test values (1000)') == 1)
|
40
|
-
assert(cxn.execute_immediate('insert into test values (1000)') == 1)
|
41
|
-
assert(cxn.execute('insert into test values (2000)', tx) == 1)
|
42
|
-
assert(cxn.execute('insert into test values (2000)', tx) == 1)
|
43
|
-
assert(tx.execute('insert into test values (3000)') == 1)
|
44
|
-
assert(tx.execute('insert into test values (3000)') == 1)
|
45
|
-
assert(tx.execute('insert into test values (4000)') == 1)
|
46
|
-
assert(tx.execute('insert into test values (4000)') == 1)
|
47
|
-
|
48
|
-
assert(cxn.execute_immediate('update test set id = 10000 where '\
|
49
|
-
'id = 1000') == 2)
|
50
|
-
assert(cxn.execute('update test set id = 20000 where id = 2000',
|
51
|
-
tx) == 2)
|
52
|
-
assert(tx.execute('update test set id = 30000 where id = 3000') == 2)
|
53
|
-
|
54
|
-
s = Statement.new(cxn, tx, 'update test set id = 40000 where id = ?',
|
55
|
-
3)
|
56
|
-
assert(s.execute_for([4000]) == 2)
|
57
|
-
|
58
|
-
|
59
|
-
assert(cxn.execute_immediate('delete from test where id = 10000') == 2)
|
60
|
-
assert(cxn.execute('delete from test where id = 20000', tx) == 2)
|
61
|
-
assert(tx.execute('delete from test where id = 30000') == 2)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'fireruby'
|
7
|
+
|
8
|
+
include FireRuby
|
9
|
+
|
10
|
+
class RowCountTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}row_count_test.fdb"
|
13
|
+
|
14
|
+
def setup
|
15
|
+
puts "#{self.class.name} started." if TEST_LOGGING
|
16
|
+
# Create the database for use in testing.
|
17
|
+
if File.exist?(DB_FILE)
|
18
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
19
|
+
end
|
20
|
+
@database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
21
|
+
|
22
|
+
# Create the test table.
|
23
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
24
|
+
cxn.execute_immediate('create table test(id integer)')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
if File.exist?(DB_FILE)
|
31
|
+
@database.drop(DB_USER_NAME, DB_PASSWORD)
|
32
|
+
end
|
33
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
34
|
+
end
|
35
|
+
|
36
|
+
def test01
|
37
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
38
|
+
cxn.start_transaction do |tx|
|
39
|
+
assert(cxn.execute_immediate('insert into test values (1000)') == 1)
|
40
|
+
assert(cxn.execute_immediate('insert into test values (1000)') == 1)
|
41
|
+
assert(cxn.execute('insert into test values (2000)', tx) == 1)
|
42
|
+
assert(cxn.execute('insert into test values (2000)', tx) == 1)
|
43
|
+
assert(tx.execute('insert into test values (3000)') == 1)
|
44
|
+
assert(tx.execute('insert into test values (3000)') == 1)
|
45
|
+
assert(tx.execute('insert into test values (4000)') == 1)
|
46
|
+
assert(tx.execute('insert into test values (4000)') == 1)
|
47
|
+
|
48
|
+
assert(cxn.execute_immediate('update test set id = 10000 where '\
|
49
|
+
'id = 1000') == 2)
|
50
|
+
assert(cxn.execute('update test set id = 20000 where id = 2000',
|
51
|
+
tx) == 2)
|
52
|
+
assert(tx.execute('update test set id = 30000 where id = 3000') == 2)
|
53
|
+
|
54
|
+
s = Statement.new(cxn, tx, 'update test set id = 40000 where id = ?',
|
55
|
+
3)
|
56
|
+
assert(s.execute_for([4000]) == 2)
|
57
|
+
|
58
|
+
|
59
|
+
assert(cxn.execute_immediate('delete from test where id = 10000') == 2)
|
60
|
+
assert(cxn.execute('delete from test where id = 20000', tx) == 2)
|
61
|
+
assert(tx.execute('delete from test where id = 30000') == 2)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/test/RowTest.rb
CHANGED
@@ -1,203 +1,203 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'TestSetup'
|
4
|
-
require 'test/unit'
|
5
|
-
require 'rubygems'
|
6
|
-
require 'fireruby'
|
7
|
-
|
8
|
-
include FireRuby
|
9
|
-
|
10
|
-
class RowTest < Test::Unit::TestCase
|
11
|
-
CURDIR = "#{Dir.getwd}"
|
12
|
-
DB_FILE = "#{CURDIR}#{File::SEPARATOR}row_unit_test.fdb"
|
13
|
-
|
14
|
-
def setup
|
15
|
-
puts "#{self.class.name} started." if TEST_LOGGING
|
16
|
-
if File::exist?(DB_FILE)
|
17
|
-
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
18
|
-
end
|
19
|
-
|
20
|
-
database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
21
|
-
@connection = database.connect(DB_USER_NAME, DB_PASSWORD)
|
22
|
-
@transaction = @connection.start_transaction
|
23
|
-
@results = ResultSet.new(@connection, @transaction,
|
24
|
-
'SELECT * FROM RDB$FIELDS', 3, nil)
|
25
|
-
@empty = [[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
26
|
-
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
27
|
-
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
28
|
-
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
29
|
-
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
30
|
-
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
31
|
-
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
32
|
-
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
33
|
-
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
34
|
-
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
35
|
-
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
36
|
-
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
37
|
-
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
38
|
-
[0, SQLType::INTEGER], [0, SQLType::INTEGER]]
|
39
|
-
|
40
|
-
@connection.start_transaction do |tx|
|
41
|
-
tx.execute('create table rowtest (COL01 integer, COL02 varchar(10), '\
|
42
|
-
'COL03 integer)')
|
43
|
-
tx.execute('create table all_types (col01 bigint, col02 blob, '\
|
44
|
-
'col03 char(100), col04 date, col05 decimal(5,2), '\
|
45
|
-
'col06 double precision, col07 float, col08 integer, '\
|
46
|
-
'col09 numeric(10,3), col10 smallint, col11 time, '\
|
47
|
-
'col12 timestamp, col13 varchar(23))')
|
48
|
-
end
|
49
|
-
@connection.start_transaction do |tx|
|
50
|
-
tx.execute("insert into rowtest values (1, 'Two', 3)")
|
51
|
-
|
52
|
-
stmt = Statement.new(@connection, tx,
|
53
|
-
"insert into all_types values(?, ?, ?, ?, ?, ?, "\
|
54
|
-
"?, ?, ?, ?, ?, ?, ?)",
|
55
|
-
3)
|
56
|
-
#stmt.execute_for([nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil])
|
57
|
-
stmt.execute_for([100000, nil, 'La la la', Date.new(2005, 10, 29),
|
58
|
-
10.23, 100.751, 56.25, 12345, 19863.21, 123,
|
59
|
-
Time.new, Time.new, 'The End!'])
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def teardown
|
64
|
-
@results.close
|
65
|
-
@transaction.rollback
|
66
|
-
@connection.close
|
67
|
-
if File::exist?(DB_FILE)
|
68
|
-
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
69
|
-
end
|
70
|
-
puts "#{self.class.name} finished." if TEST_LOGGING
|
71
|
-
end
|
72
|
-
|
73
|
-
def test01
|
74
|
-
row = Row.new(@results, @empty, 100)
|
75
|
-
|
76
|
-
assert(row.column_count == 28)
|
77
|
-
assert(row.number == 100)
|
78
|
-
assert(row.column_name(0) == 'RDB$FIELD_NAME')
|
79
|
-
assert(row.column_alias(10) == 'RDB$FIELD_TYPE')
|
80
|
-
assert(row[0] == 0)
|
81
|
-
assert(row['RDB$FIELD_TYPE'] == 0)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test02
|
85
|
-
sql = 'select COL01 one, COL02 two, COL03 three from rowtest'
|
86
|
-
rows = @connection.execute_immediate(sql)
|
87
|
-
data = rows.fetch
|
88
|
-
|
89
|
-
count = 0
|
90
|
-
data.each do |name, value|
|
91
|
-
assert(['ONE', 'TWO', 'THREE'].include?(name))
|
92
|
-
assert([1, 'Two', 3].include?(value))
|
93
|
-
count += 1
|
94
|
-
end
|
95
|
-
assert(count == 3)
|
96
|
-
|
97
|
-
count = 0
|
98
|
-
data.each_key do |name|
|
99
|
-
assert(['ONE', 'TWO', 'THREE'].include?(name))
|
100
|
-
count += 1
|
101
|
-
end
|
102
|
-
assert(count == 3)
|
103
|
-
|
104
|
-
count = 0
|
105
|
-
data.each_value do |value|
|
106
|
-
assert([1, 'Two', 3].include?(value))
|
107
|
-
count += 1
|
108
|
-
end
|
109
|
-
assert(count == 3)
|
110
|
-
|
111
|
-
assert(data.fetch('TWO') == 'Two')
|
112
|
-
assert(data.fetch('FOUR', 'LALALA') == 'LALALA')
|
113
|
-
assert(data.fetch('ZERO') {'NOT FOUND'} == 'NOT FOUND')
|
114
|
-
begin
|
115
|
-
data.fetch('FIVE')
|
116
|
-
assert(false, 'Row#fetch succeeded for non-existent column name.')
|
117
|
-
rescue IndexError
|
118
|
-
end
|
119
|
-
|
120
|
-
assert(data.has_key?('ONE'))
|
121
|
-
assert(data.has_key?('TEN') == false)
|
122
|
-
|
123
|
-
assert(data.has_column?('COL02'))
|
124
|
-
assert(data.has_column?('COL22') == false)
|
125
|
-
|
126
|
-
assert(data.has_alias?('TWO'))
|
127
|
-
assert(data.has_alias?('FOUR') == false)
|
128
|
-
|
129
|
-
assert(data.has_value?(3))
|
130
|
-
assert(data.has_value?('LALALA') == false)
|
131
|
-
|
132
|
-
assert(data.keys.size == 3)
|
133
|
-
data.keys.each do |name|
|
134
|
-
assert(['ONE', 'TWO', 'THREE'].include?(name))
|
135
|
-
end
|
136
|
-
|
137
|
-
assert(data.names.size == 3)
|
138
|
-
data.names.each do |name|
|
139
|
-
assert(['COL01', 'COL02', 'COL03'].include?(name))
|
140
|
-
end
|
141
|
-
|
142
|
-
assert(data.aliases.size == 3)
|
143
|
-
data.aliases.each do |name|
|
144
|
-
assert(['ONE', 'TWO', 'THREE'].include?(name))
|
145
|
-
end
|
146
|
-
|
147
|
-
assert(data.values.size == 3)
|
148
|
-
data.values.each do |value|
|
149
|
-
assert([1, 'Two', 3].include?(value))
|
150
|
-
end
|
151
|
-
|
152
|
-
array = data.select {|name, value| name == 'TWO'}
|
153
|
-
assert(array.size == 1)
|
154
|
-
assert(array[0][0] == 'TWO')
|
155
|
-
assert(array[0][1] == 'Two')
|
156
|
-
|
157
|
-
array = data.to_a
|
158
|
-
assert(array.size == 3)
|
159
|
-
assert(array.include?(['ONE', 1]))
|
160
|
-
assert(array.include?(['TWO', 'Two']))
|
161
|
-
assert(array.include?(['THREE', 3]))
|
162
|
-
|
163
|
-
hash = data.to_hash
|
164
|
-
assert(hash.length == 3)
|
165
|
-
assert(hash['ONE'] == 1)
|
166
|
-
assert(hash['TWO'] == 'Two')
|
167
|
-
assert(hash['THREE'] == 3)
|
168
|
-
|
169
|
-
array = data.values_at('TEN', 'TWO', 'THREE')
|
170
|
-
assert(array.size == 3)
|
171
|
-
assert(array.include?('Two'))
|
172
|
-
assert(array.include?(3))
|
173
|
-
assert(array.include?(nil))
|
174
|
-
|
175
|
-
rows.close
|
176
|
-
end
|
177
|
-
|
178
|
-
def test03
|
179
|
-
results = nil
|
180
|
-
row = nil
|
181
|
-
|
182
|
-
begin
|
183
|
-
results = @connection.execute_immediate('select * from all_types')
|
184
|
-
row = results.fetch
|
185
|
-
|
186
|
-
assert(row.get_base_type(0) == SQLType::BIGINT)
|
187
|
-
assert(row.get_base_type(1) == SQLType::BLOB)
|
188
|
-
assert(row.get_base_type(2) == SQLType::CHAR)
|
189
|
-
assert(row.get_base_type(3) == SQLType::DATE)
|
190
|
-
assert(row.get_base_type(4) == SQLType::DECIMAL)
|
191
|
-
assert(row.get_base_type(5) == SQLType::DOUBLE)
|
192
|
-
assert(row.get_base_type(6) == SQLType::FLOAT)
|
193
|
-
assert(row.get_base_type(7) == SQLType::INTEGER)
|
194
|
-
assert(row.get_base_type(8) == SQLType::NUMERIC)
|
195
|
-
assert(row.get_base_type(9) == SQLType::SMALLINT)
|
196
|
-
assert(row.get_base_type(10) == SQLType::TIME)
|
197
|
-
assert(row.get_base_type(11) == SQLType::TIMESTAMP)
|
198
|
-
assert(row.get_base_type(12) == SQLType::VARCHAR)
|
199
|
-
ensure
|
200
|
-
results.close if results != nil
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'fireruby'
|
7
|
+
|
8
|
+
include FireRuby
|
9
|
+
|
10
|
+
class RowTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}row_unit_test.fdb"
|
13
|
+
|
14
|
+
def setup
|
15
|
+
puts "#{self.class.name} started." if TEST_LOGGING
|
16
|
+
if File::exist?(DB_FILE)
|
17
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
18
|
+
end
|
19
|
+
|
20
|
+
database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
21
|
+
@connection = database.connect(DB_USER_NAME, DB_PASSWORD)
|
22
|
+
@transaction = @connection.start_transaction
|
23
|
+
@results = ResultSet.new(@connection, @transaction,
|
24
|
+
'SELECT * FROM RDB$FIELDS', 3, nil)
|
25
|
+
@empty = [[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
26
|
+
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
27
|
+
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
28
|
+
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
29
|
+
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
30
|
+
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
31
|
+
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
32
|
+
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
33
|
+
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
34
|
+
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
35
|
+
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
36
|
+
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
37
|
+
[0, SQLType::INTEGER], [0, SQLType::INTEGER],
|
38
|
+
[0, SQLType::INTEGER], [0, SQLType::INTEGER]]
|
39
|
+
|
40
|
+
@connection.start_transaction do |tx|
|
41
|
+
tx.execute('create table rowtest (COL01 integer, COL02 varchar(10), '\
|
42
|
+
'COL03 integer)')
|
43
|
+
tx.execute('create table all_types (col01 bigint, col02 blob, '\
|
44
|
+
'col03 char(100), col04 date, col05 decimal(5,2), '\
|
45
|
+
'col06 double precision, col07 float, col08 integer, '\
|
46
|
+
'col09 numeric(10,3), col10 smallint, col11 time, '\
|
47
|
+
'col12 timestamp, col13 varchar(23))')
|
48
|
+
end
|
49
|
+
@connection.start_transaction do |tx|
|
50
|
+
tx.execute("insert into rowtest values (1, 'Two', 3)")
|
51
|
+
|
52
|
+
stmt = Statement.new(@connection, tx,
|
53
|
+
"insert into all_types values(?, ?, ?, ?, ?, ?, "\
|
54
|
+
"?, ?, ?, ?, ?, ?, ?)",
|
55
|
+
3)
|
56
|
+
#stmt.execute_for([nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil])
|
57
|
+
stmt.execute_for([100000, nil, 'La la la', Date.new(2005, 10, 29),
|
58
|
+
10.23, 100.751, 56.25, 12345, 19863.21, 123,
|
59
|
+
Time.new, Time.new, 'The End!'])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def teardown
|
64
|
+
@results.close
|
65
|
+
@transaction.rollback
|
66
|
+
@connection.close
|
67
|
+
if File::exist?(DB_FILE)
|
68
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
69
|
+
end
|
70
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
71
|
+
end
|
72
|
+
|
73
|
+
def test01
|
74
|
+
row = Row.new(@results, @empty, 100)
|
75
|
+
|
76
|
+
assert(row.column_count == 28)
|
77
|
+
assert(row.number == 100)
|
78
|
+
assert(row.column_name(0) == 'RDB$FIELD_NAME')
|
79
|
+
assert(row.column_alias(10) == 'RDB$FIELD_TYPE')
|
80
|
+
assert(row[0] == 0)
|
81
|
+
assert(row['RDB$FIELD_TYPE'] == 0)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test02
|
85
|
+
sql = 'select COL01 one, COL02 two, COL03 three from rowtest'
|
86
|
+
rows = @connection.execute_immediate(sql)
|
87
|
+
data = rows.fetch
|
88
|
+
|
89
|
+
count = 0
|
90
|
+
data.each do |name, value|
|
91
|
+
assert(['ONE', 'TWO', 'THREE'].include?(name))
|
92
|
+
assert([1, 'Two', 3].include?(value))
|
93
|
+
count += 1
|
94
|
+
end
|
95
|
+
assert(count == 3)
|
96
|
+
|
97
|
+
count = 0
|
98
|
+
data.each_key do |name|
|
99
|
+
assert(['ONE', 'TWO', 'THREE'].include?(name))
|
100
|
+
count += 1
|
101
|
+
end
|
102
|
+
assert(count == 3)
|
103
|
+
|
104
|
+
count = 0
|
105
|
+
data.each_value do |value|
|
106
|
+
assert([1, 'Two', 3].include?(value))
|
107
|
+
count += 1
|
108
|
+
end
|
109
|
+
assert(count == 3)
|
110
|
+
|
111
|
+
assert(data.fetch('TWO') == 'Two')
|
112
|
+
assert(data.fetch('FOUR', 'LALALA') == 'LALALA')
|
113
|
+
assert(data.fetch('ZERO') {'NOT FOUND'} == 'NOT FOUND')
|
114
|
+
begin
|
115
|
+
data.fetch('FIVE')
|
116
|
+
assert(false, 'Row#fetch succeeded for non-existent column name.')
|
117
|
+
rescue IndexError
|
118
|
+
end
|
119
|
+
|
120
|
+
assert(data.has_key?('ONE'))
|
121
|
+
assert(data.has_key?('TEN') == false)
|
122
|
+
|
123
|
+
assert(data.has_column?('COL02'))
|
124
|
+
assert(data.has_column?('COL22') == false)
|
125
|
+
|
126
|
+
assert(data.has_alias?('TWO'))
|
127
|
+
assert(data.has_alias?('FOUR') == false)
|
128
|
+
|
129
|
+
assert(data.has_value?(3))
|
130
|
+
assert(data.has_value?('LALALA') == false)
|
131
|
+
|
132
|
+
assert(data.keys.size == 3)
|
133
|
+
data.keys.each do |name|
|
134
|
+
assert(['ONE', 'TWO', 'THREE'].include?(name))
|
135
|
+
end
|
136
|
+
|
137
|
+
assert(data.names.size == 3)
|
138
|
+
data.names.each do |name|
|
139
|
+
assert(['COL01', 'COL02', 'COL03'].include?(name))
|
140
|
+
end
|
141
|
+
|
142
|
+
assert(data.aliases.size == 3)
|
143
|
+
data.aliases.each do |name|
|
144
|
+
assert(['ONE', 'TWO', 'THREE'].include?(name))
|
145
|
+
end
|
146
|
+
|
147
|
+
assert(data.values.size == 3)
|
148
|
+
data.values.each do |value|
|
149
|
+
assert([1, 'Two', 3].include?(value))
|
150
|
+
end
|
151
|
+
|
152
|
+
array = data.select {|name, value| name == 'TWO'}
|
153
|
+
assert(array.size == 1)
|
154
|
+
assert(array[0][0] == 'TWO')
|
155
|
+
assert(array[0][1] == 'Two')
|
156
|
+
|
157
|
+
array = data.to_a
|
158
|
+
assert(array.size == 3)
|
159
|
+
assert(array.include?(['ONE', 1]))
|
160
|
+
assert(array.include?(['TWO', 'Two']))
|
161
|
+
assert(array.include?(['THREE', 3]))
|
162
|
+
|
163
|
+
hash = data.to_hash
|
164
|
+
assert(hash.length == 3)
|
165
|
+
assert(hash['ONE'] == 1)
|
166
|
+
assert(hash['TWO'] == 'Two')
|
167
|
+
assert(hash['THREE'] == 3)
|
168
|
+
|
169
|
+
array = data.values_at('TEN', 'TWO', 'THREE')
|
170
|
+
assert(array.size == 3)
|
171
|
+
assert(array.include?('Two'))
|
172
|
+
assert(array.include?(3))
|
173
|
+
assert(array.include?(nil))
|
174
|
+
|
175
|
+
rows.close
|
176
|
+
end
|
177
|
+
|
178
|
+
def test03
|
179
|
+
results = nil
|
180
|
+
row = nil
|
181
|
+
|
182
|
+
begin
|
183
|
+
results = @connection.execute_immediate('select * from all_types')
|
184
|
+
row = results.fetch
|
185
|
+
|
186
|
+
assert(row.get_base_type(0) == SQLType::BIGINT)
|
187
|
+
assert(row.get_base_type(1) == SQLType::BLOB)
|
188
|
+
assert(row.get_base_type(2) == SQLType::CHAR)
|
189
|
+
assert(row.get_base_type(3) == SQLType::DATE)
|
190
|
+
assert(row.get_base_type(4) == SQLType::DECIMAL)
|
191
|
+
assert(row.get_base_type(5) == SQLType::DOUBLE)
|
192
|
+
assert(row.get_base_type(6) == SQLType::FLOAT)
|
193
|
+
assert(row.get_base_type(7) == SQLType::INTEGER)
|
194
|
+
assert(row.get_base_type(8) == SQLType::NUMERIC)
|
195
|
+
assert(row.get_base_type(9) == SQLType::SMALLINT)
|
196
|
+
assert(row.get_base_type(10) == SQLType::TIME)
|
197
|
+
assert(row.get_base_type(11) == SQLType::TIMESTAMP)
|
198
|
+
assert(row.get_base_type(12) == SQLType::VARCHAR)
|
199
|
+
ensure
|
200
|
+
results.close if results != nil
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|