rdbi-driver-sqlite3 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ begin
17
17
  gem.add_development_dependency 'rdoc'
18
18
 
19
19
  gem.add_dependency 'rdbi'
20
- gem.add_dependency 'sqlite3-ruby', '= 1.3.1'
20
+ gem.add_dependency 'sqlite3-ruby', '~> 1.3'
21
21
  gem.add_dependency 'methlab'
22
22
  gem.add_dependency 'epoxy', '>= 0.3.1'
23
23
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.0
1
+ 0.9.1
@@ -0,0 +1,2 @@
1
+ require 'rdbi'
2
+ require 'rdbi/driver/sqlite3'
@@ -2,7 +2,6 @@ require 'rdbi'
2
2
  require 'epoxy'
3
3
  require 'methlab'
4
4
 
5
- gem 'sqlite3-ruby', '= 1.3.1'
6
5
  require 'sqlite3'
7
6
 
8
7
  class RDBI::Driver::SQLite3 < RDBI::Driver
@@ -130,6 +129,7 @@ class RDBI::Driver::SQLite3 < RDBI::Driver
130
129
  end
131
130
 
132
131
  def result_count
132
+ return 0 unless rewindable_result
133
133
  coerce_to_array
134
134
  @array_handle.size
135
135
  end
@@ -153,14 +153,24 @@ class RDBI::Driver::SQLite3 < RDBI::Driver
153
153
  end
154
154
 
155
155
  def rest
156
- coerce_to_array
157
- oindex, @index = @index, @array_handle.size
158
- @array_handle[oindex, @index]
156
+ if rewindable_result
157
+ rewind
158
+ coerce_to_array
159
+ oindex, @index = @index, @array_handle.size
160
+ @array_handle[oindex, @index]
161
+ else
162
+ @handle.to_a
163
+ end
159
164
  end
160
165
 
161
166
  def all
162
- coerce_to_array
163
- @array_handle.dup
167
+ if rewindable_result
168
+ rewind
169
+ coerce_to_array
170
+ @array_handle
171
+ else
172
+ @handle.to_a
173
+ end
164
174
  end
165
175
 
166
176
  def [](index)
@@ -177,6 +187,8 @@ class RDBI::Driver::SQLite3 < RDBI::Driver
177
187
  end
178
188
 
179
189
  def rewind
190
+ # FIXME better exception
191
+ raise StandardError, "rewindable_result is not true" unless rewindable_result
180
192
  @index = 0
181
193
  @handle.reset unless @handle.closed?
182
194
  end
@@ -191,8 +203,10 @@ class RDBI::Driver::SQLite3 < RDBI::Driver
191
203
  end
192
204
 
193
205
  def coerce_to_array
194
- unless @array_handle
206
+ unless @coerced
207
+ rewind
195
208
  @array_handle = @handle.to_a
209
+ @coerced = true
196
210
  end
197
211
  end
198
212
  end
@@ -202,6 +216,16 @@ class RDBI::Driver::SQLite3 < RDBI::Driver
202
216
 
203
217
  attr_accessor :handle
204
218
 
219
+ class << self
220
+ def input_type_map
221
+ @input_type_map ||= RDBI::Type.create_type_hash(RDBI::Type::In)
222
+ end
223
+
224
+ def output_type_map
225
+ @output_type_map ||= RDBI::Type.create_type_hash(RDBI::Type::Out)
226
+ end
227
+ end
228
+
205
229
  def initialize(query, dbh)
206
230
  super
207
231
 
@@ -214,25 +238,22 @@ class RDBI::Driver::SQLite3 < RDBI::Driver
214
238
  query = ep.quote(@index_map.compact.inject({}) { |x,y| x.merge({ y => nil }) }) { '?' }
215
239
 
216
240
  @handle = check_exception { dbh.handle.prepare(query) }
217
- @input_type_map = RDBI::Type.create_type_hash(RDBI::Type::In)
218
- @output_type_map = RDBI::Type.create_type_hash(RDBI::Type::Out)
241
+ @input_type_map = self.class.input_type_map
242
+ @output_type_map = self.class.output_type_map
243
+
244
+ prep_finalizer { @handle.close unless @handle.closed? }
219
245
  end
220
246
 
221
- def new_execution(*binds)
247
+ def new_modification(*binds)
248
+ binds = RDBI::Util.index_binds(binds, @index_map)
222
249
 
223
- # XXX is there a patron saint of being too clever? I don't like this
224
- # code.
225
-
226
- # FIXME move to RDBI::Util or something.
227
- hashes, binds = binds.partition { |x| x.kind_of?(Hash) }
228
- hash = hashes.inject({}) { |x, y| x.merge(y) }
229
- hash.keys.each do |key|
230
- if index = @index_map.index(key)
231
- binds.insert(index, hash[key])
232
- end
233
- end
250
+ rs = check_exception { @handle.execute(*binds) }
234
251
 
