dbi 0.4.3 → 0.4.4

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.
@@ -45,7 +45,7 @@ namespace :dbi do
45
45
  spec.files = gem_files(code_files)
46
46
  spec.summary = 'A vendor independent interface for accessing databases, similar to Perl\'s DBI'
47
47
  spec.description = 'A vendor independent interface for accessing databases, similar to Perl\'s DBI'
48
- spec.add_dependency 'deprecated', '>= 2.0.0'
48
+ spec.add_dependency 'deprecated', '= 2.0.1'
49
49
 
50
50
  build_package_tasks(spec, code_files)
51
51
  end
data/lib/dbi.rb CHANGED
@@ -37,7 +37,7 @@ module DBI; end
37
37
 
38
38
  begin
39
39
  require "rubygems"
40
- gem "deprecated"
40
+ gem "deprecated", "= 2.0.1"
41
41
  rescue LoadError
42
42
  end
43
43
 
@@ -90,7 +90,7 @@ Deprecate.set_action(
90
90
 
91
91
  #++
92
92
  module DBI
93
- VERSION = "0.4.3"
93
+ VERSION = "0.4.4"
94
94
 
95
95
  module DBD # :nodoc:
96
96
  API_VERSION = "0.3"
@@ -2,7 +2,7 @@ require 'delegate'
2
2
 
3
3
  begin
4
4
  require 'rubygems'
5
- gem 'deprecated'
5
+ gem 'deprecated', "= 2.0.1"
6
6
  rescue LoadError => e
7
7
  end
8
8
 
@@ -1,5 +1,6 @@
1
1
  require 'time'
2
2
  require 'bigdecimal'
3
+ require 'rational'
3
4
 
4
5
  module DBI
5
6
  #
@@ -108,30 +109,24 @@ module DBI
108
109
  # store this before we modify it
109
110
  civil = year, month, day
110
111
  time = hour, min, sec, usec
111
- if month <= 2
112
- month += 12
113
- year -= 1
114
- end
115
- y = year + 4800
116
- m = month - 3
117
- jd = day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045
118
- #fr = hour / 24.0 + min / 1440.0 + sec / 86400.0
119
- # ridiculously, this line does the same thing but twice as fast... :/
120
- fr = ::Time.gm(1970, 1, 1, hour, min, sec, usec).to_f / 86400
121
- date = ::DateTime.new!(jd + fr - 0.5, of, ::DateTime::ITALY)
122
- prefill_cache date, civil, time
112
+
113
+ date = ::DateTime.civil(year, month, day, hour, min, sec, of)
114
+ date += usec
115
+ #prefill_cache date, civil, time
123
116
  date
124
117
  end
125
118
 
119
+ # FIXME these methods are broken, I don't know why, and I don't really care right now.
120
+ # we shouldn't be playing in datetime's garden anyways.
126
121
  if RUBY_VERSION =~ /^1\.8\./
127
122
  def self.prefill_cache date, civil, time
128
- time[3] /= 86400000000.0
123
+ time[3] /= 86400000000.0
129
124
  date.instance_variable_set :"@__#{:civil.to_i}__", [civil]
130
125
  date.instance_variable_set :"@__#{:time.to_i}__", [time]
131
126
  end
132
127
  else
133
128
  def self.prefill_cache date, civil, time
134
- time[3] /= 1000000.0
129
+ time[3] /= 1000000.0
135
130
  date.instance_variable_get(:@__ca__)[:civil.object_id] = civil
136
131
  date.instance_variable_get(:@__ca__)[:time.object_id] = time
137
132
  end
@@ -143,8 +138,14 @@ module DBI
143
138
  case str
144
139
  when /^(\d{4})-(\d{2})-(\d{2})(?: (\d{2}):(\d{2}):(\d{2})(\.\d+)?)?(?: ([+-]?\d{2}):?(\d{2}))?$/
145
140
  parts = $~[1..-4].map { |s| s.to_i }
146
- parts << $7.to_f * 1000000.0
147
- parts << ($8 ? ($8.to_f * 60 + $9.to_i) / 1440 : 0)
141
+ # i feel unclean. if we have fractional seconds, pad the number and then stuff it into a rational.
142
+ if $7
143
+ frac = $7.to_f * 10000000
144
+ parts << Rational(frac.to_i, 864000000000)
145
+ else
146
+ parts << 0
147
+ end
148
+ parts << Rational(($8 || 0).to_i * 60 + ($9 || 0).to_i, 1440)
148
149
  else
149
150
  parts = ::Date._parse(str).values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction, :offset)
150
151
  # some defaults
@@ -154,8 +155,9 @@ module DBI
154
155
  today ||= ::Time.now.to_a.values_at(5, 4, 3) + [0, 0, 0, 0, 0]
155
156
  parts[i] = today[i]
156
157
  end
