sequel 5.51.0 → 5.52.0

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +28 -0
  3. data/README.rdoc +5 -0
  4. data/doc/opening_databases.rdoc +1 -1
  5. data/doc/release_notes/5.52.0.txt +87 -0
  6. data/doc/testing.rdoc +3 -1
  7. data/lib/sequel/adapters/amalgalite.rb +3 -5
  8. data/lib/sequel/adapters/jdbc.rb +7 -9
  9. data/lib/sequel/adapters/mysql.rb +80 -67
  10. data/lib/sequel/adapters/mysql2.rb +41 -43
  11. data/lib/sequel/adapters/postgres.rb +17 -21
  12. data/lib/sequel/adapters/shared/mysql.rb +3 -2
  13. data/lib/sequel/adapters/shared/postgres.rb +2 -2
  14. data/lib/sequel/adapters/sqlite.rb +16 -18
  15. data/lib/sequel/connection_pool/sharded_single.rb +5 -7
  16. data/lib/sequel/connection_pool/single.rb +6 -8
  17. data/lib/sequel/core.rb +17 -18
  18. data/lib/sequel/database/query.rb +1 -1
  19. data/lib/sequel/extensions/core_refinements.rb +36 -11
  20. data/lib/sequel/extensions/date_parse_input_handler.rb +67 -0
  21. data/lib/sequel/extensions/datetime_parse_to_time.rb +5 -1
  22. data/lib/sequel/extensions/pg_array_ops.rb +1 -1
  23. data/lib/sequel/extensions/pg_hstore_ops.rb +1 -1
  24. data/lib/sequel/extensions/pg_inet_ops.rb +1 -1
  25. data/lib/sequel/extensions/pg_interval.rb +1 -0
  26. data/lib/sequel/extensions/pg_json.rb +3 -5
  27. data/lib/sequel/extensions/pg_json_ops.rb +1 -1
  28. data/lib/sequel/extensions/pg_range_ops.rb +1 -1
  29. data/lib/sequel/extensions/pg_row_ops.rb +1 -1
  30. data/lib/sequel/extensions/s.rb +2 -1
  31. data/lib/sequel/extensions/server_block.rb +8 -12
  32. data/lib/sequel/extensions/sql_comments.rb +108 -3
  33. data/lib/sequel/extensions/string_date_time.rb +19 -23
  34. data/lib/sequel/model/base.rb +8 -12
  35. data/lib/sequel/plugins/sql_comments.rb +189 -0
  36. data/lib/sequel/plugins/subclasses.rb +28 -11
  37. data/lib/sequel/plugins/unused_associations.rb +2 -2
  38. data/lib/sequel/timezones.rb +12 -14
  39. data/lib/sequel/version.rb +1 -1
  40. metadata +7 -3
@@ -24,15 +24,13 @@ class Sequel::SingleConnectionPool < Sequel::ConnectionPool
24
24
 
25
25
  # Yield the connection to the block.
26
26
  def hold(server=nil)
27
- begin
28
- unless c = @conn.first
29
- @conn.replace([c = make_new(:default)])
30
- end
31
- yield c
32
- rescue Sequel::DatabaseDisconnectError, *@error_classes => e
33
- disconnect if disconnect_error?(e)
34
- raise
27
+ unless c = @conn.first
28
+ @conn.replace([c = make_new(:default)])
35
29
  end
30
+ yield c
31
+ rescue Sequel::DatabaseDisconnectError, *@error_classes => e
32
+ disconnect if disconnect_error?(e)
33
+ raise
36
34
  end
37
35
 
38
36
  # The SingleConnectionPool always has a maximum size of 1.
data/lib/sequel/core.rb CHANGED
@@ -278,11 +278,9 @@ module Sequel
278
278
  #
279
279
  # Sequel.string_to_date('2010-09-10') # Date.civil(2010, 09, 10)
280
280
  def string_to_date(string)
