rdbi 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'benchmark'
3
+ require 'sequel'
4
+ require 'rdbi'
5
+ require 'rdbi/driver/sqlite3'
6
+ gem 'activerecord', '= 2.3.8'
7
+ require 'active_record'
8
+ require 'fileutils'
9
+
10
+ include FileUtils
11
+
12
+ %w[rdbi-test.db sequel-test.db ar-test.db].each do |db|
13
+ rm db rescue nil
14
+
15
+ dbh = RDBI.connect(:SQLite3, :database => db)
16
+ dbh.execute("create table foo (i integer)")
17
+ 10_000.times do |x|
18
+ dbh.execute("insert into foo (i) values (?i)", { :i => x })
19
+ end
20
+ dbh.disconnect
21
+ end
22
+
23
+ dbh = RDBI.connect(:SQLite3, :database => "rdbi-test.db")
24
+ dbh.rewindable_result = false
25
+ sql = "select * from foo limit 1"
26
+ db = Sequel.connect('sqlite://sequel-test.db')
27
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "ar-test.db")
28
+ class Foo < ActiveRecord::Base
29
+ set_table_name "foo"
30
+ end
31
+
32
+ puts "Single select"
33
+
34
+ n = 10_000
35
+
36
+ Benchmark.bm do |x|
37
+ x.report("AR") { n.times { Foo.find_by_sql(sql) } }
38
+ x.report("AR connection") { n.times { ActiveRecord::Base.connection.select_one(sql, :cache => false) } }
39
+ x.report("RDBI") { n.times { dbh.execute(sql).first } }
40
+ x.report("Sequel") { n.times { db[sql].first } }
41
+ end
42
+
43
+ puts "Big select"
44
+
45
+ sql = "select * from foo"
46
+
47
+ n = 50
48
+
49
+ Benchmark.bm do |x|
50
+ x.report("AR") { n.times { Foo.find_by_sql(sql) } }
51
+ x.report("AR connection") { n.times { ActiveRecord::Base.connection.select_all(sql, :cache => false) } }
52
+ x.report("RDBI") { n.times { dbh.execute(sql).fetch(:all) } }
53
+ x.report("Sequel") { n.times { db[sql].all } }
54
+ end
55
+
56
+ dbh.disconnect
57
+ db.disconnect
58
+ # wtf does AR use to disconnect anyhow
@@ -0,0 +1,123 @@
1
+ $:.unshift 'lib'
2
+ require 'rubygems'
3
+ require 'rdbi'
4
+ require 'fileutils'
5
+ ENV["driver"] ||= "SQLite3"
6
+ gem "rdbi-driver-#{ENV["driver"].downcase}"
7
+ require "rdbi/driver/#{ENV["driver"].downcase}"
8
+ gem 'perftools.rb'
9
+ require 'perftools'
10
+
11
+ FileUtils.rm 'test.db' rescue nil
12
+
13
+ dbh = nil
14
+
15
+ if ENV["driver"] == "SQLite3"
16
+ dbh = RDBI.connect(:SQLite3, :database => "test.db")
17
+ else
18
+ require 'rdbi-dbrc'
19
+ dbh = RDBI::DBRC.connect("#{ENV["driver"]}_test")
20
+ end
21
+
22
+ dbh.execute("drop table foo") rescue nil
23
+ dbh.execute("create table foo (i integer)")
24
+
25
+ case ARGV[0]
26
+ when "prepared_insert"
27
+ FileUtils.rm '/tmp/rdbi_prepared_insert' rescue nil
28
+ PerfTools::CpuProfiler.start("/tmp/rdbi_prepared_insert") do
29
+ sth = dbh.prepare("insert into foo (i) values (?)")
30
+ 10_000.times do |x|
31
+ sth.execute_modification(x)
32
+ end
33
+ sth.finish
34
+ end
35
+ when "insert"
36
+ FileUtils.rm '/tmp/rdbi_unprepared_insert' rescue nil
37
+ PerfTools::CpuProfiler.start("/tmp/rdbi_unprepared_insert") do
38
+ 10_000.times do |x|
39
+ dbh.execute_modification("insert into foo (i) values (?)")
40
+ end
41
+ end
42
+ when "raw_select"
43
+ sth = dbh.prepare("insert into foo (i) values (?)")
44
+ 10_000.times do |x|
45
+ sth.execute_modification(x)
46
+ end
47
+ sth.finish
48
+
49
+ FileUtils.rm '/tmp/rdbi_raw_select' rescue nil
50
+ PerfTools::CpuProfiler.start("/tmp/rdbi_raw_select") do
51
+ sth = dbh.prepare("select * from foo")
52
+ 100.times do |x|
53
+ sth.execute.raw_fetch(:all)
54
+ end
55
+ sth.finish
56
+ end
57
+ when "res_select"
58
+ sth = dbh.prepare("insert into foo (i) values (?)")
59
+ 10_000.times do |x|
60
+ sth.execute_modification(x)
61
+ end
62
+ sth.finish
63
+
64
+ FileUtils.rm '/tmp/rdbi_res_select' rescue nil
65
+ PerfTools::CpuProfiler.start("/tmp/rdbi_res_select") do
66
+ sth = dbh.prepare("select * from foo")
67
+ 100.times do |x|
68
+ sth.execute.fetch(:all)
69
+ end
70
+ sth.finish
71
+ end
72
+ when "single_fetch"
73
+ dbh.execute("insert into foo (i) values (?)", 1)
74
+
75
+ FileUtils.rm '/tmp/rdbi_single_fetch' rescue nil
76
+ PerfTools::CpuProfiler.start("/tmp/rdbi_single_fetch") do
77
+ sth = dbh.prepare("select * from foo")
78
+ 10_000.times do |x|
79
+ sth.execute.fetch(1)
80
+ end
81
+ sth.finish
82
+ end
83
+ when "unprepared_raw_select"
84
+ sth = dbh.prepare("insert into foo (i) values (?)")
85
+ 10_000.times do |x|
86
+ sth.execute_modification(x)
87
+ end
88
+ sth.finish
89
+
90
+ FileUtils.rm '/tmp/rdbi_unprepared_raw_select' rescue nil
91
+ PerfTools::CpuProfiler.start("/tmp/rdbi_unprepared_raw_select") do
92
+ 100.times do |x|
93
+ dbh.execute("select * from foo").raw_fetch(:all)
94
+ end
95
+ end
96
+ when "unprepared_res_select"
97
+ sth = dbh.prepare("insert into foo (i) values (?)")
98
+ 10_000.times do |x|
99
+ sth.execute_modification(x)
100
+ end
101
+ sth.finish
102
+
103
+ FileUtils.rm '/tmp/rdbi_unprepared_res_select' rescue nil
104
+ PerfTools::CpuProfiler.start("/tmp/rdbi_unprepared_res_select") do
105
+ 100.times do |x|
106
+ dbh.execute("select * from foo").fetch(:all)
107
+ end
108
+ end
109
+ when "unprepared_single_fetch"
110
+ dbh.execute("insert into foo (i) values (?)", 1)
111
+
112
+ FileUtils.rm '/tmp/rdbi_unprepared_single_fetch' rescue nil
113
+ PerfTools::CpuProfiler.start("/tmp/rdbi_unprepared_single_fetch") do
114
+ 10_000.times do |x|
115
+ dbh.execute("select * from foo").fetch(1)
116
+ end
117
+ end
118
+ else
119
+ $stderr.puts "[prepared_insert|insert|raw_select|res_select|single_fetch|unprepared_res_select|unprepared_single_fetch]"
120
+ exit 1
121
+ end
122
+
123
+ dbh.disconnect
@@ -1,63 +1,63 @@
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}
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{RDBI is a rearchitecture of the Ruby/DBI project by its maintainer and others. It intends to fully supplant Ruby/DBI in the future for similar database access needs.}
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
- "docs/external-api.pdf",
27
- "docs/external-api.texi",
28
- "lib/rdbi.rb",
29
- "lib/rdbi/cursor.rb",
30
- "lib/rdbi/database.rb",
31
- "lib/rdbi/driver.rb",
32
- "lib/rdbi/pool.rb",
33
- "lib/rdbi/result.rb",
34
- "lib/rdbi/schema.rb",
35
- "lib/rdbi/statement.rb",
36
- "lib/rdbi/types.rb",
37
- "rdbi.gemspec",
38
- "test/helper.rb",
39
- "test/test_database.rb",
40
- "test/test_pool.rb",
41
- "test/test_rdbi.rb",
42
- "test/test_result.rb",
43
- "test/test_statement.rb",
44
- "test/test_types.rb",
45
- "test/test_util.rb"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "docs/external-api.pdf",
26
+ "docs/external-api.texi",
27
+ "lib/rdbi.rb",
28
+ "lib/rdbi/cursor.rb",
29
+ "lib/rdbi/database.rb",
30
+ "lib/rdbi/driver.rb",
31
+ "lib/rdbi/pool.rb",
32
+ "lib/rdbi/result.rb",
33
+ "lib/rdbi/schema.rb",
34
+ "lib/rdbi/statement.rb",
35
+ "lib/rdbi/types.rb",
36
+ "perf/bench.rb",
37
+ "perf/profile.rb",
38
+ "rdbi.gemspec",
39
+ "test/helper.rb",
40
+ "test/test_database.rb",
41
+ "test/test_pool.rb",
42
+ "test/test_rdbi.rb",
43
+ "test/test_result.rb",
44
+ "test/test_statement.rb",
45
+ "test/test_types.rb",
46
+ "test/test_util.rb"
46
47
  ]
