ibruby 0.5.5-i686-darwin8.9.1

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/test/RowTest.rb ADDED
@@ -0,0 +1,205 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'TestSetup'
4
+ require 'test/unit'
5
+ #require 'rubygems'
6
+ require 'ibruby'
7
+
8
+ include IBRuby
9
+
10
+ class RowTest < Test::Unit::TestCase
11
+ CURDIR = "#{Dir.getwd}"
12
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}row_unit_test.ib"
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 boolean, 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([false, 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
+
185
+ row = results.fetch
186
+
187
+ assert(row.get_base_type(0) == SQLType::BOOLEAN)
188
+ assert(row.get_base_type(1) == SQLType::BLOB)
189
+ assert(row.get_base_type(2) == SQLType::CHAR)
190
+ assert(row.get_base_type(3) == SQLType::DATE)
191
+ assert(row.get_base_type(4) == SQLType::DECIMAL)
192
+ assert(row.get_base_type(5) == SQLType::DOUBLE)
193
+ assert(row.get_base_type(6) == SQLType::FLOAT)
194
+ assert(row.get_base_type(7) == SQLType::INTEGER)
195
+ assert(row.get_base_type(8) == SQLType::NUMERIC)
196
+ assert(row.get_base_type(9) == SQLType::SMALLINT)
197
+ assert(row.get_base_type(10) == SQLType::TIME)
198
+ assert(row.get_base_type(11) == SQLType::TIMESTAMP)
199
+ assert(row.get_base_type(12) == SQLType::VARCHAR)
200
+
201
+ ensure
202
+ results.close if results != nil
203
+ end
204
+ end
205
+ end
data/test/SQLTest.rb ADDED
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'TestSetup'
4
+ require 'test/unit'
5
+ #require 'rubygems'
6
+ require 'ibruby'
7
+
8
+ include IBRuby
9
+
10
+ class SQLTest < Test::Unit::TestCase
11
+ CURDIR = "#{Dir.getwd}"
12
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}sql_unit_test.ib"
13
+ ITERATIONS = 100
14
+
15
+ INSERT_SQL = "INSERT INTO TEST_TABLE VALUES(?, ?, ?, ?, ?, ?)"
16
+
17
+ def setup
18
+ puts "#{self.class.name} started." if TEST_LOGGING
19
+ if File::exist?(DB_FILE)
20
+ Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
21
+ end
22
+ @database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
23
+ @connections = []
24
+ @transactions = []
25
+
26
+ @database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
27
+ cxn.execute_immediate('CREATE TABLE TEST_TABLE (TESTID INTEGER '\
28
+ 'NOT NULL PRIMARY KEY, TESTTEXT VARCHAR(100), '\
29
+ 'TESTFLOAT NUMERIC(8,2), TESTDATE DATE, TESTTIME '\
30
+ 'TIME, TESTSTAMP TIMESTAMP)')
31
+ end
32
+ end
33
+
34
+ def teardown
35
+ @transactions.each do |tx|
36
+ tx.rollback if tx.active?
37
+ end
38
+
39
+ @connections.each do |cxn|
40
+ cxn.close if cxn.open?
41
+ end
42
+
43
+ if File::exist?(DB_FILE)
44
+ Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
45
+ end
46
+ puts "#{self.class.name} finished." if TEST_LOGGING
47
+ end
48
+
49
+ def test01
50
+ @database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
51
+ cxn.start_transaction do |tx|
52
+ s = Statement.new(cxn, tx, INSERT_SQL, 3)
53
+ f = 0.0
54
+ t = Time.new
55
+
56
+ 1.upto(ITERATIONS) do |i|
57
+ f += 0.321
58
+ t = Time.at(t.to_i + 5)
59
+ s.execute_for([i, i.to_s, f, t, nil, t])
60
+ end
61
+
62
+ s.close
63
+ end
64
+ end
65
+
66
+ @connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
67
+ @connections[0].start_transaction do |tx|
68
+ r = tx.execute("SELECT COUNT(*) FROM TEST_TABLE")
69
+ assert(r.fetch[0] == ITERATIONS)
70
+ r.close
71
+ end
72
+ end
73
+
74
+ def test02
75
+ f = 0.0
76
+ @database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
77
+ 1.upto(20) do |i|
78
+ f += i
79
+ sql = "INSERT INTO TEST_TABLE VALUES (#{i}, "\
80
+ "#{f.to_s}, #{f}, NULL, NULL, 'NOW')"
81
+ cxn.execute_immediate(sql)
82
+ end
83
+ end
84
+
85
+ @connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
86
+ @transactions.push(@connections[0].start_transaction)
87
+ r = @transactions[0].execute("SELECT COUNT(*) FROM TEST_TABLE")
88
+ assert(r.fetch[0] == 20)
89
+ r.close
90
+
91
+ r = @transactions[0].execute("SELECT * FROM TEST_TABLE WHERE TESTID IN "\
92
+ "(2, 4, 6, 8, 10) ORDER BY TESTID ASCENDING")
93
+ a = r.fetch
94
+ assert(a[0] == 2)
95
+ assert(a[1] == '3.0')
96
+ assert(a[2] == 3.0)
97
+ assert(a[3] == nil)
98
+ assert(a[4] == nil)
99
+
100
+ a = r.fetch
101
+ assert(a[0] == 4)
102
+ assert(a[1] == '10.0')
103
+ assert(a[2] == 10.0)
104
+ assert(a[3] == nil)
105
+ assert(a[4] == nil)
106
+
107
+ a = r.fetch
108
+ assert(a[0] == 6)
109
+ assert(a[1] == '21.0')
110
+ assert(a[2] == 21.0)
111
+ assert(a[3] == nil)
112
+ assert(a[4] == nil)
113
+
114
+ a = r.fetch
115
+ assert(a[0] == 8)
116
+ assert(a[1] == '36.0')
117
+ assert(a[2] == 36.0)
118
+ assert(a[3] == nil)
119
+ assert(a[4] == nil)
120
+
121
+ a = r.fetch
122
+ assert(a[0] == 10)
123
+ assert(a[1] == '55.0')
124
+ assert(a[2] == 55.0)
125
+ assert(a[3] == nil)
126
+ assert(a[4] == nil)
127
+
128
+ r.close
129
+
130
+ @transactions[0].commit
131
+
132
+ @connections[0].start_transaction do |tx|
133
+ s = Statement.new(@connections[0], tx,
134
+ "UPDATE TEST_TABLE SET TESTSTAMP = NULL", 3)
135
+ s.execute()
136
+ s.close
137
+
138
+ r = tx.execute("SELECT TESTSTAMP FROM TEST_TABLE")
139
+ total = 0
140
+ r.each do |row|
141
+ assert(row[0] == nil)
142
+ total = total + 1
143
+ end
144
+ assert(total == 20)
145
+ r.close
146
+ end
147
+
148
+ a = []
149
+ t = nil
150
+ @connections[0].start_transaction do |tx|
151
+ # Perform an insert via a parameterized statement.
152
+ s = Statement.new(@connections[0], tx,
153
+ "INSERT INTO TEST_TABLE (TESTID, TESTTEXT, "\
154
+ "TESTFLOAT, TESTSTAMP) VALUES(?, ?, ?, ?)", 3)
155
+ t = Time.new
156
+ s.execute_for([25000, 'La la la', 3.14, t])
157
+ s.close
158
+
159
+ # Fetch the record and check the data.
160
+ r = tx.execute("SELECT TESTTEXT, TESTFLOAT, TESTSTAMP FROM "\
161
+ "TEST_TABLE WHERE TESTID = 25000")
162
+ a = r.fetch
163
+ r.close
164
+ end
165
+ assert(a[0] == 'La la la')
166
+ assert(a[1] == 3.14)
167
+ assert(a[2].to_i == t.to_i)
168
+
169
+ @connections[0].execute_immediate("DELETE FROM TEST_TABLE WHERE TESTID "\
170
+ "IN (1, 3, 5, 7, 9, 12, 14, 16, 18, 20)")
171
+ @database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
172
+ a = []
173
+ cxn.start_transaction do |tx|
174
+ r = tx.execute("SELECT COUNT(*) FROM TEST_TABLE")
175
+ a = r.fetch
176
+ r.close
177
+ end
178
+ assert(a[0] == 11)
179
+ end
180
+ end
181
+ end
182
+
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'TestSetup'
4
+ require 'test/unit'
5
+ #require 'rubygems'
6
+ require 'ibruby'
7
+
8
+ include IBRuby
9
+
10
+ class SQLTypeTest < Test::Unit::TestCase
11
+ CURDIR = "#{Dir.getwd}"
12
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}sql_type_test.ib"
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
+
23
+ @connection.start_transaction do |tx|
24
+ tx.execute("create table all_types (col01 boolean, col02 blob, "\
25
+ "col03 char(100), col04 date, col05 decimal(5,2), "\
26
+ "col06 double precision, col07 float, col08 integer, "\
27
+ "col09 numeric(10,3), col10 smallint, col11 time, "\
28
+ "col12 timestamp, col13 varchar(23))")
29
+ end
30
+ end
31
+
32
+ def teardown
33
+ @connection.close if @connection != nil && @connection.open?
34
+
35
+ if File::exist?(DB_FILE)
36
+ Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
37
+ end
38
+ puts "#{self.class.name} finished." if TEST_LOGGING
39
+ end
40
+
41
+ def test01
42
+ types = []
43
+ types.push(SQLType.new(SQLType::BOOLEAN))
44
+ types.push(SQLType.new(SQLType::VARCHAR, 1000))
45
+ types.push(SQLType.new(SQLType::DECIMAL, nil, 10))
46
+ types.push(SQLType.new(SQLType::NUMERIC, nil, 5, 3))
47
+ types.push(SQLType.new(SQLType::BLOB, nil, nil, nil, 1))
48
+
49
+ assert(types[0] == types[0])
50
+ assert(!(types[0] == types[1]))
51
+ assert(types[1] == SQLType.new(SQLType::VARCHAR, 1000))
52
+
53
+ assert(types[0].type == SQLType::BOOLEAN)
54
+ assert(types[0].length == nil)
55
+ assert(types[0].precision == nil)
56
+ assert(types[0].scale == nil)
57
+ assert(types[0].subtype == nil)
58
+
59
+ assert(types[1].type == SQLType::VARCHAR)
60
+ assert(types[1].length == 1000)
61
+ assert(types[1].precision == nil)
62
+ assert(types[1].scale == nil)
63
+ assert(types[1].subtype == nil)
64
+
65
+ assert(types[2].type == SQLType::DECIMAL)
66
+ assert(types[2].length == nil)
67
+ assert(types[2].precision == 10)
68
+ assert(types[2].scale == nil)
69
+ assert(types[2].subtype == nil)
70
+
71
+ assert(types[3].type == SQLType::NUMERIC)
72
+ assert(types[3].length == nil)
73
+ assert(types[3].precision == 5)
74
+ assert(types[3].scale == 3)
75
+ assert(types[3].subtype == nil)
76
+
77
+ assert(types[4].type == SQLType::BLOB)
78
+ assert(types[4].length == nil)
79
+ assert(types[4].precision == nil)
80
+ assert(types[4].scale == nil)
81
+ assert(types[4].subtype == 1)
82
+ end
83
+
84
+ def test02
85
+ types = SQLType.for_table("all_types", @connection)
86
+
87
+ assert(types['COL01'] == SQLType.new(SQLType::BOOLEAN))
88
+ assert(types['COL02'] == SQLType.new(SQLType::BLOB, nil, nil, nil, 0))
89
+ assert(types['COL03'] == SQLType.new(SQLType::CHAR, 100))
90
+ assert(types['COL04'] == SQLType.new(SQLType::DATE))
91
+ assert(types['COL05'] == SQLType.new(SQLType::DECIMAL, nil, 5, 2))
92
+ assert(types['COL06'] == SQLType.new(SQLType::DOUBLE))
93
+ assert(types['COL07'] == SQLType.new(SQLType::FLOAT))
94
+ assert(types['COL08'] == SQLType.new(SQLType::INTEGER))
95
+ assert(types['COL09'] == SQLType.new(SQLType::NUMERIC, nil, 10, 3))
96
+ assert(types['COL10'] == SQLType.new(SQLType::SMALLINT))
97
+ assert(types['COL11'] == SQLType.new(SQLType::TIME))
98
+ assert(types['COL12'] == SQLType.new(SQLType::TIMESTAMP))
99
+ assert(types['COL13'] == SQLType.new(SQLType::VARCHAR, 23))
100
+ end
101
+ end
@@ -0,0 +1,17 @@
1
+ ***************
2
+ *** 9,15 ****
3
+
4
+ class SQLTypeTest < Test::Unit::TestCase
5
+ CURDIR = "#{Dir.getwd}"
6
+ - DB_FILE = "#{CURDIR}#{File::SEPARATOR}sql_type_test.fdb"
7
+
8
+ def setup
9
+ puts "#{self.class.name} started." if TEST_LOGGING
10
+ --- 9,15 ----
11
+
12
+ class SQLTypeTest < Test::Unit::TestCase
13
+ CURDIR = "#{Dir.getwd}"
14
+ + DB_FILE = "#{CURDIR}#{File::SEPARATOR}sql_type_test.ib"
15
+
16
+ def setup
17
+ puts "#{self.class.name} started." if TEST_LOGGING
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'TestSetup'
4
+ require 'test/unit'
5
+ #require 'rubygems'
6
+ require 'ibruby'
7
+
8
+ include IBRuby
9
+
10
+ class ServiceManagerTest < Test::Unit::TestCase
11
+ def setup
12
+ puts "#{self.class.name} started." if TEST_LOGGING
13
+ end
14
+
15
+ def teardown
16
+ puts "#{self.class.name} finished." if TEST_LOGGING
17
+ end
18
+
19
+ def test01
20
+ sm = ServiceManager.new('localhost')
21
+ assert(sm.connected? == false)
22
+
23
+ assert(sm.connect(DB_USER_NAME, DB_PASSWORD) == sm)
24
+ assert(sm.connected?)
25
+
26
+ assert(sm.disconnect == sm)
27
+ assert(sm.connected? == false)
28
+ end
29
+ end
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'TestSetup'
4
+ require 'test/unit'
5
+ #require 'rubygems'
6
+ require 'ibruby'
7
+
8
+ include IBRuby
9
+
10
+ class StatementTest < Test::Unit::TestCase
11
+ CURDIR = "#{Dir.getwd}"
12
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}stmt_unit_test.ib"
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
+ end
23
+
24
+ def teardown
25
+ @transactions.each do |tx|
26
+ tx.rollback if tx.active?
27
+ end
28
+ @transactions.clear
29
+ @connections.each do |cxn|
30
+ cxn.close if cxn.open?
31
+ end
32
+ @connections.clear
33
+ if File::exist?(DB_FILE)
34
+ Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
35
+ end
36
+ puts "#{self.class.name} finished." if TEST_LOGGING
37
+ end
38
+
39
+ def test01
40
+ @connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
41
+ @transactions.push(@connections.last.start_transaction)
42
+
43
+ s1 = Statement.new(@connections[0],
44
+ @transactions[0],
45
+ "SELECT RDB$FIELD_NAME FROM RDB$FIELDS", 3)
46
+ assert(s1 != nil)
47
+ assert(s1.sql == "SELECT RDB$FIELD_NAME FROM RDB$FIELDS")
48
+ assert(s1.connection == @connections[0])
49
+ assert(s1.transaction == @transactions[0])
50
+ assert(s1.dialect == 3)
51
+ assert(s1.type == Statement::SELECT_STATEMENT)
52
+ s1.close
53
+
54
+ s2 = Statement.new(@connections[0],
55
+ @transactions[0],
56
+ "DELETE FROM RDB$EXCEPTIONS", 1)
57
+ assert(s2 != nil)
58
+ assert(s2.sql == "DELETE FROM RDB$EXCEPTIONS")
59
+ assert(s2.connection == @connections[0])
60
+ assert(s2.transaction == @transactions[0])
61
+ assert(s2.dialect == 1)
62
+ assert(s2.type == Statement::DELETE_STATEMENT)
63
+ s2.close
64
+ end
65
+
66
+ def test02
67
+ @connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
68
+ @transactions.push(@connections[0].start_transaction)
69
+
70
+ s = Statement.new(@connections[0], @transactions[0],
71
+ "SELECT RDB$FIELD_NAME FROM RDB$FIELDS "\
72
+ "WHERE RDB$FIELD_NAME LIKE ?", 3)
73
+
74
+ begin
75
+ r = s.execute
76
+ r.close
77
+ assert(false,
78
+ "Executed statement that required parameter without the "\
79
+ "parameter being specified.")
80
+ rescue Exception => error
81
+ end
82
+
83
+ begin
84
+ r = s.execute_for([])
85
+ r.close
86
+ assert(false,
87
+ "Executed statement that required a parameter with an empty "\
88
+ "parameter set.")
89
+ rescue Exception => error
90
+ end
91
+
92
+ begin
93
+ r = s.execute_for(['LALALA', 25])
94
+ r.close
95
+ assert(false,
96
+ "Executed statement that required a parameter with too many "\
97
+ "parameters.")
98
+ rescue Exception => error
99
+ end
100
+
101
+ r = s.execute_for(['LALALA'])
102
+ assert(r != nil)
103
+ assert(r.class == ResultSet)
104
+ r.close
105
+
106
+ total = 0
107
+ s.execute_for(["%"]) do |row|
108
+ total = total + 1
109
+ end
110
+ assert(total = 88)
111
+ s.close
112
+ end
113
+
114
+ def test03
115
+ d = nil
116
+ @database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
117
+ cxn.execute_immediate('CREATE TABLE STRING_TEST(TEXT VARCHAR(10))')
118
+ cxn.start_transaction do |tx|
119
+ # Perform an truncated insert.
120
+ s = Statement.new(cxn, tx, 'INSERT INTO STRING_TEST VALUES(?)', 3)
121
+ s.execute_for(['012345678901234'])
122
+
123
+ # Perform a select of the value inserted.
124
+ r = cxn.execute('SELECT * FROM STRING_TEST', tx)
125
+ d = r.fetch
126
+
127
+ # Clean up.
128
+ s.close
129
+ r.close
130
+ end
131
+ assert(d[0] == '0123456789')
132
+ cxn.execute_immediate('DROP TABLE STRING_TEST')
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,17 @@
1
+ ***************
2
+ *** 9,15 ****
3
+
4
+ class StatementTest < Test::Unit::TestCase
5
+ CURDIR = "#{Dir.getwd}"
6
+ - DB_FILE = "#{CURDIR}#{File::SEPARATOR}stmt_unit_test.fdb"
7
+
8
+ def setup
9
+ puts "#{self.class.name} started." if TEST_LOGGING
10
+ --- 9,15 ----
11
+
12
+ class StatementTest < Test::Unit::TestCase
13
+ CURDIR = "#{Dir.getwd}"
14
+ + DB_FILE = "#{CURDIR}#{File::SEPARATOR}stmt_unit_test.ib"
15
+
16
+ def setup
17
+ puts "#{self.class.name} started." if TEST_LOGGING
data/test/TestSetup.rb ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Add extra search paths.
4
+ basedir = File::dirname(Dir.getwd)
5
+ $:.push(basedir)
6
+ $:.push("#{basedir}#{File::SEPARATOR}test")
7
+ $:.push("#{basedir}#{File::SEPARATOR}lib")
8
+
9
+ DB_USER_NAME = 'sysdba'
10
+ DB_PASSWORD = 'masterkey'
11
+ TEST_LOGGING = true