data_objects 0.10.1 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.markdown +6 -2
- data/lib/data_objects/connection.rb +11 -0
- data/lib/data_objects/extension.rb +11 -0
- data/lib/data_objects/logger.rb +14 -0
- data/lib/data_objects/spec/connection_spec.rb +1 -1
- data/lib/data_objects/spec/encoding_spec.rb +74 -10
- data/lib/data_objects/spec/reader_spec.rb +19 -1
- data/lib/data_objects/spec/result_spec.rb +28 -1
- data/lib/data_objects/spec/typecast/boolean_spec.rb +24 -0
- data/lib/data_objects/spec/typecast/other_spec.rb +3 -3
- data/lib/data_objects/version.rb +1 -1
- data/lib/data_objects.rb +1 -0
- metadata +41 -21
data/ChangeLog.markdown
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
-
## 0.10.
|
1
|
+
## 0.10.2 2010-05-19
|
2
|
+
* Support for Encoding.default_internal
|
3
|
+
* Rework logging to adding a callback is possible
|
4
|
+
|
5
|
+
## 0.10.1 2010-01-08
|
2
6
|
|
3
7
|
* Removal of Extlib dependency: Pooling and Utilities code moved to DataObjects.
|
4
8
|
* Switch to Jeweler for Gem building tasks (this change may be temporary).
|
5
9
|
* Switch to using Bacon for running specs: This should make specs friendlier to
|
6
10
|
new Ruby implementations that are not yet 100% MRI-compatible, and in turn,
|
7
|
-
|
11
|
+
pave the road for our own IronRuby and MacRuby support.
|
8
12
|
* Make DataObjects::Reader Enumerable.
|
9
13
|
|
10
14
|
## 0.10.0 2009-09-15
|
@@ -7,6 +7,8 @@ module DataObjects
|
|
7
7
|
# An abstract connection to a DataObjects resource. The physical connection may be broken and re-established from time to time.
|
8
8
|
class Connection
|
9
9
|
|
10
|
+
include Logging
|
11
|
+
|
10
12
|
# Make a connection to the database using the DataObjects::URI given.
|
11
13
|
# Note that the physical connection may be delayed until the first command is issued, so success here doesn't necessarily mean you can connect.
|
12
14
|
def self.new(uri_s)
|
@@ -116,7 +118,16 @@ module DataObjects
|
|
116
118
|
concrete_command.new(self, text)
|
117
119
|
end
|
118
120
|
|
121
|
+
def extension
|
122
|
+
driver_namespace.const_get('Extension').new(self)
|
123
|
+
end
|
124
|
+
|
119
125
|
private
|
126
|
+
|
127
|
+
def driver_namespace
|
128
|
+
DataObjects::const_get(self.class.name.split('::')[-2])
|
129
|
+
end
|
130
|
+
|
120
131
|
def concrete_command
|
121
132
|
@concrete_command || begin
|
122
133
|
|
data/lib/data_objects/logger.rb
CHANGED
@@ -2,6 +2,18 @@ require "time" # httpdate
|
|
2
2
|
|
3
3
|
module DataObjects
|
4
4
|
|
5
|
+
module Logging
|
6
|
+
|
7
|
+
def log(message)
|
8
|
+
logger = driver_namespace.logger
|
9
|
+
if logger.level <= DataObjects::Logger::LEVELS[:debug]
|
10
|
+
message = "(%.6f) %s" % [message.duration / 1000000.0, message.query]
|
11
|
+
logger.debug message
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
5
17
|
class << self
|
6
18
|
# The global logger for DataObjects
|
7
19
|
attr_accessor :logger
|
@@ -51,6 +63,8 @@ module DataObjects
|
|
51
63
|
# The name of the log file
|
52
64
|
attr_reader :log
|
53
65
|
|
66
|
+
Message = Struct.new(:query, :start, :duration)
|
67
|
+
|
54
68
|
#
|
55
69
|
# Ruby (standard) logger levels:
|
56
70
|
# off: absolutely nothing
|
@@ -8,7 +8,6 @@ shared 'a driver supporting different encodings' do
|
|
8
8
|
@connection.close
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
11
|
it 'should respond to #character_set' do @connection.should.respond_to(:character_set) end
|
13
12
|
|
14
13
|
describe 'character_set' do
|
@@ -44,25 +43,88 @@ shared 'a driver supporting different encodings' do
|
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
|
-
shared 'returning correctly encoded strings for the default encoding' do
|
46
|
+
shared 'returning correctly encoded strings for the default database encoding' do
|
48
47
|
|
48
|
+
if defined?(::Encoding)
|
49
49
|
|
50
|
-
|
50
|
+
setup_test_environment
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
before do
|
53
|
+
@connection.close if @connection
|
54
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
57
|
+
after do
|
58
|
+
@connection.close
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'with encoded string support' do
|
62
|
+
|
63
|
+
describe 'reading a String' do
|
64
|
+
before do
|
65
|
+
@reader = @connection.create_command("SELECT name, whitepaper_text FROM widgets WHERE ad_description = ?").execute_reader('Buy this product now!')
|
66
|
+
@reader.next!
|
67
|
+
@values = @reader.values
|
68
|
+
end
|
69
|
+
|
70
|
+
after do
|
71
|
+
@reader.close
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should return UTF-8 encoded String' do
|
75
|
+
@values.first.should.be.kind_of(String)
|
76
|
+
@values.first.encoding.name.should == 'UTF-8'
|
77
|
+
@values.last.should.be.kind_of(String)
|
78
|
+
@values.last.encoding.name.should == 'UTF-8'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'reading a ByteArray' do
|
83
|
+
before do
|
84
|
+
@command = @connection.create_command("SELECT ad_image FROM widgets WHERE ad_description = ?")
|
85
|
+
@command.set_types(Extlib::ByteArray)
|
86
|
+
@reader = @command.execute_reader('Buy this product now!')
|
87
|
+
@reader.next!
|
88
|
+
@values = @reader.values
|
89
|
+
end
|
90
|
+
|
91
|
+
after do
|
92
|
+
@reader.close
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should return ASCII-8BIT encoded ByteArray' do
|
96
|
+
@values.first.should.be.kind_of(::Extlib::ByteArray)
|
97
|
+
@values.first.encoding.name.should == 'ASCII-8BIT'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
58
101
|
end
|
59
102
|
|
103
|
+
end
|
104
|
+
|
105
|
+
shared 'returning correctly encoded strings for the default internal encoding' do
|
106
|
+
|
60
107
|
if defined?(::Encoding)
|
108
|
+
|
109
|
+
setup_test_environment
|
110
|
+
|
111
|
+
before do
|
112
|
+
@connection.close if @connection
|
113
|
+
@encoding_before = Encoding.default_internal
|
114
|
+
Encoding.default_internal = 'ISO-8859-1'
|
115
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
116
|
+
end
|
117
|
+
|
118
|
+
after do
|
119
|
+
@connection.close
|
120
|
+
Encoding.default_internal = @encoding_before
|
121
|
+
end
|
122
|
+
|
61
123
|
describe 'with encoded string support' do
|
62
124
|
|
63
125
|
describe 'reading a String' do
|
64
126
|
before do
|
65
|
-
@reader = @connection.create_command("SELECT name FROM widgets WHERE ad_description = ?").execute_reader('Buy this product now!')
|
127
|
+
@reader = @connection.create_command("SELECT name, whitepaper_text FROM widgets WHERE ad_description = ?").execute_reader('Buy this product now!')
|
66
128
|
@reader.next!
|
67
129
|
@values = @reader.values
|
68
130
|
end
|
@@ -73,7 +135,9 @@ shared 'returning correctly encoded strings for the default encoding' do
|
|
73
135
|
|
74
136
|
it 'should return UTF-8 encoded String' do
|
75
137
|
@values.first.should.be.kind_of(String)
|
76
|
-
@values.first.encoding.name.should == '
|
138
|
+
@values.first.encoding.name.should == 'ISO-8859-1'
|
139
|
+
@values.last.should.be.kind_of(String)
|
140
|
+
@values.last.encoding.name.should == 'ISO-8859-1'
|
77
141
|
end
|
78
142
|
end
|
79
143
|
|
@@ -5,10 +5,12 @@ shared 'a Reader' do
|
|
5
5
|
before do
|
6
6
|
@connection = DataObjects::Connection.new(CONFIG.uri)
|
7
7
|
@reader = @connection.create_command("SELECT code, name FROM widgets WHERE ad_description = ? order by id").execute_reader('Buy this product now!')
|
8
|
+
@reader2 = @connection.create_command("SELECT code FROM widgets WHERE ad_description = ? order by id").execute_reader('Buy this product now!')
|
8
9
|
end
|
9
10
|
|
10
11
|
after do
|
11
12
|
@reader.close
|
13
|
+
@reader2.close
|
12
14
|
@connection.close
|
13
15
|
end
|
14
16
|
|
@@ -153,7 +155,7 @@ shared 'a Reader' do
|
|
153
155
|
|
154
156
|
describe 'each' do
|
155
157
|
|
156
|
-
it 'should yield each row to the block' do
|
158
|
+
it 'should yield each row to the block for multiple columns' do
|
157
159
|
rows_yielded = 0
|
158
160
|
@reader.each do |row|
|
159
161
|
row.should.respond_to(:[])
|
@@ -170,6 +172,22 @@ shared 'a Reader' do
|
|
170
172
|
rows_yielded.should == 15
|
171
173
|
end
|
172
174
|
|
175
|
+
it 'should yield each row to the block for a single column' do
|
176
|
+
rows_yielded = 0
|
177
|
+
@reader2.each do |row|
|
178
|
+
row.should.respond_to(:[])
|
179
|
+
|
180
|
+
row.size.should == 1
|
181
|
+
|
182
|
+
# the field names need to be case insensitive as some drivers such as
|
183
|
+
# do_derby, do_h2, do_hsqldb return the field names as uppercase
|
184
|
+
(row['code'] || row['CODE']).should.be.kind_of(String)
|
185
|
+
|
186
|
+
rows_yielded += 1
|
187
|
+
end
|
188
|
+
rows_yielded.should == 15
|
189
|
+
end
|
190
|
+
|
173
191
|
it 'should return the reader' do
|
174
192
|
@reader.each { |row| }.should.equal(@reader)
|
175
193
|
end
|
@@ -23,7 +23,7 @@ shared 'a Result' do
|
|
23
23
|
|
24
24
|
end
|
25
25
|
|
26
|
-
shared 'a Result which returns inserted
|
26
|
+
shared 'a Result which returns inserted key with sequences' do
|
27
27
|
|
28
28
|
before do
|
29
29
|
setup_test_environment
|
@@ -50,3 +50,30 @@ shared 'a Result which returns inserted keys' do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
end
|
53
|
+
|
54
|
+
shared 'a Result which returns nil without sequences' do
|
55
|
+
|
56
|
+
before do
|
57
|
+
setup_test_environment
|
58
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
59
|
+
command = @connection.create_command("INSERT INTO invoices (invoice_number) VALUES (?)")
|
60
|
+
# execute the command twice and expose the second result
|
61
|
+
@result = command.execute_non_query("monkey")
|
62
|
+
end
|
63
|
+
|
64
|
+
after do
|
65
|
+
@connection.close
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should respond to #affected_rows' do @result.should.respond_to(:affected_rows) end
|
69
|
+
|
70
|
+
describe 'insert_id' do
|
71
|
+
|
72
|
+
it 'should return the insert_id' do
|
73
|
+
# This is actually the 2nd record inserted
|
74
|
+
@result.insert_id.should.be.nil
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -36,6 +36,30 @@ shared 'supporting Boolean' do
|
|
36
36
|
|
37
37
|
end
|
38
38
|
|
39
|
+
describe 'with manual typecasting a true value' do
|
40
|
+
|
41
|
+
before do
|
42
|
+
@command = @connection.create_command("SELECT flags FROM widgets WHERE id = ?")
|
43
|
+
@command.set_types(TrueClass)
|
44
|
+
@reader = @command.execute_reader(2)
|
45
|
+
@reader.next!
|
46
|
+
@values = @reader.values
|
47
|
+
end
|
48
|
+
|
49
|
+
after do
|
50
|
+
@reader.close
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should return the correctly typed result' do
|
54
|
+
@values.first.should.be.kind_of(TrueClass)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should return the correct result' do
|
58
|
+
@values.first.should.be.true
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
39
63
|
describe 'with manual typecasting a nil value' do
|
40
64
|
|
41
65
|
before do
|
@@ -25,9 +25,9 @@ shared 'supporting other (unknown) type' do
|
|
25
25
|
describe 'writing an object of unknown type' do
|
26
26
|
|
27
27
|
before do
|
28
|
-
@command = @connection.create_command("SELECT
|
28
|
+
@command = @connection.create_command("SELECT ad_description FROM widgets WHERE ad_description = ?")
|
29
29
|
@command.set_types(::CustomTextType)
|
30
|
-
@reader = @command.execute_reader('
|
30
|
+
@reader = @command.execute_reader('Buy this product now!')
|
31
31
|
@reader.next!
|
32
32
|
@values = @reader.values
|
33
33
|
end
|
@@ -37,7 +37,7 @@ shared 'supporting other (unknown) type' do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'should return the correct entry' do
|
40
|
-
@values.first.should == '
|
40
|
+
@values.first.should == 'Buy this product now!'
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
data/lib/data_objects/version.rb
CHANGED
data/lib/data_objects.rb
CHANGED
@@ -10,6 +10,7 @@ require 'data_objects/command'
|
|
10
10
|
require 'data_objects/result'
|
11
11
|
require 'data_objects/reader'
|
12
12
|
require 'data_objects/quoting'
|
13
|
+
require 'data_objects/extension'
|
13
14
|
require 'data_objects/error'
|
14
15
|
require 'data_objects/error/sql_error'
|
15
16
|
require 'data_objects/error/connection_error'
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 10
|
8
|
+
- 2
|
9
|
+
version: 0.10.2
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Dirkjan Bussink
|
@@ -9,49 +14,61 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-05-19 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: addressable
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ~>
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 1
|
23
30
|
version: "2.1"
|
24
|
-
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
25
33
|
- !ruby/object:Gem::Dependency
|
26
34
|
name: bacon
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
37
|
requirements:
|
31
38
|
- - ~>
|
32
39
|
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 1
|
42
|
+
- 1
|
33
43
|
version: "1.1"
|
34
|
-
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
35
46
|
- !ruby/object:Gem::Dependency
|
36
47
|
name: mocha
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
42
52
|
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
- 9
|
43
56
|
version: "0.9"
|
44
|
-
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id003
|
45
59
|
- !ruby/object:Gem::Dependency
|
46
60
|
name: yard
|
47
|
-
|
48
|
-
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
63
|
requirements:
|
51
64
|
- - ~>
|
52
65
|
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
- 5
|
53
69
|
version: "0.5"
|
54
|
-
|
70
|
+
type: :development
|
71
|
+
version_requirements: *id004
|
55
72
|
description: Provide a standard and simplified API for communicating with RDBMS from Ruby
|
56
73
|
email: d.bussink@gmail.com
|
57
74
|
executables: []
|
@@ -76,6 +93,7 @@ files:
|
|
76
93
|
- lib/data_objects/error/sql_error.rb
|
77
94
|
- lib/data_objects/error/syntax_error.rb
|
78
95
|
- lib/data_objects/error/transaction_error.rb
|
96
|
+
- lib/data_objects/extension.rb
|
79
97
|
- lib/data_objects/logger.rb
|
80
98
|
- lib/data_objects/pooling.rb
|
81
99
|
- lib/data_objects/quoting.rb
|
@@ -138,18 +156,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
156
|
requirements:
|
139
157
|
- - ">="
|
140
158
|
- !ruby/object:Gem::Version
|
159
|
+
segments:
|
160
|
+
- 0
|
141
161
|
version: "0"
|
142
|
-
version:
|
143
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
163
|
requirements:
|
145
164
|
- - ">="
|
146
165
|
- !ruby/object:Gem::Version
|
166
|
+
segments:
|
167
|
+
- 0
|
147
168
|
version: "0"
|
148
|
-
version:
|
149
169
|
requirements: []
|
150
170
|
|
151
171
|
rubyforge_project: dorb
|
152
|
-
rubygems_version: 1.3.
|
172
|
+
rubygems_version: 1.3.6
|
153
173
|
signing_key:
|
154
174
|
specification_version: 3
|
155
175
|
summary: DataObjects basic API and shared driver specifications
|