ydbi 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/ChangeLog +3699 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/Rakefile +8 -0
  7. data/TODO +44 -0
  8. data/bench/bench.rb +79 -0
  9. data/bin/dbi +518 -0
  10. data/bin/test_broken_dbi +37 -0
  11. data/build/Rakefile.dbi.rb +60 -0
  12. data/build/rake_task_lib.rb +187 -0
  13. data/doc/DBD_SPEC.rdoc +88 -0
  14. data/doc/DBI_SPEC.rdoc +157 -0
  15. data/doc/homepage/contact.html +62 -0
  16. data/doc/homepage/development.html +124 -0
  17. data/doc/homepage/index.html +83 -0
  18. data/doc/homepage/ruby-dbi.css +91 -0
  19. data/examples/test1.pl +39 -0
  20. data/examples/test1.rb +20 -0
  21. data/examples/xmltest.rb +8 -0
  22. data/lib/dbd/Mysql.rb +137 -0
  23. data/lib/dbd/ODBC.rb +89 -0
  24. data/lib/dbd/Pg.rb +188 -0
  25. data/lib/dbd/SQLite.rb +97 -0
  26. data/lib/dbd/SQLite3.rb +124 -0
  27. data/lib/dbd/mysql/database.rb +405 -0
  28. data/lib/dbd/mysql/driver.rb +125 -0
  29. data/lib/dbd/mysql/statement.rb +188 -0
  30. data/lib/dbd/odbc/database.rb +128 -0
  31. data/lib/dbd/odbc/driver.rb +38 -0
  32. data/lib/dbd/odbc/statement.rb +137 -0
  33. data/lib/dbd/pg/database.rb +516 -0
  34. data/lib/dbd/pg/exec.rb +47 -0
  35. data/lib/dbd/pg/statement.rb +160 -0
  36. data/lib/dbd/pg/tuples.rb +121 -0
  37. data/lib/dbd/pg/type.rb +209 -0
  38. data/lib/dbd/sqlite/database.rb +151 -0
  39. data/lib/dbd/sqlite/statement.rb +125 -0
  40. data/lib/dbd/sqlite3/database.rb +201 -0
  41. data/lib/dbd/sqlite3/statement.rb +78 -0
  42. data/lib/dbi.rb +336 -0
  43. data/lib/dbi/base_classes.rb +12 -0
  44. data/lib/dbi/base_classes/database.rb +135 -0
  45. data/lib/dbi/base_classes/driver.rb +47 -0
  46. data/lib/dbi/base_classes/statement.rb +171 -0
  47. data/lib/dbi/binary.rb +25 -0
  48. data/lib/dbi/columninfo.rb +107 -0
  49. data/lib/dbi/exceptions.rb +65 -0
  50. data/lib/dbi/handles.rb +49 -0
  51. data/lib/dbi/handles/database.rb +241 -0
  52. data/lib/dbi/handles/driver.rb +60 -0
  53. data/lib/dbi/handles/statement.rb +408 -0
  54. data/lib/dbi/row.rb +269 -0
  55. data/lib/dbi/sql.rb +22 -0
  56. data/lib/dbi/sql/preparedstatement.rb +115 -0
  57. data/lib/dbi/sql_type_constants.rb +75 -0
  58. data/lib/dbi/trace.rb +91 -0
  59. data/lib/dbi/types.rb +218 -0
  60. data/lib/dbi/typeutil.rb +109 -0
  61. data/lib/dbi/utils.rb +60 -0
  62. data/lib/dbi/utils/date.rb +59 -0
  63. data/lib/dbi/utils/tableformatter.rb +112 -0
  64. data/lib/dbi/utils/time.rb +52 -0
  65. data/lib/dbi/utils/timestamp.rb +96 -0
  66. data/lib/dbi/utils/xmlformatter.rb +73 -0
  67. data/lib/dbi/version.rb +3 -0
  68. data/prototypes/types2.rb +237 -0
  69. data/readme.md +274 -0
  70. data/setup.rb +1585 -0
  71. data/test/DBD_TESTS +50 -0
  72. data/test/TESTING +16 -0
  73. data/test/dbd/general/test_database.rb +206 -0
  74. data/test/dbd/general/test_statement.rb +326 -0
  75. data/test/dbd/general/test_types.rb +296 -0
  76. data/test/dbd/mysql/base.rb +26 -0
  77. data/test/dbd/mysql/down.sql +19 -0
  78. data/test/dbd/mysql/test_blob.rb +18 -0
  79. data/test/dbd/mysql/test_new_methods.rb +7 -0
  80. data/test/dbd/mysql/test_patches.rb +111 -0
  81. data/test/dbd/mysql/up.sql +28 -0
  82. data/test/dbd/odbc/base.rb +30 -0
  83. data/test/dbd/odbc/down.sql +19 -0
  84. data/test/dbd/odbc/test_new_methods.rb +12 -0
  85. data/test/dbd/odbc/test_ping.rb +10 -0
  86. data/test/dbd/odbc/test_statement.rb +44 -0
  87. data/test/dbd/odbc/test_transactions.rb +58 -0
  88. data/test/dbd/odbc/up.sql +33 -0
  89. data/test/dbd/postgresql/base.rb +31 -0
  90. data/test/dbd/postgresql/down.sql +31 -0
  91. data/test/dbd/postgresql/test_arrays.rb +179 -0
  92. data/test/dbd/postgresql/test_async.rb +121 -0
  93. data/test/dbd/postgresql/test_blob.rb +36 -0
  94. data/test/dbd/postgresql/test_bytea.rb +87 -0
  95. data/test/dbd/postgresql/test_ping.rb +10 -0
  96. data/test/dbd/postgresql/test_timestamp.rb +77 -0
  97. data/test/dbd/postgresql/test_transactions.rb +58 -0
  98. data/test/dbd/postgresql/testdbipg.rb +307 -0
  99. data/test/dbd/postgresql/up.sql +60 -0
  100. data/test/dbd/sqlite/base.rb +32 -0
  101. data/test/dbd/sqlite/test_database.rb +30 -0
  102. data/test/dbd/sqlite/test_driver.rb +68 -0
  103. data/test/dbd/sqlite/test_statement.rb +112 -0
  104. data/test/dbd/sqlite/up.sql +25 -0
  105. data/test/dbd/sqlite3/base.rb +32 -0
  106. data/test/dbd/sqlite3/test_database.rb +77 -0
  107. data/test/dbd/sqlite3/test_driver.rb +67 -0
  108. data/test/dbd/sqlite3/test_statement.rb +88 -0
  109. data/test/dbd/sqlite3/up.sql +33 -0
  110. data/test/dbi/tc_columninfo.rb +94 -0
  111. data/test/dbi/tc_date.rb +88 -0
  112. data/test/dbi/tc_dbi.rb +184 -0
  113. data/test/dbi/tc_row.rb +256 -0
  114. data/test/dbi/tc_sqlbind.rb +168 -0
  115. data/test/dbi/tc_statementhandle.rb +29 -0
  116. data/test/dbi/tc_time.rb +77 -0
  117. data/test/dbi/tc_timestamp.rb +142 -0
  118. data/test/dbi/tc_types.rb +268 -0
  119. data/test/ts_dbd.rb +131 -0
  120. data/test/ts_dbi.rb +16 -0
  121. data/ydbi.gemspec +24 -0
  122. metadata +224 -0
