dbd-mysql 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -49,7 +49,7 @@ module DBI
49
49
  # Only things that extend DBI's results are documented.
50
50
  #
51
51
  module Mysql
52
- VERSION = "0.4.2"
52
+ VERSION = "0.4.3"
53
53
  DESCRIPTION = "MySQL DBI DBD, Leverages 'mysql' low-level driver"
54
54
 
55
55
  MyError = ::MysqlError
@@ -109,28 +109,6 @@ module DBI::DBD::Mysql::Util
109
109
  end # module Util
110
110
 
111
111
  module DBI::DBD::Mysql::Type
112
- #
113
- # Custom handling for TIMESTAMP and DATETIME types in MySQL. See DBI::Type
114
- # for more information.
115
- #
116
- class Timestamp < DBI::Type::Null
117
- def self.parse(obj)
118
- obj = super
119
- return obj unless obj
120
-
121
- case obj.class
122
- when ::DateTime
123
- return obj
124
- when ::String
125
- return ::DateTime.strptime(obj, "%Y-%m-%d %H:%M:%S")
126
- else
127
- return ::DateTime.parse(obj.to_s) if obj.respond_to? :to_s
128
- return ::DateTime.parse(obj.to_str) if obj.respond_to? :to_str
129
- return obj
130
- end
131
- end
132
- end
133
-
134
112
  #
135
113
  # Custom handling for DATE types in MySQL. See DBI::Type for more
136
114
  # information.
@@ -93,7 +93,7 @@ module DBI::DBD::Mysql
93
93
  coercion_method = DBI::Type::Timestamp
94
94
  when 'TYPE_DATETIME', 'TYPE_TIMESTAMP'
95
95
  mysql_type_name = 'DATETIME'
96
- coercion_method = DBI::DBD::Mysql::Type::Timestamp
96
+ coercion_method = DBI::Type::Timestamp
97
97
  when 'TYPE_CHAR'
98
98
  mysql_type_name = 'TINYINT' # questionable?
99
99
  when 'TYPE_TINY_BLOB'
@@ -149,6 +149,14 @@ module DBI::DBD::Mysql
149
149
  error(err)
150
150
  end
151
151
 
152
+ def database_name
153
+ sth = Statement.new(self, @handle, "select DATABASE()", @mutex)
154
+ sth.execute
155
+ res = sth.fetch
156
+ sth.finish
157
+ return res[0]
158
+ end
159
+
152
160
  def ping
153
161
  begin
154
162
  @handle.ping
@@ -209,7 +217,7 @@ module DBI::DBD::Mysql
209
217
 
210
218
  case col['type_name']
211
219
  when 'timestamp'
212
- col['dbi_type'] = DBI::DBD::Mysql::Type::Timestamp
220
+ col['dbi_type'] = DBI::Type::Timestamp
213
221
  end
214
222
 
215
223
  col
@@ -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
@@ -30,7 +54,7 @@
30
54
  end
31
55
 
32
56
  assert_equal(
33
- DBI::Type::Varchar.object_id,
57
+ DBI::Type::Varchar.object_id,
34
58
  DBI::TypeUtil.type_name_to_module(cols[0]["type_name"]).object_id
35
59
  )
36
60
 
@@ -40,8 +64,9 @@
40
64
  assert(cols[1]["nullable"])
41
65
  assert_equal(1, cols[2]["scale"])
42
66
  assert_equal(2, cols[2]["precision"])
67
+
43
68
  assert_equal(
44
- DBI::Type::Integer.object_id,
69
+ DBI::Type::Integer.object_id,
45
70
  DBI::TypeUtil.type_name_to_module(cols[1]["type_name"]).object_id
46
71
  )
47
72
 
@@ -52,7 +77,7 @@
52
77
  assert_equal(1, cols[2]["scale"])
53
78
  assert_equal(2, cols[2]["precision"])
54
79
  assert_equal(
55
- DBI::Type::Decimal.object_id,
80
+ DBI::Type::Decimal.object_id,
56
81
  DBI::TypeUtil.type_name_to_module(cols[2]["type_name"]).object_id
57
82
  )
58
83
 
@@ -63,7 +88,7 @@
63
88
  assert_equal(6, cols[3]["scale"])
64
89
  assert_equal(30, cols[3]["precision"])
