fireruby 0.4.1-mswin32 → 0.4.2-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/doc/README +456 -456
  2. data/doc/license.txt +411 -411
  3. data/examples/example01.rb +65 -65
  4. data/lib/SQLType.rb +223 -227
  5. data/lib/fireruby.rb +22 -22
  6. data/lib/fr_lib.so +0 -0
  7. data/lib/mkdoc +1 -1
  8. data/lib/src.rb +1795 -1795
  9. data/test/AddRemoveUserTest.rb +56 -55
  10. data/test/BackupRestoreTest.rb +99 -99
  11. data/test/BlobTest.rb +57 -0
  12. data/test/CharacterSetTest.rb +63 -63
  13. data/test/ConnectionTest.rb +111 -111
  14. data/test/DDLTest.rb +54 -54
  15. data/test/DatabaseTest.rb +83 -83
  16. data/test/GeneratorTest.rb +50 -50
  17. data/test/KeyTest.rb +140 -140
  18. data/test/ResultSetTest.rb +162 -162
  19. data/test/RoleTest.rb +73 -0
  20. data/test/RowCountTest.rb +65 -65
  21. data/test/RowTest.rb +203 -203
  22. data/test/SQLTest.rb +182 -182
  23. data/test/SQLTypeTest.rb +101 -101
  24. data/test/ServiceManagerTest.rb +29 -29
  25. data/test/StatementTest.rb +135 -135
  26. data/test/TestSetup.rb +11 -11
  27. data/test/TransactionTest.rb +112 -112
  28. data/test/TypeTest.rb +92 -92
  29. data/test/UnitTest.rb +65 -64
  30. metadata +49 -110
  31. data/doc/CVS/Entries +0 -3
  32. data/doc/CVS/Entries.Log +0 -2
  33. data/doc/CVS/Repository +0 -1
  34. data/doc/CVS/Root +0 -1
  35. data/doc/classes/CVS/Entries +0 -1
  36. data/doc/classes/CVS/Entries.Log +0 -1
  37. data/doc/classes/CVS/Repository +0 -1
  38. data/doc/classes/CVS/Root +0 -1
  39. data/doc/classes/FireRuby/CVS/Entries +0 -1
  40. data/doc/classes/FireRuby/CVS/Entries.Log +0 -7
  41. data/doc/classes/FireRuby/CVS/Repository +0 -1
  42. data/doc/classes/FireRuby/CVS/Root +0 -1
  43. data/doc/classes/FireRuby/Connection.src/CVS/Entries +0 -1
  44. data/doc/classes/FireRuby/Connection.src/CVS/Repository +0 -1
  45. data/doc/classes/FireRuby/Connection.src/CVS/Root +0 -1
  46. data/doc/classes/FireRuby/Database.src/CVS/Entries +0 -1
  47. data/doc/classes/FireRuby/Database.src/CVS/Repository +0 -1
  48. data/doc/classes/FireRuby/Database.src/CVS/Root +0 -1
  49. data/doc/classes/FireRuby/FireRubyError.src/CVS/Entries +0 -1
  50. data/doc/classes/FireRuby/FireRubyError.src/CVS/Repository +0 -1
  51. data/doc/classes/FireRuby/FireRubyError.src/CVS/Root +0 -1
  52. data/doc/classes/FireRuby/Generator.src/CVS/Entries +0 -1
  53. data/doc/classes/FireRuby/Generator.src/CVS/Repository +0 -1
  54. data/doc/classes/FireRuby/Generator.src/CVS/Root +0 -1
  55. data/doc/classes/FireRuby/ResultSet.src/CVS/Entries +0 -1
  56. data/doc/classes/FireRuby/ResultSet.src/CVS/Repository +0 -1
  57. data/doc/classes/FireRuby/ResultSet.src/CVS/Root +0 -1
  58. data/doc/classes/FireRuby/Statement.src/CVS/Entries +0 -1
  59. data/doc/classes/FireRuby/Statement.src/CVS/Repository +0 -1
  60. data/doc/classes/FireRuby/Statement.src/CVS/Root +0 -1
  61. data/doc/classes/FireRuby/Transaction.src/CVS/Entries +0 -1
  62. data/doc/classes/FireRuby/Transaction.src/CVS/Repository +0 -1
  63. data/doc/classes/FireRuby/Transaction.src/CVS/Root +0 -1
  64. data/doc/files/CVS/Entries +0 -1
  65. data/doc/files/CVS/Repository +0 -1
  66. data/doc/files/CVS/Root +0 -1
  67. data/examples/CVS/Entries +0 -2
  68. data/examples/CVS/Repository +0 -1
  69. data/examples/CVS/Root +0 -1
  70. data/lib/CVS/Entries +0 -6
  71. data/lib/CVS/Repository +0 -1
  72. data/lib/CVS/Root +0 -1
  73. data/test/CVS/Entries +0 -20
  74. data/test/CVS/Repository +0 -1
  75. data/test/CVS/Root +0 -1