281
- begin
282
- Date.parse(string, Sequel.convert_two_digit_years)
283
- rescue => e
284
- raise convert_exception_class(e, InvalidValue)
285
- end
281
+ Date.parse(string, Sequel.convert_two_digit_years)
282
+ rescue => e
283
+ raise convert_exception_class(e, InvalidValue)
286
284
  end
287
285
 
288
286
  # Converts the given +string+ into a +Time+ or +DateTime+ object, depending on the
@@ -290,15 +288,13 @@ module Sequel
290
288
  #
291
289
  # Sequel.string_to_datetime('2010-09-10 10:20:30') # Time.local(2010, 09, 10, 10, 20, 30)
292
290
  def string_to_datetime(string)
293
- begin
294
- if datetime_class == DateTime
295
- DateTime.parse(string, convert_two_digit_years)
296
- else
297
- datetime_class.parse(string)
298
- end
299
- rescue => e
300
- raise convert_exception_class(e, InvalidValue)
291
+ if datetime_class == DateTime
292
+ DateTime.parse(string, convert_two_digit_years)
293
+ else
294
+ datetime_class.parse(string)
301
295
  end
296
+ rescue => e
297
+ raise convert_exception_class(e, InvalidValue)
302
298
  end
303
299
 
304
300
  # Converts the given +string+ into a <tt>Sequel::SQLTime</tt> object.
@@ -306,11 +302,9 @@ module Sequel
306
302
  # v = Sequel.string_to_time('10:20:30') # Sequel::SQLTime.parse('10:20:30')
307
303
  # DB.literal(v) # => '10:20:30'
308
304
  def string_to_time(string)
309
- begin
310
- SQLTime.parse(string)
311
- rescue => e
312
- raise convert_exception_class(e, InvalidValue)
313
- end
305
+ SQLTime.parse(string)
306
+ rescue => e
307
+ raise convert_exception_class(e, InvalidValue)
314
308
  end
315
309
 
316
310
  # Unless in single threaded mode, protects access to any mutable
@@ -400,6 +394,11 @@ module Sequel
400
394
 
401
395
  private
402
396
 
397
+ # Return a hash of date information parsed from the given string.
398
+ def _date_parse(string)
399
+ Date._parse(string)
400
+ end
401
+
403
402
  # Helper method that the database adapter class methods that are added to Sequel via
404
403
  # metaprogramming use to parse arguments.
405
404
  def adapter_method(adapter, *args, &block)
@@ -236,7 +236,7 @@ module Sequel
236
236
  when :date
237
237
  Sequel.string_to_date(default)
238
238
  when :datetime
239
- DateTime.parse(default)
239
+ Sequel.string_to_datetime(default)
240
240
  when :time
241
241
  Sequel.string_to_time(default)
242
242
  when :decimal
@@ -15,6 +15,12 @@ raise(Sequel::Error, "Refinements require ruby 2.0.0 or greater") unless RUBY_VE
15
15
  # :nocov:
16
16
 
17
17
  module Sequel::CoreRefinements
18
+ # :nocov:
19
+ include_meth = RUBY_VERSION >= '3.1' ? :import_methods : :include
20
+ # :nocov:
21
+ INCLUDE_METH = include_meth
22
+ private_constant :INCLUDE_METH
23
+
18
24
  refine Array do
19
25
  # Return a <tt>Sequel::SQL::BooleanExpression</tt> created from this array, not matching all of the
20
26
  # conditions.
@@ -161,8 +167,8 @@ module Sequel::CoreRefinements
161
167
  end
162
168
 
163
169
  refine String do
164
- include Sequel::SQL::AliasMethods
165
- include Sequel::SQL::CastMethods
170
+ send include_meth, Sequel::SQL::AliasMethods
171
+ send include_meth, Sequel::SQL::CastMethods
166
172
 
167
173
  # Converts a string into a <tt>Sequel::LiteralString</tt>, in order to override string
168
174
  # literalization, e.g.:
@@ -189,15 +195,34 @@ module Sequel::CoreRefinements
189
195
  end