65
90
  assert_equal(
66
- DBI::Type::Decimal.object_id,
91
+ DBI::Type::Decimal.object_id,
67
92
  DBI::TypeUtil.type_name_to_module(cols[3]["type_name"]).object_id
68
93
  )
69
94
 
@@ -145,11 +170,13 @@
145
170
  "views"
146
171
  ]
147
172
  end
148
-
149
- case dbtype
173
+
174
+ case dbtype
150
175
  when "postgresql"
151
176
  tables.reject! { |x| x =~ /^pg_/ }
152
- 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
153
180
  else
154
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
155
182
  end
@@ -164,13 +191,13 @@
164
191
  assert !@dbh["AutoCommit"]
165
192
 
166
193
  # test committing an outstanding transaction
167
-
194
+
168
195
  @sth = @dbh.prepare("insert into names (name, age) values (?, ?)")
169
196
  @sth.execute("Billy", 22)
170
197
  @sth.finish
171
198
 
172
199
  assert @dbh["AutoCommit"] = true # should commit at this point
173
-
200
+
174
201
  @sth = @dbh.prepare("select * from names where name = ?")
175
202
  @sth.execute("Billy")
176
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
@@ -90,9 +90,9 @@
90
90
  @sth = @dbh.prepare("select name, age from names order by age")
91
91
 
92
92
  # can't bind_coltype before execute
93
- assert_raise(DBI::InterfaceError) { @sth.bind_coltype(1, DBI::Type::Float) }
93
+ assert_raises(DBI::InterfaceError) { @sth.bind_coltype(1, DBI::Type::Float) }
94
94
  # can't index < 1
95
- assert_raise(DBI::InterfaceError) { @sth.bind_coltype(0, DBI::Type::Float) }
95
+ assert_raises(DBI::InterfaceError) { @sth.bind_coltype(0, DBI::Type::Float) }
96
96
  end
97
97
 
98
98
  def test_noconv
@@ -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
@@ -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,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: dbd-mysql
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.4.2
7
- date: 2008-11-09 00:00:00 -08:00
8
- summary: MySQL DBI DBD, Leverages 'mysql' low-level driver
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: MySQL DBI DBD, Leverages 'mysql' low-level driver
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.4.3
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: mysql
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: MySQL DBI DBD, Leverages 'mysql' low-level driver
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/mysql/base.rb
37
- - test/dbd/mysql/down.sql
38
- - test/dbd/mysql/test_blob.rb
39
51
  - test/dbd/mysql/test_patches.rb
52
+ - test/dbd/mysql/down.sql
40
53
  - test/dbd/mysql/up.sql
54
+ - test/dbd/mysql/test_new_methods.rb
55
+ - test/dbd/mysql/test_blob.rb
41
56
  - lib/dbd/Mysql.rb
42
57
  - lib/dbd/mysql/database.rb
43
58
  - lib/dbd/mysql/driver.rb
@@ -46,36 +61,31 @@ files:
46
61
  - README
47
62
  - LICENSE
48
63
  - ChangeLog
49
- test_files:
50
- - test/ts_dbd.rb
64
+ has_rdoc: true
65
+ homepage: http://www.rubyforge.org/projects/ruby-dbi
66
+ post_install_message:
51
67
  rdoc_options: []
52
68
 
53
- extra_rdoc_files:
54
- - README
55
- - LICENSE
56
- - ChangeLog
57
- executables: []
58
-
59
- extensions: []
60
-
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.8.0
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
61
83
  requirements: []
62
84
 
63
- dependencies:
64
- - !ruby/object:Gem::Dependency
65
- name: dbi
66
- version_requirement:
67
- version_requirements: !ruby/object:Gem::Version::Requirement
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- version: 0.4.0
72
- version:
73
- - !ruby/object:Gem::Dependency
74
- name: mysql
75
- version_requirement:
76
- version_requirements: !ruby/object:Gem::Version::Requirement
77
- requirements:
78
- - - ">"
79
- - !ruby/object:Gem::Version
80
- version: 0.0.0
81
- version:
85
+ rubyforge_project: ruby-dbi
86
+ rubygems_version: 1.3.1
87
+ signing_key:
88
+ specification_version: 2
89
+ summary: MySQL DBI DBD, Leverages 'mysql' low-level driver
90
+ test_files:
91
+ - test/ts_dbd.rb