dbd-sqlite 0.1.1 → 0.1.2

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.
@@ -36,7 +36,7 @@ module DBI
36
36
  # Only things that extend DBI's results are documented.
37
37
  #
38
38
  class SQLite
39
- VERSION = "0.1.1"
39
+ VERSION = "0.1.2"
40
40
  DESCRIPTION = "SQLite 2.x DBI DBD"
41
41
 
42
42
  #
@@ -46,6 +46,15 @@ class DBI::DBD::SQLite::Database < DBI::BaseDatabase
46
46
  @db = nil
47
47
  end
48
48
 
49
+ def database_name
50
+ st = DBI::DBD::SQLite::Statement.new('PRAGMA database_list', self)
51
+ st.execute
52
+ row = st.fetch
53
+ st.finish
54
+
55
+ return row[2]
56
+ end
57
+
49
58
  def prepare(stmt)
50
59
  return DBI::DBD::SQLite::Statement.new(stmt, self)
51
60
  end
@@ -2,6 +2,8 @@
2
2
  Using DBD tests
3
3
  ================================================================================
4
4
 
5
+ Before you do anything, read the TESTING file.
6
+
5
7
  Create a YAML file named .ruby-dbi.test-config.yaml in your home directory.
6
8
 
7
9
  This file is a hash of keys that determine what you want to test and how you
@@ -1,4 +1,28 @@
1
1
  @class = Class.new(DBDConfig.testbase(DBDConfig.current_dbtype)) do
2
+
3
+ def test_last_statement
4
+ @sth = @dbh.prepare("select * from names")
5
+ @sth.finish
6
+ assert_equal "select * from names", @dbh.last_statement
7
+
8
+ @sth = @dbh.execute("select * from names")
9
+ @sth.finish
10
+ assert_equal "select * from names", @dbh.last_statement
11
+
12
+ @dbh.do("select * from names")
13
+ assert_equal "select * from names", @dbh.last_statement
14
+ end
15
+
16
+ def test_empty_query
17
+ ["", " ", "\t"].each do |str|
18
+ [:do, :prepare, :execute, :select_one, :select_all].each do |call|
19
+ assert_raises(DBI::InterfaceError) do
20
+ @dbh.send(call, str)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
2
26
  def test_ping
3
27
  assert @dbh.ping
4
28
  # XXX if it isn't obvious, this should be tested better. Not sure what
@@ -11,7 +35,7 @@
11
35
 
12
36
  assert(cols)
13
37
  assert_kind_of(Array, cols)
14
- assert_equal(2, cols.length)
38
+ assert_equal(4, cols.length)
15
39
 
16
40
  # the first column should always be "text_field" and have the following
17
41
  # properties:
@@ -30,19 +54,42 @@
30
54
  end
31
55
 
32
56
  assert_equal(
33
- DBI::Type::Varchar,
34
- DBI::TypeUtil.type_name_to_module(cols[0]["type_name"])
57
+ DBI::Type::Varchar.object_id,
58
+ DBI::TypeUtil.type_name_to_module(cols[0]["type_name"]).object_id
35
59
  )
36
60
 
37
61
  # the second column should always be "integer_field" and have the following
38
62
  # properties:
39
63
  assert_equal("integer_field", cols[1]["name"])
40
64
  assert(cols[1]["nullable"])