190
196
 
191
197
  refine Symbol do
192
- include Sequel::SQL::AliasMethods
193
- include Sequel::SQL::CastMethods
194
- include Sequel::SQL::OrderMethods
195
- include Sequel::SQL::BooleanMethods
196
- include Sequel::SQL::NumericMethods
197
- include Sequel::SQL::QualifyingMethods
198
- include Sequel::SQL::StringMethods
199
- include Sequel::SQL::SubscriptMethods
200
- include Sequel::SQL::ComplexExpressionMethods
198
+ send include_meth, Sequel::SQL::AliasMethods
199
+ send include_meth, Sequel::SQL::CastMethods
200
+ send include_meth, Sequel::SQL::OrderMethods
201
+ send include_meth, Sequel::SQL::BooleanMethods
202
+ send include_meth, Sequel::SQL::NumericMethods
203
+
204
+ # :nocov:
205
+ remove_method :* if RUBY_VERSION >= '3.1'
206
+ # :nocov:
207
+
208
+ send include_meth, Sequel::SQL::QualifyingMethods
209
+ send include_meth, Sequel::SQL::StringMethods
210
+ send include_meth, Sequel::SQL::SubscriptMethods
211
+ send include_meth, Sequel::SQL::ComplexExpressionMethods
212
+
213
+ # :nocov:
214
+ if RUBY_VERSION >= '3.1'
215
+ remove_method :*
216
+ def *(ce=(arg=false;nil))
217
+ if arg == false
218
+ Sequel::SQL::ColumnAll.new(self)
219
+ else
220
+ Sequel::SQL::NumericExpression.new(:*, self, ce)
221
+ end
222
+ end
223
+
224
+ end
225
+ # :nocov:
201
226
 
202
227
  # Returns receiver wrapped in an <tt>Sequel::SQL::Identifier</tt>.
203
228
  #
@@ -0,0 +1,67 @@
1
+ # frozen-string-literal: true
2
+ #
3
+ # The date_parse_input_handler extension allows for configuring how input
4
+ # to date parsing methods should be handled. By default, the
5
+ # extension does not change behavior. However, you can use the
6
+ # +Sequel.date_parse_input_handler+ method to support custom handling
7
+ # of input strings to the date parsing methods. For example, if you want
8
+ # to implement a length check to prevent denial of service vulnerabilities
9
+ # in older versions of Ruby, you can do:
10
+ #
11
+ # Sequel.extension :date_parse_input_handler
12
+ # Sequel.date_parse_input_handler do |string|
13
+ # raise Sequel::InvalidValue, "string length (200) exceeds the limit 128" if string.bytesize > 128
14
+ # string
15
+ # end
16
+ #
17
+ # You can also use +Sequel.date_parse_input_handler+ to modify the string
18
+ # that will be passed to the parsing methods. For example, you could
19
+ # truncate it:
20
+ #
21
+ # Sequel.date_parse_input_handler do |string|
22
+ # string.b[0, 128]
23
+ # end
24
+ #
25
+ # Be aware that modern versions of Ruby will raise an exception if
26
+ # date parsing input exceeds 128 bytes.
27
+
28
+ module Sequel
29
+ module DateParseInputHandler
30
+ def date_parse_input_handler(&block)
31
+ singleton_class.class_eval do
32
+ define_method(:handle_date_parse_input, &block)
33
+ private :handle_date_parse_input
34
+ alias handle_date_parse_input handle_date_parse_input
35
+ end
36
+ end
37
+
38
+ # Call date parse input handler with input string.
39
+ def string_to_date(string)
40
+ super(handle_date_parse_input(string))
41
+ end
42
+
43
+ # Call date parse input handler with input string.
44
+ def string_to_datetime(string)
45
+ super(handle_date_parse_input(string))
46
+ end
47
+
48
+ # Call date parse input handler with input string.
49
+ def string_to_time(string)
50
+ super(handle_date_parse_input(string))
51
+ end
52
+
53
+ private
54
+
55
+ # Call date parse input handler with input string.
56
+ def _date_parse(string)
57
+ super(handle_date_parse_input(string))
58
+ end
59
+
60
+ # Return string as-is by default, so by default behavior does not change.
61
+ def handle_date_parse_input(string)
62
+ string
63
+ end
64
+ end
65
+
66
+ extend DateParseInputHandler
67
+ end
@@ -19,7 +19,11 @@ module Sequel::DateTimeParseToTime
19
19
  # Use DateTime.parse.to_time to do the conversion if the input a string and is assumed to
