rdbi-driver-odbc 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/CHANGELOG.md +18 -1
  2. data/lib/rdbi/driver/odbc.rb +57 -2
  3. metadata +21 -7
data/CHANGELOG.md CHANGED
@@ -1,6 +1,23 @@
1
+ RDBI-DRIVER-ODBC 0.1.1
2
+ ======================
3
+
4
+ Features
5
+ --------
6
+ - Add specs for all classes
7
+ - Update RDBI::Column information
8
+ - Automatically convert ::ODBC::Date, ::ODBC::Time and ::ODBC::TimeStamp
9
+ objects to ::Date, ::Time, ::TimeStamp
10
+
11
+ Bugfixes
12
+ --------
13
+ - Call #super at end of Statement#finish to cleanup
14
+ - Return nil when Cursor#next_row is called and no more rows to fetch
15
+ - Return +all+ remaning rows from Cursor#rest
16
+
17
+
1
18
  RDBI-DRIVER-ODBC 0.1.0
2
19
  ======================
3
20
 
4
21
  Features
5
22
  --------
6
- - Initial release. Please experiment and report and bugs you find.
23
+ - Initial release. Please experiment and report and bugs you find.
@@ -2,6 +2,7 @@ require 'rdbi'
2
2
  require 'rubygems'
3
3
  gem 'ruby-odbc', '= 0.99992'
4
4
  require 'odbc'
5
+ require 'time'
5
6
 
6
7
  class RDBI::Driver::ODBC < RDBI::Driver
7
8
  def initialize(*args)
@@ -10,6 +11,37 @@ class RDBI::Driver::ODBC < RDBI::Driver
10
11
  end
11
12
 
12
13
  class RDBI::Driver::ODBC < RDBI::Driver
14
+
15
+ SQL_TYPES = {
16
+ 1 => {:type => "CHAR", :ruby_type => :default},
17
+ 2 => {:type => "NUMERIC", :ruby_type => :decimal},
18
+ 3 => {:type => "DECIMAL", :ruby_type => :decimal},
19
+ 4 => {:type => "INTEGER", :ruby_type => :integer},
20
+ 5 => {:type => "SMALLINT", :ruby_type => :integer},
21
+ 6 => {:type => "FLOAT", :ruby_type => :decimal},
22
+ 7 => {:type => "REAL", :ruby_type => :decimal},
23
+ 8 => {:type => "DOUBLE", :ruby_type => :decimal},
24
+ 9 => {:type => "DATE", :ruby_type => :date},
25
+ 10 => {:type => "TIME", :ruby_type => :time},
26
+ 11 => {:type => "TIMESTAMP", :ruby_type => :timestamp},
27
+ 12 => {:type => "VARCHAR", :ruby_type => :default},
28
+ 13 => {:type => "BOOLEAN", :ruby_type => :boolean},
29
+ 91 => {:type => "DATE", :ruby_type => :date},
30
+ 92 => {:type => "TIME", :ruby_type => :time},
31
+ 93 => {:type => "TIMESTAMP", :ruby_type => :timestamp},
32
+ 100 => {:type => nil, :ruby_type => :default},
33
+ -1 => {:type => "LONG VARCHAR", :ruby_type => :default},
34
+ -2 => {:type => "BINARY", :ruby_type => :default},
35
+ -3 => {:type => "VARBINARY", :ruby_type => :default},
36
+ -4 => {:type => "LONG VARBINARY", :ruby_type => :default},
37
+ -5 => {:type => "BIGINT", :ruby_type => :integer},
38
+ -6 => {:type => "TINYINT", :ruby_type => :integer},
39
+ -7 => {:type => "BIT", :ruby_type => :default},
40
+ -8 => {:type => "CHAR", :ruby_type => :default},
41
+ -10 => {:type => "BLOB", :ruby_type => :default},
42
+ -11 => {:type => "CLOB", :ruby_type => :default},
43
+ }
44
+
13
45
  class Database < RDBI::Database
