sequel 3.42.0 → 3.43.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +40 -0
- data/MIT-LICENSE +1 -1
- data/Rakefile +1 -1
- data/doc/opening_databases.rdoc +2 -2
- data/doc/prepared_statements.rdoc +7 -0
- data/doc/release_notes/3.43.0.txt +105 -0
- data/doc/schema_modification.rdoc +19 -0
- data/lib/sequel/adapters/do/mysql.rb +1 -1
- data/lib/sequel/adapters/jdbc.rb +13 -8
- data/lib/sequel/adapters/jdbc/hsqldb.rb +5 -0
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +6 -0
- data/lib/sequel/adapters/jdbc/postgresql.rb +9 -3
- data/lib/sequel/adapters/mysql.rb +1 -1
- data/lib/sequel/adapters/mysql2.rb +1 -1
- data/lib/sequel/adapters/oracle.rb +1 -1
- data/lib/sequel/adapters/postgres.rb +4 -2
- data/lib/sequel/adapters/shared/db2.rb +12 -0
- data/lib/sequel/adapters/shared/mssql.rb +9 -5
- data/lib/sequel/adapters/shared/postgres.rb +2 -0
- data/lib/sequel/adapters/swift/mysql.rb +1 -1
- data/lib/sequel/core.rb +2 -2
- data/lib/sequel/database.rb +0 -2
- data/lib/sequel/database/query.rb +20 -5
- data/lib/sequel/database/schema_generator.rb +5 -0
- data/lib/sequel/database/schema_methods.rb +5 -0
- data/lib/sequel/dataset.rb +0 -2
- data/lib/sequel/dataset/actions.rb +25 -2
- data/lib/sequel/dataset/misc.rb +1 -1
- data/lib/sequel/dataset/sql.rb +28 -6
- data/lib/sequel/extensions/core_refinements.rb +221 -0
- data/lib/sequel/extensions/date_arithmetic.rb +194 -0
- data/lib/sequel/extensions/meta_def.rb +30 -0
- data/lib/sequel/extensions/migration.rb +5 -0
- data/lib/sequel/extensions/null_dataset.rb +2 -0
- data/lib/sequel/extensions/pagination.rb +2 -0
- data/lib/sequel/extensions/pg_array.rb +12 -1
- data/lib/sequel/extensions/pg_array_ops.rb +10 -1
- data/lib/sequel/extensions/pg_hstore.rb +12 -1
- data/lib/sequel/extensions/pg_hstore_ops.rb +10 -1
- data/lib/sequel/extensions/pg_json.rb +18 -1
- data/lib/sequel/extensions/pg_range.rb +12 -1
- data/lib/sequel/extensions/pg_range_ops.rb +10 -1
- data/lib/sequel/extensions/pg_row.rb +18 -2
- data/lib/sequel/extensions/pg_row_ops.rb +10 -1
- data/lib/sequel/extensions/query.rb +2 -0
- data/lib/sequel/model/associations.rb +5 -13
- data/lib/sequel/model/base.rb +4 -6
- data/lib/sequel/plugins/boolean_readers.rb +4 -2
- data/lib/sequel/plugins/many_through_many.rb +23 -0
- data/lib/sequel/plugins/string_stripper.rb +53 -3
- data/lib/sequel/plugins/validation_class_methods.rb +5 -0
- data/lib/sequel/sql.rb +3 -3
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +19 -8
- data/spec/adapters/mssql_spec.rb +1 -2
- data/spec/adapters/mysql_spec.rb +2 -2
- data/spec/adapters/postgres_spec.rb +29 -3
- data/spec/core/dataset_spec.rb +107 -0
- data/spec/core/expression_filters_spec.rb +5 -0
- data/spec/core/schema_spec.rb +14 -3
- data/spec/core/spec_helper.rb +2 -0
- data/spec/extensions/core_refinements_spec.rb +551 -0
- data/spec/extensions/date_arithmetic_spec.rb +150 -0
- data/spec/extensions/force_encoding_spec.rb +1 -1
- data/spec/extensions/meta_def_spec.rb +21 -0
- data/spec/extensions/spec_helper.rb +5 -0
- data/spec/extensions/string_stripper_spec.rb +44 -2
- data/spec/integration/associations_test.rb +2 -2
- data/spec/integration/plugin_test.rb +90 -0
- data/spec/integration/schema_test.rb +1 -1
- data/spec/model/association_reflection_spec.rb +4 -4
- data/spec/model/associations_spec.rb +2 -2
- data/spec/model/base_spec.rb +2 -2
- data/spec/model/eager_loading_spec.rb +5 -5
- data/spec/model/hooks_spec.rb +4 -4
- data/spec/model/model_spec.rb +9 -9
- data/spec/model/record_spec.rb +15 -18
- metadata +12 -5
- data/lib/sequel/metaprogramming.rb +0 -13
data/CHANGELOG
CHANGED
@@ -1,3 +1,43 @@
|
|
1
|
+
=== 3.43.0 (2013-01-08)
|
2
|
+
|
3
|
+
* Move the #meta_def support for Database, Dataset, and Model to the meta_def extension (jeremyevans)
|
4
|
+
|
5
|
+
* Fix Database#copy_into on jdbc/postgres when an exception is raised (jeremyevans)
|
6
|
+
|
7
|
+
* Add core_refinements extension, providing refinement versions of Sequel's core extensions (jeremyevans)
|
8
|
+
|
9
|
+
* Make Database#copy_into raise a DatabaseError if the database signals an error in the postgres adapter (jeremyevans)
|
10
|
+
|
11
|
+
* Define respond_to_missing? where method_missing is defined and the object supports respond_to? (jeremyevans)
|
12
|
+
|
13
|
+
* Allow lambda procs with 0 arity as virtual row blocks on ruby 1.9 (jeremyevans)
|
14
|
+
|
15
|
+
* Handle schema-qualified row_types in the pg_array integration in the pg_row extension (jeremyevans) (#595)
|
16
|
+
|
17
|
+
* Support default_schema when reseting primary key sequences on PostgreSQL (jeremyevans) (#596)
|
18
|
+
|
19
|
+
* Allow treating tinyint(1) unsigned columns as booleans in the mysql adapters (jeremyevans)
|
20
|
+
|
21
|
+
* Support the jdbc-hsqldb gem in the jdbc adapter, since it has been updated to 2.2.9 (jeremyevans)
|
22
|
+
|
23
|
+
* Work with new jdbc-* gems that require manual driver loading (kares) (#598)
|
24
|
+
|
25
|
+
* Cast blobs correctly on DB2 when use_clob_as_blob is false (mluu, jeremyevans) (#594)
|
26
|
+
|
27
|
+
* Add date_arithmetic extension for database-independent date calculations (jeremyevans)
|
28
|
+
|
29
|
+
* Make Database#schema handle [host.]database.schema.table qualified tables on Microsoft SQL Server (jeremyevans)
|
30
|
+
|
31
|
+
* Add Dataset#split_qualifiers helper method for splitting a qualifier identifier into array of strings (jeremyevans)
|
32
|
+
|
33
|
+
* Make Database#schema_and_table always return strings for the schema and table (jeremyevans)
|
34
|
+
|
35
|
+
* Skip stripping of blob columns in the string_stripper plugin (jeremyevans) (#593)
|
36
|
+
|
37
|
+
* Allow Dataset#get to take an array to return multiple values, similar to map/select_map (jeremyevans)
|
38
|
+
|
39
|
+
* Default :prefetch_rows to 100 in the Oracle adapter (andrewhr) (#592)
|
40
|
+
|
1
41
|
=== 3.42.0 (2012-12-03)
|
2
42
|
|
3
43
|
* If an exception occurs while committing a transaction, attempt to rollback (jeremyevans)
|
data/MIT-LICENSE
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Copyright (c) 2007-2008 Sharon Rosner
|
2
|
-
Copyright (c) 2008-
|
2
|
+
Copyright (c) 2008-2013 Jeremy Evans
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
of this software and associated documentation files (the "Software"), to
|
data/Rakefile
CHANGED
data/doc/opening_databases.rdoc
CHANGED
@@ -338,8 +338,8 @@ The following additional options are supported:
|
|
338
338
|
|
339
339
|
:autosequence :: Set to true to use Sequel's conventions to guess the sequence to use for datasets. False
|
340
340
|
by default.
|
341
|
-
:prefetch_rows :: The number of rows to prefetch. Defaults to
|
342
|
-
and
|
341
|
+
:prefetch_rows :: The number of rows to prefetch. Defaults to 100, a larger number can be specified
|
342
|
+
and may improve performance when retrieving a large number of rows.
|
343
343
|
:privilege :: The Oracle privilege level.
|
344
344
|
|
345
345
|
=== postgres
|
@@ -75,6 +75,13 @@ and update queries, the hash to insert/update is passed to +prepare+:
|
|
75
75
|
ps2.call(:n=>'Jim', :new_n=>'Bob')
|
76
76
|
DB.call(:update_name, :n=>'Jim', :new_n=>'Bob') # same as above
|
77
77
|
|
78
|
+
== Implementation Issues
|
79
|
+
|
80
|
+
Currently, creating a prepared statement uses Object#extend, which can hurt
|
81
|
+
performance. For high performance applications, it's recommended to create
|
82
|
+
all of your prepared statements upon application initialization, and not
|
83
|
+
to create prepared statements dynamically at runtime.
|
84
|
+
|
78
85
|
== Database support
|
79
86
|
|
80
87
|
=== PostgreSQL
|
@@ -0,0 +1,105 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* A core_refinements extension has been added, which offers
|
4
|
+
refinement versions of Sequel's core extensions. This requires
|
5
|
+
the new experimental refinement support added in ruby 2.0, and
|
6
|
+
allows you to use the Sequel DSL methods in a file without
|
7
|
+
actually modifying the Symbol, String, Array, and Hash classes.
|
8
|
+
|
9
|
+
* A date_arithmetic extension has been added for performing
|
10
|
+
database-independent date calculations (adding/subtracting an
|
11
|
+
interval to/from a date):
|
12
|
+
|
13
|
+
Sequel.extension :date_arithmetic
|
14
|
+
e = Sequel.date_add(:date_column, :years=>1, :months=>2, :days=>3)
|
15
|
+
DB[:table].where(e > Sequel::CURRENT_DATE)
|
16
|
+
|
17
|
+
In addition to providing the interval as a hash, you can also
|
18
|
+
provide it as an ActiveSupport::Duration object. This extension
|
19
|
+
is supported on 11 database types.
|
20
|
+
|
21
|
+
* Dataset#get can now take an array of multiple expressions to get
|
22
|
+
an array of values, similar to map/select_map:
|
23
|
+
|
24
|
+
value1, value2 = DB[:table].get([:column1, :column2])
|
25
|
+
|
26
|
+
* Sequel can now handle [host.]database.schema.table qualified
|
27
|
+
tables on Microsoft SQL Server. To implement this support,
|
28
|
+
the split_qualifiers method has been added to Database and
|
29
|
+
Dataset for taking a possibly qualified identifier and splitting
|
30
|
+
it into an array of identifier strings.
|
31
|
+
|
32
|
+
* The string_stripper plugin now offers the ability to manually
|
33
|
+
specify which columns to skip stripping for via
|
34
|
+
Model.skip_string_stripping.
|
35
|
+
|
36
|
+
= Other Improvements
|
37
|
+
|
38
|
+
* The jdbc adapter now works with the new jdbc-* gems, which require
|
39
|
+
a manual load_driver step that the older jdbc-* gems did not
|
40
|
+
require.
|
41
|
+
|
42
|
+
* The string_stripper plugin no longer strips blob columns or values.
|
43
|
+
|
44
|
+
* Database#copy_into in both the postgres and jdbc/postgres adapters
|
45
|
+
has been fixed to better handle exceptions.
|
46
|
+
|
47
|
+
* Dataset#hash and Model#hash are now significantly faster.
|
48
|
+
|
49
|
+
* Lambda procs with 0 arity can now be used as virtual row blocks
|
50
|
+
on ruby 1.9. Previously, attempting to use a lambda proc with
|
51
|
+
0 arity as a virtual row block on ruby 1.9 would raise an exception.
|
52
|
+
|
53
|
+
* Schema-qualified composite types are now handled correctly in
|
54
|
+
the pg_row extension.
|
55
|
+
|
56
|
+
* Database#reset_primary_key_sequence on PostgreSQL now works
|
57
|
+
correctly when a default_schema is set.
|
58
|
+
|
59
|
+
* tinyint(1) unsigned columns on MySQL are now parsed as booleans
|
60
|
+
instead of integers on MySQL if converting tinyint to boolean.
|
61
|
+
|
62
|
+
* The jdbc adapter now supports the jdbc-hsqldb gem, so you can
|
63
|
+
now install that instead of having to require the .jar manually.
|
64
|
+
|
65
|
+
* Blobs are now casted correctly on DB2 when the use_clob_as_blob
|
66
|
+
setting is false.
|
67
|
+
|
68
|
+
* Oracle timestamptz types are now handled correctly in the
|
69
|
+
jdbc/oracle adapter.
|
70
|
+
|
71
|
+
* Sequel now defaults to :prefetch_rows = 100 in the oracle
|
72
|
+
adapter, which can significantly improve performance.
|
73
|
+
|
74
|
+
* Sequel now defines respond_to_missing? where method_missing? is
|
75
|
+
defined and the object also responds to respond_to?.
|
76
|
+
|
77
|
+
* Sequel::BasicObject now responds to instance_exec on ruby 1.8.
|
78
|
+
|
79
|
+
= Backwards Compatibility
|
80
|
+
|
81
|
+
* The meta_def method that was defined on Database, Dataset, and
|
82
|
+
Model classes and instances has been moved to an extension named
|
83
|
+
meta_def, and is no longer loaded by default. This method was
|
84
|
+
previously used internally, and it wasn't designed for external
|
85
|
+
use. If you have code that uses meta_def, you should now load the
|
86
|
+
extension manually:
|
87
|
+
|
88
|
+
Sequel.extension :meta_def
|
89
|
+
|
90
|
+
* The private _*_dataset_helper model association methods are no
|
91
|
+
longer defined. The AssociationReflection#dataset_helper_method
|
92
|
+
public method is also no longer defined.
|
93
|
+
|
94
|
+
* Dataset#schema_and_table now always returns strings (or nil).
|
95
|
+
Before, in some cases it would return symbols.
|
96
|
+
|
97
|
+
* Using a conditions specifier array with Dataset#get no longer
|
98
|
+
works due to the new multiple values support in Database#get.
|
99
|
+
So code such as:
|
100
|
+
|
101
|
+
DB[:table].get([[:a, 1], [:b, 2]])
|
102
|
+
|
103
|
+
should be changed to:
|
104
|
+
|
105
|
+
DB[:table].get(Sequel.expr([[:a, 1], [:b, 2]]))
|
@@ -162,6 +162,25 @@ column, but create a foreign key constraint:
|
|
162
162
|
foreign_key [:artist_name, :artist_location], :artists
|
163
163
|
end
|
164
164
|
|
165
|
+
When using an array of symbols, you can also provide a :name option to name the constraint:
|
166
|
+
|
167
|
+
create_table(:albums) do
|
168
|
+
String :artist_name
|
169
|
+
String :artist_location
|
170
|
+
String :name
|
171
|
+
foreign_key [:artist_name, :artist_location], :artists, :name=>'albums_artist_name_location_fkey'
|
172
|
+
end
|
173
|
+
|
174
|
+
If you want to add a foreign key for a single column with a named constraint, you must use
|
175
|
+
the array form with a single symbol:
|
176
|
+
|
177
|
+
create_table(:albums) do
|
178
|
+
primary_key :id
|
179
|
+
Integer :artist_id
|
180
|
+
String :name
|
181
|
+
foreign_key [:artist_id], :artists, :name=>'albums_artist_id_fkey'
|
182
|
+
end
|
183
|
+
|
165
184
|
==== +index+
|
166
185
|
|
167
186
|
+index+ creates indexes on the table. For single columns, calling index is the same as using the
|
@@ -20,7 +20,7 @@ module Sequel
|
|
20
20
|
|
21
21
|
# Recognize the tinyint(1) column as boolean.
|
22
22
|
def schema_column_type(db_type)
|
23
|
-
db_type
|
23
|
+
db_type =~ /\Atinyint\(1\)/ ? :boolean : super
|
24
24
|
end
|
25
25
|
|
26
26
|
# Apply the connectiong setting SQLs for every new connection.
|
data/lib/sequel/adapters/jdbc.rb
CHANGED
@@ -33,14 +33,14 @@ module Sequel
|
|
33
33
|
Sequel.ts_require 'adapters/jdbc/postgresql'
|
34
34
|
db.extend(Sequel::JDBC::Postgres::DatabaseMethods)
|
35
35
|
db.dataset_class = Sequel::JDBC::Postgres::Dataset
|
36
|
-
JDBC.load_gem(
|
36
|
+
JDBC.load_gem(:Postgres)
|
37
37
|
org.postgresql.Driver
|
38
38
|
end,
|
39
39
|
:mysql=>proc do |db|
|
40
40
|
Sequel.ts_require 'adapters/jdbc/mysql'
|
41
41
|
db.extend(Sequel::JDBC::MySQL::DatabaseMethods)
|
42
42
|
db.extend_datasets Sequel::MySQL::DatasetMethods
|
43
|
-
JDBC.load_gem(
|
43
|
+
JDBC.load_gem(:MySQL)
|
44
44
|
com.mysql.jdbc.Driver
|
45
45
|
end,
|
46
46
|
:sqlite=>proc do |db|
|
@@ -48,7 +48,7 @@ module Sequel
|
|
48
48
|
db.extend(Sequel::JDBC::SQLite::DatabaseMethods)
|
49
49
|
db.extend_datasets Sequel::SQLite::DatasetMethods
|
50
50
|
db.set_integer_booleans
|
51
|
-
JDBC.load_gem(
|
51
|
+
JDBC.load_gem(:SQLite3)
|
52
52
|
org.sqlite.JDBC
|
53
53
|
end,
|
54
54
|
:oracle=>proc do |db|
|
@@ -69,28 +69,28 @@ module Sequel
|
|
69
69
|
db.extend(Sequel::JDBC::JTDS::DatabaseMethods)
|
70
70
|
db.dataset_class = Sequel::JDBC::JTDS::Dataset
|
71
71
|
db.send(:set_mssql_unicode_strings)
|
72
|
-
JDBC.load_gem(
|
72
|
+
JDBC.load_gem(:JTDS)
|
73
73
|
Java::net.sourceforge.jtds.jdbc.Driver
|
74
74
|
end,
|
75
75
|
:h2=>proc do |db|
|
76
76
|
Sequel.ts_require 'adapters/jdbc/h2'
|
77
77
|
db.extend(Sequel::JDBC::H2::DatabaseMethods)
|
78
78
|
db.dataset_class = Sequel::JDBC::H2::Dataset
|
79
|
-
JDBC.load_gem(
|
79
|
+
JDBC.load_gem(:H2)
|
80
80
|
org.h2.Driver
|
81
81
|
end,
|
82
82
|
:hsqldb=>proc do |db|
|
83
83
|
Sequel.ts_require 'adapters/jdbc/hsqldb'
|
84
84
|
db.extend(Sequel::JDBC::HSQLDB::DatabaseMethods)
|
85
85
|
db.dataset_class = Sequel::JDBC::HSQLDB::Dataset
|
86
|
-
|
86
|
+
JDBC.load_gem(:HSQLDB)
|
87
87
|
org.hsqldb.jdbcDriver
|
88
88
|
end,
|
89
89
|
:derby=>proc do |db|
|
90
90
|
Sequel.ts_require 'adapters/jdbc/derby'
|
91
91
|
db.extend(Sequel::JDBC::Derby::DatabaseMethods)
|
92
92
|
db.dataset_class = Sequel::JDBC::Derby::Dataset
|
93
|
-
JDBC.load_gem(
|
93
|
+
JDBC.load_gem(:Derby)
|
94
94
|
org.apache.derby.jdbc.EmbeddedDriver
|
95
95
|
end,
|
96
96
|
:as400=>proc do |db|
|
@@ -135,9 +135,14 @@ module Sequel
|
|
135
135
|
# works for PostgreSQL, MySQL, and SQLite.
|
136
136
|
def self.load_gem(name)
|
137
137
|
begin
|
138
|
-
Sequel.tsk_require "jdbc/#{name}"
|
138
|
+
Sequel.tsk_require "jdbc/#{name.to_s.downcase}"
|
139
139
|
rescue LoadError
|
140
140
|
# jdbc gem not used, hopefully the user has the .jar in their CLASSPATH
|
141
|
+
else
|
142
|
+
if defined?(::Jdbc) && ( ::Jdbc.const_defined?(name) rescue nil )
|
143
|
+
jdbc_module = ::Jdbc.const_get(name) # e.g. Jdbc::SQLite3
|
144
|
+
jdbc_module.load_driver if jdbc_module.respond_to?(:load_driver)
|
145
|
+
end
|
141
146
|
end
|
142
147
|
end
|
143
148
|
|
@@ -97,10 +97,16 @@ module Sequel
|
|
97
97
|
db.to_application_timestamp(v.to_string)
|
98
98
|
end
|
99
99
|
|
100
|
+
def convert_type_oracle_timestamptz(v)
|
101
|
+
convert_type_oracle_timestamp(db.synchronize{|c| v.timestampValue(c)})
|
102
|
+
end
|
103
|
+
|
100
104
|
def convert_type_proc(v)
|
101
105
|
case v
|
102
106
|
when JAVA_BIG_DECIMAL
|
103
107
|
ORACLE_DECIMAL_METHOD
|
108
|
+
when Java::OracleSql::TIMESTAMPTZ
|
109
|
+
method(:convert_type_oracle_timestamptz)
|
104
110
|
when Java::OracleSql::TIMESTAMP
|
105
111
|
method(:convert_type_oracle_timestamp)
|
106
112
|
else
|
@@ -29,7 +29,7 @@ module Sequel
|
|
29
29
|
raise Error, "Must provide either a :data option or a block to copy_into"
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
synchronize(opts) do |conn|
|
33
33
|
begin
|
34
34
|
copy_manager = org.postgresql.copy.CopyManager.new(conn)
|
35
35
|
copier = copy_manager.copy_in(copy_into_sql(table, opts))
|
@@ -41,10 +41,16 @@ module Sequel
|
|
41
41
|
data.each { |d| copier.writeToCopy(d.to_java_bytes, 0, d.length) }
|
42
42
|
end
|
43
43
|
rescue Exception => e
|
44
|
-
copier.
|
44
|
+
copier.cancelCopy
|
45
45
|
raise
|
46
46
|
ensure
|
47
|
-
|
47
|
+
unless e
|
48
|
+
begin
|
49
|
+
copier.endCopy
|
50
|
+
rescue NativeException => e2
|
51
|
+
raise_error(e2)
|
52
|
+
end
|
53
|
+
end
|
48
54
|
end
|
49
55
|
end
|
50
56
|
end
|
@@ -275,7 +275,7 @@ module Sequel
|
|
275
275
|
|
276
276
|
# Convert tinyint(1) type to boolean if convert_tinyint_to_bool is true
|
277
277
|
def schema_column_type(db_type)
|
278
|
-
convert_tinyint_to_bool && db_type
|
278
|
+
convert_tinyint_to_bool && db_type =~ /\Atinyint\(1\)/ ? :boolean : super
|
279
279
|
end
|
280
280
|
end
|
281
281
|
|
@@ -124,7 +124,7 @@ module Sequel
|
|
124
124
|
|
125
125
|
# Convert tinyint(1) type to boolean if convert_tinyint_to_bool is true
|
126
126
|
def schema_column_type(db_type)
|
127
|
-
convert_tinyint_to_bool && db_type
|
127
|
+
convert_tinyint_to_bool && db_type =~ /\Atinyint\(1\)/ ? :boolean : super
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
@@ -37,7 +37,7 @@ module Sequel
|
|
37
37
|
dbname = opts[:host]
|
38
38
|
end
|
39
39
|
conn = OCI8.new(opts[:user], opts[:password], dbname, opts[:privilege])
|
40
|
-
conn.prefetch_rows = typecast_value_integer(opts
|
40
|
+
conn.prefetch_rows = typecast_value_integer(opts.fetch(:prefetch_rows, 100))
|
41
41
|
conn.autocommit = true
|
42
42
|
conn.non_blocking = true
|
43
43
|
|
@@ -328,10 +328,12 @@ module Sequel
|
|
328
328
|
end
|
329
329
|
rescue Exception => e
|
330
330
|
conn.put_copy_end("ruby exception occurred while copying data into PostgreSQL")
|
331
|
-
raise
|
332
331
|
ensure
|
333
332
|
conn.put_copy_end unless e
|
334
|
-
conn.get_result
|
333
|
+
while res = conn.get_result
|
334
|
+
raise e if e
|
335
|
+
check_database_errors{res.check}
|
336
|
+
end
|
335
337
|
end
|
336
338
|
end
|
337
339
|
end
|
@@ -216,6 +216,9 @@ module Sequel
|
|
216
216
|
FETCH_FIRST = " FETCH FIRST ".freeze
|
217
217
|
ROWS_ONLY = " ROWS ONLY".freeze
|
218
218
|
EMPTY_FROM_TABLE = ' FROM "SYSIBM"."SYSDUMMY1"'.freeze
|
219
|
+
HSTAR = "H*".freeze
|
220
|
+
BLOB_OPEN = "BLOB(X'".freeze
|
221
|
+
BLOB_CLOSE = "')".freeze
|
219
222
|
|
220
223
|
# DB2 casts strings using RTRIM and CHAR instead of VARCHAR.
|
221
224
|
def cast_sql_append(sql, expr, type)
|
@@ -316,6 +319,15 @@ module Sequel
|
|
316
319
|
BOOL_TRUE
|
317
320
|
end
|
318
321
|
|
322
|
+
# DB2 uses a literal hexidecimal number for blob strings
|
323
|
+
def literal_blob_append(sql, v)
|
324
|
+
if ::Sequel::DB2.use_clob_as_blob
|
325
|
+
super
|
326
|
+
else
|
327
|
+
sql << BLOB_OPEN << v.unpack(HSTAR).first << BLOB_CLOSE
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
319
331
|
# Add a fallback table for empty from situation
|
320
332
|
def select_from_sql(sql)
|
321
333
|
@opts[:from] ? super : (sql << EMPTY_FROM_TABLE)
|