20
20
  # be in UTC and there is no offset information in the string.
21
21
  def convert_input_timestamp(v, input_timezone)
22
- if v.is_a?(String) && datetime_class == Time && input_timezone == :utc && !Date._parse(v).has_key?(:offset)
22
+ if v.is_a?(String) && datetime_class == Time && input_timezone == :utc && !_date_parse(v).has_key?(:offset)
23
+ # :nocov:
24
+ # Whether this is fully branch covered depends on the order in which the specs are run.
25
+ v = handle_date_parse_input(v) if respond_to?(:handle_date_parse_input, true)
26
+ # :nocov:
23
27
  t = DateTime.parse(v).to_time
24
28
  case application_timezone
25
29
  when nil, :local
@@ -329,7 +329,7 @@ end
329
329
  if defined?(Sequel::CoreRefinements)
330
330
  module Sequel::CoreRefinements
331
331
  refine Symbol do
332
- include Sequel::Postgres::ArrayOpMethods
332
+ send INCLUDE_METH, Sequel::Postgres::ArrayOpMethods
333
333
  end
334
334
  end
335
335
  end
@@ -406,7 +406,7 @@ end
406
406
  if defined?(Sequel::CoreRefinements)
407
407
  module Sequel::CoreRefinements
408
408
  refine Symbol do
409
- include Sequel::Postgres::HStoreOpMethods
409
+ send INCLUDE_METH, Sequel::Postgres::HStoreOpMethods
410
410
  end
411
411
  end
412
412
  end
@@ -197,7 +197,7 @@ end
197
197
  if defined?(Sequel::CoreRefinements)
198
198
  module Sequel::CoreRefinements
199
199
  refine Symbol do
200
- include Sequel::Postgres::InetOpMethods
200
+ send INCLUDE_METH, Sequel::Postgres::InetOpMethods
201
201
  end
202
202
  end
203
203
  end
@@ -32,6 +32,7 @@
32
32
  #
33
33
  # Related module: Sequel::Postgres::IntervalDatabaseMethods
34
34
 
35
+ require 'active_support'
35
36
  require 'active_support/duration'
36
37
 
37
38
  # :nocov:
@@ -387,11 +387,9 @@ module Sequel
387
387
  # argument is true), or a String, Numeric, true, false, or nil
388
388
  # if the json library used supports that.
389
389
  def _parse_json(s)
390
- begin
391
- Sequel.parse_json(s)
392
- rescue Sequel.json_parser_error_class => e
393
- raise Sequel.convert_exception_class(e, Sequel::InvalidValue)
394
- end
390
+ Sequel.parse_json(s)
391
+ rescue Sequel.json_parser_error_class => e
392
+ raise Sequel.convert_exception_class(e, Sequel::InvalidValue)
395
393
  end
396
394
 
397
395
  # Wrap the parsed JSON value in the appropriate JSON wrapper class.
@@ -744,7 +744,7 @@ end
744
744
  if defined?(Sequel::CoreRefinements)
745
745
  module Sequel::CoreRefinements
746
746
  refine Symbol do
747
- include Sequel::Postgres::JSONOpMethods
747
+ send INCLUDE_METH, Sequel::Postgres::JSONOpMethods
748
748
  end
749
749
  end
750
750
  end
@@ -188,7 +188,7 @@ end
188
188
  if defined?(Sequel::CoreRefinements)
189
189
  module Sequel::CoreRefinements