41
- assert_equal(1, cols[1]["scale"])
42
- assert_equal(2, cols[1]["precision"])
65
+ assert_equal(1, cols[2]["scale"])
66
+ assert_equal(2, cols[2]["precision"])
67
+
43
68
  assert_equal(
44
- DBI::Type::Decimal,
45
- DBI::TypeUtil.type_name_to_module(cols[1]["type_name"])
69
+ DBI::Type::Integer.object_id,
70
+ DBI::TypeUtil.type_name_to_module(cols[1]["type_name"]).object_id
71
+ )
72
+
73
+ # the second column should always be "integer_field" and have the following
74
+ # properties:
75
+ assert_equal("decimal_field", cols[2]["name"])
76
+ assert(cols[2]["nullable"])
77
+ assert_equal(1, cols[2]["scale"])
78
+ assert_equal(2, cols[2]["precision"])
79
+ assert_equal(
80
+ DBI::Type::Decimal.object_id,
81
+ DBI::TypeUtil.type_name_to_module(cols[2]["type_name"]).object_id
82
+ )
83
+
84
+ # the second column should always be "numeric_field" and have the following
85
+ # properties:
86
+ assert_equal("numeric_field", cols[3]["name"])
87
+ assert(cols[3]["nullable"])
88
+ assert_equal(6, cols[3]["scale"])
89
+ assert_equal(30, cols[3]["precision"])
90
+ assert_equal(
91
+ DBI::Type::Decimal.object_id,
92
+ DBI::TypeUtil.type_name_to_module(cols[3]["type_name"]).object_id
46
93
  )
47
94
 
48
95
  # finally, we ensure that every column in the array is a ColumnInfo
@@ -123,11 +170,13 @@
123
170
  "views"
124
171
  ]
125
172
  end
126
-
127
- case dbtype
173
+
174
+ case dbtype
128
175
  when "postgresql"
129
176
  tables.reject! { |x| x =~ /^pg_/ }
130
- assert_equal %w(array_test bit_test blob_test boolean_test bytea_test db_specific_types_test field_types_test names precision_test time_test timestamp_test view_names), tables
177
+ assert_equal %w(array_test bit_test blob_test boolean_test bytea_test db_specific_types_test enum_type_test field_types_test names precision_test time_test timestamp_test view_names), tables
178
+ when 'sqlite3'
179
+ assert_equal %w(bit_test blob_test boolean_test db_specific_types_test field_types_test names names_defined_with_spaces precision_test time_test timestamp_test view_names), tables
131
180
  else
132
181
  assert_equal %w(bit_test blob_test boolean_test db_specific_types_test field_types_test names precision_test time_test timestamp_test view_names), tables
133
182
  end
@@ -142,13 +191,13 @@
142
191
  assert !@dbh["AutoCommit"]
143
192
 
144
193
  # test committing an outstanding transaction
145
-
194
+
146
195
  @sth = @dbh.prepare("insert into names (name, age) values (?, ?)")
147
196
  @sth.execute("Billy", 22)
148
197
  @sth.finish
149
198
 
150
199
  assert @dbh["AutoCommit"] = true # should commit at this point
151
-
200
+
152
201
  @sth = @dbh.prepare("select * from names where name = ?")
153
202
  @sth.execute("Billy")
154
203
  assert_equal [ "Billy", 22 ], @sth.fetch
@@ -1,4 +1,50 @@
1
1
  @class = Class.new(DBDConfig.testbase(DBDConfig.current_dbtype)) do
2
+
3
+ def prep_status_statement
4
+ @sth.finish if (@sth and !@sth.finished?)
5
+ @sth = @dbh.prepare("select * from names order by age")
6
+ @sth.raise_error = true
7
+ end
8
+
9
+ def test_status
10
+ names_rc = 3
11
+
12
+ [:fetch, :fetch_hash, :each, :fetch_all].each do |call|
13
+ assert_raise(DBI::InterfaceError, DBI::NotSupportedError) do
14
+ prep_status_statement
15
+ @sth.send(call)
16
+ end
17
+ end
18
+
19
+ # for these next three, it doesn't really matter what the args are, it should fail
20
+ assert_raises(DBI::InterfaceError, DBI::NotSupportedError) do
21
+ prep_status_statement
22
+ @sth.fetch_many(1)
23
+ end
24
+
25
+ assert_raises(DBI::InterfaceError, DBI::NotSupportedError) do
26
+ prep_status_statement
27
+ @sth.fetch_scroll(0, 0)
28
+ end
29
+
30
+ assert_raises(DBI::InterfaceError, DBI::NotSupportedError) do
31
+ prep_status_statement
32
+ @sth.each { |x| }
33
+ end
34
+
35
+ assert_raises(DBI::InterfaceError) do
36
+ prep_status_statement
37
+ @sth.execute
38
+ 2.times { @sth.fetch_all }
39
+ end
40
+
41
+ assert_raises(DBI::InterfaceError) do
42
+ prep_status_statement
43
+ @sth.execute
44
+ # XXX fetch_many won't know it can't fetch anything until the third time around.
45
+ 3.times { @sth.fetch_many(names_rc) }
46
+ end
47
+ end
2
48
 