157
- parts[6] *= 1000000.0
158
- parts[7] /= 86400.0
158
+ parts[6] = parts[6].kind_of?(Rational) ? parts[6] : Rational(parts[6], 1)
159
+ parts[6] *= Rational(1, 86400)
160
+ parts[7] = Rational(parts[7], 86400)
159
161
  end
160
162
  parts
161
163
  end
@@ -167,7 +169,7 @@ module DBI
167
169
  when ::Date
168
170
  return create(obj.year, obj.month, obj.day, 0, 0, 0)
169
171
  when ::Time
170
- return create(obj.year, obj.month, obj.day, obj.hour, obj.min, obj.sec, obj.usec, obj.utc_offset / 86400.0)
172
+ return create(obj.year, obj.month, obj.day, obj.hour, obj.min, obj.sec, Rational(obj.usec, 86400000000), Rational(obj.utc_offset, 86400))
171
173
  else
172
174
  obj = super
173
175
  return obj unless obj
@@ -94,7 +94,8 @@ DBI::TypeUtil.register_conversion("default") do |obj|
94
94
  "'0'"
95
95
  when ::Time, ::Date, ::DateTime
96
96
  "'#{::DateTime.parse(obj.to_s).strftime("%Y-%m-%dT%H:%M:%S")}'"
97
- when ::String
97
+ when ::String, ::Symbol
98
+ obj = obj.to_s
98
99
  obj = obj.gsub(/\\/) { "\\\\" }