190
190
  refine Symbol do
191
- include Sequel::Postgres::RangeOpMethods
191
+ send INCLUDE_METH, Sequel::Postgres::RangeOpMethods
192
192
  end
193
193
  end
194
194
  end
@@ -210,7 +210,7 @@ end
210
210
  if defined?(Sequel::CoreRefinements)
211
211
  module Sequel::CoreRefinements
212
212
  refine Symbol do
213
- include Sequel::Postgres::PGRowOp::ExpressionMethods
213
+ send INCLUDE_METH, Sequel::Postgres::PGRowOp::ExpressionMethods
214
214
  end
215
215
  end
216
216
  end
@@ -51,9 +51,10 @@ module Sequel::S
51
51
 
52
52
  # :nocov:
53
53
  if RUBY_VERSION >= '2.0.0'
54
+ include_meth = RUBY_VERSION >= '3.1' ? :import_methods : :include
54
55
  # :nocov:
55
56
  refine Object do
56
- include Sequel::S
57
+ send include_meth, Sequel::S
57
58
  end
58
59
  end
59
60
  end
@@ -88,12 +88,10 @@ module Sequel
88
88
  module UnthreadedServerBlock
89
89
  # Set a default server/shard to use inside the block.
90
90
  def with_server(default_server, read_only_server=default_server)
91
- begin
92
- set_default_server(default_server, read_only_server)
93
- yield
94
- ensure
95
- clear_default_server
96
- end
91
+ set_default_server(default_server, read_only_server)
92
+ yield
93
+ ensure
94
+ clear_default_server
97
95
  end
98
96
 
99
97
  private
@@ -131,12 +129,10 @@ module Sequel
131
129
  # Set a default server/shard to use inside the block for the current
132
130
  # thread.
133
131
  def with_server(default_server, read_only_server=default_server)
134
- begin
135
- set_default_server(default_server, read_only_server)
136
- yield
137
- ensure
138
- clear_default_server
139
- end
132
+ set_default_server(default_server, read_only_server)
133
+ yield
134
+ ensure
135
+ clear_default_server
140
136
  end
141
137
 
142
138
  private
@@ -44,11 +44,51 @@
44
44
  #
45
45
  # DB.extension(:sql_comments)
46
46
  #
47
+ # Loading the sql_comments extension into the database also adds
48
+ # support for block-level comment support via Database#with_comments.
49
+ # You call #with_comments with a hash. Queries inside the hash will
50
+ # include a comment based on the hash (assuming they are inside the
51
+ # same thread):
52
+ #
53
+ # DB.with_comments(model: Album, action: :all) do
54
+ # DB[:albums].all
55
+ # # SELECT * FROM albums -- model:Album,action:all
56
+ # end
57
+ #
58
+ # You can nest calls to #with_comments, which will combine the
59
+ # entries from both calls:
60
+ #
61
+ # DB.with_comments(application: App, path: :scrubbed_path) do
62
+ # DB.with_comments(model: Album, action: :all) do
63
+ # ds = DB[:albums].all
64
+ # # SELECT * FROM albums
65
+ # # -- application:App,path:scrubbed_path,model:Album,action:all
66
+ # end
67
+ # end
68
+ #
69
+ # You can override comment entries specified in earlier blocks, or
70
+ # remove entries specified earlier using a nil value:
71
+ #
72
+ # DB.with_comments(application: App, path: :scrubbed_path) do
73
+ # DB.with_comments(application: Foo, path: nil) do
74
+ # ds = DB[:albums].all
75
+ # # SELECT * FROM albums # -- application:Foo
76
+ # end
77
+ # end
78
+ #
79
+ # You can combine block-level comments with dataset-specific
80
+ # comments:
81
+ #
82
+ # DB.with_comments(model: Album, action: :all) do
83
+ # DB[:table].comment("Some Comment").all
84
+ # # SELECT * FROM albums -- model:Album,action:all -- Some Comment
85
+ # end
86
+ #
47
87
  # Note that Microsoft Access does not support inline comments,