235
- # but this code is still ok.
252
+ return 0
253
+ end
254
+
255
+ def new_execution(*binds)
256
+ binds = RDBI::Util.index_binds(binds, @index_map)
236
257
 
237
258
  rs = check_exception { @handle.execute(*binds) }
238
259
 
@@ -252,11 +273,6 @@ class RDBI::Driver::SQLite3 < RDBI::Driver
252
273
  return Cursor.new(rs), this_schema, @output_type_map
253
274
  end
254
275
 
255
- def finish
256
- @handle.close rescue nil
257
- super
258
- end
259
-
260
276
  protected
261
277
 
262
278
  def check_exception(&block)
@@ -1,41 +1,40 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rdbi-driver-sqlite3}
8
- s.version = "0.9.0"
8
+ s.version = "0.9.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Erik Hollensbe"]
12
- s.date = %q{2010-08-21}
12
+ s.date = %q{2010-12-10}
13
13
  s.description = %q{sqlite3 driver for RDBI}
14
14
  s.email = %q{erik@hollensbe.org}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/rdbi/driver/sqlite3.rb",
27
- "rdbi-driver-sqlite3.gemspec",
28
- "test/helper.rb",
29
- "test/test_database.rb"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/rdbi-driver-sqlite3.rb",
26
+ "lib/rdbi/driver/sqlite3.rb",
27
+ "rdbi-driver-sqlite3.gemspec",
28
+ "test/helper.rb",
29
+ "test/test_database.rb"
30
30
  ]
