ydbi 0.5.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 (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,60 @@
1
+ create table names (
2
+ name varchar(255),
3
+ age integer
4
+ );
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 OID);
15
+ ---
16
+ create view view_names as select * from names;
17
+ ---
18
+ create or replace function test_insert (varchar(255), integer)
19
+ returns integer
20
+ language sql
21
+ as 'insert into names (name, age) values ($1, $2); select age from names where name = $1';
22
+ ---
23
+ create table boolean_test (num integer, mybool boolean);
24
+ ---
25
+ create table time_test (mytime time);
26
+ ---
27
+ create table timestamp_test (mytimestamp timestamp);
28
+ ---
29
+ create table bit_test (mybit bit);
30
+ ---
31
+ create table field_types_test (foo integer not null primary key default 1);
32
+ ---
33
+ create type enum_test as ENUM ('one', 'two', 'three');
34
+ ---
35
+ create table enum_type_test (foo enum_test);
36
+ ---
37
+ create table db_specific_types_test (foo integer);
38
+ ---
39
+ create table array_test (foo integer[], bar integer[3], baz integer[3][3], quux varchar[2]);
40
+ ---
41
+ create table bytea_test (foo bytea);
42
+ ---
43
+ create schema schema1;
44
+ ---
45
+ create schema schema2;
46
+ ---
47
+ create table schema1.tbl (foo integer);
48
+ ---
49
+ create table schema2.tbl (bar integer);
50
+ ---
51
+ create or replace function
52
+ select_subproperty(value names.age%TYPE, sub names.age%TYPE, out retval names.age%TYPE)
53
+ as $$
54
+ select
55
+ case
56
+ when $2 is not null
57
+ then $1
58
+ else null
59
+ end
60
+ $$ language sql;
@@ -0,0 +1,32 @@
1
+ require 'fileutils'
2
+
3
+ DBDConfig.set_testbase(:sqlite, Class.new(Test::Unit::TestCase) do
4
+
5
+ def dbtype
6
+ "sqlite"
7
+ end
8
+
9
+ def test_base
10
+ if @dbh # FIXME for some reason, @dbh isn't initialized in some cases. investigate.
11
+ assert_equal(@dbh.driver_name, "SQLite")
12
+ assert_kind_of(DBI::DBD::SQLite::Database, @dbh.instance_variable_get(:@handle))
13
+ end
14
+ end
15
+
16
+ def set_base_dbh
17
+ config = DBDConfig.get_config['sqlite']
18
+ @dbh = DBI.connect('dbi:SQLite:'+config['dbname'], nil, nil, { })
19
+ end
20
+
21
+ def setup
22
+ set_base_dbh
23
+ DBDConfig.inject_sql(@dbh, dbtype, "dbd/sqlite/up.sql")
24
+ end
25
+
26
+ def teardown
27
+ @dbh.disconnect if @dbh.connected?
28
+ config = DBDConfig.get_config['sqlite']
29
+ FileUtils.rm_f(config['dbname'])
30
+ end
31
+ end
32
+ )
@@ -0,0 +1,30 @@
1
+ class TestSQLiteDatabase < DBDConfig.testbase(:sqlite)
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
+
8
+ def test_disconnect
9
+ assert_nil @dbh.disconnect
10
+ assert_nil @dbh.instance_variable_get("@db")
11
+ end
12
+
13
+ def test_columns
14
+ assert_equal [
15
+ {
16
+ :name => "name",
17
+ :default => nil,
18
+ :nullable => true,
19
+ :precision => 255,
20
+ :type_name => "varchar"
21
+ },
22
+ {
23
+ :name => "age",
24
+ :default => nil,
25
+ :nullable => true,
26
+ :type_name => "integer"
27
+ }
28
+ ], @dbh.columns("names")
29
+ end
30
+ end
@@ -0,0 +1,68 @@
1
+ class TestSQLiteDriver < DBDConfig.testbase(:sqlite)
2
+ def test_require
3
+ require 'dbd/SQLite'
4
+ assert_kind_of Module, DBI
5
+ assert_kind_of Module, DBI::DBD
6
+ assert_kind_of Class, DBI::DBD::SQLite
7
+ assert_kind_of Class, DBI::DBD::SQLite::Driver
8
+ assert_kind_of Class, DBI::DBD::SQLite::Database
9
+ assert_kind_of Class, DBI::DBD::SQLite::Statement
10
+ end
11
+
12
+ def test_connect
13
+ config = DBDConfig.get_config['sqlite']
14
+
15
+ # this tests DBI more than SQLite, but makes sure our chain works with it.
16
+ dbh = DBI.connect("dbi:SQLite:" + config['dbname'], nil, nil, {})
17
+ assert dbh
18
+ assert_kind_of DBI::DatabaseHandle, dbh
19
+
20
+ # first argument should be a string
21
+ assert_raises(DBI::InterfaceError) do
22
+ DBI::DBD::SQLite::Driver.new.connect(nil, nil, nil, { })
23
+ end
24
+
25
+ # that string should have some frackin' length
26
+ assert_raises(DBI::InterfaceError) do
27
+ DBI::DBD::SQLite::Driver.new.connect("", nil, nil, { })
28
+ end
29
+
30
+ # last argument should be a hash
31
+ assert_raises(DBI::InterfaceError) do
32
+ DBI::DBD::SQLite::Driver.new.connect(config['dbname'], nil, nil, nil)
33
+ end
34
+
35
+ dbh = nil
36
+ driver = nil
37
+ assert_nothing_raised do
38
+ driver = DBI::DBD::SQLite::Driver.new
39
+ dbh = driver.connect(config['dbname'], nil, nil, { })
40
+ end
41
+
42
+ assert_kind_of DBI::DBD::SQLite::Driver, driver
43
+ assert_kind_of DBI::DBD::SQLite::Database, dbh
44
+
45
+ assert !dbh.instance_variable_get("@autocommit")
46
+
47
+ dbh = nil
48
+ driver = nil
49
+ assert_nothing_raised do
50
+ dbh = DBI::DBD::SQLite::Driver.new.connect(config['dbname'], nil, nil, { "AutoCommit" => true, "sqlite_full_column_names" => true })
51
+ end
52
+
53
+ assert dbh
54
+ assert dbh.instance_variable_get("@attr_hash")
55
+ assert_equal 0, dbh.instance_variable_get("@open_handles")
56
+ assert_kind_of SQLite::Database, dbh.instance_variable_get("@db")
57
+
58
+ assert File.exists?(config['dbname'])
59
+ end
60
+
61
+ def setup
62
+ end
63
+
64
+ def teardown
65
+ config = DBDConfig.get_config['sqlite']
66
+ FileUtils.rm_f(config['dbname'])
67
+ end
68
+ end
@@ -0,0 +1,112 @@
1
+ class TestSQLiteStatement < DBDConfig.testbase(:sqlite)
2
+ def test_constructor
3
+ sth = DBI::DBD::SQLite::Statement.new("select * from foo", @dbh.instance_variable_get("@handle"))
4
+
5
+ assert_kind_of DBI::DBD::SQLite::Statement, sth
6
+ assert sth.instance_variable_get("@dbh")
7
+ assert_kind_of DBI::DBD::SQLite::Database, sth.instance_variable_get("@dbh")
8
+ assert_equal(@dbh.instance_variable_get("@handle"), sth.instance_variable_get("@dbh"))
9
+ assert_kind_of DBI::SQL::PreparedStatement, sth.instance_variable_get("@statement")
10
+ assert_equal({ }, sth.instance_variable_get("@attr"))
11
+ assert_equal([ ], sth.instance_variable_get("@params"))
12
+ assert_nil(sth.instance_variable_get("@result_set"))
13
+ assert_equal([ ], sth.instance_variable_get("@rows"))
14
+
15
+ sth = @dbh.prepare("select * from foo")
16
+
17
+ assert_kind_of DBI::StatementHandle, sth
18
+ end
19
+
20
+ def test_bind_param
21
+ sth = DBI::DBD::SQLite::Statement.new("select * from foo", @dbh.instance_variable_get("@handle"))
22
+
23
+ assert_raises(DBI::InterfaceError) do
24
+ sth.bind_param(:foo, "monkeys")
25
+ end
26
+
27
+ # XXX this is fairly ugly, but...
28
+ # what i've attempted to do here is normalize what is tested, even
29
+ # though the data differs subtly. you'll notice that there are two
30
+ # arrays that get passed to the each block for evaluation. the first
31
+ # argument is the statment handle (raw from SQLite DBD or the facade
32
+ # from DBI), the second is how we access the @params internally held
33
+ # variable, and the third is how these params are scrubbed before we
34
+ # assert against them.
35
+ #
36
+ # the @params variable is in different spots in both statement handles
37
+ # and the values of the params are quoted differently. However, the
38
+ # full pipe works and I'd like to ensure that both do their job as a
39
+ # team.
40
+ #
41
+ [
42
+ [
43
+ sth,
44
+ proc { |x| x.instance_variable_get("@params") },
45
+ proc { |x| x }
46
+ ],
47
+ [
48
+ @dbh.prepare("select * from foo"),
49
+ proc { |x| x.instance_variable_get("@handle").instance_variable_get("@params") },
50
+ proc { |x| x.gsub(/(^')|('$)/, '') }
51
+ ]
52
+ ].each do |sthpack|
53
+ sthpack[0].bind_param(1, "monkeys", nil)
54
+
55
+ params = sthpack[1].call(sthpack[0])
56
+
57
+ assert_equal "monkeys", sthpack[2].call(params[0])
58
+
59
+ # set a bunch of stuff.
60
+ %w(I like monkeys).each_with_index { |x, i| sthpack[0].bind_param(i+1, x) }
61
+
62
+ params = sthpack[1].call(sthpack[0])
63
+
64
+ assert_equal %w(I like monkeys), params.collect { |x| sthpack[2].call(x) }
65
+
66
+ # FIXME what to do with attributes? are they important in SQLite?
67
+ end
68
+ end
69
+
70
+ def test_column_info
71
+ sth = nil
72
+
73
+ assert_nothing_raised do
74
+ sth = @dbh.prepare("select * from names")
75
+ sth.execute
76
+ end
77
+
78
+ assert_kind_of Array, sth.column_info
79
+ assert_kind_of DBI::ColumnInfo, sth.column_info[0]
80
+ assert_kind_of DBI::ColumnInfo, sth.column_info[1]
81
+ assert_equal [
82
+ {
83
+ :name => "name",
84
+ :sql_type => 12,
85
+ :precision => 255,
86
+ :type_name => "varchar"
87
+ },
88
+ {
89
+ :name => "age",
90
+ :sql_type => 4,
91
+ :type_name => "integer"
92
+ }
93
+ ], sth.column_info
94
+
95
+ sth.finish
96
+ end
97
+
98
+ def test_specific_types
99
+ assert_nothing_raised do
100
+ @sth = @dbh.prepare("insert into db_specific_types_test (dbl) values (?)")
101
+ @sth.execute(11111111.111111)
102
+ @sth.finish
103
+ end
104
+
105
+ assert_nothing_raised do
106
+ @sth = @dbh.prepare("select * from db_specific_types_test")
107
+ @sth.execute
108
+ assert_equal([11111111.111111], @sth.fetch)
109
+ @sth.finish
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,25 @@
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);
@@ -0,0 +1,32 @@
1
+ require 'fileutils'
2
+
3
+ DBDConfig.set_testbase(:sqlite3, Class.new(Test::Unit::TestCase) do
4
+ def dbtype
5
+ "sqlite3"
6
+ end
7
+
8
+ def test_base
9
+ if @dbh # FIXME for some reason, @dbh isn't initialized in some cases. investigate.
10
+ assert_equal(@dbh.driver_name, "SQLite3")
11
+ assert_kind_of(DBI::DBD::SQLite3::Database, @dbh.instance_variable_get(:@handle))
12
+ end
13
+ end
14
+
15
+ def set_base_dbh
16
+ config = DBDConfig.get_config['sqlite3']
17
+ @dbh = DBI.connect('dbi:SQLite3:'+config['dbname'], nil, nil, { })
18
+ end
19
+
20
+ def setup
21
+ set_base_dbh
22
+ DBDConfig.inject_sql(@dbh, dbtype, "dbd/sqlite3/up.sql")
23
+ end
24
+
25
+ def teardown
26
+ @sth.finish if(@sth && !@sth.finished?)
27
+ @dbh.disconnect if @dbh.connected?
28
+ config = DBDConfig.get_config['sqlite3']
29
+ FileUtils.rm_f(config['dbname'])
30
+ end
31
+ end
32
+ )
@@ -0,0 +1,77 @@
1
+ class TestDatabase < DBDConfig.testbase(:sqlite3)
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
+
8
+ def test_disconnect
9
+ assert_nil @dbh.disconnect
10
+ assert_nil @dbh.instance_variable_get("@db")
11
+ end
12
+
13
+ def test_columns
14
+ assert_equal [
15
+ {
16
+ :name => "name",
17
+ :default => nil,
18
+ :nullable => true,
19
+ :sql_type => 100,
20
+ :precision => 255,
21
+ :type_name => "varchar"
22
+ },
23
+ {
24
+ :name => "age",
25
+ :default => nil,
26
+ :nullable => true,
27
+ :sql_type => 4,
28
+ :type_name => "integer"
29
+ }
30
+ ], @dbh.columns("names")
31
+
32
+ assert_equal [
33
+ {
34
+ :name => "name",
35
+ :default => nil,
36
+ :nullable => true,
37
+ :sql_type => 100,
38
+ :precision => 255,
39
+ :type_name => "varchar"
40
+ },
41
+ {
42
+ :name => "age",
43
+ :default => nil,
44
+ :nullable => true,
45
+ :sql_type => 4,
46
+ :type_name => "integer"
47
+ }
48
+ ], @dbh.columns("names_defined_with_spaces")
49
+ end
50
+
51
+ def test_parse_type
52
+ # Some tests to ensure various whitespace and case styles don't confuse parse_type.
53
+
54
+ match = DBI::DBD::SQLite3.parse_type( 'VARCHAR' )
55
+ assert_equal 'VARCHAR', match[ 1 ]
56
+
57
+ match = DBI::DBD::SQLite3.parse_type( 'VARCHAR(4096)' )
58
+ assert_equal 'VARCHAR', match[ 1 ]
59
+ assert_equal '4096', match[ 3 ]
60
+
61
+ match = DBI::DBD::SQLite3.parse_type( 'varchar(4096)' )
62
+ assert_equal 'varchar', match[ 1 ]
63
+ assert_equal '4096', match[ 3 ]
64
+
65
+ match = DBI::DBD::SQLite3.parse_type( 'VARCHAR( 4096 )' )
66
+ assert_equal 'VARCHAR', match[ 1 ]
67
+ assert_equal '4096', match[ 3 ]
68
+
69
+ match = DBI::DBD::SQLite3.parse_type( 'VARCHAR ( 4096 )' )
70
+ assert_equal 'VARCHAR', match[ 1 ]
71
+ assert_equal '4096', match[ 3 ]
72
+
73
+ match = DBI::DBD::SQLite3.parse_type( 'VARCHAR (4096)' )
74
+ assert_equal 'VARCHAR', match[ 1 ]
75
+ assert_equal '4096', match[ 3 ]
76
+ end
77
+ end
@@ -0,0 +1,67 @@
1
+ class TestDriver < DBDConfig.testbase(:sqlite3)
2
+ def test_require
3
+ require 'dbd/SQLite3'
4
+ assert_kind_of Module, DBI
5
+ assert_kind_of Module, DBI::DBD
6
+ assert_kind_of Module, DBI::DBD::SQLite3
7
+ assert_kind_of Class, DBI::DBD::SQLite3::Driver
8
+ assert_kind_of Class, DBI::DBD::SQLite3::Database
9
+ assert_kind_of Class, DBI::DBD::SQLite3::Statement
10
+ end
11
+
12
+ def test_connect
13
+ config = DBDConfig.get_config['sqlite3']
14
+
15
+ # this tests DBI more than SQLite, but makes sure our chain works with it.
16
+ dbh = DBI.connect("dbi:SQLite3:" + config['dbname'], nil, nil, {})
17
+ assert dbh
18
+ assert_kind_of DBI::DatabaseHandle, dbh
19
+
20
+ # first argument should be a string
21
+ assert_raises(DBI::InterfaceError) do
22
+ DBI::DBD::SQLite3::Driver.new.connect(nil, nil, nil, { })
23
+ end
24
+
25
+ # that string should have some frackin' length
26
+ assert_raises(DBI::InterfaceError) do
27
+ DBI::DBD::SQLite3::Driver.new.connect("", nil, nil, { })
28
+ end
29
+
30
+ # last argument should be a hash
31
+ assert_raises(DBI::InterfaceError) do
32
+ DBI::DBD::SQLite3::Driver.new.connect(config['dbname'], nil, nil, nil)
33
+ end
34
+
35
+ dbh = nil
36
+ driver = nil
37
+ assert_nothing_raised do
38
+ driver = DBI::DBD::SQLite3::Driver.new
39
+ dbh = driver.connect(config['dbname'], nil, nil, { })
40
+ end
41
+
42
+ assert_kind_of DBI::DBD::SQLite3::Driver, driver
43
+ assert_kind_of DBI::DBD::SQLite3::Database, dbh
44
+
45
+ assert !dbh.instance_variable_get("@autocommit")
46
+
47
+ dbh = nil
48
+ driver = nil
49
+ assert_nothing_raised do
50
+ dbh = DBI::DBD::SQLite3::Driver.new.connect(config['dbname'], nil, nil, { "AutoCommit" => true, "sqlite_full_column_names" => true })
51
+ end
52
+
53
+ assert dbh
54
+ assert dbh.instance_variable_get("@attr")
55
+ assert_kind_of SQLite3::Database, dbh.instance_variable_get("@db")
56
+
57
+ assert File.exists?(config['dbname'])
58
+ end
59
+
60
+ def setup
61
+ end
62
+
63
+ def teardown
64
+ config = DBDConfig.get_config['sqlite3']
65
+ FileUtils.rm_f(config['dbname'])
66
+ end
67
+ end