3
49
  def test_execute
4
50
  assert_nothing_raised do
@@ -44,7 +90,7 @@
44
90
 
45
91
  assert(cols)
46
92
  assert_kind_of(Array, cols)
47
- assert_equal(2, cols.length)
93
+ assert_equal(4, cols.length)
48
94
 
49
95
  # the first column should always be "text_field" and have the following
50
96
  # properties:
@@ -61,18 +107,49 @@
61
107
  end
62
108
 
63
109
  assert_equal(
64
- DBI::Type::Varchar,
65
- DBI::TypeUtil.type_name_to_module(cols[0]["type_name"])
110
+ DBI::Type::Varchar.object_id,
111
+ DBI::TypeUtil.type_name_to_module(cols[0]["type_name"]).object_id
66
112
  )
67
113
 
68
114
  # the second column should always be "integer_field" and have the following
69
115
  # properties:
70
116
  assert_equal("integer_field", cols[1]["name"])
71
- assert_equal(1, cols[1]["scale"])
72
- assert_equal(2, cols[1]["precision"])
117
+ # if these aren't set on the field, they should not exist
118
+ # FIXME mysql does not follow this rule, neither does ODBC
119
+ if dbtype == "mysql"
120
+ assert_equal(0, cols[1]["scale"])
121
+ assert_equal(11, cols[1]["precision"])
122
+ elsif dbtype == "odbc"
123
+ assert_equal(0, cols[1]["scale"])
124
+ assert_equal(10, cols[1]["precision"])
125
+ else
126
+ assert(!cols[1]["scale"])
127
+ assert(!cols[1]["precision"])
128
+ end
129
+
130
+ assert_equal(
131
+ DBI::Type::Integer.object_id,
132
+ DBI::TypeUtil.type_name_to_module(cols[1]["type_name"]).object_id
133
+ )
134
+
135
+ # the second column should always be "integer_field" and have the following
136
+ # properties:
137
+ assert_equal("decimal_field", cols[2]["name"])
138
+ assert_equal(1, cols[2]["scale"])
139
+ assert_equal(2, cols[2]["precision"])
140
+ assert_equal(
141
+ DBI::Type::Decimal.object_id,
142
+ DBI::TypeUtil.type_name_to_module(cols[2]["type_name"]).object_id
143
+ )
144
+
145
+ # the second column should always be "numeric_field" and have the following
146
+ # properties:
147
+ assert_equal("numeric_field", cols[3]["name"])
148
+ assert_equal(6, cols[3]["scale"])
149
+ assert_equal(30, cols[3]["precision"])
73
150
  assert_equal(
74
- DBI::Type::Decimal,
75
- DBI::TypeUtil.type_name_to_module(cols[1]["type_name"])
151
+ DBI::Type::Decimal.object_id,
152
+ DBI::TypeUtil.type_name_to_module(cols[3]["type_name"]).object_id
76
153
  )
77
154
 
78
155
  cols.each { |col| assert_kind_of(DBI::ColumnInfo, col) }
@@ -25,6 +25,34 @@
25
25
  end
26
26
  end
27
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
+
45
+ assert_kind_of(Integer, row[0])
46
+ assert_kind_of(BigDecimal, row[1])
47
+ assert_kind_of(BigDecimal, row[2])
48
+
49
+ # FIXME BigDecimal requires a string and some databases will pad
50
+ # decimal/numeric with constrained precision. We should account for
51
+ # this, but I'm not quite sure how yet.
52
+ end
53
+ @sth.finish
54
+ end
55
+
28
56
  # FIXME