99
100
  obj = obj.gsub(/'/) { "''" }
100
101
  "'#{obj}'"
@@ -138,7 +138,7 @@ class TC_DBI < Test::Unit::TestCase
138
138
  def test_connect
139
139
  assert_respond_to(DBI, :connect)
140
140
  end
141
-
141
+
142
142
  def test_available_drivers
143
143
  assert_respond_to(DBI, :available_drivers)
144
144
  assert_equal(
@@ -167,7 +167,7 @@ class TC_DBI < Test::Unit::TestCase
167
167
 
168
168
  # XXX we're looking for a specific exception message here
169
169
  assert_nothing_raised do
170
- begin
170
+ begin
171
171
  DBI.send(:parse_url, 'dbi:blah')
172
172
  rescue DBI::InterfaceError => e
173
173
  assert true
@@ -135,6 +135,47 @@ class TC_DBI_Type < Test::Unit::TestCase
135
135
  "#{md}-2008 10:01:02",
136
136
  klass.parse(DateTime.parse("10/11/2008 10:01:02")).strftime("%m-%d-%Y %H:%M:%S")
137
137
  )
138
+
139
+ # precision tests, related to ticket #27182
140
+
141
+ # iso8601 (bypasses regex)
142
+ [
143
+ '2009-09-27T19:41:00-05:00',
144
+ '2009-09-27T19:41:00.123-05:00'
145
+ ].each do |string|
146
+ assert_equal(DateTime.parse(string), klass.parse(string))
147
+ end
148
+
149
+ # offset comparison check
150
+ assert_equal(
151
+ DateTime.parse('2009-09-27T19:41:00.123-05:00'),
152
+ klass.parse('2009-09-28T00:41:00.123+00:00')
153
+ )
154
+
155
+ assert_equal(
156
+ DateTime.parse('2009-09-28T00:41:00.123+00:00'),
157
+ klass.parse('2009-09-27T19:41:00.123-05:00')
158
+ )
159
+
160
+ # unix convention (uses regex)
161
+
162
+ [
163
+ '2009-09-27 19:41:00 -05:00',
164
+ '2009-09-27 19:41:00.123 -05:00'
165
+ ].each do |string|
166
+ assert_equal(DateTime.parse(string), klass.parse(string))
167
+ end
168
+
169
+ # offset comparison check
170
+ assert_equal(
171
+ DateTime.parse('2009-09-27 19:41:00.123 -05:00'),
172
+ klass.parse('2009-09-28 00:41:00.123 +00:00')
173
+ )
174
+
175
+ assert_equal(
176
+ DateTime.parse('2009-09-28 00:41:00.123 +00:00'),
177
+ klass.parse('2009-09-27 19:41:00.123 -05:00')
178
+ )
138
179
  end
139
180
  end
140
181
 
@@ -218,6 +259,7 @@ class TC_DBI_TypeUtil_Custom < Test::Unit::TestCase
218
259
  end
219
260
 
220
261
  def test_custom_fallthrough
262
+ assert_equal("'foo'", cast(:foo))
221
263
  assert_equal("'foo'", cast("foo"))
222
264
  assert_equal("'foo''bar'", cast("foo'bar"))
223
265
  assert_equal("1", cast(1))
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 4
9
+ version: 0.4.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - Erik Hollensbe
@@ -10,19 +15,23 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2009-09-13 00:00:00 -04:00
18
+ date: 2010-05-05 00:00:00 -04:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: deprecated
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
21
25
  requirements:
22
- - - ">="
26
+ - - "="
23
27
  - !ruby/object:Gem::Version
24
- version: 2.0.0
25
- version:
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 1
32
+ version: 2.0.1
33
+ type: :runtime
34
+ version_requirements: *id001
26
35
  description: A vendor independent interface for accessing databases, similar to Perl's DBI
27
36
  email: ruby-dbi-users@rubyforge.org
28
37
  executables:
@@ -35,51 +44,53 @@ extra_rdoc_files:
35
44
  - LICENSE
36
45
  - ChangeLog
37
46
  files:
38
- - examples/xmltest.rb
39
47
  - examples/test1.pl
40
48
  - examples/test1.rb
49
+ - examples/xmltest.rb
41
50
  - bin/dbi
42
51
  - build/Rakefile.dbi.rb
43
52
  - lib/dbi.rb
44
- - lib/dbi/typeutil.rb
45
- - lib/dbi/handles.rb
46
- - lib/dbi/sql_type_constants.rb
47
- - lib/dbi/exceptions.rb
53
+ - lib/dbi/base_classes/database.rb
54
+ - lib/dbi/base_classes/driver.rb
55
+ - lib/dbi/base_classes/statement.rb
56
+ - lib/dbi/base_classes.rb
57
+ - lib/dbi/binary.rb
48
58
  - lib/dbi/columninfo.rb
59
+ - lib/dbi/exceptions.rb
60
+ - lib/dbi/handles/database.rb
61
+ - lib/dbi/handles/driver.rb
62
+ - lib/dbi/handles/statement.rb
63
+ - lib/dbi/handles.rb
64
+ - lib/dbi/row.rb
65
+ - lib/dbi/sql/preparedstatement.rb
49
66
  - lib/dbi/sql.rb
50
- - lib/dbi/utils.rb
67
+ - lib/dbi/sql_type_constants.rb
68
+ - lib/dbi/trace.rb
69
+ - lib/dbi/types.rb
70
+ - lib/dbi/typeutil.rb
71
+ - lib/dbi/utils/date.rb
51
72
  - lib/dbi/utils/tableformatter.rb
73
+ - lib/dbi/utils/time.rb
52
74
  - lib/dbi/utils/timestamp.rb
53
- - lib/dbi/utils/date.rb
54
75
  - lib/dbi/utils/xmlformatter.rb
55
- - lib/dbi/utils/time.rb
56
- - lib/dbi/base_classes.rb
57
- - lib/dbi/sql/preparedstatement.rb
58
- - lib/dbi/trace.rb
59
- - lib/dbi/handles/driver.rb
60
- - lib/dbi/handles/database.rb
61
- - lib/dbi/handles/statement.rb
62
- - lib/dbi/base_classes/driver.rb
63
- - lib/dbi/base_classes/database.rb
64
- - lib/dbi/base_classes/statement.rb
65
- - lib/dbi/binary.rb
66
- - lib/dbi/types.rb
67
- - lib/dbi/row.rb
76
+ - lib/dbi/utils.rb
68
77
  - test/ts_dbi.rb
69
- - test/dbi/tc_sqlbind.rb
78
+ - test/dbi/tc_columninfo.rb
79
+ - test/dbi/tc_date.rb
70
80
  - test/dbi/tc_dbi.rb
71
- - test/dbi/tc_statementhandle.rb
72
81
  - test/dbi/tc_row.rb
82
+ - test/dbi/tc_sqlbind.rb
83
+ - test/dbi/tc_statementhandle.rb
84
+ - test/dbi/tc_time.rb
73
85
  - test/dbi/tc_timestamp.rb
74
- - test/dbi/tc_columninfo.rb
75
86
  - test/dbi/tc_types.rb
76
- - test/dbi/tc_time.rb
77
- - test/dbi/tc_date.rb
78
87
  - README
79
88
  - LICENSE
80
89
  - ChangeLog
81
90
  has_rdoc: true
82
91
  homepage: http://www.rubyforge.org/projects/ruby-dbi
92
+ licenses: []
93
+
83
94
  post_install_message:
84
95
  rdoc_options: []
85
96
 
@@ -89,20 +100,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
100
  requirements:
90
101
  - - ">="
91
102
  - !ruby/object:Gem::Version
103
+ segments:
104
+ - 1
105
+ - 8
106
+ - 0
92
107
  version: 1.8.0
93
- version:
94
108
  required_rubygems_version: !ruby/object:Gem::Requirement
95
109
  requirements:
96
110
  - - ">="
97
111
  - !ruby/object:Gem::Version
112
+ segments:
113
+ - 0
98
114
  version: "0"
99
- version:
100
115
  requirements: []
101
116
 
102
117
  rubyforge_project: ruby-dbi
103
- rubygems_version: 1.3.1
118
+ rubygems_version: 1.3.6
104
119
  signing_key:
105
- specification_version: 2
120
+ specification_version: 3
106
121
  summary: A vendor independent interface for accessing databases, similar to Perl's DBI
107
122
  test_files:
108
123
  - test/ts_dbi.rb