ydbi 0.5.8 → 0.6.0

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.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +3 -0
  3. data/.github/workflows/ruby.yml +65 -0
  4. data/.gitignore +19 -0
  5. data/ChangeLog +8 -0
  6. data/Gemfile +5 -0
  7. data/Rakefile +14 -0
  8. data/TODO +44 -0
  9. data/bench/bench.rb +79 -0
  10. data/build/rake_task_lib.rb +186 -0
  11. data/devenv.lock +228 -0
  12. data/devenv.nix +55 -0
  13. data/devenv.yaml +8 -0
  14. data/doc/DBD_SPEC.rdoc +88 -0
  15. data/doc/DBI_SPEC.rdoc +157 -0
  16. data/doc/homepage/contact.html +62 -0
  17. data/doc/homepage/development.html +124 -0
  18. data/doc/homepage/index.html +83 -0
  19. data/doc/homepage/ruby-dbi.css +91 -0
  20. data/lib/dbd/Mysql.rb +137 -0
  21. data/lib/dbd/ODBC.rb +89 -0
  22. data/lib/dbd/Pg.rb +189 -0
  23. data/lib/dbd/SQLite.rb +97 -0
  24. data/lib/dbd/SQLite3.rb +124 -0
  25. data/lib/dbd/mysql/database.rb +405 -0
  26. data/lib/dbd/mysql/driver.rb +125 -0
  27. data/lib/dbd/mysql/statement.rb +188 -0
  28. data/lib/dbd/odbc/database.rb +128 -0
  29. data/lib/dbd/odbc/driver.rb +38 -0
  30. data/lib/dbd/odbc/statement.rb +137 -0
  31. data/lib/dbd/pg/database.rb +508 -0
  32. data/lib/dbd/pg/exec.rb +47 -0
  33. data/lib/dbd/pg/statement.rb +160 -0
  34. data/lib/dbd/pg/tuples.rb +121 -0
  35. data/lib/dbd/pg/type.rb +209 -0
  36. data/lib/dbd/sqlite/database.rb +151 -0
  37. data/lib/dbd/sqlite/statement.rb +125 -0
  38. data/lib/dbd/sqlite3/database.rb +201 -0
  39. data/lib/dbd/sqlite3/statement.rb +78 -0
  40. data/lib/dbi/version.rb +1 -1
  41. data/prototypes/types2.rb +237 -0
  42. data/readme.md +3 -4
  43. data/setup.rb +1585 -0
  44. data/test/DBD_TESTS +50 -0
  45. data/test/TESTING +16 -0
  46. data/test/dbd/general/test_database.rb +206 -0
  47. data/test/dbd/general/test_statement.rb +325 -0
  48. data/test/dbd/general/test_types.rb +295 -0
  49. data/test/dbd/mysql/base.rb +26 -0
  50. data/test/dbd/mysql/down.sql +19 -0
  51. data/test/dbd/mysql/test_blob.rb +18 -0
  52. data/test/dbd/mysql/test_new_methods.rb +7 -0
  53. data/test/dbd/mysql/test_patches.rb +111 -0
  54. data/test/dbd/mysql/up.sql +28 -0
  55. data/test/dbd/odbc/base.rb +30 -0
  56. data/test/dbd/odbc/down.sql +19 -0
  57. data/test/dbd/odbc/test_new_methods.rb +12 -0
  58. data/test/dbd/odbc/test_ping.rb +10 -0
  59. data/test/dbd/odbc/test_statement.rb +44 -0
  60. data/test/dbd/odbc/test_transactions.rb +58 -0
  61. data/test/dbd/odbc/up.sql +33 -0
  62. data/test/dbd/postgresql/base.rb +31 -0
  63. data/test/dbd/postgresql/down.sql +31 -0
  64. data/test/dbd/postgresql/test_arrays.rb +179 -0
  65. data/test/dbd/postgresql/test_async.rb +121 -0
  66. data/test/dbd/postgresql/test_blob.rb +37 -0
  67. data/test/dbd/postgresql/test_bytea.rb +88 -0
  68. data/test/dbd/postgresql/test_ping.rb +10 -0
  69. data/test/dbd/postgresql/test_timestamp.rb +77 -0
  70. data/test/dbd/postgresql/test_transactions.rb +58 -0
  71. data/test/dbd/postgresql/testdbipg.rb +307 -0
  72. data/test/dbd/postgresql/up.sql +60 -0
  73. data/test/dbd/sqlite/base.rb +32 -0
  74. data/test/dbd/sqlite/test_database.rb +30 -0
  75. data/test/dbd/sqlite/test_driver.rb +68 -0
  76. data/test/dbd/sqlite/test_statement.rb +112 -0
  77. data/test/dbd/sqlite/up.sql +25 -0
  78. data/test/dbd/sqlite3/base.rb +32 -0
  79. data/test/dbd/sqlite3/test_database.rb +77 -0
  80. data/test/dbd/sqlite3/test_driver.rb +67 -0
  81. data/test/dbd/sqlite3/test_statement.rb +88 -0
  82. data/test/dbd/sqlite3/up.sql +33 -0
  83. data/test/dbi/tc_dbi.rb +1 -1
  84. data/test/ts_dbd.rb +136 -0
  85. data/ydbi.gemspec +25 -0
  86. metadata +148 -12