48
88
  # and attempting to use comments on it will result in SQL syntax
49
89
  # errors.
50
90
  #
51
- # Related module: Sequel::SQLComments
91
+ # Related modules: Sequel::SQLComments, Sequel::Database::SQLComments
52
92
 
53
93
  #
54
94
  module Sequel
@@ -62,7 +102,7 @@ module Sequel
62
102
  %w'select insert update delete'.each do |type|
63
103
  define_method(:"#{type}_sql") do |*a|
64
104
  sql = super(*a)
65
- if comment = @opts[:comment]
105
+ if comment = _sql_comment
66
106
  # This assumes that the comment stored in the dataset has
67
107
  # already been formatted. If not, this could result in SQL
68
108
  # injection.
@@ -74,8 +114,10 @@ module Sequel
74
114
  if sql.frozen?
75
115
  sql += comment
76
116
  sql.freeze
77
- else
117
+ elsif @opts[:append_sql] || @opts[:placeholder_literalizer]
78
118
  sql << comment
119
+ else
120
+ sql += comment
79
121
  end
80
122
  end
81
123
  sql
@@ -84,6 +126,11 @@ module Sequel
84
126
 
85
127
  private
86
128
 
129
+ # The comment to include in the SQL query, if any.
130
+ def _sql_comment
131
+ @opts[:comment]
132
+ end
133
+
87
134
  # Format the comment. For maximum compatibility, this uses a
88
135
  # single line SQL comment, and converts all consecutive whitespace
89
136
  # in the comment to a single space.
@@ -92,5 +139,63 @@ module Sequel
92
139
  end
93
140
  end
94
141
 
142
+ module Database::SQLComments
143
+ def self.extended(db)
144
+ db.instance_variable_set(:@comment_hashes, {})
145
+ db.extend_datasets DatasetSQLComments
146
+ end
147
+
148
+ # A map of threads to comment hashes, used for correctly setting
149
+ # comments for all queries inside #with_comments blocks.
150
+ attr_reader :comment_hashes
151
+
152
+ # Store the comment hash and use it to create comments inside the block
153
+ def with_comments(comment_hash)
154
+ hashes = @comment_hashes
155
+ t = Sequel.current
156
+ new_hash = if hash = Sequel.synchronize{hashes[t]}
157
+ hash.merge(comment_hash)
158
+ else
159
+ comment_hash.dup
160
+ end
161
+ yield Sequel.synchronize{hashes[t] = new_hash}
162
+ ensure
163
+ if hash
164
+ Sequel.synchronize{hashes[t] = hash}
165
+ else
166
+ t && Sequel.synchronize{hashes.delete(t)}
167
+ end
168
+ end
169
+
170
+ module DatasetSQLComments
171
+ include Sequel::SQLComments
172
+
173
+ # Include comments added via Database#with_comments in the output SQL.
174
+ def _sql_comment
175
+ specific_comment = super
176
+ return specific_comment if @opts[:append_sql]
177
+
178
+ t = Sequel.current
179
+ hashes = db.comment_hashes
180
+ block_comment = if comment_hash = Sequel.synchronize{hashes[t]}
181
+ comment_array = comment_hash.map{|k,v| "#{k}:#{v}" unless v.nil?}
182
+ comment_array.compact!
183
+ comment_array.join(",")
184
+ end
185
+
186
+ if block_comment
187
+ if specific_comment
188
+ format_sql_comment(block_comment + specific_comment)
189
+ else
190
+ format_sql_comment(block_comment)
191
+ end
192
+ else
193
+ specific_comment
194
+ end
195
+ end
196
+ end
197
+ end
198
+
95
199
  Dataset.register_extension(:sql_comments, SQLComments)
200
+ Database.register_extension(:sql_comments, Database::SQLComments)
96
201
  end
@@ -4,6 +4,10 @@
4
4
  # for converting the strings to a date (e.g. String#to_date), allowing