47
48
  s.homepage = %q{http://github.com/RDBI/rdbi}
48
- s.rdoc_options = ["--charset=UTF-8"]
49
49
  s.require_paths = ["lib"]
50
50
  s.rubygems_version = %q{1.3.7}
51
51
  s.summary = %q{RDBI provides sane query-level database access with low magic.}
52
52
  s.test_files = [
53
53
  "test/helper.rb",
54
- "test/test_database.rb",
55
- "test/test_pool.rb",
56
- "test/test_rdbi.rb",
57
- "test/test_result.rb",
58
- "test/test_statement.rb",
59
- "test/test_types.rb",
60
- "test/test_util.rb"
54
+ "test/test_database.rb",
55
+ "test/test_pool.rb",
56
+ "test/test_rdbi.rb",
57
+ "test/test_result.rb",
58
+ "test/test_statement.rb",
59
+ "test/test_types.rb",
60
+ "test/test_util.rb"
61
61
  ]
62
62
 
63
63
  if s.respond_to? :specification_version then
@@ -226,11 +226,12 @@ class TestDatabase < Test::Unit::TestCase
226
226
  sth = @dbh.prepare("some statement")
227
227
  assert(sth)
228
228
 
229
- assert_equal(@dbh.open_statements.length, 1)
229
+ assert_equal(@dbh.open_statements.keys.length, 1)
230
230
 
231
- warn "The next message should appear *exactly once*"
232
231
  @dbh.disconnect
233
232
 
233
+ assert_equal(@dbh.open_statements.keys.length, 0)
234
+
234
235
  @dbh = mock_connect
235
236
  sth = @dbh.prepare("some statement")
236
237
  sth.finish
@@ -81,10 +81,16 @@ class TestPool < Test::Unit::TestCase
81
81
  end
82
82
  end
83
83
 
84
- def test_06_ping
84
+ def test_06_ping_and_up
85
85
  pool = create_pool(:test_06)
86
86
  4.times { pool.add_connection }
87
87
  assert_equal(10, pool.ping)
88
+
89
+ assert(pool.up)
90
+
91
+ pool.handles[0].disconnect
92
+
93
+ assert(!pool.up)
88
94
  end
89
95
 
90
96
  def test_07_resize
@@ -63,23 +63,6 @@ class TestRDBI < Test::Unit::TestCase
63
63
  dbh = RDBI.connect_cached(:Mock, :username => :foo, :pool_name => :test_05)
64
64
  assert_equal(RDBI.pool(:test_05).handles[0], dbh)
65
65
  end
66
-
67
- def test_06_re_disconnect_all
68
- RDBI.disconnect_all
69
- connected_size = RDBI.all_connections.select(&:connected).size
70
- assert_equal(0, connected_size)
71
-
72
- total_size = RDBI.all_connections.size
73
- RDBI.reconnect_all
74
- connected_size = RDBI.all_connections.select(&:connected).size
75
- assert_equal(connected_size, total_size)
76
- end
77
-
78
- def test_07_all_connections
79
- total_size = RDBI.all_connections.size
80
- mock_connect
81
- assert_equal(RDBI.all_connections.size, total_size + 1)
82
- end
83
66
  end
84
67
 
85
68
  # vim: syntax=ruby ts=2 et sw=2 sts=2
@@ -108,6 +108,8 @@ class TestResult < Test::Unit::TestCase
108
108
 
109
109
  assert_equal(generate_data[0], res.fetch(:first))
110
110
  assert_equal(generate_data[-1], res.fetch(:last))
111
+ assert_equal(generate_data[0], res.first)
112
+ assert_equal(generate_data[-1], res.last)
111
113
 
112
114
  res.sth.finish
113
115
  end
@@ -164,10 +166,8 @@ class TestResult < Test::Unit::TestCase
164
166
  # XXX reset intentionally.
165
167
  res.as(:Array)
166
168
  assert_equal([[-1, 0, 1]], res.fetch(1))
167
-
168
169
  res.sth.finish
169
- res.rewind
170
-
170
+
171
171
  assert_equal(
172
172
  "-1,0,1\n",
173
173
  res.fetch(1, RDBI::Result::Driver::CSV)
@@ -264,6 +264,41 @@ class TestResult < Test::Unit::TestCase
264
264
  assert_equal([], res.fetch(1))
265
265
  res.sth.finish
266
266
  end
267
+
268
+ def test_11_rewindable_results
269
+ @dbh.rewindable_result = true
270
+ res = RDBI::Result.new(@dbh.prepare("foo"), [1], RDBI::Driver::Mock::Cursor.new([]), [], 0)
271
+
272
+ res.sth.rewindable_result = false
273
+ assert_raises(StandardError) { res.rewind }
274
+ res.sth.rewindable_result = true
275
+ res.reload
276
+ res.rewind
277
+ end
278
+
279
+ def test_12_as_yaml
280
+ res = mock_result
281
+ require 'yaml'
282
+
283
+ assert_equal(
284
+ [
285
+ {:zero=>-1, :one=>0, :two=>1},
286
+ {:zero=>0, :one=>1, :two=>2},
287
+ {:zero=>1, :one=>2, :two=>3},
288
+ {:zero=>2, :one=>3, :two=>4},
289
+ {:zero=>3, :one=>4, :two=>5},
290
+ {:zero=>4, :one=>5, :two=>6},
291
+ {:zero=>5, :one=>6, :two=>7},
292
+ {:zero=>6, :one=>7, :two=>8},
293
+ {:zero=>7, :one=>8, :two=>9},
294
+ {:zero=>8, :one=>9, :two=>10}
295
+ ],
296
+ YAML.load(res.as(:YAML).fetch(:all))
297
+ )
298
+
299
+ assert_equal({:zero=>-1, :one=>0, :two=>1}, YAML.load(res.as(:YAML).first))
300
+ assert_equal({:zero=>8, :one=>9, :two=>10}, YAML.load(res.as(:YAML).last))
301
+ end
267
302
  end
268
303
 
269
304
  # vim: syntax=ruby ts=2 et sw=2 sts=2
@@ -23,7 +23,6 @@ class TestStatement < Test::Unit::TestCase
23
23
  def test_02_accessors
24
24
  sth = dbh.new_statement("some query")
25
25
  assert(sth)
26
- assert_kind_of(Mutex, sth.mutex)
27
26
  assert(!sth.finished?)
28
27
  assert(!sth.finished)
29
28
  sth.finish
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdbi
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"
@@ -68,7 +64,6 @@ dependencies:
68
64
  requirements:
69
65
  - - ">="
70
66
  - !ruby/object:Gem::Version
71
- hash: 3
72
67
  segments:
73
68
  - 0
74
69
  version: "0"
@@ -82,7 +77,6 @@ dependencies:
82
77
  requirements:
83
78
  - - ">="
84
79
  - !ruby/object:Gem::Version
85
- hash: 13
86
80
  segments:
87
81
  - 0
88
82
  - 0
@@ -98,7 +92,6 @@ dependencies:
98
92
  requirements:
99
93
  - - ">="
100
94
  - !ruby/object:Gem::Version
101
- hash: 17
102
95
  segments:
103
96
  - 0
104
97
  - 3
@@ -114,7 +107,6 @@ dependencies:
114
107
  requirements:
115
108
  - - ">="
116
109
  - !ruby/object:Gem::Version
117
- hash: 3
118
110
  segments:
119
111
  - 0
120
112
  version: "0"
@@ -131,7 +123,6 @@ extra_rdoc_files:
131
123
  - README.rdoc
132
124
  files:
133
125
  - .document
134
- - .gitignore
135
126
  - LICENSE
136
127
  - README.rdoc
137
128
  - Rakefile
@@ -147,6 +138,8 @@ files:
147
138
  - lib/rdbi/schema.rb
148
139
  - lib/rdbi/statement.rb
149
140
  - lib/rdbi/types.rb
141
+ - perf/bench.rb
142
+ - perf/profile.rb
150
143
  - rdbi.gemspec
151
144
  - test/helper.rb
152
145
  - test/test_database.rb
@@ -161,8 +154,8 @@ homepage: http://github.com/RDBI/rdbi
161
154
  licenses: []
162
155
 
163
156
  post_install_message:
164
- rdoc_options:
165
- - --charset=UTF-8
157
+ rdoc_options: []
158
+
166
159
  require_paths:
167
160
  - lib
168
161
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -170,7 +163,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
163
  requirements:
171
164
  - - ">="
172
165
  - !ruby/object:Gem::Version
173
- hash: 3
174
166
  segments:
175
167
  - 0
176
168
  version: "0"
@@ -179,7 +171,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
171
  requirements:
180
172
  - - ">="
181
173
  - !ruby/object:Gem::Version
182
- hash: 3
183
174
  segments:
184
175
  - 0
185
176
  version: "0"