29
57
  # Ideally, this test should be split across the DBI tests and DBD, but for
30
58
  # now testing against the DBDs really doesn't cost us anything other than
@@ -62,9 +90,9 @@
62
90
  @sth = @dbh.prepare("select name, age from names order by age")
63
91
 
64
92
  # can't bind_coltype before execute
65
- assert_raise(DBI::InterfaceError) { @sth.bind_coltype(1, DBI::Type::Float) }
93
+ assert_raises(DBI::InterfaceError) { @sth.bind_coltype(1, DBI::Type::Float) }
66
94
  # can't index < 1
67
- assert_raise(DBI::InterfaceError) { @sth.bind_coltype(0, DBI::Type::Float) }
95
+ assert_raises(DBI::InterfaceError) { @sth.bind_coltype(0, DBI::Type::Float) }
68
96
  end
69
97
 
70
98
  def test_noconv
@@ -1,4 +1,3 @@
1
- require 'test/unit'
2
1
  require 'fileutils'
3
2
 
4
3
  DBDConfig.set_testbase(:sqlite, Class.new(Test::Unit::TestCase) do
@@ -1,4 +1,10 @@
1
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
+
2
8
  def test_disconnect
3
9
  assert_nil @dbh.disconnect
4
10
  assert_nil @dbh.instance_variable_get("@db")
@@ -18,17 +18,17 @@ class TestSQLiteDriver < DBDConfig.testbase(:sqlite)
18
18
  assert_kind_of DBI::DatabaseHandle, dbh
19
19
 
20
20
  # first argument should be a string
21
- assert_raise(DBI::InterfaceError) do
21
+ assert_raises(DBI::InterfaceError) do
22
22
  DBI::DBD::SQLite::Driver.new.connect(nil, nil, nil, { })
23
23
  end
24
24
 
25
25
  # that string should have some frackin' length
26
- assert_raise(DBI::InterfaceError) do
26
+ assert_raises(DBI::InterfaceError) do
27
27
  DBI::DBD::SQLite::Driver.new.connect("", nil, nil, { })
28
28
  end
29
29
 
30
30
  # last argument should be a hash
31
- assert_raise(DBI::InterfaceError) do
31
+ assert_raises(DBI::InterfaceError) do
32
32
  DBI::DBD::SQLite::Driver.new.connect(config['dbname'], nil, nil, nil)
33
33
  end
34
34
 
@@ -20,7 +20,7 @@ class TestSQLiteStatement < DBDConfig.testbase(:sqlite)
20
20
  def test_bind_param
21
21
  sth = DBI::DBD::SQLite::Statement.new("select * from foo", @dbh.instance_variable_get("@handle"))
22
22
 
23
- assert_raise(DBI::InterfaceError) do
23
+ assert_raises(DBI::InterfaceError) do
24
24
  sth.bind_param(:foo, "monkeys")
25
25
  end
26
26
 
@@ -6,7 +6,7 @@ insert into names (name, age) values ("Joe", 19);
6
6
  ---
7
7
  insert into names (name, age) values ("Jim", 30);
8
8
  ---
9
- create table precision_test (text_field varchar(20) primary key not null, integer_field decimal(2,1));
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
10
  ---
11
11
  create view view_names as select * from names;
12
12
  ---
@@ -1,3 +1,5 @@
1
+ require 'rubygems'
2
+ gem 'test-unit'
1
3
  # figure out what tests to run
2
4
  require 'yaml'
3
5
  require 'test/unit/testsuite'
@@ -17,6 +19,16 @@ module Test::Unit::Assertions
17
19
  end
18
20
  end
19
21
 
22
+ class Class
23
+ def name=(klass_name)
24
+ @name = klass_name
25
+ end
26
+
27
+ def name
28
+ return @name || super
29
+ end
30
+ end
31
+
20
32
  module DBDConfig
21
33
  @testbase = { }
22
34
  @current_dbtype = nil
@@ -68,6 +80,7 @@ module DBDConfig
68
80
 
69
81
  def self.set_testbase(klass_name, klass)
70
82
  @testbase[klass_name] = klass
83
+ klass.name = klass_name.to_s
71
84
  end
72
85
 
73
86
  def self.suite
@@ -110,7 +123,7 @@ if __FILE__ == $0
110
123
  Dir["dbd/#{dbtype}/test*.rb"].each { |file| require file }
111
124
  # run the general tests
112
125
  DBDConfig.current_dbtype = dbtype.to_sym
113
- Dir["dbd/general/test*.rb"].each { |file| load file; DBDConfig.suite << @class }
126
+ Dir["dbd/general/test*.rb"].each { |file| load file; @class.name = file; DBDConfig.suite << @class }
114
127
  end
115
128
  elsif !config["dbtypes"]
116
129
  warn "Please see test/DBD_TESTS for information on configuring DBD tests."
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: dbd-sqlite
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2008-09-27 00:00:00 -07:00
8
- summary: SQLite 2.x DBI DBD
9
- require_paths:
10
- - lib
11
- email: ruby-dbi-users@rubyforge.org
12
- homepage: http://www.rubyforge.org/projects/ruby-dbi
13
- rubyforge_project: ruby-dbi
14
- description: SQLite 2.x DBI DBD
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.8.0
24
- version:
4
+ version: 0.1.2
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Erik Hollensbe
31
8
  - Christopher Maujean
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-07-11 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: dbi
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.4.0
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: sqlite-ruby
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ version:
36
+ description: SQLite 2.x DBI DBD
37
+ email: ruby-dbi-users@rubyforge.org
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README
44
+ - LICENSE
45
+ - ChangeLog
32
46
  files:
33
- - test/dbd/general/test_database.rb
34
47
  - test/dbd/general/test_statement.rb
48
+ - test/dbd/general/test_database.rb
35
49
  - test/dbd/general/test_types.rb
36
50
  - test/dbd/sqlite/base.rb
37
- - test/dbd/sqlite/test_database.rb
38
- - test/dbd/sqlite/test_statement.rb
39
51
  - test/dbd/sqlite/test_driver.rb
52
+ - test/dbd/sqlite/test_statement.rb
40
53
  - test/dbd/sqlite/up.sql
54
+ - test/dbd/sqlite/test_database.rb
41
55
  - lib/dbd/SQLite.rb
42
56
  - lib/dbd/sqlite/database.rb
43
57
  - lib/dbd/sqlite/statement.rb
@@ -45,36 +59,31 @@ files:
45
59
  - README
46
60
  - LICENSE
47
61
  - ChangeLog
48
- test_files:
49
- - test/ts_dbd.rb
62
+ has_rdoc: true
63
+ homepage: http://www.rubyforge.org/projects/ruby-dbi
64
+ post_install_message:
50
65
  rdoc_options: []
51
66
 
52
- extra_rdoc_files:
53
- - README
54
- - LICENSE
55
- - ChangeLog
56
- executables: []
57
-
58
- extensions: []
59
-
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 1.8.0
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
60
81
  requirements: []
61
82
 
62
- dependencies:
63
- - !ruby/object:Gem::Dependency
64
- name: dbi
65
- version_requirement:
66
- version_requirements: !ruby/object:Gem::Version::Requirement
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: 0.4.0
71
- version:
72
- - !ruby/object:Gem::Dependency
73
- name: sqlite-ruby
74
- version_requirement:
75
- version_requirements: !ruby/object:Gem::Version::Requirement
76
- requirements:
77
- - - ">"
78
- - !ruby/object:Gem::Version
79
- version: 0.0.0
80
- version:
83
+ rubyforge_project: ruby-dbi
84
+ rubygems_version: 1.3.1
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: SQLite 2.x DBI DBD
88
+ test_files:
89
+ - test/ts_dbd.rb