@@ -1,50 +1,50 @@
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 GeneratorTest < Test::Unit::TestCase
11
- CURDIR = "#{Dir.getwd}"
12
- DB_FILE = "#{CURDIR}#{File::SEPARATOR}generator_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
- @database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
20
- @connections = []
21
-
22
- @connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
23
- end
24
-
25
- def teardown
26
- @connections.each do |cxn|
27
- cxn.close if cxn.open?
28
- end
29
- @connections.clear
30
- if File::exist?(DB_FILE)
31
- Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
32
- end
33
- puts "#{self.class.name} finished." if TEST_LOGGING
34
- end
35
-
36
- def test01
37
- assert(Generator::exists?('TEST_GEN', @connections[0]) == false)
38
- g = Generator::create('TEST_GEN', @connections[0])
39
- assert(Generator::exists?('TEST_GEN', @connections[0]))
40
- assert(g.last == 0)
41
- assert(g.next(1) == 1)
42
- assert(g.last == 1)
43
- assert(g.next(10) == 11)
44
- assert(g.connection == @connections[0])
45
- assert(g.name == 'TEST_GEN')
46
-
47
- g.drop
48
- assert(Generator::exists?('TEST_GEN', @connections[0]) == false)
49
- end
50
- 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 GeneratorTest < Test::Unit::TestCase
11
+ CURDIR = "#{Dir.getwd}"
12
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}generator_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
+ @database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
20
+ @connections = []
21
+
22
+ @connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
23
+ end
24
+
25
+ def teardown
26
+ @connections.each do |cxn|
27
+ cxn.close if cxn.open?
28
+ end
29
+ @connections.clear
30
+ if File::exist?(DB_FILE)
31
+ Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
32
+ end
33
+ puts "#{self.class.name} finished." if TEST_LOGGING
34
+ end
35
+
36
+ def test01
37
+ assert(Generator::exists?('TEST_GEN', @connections[0]) == false)
38
+ g = Generator::create('TEST_GEN', @connections[0])
39
+ assert(Generator::exists?('TEST_GEN', @connections[0]))
40
+ assert(g.last == 0)
41
+ assert(g.next(1) == 1)
42
+ assert(g.last == 1)
43
+ assert(g.next(10) == 11)
44
+ assert(g.connection == @connections[0])
45
+ assert(g.name == 'TEST_GEN')
46
+
47
+ g.drop
48
+ assert(Generator::exists?('TEST_GEN', @connections[0]) == false)
49
+ end
50
+ end
data/test/KeyTest.rb CHANGED
@@ -1,140 +1,140 @@
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 KeyTest < Test::Unit::TestCase
11
- CURDIR = "#{Dir.getwd}"
12
- DB_FILE = "#{CURDIR}#{File::SEPARATOR}key_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
- # Switch to the old way of keying.
21
- $FireRubySettings[:ALIAS_KEYS] = false
22
-
23
- database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
24
- @connection = database.connect(DB_USER_NAME, DB_PASSWORD)
25
- @transaction = @connection.start_transaction
26
- @results = ResultSet.new(@connection, @transaction,
27
- 'SELECT * FROM RDB$FIELDS', 3, nil)
28
- @empty = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
29
- 0, 0, 0, 0, 0, 0, 0, 0, 0]
30
-
31
- @connection.execute_immediate('create table keytest (COL01 integer, '\
32
- 'COL02 varchar(10), COL03 integer)')
33
- @connection.execute_immediate("insert into keytest values (1, 'Two', 3)")
34
- end
35
-
36
- def teardown
37
- @results.close
38
- @transaction.rollback
39
- @connection.close
40
- if File::exist?(DB_FILE)
41
- Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
42
- end
43
- $FireRubySettings[:ALIAS_KEYS] = true
44
- puts "#{self.class.name} finished." if TEST_LOGGING
45
- end
46
-
47
- def test_01
48
- sql = 'select COL01 one, COL02 two, COL03 three from keytest'
49
- rows = @connection.execute_immediate(sql)
50
- data = rows.fetch
51
-
52
- count = 0
53
- data.each do |name, value|
54
- assert(['COL01', 'COL02', 'COL03'].include?(name))
55
- assert([1, 'Two', 3].include?(value))
56
- count += 1
57
- end
58
- assert(count == 3)
59
-
60
- count = 0
61
- data.each_key do |name|
62
- assert(['COL01', 'COL02', 'COL03'].include?(name))
63
- count += 1
64
- end
65
- assert(count == 3)
66
-
67
- count = 0
68
- data.each_value do |value|
69
- assert([1, 'Two', 3].include?(value))
70
- count += 1
71
- end
72
- assert(count == 3)
73
-
74
- assert(data.fetch('COL02') == 'Two')
75
- assert(data.fetch('COL04', 'LALALA') == 'LALALA')
76
- assert(data.fetch('COL00') {'NOT FOUND'} == 'NOT FOUND')
77
- begin
78
- data.fetch('COL05')
79
- assert(false, 'Row#fetch succeeded for non-existent column name.')
80
- rescue IndexError
81
- end
82
-
83
- assert(data.has_key?('COL01'))
84
- assert(data.has_key?('COL10') == false)
85
-
86
- assert(data.has_column?('COL02'))
87
- assert(data.has_column?('COL22') == false)
88
-
89
- assert(data.has_alias?('TWO'))
90
- assert(data.has_alias?('FOUR') == false)
91
-
92
- assert(data.has_value?(3))
93
- assert(data.has_value?('LALALA') == false)
94
-
95
- assert(data.keys.size == 3)
96
- data.keys.each do |name|
97
- assert(['COL01', 'COL02', 'COL03'].include?(name))
98
- end
99
-
100
- assert(data.names.size == 3)
101
- data.names.each do |name|
102
- assert(['COL01', 'COL02', 'COL03'].include?(name))
103
- end
104
-
105
- assert(data.aliases.size == 3)
106
- data.aliases.each do |name|
107
- assert(['ONE', 'TWO', 'THREE'].include?(name))
108
- end
109
-
110
- assert(data.values.size == 3)
111
- data.values.each do |value|
112
- assert([1, 'Two', 3].include?(value))
113
- end
114
-
115
- array = data.select {|name, value| name == 'COL02'}
116
- assert(array.size == 1)
117
- assert(array[0][0] == 'COL02')
118
- assert(array[0][1] == 'Two')
119
-
120
- array = data.to_a
121
- assert(array.size == 3)
122
- assert(array.include?(['COL01', 1]))
123
- assert(array.include?(['COL02', 'Two']))
124
- assert(array.include?(['COL03', 3]))
125
-
126
- hash = data.to_hash
127
- assert(hash.length == 3)
128
- assert(hash['COL01'] == 1)
129
- assert(hash['COL02'] == 'Two')
130
- assert(hash['COL03'] == 3)
131
-
132
- array = data.values_at('COL10', 'COL02', 'COL03')
133
- assert(array.size == 3)
134
- assert(array.include?('Two'))
135
- assert(array.include?(3))
136
- assert(array.include?(nil))
137
-
138
- rows.close
139
- end
140
- 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 KeyTest < Test::Unit::TestCase
11
+ CURDIR = "#{Dir.getwd}"
12
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}key_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
+ # Switch to the old way of keying.
21
+ $FireRubySettings[:ALIAS_KEYS] = false
22
+
23
+ database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
24
+ @connection = database.connect(DB_USER_NAME, DB_PASSWORD)
25
+ @transaction = @connection.start_transaction
26
+ @results = ResultSet.new(@connection, @transaction,
27
+ 'SELECT * FROM RDB$FIELDS', 3, nil)
28
+ @empty = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
29
+ 0, 0, 0, 0, 0, 0, 0, 0, 0]
30
+
31
+ @connection.execute_immediate('create table keytest (COL01 integer, '\
32
+ 'COL02 varchar(10), COL03 integer)')
33
+ @connection.execute_immediate("insert into keytest values (1, 'Two', 3)")
34
+ end
35
+
36
+ def teardown
37
+ @results.close
38
+ @transaction.rollback
39
+ @connection.close
40
+ if File::exist?(DB_FILE)
41
+ Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
42
+ end
43
+ $FireRubySettings[:ALIAS_KEYS] = true
44
+ puts "#{self.class.name} finished." if TEST_LOGGING
45
+ end
46
+
47
+ def test_01
48
+ sql = 'select COL01 one, COL02 two, COL03 three from keytest'
49
+ rows = @connection.execute_immediate(sql)
50
+ data = rows.fetch
51
+
52
+ count = 0
53
+ data.each do |name, value|
54
+ assert(['COL01', 'COL02', 'COL03'].include?(name))
55
+ assert([1, 'Two', 3].include?(value))
56
+ count += 1
57
+ end
58
+ assert(count == 3)
59
+
60
+ count = 0
61
+ data.each_key do |name|
62
+ assert(['COL01', 'COL02', 'COL03'].include?(name))
63
+ count += 1
64
+ end
65
+ assert(count == 3)
66
+
67
+ count = 0
68
+ data.each_value do |value|
69
+ assert([1, 'Two', 3].include?(value))
70
+ count += 1
71
+ end
72
+ assert(count == 3)
73
+
74
+ assert(data.fetch('COL02') == 'Two')
75
+ assert(data.fetch('COL04', 'LALALA') == 'LALALA')
76
+ assert(data.fetch('COL00') {'NOT FOUND'} == 'NOT FOUND')
77
+ begin
78
+ data.fetch('COL05')
79
+ assert(false, 'Row#fetch succeeded for non-existent column name.')
80
+ rescue IndexError
81
+ end
82
+
83
+ assert(data.has_key?('COL01'))
84
+ assert(data.has_key?('COL10') == false)
85
+
86
+ assert(data.has_column?('COL02'))
87
+ assert(data.has_column?('COL22') == false)
88
+
89
+ assert(data.has_alias?('TWO'))
90
+ assert(data.has_alias?('FOUR') == false)
91
+
92
+ assert(data.has_value?(3))
93
+ assert(data.has_value?('LALALA') == false)
94
+
95
+ assert(data.keys.size == 3)
96
+ data.keys.each do |name|
97
+ assert(['COL01', 'COL02', 'COL03'].include?(name))
98
+ end
99
+
100
+ assert(data.names.size == 3)
101
+ data.names.each do |name|
102
+ assert(['COL01', 'COL02', 'COL03'].include?(name))
103
+ end
104
+
105
+ assert(data.aliases.size == 3)
106
+ data.aliases.each do |name|
107
+ assert(['ONE', 'TWO', 'THREE'].include?(name))
108
+ end
109
+
110
+ assert(data.values.size == 3)
111
+ data.values.each do |value|
112
+ assert([1, 'Two', 3].include?(value))
113
+ end
114
+
115
+ array = data.select {|name, value| name == 'COL02'}
116
+ assert(array.size == 1)
117
+ assert(array[0][0] == 'COL02')
118
+ assert(array[0][1] == 'Two')
119
+
120
+ array = data.to_a
121
+ assert(array.size == 3)
122
+ assert(array.include?(['COL01', 1]))
123
+ assert(array.include?(['COL02', 'Two']))
124
+ assert(array.include?(['COL03', 3]))
125
+
126
+ hash = data.to_hash
127
+ assert(hash.length == 3)
128
+ assert(hash['COL01'] == 1)
129
+ assert(hash['COL02'] == 'Two')
130
+ assert(hash['COL03'] == 3)
131
+
132
+ array = data.values_at('COL10', 'COL02', 'COL03')
133
+ assert(array.size == 3)
134
+ assert(array.include?('Two'))
135
+ assert(array.include?(3))
136
+ assert(array.include?(nil))
137
+
138
+ rows.close
139
+ end
140
+ end
@@ -1,162 +1,162 @@
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 ResultSetTest < Test::Unit::TestCase
11
- CURDIR = "#{Dir.getwd}"
12
- DB_FILE = "#{CURDIR}#{File::SEPARATOR}result_set_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
- @database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
20
- @connections = []
21
- @transactions = []
22
-
23
- @connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
24
-
25
- @connections[0].start_transaction do |tx|
26
- tx.execute("CREATE TABLE TEST_TABLE (TESTID INTEGER NOT NULL "\
27
- "primary KEY, TESTINFO VARCHAR(100))")
28
- tx.execute('create table all_types (col01 bigint, col02 blob, '\
29
- 'col03 char(100), col04 date, col05 decimal(5,2), '\
30
- 'col06 double precision, col07 float, col08 integer, '\
31
- 'col09 numeric(10,3), col10 smallint, col11 time, '\
32
- 'col12 timestamp, col13 varchar(23))')
33
- end
34
-
35
- @connections[0].start_transaction do |tx|
36
- begin
37
- tx.execute("INSERT INTO TEST_TABLE VALUES (10, 'Record One.')")
38
- tx.execute("INSERT INTO TEST_TABLE VALUES (20, 'Record Two.')")
39
- tx.execute("INSERT INTO TEST_TABLE VALUES (30, 'Record Three.')")
40
- tx.execute("INSERT INTO TEST_TABLE VALUES (40, 'Record Four.')")
41
- tx.execute("INSERT INTO TEST_TABLE VALUES (50, 'Record Five.')")
42
- rescue Exception => error
43
- puts error.message
44
- error.backtrace.each {|step| puts " #{step}"}
45
- raise
46
- end
47
- end
48
-
49
- @transactions.push(@connections[0].start_transaction)
50
- end
51
-
52
- def teardown
53
- @transactions.each do |tx|
54
- tx.rollback if tx.active?
55
- end
56
- @transactions.clear
57
- @connections.each do |cxn|
58
- cxn.close if cxn.open?
59
- end
60
- @connections.clear
61
- if File::exist?(DB_FILE)
62
- Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
63
- end
64
- puts "#{self.class.name} finished." if TEST_LOGGING
65
- end
66
-
67
- def test01
68
- r = ResultSet.new(@connections[0], @transactions[0],
69
- "SELECT * FROM TEST_TABLE ORDER BY TESTID", 3, nil)
70
-
71
- assert(r.connection == @connections[0])
72
- assert(r.transaction == @transactions[0])
73
- assert(r.sql == "SELECT * FROM TEST_TABLE ORDER BY TESTID")
74
- assert(r.dialect == 3)
75
-
76
- assert(r.fetch != nil)
77
- assert(r.fetch.class == Row)
78
- assert(r.fetch[0] == 30)
79
- assert(r.fetch[1] == 'Record Four.')
80
- r.fetch
81
- assert(r.fetch == nil)
82
- r.close
83
-
84
- r = ResultSet.new(@connections[0], @transactions[0],
85
- "SELECT * FROM TEST_TABLE ORDER BY TESTID", 3, nil)
86
- assert(r.column_count == 2)
87
- assert(r.column_name(0) == 'TESTID')
88
- assert(r.column_name(1) == 'TESTINFO')
89
- assert(r.column_name(3) == nil)
90
- assert(r.column_name(-1) == nil)
91
- assert(r.column_table(0) == 'TEST_TABLE')
92
- assert(r.column_table(1) == 'TEST_TABLE')
93
- assert(r.column_table(2) == nil)
94
- assert(r.column_table(-1) == nil)
95
- assert(r.column_alias(0) == 'TESTID')
96
- assert(r.column_alias(1) == 'TESTINFO')
97
- assert(r.column_alias(3) == nil)
98
- assert(r.column_alias(-1) == nil)
99
- r.close
100
-
101
- r = ResultSet.new(@connections[0], @transactions[0],
102
- "SELECT * FROM TEST_TABLE ORDER BY TESTID", 3, nil)
103
- total = 0
104
- r.each do |row|
105
- total += 1
106
- end
107
- assert(total == 5)
108
- assert(r.exhausted?)
109
- end
110
-
111
- def test02
112
- r = ResultSet.new(@connections[0], @transactions[0],
113
- 'select * from test_table where testid between ? and ?',
114
- 3, [20, 40])
115
- assert(r.exhausted? == false)
116
- total = 0
117
- r.each {|row| total += 1}
118
- assert(total == 3)
119
- assert(r.exhausted?)
120
- end
121
-
122
- def test03
123
- begin
124
- ResultSet.new(@connections[0], @transactions[0],
125
- "insert into test_table values(?, ?)", 3,
126
- [100, 'Should fail.'])
127
- assert(false, "Created result set with non-query SQL statement.")
128
- rescue FireRubyException
129
- end
130
-
131
- begin
132
- ResultSet.new(@connections[0], @transactions[0],
133
- "select * from test_table where testid = ?", 3,
134
- [])
135
- assert(false, 'Created result set with insufficient parameters.')
136
- rescue FireRubyException
137
- end
138
- end
139
-
140
- def test04
141
- results = nil
142
- begin
143
- results = @transactions[0].execute('select * from all_types')
144
-
145
- assert(results.get_base_type(0) == SQLType::BIGINT)
146
- assert(results.get_base_type(1) == SQLType::BLOB)
147
- assert(results.get_base_type(2) == SQLType::CHAR)
148
- assert(results.get_base_type(3) == SQLType::DATE)
149
- assert(results.get_base_type(4) == SQLType::DECIMAL)
150
- assert(results.get_base_type(5) == SQLType::DOUBLE)
151
- assert(results.get_base_type(6) == SQLType::FLOAT)
152
- assert(results.get_base_type(7) == SQLType::INTEGER)
153
- assert(results.get_base_type(8) == SQLType::NUMERIC)
154
- assert(results.get_base_type(9) == SQLType::SMALLINT)
155
- assert(results.get_base_type(10) == SQLType::TIME)
156
- assert(results.get_base_type(11) == SQLType::TIMESTAMP)
157
- assert(results.get_base_type(12) == SQLType::VARCHAR)
158
- ensure
159
- results.close if results != nil
160
- end
161
- end
162
- 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 ResultSetTest < Test::Unit::TestCase
11
+ CURDIR = "#{Dir.getwd}"
12
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}result_set_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
+ @database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
20
+ @connections = []
21
+ @transactions = []
22
+
23
+ @connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
24
+
25
+ @connections[0].start_transaction do |tx|
26
+ tx.execute("CREATE TABLE TEST_TABLE (TESTID INTEGER NOT NULL "\
27
+ "primary KEY, TESTINFO VARCHAR(100))")
28
+ tx.execute('create table all_types (col01 bigint, col02 blob, '\
29
+ 'col03 char(100), col04 date, col05 decimal(5,2), '\
30
+ 'col06 double precision, col07 float, col08 integer, '\
31
+ 'col09 numeric(10,3), col10 smallint, col11 time, '\
32
+ 'col12 timestamp, col13 varchar(23))')
33
+ end
34
+
35
+ @connections[0].start_transaction do |tx|
36
+ begin
37
+ tx.execute("INSERT INTO TEST_TABLE VALUES (10, 'Record One.')")
38
+ tx.execute("INSERT INTO TEST_TABLE VALUES (20, 'Record Two.')")
39
+ tx.execute("INSERT INTO TEST_TABLE VALUES (30, 'Record Three.')")
40
+ tx.execute("INSERT INTO TEST_TABLE VALUES (40, 'Record Four.')")
41
+ tx.execute("INSERT INTO TEST_TABLE VALUES (50, 'Record Five.')")
42
+ rescue Exception => error
43
+ puts error.message
44
+ error.backtrace.each {|step| puts " #{step}"}
45
+ raise
46
+ end
47
+ end
48
+
49
+ @transactions.push(@connections[0].start_transaction)
50
+ end
51
+
52
+ def teardown
53
+ @transactions.each do |tx|
54
+ tx.rollback if tx.active?
55
+ end
56
+ @transactions.clear
57
+ @connections.each do |cxn|
58
+ cxn.close if cxn.open?
59
+ end
60
+ @connections.clear
61
+ if File::exist?(DB_FILE)
62
+ Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
63
+ end
64
+ puts "#{self.class.name} finished." if TEST_LOGGING
65
+ end
66
+
67
+ def test01
68
+ r = ResultSet.new(@connections[0], @transactions[0],
69
+ "SELECT * FROM TEST_TABLE ORDER BY TESTID", 3, nil)
70
+
71
+ assert(r.connection == @connections[0])
72
+ assert(r.transaction == @transactions[0])
73
+ assert(r.sql == "SELECT * FROM TEST_TABLE ORDER BY TESTID")
74
+ assert(r.dialect == 3)
75
+
76
+ assert(r.fetch != nil)
77
+ assert(r.fetch.class == Row)
78
+ assert(r.fetch[0] == 30)
79
+ assert(r.fetch[1] == 'Record Four.')
80
+ r.fetch
81
+ assert(r.fetch == nil)
82
+ r.close
83
+
84
+ r = ResultSet.new(@connections[0], @transactions[0],
85
+ "SELECT * FROM TEST_TABLE ORDER BY TESTID", 3, nil)
86
+ assert(r.column_count == 2)
87
+ assert(r.column_name(0) == 'TESTID')
88
+ assert(r.column_name(1) == 'TESTINFO')
89
+ assert(r.column_name(3) == nil)
90
+ assert(r.column_name(-1) == nil)
91
+ assert(r.column_table(0) == 'TEST_TABLE')
92
+ assert(r.column_table(1) == 'TEST_TABLE')
93
+ assert(r.column_table(2) == nil)
94
+ assert(r.column_table(-1) == nil)
95
+ assert(r.column_alias(0) == 'TESTID')
96
+ assert(r.column_alias(1) == 'TESTINFO')
97
+ assert(r.column_alias(3) == nil)
98
+ assert(r.column_alias(-1) == nil)
99
+ r.close
100
+
101
+ r = ResultSet.new(@connections[0], @transactions[0],
102
+ "SELECT * FROM TEST_TABLE ORDER BY TESTID", 3, nil)
103
+ total = 0
104
+ r.each do |row|
105
+ total += 1
106
+ end
107
+ assert(total == 5)
108
+ assert(r.exhausted?)
109
+ end
110
+
111
+ def test02
112
+ r = ResultSet.new(@connections[0], @transactions[0],
113
+ 'select * from test_table where testid between ? and ?',
114
+ 3, [20, 40])
115
+ assert(r.exhausted? == false)
116
+ total = 0
117
+ r.each {|row| total += 1}
118
+ assert(total == 3)
119
+ assert(r.exhausted?)
120
+ end
121
+
122
+ def test03
123
+ begin
124
+ ResultSet.new(@connections[0], @transactions[0],
125
+ "insert into test_table values(?, ?)", 3,
126
+ [100, 'Should fail.'])
127
+ assert(false, "Created result set with non-query SQL statement.")
128
+ rescue FireRubyException
129
+ end
130
+
131
+ begin
132
+ ResultSet.new(@connections[0], @transactions[0],
133
+ "select * from test_table where testid = ?", 3,
134
+ [])
135
+ assert(false, 'Created result set with insufficient parameters.')
136
+ rescue FireRubyException
137
+ end
138
+ end
139
+
140
+ def test04
141
+ results = nil
142
+ begin
143
+ results = @transactions[0].execute('select * from all_types')
144
+
145
+ assert(results.get_base_type(0) == SQLType::BIGINT)
146
+ assert(results.get_base_type(1) == SQLType::BLOB)
147
+ assert(results.get_base_type(2) == SQLType::CHAR)
148
+ assert(results.get_base_type(3) == SQLType::DATE)
149
+ assert(results.get_base_type(4) == SQLType::DECIMAL)
150
+ assert(results.get_base_type(5) == SQLType::DOUBLE)
151
+ assert(results.get_base_type(6) == SQLType::FLOAT)
152
+ assert(results.get_base_type(7) == SQLType::INTEGER)
153
+ assert(results.get_base_type(8) == SQLType::NUMERIC)
154
+ assert(results.get_base_type(9) == SQLType::SMALLINT)
155
+ assert(results.get_base_type(10) == SQLType::TIME)
156
+ assert(results.get_base_type(11) == SQLType::TIMESTAMP)
157
+ assert(results.get_base_type(12) == SQLType::VARCHAR)
158
+ ensure
159
+ results.close if results != nil
160
+ end
161
+ end
162
+ end