data_objects 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.10.3 2011-01-30
2
+ * Reworked transactions
3
+ * Fix a DST bug that could cause datetimes in the wrong timezone
4
+
1
5
  ## 0.10.2 2010-05-19
2
6
  * Support for Encoding.default_internal
3
7
  * Rework logging to adding a callback is possible
@@ -8,4 +8,4 @@ module DataObjects
8
8
  end
9
9
 
10
10
  end
11
- end
11
+ end
@@ -0,0 +1,19 @@
1
+ shared 'raising a SQLError' do
2
+
3
+ setup_test_environment
4
+
5
+ before do
6
+ @connection = DataObjects::Connection.new(CONFIG.uri)
7
+ @invalid_query = @connection.create_command("SLCT * FROM widgets WHERE ad_description = ? order by id")
8
+ @invalid_result = @connection.create_command("SELECT MAX((SELECT 1 UNION SELECT 2))")
9
+ end
10
+
11
+ it 'should raise an error on an invalid query' do
12
+ should.raise(DataObjects::SQLError) { @invalid_query.execute_reader('Buy this product now!') }
13
+ end
14
+
15
+ it 'should raise on an invalid result set' do
16
+ should.raise(DataObjects::SQLError) { @invalid_result.execute_reader }
17
+ end
18
+
19
+ end
@@ -18,10 +18,14 @@ shared 'a Reader' do
18
18
 
19
19
  describe 'fields' do
20
20
 
21
+ def array_case_insensitively_equal_to(arr)
22
+ lambda { |obj| obj.map { |f| f.downcase } == arr }
23
+ end
24
+
21
25
  it 'should return the correct fields in the reader' do
22
26
  # we downcase the field names as some drivers such as do_derby, do_h2,
23
- # do_hsqldb return the field names as uppercase
24
- @reader.fields.map{ |f| f.downcase }.should == ['code', 'name']
27
+ # do_hsqldb, do_oracle return the field names as uppercase
28
+ @reader.fields.should.be array_case_insensitively_equal_to(['code', 'name'])
25
29
  end
26
30
 
27
31
  end
@@ -63,6 +63,32 @@ shared 'supporting DateTime' do
63
63
 
64
64
  end
65
65
 
66
+ describe 'with manual typecasting a datetime column' do
67
+
68
+ before do
69
+ @command = @connection.create_command("SELECT release_datetime FROM widgets WHERE id = ? OR id = ? ORDER BY id")
70
+ @command.set_types(DateTime)
71
+ @reader = @command.execute_reader(1, 10)
72
+ @reader.next!
73
+ @feb_row = @reader.values
74
+ @reader.next!
75
+ @jul_row = @reader.values
76
+ end
77
+
78
+ after do
79
+ @reader.close
80
+ end
81
+
82
+ it 'should return the correct offset in Feb' do
83
+ (@feb_row.first.offset * 86400).to_i.should == Time.local(2008, 2, 14, 0, 31, 12).utc_offset
84
+ end
85
+
86
+ it 'should return the correct offset in Jul' do
87
+ (@jul_row.first.offset * 86400).to_i.should == Time.local(2008, 7, 14, 0, 31, 12).utc_offset
88
+ end
89
+
90
+ end
91
+
66
92
  end
67
93
 
68
94
  describe 'writing an DateTime' do
@@ -79,4 +79,23 @@ shared 'supporting Integer' do
79
79
 
80
80
  end
81
81
 
82
+ describe 'writing a big Integer' do
83
+
84
+ before do
85
+ @connection.create_command("UPDATE widgets SET super_number = ? WHERE id = 10").execute_non_query(2147483648) # bigger than Integer.MAX in java !!
86
+ @reader = @connection.create_command("SELECT super_number FROM widgets WHERE id = ?").execute_reader(10)
87
+ @reader.next!
88
+ @values = @reader.values
89
+ end
90
+
91
+ after do
92
+ @reader.close
93
+ end
94
+
95
+ it 'should return the correct entry' do
96
+ @values.first.should == 2147483648
97
+ end
98
+
99
+ end
100
+
82
101
  end
@@ -1,3 +1,4 @@
1
+ require 'socket'
1
2
  require 'digest'
2
3
  require 'digest/sha2'
3
4
 
@@ -23,9 +24,10 @@ module DataObjects
23
24
  #
24
25
  # Creates a Transaction bound to a connection for the given DataObjects::URI
25
26
  #
26
- def initialize(uri)
27
- @connection = DataObjects::Connection.new(uri)
28
- @id = Digest::SHA256.hexdigest("#{HOST}:#{$$}:#{Time.now.to_f}:#{@@counter += 1}")
27
+ def initialize(uri, connection = nil)
28
+ @connection = connection || DataObjects::Connection.new(uri)
29
+ # PostgreSQL can't handle the full 64 bytes. This should be enough for everyone.
30
+ @id = Digest::SHA256.hexdigest("#{HOST}:#{$$}:#{Time.now.to_f}:#{@@counter += 1}")[0..-2]
29
31
  end
30
32
 
31
33
  # Close the connection for this Transaction