14
46
 
15
47
  attr_accessor :handle
@@ -77,6 +109,7 @@ class RDBI::Driver::ODBC < RDBI::Driver
77
109
  end
78
110
 
79
111
  def next_row
112
+ return nil if last_row?
80
113
  val = @rs[@index]
81
114
  @index += 1
82
115
  val
@@ -99,7 +132,7 @@ class RDBI::Driver::ODBC < RDBI::Driver
99
132
  end
100
133
 
101
134
  def rest
102
- @rs[@index+1..-1]
135
+ @rs[@index..-1]
103
136
  end
104
137
 
105
138
  def all
@@ -149,6 +182,21 @@ class RDBI::Driver::ODBC < RDBI::Driver
149
182
 
150
183
  @handle = @dbh.handle.prepare(query)
151
184
  @output_type_map = RDBI::Type.create_type_hash(RDBI::Type::Out)
185
+
186
+ @output_type_map[:date] = TypeLib::Filter.new(
187
+ proc{|obj| obj.is_a?(::ODBC::Date)},
188
+ proc{|obj| Date.parse(obj.to_s)}
189
+ )
190
+
191
+ @output_type_map[:time] = TypeLib::Filter.new(
192
+ proc{|obj| obj.is_a?(::ODBC::Time)},
193
+ proc{|obj| Time.parse(obj.to_s)}
194
+ )
195
+
196
+ @output_type_map[:timestamp] = TypeLib::Filter.new(
197
+ proc{|obj| obj.is_a?(::ODBC::TimeStamp)},
198
+ proc{|obj| DateTime.parse(obj.to_s)}
199
+ )
152
200
  end
153
201
 
154
202
  def new_execution(*binds)
@@ -156,7 +204,13 @@ class RDBI::Driver::ODBC < RDBI::Driver
156
204
 
157
205
  columns = @handle.columns(true).collect do |col|
158
206
  newcol = RDBI::Column.new
159
- newcol.name = col.name.to_sym
207
+ newcol.name = col.name.to_sym
208
+ newcol.type = SQL_TYPES[col.type][:type]
209
+ newcol.ruby_type = SQL_TYPES[col.type][:ruby_type]
210
+ newcol.precision = col.precision
211
+ newcol.scale = col.scale
212
+ newcol.nullable = col.nullable
213
+ newcol.table = col.table
160
214
  newcol
161
215
  end
162
216
 
@@ -165,6 +219,7 @@ class RDBI::Driver::ODBC < RDBI::Driver
165
219
 
166
220
  def finish
167
221
  @handle.drop
222
+ super
168
223
  end
169
224
  end
170
225
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Shane Emmons
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-08 00:00:00 -05:00
17
+ date: 2010-12-14 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -46,9 +46,23 @@ dependencies:
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
- name: rspec
49
+ name: rdbi-dbrc
50
50
  prerelease: false
51
51
  requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ - 1
59
+ version: "0.1"
60
+ type: :development
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
52
66
  none: false
53
67
  requirements:
54
68
  - - ~>
@@ -58,11 +72,11 @@ dependencies:
58
72
  - 2
59
73
  version: "2.2"
60
74
  type: :development
61
- version_requirements: *id003
75
+ version_requirements: *id004
62
76
  - !ruby/object:Gem::Dependency
63
77
  name: yard
64
78
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
79
+ requirement: &id005 !ruby/object:Gem::Requirement
66
80
  none: false
67
81
  requirements:
68
82
  - - ">="
@@ -71,7 +85,7 @@ dependencies:
71
85
  - 0
72
86
  version: "0"
73
87
  type: :development
74
- version_requirements: *id004
88
+ version_requirements: *id005
75
89
  description: This gem gives you the ability to query ODBC connections with RDBI.
76
90
  email: semmons99@gmail.com
77
91
  executables: []