dbi 0.4.0 → 0.4.1
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.
- data/build/Rakefile.dbi.rb +2 -2
- data/lib/dbi.rb +10 -2
- data/lib/dbi/base_classes/statement.rb +4 -0
- data/lib/dbi/columninfo.rb +2 -1
- data/lib/dbi/handles/database.rb +34 -16
- data/lib/dbi/handles/statement.rb +62 -29
- data/lib/dbi/row.rb +21 -10
- data/lib/dbi/sql.rb +0 -1
- data/lib/dbi/typeutil.rb +1 -1
- data/test/dbi/tc_columninfo.rb +1 -1
- data/test/dbi/tc_dbi.rb +1 -1
- data/test/dbi/tc_sqlbind.rb +2 -2
- data/test/dbi/tc_statementhandle.rb +14 -1
- data/test/dbi/tc_types.rb +10 -4
- metadata +68 -76
data/build/Rakefile.dbi.rb
CHANGED
@@ -14,11 +14,11 @@ task :package => (map_task("package") + map_task("gem"))
|
|
14
14
|
task :clobber_package => map_task("clobber_package")
|
15
15
|
|
16
16
|
task :test_dbi do
|
17
|
-
ruby
|
17
|
+
ruby("test/ts_dbi.rb")
|
18
18
|
end
|
19
19
|
|
20
20
|
task :test_dbd do
|
21
|
-
ruby
|
21
|
+
ruby("test/ts_dbd.rb")
|
22
22
|
end
|
23
23
|
|
24
24
|
task :test => [:test_dbi, :test_dbd]
|
data/lib/dbi.rb
CHANGED
@@ -90,7 +90,7 @@ Deprecate.set_action(
|
|
90
90
|
|
91
91
|
#++
|
92
92
|
module DBI
|
93
|
-
VERSION = "0.4.
|
93
|
+
VERSION = "0.4.1"
|
94
94
|
|
95
95
|
module DBD # :nodoc:
|
96
96
|
API_VERSION = "0.3"
|
@@ -269,9 +269,10 @@ module DBI
|
|
269
269
|
# driver handle.
|
270
270
|
|
271
271
|
dr = nil
|
272
|
+
dr_error = nil
|
272
273
|
begin
|
273
274
|
dr = DBI::DBD.const_get(driver_name.intern)
|
274
|
-
rescue NameError
|
275
|
+
rescue NameError => dr_error
|
275
276
|
# caseless look for constants to find actual constant
|
276
277
|
dc = driver_name.downcase
|
277
278
|
found = DBI::DBD.constants.find { |e| e.downcase == dc }
|
@@ -283,6 +284,13 @@ module DBI
|
|
283
284
|
# can fail for other reasons.
|
284
285
|
if dr.nil?
|
285
286
|
err = "Unable to load driver '#{driver_name}'"
|
287
|
+
|
288
|
+
if dr_error
|
289
|
+
err += " (underlying error: #{dr_error.message})"
|
290
|
+
else
|
291
|
+
err += " (BUG: could not determine underlying error)"
|
292
|
+
end
|
293
|
+
|
286
294
|
raise DBI::InterfaceError, err
|
287
295
|
end
|
288
296
|
|
@@ -8,6 +8,9 @@ module DBI
|
|
8
8
|
# Optional" are defined in DBI::BaseDatabase.
|
9
9
|
#
|
10
10
|
class BaseStatement < Base
|
11
|
+
|
12
|
+
attr_accessor :raise_error
|
13
|
+
|
11
14
|
def initialize(attr=nil)
|
12
15
|
@attr = attr || {}
|
13
16
|
end
|
@@ -154,6 +157,7 @@ module DBI
|
|
154
157
|
# Get statement attributes.
|
155
158
|
#
|
156
159
|
def [](attr)
|
160
|
+
@attr ||= { }
|
157
161
|
@attr[attr]
|
158
162
|
end
|
159
163
|
|
data/lib/dbi/columninfo.rb
CHANGED
data/lib/dbi/handles/database.rb
CHANGED
@@ -8,6 +8,9 @@ module DBI
|
|
8
8
|
# Note: almost all methods in this class will raise InterfaceError if the
|
9
9
|
# database is not connected.
|
10
10
|
class DatabaseHandle < Handle
|
11
|
+
|
12
|
+
attr_accessor :raise_error
|
13
|
+
|
11
14
|
# This is the driver name as supplied by the DBD's driver_name method.
|
12
15
|
# Its primary utility is in DBI::TypeUtil#convert.
|
13
16
|
def driver_name
|
@@ -34,7 +37,7 @@ module DBI
|
|
34
37
|
# already done prior.
|
35
38
|
#
|
36
39
|
def disconnect
|
37
|
-
|
40
|
+
sanity_check
|
38
41
|
@handle.disconnect
|
39
42
|
@handle = nil
|
40
43
|
end
|
@@ -45,10 +48,11 @@ module DBI
|
|
45
48
|
# BaseStatement#finish it when the block is done executing.
|
46
49
|
#
|
47
50
|
def prepare(stmt)
|
48
|
-
|
51
|
+
sanity_check(stmt)
|
49
52
|
sth = StatementHandle.new(@handle.prepare(stmt), false, true, @convert_types)
|
50
53
|
# FIXME trace sth.trace(@trace_mode, @trace_output)
|
51
54
|
sth.dbh = self
|
55
|
+
sth.raise_error = raise_error
|
52
56
|
|
53
57
|
if block_given?
|
54
58
|
begin
|
@@ -65,15 +69,16 @@ module DBI
|
|
65
69
|
# Prepare and execute a statement. It has block semantics equivalent to #prepare.
|
66
70
|
#
|
67
71
|
def execute(stmt, *bindvars)
|
68
|
-
|
72
|
+
sanity_check(stmt)
|
69
73
|
|
70
74
|
if @convert_types
|
71
75
|
bindvars = DBI::Utils::ConvParam.conv_param(driver_name, *bindvars)
|
72
76
|
end
|
73
77
|
|
74
|
-
sth = StatementHandle.new(@handle.execute(stmt, *bindvars), true,
|
78
|
+
sth = StatementHandle.new(@handle.execute(stmt, *bindvars), true, true, @convert_types, true)
|
75
79
|
# FIXME trace sth.trace(@trace_mode, @trace_output)
|
76
80
|
sth.dbh = self
|
81
|
+
sth.raise_error = raise_error
|
77
82
|
|
78
83
|
if block_given?
|
79
84
|
begin
|
@@ -92,7 +97,8 @@ module DBI
|
|
92
97
|
# #execute and #prepare. Should return a row modified count.
|
93
98
|
#
|
94
99
|
def do(stmt, *bindvars)
|
95
|
-
|
100
|
+
sanity_check(stmt)
|
101
|
+
|
96
102
|
@handle.do(stmt, *DBI::Utils::ConvParam.conv_param(driver_name, *bindvars))
|
97
103
|
end
|
98
104
|
|
@@ -100,7 +106,7 @@ module DBI
|
|
100
106
|
# Executes a statement and returns the first row from the result.
|
101
107
|
#
|
102
108
|
def select_one(stmt, *bindvars)
|
103
|
-
|
109
|
+
sanity_check(stmt)
|
104
110
|
row = nil
|
105
111
|
execute(stmt, *bindvars) do |sth|
|
106
112
|
row = sth.fetch
|
@@ -113,7 +119,7 @@ module DBI
|
|
113
119
|
# is given, it is executed for each row.
|
114
120
|
#
|
115
121
|
def select_all(stmt, *bindvars, &p)
|
116
|
-
|
122
|
+
sanity_check(stmt)
|
117
123
|
rows = nil
|
118
124
|
execute(stmt, *bindvars) do |sth|
|
119
125
|
if block_given?
|
@@ -129,7 +135,7 @@ module DBI
|
|
129
135
|
# Return the tables available to this DatabaseHandle as an array of strings.
|
130
136
|
#
|
131
137
|
def tables
|
132
|
-
|
138
|
+
sanity_check
|
133
139
|
@handle.tables
|
134
140
|
end
|
135
141
|
|
@@ -139,7 +145,7 @@ module DBI
|
|
139
145
|
# this method must provide.
|
140
146
|
#
|
141
147
|
def columns( table )
|
142
|
-
|
148
|
+
sanity_check
|
143
149
|
@handle.columns( table ).collect {|col| ColumnInfo.new(col) }
|
144
150
|
end
|
145
151
|
|
@@ -149,7 +155,7 @@ module DBI
|
|
149
155
|
# is an active operation that will contact the database.
|
150
156
|
#
|
151
157
|
def ping
|
152
|
-
|
158
|
+
sanity_check
|
153
159
|
@handle.ping
|
154
160
|
end
|
155
161
|
|
@@ -157,7 +163,7 @@ module DBI
|
|
157
163
|
# Attempt to escape the value, rendering it suitable for inclusion in a SQL statement.
|
158
164
|
#
|
159
165
|
def quote(value)
|
160
|
-
|
166
|
+
sanity_check
|
161
167
|
@handle.quote(value)
|
162
168
|
end
|
163
169
|
|
@@ -165,7 +171,7 @@ module DBI
|
|
165
171
|
# Force a commit to the database immediately.
|
166
172
|
#
|
167
173
|
def commit
|
168
|
-
|
174
|
+
sanity_check
|
169
175
|
@handle.commit
|
170
176
|
end
|
171
177
|
|
@@ -173,7 +179,7 @@ module DBI
|
|
173
179
|
# Force a rollback to the database immediately.
|
174
180
|
#
|
175
181
|
def rollback
|
176
|
-
|
182
|
+
sanity_check
|
177
183
|
@handle.rollback
|
178
184
|
end
|
179
185
|
|
@@ -183,7 +189,7 @@ module DBI
|
|
183
189
|
# Otherwise, commit occurs.
|
184
190
|
#
|
185
191
|
def transaction
|
186
|
-
|
192
|
+
sanity_check
|
187
193
|
raise InterfaceError, "No block given" unless block_given?
|
188
194
|
|
189
195
|
commit
|
@@ -198,14 +204,26 @@ module DBI
|
|
198
204
|
|
199
205
|
# Get an attribute from the DatabaseHandle.
|
200
206
|
def [] (attr)
|
201
|
-
|
207
|
+
sanity_check
|
202
208
|
@handle[attr]
|
203
209
|
end
|
204
210
|
|
205
211
|
# Set an attribute on the DatabaseHandle.
|
206
212
|
def []= (attr, val)
|
207
|
-
|
213
|
+
sanity_check
|
208
214
|
@handle[attr] = val
|
209
215
|
end
|
216
|
+
|
217
|
+
protected
|
218
|
+
|
219
|
+
def sanity_check(stmt=nil)
|
220
|
+
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
|
221
|
+
check_statement(stmt) if stmt
|
222
|
+
end
|
223
|
+
|
224
|
+
# basic sanity checks for statements
|
225
|
+
def check_statement(stmt)
|
226
|
+
raise InterfaceError, "Statement is empty, or contains nothing but whitespace" if stmt !~ /\S/
|
227
|
+
end
|
210
228
|
end
|
211
229
|
end
|
@@ -12,11 +12,13 @@ module DBI
|
|
12
12
|
include Enumerable
|
13
13
|
|
14
14
|
attr_accessor :dbh
|
15
|
+
attr_accessor :raise_error
|
15
16
|
|
16
|
-
def initialize(handle, fetchable=false, prepared=true, convert_types=true)
|
17
|
+
def initialize(handle, fetchable=false, prepared=true, convert_types=true, executed=false)
|
17
18
|
super(handle)
|
18
19
|
@fetchable = fetchable
|
19
20
|
@prepared = prepared # only false if immediate execute was used
|
21
|
+
@executed = executed # only true if the statement was already executed.
|
20
22
|
@cols = nil
|
21
23
|
@coltypes = nil
|
22
24
|
@convert_types = convert_types
|
@@ -68,8 +70,8 @@ module DBI
|
|
68
70
|
# sth.finish
|
69
71
|
#
|
70
72
|
def bind_coltype(pos, type)
|
71
|
-
|
72
|
-
|
73
|
+
sanity_check({:prepared => true, :executed => true})
|
74
|
+
|
73
75
|
coltypes = column_types
|
74
76
|
|
75
77
|
if (pos - 1) < 1
|
@@ -85,8 +87,7 @@ module DBI
|
|
85
87
|
# type if it's supposed to, adhering to the DBD's current ruleset.
|
86
88
|
#
|
87
89
|
def bind_param(param, value, attribs=nil)
|
88
|
-
|
89
|
-
raise InterfaceError, "Statement wasn't prepared before." unless @prepared
|
90
|
+
sanity_check({ :prepared => true })
|
90
91
|
|
91
92
|
if @convert_types
|
92
93
|
value = DBI::Utils::ConvParam.conv_param(dbh.driver_name, value)[0]
|
@@ -105,8 +106,7 @@ module DBI
|
|
105
106
|
# If arguments are supplied, these are fed to #bind_param.
|
106
107
|
def execute(*bindvars)
|
107
108
|
cancel # cancel before
|
108
|
-
|
109
|
-
raise InterfaceError, "Statement wasn't prepared before." unless @prepared
|
109
|
+
sanity_check({:prepared => true })
|
110
110
|
|
111
111
|
if @convert_types
|
112
112
|
bindvars = DBI::Utils::ConvParam.conv_param(dbh.driver_name, *bindvars)
|
@@ -132,7 +132,7 @@ module DBI
|
|
132
132
|
# inoperable and unavailable for further use.
|
133
133
|
#
|
134
134
|
def finish
|
135
|
-
|
135
|
+
sanity_check
|
136
136
|
@handle.finish
|
137
137
|
@handle = nil
|
138
138
|
end
|
@@ -144,7 +144,7 @@ module DBI
|
|
144
144
|
# may be re-executed.
|
145
145
|
#
|
146
146
|
def cancel
|
147
|
-
|
147
|
+
sanity_check
|
148
148
|
@handle.cancel if @fetchable
|
149
149
|
@fetchable = false
|
150
150
|
end
|
@@ -153,7 +153,7 @@ module DBI
|
|
153
153
|
# Obtains the column names for this query as an array.
|
154
154
|
#
|
155
155
|
def column_names
|
156
|
-
|
156
|
+
sanity_check
|
157
157
|
return @cols unless @cols.nil?
|
158
158
|
@cols = @handle.column_info.collect {|col| col['name'] }
|
159
159
|
end
|
@@ -166,7 +166,7 @@ module DBI
|
|
166
166
|
# to the DBI::Type calling syntax.
|
167
167
|
#
|
168
168
|
def column_types
|
169
|
-
|
169
|
+
sanity_check
|
170
170
|
return @coltypes unless @coltypes.nil?
|
171
171
|
@coltypes = @handle.column_info.collect do |col|
|
172
172
|
if col['dbi_type']
|
@@ -181,7 +181,7 @@ module DBI
|
|
181
181
|
# See BaseStatement#column_info.
|
182
182
|
#
|
183
183
|
def column_info
|
184
|
-
|
184
|
+
sanity_check
|
185
185
|
@handle.column_info.collect {|col| ColumnInfo.new(col) }
|
186
186
|
end
|
187
187
|
|
@@ -193,7 +193,7 @@ module DBI
|
|
193
193
|
# statements, f.e.)
|
194
194
|
#
|
195
195
|
def rows
|
196
|
-
|
196
|
+
sanity_check
|
197
197
|
@handle.rows
|
198
198
|
end
|
199
199
|
|
@@ -205,7 +205,7 @@ module DBI
|
|
205
205
|
# similar fashion to Enumerable#collect. See #each.
|
206
206
|
#
|
207
207
|
def fetch(&p)
|
208
|
-
|
208
|
+
sanity_check({ :fetchable => true, :prepared => true, :executed => true })
|
209
209
|
|
210
210
|
if block_given?
|
211
211
|
while (res = @handle.fetch) != nil
|
@@ -234,8 +234,7 @@ module DBI
|
|
234
234
|
# Synonym for #fetch with a block.
|
235
235
|
#
|
236
236
|
def each(&p)
|
237
|
-
|
238
|
-
raise InterfaceError, "Statement must first be executed" unless @fetchable
|
237
|
+
sanity_check({:fetchable => true, :prepared => true, :executed => true})
|
239
238
|
raise InterfaceError, "No block given" unless block_given?
|
240
239
|
|
241
240
|
fetch(&p)
|
@@ -247,8 +246,7 @@ module DBI
|
|
247
246
|
# is basically a way to get the raw data from the DBD.
|
248
247
|
#
|
249
248
|
def fetch_array
|
250
|
-
|
251
|
-
raise InterfaceError, "Statement must first be executed" unless @fetchable
|
249
|
+
sanity_check({:fetchable => true, :prepared => true, :executed => true})
|
252
250
|
|
253
251
|
if block_given?
|
254
252
|
while (res = @handle.fetch) != nil
|
@@ -273,8 +271,7 @@ module DBI
|
|
273
271
|
# No type conversion is performed here. Expect this to change in 0.6.0.
|
274
272
|
#
|
275
273
|
def fetch_hash
|
276
|
-
|
277
|
-
raise InterfaceError, "Statement must first be executed" unless @fetchable
|
274
|
+
sanity_check({:fetchable => true, :prepared => true, :executed => true})
|
278
275
|
|
279
276
|
cols = column_names
|
280
277
|
|
@@ -305,12 +302,11 @@ module DBI
|
|
305
302
|
# Fetch `cnt` rows. Result is array of DBI::Row
|
306
303
|
#
|
307
304
|
def fetch_many(cnt)
|
308
|
-
|
309
|
-
raise InterfaceError, "Statement must first be executed" unless @fetchable
|
305
|
+
sanity_check({:fetchable => true, :prepared => true, :executed => true})
|
310
306
|
|
311
307
|
cols = column_names
|
312
308
|
rows = @handle.fetch_many(cnt)
|
313
|
-
if rows.nil?
|
309
|
+
if rows.nil? or rows.empty?
|
314
310
|
@handle.cancel
|
315
311
|
@fetchable = false
|
316
312
|
return []
|
@@ -323,8 +319,7 @@ module DBI
|
|
323
319
|
# Fetch the entire result set. Result is array of DBI::Row.
|
324
320
|
#
|
325
321
|
def fetch_all
|
326
|
-
|
327
|
-
raise InterfaceError, "Statement must first be executed" unless @fetchable
|
322
|
+
sanity_check({:fetchable => true, :prepared => true, :executed => true})
|
328
323
|
|
329
324
|
cols = column_names
|
330
325
|
fetched_rows = []
|
@@ -346,8 +341,7 @@ module DBI
|
|
346
341
|
# See BaseStatement#fetch_scroll.
|
347
342
|
#
|
348
343
|
def fetch_scroll(direction, offset=1)
|
349
|
-
|
350
|
-
raise InterfaceError, "Statement must first be executed" unless @fetchable
|
344
|
+
sanity_check({:fetchable => true, :prepared => true, :executed => true})
|
351
345
|
|
352
346
|
row = @handle.fetch_scroll(direction, offset)
|
353
347
|
if row.nil?
|
@@ -362,14 +356,53 @@ module DBI
|
|
362
356
|
|
363
357
|
# Get an attribute from the StatementHandle object.
|
364
358
|
def [] (attr)
|
365
|
-
|
359
|
+
sanity_check
|
366
360
|
@handle[attr]
|
367
361
|
end
|
368
362
|
|
369
363
|
# Set an attribute on the StatementHandle object.
|
370
364
|
def []= (attr, val)
|
371
|
-
|
365
|
+
sanity_check
|
372
366
|
@handle[attr] = val
|
373
367
|
end
|
368
|
+
|
369
|
+
protected
|
370
|
+
|
371
|
+
def sanity_check(params={})
|
372
|
+
raise InterfaceError, "Statement was already closed!" if @handle.nil?
|
373
|
+
|
374
|
+
params.each_key do |key|
|
375
|
+
case key
|
376
|
+
when :fetchable
|
377
|
+
check_fetchable
|
378
|
+
when :executed
|
379
|
+
check_executed
|
380
|
+
when :prepared
|
381
|
+
check_prepared
|
382
|
+
when :statement
|
383
|
+
check_statement(params[:statement])
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
def check_prepared
|
389
|
+
raise InterfaceError, "Statement wasn't prepared before." unless @prepared
|
390
|
+
end
|
391
|
+
|
392
|
+
def check_fetchable
|
393
|
+
if !@fetchable and @raise_error
|
394
|
+
raise InterfaceError, "Statement does not have any data for fetching."
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
def check_executed
|
399
|
+
raise InterfaceError, "Statement hasn't been executed yet." unless @executed
|
400
|
+
end
|
401
|
+
|
402
|
+
# basic sanity checks for statements
|
403
|
+
def check_statement(stmt)
|
404
|
+
raise InterfaceError, "Statement is empty, or contains nothing but whitespace" if stmt !~ /\S/
|
405
|
+
end
|
406
|
+
|
374
407
|
end # class StatementHandle
|
375
408
|
end
|
data/lib/dbi/row.rb
CHANGED
@@ -98,7 +98,7 @@ module DBI
|
|
98
98
|
# Create a new row with 'new_values', reusing the field name hash.
|
99
99
|
# Initial cloning is done deeply, via Marshal.
|
100
100
|
def clone_with(new_values)
|
101
|
-
obj =
|
101
|
+
obj = clone
|
102
102
|
obj.set_values(new_values)
|
103
103
|
|
104
104
|
return obj
|
@@ -208,16 +208,27 @@ module DBI
|
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
211
|
-
#
|
212
|
-
# See Object#clone.
|
213
|
-
#
|
214
|
-
# #clone and #dup here, however, are both deep copies via Marshal.
|
215
|
-
#
|
216
|
-
def clone
|
217
|
-
Marshal.load(Marshal.dump(self))
|
218
|
-
end
|
219
211
|
|
220
|
-
|
212
|
+
if RUBY_VERSION =~ /^1\.9/
|
213
|
+
def __getobj__
|
214
|
+
@arr
|
215
|
+
end
|
216
|
+
|
217
|
+
def __setobj__(obj)
|
218
|
+
@delegate_dc_obj = @arr = obj
|
219
|
+
end
|
220
|
+
else
|
221
|
+
#
|
222
|
+
# See Object#clone.
|
223
|
+
#
|
224
|
+
# #clone and #dup here, however, are both deep copies via Marshal.
|
225
|
+
#
|
226
|
+
def clone
|
227
|
+
Marshal.load(Marshal.dump(self))
|
228
|
+
end
|
229
|
+
|
230
|
+
alias dup clone
|
231
|
+
end
|
221
232
|
|
222
233
|
private
|
223
234
|
|
data/lib/dbi/sql.rb
CHANGED
data/lib/dbi/typeutil.rb
CHANGED
@@ -93,7 +93,7 @@ DBI::TypeUtil.register_conversion("default") do |obj|
|
|
93
93
|
when ::FalseClass
|
94
94
|
"'0'"
|
95
95
|
when ::Time, ::Date, ::DateTime
|
96
|
-
"'#{::DateTime.parse(obj.to_s).strftime("%m
|
96
|
+
"'#{::DateTime.parse(obj.to_s).strftime("%Y-%m-%dT%H:%M:%S")}'"
|
97
97
|
when ::String
|
98
98
|
obj = obj.gsub(/\\/) { "\\\\" }
|
99
99
|
obj = obj.gsub(/'/) { "''" }
|
data/test/dbi/tc_columninfo.rb
CHANGED
data/test/dbi/tc_dbi.rb
CHANGED
data/test/dbi/tc_sqlbind.rb
CHANGED
@@ -22,13 +22,13 @@ class TestSqlBind < Test::Unit::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_too_many
|
25
|
-
|
25
|
+
assert_raises (RuntimeError) {
|
26
26
|
bind(self, "age=?", [10, 11])
|
27
27
|
}
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_too_few
|
31
|
-
|
31
|
+
assert_raises (RuntimeError) {
|
32
32
|
bind(self, "age in (?, ?, ?)", [10, 11])
|
33
33
|
}
|
34
34
|
end
|
@@ -8,7 +8,20 @@ class TC_DBI_StatementHandle < Test::Unit::TestCase
|
|
8
8
|
def mock_handle.cancel; end
|
9
9
|
def mock_handle.column_info; {}; end
|
10
10
|
def mock_handle.fetch; nil; end
|
11
|
-
sth = DBI::StatementHandle.new( mock_handle, true, false )
|
11
|
+
sth = DBI::StatementHandle.new( mock_handle, true, true, false, true)
|
12
|
+
|
13
|
+
10.times do
|
14
|
+
assert_nil sth.fetch
|
15
|
+
end
|
16
|
+
|
17
|
+
sth.raise_error = true
|
18
|
+
|
19
|
+
assert_raises(DBI::InterfaceError) do
|
20
|
+
sth.fetch
|
21
|
+
end
|
22
|
+
|
23
|
+
sth.raise_error = false
|
24
|
+
|
12
25
|
10.times do
|
13
26
|
assert_nil sth.fetch
|
14
27
|
end
|
data/test/dbi/tc_types.rb
CHANGED
@@ -114,9 +114,15 @@ class TC_DBI_Type < Test::Unit::TestCase
|
|
114
114
|
d = Date.today
|
115
115
|
assert_equal(DateTime.parse(d.to_s), klass.parse(d))
|
116
116
|
|
117
|
+
md = "10-11"
|
118
|
+
|
119
|
+
if RUBY_VERSION =~ /^1\.9/
|
120
|
+
md = "11-10"
|
121
|
+
end
|
122
|
+
|
117
123
|
# be sure we're actually getting the right data back
|
118
124
|
assert_equal(
|
119
|
-
"2008
|
125
|
+
"2008-#{md}",
|
120
126
|
klass.parse(Date.parse("10/11/2008")).strftime("%Y-%m-%d")
|
121
127
|
)
|
122
128
|
|
@@ -126,8 +132,8 @@ class TC_DBI_Type < Test::Unit::TestCase
|
|
126
132
|
)
|
127
133
|
|
128
134
|
assert_equal(
|
129
|
-
"
|
130
|
-
klass.parse(DateTime.parse("10/11/2008 10:01:02")).strftime("%m
|
135
|
+
"#{md}-2008 10:01:02",
|
136
|
+
klass.parse(DateTime.parse("10/11/2008 10:01:02")).strftime("%m-%d-%Y %H:%M:%S")
|
131
137
|
)
|
132
138
|
end
|
133
139
|
end
|
@@ -138,7 +144,7 @@ class TC_DBI_TypeUtil < Test::Unit::TestCase
|
|
138
144
|
end
|
139
145
|
|
140
146
|
def datecast(obj)
|
141
|
-
"'#{::DateTime.parse(obj.to_s).strftime("%m
|
147
|
+
"'#{::DateTime.parse(obj.to_s).strftime("%Y-%m-%dT%H:%M:%S")}'"
|
142
148
|
end
|
143
149
|
|
144
150
|
def test_default_unknown_cast
|
metadata
CHANGED
@@ -1,108 +1,100 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
2
4
|
name: dbi
|
3
5
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
6
|
+
version: 0.4.1
|
7
|
+
date: 2008-11-28 00:00:00 -08:00
|
8
|
+
summary: A vendor independent interface for accessing databases, similar to Perl's DBI
|
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: A vendor independent interface for accessing databases, similar to Perl's DBI
|
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:
|
5
25
|
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
6
29
|
authors:
|
7
30
|
- Erik Hollensbe
|
8
31
|
- Christopher Maujean
|
9
|
-
autorequire:
|
10
|
-
bindir: bin
|
11
|
-
cert_chain: []
|
12
|
-
|
13
|
-
date: 2008-08-23 00:00:00 -07:00
|
14
|
-
default_executable:
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
17
|
-
name: deprecated
|
18
|
-
type: :runtime
|
19
|
-
version_requirement:
|
20
|
-
version_requirements: !ruby/object:Gem::Requirement
|
21
|
-
requirements:
|
22
|
-
- - ">="
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 2.0.0
|
25
|
-
version:
|
26
|
-
description: A vendor independent interface for accessing databases, similar to Perl's DBI
|
27
|
-
email: ruby-dbi-users@rubyforge.org
|
28
|
-
executables:
|
29
|
-
- dbi
|
30
|
-
extensions: []
|
31
|
-
|
32
|
-
extra_rdoc_files:
|
33
|
-
- README
|
34
|
-
- LICENSE
|
35
|
-
- ChangeLog
|
36
32
|
files:
|
37
|
-
- examples/xmltest.rb
|
38
|
-
- examples/test1.rb
|
39
33
|
- examples/test1.pl
|
34
|
+
- examples/test1.rb
|
35
|
+
- examples/xmltest.rb
|
40
36
|
- bin/dbi
|
41
37
|
- build/Rakefile.dbi.rb
|
42
38
|
- lib/dbi.rb
|
39
|
+
- lib/dbi/row.rb
|
40
|
+
- lib/dbi/columninfo.rb
|
41
|
+
- lib/dbi/sql/preparedstatement.rb
|
42
|
+
- lib/dbi/typeutil.rb
|
43
|
+
- lib/dbi/utils/time.rb
|
44
|
+
- lib/dbi/utils/xmlformatter.rb
|
43
45
|
- lib/dbi/utils/timestamp.rb
|
44
46
|
- lib/dbi/utils/date.rb
|
45
47
|
- lib/dbi/utils/tableformatter.rb
|
46
|
-
- lib/dbi/
|
47
|
-
- lib/dbi/
|
48
|
+
- lib/dbi/binary.rb
|
49
|
+
- lib/dbi/base_classes/database.rb
|
50
|
+
- lib/dbi/base_classes/driver.rb
|
51
|
+
- lib/dbi/base_classes/statement.rb
|
48
52
|
- lib/dbi/sql_type_constants.rb
|
49
|
-
- lib/dbi/sql/preparedstatement.rb
|
50
|
-
- lib/dbi/handles/driver.rb
|
51
|
-
- lib/dbi/handles/database.rb
|
52
|
-
- lib/dbi/handles/statement.rb
|
53
53
|
- lib/dbi/handles.rb
|
54
|
-
- lib/dbi/sql.rb
|
55
|
-
- lib/dbi/typeutil.rb
|
56
54
|
- lib/dbi/exceptions.rb
|
55
|
+
- lib/dbi/types.rb
|
57
56
|
- lib/dbi/trace.rb
|
58
|
-
- lib/dbi/binary.rb
|
59
|
-
- lib/dbi/utils.rb
|
60
|
-
- lib/dbi/base_classes/driver.rb
|
61
|
-
- lib/dbi/base_classes/database.rb
|
62
|
-
- lib/dbi/base_classes/statement.rb
|
63
|
-
- lib/dbi/row.rb
|
64
|
-
- lib/dbi/columninfo.rb
|
65
57
|
- lib/dbi/base_classes.rb
|
66
|
-
- lib/dbi/
|
58
|
+
- lib/dbi/utils.rb
|
59
|
+
- lib/dbi/sql.rb
|
60
|
+
- lib/dbi/handles/database.rb
|
61
|
+
- lib/dbi/handles/driver.rb
|
62
|
+
- lib/dbi/handles/statement.rb
|
67
63
|
- test/ts_dbi.rb
|
68
|
-
- test/dbi/
|
64
|
+
- test/dbi/tc_time.rb
|
65
|
+
- test/dbi/tc_row.rb
|
66
|
+
- test/dbi/tc_dbi.rb
|
69
67
|
- test/dbi/tc_statementhandle.rb
|
70
|
-
- test/dbi/tc_columninfo.rb
|
71
|
-
- test/dbi/tc_timestamp.rb
|
72
68
|
- test/dbi/tc_sqlbind.rb
|
69
|
+
- test/dbi/tc_columninfo.rb
|
73
70
|
- test/dbi/trace.rb
|
74
|
-
- test/dbi/
|
71
|
+
- test/dbi/tc_timestamp.rb
|
75
72
|
- test/dbi/tc_types.rb
|
76
|
-
- test/dbi/
|
77
|
-
- test/dbi/tc_time.rb
|
73
|
+
- test/dbi/tc_date.rb
|
78
74
|
- README
|
79
75
|
- LICENSE
|
80
76
|
- ChangeLog
|
81
|
-
|
82
|
-
|
83
|
-
post_install_message:
|
77
|
+
test_files:
|
78
|
+
- test/ts_dbi.rb
|
84
79
|
rdoc_options: []
|
85
80
|
|
86
|
-
|
87
|
-
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
-
requirements:
|
96
|
-
- - ">="
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version: "0"
|
99
|
-
version:
|
81
|
+
extra_rdoc_files:
|
82
|
+
- README
|
83
|
+
- LICENSE
|
84
|
+
- ChangeLog
|
85
|
+
executables:
|
86
|
+
- dbi
|
87
|
+
extensions: []
|
88
|
+
|
100
89
|
requirements: []
|
101
90
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
-
|
91
|
+
dependencies:
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: deprecated
|
94
|
+
version_requirement:
|
95
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 2.0.0
|
100
|
+
version:
|