31
31
  s.homepage = %q{http://github.com/RDBI/rdbi-driver-sqlite3}
32
- s.rdoc_options = ["--charset=UTF-8"]
33
32
  s.require_paths = ["lib"]
34
33
  s.rubygems_version = %q{1.3.7}
35
34
  s.summary = %q{sqlite3 driver for RDBI}
36
35
  s.test_files = [
37
36
  "test/helper.rb",
38
- "test/test_database.rb"
37
+ "test/test_database.rb"
39
38
  ]
40
39
 
41
40
  if s.respond_to? :specification_version then
@@ -46,14 +45,14 @@ Gem::Specification.new do |s|
46
45
  s.add_development_dependency(%q<test-unit>, [">= 0"])
47
46
  s.add_development_dependency(%q<rdoc>, [">= 0"])
48
47
  s.add_runtime_dependency(%q<rdbi>, [">= 0"])
49
- s.add_runtime_dependency(%q<sqlite3-ruby>, ["= 1.3.1"])
48
+ s.add_runtime_dependency(%q<sqlite3-ruby>, ["~> 1.3"])
50
49
  s.add_runtime_dependency(%q<methlab>, [">= 0"])
51
50
  s.add_runtime_dependency(%q<epoxy>, [">= 0.3.1"])
52
51
  else
53
52
  s.add_dependency(%q<test-unit>, [">= 0"])
54
53
  s.add_dependency(%q<rdoc>, [">= 0"])
55
54
  s.add_dependency(%q<rdbi>, [">= 0"])
56
- s.add_dependency(%q<sqlite3-ruby>, ["= 1.3.1"])
55
+ s.add_dependency(%q<sqlite3-ruby>, ["~> 1.3"])
57
56
  s.add_dependency(%q<methlab>, [">= 0"])
58
57
  s.add_dependency(%q<epoxy>, [">= 0.3.1"])
59
58
  end
@@ -61,7 +60,7 @@ Gem::Specification.new do |s|
61
60
  s.add_dependency(%q<test-unit>, [">= 0"])
62
61
  s.add_dependency(%q<rdoc>, [">= 0"])
63
62
  s.add_dependency(%q<rdbi>, [">= 0"])
64
- s.add_dependency(%q<sqlite3-ruby>, ["= 1.3.1"])
63
+ s.add_dependency(%q<sqlite3-ruby>, ["~> 1.3"])
65
64
  s.add_dependency(%q<methlab>, [">= 0"])
66
65
  s.add_dependency(%q<epoxy>, [">= 0.3.1"])
67
66
  end
@@ -226,43 +226,7 @@ class TestDatabase < Test::Unit::TestCase
226
226
  sth.finish
227
227
  end
228
228
 
229
- def test_12_multiple_fields
230
- self.dbh = init_database
231
- sth = dbh.prepare("insert into multi_fields (foo, bar) values (?, ?)")
232
- sth.execute(1, "foo")
233
- sth.execute(2, "bar")
234
- sth.finish
235
-
236
- sth = dbh.prepare("select foo, bar from multi_fields")
237
- res = sth.execute
238
-
239
- assert(res)
240
-
241
- assert_equal(2, res.fetch(:all).length)
242
- assert_equal(2, res.fetch(:all)[0].length)
243
-
244
- assert_equal([1, "foo"], res.fetch(1)[0])
245
- assert_equal([2, "bar"], res.fetch(1)[0])
246
- sth.finish
247
-
248
- res = dbh.execute("select foo, bar from multi_fields where foo = ? and bar = ?bar", 1, { :bar => "foo" })
249
- assert(res)
250
- assert_equal([[1, "foo"]], res.fetch(:all))
251
-
252
- res = dbh.execute("select foo, bar from multi_fields where foo = ? and bar = ?bar", { :bar => "foo" }, 1)
253
- assert(res)
254
- assert_equal([[1, "foo"]], res.fetch(:all))
255
-
256
- res = dbh.execute("select foo, bar from multi_fields where foo = ?foo and bar = ?bar", { :foo => 1, :bar => "foo" })
257
- assert(res)
258
- assert_equal([[1, "foo"]], res.fetch(:all))
259
-
260
- res = dbh.execute("select foo, bar from multi_fields where foo = ?foo and bar = ?", { :foo => 1 }, "foo")
261
- assert(res)
262
- assert_equal([[1, "foo"]], res.fetch(:all))
263
- end
264
-
265
- def test_13_reconnection
229
+ def test_12_reconnection
266
230
  self.dbh = init_database
267
231
 
268
232
  assert_nothing_raised do
@@ -272,13 +236,11 @@ class TestDatabase < Test::Unit::TestCase
272
236
  end
273
237
 
274
238
  sth = dbh.prepare("select 1")
275
- $stderr.puts "You should see the next warning exactly once"
276
- dbh.reconnect
277
- dbh.disconnect
278
239
  dbh.reconnect
240
+ assert sth.finished?
279
241
  end
280
242
 
281
- def test_14_aggregates
243
+ def test_13_aggregates
282
244
  self.dbh = init_database
283
245
 
284
246
  res = dbh.execute("select count(*) from multi_fields")
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdbi-driver-sqlite3
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 9
9
- - 0
10
- version: 0.9.0
8
+ - 1
9
+ version: 0.9.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Erik Hollensbe
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-08-21 00:00:00 -04:00
17
+ date: 2010-12-10 00:00:00 -05:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,7 +38,6 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 3
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
@@ -54,7 +51,6 @@ dependencies:
54
51
  requirements:
55
52
  - - ">="
56
53
  - !ruby/object:Gem::Version
57
- hash: 3
58
54
  segments:
59
55
  - 0
60
56
  version: "0"
@@ -66,14 +62,12 @@ dependencies:
66
62
  requirement: &id004 !ruby/object:Gem::Requirement
67
63
  none: false
68
64
  requirements:
69
- - - "="
65
+ - - ~>
70
66
  - !ruby/object:Gem::Version
71
- hash: 25
72
67
  segments:
73
68
  - 1
74
69
  - 3
75
- - 1
76
- version: 1.3.1
70
+ version: "1.3"
77
71
  type: :runtime
78
72
  version_requirements: *id004
79
73
  - !ruby/object:Gem::Dependency
@@ -84,7 +78,6 @@ dependencies:
84
78
  requirements:
85
79
  - - ">="
86
80
  - !ruby/object:Gem::Version
87
- hash: 3
88
81
  segments:
89
82
  - 0
90
83
  version: "0"
@@ -98,7 +91,6 @@ dependencies:
98
91
  requirements:
99
92
  - - ">="
100
93
  - !ruby/object:Gem::Version
101
- hash: 17
102
94
  segments:
103
95
  - 0
104
96
  - 3
@@ -117,11 +109,11 @@ extra_rdoc_files:
117
109
  - README.rdoc
118
110
  files:
119
111
  - .document
120
- - .gitignore
121
112
  - LICENSE
122
113
  - README.rdoc
123
114
  - Rakefile
124
115
  - VERSION
116
+ - lib/rdbi-driver-sqlite3.rb
125
117
  - lib/rdbi/driver/sqlite3.rb
126
118
  - rdbi-driver-sqlite3.gemspec
127
119
  - test/helper.rb
@@ -131,8 +123,8 @@ homepage: http://github.com/RDBI/rdbi-driver-sqlite3
131
123
  licenses: []
132
124
 
133
125
  post_install_message:
134
- rdoc_options:
135
- - --charset=UTF-8
126
+ rdoc_options: []
127
+
136
128
  require_paths:
137
129
  - lib
138
130
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -140,7 +132,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
132
  requirements:
141
133
  - - ">="
142
134
  - !ruby/object:Gem::Version
143
- hash: 3
144
135
  segments:
145
136
  - 0
146
137
  version: "0"
@@ -149,7 +140,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
140
  requirements:
150
141
  - - ">="
151
142
  - !ruby/object:Gem::Version
152
- hash: 3
153
143
  segments:
154
144
  - 0
155
145
  version: "0"
data/.gitignore DELETED
@@ -1,24 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
- doc
21
- .yardoc
22
- rdbi-dbd-sqlite3.gemspec
23
-
24
- ## PROJECT::SPECIFIC