@@ -0,0 +1,88 @@
1
+ class TestStatement < DBDConfig.testbase(:sqlite3)
2
+ def test_constructor
3
+ sth = DBI::DBD::SQLite3::Statement.new("select * from names", @dbh.instance_variable_get("@handle").instance_variable_get("@db"))
4
+
5
+ assert_kind_of DBI::DBD::SQLite3::Statement, sth
6
+ assert sth.instance_variable_get("@db")
7
+ assert_kind_of ::SQLite3::Database, sth.instance_variable_get("@db")
8
+ assert_equal(@dbh.instance_variable_get("@handle").instance_variable_get("@db"), sth.instance_variable_get("@db"))
9
+ assert_kind_of ::SQLite3::Statement, sth.instance_variable_get("@stmt")
10
+ assert_nil(@sth.instance_variable_get("@result"))
11
+
12
+ sth.finish
13
+
14
+ sth = @dbh.prepare("select * from names")
15
+
16
+ assert_kind_of DBI::StatementHandle, sth
17
+ sth.finish
18
+ end
19
+
20
+ def test_bind_param
21
+ sth = DBI::DBD::SQLite3::Statement.new("select * from names", @dbh.instance_variable_get("@handle").instance_variable_get("@db"))
22
+
23
+ assert_raises(DBI::InterfaceError) do
24
+ sth.bind_param(:foo, "monkeys")
25
+ end
26
+
27
+ sth.finish
28
+ end
29
+
30
+ def test_column_info
31
+ @sth = nil
32
+
33
+ assert_nothing_raised do
34
+ @sth = @dbh.prepare("select * from names")
35
+ @sth.execute
36
+ end
37
+
38
+ assert_kind_of Array, @sth.column_info
39
+ assert_kind_of DBI::ColumnInfo, @sth.column_info[0]
40
+ assert_kind_of DBI::ColumnInfo, @sth.column_info[1]
41
+ assert_equal [
42
+ {
43
+ :name => "name",
44
+ :sql_type => 12,
45
+ :precision => 255,
46
+ :type_name => "varchar"
47
+ },
48
+ {
49
+ :name => "age",
50
+ :sql_type => 4,
51
+ :type_name => "integer"
52
+ }
53
+ ], @sth.column_info
54
+
55
+ @sth.finish
56
+ end
57
+
58
+ def test_specific_types
59
+ assert_nothing_raised do
60
+ @sth = @dbh.prepare("insert into db_specific_types_test (dbl) values (?)")
61
+ @sth.execute(11111111.111111)
62
+ @sth.execute(22)
63
+ @sth.finish
64
+ end
65
+
66
+ assert_nothing_raised do
67
+ @sth = @dbh.prepare("select * from db_specific_types_test")
68
+ @sth.execute
69
+ assert_equal([11111111.111111], @sth.fetch)
70
+ assert_equal([22], @sth.fetch)
71
+ @sth.finish
72
+
73
+ assert_equal([[11111111.111111], [22]], @dbh.select_all("select * from db_specific_types_test"))
74
+ end
75
+
76
+ assert_nothing_raised do
77
+ @sth = @dbh.prepare("insert into names (name, age) values (?, ?)")
78
+ @sth.execute(:joseph, 20)
79
+ @sth.finish
80
+
81
+ @sth = @dbh.prepare("select name, age from names where name=?")
82
+ @sth.execute("joseph")
83
+ rows = @sth.fetch_all
84
+ @sth.finish
85
+ assert_equal(rows, [["joseph", 20]])
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,33 @@
1
+ create table names (name varchar(255), age integer);
2
+ ---
3
+ insert into names (name, age) values ("Bob", 21);
4
+ ---
5
+ insert into names (name, age) values ("Joe", 19);
6
+ ---
7
+ insert into names (name, age) values ("Jim", 30);
8
+ ---
9
+ 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));
10
+ ---
11
+ create view view_names as select * from names;
12
+ ---
13
+ create table blob_test (name varchar(255));
14
+ ---
15
+ create table boolean_test (num integer, mybool boolean);
16
+ ---
17
+ create table time_test (mytime time);
18
+ ---
19
+ create table timestamp_test (mytimestamp timestamp);
20
+ ---
21
+ create table bit_test (mybit bit);
22
+ ---
23
+ create table field_types_test (foo integer not null primary key default 1);
24
+ ---
25
+ create table db_specific_types_test (dbl double);
26
+ ---
27
+ create table names_defined_with_spaces ( name varchar( 255 ), age integer );
28
+ ---
29
+ insert into names_defined_with_spaces (name, age) values ("Bob", 21);
30
+ ---
31
+ insert into names_defined_with_spaces (name, age) values ("Joe", 19);
32
+ ---
33
+ insert into names_defined_with_spaces (name, age) values ("Jim", 30);
@@ -0,0 +1,94 @@
1
+ ############################################################
2
+ # tc_columninfo.rb
3
+ #
4
+ # Test case for the DBI::ColumnInfo class.
5
+ ############################################################
6
+ $LOAD_PATH.unshift(Dir.pwd)
7
+ $LOAD_PATH.unshift(File.dirname(Dir.pwd))
8
+ $LOAD_PATH.unshift("../../lib")
9
+ $LOAD_PATH.unshift("../../lib/dbi")
10
+ $LOAD_PATH.unshift("lib")
11
+
12
+ require "dbi/columninfo"
13
+ require "test/unit"
14
+
15
+ class TC_DBI_ColumnInfo < Test::Unit::TestCase
16
+ def setup
17
+ @colinfo = DBI::ColumnInfo.new(
18
+ "name" => "test",
19
+ "sql_type" => "numeric",
20
+ "type_name" => "test_type_name",
21
+ "precision" => 2,
22
+ "scale" => 2,
23
+ "default" => 100.00,
24
+ "nullable" => false,
25
+ "indexed" => true,
26
+ "primary" => true,
27
+ "unique" => false
28
+ )
29
+ @keys = %w/name sql_type type_name precision scale default nullable
30
+ indexed primary unique
31
+ /
32
+ end
33
+
34
+ def test_constructor
35
+ assert_nothing_raised{ DBI::ColumnInfo.new }
36
+
37
+ assert_nothing_raised do
38
+ DBI::ColumnInfo.new({"foo" => "bar", "baz" => "quux"})
39
+ DBI::ColumnInfo.new({:foo => "bar", :baz => "quux"})
40
+ end
41
+
42
+ assert_raises(ArgumentError) do
43
+ DBI::ColumnInfo.new({"foo" => "bar", :foo => "quux"})
44
+ end
45
+ end
46
+
47
+ def test_accessors
48
+ assert_nothing_raised do
49
+ @keys.each do |x|
50
+ assert_equal(@colinfo[x], @colinfo[x.to_sym])
51
+ assert_equal(@colinfo.send(x.to_sym), @colinfo[x.to_sym])
52
+ @colinfo[x] = "poop"
53
+ assert_equal("poop", @colinfo[x])
54
+ assert_equal("poop", @colinfo[x.to_sym])
55
+ end
56
+ end
57
+ end
58
+
59
+ def test_precision_basic
60
+ assert_respond_to(@colinfo, :size)
61
+ assert_respond_to(@colinfo, :size=)
62
+ assert_respond_to(@colinfo, :length)
63
+ assert_respond_to(@colinfo, :length=)
64
+ end
65
+
66
+ def test_scale_basic
67
+ assert_respond_to(@colinfo, :decimal_digits)
68
+ assert_respond_to(@colinfo, :decimal_digits=)
69
+ end
70
+
71
+ def test_default_value_basic
72
+ assert_respond_to(@colinfo, :default_value)
73
+ assert_respond_to(@colinfo, :default_value=)
74
+ end
75
+
76
+ def test_unique_basic
77
+ assert_respond_to(@colinfo, :is_unique)
78
+ end
79
+
80
+ def test_keys
81
+ assert_respond_to(@colinfo, :keys)
82
+ assert_equal(@keys.sort, @colinfo.keys.collect { |x| x.to_s }.sort)
83
+ end
84
+
85
+ def test_respond_to_hash_methods
86
+ assert_respond_to(@colinfo, :each)
87
+ assert_respond_to(@colinfo, :empty?)
88
+ assert_respond_to(@colinfo, :has_key?)
89
+ end
90
+
91
+ def teardown
92
+ @colinfo = nil
93
+ end
94
+ end
@@ -0,0 +1,88 @@
1
+ ##############################################################################
2
+ # tc_date.rb
3
+ #
4
+ # Test case for the DBI::Date class (currently) located in the utils.rb file.
5
+ ##############################################################################
6
+ $LOAD_PATH.unshift(Dir.pwd)
7
+ $LOAD_PATH.unshift(File.dirname(Dir.pwd))
8
+ $LOAD_PATH.unshift("../../lib")
9
+ $LOAD_PATH.unshift("../../lib/dbi")
10
+ $LOAD_PATH.unshift("lib")
11
+
12
+ require 'date'
13
+ require 'dbi'
14
+ require 'test/unit'
15
+
16
+ Deprecate.set_action(proc { })
17
+
18
+ class TC_DBI_Date < Test::Unit::TestCase
19
+ def setup
20
+ @date = Date.new
21
+ @time = Time.now
22
+ @dbi_date = DBI::Date.new
23
+ end
24
+
25
+ def test_constructor
26
+ assert_nothing_raised{ DBI::Date.new(2006) }
27
+ assert_nothing_raised{ DBI::Date.new(2006, 1) }
28
+ assert_nothing_raised{ DBI::Date.new(2006, 1, 20) }
29
+ assert_nothing_raised{ DBI::Date.new(Date.new) }
30
+ assert_nothing_raised{ DBI::Date.new(Time.now) }
31
+ end
32
+
33
+ def test_year
34
+ assert_respond_to(@dbi_date, :year)
35
+ assert_respond_to(@dbi_date, :year=)
36
+ assert_equal(0, @dbi_date.year)
37
+ end
38
+
39
+ def test_month
40
+ assert_respond_to(@dbi_date, :month)
41
+ assert_respond_to(@dbi_date, :month=)
42
+ end
43
+
44
+ # An alias for :month, :month=
45
+ def test_mon
46
+ assert_respond_to(@dbi_date, :mon)
47
+ assert_respond_to(@dbi_date, :mon=)
48
+ assert_equal(0, @dbi_date.mon)
49
+ end
50
+
51
+ def test_day
52
+ assert_respond_to(@dbi_date, :day)
53
+ assert_respond_to(@dbi_date, :day=)
54
+ assert_equal(0, @dbi_date.day)
55
+ end
56
+
57
+ # An alias for :day, :day=
58
+ def test_mday
59
+ assert_respond_to(@dbi_date, :mday)
60
+ assert_respond_to(@dbi_date, :mday=)
61
+ end
62
+
63
+ def test_to_time
64
+ assert_respond_to(@dbi_date, :to_time)
65
+ assert_equal(@time, DBI::Date.new(@time).to_time)
66
+ assert_equal(@time.object_id, DBI::Date.new(@time).to_time.object_id)
67
+ end
68
+
69
+ def test_to_date
70
+ assert_respond_to(@dbi_date, :to_date)
71
+ assert_equal(@date, DBI::Date.new(@date).to_date)
72
+ assert_equal(@date.object_id, DBI::Date.new(@date).to_date.object_id)
73
+ end
74
+
75
+ # We test .to_s because it has an explicit implementation
76
+ def test_to_s
77
+ assert_respond_to(@dbi_date, :to_s)
78
+ assert_nothing_raised{ @dbi_date.to_s }
79
+ assert_kind_of(String, @dbi_date.to_s)
80
+ assert_equal("0000-00-00", @dbi_date.to_s)
81
+ end
82
+
83
+ def teardown
84
+ @date = nil
85
+ @time = nil
86
+ @dbi_date = nil
87
+ end
88
+ end
@@ -0,0 +1,184 @@
1
+ ######################################################################
2
+ # tc_dbi.rb
3
+ #
4
+ # Test case for the DBI module (dbi.rb).
5
+ ######################################################################
6
+ $LOAD_PATH.unshift(Dir.pwd)
7
+ $LOAD_PATH.unshift(File.dirname(Dir.pwd))
8
+ $LOAD_PATH.unshift("../../lib")
9
+ $LOAD_PATH.unshift("../../lib/dbi")
10
+ $LOAD_PATH.unshift("lib")
11
+
12
+ require 'dbi'
13
+ require 'test/unit'
14
+
15
+ class TC_DBI < Test::Unit::TestCase
16
+ def setup
17
+ @db_error = DBI::DatabaseError.new("test", 1, "montana")
18
+ @db_binary = DBI::Binary.new("test")
19
+ @url_basic = 'dbi:foo:bar'
20
+ @url_inter = 'dbi:foo:bar:host'
21
+ @url_advan = 'dbi:foo:database=db;host=xx;port=99'
22
+ end
23
+
24
+ def test_dbi_version
25
+ assert_equal("0.5.0", DBI::VERSION)
26
+ end
27
+
28
+ def test_dbd_module
29
+ assert_equal("0.3", DBI::DBD::API_VERSION)
30
+ end
31
+
32
+ def test_fetch_scroll_constants
33
+ assert_equal(1, DBI::SQL_FETCH_NEXT)
34
+ assert_equal(2, DBI::SQL_FETCH_PRIOR)
35
+ assert_equal(3, DBI::SQL_FETCH_FIRST)
36
+ assert_equal(4, DBI::SQL_FETCH_LAST)
37
+ assert_equal(5, DBI::SQL_FETCH_ABSOLUTE)
38
+ assert_equal(6, DBI::SQL_FETCH_RELATIVE)
39
+ end
40
+
41
+ def test_sql_type_constants
42
+ assert_equal(1, DBI::SQL_CHAR)
43
+ assert_equal(2, DBI::SQL_NUMERIC)
44
+ assert_equal(3, DBI::SQL_DECIMAL)
45
+ assert_equal(4, DBI::SQL_INTEGER)
46
+ assert_equal(5, DBI::SQL_SMALLINT)
47
+ assert_equal(6, DBI::SQL_FLOAT)
48
+ assert_equal(7, DBI::SQL_REAL)
49
+ assert_equal(8, DBI::SQL_DOUBLE)
50
+ assert_equal(9, DBI::SQL_DATE)
51
+ assert_equal(10, DBI::SQL_TIME)
52
+ assert_equal(11, DBI::SQL_TIMESTAMP)
53
+ assert_equal(12, DBI::SQL_VARCHAR)
54
+ assert_equal(100, DBI::SQL_OTHER)
55
+ assert_equal(-1, DBI::SQL_LONGVARCHAR)
56
+ assert_equal(-2, DBI::SQL_BINARY)
57
+ assert_equal(-3, DBI::SQL_VARBINARY)
58
+ assert_equal(-4, DBI::SQL_LONGVARBINARY)
59
+ assert_equal(-5, DBI::SQL_BIGINT)
60
+ assert_equal(-6, DBI::SQL_TINYINT)
61
+ assert_equal(-7, DBI::SQL_BIT)
62
+ assert_equal(-10, DBI::SQL_BLOB)
63
+ assert_equal(-11, DBI::SQL_CLOB)
64
+ end
65
+
66
+ def test_sql_type_names
67
+ assert_equal('BIT', DBI::SQL_TYPE_NAMES[DBI::SQL_BIT])
68
+ assert_equal('TINYINT', DBI::SQL_TYPE_NAMES[DBI::SQL_TINYINT])
69
+ assert_equal('SMALLINT', DBI::SQL_TYPE_NAMES[DBI::SQL_SMALLINT])
70
+ assert_equal('INTEGER', DBI::SQL_TYPE_NAMES[DBI::SQL_INTEGER])
71
+ assert_equal('BIGINT', DBI::SQL_TYPE_NAMES[DBI::SQL_BIGINT])
72
+ assert_equal('FLOAT', DBI::SQL_TYPE_NAMES[DBI::SQL_FLOAT])
73
+ assert_equal('REAL', DBI::SQL_TYPE_NAMES[DBI::SQL_REAL])
74
+ assert_equal('DOUBLE', DBI::SQL_TYPE_NAMES[DBI::SQL_DOUBLE])
75
+ assert_equal('NUMERIC', DBI::SQL_TYPE_NAMES[DBI::SQL_NUMERIC])
76
+ assert_equal('DECIMAL', DBI::SQL_TYPE_NAMES[DBI::SQL_DECIMAL])
77
+ assert_equal('CHAR', DBI::SQL_TYPE_NAMES[DBI::SQL_CHAR])
78
+ assert_equal('VARCHAR', DBI::SQL_TYPE_NAMES[DBI::SQL_VARCHAR])
79
+ assert_equal('LONG VARCHAR', DBI::SQL_TYPE_NAMES[DBI::SQL_LONGVARCHAR])
80
+ assert_equal('DATE', DBI::SQL_TYPE_NAMES[DBI::SQL_DATE])
81
+ assert_equal('TIME', DBI::SQL_TYPE_NAMES[DBI::SQL_TIME])
82
+ assert_equal('TIMESTAMP', DBI::SQL_TYPE_NAMES[DBI::SQL_TIMESTAMP])
83
+ assert_equal('BINARY', DBI::SQL_TYPE_NAMES[DBI::SQL_BINARY])
84
+ assert_equal('VARBINARY', DBI::SQL_TYPE_NAMES[DBI::SQL_VARBINARY])
85
+ assert_equal('LONG VARBINARY',
86
+ DBI::SQL_TYPE_NAMES[DBI::SQL_LONGVARBINARY])
87
+ assert_equal('BLOB', DBI::SQL_TYPE_NAMES[DBI::SQL_BLOB])
88
+ assert_equal('CLOB', DBI::SQL_TYPE_NAMES[DBI::SQL_CLOB])
89
+ assert_equal(nil, DBI::SQL_TYPE_NAMES[DBI::SQL_OTHER])
90
+ end
91
+
92
+ def test_dbi_exception_classes
93
+ assert(DBI::Error)
94
+ assert(DBI::Warning)
95
+ assert(DBI::InterfaceError)
96
+ assert(DBI::NotImplementedError)
97
+ assert(DBI::DatabaseError)
98
+ assert(DBI::DataError)
99
+ assert(DBI::OperationalError)
100
+ assert(DBI::IntegrityError)
101
+ assert(DBI::InternalError)
102
+ assert(DBI::ProgrammingError)
103
+ assert(DBI::NotSupportedError)
104
+ end
105
+
106
+ # This error class gets extra testing since it defines some custom
107
+ # accessors.
108
+ def test_dbi_database_error
109
+ assert_respond_to(@db_error, :errstr)
110
+ assert_respond_to(@db_error, :err)
111
+ assert_respond_to(@db_error, :state)
112
+ assert_equal("test", @db_error.errstr)
113
+ assert_equal(1, @db_error.err)
114
+ assert_equal("montana", @db_error.state)
115
+ end
116
+
117
+ def test_binary_datatype
118
+ assert_respond_to(@db_binary, :data)
119
+ assert_respond_to(@db_binary, :to_s)
120
+ assert_equal("test", @db_binary.data)
121
+ assert_equal("test", @db_binary.to_s)
122
+ end
123
+
124
+ def test_misc_constants
125
+ assert_equal(2, DBI::DEFAULT_TRACE_MODE)
126
+ assert_equal(STDERR, DBI::DEFAULT_TRACE_OUTPUT)
127
+ end
128
+
129
+ def test_last_connection
130
+ assert_respond_to(DBI, :last_connection)
131
+ end
132
+
133
+ def test_convert_types
134
+ assert_respond_to(DBI, :convert_types)
135
+ assert_respond_to(DBI, :convert_types=)
136
+ end
137
+
138
+ def test_connect
139
+ assert_respond_to(DBI, :connect)
140
+ end
141
+
142
+ def test_available_drivers
143
+ assert_respond_to(DBI, :available_drivers)
144
+ assert_equal(
145
+ [
146
+ "dbi:Mysql:",
147
+ "dbi:ODBC:",
148
+ "dbi:Pg:",
149
+ "dbi:SQLite3:",
150
+ "dbi:SQLite:"
151
+ ], DBI.available_drivers.sort)
152
+ end
153
+
154
+ # PRIVATE METHODS
155
+ def test_parse_url
156
+ assert_nothing_raised{ DBI.send(:parse_url, "dbi:foo:bar") }
157
+ assert_equal(["foo","bar"], DBI.send(:parse_url, @url_basic))
158
+ assert_equal(["foo","bar:host"], DBI.send(:parse_url, @url_inter))
159
+ assert_equal(["foo","database=db;host=xx;port=99"],
160
+ DBI.send(:parse_url, @url_advan)
161
+ )
162
+ end
163
+
164
+ def test_parse_url_expected_errors
165
+ assert_raises(DBI::InterfaceError){ DBI.send(:parse_url, 'dbi') }
166
+ assert_raises(DBI::InterfaceError){ DBI.send(:parse_url, 'dbi::foo') }
167
+
168
+ # XXX we're looking for a specific exception message here
169
+ assert_nothing_raised do
170
+ begin
171
+ DBI.send(:parse_url, 'dbi:blah')
172
+ rescue DBI::InterfaceError => e
173
+ assert true
174
+ assert_kind_of DBI::InterfaceError, e
175
+ assert_equal "Invalid Data Source Name", e.message
176
+ end
177
+ end
178
+ end
179
+
180
+ def teardown
181
+ @db_error = nil
182
+ @db_binary = nil
183
+ end
184
+ end