5
5
  # for backwards compatibility with legacy Sequel code.
6
6
  #
7
+ # These methods calls +parse+ on the related class, and as such, can
8
+ # result in denial of service in older versions of Ruby for large
9
+ # untrusted input, and raise exceptions in newer versions of Ruby.
10
+ #
7
11
  # To load the extension:
8
12
  #
9
13
  # Sequel.extension :string_date_time
@@ -11,42 +15,34 @@
11
15
  class String
12
16
  # Converts a string into a Date object.
13
17
  def to_date
14
- begin
15
- Date.parse(self, Sequel.convert_two_digit_years)
16
- rescue => e
17
- raise Sequel.convert_exception_class(e, Sequel::InvalidValue)
18
- end
18
+ Date.parse(self, Sequel.convert_two_digit_years)
19
+ rescue => e
20
+ raise Sequel.convert_exception_class(e, Sequel::InvalidValue)
19
21
  end
20
22
 
21
23
  # Converts a string into a DateTime object.
22
24
  def to_datetime
23
- begin
24
- DateTime.parse(self, Sequel.convert_two_digit_years)
25
- rescue => e
26
- raise Sequel.convert_exception_class(e, Sequel::InvalidValue)
27
- end
25
+ DateTime.parse(self, Sequel.convert_two_digit_years)
26
+ rescue => e
27
+ raise Sequel.convert_exception_class(e, Sequel::InvalidValue)
28
28
  end
29
29
 
30
30
  # Converts a string into a Time or DateTime object, depending on the
31
31
  # value of Sequel.datetime_class
32
32
  def to_sequel_time
33
- begin
34
- if Sequel.datetime_class == DateTime
35
- DateTime.parse(self, Sequel.convert_two_digit_years)
36
- else
37
- Sequel.datetime_class.parse(self)
38
- end
39
- rescue => e
40
- raise Sequel.convert_exception_class(e, Sequel::InvalidValue)
33
+ if Sequel.datetime_class == DateTime
34
+ DateTime.parse(self, Sequel.convert_two_digit_years)
35
+ else
36
+ Sequel.datetime_class.parse(self)
41
37
  end
38
+ rescue => e
39
+ raise Sequel.convert_exception_class(e, Sequel::InvalidValue)
42
40
  end
43
41
 
44
42
  # Converts a string into a Time object.
45
43
  def to_time
46
- begin
47
- Time.parse(self)
48
- rescue => e
49
- raise Sequel.convert_exception_class(e, Sequel::InvalidValue)
50
- end
44
+ Time.parse(self)
45
+ rescue => e
46
+ raise Sequel.convert_exception_class(e, Sequel::InvalidValue)
51
47
  end
52
48
  end
@@ -682,13 +682,11 @@ module Sequel
682
682
 
683
683
  # Yield to the passed block and if do_raise is false, swallow all errors other than DatabaseConnectionErrors.
684
684
  def check_non_connection_error(do_raise=require_valid_table)
685
- begin
686
- db.transaction(:savepoint=>:only){yield}
687
- rescue Sequel::DatabaseConnectionError
688
- raise
689
- rescue Sequel::Error
690
- raise if do_raise
691
- end
685
+ db.transaction(:savepoint=>:only){yield}
686
+ rescue Sequel::DatabaseConnectionError
687
+ raise
688
+ rescue Sequel::Error
689
+ raise if do_raise
692
690
  end
693
691
 
694
692
  # Convert the given object to a Dataset that should be used as
@@ -1630,11 +1628,9 @@ module Sequel
1630
1628
  # artist.set(name: 'Invalid').valid? # => false
1631
1629
  # artist.errors.full_messages # => ['name cannot be Invalid']
1632
1630
  def valid?(opts = OPTS)
1633
- begin
1634
- _valid?(opts)
1635
- rescue HookFailed
1636
- false
1637
- end
1631
+ _valid?(opts)
1632
+ rescue HookFailed
1633
+ false
1638
1634
  end
1639
1635
 
1640
1636
  private