fb 0.5.5 → 0.5.9
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/README +14 -0
- data/fb.c +245 -210
- data/test/ConnectionTestCases.rb +462 -462
- data/test/CursorTestCases.rb +235 -235
- data/test/DataTypesTestCases.rb +428 -428
- data/test/DatabaseTestCases.rb +180 -180
- data/test/FbTestCases.rb +36 -33
- data/test/TransactionTestCases.rb +259 -259
- metadata +41 -34
data/test/CursorTestCases.rb
CHANGED
@@ -1,235 +1,235 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'test/FbTestCases'
|
3
|
-
require 'fb'
|
4
|
-
include Fb
|
5
|
-
|
6
|
-
class CursorTestCases < Test::Unit::TestCase
|
7
|
-
include FbTestCases
|
8
|
-
|
9
|
-
def test_fetch_array
|
10
|
-
Database.create(@parms) do |connection|
|
11
|
-
connection.execute("select * from rdb$database") do |cursor|
|
12
|
-
assert_instance_of Cursor, cursor
|
13
|
-
row = cursor.fetch :array
|
14
|
-
assert_instance_of Array, row
|
15
|
-
assert_equal 4, row.size
|
16
|
-
end
|
17
|
-
connection.drop
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_fetch_hash
|
22
|
-
Database.create(@parms) do |connection|
|
23
|
-
connection.execute("select * from rdb$database") do |cursor|
|
24
|
-
assert_instance_of Cursor, cursor
|
25
|
-
row = cursor.fetch :hash
|
26
|
-
assert_instance_of Hash, row
|
27
|
-
assert_equal 4, row.size
|
28
|
-
end
|
29
|
-
connection.drop
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_fetch_all_array
|
34
|
-
Database.create(@parms) do |connection|
|
35
|
-
connection.execute("select * from rdb$database") do |cursor|
|
36
|
-
assert_instance_of Cursor, cursor
|
37
|
-
rows = cursor.fetchall :array
|
38
|
-
assert_instance_of Array, rows
|
39
|
-
assert_equal 1, rows.size
|
40
|
-
assert_instance_of Array, rows[0]
|
41
|
-
assert_equal 4, rows[0].size
|
42
|
-
end
|
43
|
-
connection.drop
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_fetch_all_hash
|
48
|
-
Database.create(@parms) do |connection|
|
49
|
-
connection.execute("select * from rdb$database") do |cursor|
|
50
|
-
assert_instance_of Cursor, cursor
|
51
|
-
rows = cursor.fetchall :hash
|
52
|
-
assert_instance_of Array, rows
|
53
|
-
assert_equal 1, rows.size
|
54
|
-
assert_instance_of Hash, rows[0]
|
55
|
-
assert_equal 4, rows[0].size
|
56
|
-
end
|
57
|
-
connection.drop
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_fields_array
|
62
|
-
Database.create(@parms) do |connection|
|
63
|
-
connection.execute("select * from rdb$database") do |cursor|
|
64
|
-
fields = cursor.fields
|
65
|
-
fields_ary = cursor.fields :array
|
66
|
-
assert_equal fields, fields_ary
|
67
|
-
assert_equal 4, fields.size
|
68
|
-
assert_equal "RDB$DESCRIPTION", fields[0].name;
|
69
|
-
assert_equal "RDB$RELATION_ID", fields[1].name;
|
70
|
-
assert_equal "RDB$SECURITY_CLASS", fields[2].name;
|
71
|
-
assert_equal "RDB$CHARACTER_SET_NAME", fields[3].name;
|
72
|
-
end
|
73
|
-
connection.drop
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_fields_array_downcased
|
78
|
-
Database.create(@parms.merge(:downcase_names => true)) do |connection|
|
79
|
-
connection.execute("select * from rdb$database") do |cursor|
|
80
|
-
fields = cursor.fields
|
81
|
-
fields_ary = cursor.fields :array
|
82
|
-
assert_equal fields, fields_ary
|
83
|
-
assert_equal 4, fields.size
|
84
|
-
assert_equal "rdb$description", fields[0].name;
|
85
|
-
assert_equal "rdb$relation_id", fields[1].name;
|
86
|
-
assert_equal "rdb$security_class", fields[2].name;
|
87
|
-
assert_equal "rdb$character_set_name", fields[3].name;
|
88
|
-
end
|
89
|
-
connection.drop
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_fields_hash
|
94
|
-
Database.create(@parms) do |connection|
|
95
|
-
connection.execute("select * from rdb$database") do |cursor|
|
96
|
-
fields = cursor.fields :hash
|
97
|
-
assert_equal 4, fields.size
|
98
|
-
assert_equal 520, fields["RDB$DESCRIPTION"].type_code
|
99
|
-
assert_equal 500, fields["RDB$RELATION_ID"].type_code
|
100
|
-
assert_equal 452, fields["RDB$SECURITY_CLASS"].type_code
|
101
|
-
assert_equal 452, fields["RDB$CHARACTER_SET_NAME"].type_code
|
102
|
-
end
|
103
|
-
connection.drop
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_fields_hash_downcased
|
108
|
-
Database.create(@parms.merge(:downcase_names => true)) do |connection|
|
109
|
-
connection.execute("select * from rdb$database") do |cursor|
|
110
|
-
fields = cursor.fields :hash
|
111
|
-
assert_equal 4, fields.size
|
112
|
-
assert_equal 520, fields["rdb$description"].type_code
|
113
|
-
assert_equal 500, fields["rdb$relation_id"].type_code
|
114
|
-
assert_equal 452, fields["rdb$security_class"].type_code
|
115
|
-
assert_equal 452, fields["rdb$character_set_name"].type_code
|
116
|
-
end
|
117
|
-
connection.drop
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_each_array
|
122
|
-
Database.create(@parms) do |connection|
|
123
|
-
connection.execute("select * from rdb$database") do |cursor|
|
124
|
-
count = 0
|
125
|
-
cursor.each :array do |row|
|
126
|
-
count += 1
|
127
|
-
assert_instance_of Array, row
|
128
|
-
assert_equal 4, row.size
|
129
|
-
end
|
130
|
-
assert_equal 1, count
|
131
|
-
end
|
132
|
-
connection.drop
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_each_hash
|
137
|
-
Database.create(@parms) do |connection|
|
138
|
-
connection.execute("select * from rdb$database") do |cursor|
|
139
|
-
count = 0
|
140
|
-
cursor.each :hash do |row|
|
141
|
-
count += 1
|
142
|
-
assert_instance_of Hash, row
|
143
|
-
assert_equal 4, row.size
|
144
|
-
end
|
145
|
-
assert_equal 1, count
|
146
|
-
end
|
147
|
-
connection.drop
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_fetch_after_nil
|
152
|
-
Database.create(@parms) do |connection|
|
153
|
-
connection.execute("create generator test_seq");
|
154
|
-
connection.execute("select gen_id(test_seq, 1) from rdb$database") do |cursor|
|
155
|
-
r1 = cursor.fetch
|
156
|
-
assert_not_nil r1
|
157
|
-
r2 = cursor.fetch
|
158
|
-
assert_nil r2
|
159
|
-
assert_raise Error do
|
160
|
-
r3 = cursor.fetch
|
161
|
-
end
|
162
|
-
end
|
163
|
-
connection.execute("select * from rdb$database") do |cursor|
|
164
|
-
r1 = cursor.fetch
|
165
|
-
assert_not_nil r1
|
166
|
-
r2 = cursor.fetch
|
167
|
-
assert_nil r2
|
168
|
-
assert_raise Error do
|
169
|
-
r3 = cursor.fetch
|
170
|
-
end
|
171
|
-
end
|
172
|
-
connection.drop
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_fetch_hash_with_aliased_fields
|
177
|
-
sql = "SELECT RDB$DESCRIPTION DES, RDB$RELATION_ID REL, RDB$SECURITY_CLASS SEC, RDB$CHARACTER_SET_NAME FROM RDB$DATABASE"
|
178
|
-
Database.create(@parms) do |connection|
|
179
|
-
connection.execute(sql) do |cursor|
|
180
|
-
assert_instance_of Cursor, cursor
|
181
|
-
row = cursor.fetch :hash
|
182
|
-
assert_instance_of Hash, row
|
183
|
-
assert_equal 4, row.size
|
184
|
-
assert row.keys.include?("DES"), "No field DES"
|
185
|
-
assert row.keys.include?("REL"), "No field REL"
|
186
|
-
assert row.keys.include?("SEC"), "No field SEC"
|
187
|
-
assert row.keys.include?("RDB$CHARACTER_SET_NAME"), "No field RDB$CHARACTER_SET_NAME"
|
188
|
-
end
|
189
|
-
connection.drop
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_simultaneous_cursors
|
194
|
-
sql_schema = <<-END
|
195
|
-
CREATE TABLE MASTER (ID INT, NAME1 VARCHAR(10));
|
196
|
-
CREATE TABLE DETAIL (ID INT, MASTER_ID INT, NAME2 VARCHAR(10));
|
197
|
-
END
|
198
|
-
sql_insert_master = "INSERT INTO MASTER (ID, NAME1) VALUES (?, ?)"
|
199
|
-
sql_insert_detail = "INSERT INTO DETAIL (ID, MASTER_ID, NAME2) VALUES (?, ?, ?)"
|
200
|
-
sql_select_master = "SELECT * FROM MASTER ORDER BY ID"
|
201
|
-
sql_select_detail = "SELECT * FROM DETAIL ORDER BY ID"
|
202
|
-
Database.create(@parms) do |connection|
|
203
|
-
connection.execute_script(sql_schema)
|
204
|
-
connection.transaction do
|
205
|
-
3.times do |m|
|
206
|
-
connection.execute(sql_insert_master, m, "name_#{m}")
|
207
|
-
end
|
208
|
-
9.times do |d|
|
209
|
-
connection.execute(sql_insert_detail, d, d / 3, "name_#{d / 3}_#{d}")
|
210
|
-
end
|
211
|
-
end
|
212
|
-
master = connection.execute(sql_select_master)
|
213
|
-
begin
|
214
|
-
detail = connection.execute(sql_select_detail)
|
215
|
-
begin
|
216
|
-
3.times do |m|
|
217
|
-
mr = master.fetch
|
218
|
-
assert_equal m, mr[0]
|
219
|
-
assert_equal "name_#{m}", mr[1]
|
220
|
-
3.times do |d|
|
221
|
-
dr = detail.fetch
|
222
|
-
assert_equal m * 3 + d, dr[0]
|
223
|
-
assert_equal m, dr[1]
|
224
|
-
assert_equal "name_#{m}_#{m * 3 + d}", dr[2]
|
225
|
-
end
|
226
|
-
end
|
227
|
-
ensure
|
228
|
-
detail.close
|
229
|
-
end
|
230
|
-
ensure
|
231
|
-
master.close
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/FbTestCases'
|
3
|
+
# require 'fb'
|
4
|
+
# include Fb
|
5
|
+
|
6
|
+
class CursorTestCases < Test::Unit::TestCase
|
7
|
+
include FbTestCases
|
8
|
+
|
9
|
+
def test_fetch_array
|
10
|
+
Database.create(@parms) do |connection|
|
11
|
+
connection.execute("select * from rdb$database") do |cursor|
|
12
|
+
assert_instance_of Cursor, cursor
|
13
|
+
row = cursor.fetch :array
|
14
|
+
assert_instance_of Array, row
|
15
|
+
assert_equal 4, row.size
|
16
|
+
end
|
17
|
+
connection.drop
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_fetch_hash
|
22
|
+
Database.create(@parms) do |connection|
|
23
|
+
connection.execute("select * from rdb$database") do |cursor|
|
24
|
+
assert_instance_of Cursor, cursor
|
25
|
+
row = cursor.fetch :hash
|
26
|
+
assert_instance_of Hash, row
|
27
|
+
assert_equal 4, row.size
|
28
|
+
end
|
29
|
+
connection.drop
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_fetch_all_array
|
34
|
+
Database.create(@parms) do |connection|
|
35
|
+
connection.execute("select * from rdb$database") do |cursor|
|
36
|
+
assert_instance_of Cursor, cursor
|
37
|
+
rows = cursor.fetchall :array
|
38
|
+
assert_instance_of Array, rows
|
39
|
+
assert_equal 1, rows.size
|
40
|
+
assert_instance_of Array, rows[0]
|
41
|
+
assert_equal 4, rows[0].size
|
42
|
+
end
|
43
|
+
connection.drop
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_fetch_all_hash
|
48
|
+
Database.create(@parms) do |connection|
|
49
|
+
connection.execute("select * from rdb$database") do |cursor|
|
50
|
+
assert_instance_of Cursor, cursor
|
51
|
+
rows = cursor.fetchall :hash
|
52
|
+
assert_instance_of Array, rows
|
53
|
+
assert_equal 1, rows.size
|
54
|
+
assert_instance_of Hash, rows[0]
|
55
|
+
assert_equal 4, rows[0].size
|
56
|
+
end
|
57
|
+
connection.drop
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_fields_array
|
62
|
+
Database.create(@parms) do |connection|
|
63
|
+
connection.execute("select * from rdb$database") do |cursor|
|
64
|
+
fields = cursor.fields
|
65
|
+
fields_ary = cursor.fields :array
|
66
|
+
assert_equal fields, fields_ary
|
67
|
+
assert_equal 4, fields.size
|
68
|
+
assert_equal "RDB$DESCRIPTION", fields[0].name;
|
69
|
+
assert_equal "RDB$RELATION_ID", fields[1].name;
|
70
|
+
assert_equal "RDB$SECURITY_CLASS", fields[2].name;
|
71
|
+
assert_equal "RDB$CHARACTER_SET_NAME", fields[3].name;
|
72
|
+
end
|
73
|
+
connection.drop
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_fields_array_downcased
|
78
|
+
Database.create(@parms.merge(:downcase_names => true)) do |connection| # xxx true
|
79
|
+
connection.execute("select * from rdb$database") do |cursor|
|
80
|
+
fields = cursor.fields
|
81
|
+
fields_ary = cursor.fields :array
|
82
|
+
assert_equal fields, fields_ary
|
83
|
+
assert_equal 4, fields.size
|
84
|
+
assert_equal "rdb$description", fields[0].name;
|
85
|
+
assert_equal "rdb$relation_id", fields[1].name;
|
86
|
+
assert_equal "rdb$security_class", fields[2].name;
|
87
|
+
assert_equal "rdb$character_set_name", fields[3].name;
|
88
|
+
end
|
89
|
+
connection.drop
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_fields_hash
|
94
|
+
Database.create(@parms) do |connection|
|
95
|
+
connection.execute("select * from rdb$database") do |cursor|
|
96
|
+
fields = cursor.fields :hash
|
97
|
+
assert_equal 4, fields.size
|
98
|
+
assert_equal 520, fields["RDB$DESCRIPTION"].type_code
|
99
|
+
assert_equal 500, fields["RDB$RELATION_ID"].type_code
|
100
|
+
assert_equal 452, fields["RDB$SECURITY_CLASS"].type_code
|
101
|
+
assert_equal 452, fields["RDB$CHARACTER_SET_NAME"].type_code
|
102
|
+
end
|
103
|
+
connection.drop
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_fields_hash_downcased
|
108
|
+
Database.create(@parms.merge(:downcase_names => true)) do |connection| # xxx true
|
109
|
+
connection.execute("select * from rdb$database") do |cursor|
|
110
|
+
fields = cursor.fields :hash
|
111
|
+
assert_equal 4, fields.size
|
112
|
+
assert_equal 520, fields["rdb$description"].type_code
|
113
|
+
assert_equal 500, fields["rdb$relation_id"].type_code
|
114
|
+
assert_equal 452, fields["rdb$security_class"].type_code
|
115
|
+
assert_equal 452, fields["rdb$character_set_name"].type_code
|
116
|
+
end
|
117
|
+
connection.drop
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_each_array
|
122
|
+
Database.create(@parms) do |connection|
|
123
|
+
connection.execute("select * from rdb$database") do |cursor|
|
124
|
+
count = 0
|
125
|
+
cursor.each :array do |row|
|
126
|
+
count += 1
|
127
|
+
assert_instance_of Array, row
|
128
|
+
assert_equal 4, row.size
|
129
|
+
end
|
130
|
+
assert_equal 1, count
|
131
|
+
end
|
132
|
+
connection.drop
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_each_hash
|
137
|
+
Database.create(@parms) do |connection|
|
138
|
+
connection.execute("select * from rdb$database") do |cursor|
|
139
|
+
count = 0
|
140
|
+
cursor.each :hash do |row|
|
141
|
+
count += 1
|
142
|
+
assert_instance_of Hash, row
|
143
|
+
assert_equal 4, row.size
|
144
|
+
end
|
145
|
+
assert_equal 1, count
|
146
|
+
end
|
147
|
+
connection.drop
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_fetch_after_nil
|
152
|
+
Database.create(@parms) do |connection|
|
153
|
+
connection.execute("create generator test_seq");
|
154
|
+
connection.execute("select gen_id(test_seq, 1) from rdb$database") do |cursor|
|
155
|
+
r1 = cursor.fetch
|
156
|
+
assert_not_nil r1
|
157
|
+
r2 = cursor.fetch
|
158
|
+
assert_nil r2
|
159
|
+
assert_raise Error do
|
160
|
+
r3 = cursor.fetch
|
161
|
+
end
|
162
|
+
end
|
163
|
+
connection.execute("select * from rdb$database") do |cursor|
|
164
|
+
r1 = cursor.fetch
|
165
|
+
assert_not_nil r1
|
166
|
+
r2 = cursor.fetch
|
167
|
+
assert_nil r2
|
168
|
+
assert_raise Error do
|
169
|
+
r3 = cursor.fetch
|
170
|
+
end
|
171
|
+
end
|
172
|
+
connection.drop
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_fetch_hash_with_aliased_fields
|
177
|
+
sql = "SELECT RDB$DESCRIPTION DES, RDB$RELATION_ID REL, RDB$SECURITY_CLASS SEC, RDB$CHARACTER_SET_NAME FROM RDB$DATABASE"
|
178
|
+
Database.create(@parms) do |connection|
|
179
|
+
connection.execute(sql) do |cursor|
|
180
|
+
assert_instance_of Cursor, cursor
|
181
|
+
row = cursor.fetch :hash
|
182
|
+
assert_instance_of Hash, row
|
183
|
+
assert_equal 4, row.size
|
184
|
+
assert row.keys.include?("DES"), "No field DES"
|
185
|
+
assert row.keys.include?("REL"), "No field REL"
|
186
|
+
assert row.keys.include?("SEC"), "No field SEC"
|
187
|
+
assert row.keys.include?("RDB$CHARACTER_SET_NAME"), "No field RDB$CHARACTER_SET_NAME"
|
188
|
+
end
|
189
|
+
connection.drop
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_simultaneous_cursors
|
194
|
+
sql_schema = <<-END
|
195
|
+
CREATE TABLE MASTER (ID INT, NAME1 VARCHAR(10));
|
196
|
+
CREATE TABLE DETAIL (ID INT, MASTER_ID INT, NAME2 VARCHAR(10));
|
197
|
+
END
|
198
|
+
sql_insert_master = "INSERT INTO MASTER (ID, NAME1) VALUES (?, ?)"
|
199
|
+
sql_insert_detail = "INSERT INTO DETAIL (ID, MASTER_ID, NAME2) VALUES (?, ?, ?)"
|
200
|
+
sql_select_master = "SELECT * FROM MASTER ORDER BY ID"
|
201
|
+
sql_select_detail = "SELECT * FROM DETAIL ORDER BY ID"
|
202
|
+
Database.create(@parms) do |connection|
|
203
|
+
connection.execute_script(sql_schema)
|
204
|
+
connection.transaction do
|
205
|
+
3.times do |m|
|
206
|
+
connection.execute(sql_insert_master, m, "name_#{m}")
|
207
|
+
end
|
208
|
+
9.times do |d|
|
209
|
+
connection.execute(sql_insert_detail, d, d / 3, "name_#{d / 3}_#{d}")
|
210
|
+
end
|
211
|
+
end
|
212
|
+
master = connection.execute(sql_select_master)
|
213
|
+
begin
|
214
|
+
detail = connection.execute(sql_select_detail)
|
215
|
+
begin
|
216
|
+
3.times do |m|
|
217
|
+
mr = master.fetch
|
218
|
+
assert_equal m, mr[0]
|
219
|
+
assert_equal "name_#{m}", mr[1]
|
220
|
+
3.times do |d|
|
221
|
+
dr = detail.fetch
|
222
|
+
assert_equal m * 3 + d, dr[0]
|
223
|
+
assert_equal m, dr[1]
|
224
|
+
assert_equal "name_#{m}_#{m * 3 + d}", dr[2]
|
225
|
+
end
|
226
|
+
end
|
227
|
+
ensure
|
228
|
+
detail.close
|
229
|
+
end
|
230
|
+
ensure
|
231
|
+
master.close
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|