@@ -34,18 +36,15 @@ module DataObjects
34
36
  end
35
37
 
36
38
  def begin
37
- cmd = "BEGIN"
38
- connection.create_command(cmd).execute_non_query
39
+ run "BEGIN"
39
40
  end
40
41
 
41
42
  def commit
42
- cmd = "COMMIT"
43
- connection.create_command(cmd).execute_non_query
43
+ run "COMMIT"
44
44
  end
45
45
 
46
46
  def rollback
47
- cmd = "ROLLBACK"
48
- connection.create_command(cmd).execute_non_query
47
+ run "ROLLBACK"
49
48
  end
50
49
 
51
50
  def prepare; not_implemented; end;
@@ -54,9 +53,36 @@ module DataObjects
54
53
  def rollback_prepared; not_implemented; end;
55
54
  def prepare; not_implemented; end;
56
55
 
56
+ protected
57
+ def run(cmd)
58
+ connection.create_command(cmd).execute_non_query
59
+ end
60
+
57
61
  private
58
62
  def not_implemented
59
63
  raise NotImplementedError
60
64
  end
61
- end
65
+ end # class Transaction
66
+
67
+ class SavePoint < Transaction
68
+ # We don't bounce through DO::<Adapter/scheme>::SavePoint because there
69
+ # doesn't appear to be any custom SQL to support this.
70
+ def self.create_for_uri(uri, connection)
71
+ uri = uri.is_a?(String) ? URI::parse(uri) : uri
72
+ DataObjects::SavePoint.new(uri, connection)
73
+ end
74
+
75
+ def begin
76
+ run %{SAVEPOINT "#{@id}"}
77
+ end
78
+
79
+ def commit
80
+ run %{RELEASE SAVEPOINT "#{@id}"}
81
+ end
82
+
83
+ def rollback
84
+ run %{ROLLBACK TO SAVEPOINT "#{@id}"}
85
+ end
86
+ end # class SavePoint
87
+
62
88
  end
@@ -1,3 +1,3 @@
1
1
  module DataObjects
2
- VERSION = '0.10.2'
2
+ VERSION = '0.10.3'
3
3
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_objects
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 49
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 10
8
- - 2
9
- version: 0.10.2
9
+ - 3
10
+ version: 0.10.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - Dirkjan Bussink
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-19 00:00:00 +02:00
18
+ date: 2011-01-30 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: addressable
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ~>
26
28
  - !ruby/object:Gem::Version
29
+ hash: 1
27
30
  segments:
28
31
  - 2
29
32
  - 1
@@ -34,9 +37,11 @@ dependencies:
34
37
  name: bacon
35
38
  prerelease: false
36
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
37
41
  requirements:
38
42
  - - ~>
39
43
  - !ruby/object:Gem::Version
44
+ hash: 13
40
45
  segments:
41
46
  - 1
42
47
  - 1
@@ -47,9 +52,11 @@ dependencies:
47
52
  name: mocha
48
53
  prerelease: false
49
54
  requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
50
56
  requirements:
51
57
  - - ~>
52
58
  - !ruby/object:Gem::Version
59
+ hash: 25
53
60
  segments:
54
61
  - 0
55
62
  - 9
@@ -60,9 +67,11 @@ dependencies:
60
67
  name: yard
61
68
  prerelease: false
62
69
  requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
63
71
  requirements:
64
72
  - - ~>
65
73
  - !ruby/object:Gem::Version
74
+ hash: 1
66
75
  segments:
67
76
  - 0
68
77
  - 5
@@ -103,6 +112,7 @@ files:
103
112
  - lib/data_objects/spec/command_spec.rb
104
113
  - lib/data_objects/spec/connection_spec.rb
105
114
  - lib/data_objects/spec/encoding_spec.rb
115
+ - lib/data_objects/spec/error/sql_error_spec.rb
106
116
  - lib/data_objects/spec/helpers/immediate_red_green_output.rb
107
117
  - lib/data_objects/spec/helpers/pending.rb
108
118
  - lib/data_objects/spec/helpers/ssl.rb
@@ -153,23 +163,27 @@ rdoc_options:
153
163
  require_paths:
154
164
  - lib
155
165
  required_ruby_version: !ruby/object:Gem::Requirement
166
+ none: false
156
167
  requirements:
157
168
  - - ">="
158
169
  - !ruby/object:Gem::Version
170
+ hash: 3
159
171
  segments:
160
172
  - 0
161
173
  version: "0"
162
174
  required_rubygems_version: !ruby/object:Gem::Requirement
175
+ none: false
163
176
  requirements:
164
177
  - - ">="
165
178
  - !ruby/object:Gem::Version
179
+ hash: 3
166
180
  segments:
167
181
  - 0
168
182
  version: "0"
169
183
  requirements: []
170
184
 
171
185
  rubyforge_project: dorb
172
- rubygems_version: 1.3.6
186
+ rubygems_version: 1.3.7
173
187
  signing_key:
174
188
  specification_version: 3
175
189
  summary: DataObjects basic API and shared driver specifications