@@ -0,0 +1,295 @@
1
+ @class = Class.new(DBDConfig.testbase(DBDConfig.current_dbtype)) do
2
+ def skip_bit
3
+ # FIXME this test fails because DBI's type system blows goats.
4
+ @sth = nil
5
+
6
+ assert_nothing_raised do
7
+ @sth = @dbh.prepare("insert into bit_test (mybit) values (?)")
8
+ @sth.bind_param(1, 0, DBI::SQL_TINYINT)
9
+ @sth.execute
10
+ # if dbtype == "postgresql"
11
+ # @sth.execute("0")
12
+ # else
13
+ # @sth.execute(0)
14
+ # end
15
+ @sth.finish
16
+ end
17
+
18
+ assert_nothing_raised do
19
+ @sth = @dbh.prepare("select * from bit_test")
20
+ @sth.execute
21
+ row = @sth.fetch
22
+ @sth.finish
23
+
24
+ assert_equal [0], row
25
+ end
26
+ end
27
+
28
+ def test_numeric_types
29
+ assert(@dbh.convert_types)
30
+
31
+ @sth = @dbh.prepare("insert into precision_test (text_field, integer_field, decimal_field, numeric_field) values (?, ?, ?, ?)")
32
+ assert(@sth.convert_types)
33
+ 1.step(5) do |x|
34
+ @sth.execute("poop#{x}", x, x + 0.123, x + 0.234)
35
+ end
36
+
37
+ @sth.finish
38
+
39
+ @sth = @dbh.prepare("select integer_field, decimal_field, numeric_field from precision_test")
40
+ @sth.execute
41
+ col_info = @sth.column_info
42
+ 1.step(5) do |x|
43
+ row = @sth.fetch
44
+ assert_kind_of(Integer, row[0])
45
+ assert_kind_of(Float, row[1])
46
+ assert_kind_of(Float, row[2])
47
+
48
+ # FIXME BigDecimal requires a string and some databases will pad
49
+ # decimal/numeric with constrained precision. We should account for
50
+ # this, but I'm not quite sure how yet.
51
+ end
52
+ @sth.finish
53
+ end
54
+
55
+ # FIXME
56
+ # Ideally, this test should be split across the DBI tests and DBD, but for
57
+ # now testing against the DBDs really doesn't cost us anything other than
58
+ # debugging time if something breaks.
59
+ def test_bind_coltype
60
+ # ensure type conv didn't get turned off somewhere.
61
+ assert(DBI.convert_types)
62
+ assert(@dbh.convert_types)
63
+
64
+ assert_nothing_raised do
65
+ @sth = @dbh.prepare("select name, age from names order by age")
66
+ assert(@sth.convert_types) # again
67
+ @sth.execute
68
+ @sth.bind_coltype(2, DBI::Type::Varchar)
69
+ assert_equal(
70
+ [
71
+ ["Joe", "19"],
72
+ ["Bob", "21"],
73
+ ["Jim", "30"],
74
+ ], @sth.fetch_all
75
+ )
76
+ @sth.finish
77
+ end
78
+
79
+ assert_nothing_raised do
80
+ @sth = @dbh.prepare("select age, name from names order by age")
81
+ assert(@sth.convert_types) # again
82
+ @sth.execute
83
+ @sth.bind_coltype(1, DBI::Type::Varchar)
84
+ assert_equal(
85
+ [
86
+ ["19", "Joe"],
87
+ ["21", "Bob"],
88
+ ["30", "Jim"],
89
+ ], @sth.fetch_all
90
+ )
91
+ @sth.finish
92
+ end
93
+
94
+ # just to be sure..
95
+ assert_nothing_raised do
96
+ @sth = @dbh.prepare("select name, age from names order by age")
97
+ @sth.execute
98
+ @sth.bind_coltype(2, DBI::Type::Float)
99
+ @sth.fetch_all.collect { |x| assert_kind_of(Float, x[1]) }
100
+ @sth.finish
101
+ end
102
+
103
+ # now, let's check some failure cases
104
+ @sth = @dbh.prepare("select name, age from names order by age")
105
+
106
+ # can't bind_coltype before execute
107
+ assert_raises(DBI::InterfaceError) { @sth.bind_coltype(1, DBI::Type::Float) }
108
+ # can't index < 1
109
+ assert_raises(DBI::InterfaceError) { @sth.bind_coltype(0, DBI::Type::Float) }
110
+ end
111
+
112
+ def test_noconv
113
+ # XXX this test will fail the whole test suite miserably if it fails at any point.
114
+ assert(DBI.convert_types)
115
+
116
+ DBI.convert_types = false
117
+ @sth.finish rescue nil
118
+ @dbh.disconnect
119
+ set_base_dbh
120
+
121
+ assert(!@dbh.convert_types)
122
+
123
+ assert_nothing_raised do
124
+ @sth = @dbh.prepare("select * from names order by age")
125
+ assert(!@sth.convert_types)
126
+ @sth.execute
127
+ assert_equal(
128
+ [
129
+ ["Joe", "19"],
130
+ ["Bob", "21"],
131
+ ["Jim", "30"],
132
+ ], @sth.fetch_all
133
+ )
134
+ @sth.finish
135
+ end
136
+
137
+ DBI.convert_types = true
138
+ @sth.finish rescue nil
139
+ @dbh.disconnect
140
+ set_base_dbh
141
+
142
+ assert(DBI.convert_types)
143
+ assert(@dbh.convert_types)
144
+
145
+ assert_nothing_raised do
146
+ @sth = @dbh.prepare("select * from names order by age")
147
+ assert(@sth.convert_types)
148
+ @sth.execute
149
+ assert_equal(
150
+ [
151
+ ["Joe", 19],
152
+ ["Bob", 21],
153
+ ["Jim", 30],
154
+ ], @sth.fetch_all
155
+ )
156
+ @sth.finish
157
+ end
158
+
159
+ @dbh.convert_types = false
160
+
161
+ assert_nothing_raised do
162
+ @sth = @dbh.prepare("select * from names order by age")
163
+ assert(!@sth.convert_types)
164
+ @sth.execute
165
+ assert_equal(
166
+ [
167
+ ["Joe", "19"],
168
+ ["Bob", "21"],
169
+ ["Jim", "30"],
170
+ ], @sth.fetch_all
171
+ )
172
+ @sth.finish
173
+ end
174
+
175
+ @dbh.convert_types = true
176
+
177
+ assert_nothing_raised do
178
+ @sth = @dbh.prepare("select * from names order by age")
179
+ assert(@sth.convert_types)
180
+ @sth.convert_types = false
181
+ @sth.execute
182
+ assert_equal(
183
+ [
184
+ ["Joe", "19"],
185
+ ["Bob", "21"],
186
+ ["Jim", "30"],
187
+ ], @sth.fetch_all
188
+ )
189
+ @sth.finish
190
+ end
191
+ rescue Exception => e
192
+ DBI.convert_types = true
193
+ @sth.finish
194
+ @dbh.disconnect
195
+ set_base_dbh
196
+ raise e
197
+ end
198
+
199
+ def test_null
200
+ assert_nothing_raised do
201
+ @sth = @dbh.prepare('insert into names (name, age) values (?, ?)')
202
+ @sth.execute("'NULL'", 201)
203
+ @sth.execute(nil, 202)
204
+ @sth.execute("NULL", 203)
205
+ @sth.finish
206
+ end
207
+
208
+ assert_nothing_raised do
209
+ @sth = @dbh.prepare('select * from names where age > 200 order by age')
210
+ @sth.execute
211
+ assert_equal(["'NULL'", 201], @sth.fetch)
212
+ assert_equal([nil, 202], @sth.fetch)
213
+ assert_equal(["NULL", 203], @sth.fetch)
214
+ @sth.finish
215
+ end
216
+ end
217
+
218
+ def test_time
219
+ @sth = nil
220
+ t = nil
221
+ assert_nothing_raised do
222
+ @sth = @dbh.prepare("insert into time_test (mytime) values (?)")
223
+ t = Time.now
224
+ @sth.execute(t)
225
+ @sth.finish
226
+ end
227
+
228
+ assert_nothing_raised do
229
+ @sth = @dbh.prepare("select * from time_test")
230
+ @sth.execute
231
+ row = @sth.fetch
232
+ assert_kind_of DateTime, row[0]
233
+ assert_equal t.hour, row[0].hour
234
+ assert_equal t.min, row[0].min
235
+ assert_equal t.sec, row[0].sec
236
+ @sth.finish
237
+ end
238
+ end
239
+
240
+ def test_timestamp
241
+ @sth = nil
242
+ # We omit fractional second testing here -- timestamp precision
243
+ # is a very slippery, dependent on driver and driver version.
244
+ t = DBI::Timestamp.new(2008, 3, 8, 10, 39, 1)
245
+ assert_nothing_raised do
246
+ @sth = @dbh.prepare("insert into timestamp_test (mytimestamp) values (?)")
247
+ @sth.execute(t)
248
+ @sth.finish
249
+ end
250
+
251
+ assert_nothing_raised do
252
+ @sth = @dbh.prepare("select * from timestamp_test")
253
+ @sth.execute
254
+ row = @sth.fetch
255
+ assert_kind_of DateTime, row[0]
256
+ assert_equal t.year, row[0].year
257
+ assert_equal t.month, row[0].month
258
+ assert_equal t.day, row[0].day
259
+ assert_equal t.hour, row[0].hour
260
+ assert_equal t.min, row[0].min
261
+ assert_equal t.sec, row[0].sec
262
+ # omit fractional tests
263
+ @sth.finish
264
+ end
265
+ end
266
+
267
+ def test_boolean_return
268
+ @sth = nil
269
+
270
+ unless dbtype == "odbc" # ODBC has no boolean type
271
+ assert_nothing_raised do
272
+ @sth = @dbh.prepare("insert into boolean_test (num, mybool) values (?, ?)")
273
+ @sth.execute(1, true)
274
+ @sth.execute(2, false)
275
+ @sth.finish
276
+ end
277
+
278
+ assert_nothing_raised do
279
+ @sth = @dbh.prepare("select * from boolean_test order by num")
280
+ @sth.execute
281
+
282
+ pairs = @sth.fetch_all
283
+
284
+ assert_equal(
285
+ [
286
+ [1, true],
287
+ [2, false],
288
+ ], pairs
289
+ )
290
+
291
+ @sth.finish
292
+ end
293
+ end
294
+ end
295
+ end
@@ -0,0 +1,26 @@
1
+ DBDConfig.set_testbase(:mysql, Class.new(Test::Unit::TestCase) do
2
+ def dbtype
3
+ "mysql"
4
+ end
5
+
6
+ def test_base
7
+ assert_equal(@dbh.driver_name, "Mysql")
8
+ assert_kind_of(DBI::DBD::Mysql::Database, @dbh.instance_variable_get(:@handle))
9
+ end
10
+
11
+ def set_base_dbh
12
+ config = DBDConfig.get_config["mysql"]
13
+ @dbh = DBI.connect("dbi:Mysql:"+config["dbname"], config["username"], config["password"], { })
14
+ end
15
+
16
+ def setup
17
+ set_base_dbh
18
+ DBDConfig.inject_sql(@dbh, dbtype, "dbd/mysql/up.sql")
19
+ end
20
+
21
+ def teardown
22
+ DBDConfig.inject_sql(@dbh, dbtype, "dbd/mysql/down.sql")
23
+ @dbh.disconnect
24
+ end
25
+ end
26
+ )
@@ -0,0 +1,19 @@
1
+ drop view view_names;
2
+ ---
3
+ drop table names;
4
+ ---
5
+ drop table blob_test;
6
+ ---
7
+ drop table boolean_test;
8
+ ---
9
+ drop table time_test;
10
+ ---
11
+ drop table timestamp_test;
12
+ ---
13
+ drop table bit_test;
14
+ ---
15
+ drop table field_types_test;
16
+ ---
17
+ drop table db_specific_types_test;
18
+ ---
19
+ drop table precision_test;
@@ -0,0 +1,18 @@
1
+ class TestMySQLBlob < DBDConfig.testbase(:mysql)
2
+ def test_blob_round_trip
3
+ data =(0..255).collect{|n| n.chr}.join("")
4
+ sql = "INSERT INTO blob_test (name, data) VALUES (?, ?)"
5
+
6
+ @dbh.do(sql, 'test1', DBI::Binary.new(data))
7
+ @dbh.do(sql, 'test2', data)
8
+
9
+ @dbh.prepare(sql) do |sth|
10
+ sth.execute('test3', DBI::Binary.new(data))
11
+ sth.execute('test4', data)
12
+ end
13
+
14
+ @dbh.select_all("SELECT name, data FROM blob_test") do |name, fetch_data|
15
+ assert_equal fetch_data, data
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ class TestNewMethods < DBDConfig.testbase(:mysql)
2
+ def test_database_name
3
+ assert_nothing_raised do
4
+ assert_equal DBDConfig.get_config[dbtype]['dbname'], @dbh.database_name
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,111 @@
1
+ class TestMysqlPatches < DBDConfig.testbase(:mysql)
2
+ def test_exception_on_aggregate
3
+ assert_nothing_raised do
4
+ sth = @dbh.prepare("select sum(age) from names")
5
+ sth.execute
6
+ row = sth.fetch
7
+ assert_equal(70.0, row[0])
8
+ sth.finish
9
+
10
+ sth = @dbh.prepare("select count(*) from names")
11
+ sth.execute
12
+ assert_equal([3], sth.fetch)
13
+ sth.finish
14
+ end
15
+ end
16
+
17
+ def test_timestamps
18
+ timestamp = "04-06-1978 06:00:00"
19
+ datestamp = "04-06-1978"
20
+ date = Date.strptime(datestamp, "%m-%d-%Y")
21
+ stamp = DateTime.strptime(timestamp, "%m-%d-%Y %H:%M:%S")
22
+ assert_nothing_raised do
23
+ @sth = @dbh.prepare("insert into db_specific_types_test (ts) values (?)")
24
+ @sth.execute(stamp)
25
+ @sth.finish
26
+ end
27
+
28
+ assert_nothing_raised do
29
+ @sth = @dbh.prepare("select ts from db_specific_types_test where ts is not null")
30
+ @sth.execute
31
+
32
+ newstamp = @sth.fetch[0]
33
+
34
+ assert_equal(newstamp, stamp)
35
+ assert_equal(newstamp.strftime("%m-%d-%Y %H:%M:%S"), timestamp)
36
+ @sth.finish
37
+ end
38
+
39
+ assert_nothing_raised do
40
+ @sth = @dbh.prepare("insert into db_specific_types_test (dt) values (?)")
41
+ @sth.execute(date)
42
+ @sth.finish
43
+ end
44
+
45
+ assert_nothing_raised do
46
+ @sth = @dbh.prepare("select dt from db_specific_types_test where dt is not null")
47
+ @sth.execute
48
+
49
+ newdate = @sth.fetch[0]
50
+
51
+ assert_equal(newdate, date)
52
+ assert_equal(newdate.strftime("%m-%d-%Y"), datestamp)
53
+ @sth.finish
54
+ end
55
+ end
56
+
57
+ # FIXME when the spec is more solid, this should be in the general tests
58
+ def test_columns
59
+ assert_nothing_raised do
60
+ assert_equal [
61
+ {
62
+ :name =>"foo",
63
+ :default =>"1",
64
+ :primary =>true,
65
+ :scale =>nil,
66
+ :sql_type =>4,
67
+ :nullable =>false,
68
+ :indexed =>true,
69
+ :precision =>11,
70
+ :type_name =>"int",
71
+ :unique =>true
72
+ }
73
+ ], @dbh.columns("field_types_test")
74
+ end
75
+
76
+ assert_nothing_raised do
77
+ sth = @dbh.prepare("insert into field_types_test (foo) values (?)")
78
+ sth.execute(2)
79
+ sth.finish
80
+ end
81
+
82
+ assert_nothing_raised do
83
+ sth = @dbh.prepare("select * from field_types_test")
84
+ sth.execute
85
+ row = sth.fetch
86
+ columns = sth.column_info
87
+ sth.finish
88
+
89
+ assert_equal [2], row
90
+ assert_equal [
91
+ {
92
+ :dbi_type => DBI::Type::Integer,
93
+ :name =>"foo",
94
+ :mysql_type_name =>"INT",
95
+ :mysql_max_length =>1,
96
+ :primary =>true,
97
+ :scale =>0,
98
+ :mysql_flags =>49155,
99
+ :sql_type =>4,
100
+ :nullable =>false,
101
+ :mysql_type =>3,
102
+ :indexed =>true,
103
+ :mysql_length =>11,
104
+ :precision =>11,
105
+ :type_name =>"INTEGER",
106
+ :unique =>true
107
+ }
108
+ ], columns
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,28 @@
1
+ create table names (
2
+ name varchar(255),
3
+ age integer
4
+ ) Engine=InnoDB;
5
+ ---
6
+ insert into names (name, age) values ('Joe', 19);
7
+ ---
8
+ insert into names (name, age) values ('Jim', 30);
9
+ ---
10
+ insert into names (name, age) values ('Bob', 21);
11
+ ---
12
+ create table precision_test (text_field varchar(20) primary key not null, integer_field integer, decimal_field decimal(2,1), numeric_field numeric(30,6));
13
+ ---
14
+ CREATE TABLE blob_test (name VARCHAR(30), data BLOB) Engine=InnoDB;
15
+ ---
16
+ create view view_names as select * from names;
17
+ ---
18
+ create table boolean_test (num integer, mybool boolean) Engine=InnoDB;
19
+ ---
20
+ create table time_test (mytime time) Engine=InnoDB;
21
+ ---
22
+ create table timestamp_test (mytimestamp timestamp) Engine=InnoDB;
23
+ ---
24
+ create table bit_test (mybit bit) Engine=InnoDB;
25
+ ---
26
+ create table field_types_test (foo integer not null primary key default 1);
27
+ ---
28
+ create table db_specific_types_test (ts timestamp, dt date);
@@ -0,0 +1,30 @@
1
+ require 'fileutils'
2
+
3
+ DBDConfig.set_testbase(:odbc, Class.new(Test::Unit::TestCase) do
4
+
5
+ def dbtype
6
+ "odbc"
7
+ end
8
+
9
+ def test_base
10
+ assert_equal(@dbh.driver_name, "odbc")
11
+ assert_kind_of(DBI::DBD::ODBC::Database, @dbh.instance_variable_get(:@handle))
12
+ end
13
+
14
+ def set_base_dbh
15
+ config = DBDConfig.get_config['odbc']
16
+ @dbh = DBI.connect("dbi:ODBC:#{config['dbname']}", config['username'], config['password'])
17
+ end
18
+
19
+ def setup
20
+ set_base_dbh
21
+ DBDConfig.inject_sql(@dbh, dbtype, "dbd/odbc/up.sql")
22
+ end
23
+
24
+ def teardown
25
+ @sth.finish if @sth && !@sth.finished?
26
+ DBDConfig.inject_sql(@dbh, dbtype, "dbd/odbc/down.sql")
27
+ @dbh.disconnect
28
+ end
29
+ end
30
+ )
@@ -0,0 +1,19 @@
1
+ drop view view_names;
2
+ ---
3
+ drop table names;
4
+ ---
5
+ drop table blob_test;
6
+ ---
7
+ drop table boolean_test;
8
+ ---
9
+ drop table time_test;
10
+ ---
11
+ drop table timestamp_test;
12
+ ---
13
+ drop table bit_test;
14
+ ---
15
+ drop table field_types_test;
16
+ ---
17
+ drop table db_specific_types_test;
18
+ ---
19
+ drop table precision_test;
@@ -0,0 +1,12 @@
1
+ class TestODBCPing < DBDConfig.testbase(:odbc)
2
+ def test_database_name
3
+ #
4
+ # NOTE this test will fail if the database is not named "rubytest". I
5
+ # don't think there's a good way to get around this, so I've set it to
6
+ # what I typically use in my odbc.ini. - erikh
7
+ #
8
+ assert_nothing_raised do
9
+ assert_equal "rubytest", @dbh.database_name
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ class TestODBCPing < DBDConfig.testbase(:odbc)
2
+ def test_ping
3
+ config = DBDConfig.get_config['odbc']
4
+ dbh = DBI.connect("dbi:ODBC:#{config['dbname']}", config['username'], config['password'])
5
+ assert dbh
6
+ assert dbh.ping
7
+ dbh.disconnect
8
+ assert_raises(DBI::InterfaceError) { dbh.ping }
9
+ end
10
+ end
@@ -0,0 +1,44 @@
1
+ class TestODBCStatement < DBDConfig.testbase(:odbc)
2
+ def test_column_info
3
+ sth = nil
4
+
5
+ assert_nothing_raised do
6
+ sth = @dbh.prepare("select * from names")
7
+ sth.execute
8
+ end
9
+
10
+ assert_kind_of Array, sth.column_info
11
+ assert_kind_of DBI::ColumnInfo, sth.column_info[0]
12
+ assert_kind_of DBI::ColumnInfo, sth.column_info[1]
13
+ # XXX odbc seems to have a problem with this every other edition of unixodbc or so.
14
+ # yes, I know this test is important.
15
+ # assert_equal [
16
+ # {
17
+ # :table=>"names",
18
+ # :precision=>255,
19
+ # :searchable=>true,
20
+ # :name=>"name",
21
+ # :unsigned=>true,
22
+ # :length=>255,
23
+ # :sql_type=>12,
24
+ # :scale=>0,
25
+ # :nullable=>true,
26
+ # :type_name=>"VARCHAR"
27
+ # },
28
+ # {
29
+ # :table=>"names",
30
+ # :precision=>10,
31
+ # :searchable=>true,
32
+ # :name=>"age",
33
+ # :unsigned=>false,
34
+ # :length=>4,
35
+ # :sql_type=>4,
36
+ # :scale=>0,
37
+ # :nullable=>true,
38
+ # :type_name=>"INTEGER"
39
+ # }
40
+ # ], sth.column_info
41
+
42
+ sth.finish
43
+ end
44
+ end
@@ -0,0 +1,58 @@
1
+ class TestODBCTransaction < DBDConfig.testbase(:odbc)
2
+ def test_rollback
3
+ dbh = get_dbh
4
+ dbh["AutoCommit"] = false
5
+ @sth = dbh.prepare('insert into names (name, age) values (?, ?)')
6
+ @sth.execute("Foo", 51)
7
+ dbh.rollback
8
+ assert_equal 1, @sth.rows
9
+ @sth.finish
10
+
11
+
12
+ @sth = dbh.prepare('select name, age from names where name=?')
13
+ @sth.execute("Foo")
14
+ assert !@sth.fetch
15
+ @sth.finish
16
+ dbh.disconnect
17
+ end
18
+
19
+ def test_commit
20
+ dbh = get_dbh
21
+ dbh["AutoCommit"] = false
22
+ @sth = dbh.prepare('insert into names (name, age) values (?, ?)')
23
+ @sth.execute("Foo", 51)
24
+ dbh.commit
25
+ assert_equal 1, @sth.rows
26
+ @sth.finish
27
+
28
+ @sth = dbh.prepare('select name, age from names where name=?')
29
+ @sth.execute("Foo")
30
+ row = @sth.fetch
31
+ assert row
32
+ assert_equal "Foo", row[0]
33
+ assert_equal 51, row[1]
34
+ @sth.finish
35
+ dbh.disconnect
36
+ end
37
+
38
+ def test_select_transaction
39
+ # per bug #10466
40
+ dbh = get_dbh
41
+ dbh["AutoCommit"] = false
42
+ @sth = dbh.prepare('select * from test_insert(?, ?)');
43
+ @sth.execute("Foo", 51)
44
+ dbh.rollback
45
+ @sth.finish
46
+
47
+ @sth = dbh.prepare('select name, age from names where name=?')
48
+ @sth.execute("Foo")
49
+ assert !@sth.fetch
50
+ @sth.finish
51
+ dbh.disconnect
52
+ end
53
+
54
+ def get_dbh
55
+ config = DBDConfig.get_config['odbc']
56
+ DBI.connect("dbi:ODBC:#{config['dbname']}", config['username'], config['password'])
57
+ end
58
+ end