sequel 2.9.0 → 2.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +56 -0
- data/{README → README.rdoc} +85 -57
- data/Rakefile +10 -5
- data/bin/sequel +7 -16
- data/doc/advanced_associations.rdoc +5 -17
- data/doc/cheat_sheet.rdoc +18 -20
- data/doc/dataset_filtering.rdoc +8 -32
- data/doc/schema.rdoc +20 -0
- data/lib/sequel_core.rb +35 -1
- data/lib/sequel_core/adapters/ado.rb +1 -1
- data/lib/sequel_core/adapters/db2.rb +2 -2
- data/lib/sequel_core/adapters/dbi.rb +2 -11
- data/lib/sequel_core/adapters/do.rb +205 -0
- data/lib/sequel_core/adapters/do/mysql.rb +38 -0
- data/lib/sequel_core/adapters/do/postgres.rb +92 -0
- data/lib/sequel_core/adapters/do/sqlite.rb +31 -0
- data/lib/sequel_core/adapters/firebird.rb +298 -0
- data/lib/sequel_core/adapters/informix.rb +10 -1
- data/lib/sequel_core/adapters/jdbc.rb +78 -19
- data/lib/sequel_core/adapters/jdbc/h2.rb +69 -0
- data/lib/sequel_core/adapters/jdbc/mysql.rb +10 -0
- data/lib/sequel_core/adapters/jdbc/postgresql.rb +7 -3
- data/lib/sequel_core/adapters/mysql.rb +53 -77
- data/lib/sequel_core/adapters/odbc.rb +1 -1
- data/lib/sequel_core/adapters/openbase.rb +1 -1
- data/lib/sequel_core/adapters/oracle.rb +2 -2
- data/lib/sequel_core/adapters/postgres.rb +16 -14
- data/lib/sequel_core/adapters/shared/mysql.rb +44 -9
- data/lib/sequel_core/adapters/shared/oracle.rb +4 -5
- data/lib/sequel_core/adapters/shared/postgres.rb +86 -82
- data/lib/sequel_core/adapters/shared/sqlite.rb +39 -24
- data/lib/sequel_core/adapters/sqlite.rb +11 -1
- data/lib/sequel_core/connection_pool.rb +10 -2
- data/lib/sequel_core/core_sql.rb +13 -3
- data/lib/sequel_core/database.rb +131 -30
- data/lib/sequel_core/database/schema.rb +5 -5
- data/lib/sequel_core/dataset.rb +31 -6
- data/lib/sequel_core/dataset/convenience.rb +11 -11
- data/lib/sequel_core/dataset/query.rb +2 -2
- data/lib/sequel_core/dataset/sql.rb +6 -6
- data/lib/sequel_core/exceptions.rb +4 -0
- data/lib/sequel_core/migration.rb +4 -4
- data/lib/sequel_core/schema/generator.rb +19 -3
- data/lib/sequel_core/schema/sql.rb +24 -20
- data/lib/sequel_core/sql.rb +13 -16
- data/lib/sequel_core/version.rb +11 -0
- data/lib/sequel_model.rb +2 -0
- data/lib/sequel_model/base.rb +2 -2
- data/lib/sequel_model/hooks.rb +46 -7
- data/lib/sequel_model/record.rb +11 -9
- data/lib/sequel_model/schema.rb +1 -1
- data/lib/sequel_model/validations.rb +72 -61
- data/spec/adapters/firebird_spec.rb +371 -0
- data/spec/adapters/mysql_spec.rb +118 -62
- data/spec/adapters/oracle_spec.rb +5 -5
- data/spec/adapters/postgres_spec.rb +33 -18
- data/spec/adapters/sqlite_spec.rb +2 -2
- data/spec/integration/dataset_test.rb +3 -3
- data/spec/integration/schema_test.rb +55 -5
- data/spec/integration/spec_helper.rb +11 -0
- data/spec/integration/type_test.rb +59 -16
- data/spec/sequel_core/connection_pool_spec.rb +14 -0
- data/spec/sequel_core/core_sql_spec.rb +24 -14
- data/spec/sequel_core/database_spec.rb +96 -11
- data/spec/sequel_core/dataset_spec.rb +97 -37
- data/spec/sequel_core/expression_filters_spec.rb +51 -40
- data/spec/sequel_core/object_graph_spec.rb +2 -2
- data/spec/sequel_core/schema_generator_spec.rb +31 -6
- data/spec/sequel_core/schema_spec.rb +25 -9
- data/spec/sequel_core/spec_helper.rb +4 -1
- data/spec/sequel_core/version_spec.rb +7 -0
- data/spec/sequel_model/associations_spec.rb +1 -1
- data/spec/sequel_model/hooks_spec.rb +68 -13
- data/spec/sequel_model/model_spec.rb +4 -4
- data/spec/sequel_model/record_spec.rb +22 -0
- data/spec/sequel_model/spec_helper.rb +2 -1
- data/spec/sequel_model/validations_spec.rb +107 -7
- metadata +15 -5
@@ -5,6 +5,7 @@ module Sequel
|
|
5
5
|
SYNCHRONOUS = {'0' => :off, '1' => :normal, '2' => :full}.freeze
|
6
6
|
TABLES_FILTER = "type = 'table' AND NOT name = 'sqlite_sequence'"
|
7
7
|
TEMP_STORE = {'0' => :default, '1' => :file, '2' => :memory}.freeze
|
8
|
+
TYPES = Sequel::Schema::SQL::TYPES.merge(Bignum=>'integer')
|
8
9
|
|
9
10
|
# Run all alter_table commands in a transaction. This is technically only
|
10
11
|
# needed for drop column.
|
@@ -68,8 +69,15 @@ module Sequel
|
|
68
69
|
end
|
69
70
|
|
70
71
|
# Array of symbols specifying the table names in the current database.
|
71
|
-
|
72
|
-
|
72
|
+
#
|
73
|
+
# Options:
|
74
|
+
# * :server - Set the server to use.
|
75
|
+
def tables(opts={})
|
76
|
+
ds = self[:sqlite_master].server(opts[:server]).filter(TABLES_FILTER)
|
77
|
+
ds.identifier_output_method = nil
|
78
|
+
ds.identifier_input_method = nil
|
79
|
+
ds2 = dataset
|
80
|
+
ds.map{|r| ds2.send(:output_identifier, r[:name])}
|
73
81
|
end
|
74
82
|
|
75
83
|
# A symbol signifying the value of the temp_store PRAGMA.
|
@@ -85,21 +93,22 @@ module Sequel
|
|
85
93
|
|
86
94
|
private
|
87
95
|
|
88
|
-
# SQLite folds unquoted identifiers to lowercase, so it shouldn't need to upcase identifiers
|
89
|
-
def
|
90
|
-
|
96
|
+
# SQLite folds unquoted identifiers to lowercase, so it shouldn't need to upcase identifiers on input.
|
97
|
+
def identifier_input_method_default
|
98
|
+
nil
|
91
99
|
end
|
92
|
-
|
93
|
-
# SQLite
|
94
|
-
|
95
|
-
|
96
|
-
parse_pragma(table_name, opts).map do |row|
|
97
|
-
[row.delete(:name).to_sym, row]
|
98
|
-
end
|
100
|
+
|
101
|
+
# SQLite folds unquoted identifiers to lowercase, so it shouldn't need to upcase identifiers on output.
|
102
|
+
def identifier_output_method_default
|
103
|
+
nil
|
99
104
|
end
|
100
105
|
|
106
|
+
# Parse the output of the table_info pragma
|
101
107
|
def parse_pragma(table_name, opts)
|
102
|
-
|
108
|
+
ds2 = dataset
|
109
|
+
ds = self["PRAGMA table_info(?)", ds2.send(:input_identifier, table_name)]
|
110
|
+
ds.identifier_output_method = nil
|
111
|
+
ds.map do |row|
|
103
112
|
row.delete(:cid)
|
104
113
|
row[:allow_null] = row.delete(:notnull).to_i == 0
|
105
114
|
row[:default] = row.delete(:dflt_value)
|
@@ -110,6 +119,20 @@ module Sequel
|
|
110
119
|
row
|
111
120
|
end
|
112
121
|
end
|
122
|
+
|
123
|
+
# SQLite supports schema parsing using the table_info PRAGMA, so
|
124
|
+
# parse the output of that into the format Sequel expects.
|
125
|
+
def schema_parse_table(table_name, opts)
|
126
|
+
ds = dataset
|
127
|
+
parse_pragma(table_name, opts).map do |row|
|
128
|
+
[ds.send(:output_identifier, row.delete(:name)), row]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Override the standard type conversions with SQLite specific ones
|
133
|
+
def type_literal_base(column)
|
134
|
+
TYPES[column[:type]]
|
135
|
+
end
|
113
136
|
end
|
114
137
|
|
115
138
|
# Instance methods for datasets that connect to an SQLite database
|
@@ -132,20 +155,12 @@ module Sequel
|
|
132
155
|
end
|
133
156
|
|
134
157
|
# SQLite performs a TRUNCATE style DELETE if no filter is specified.
|
135
|
-
# Since we want to always return the count of records,
|
136
|
-
#
|
158
|
+
# Since we want to always return the count of records, add a condition
|
159
|
+
# that is always true and then delete.
|
137
160
|
def delete(opts = {})
|
138
161
|
# check if no filter is specified
|
139
162
|
opts = @opts.merge(opts)
|
140
|
-
|
141
|
-
@db.transaction(opts[:server]) do
|
142
|
-
unfiltered_count = count
|
143
|
-
execute_dui(delete_sql(opts))
|
144
|
-
unfiltered_count
|
145
|
-
end
|
146
|
-
else
|
147
|
-
execute_dui(delete_sql(opts))
|
148
|
-
end
|
163
|
+
super(opts[:where] ? opts : opts.merge(:where=>{1=>1}))
|
149
164
|
end
|
150
165
|
|
151
166
|
# Insert the values into the database.
|
@@ -46,6 +46,12 @@ module Sequel
|
|
46
46
|
db.translator.add_translator("decimal", &prok)
|
47
47
|
db.translator.add_translator("money", &prok)
|
48
48
|
|
49
|
+
# Handle floating point values with Float
|
50
|
+
prok = proc{|t,v| Float(v) rescue v}
|
51
|
+
db.translator.add_translator("float", &prok)
|
52
|
+
db.translator.add_translator("real", &prok)
|
53
|
+
db.translator.add_translator("double precision", &prok)
|
54
|
+
|
49
55
|
db
|
50
56
|
end
|
51
57
|
|
@@ -82,10 +88,14 @@ module Sequel
|
|
82
88
|
return yield(conn) if conn.transaction_active?
|
83
89
|
begin
|
84
90
|
result = nil
|
91
|
+
log_info('Transaction.begin')
|
85
92
|
conn.transaction{result = yield(conn)}
|
86
93
|
result
|
87
94
|
rescue ::Exception => e
|
95
|
+
log_info('Transaction.rollback')
|
88
96
|
transaction_error(e, SQLite3::Exception)
|
97
|
+
ensure
|
98
|
+
log_info('Transaction.commit') unless e
|
89
99
|
end
|
90
100
|
end
|
91
101
|
end
|
@@ -191,7 +201,7 @@ module Sequel
|
|
191
201
|
# Yield a hash for each row in the dataset.
|
192
202
|
def fetch_rows(sql)
|
193
203
|
execute(sql) do |result|
|
194
|
-
@columns = result.columns.map
|
204
|
+
@columns = result.columns.map{|c| output_identifier(c)}
|
195
205
|
column_count = @columns.size
|
196
206
|
result.each do |values|
|
197
207
|
row = {}
|
@@ -156,9 +156,17 @@ class Sequel::ConnectionPool
|
|
156
156
|
# the server is less than the maximum size of the pool.
|
157
157
|
def make_new(server)
|
158
158
|
if @created_count[server] < @max_size
|
159
|
+
raise(Sequel::Error, "No connection proc specified") unless @connection_proc
|
160
|
+
begin
|
161
|
+
conn = @connection_proc.call(server)
|
162
|
+
rescue Exception=>exception
|
163
|
+
e = Sequel::DatabaseConnectionError.new("#{exception.class} #{exception.message}")
|
164
|
+
e.set_backtrace(exception.backtrace)
|
165
|
+
raise e
|
166
|
+
end
|
167
|
+
raise(Sequel::DatabaseConnectionError, "Connection parameters not valid") unless conn
|
159
168
|
set_created_count(server, @created_count[server] + 1)
|
160
|
-
|
161
|
-
(raise Error, "No connection proc specified")
|
169
|
+
conn
|
162
170
|
end
|
163
171
|
end
|
164
172
|
|
data/lib/sequel_core/core_sql.rb
CHANGED
@@ -157,7 +157,14 @@ end
|
|
157
157
|
class Symbol
|
158
158
|
include Sequel::SQL::QualifyingMethods
|
159
159
|
include Sequel::SQL::IdentifierMethods
|
160
|
-
include Sequel::SQL::
|
160
|
+
include Sequel::SQL::AliasMethods
|
161
|
+
include Sequel::SQL::CastMethods
|
162
|
+
include Sequel::SQL::OrderMethods
|
163
|
+
include Sequel::SQL::BooleanMethods
|
164
|
+
include Sequel::SQL::NumericMethods
|
165
|
+
include Sequel::SQL::StringMethods
|
166
|
+
include Sequel::SQL::ComplexExpressionMethods
|
167
|
+
include Sequel::SQL::InequalityMethods if RUBY_VERSION < '1.9.0'
|
161
168
|
|
162
169
|
# If no argument is given, returns a Sequel::SQL::ColumnAll object specifying all
|
163
170
|
# columns for this table.
|
@@ -169,10 +176,13 @@ class Symbol
|
|
169
176
|
end
|
170
177
|
|
171
178
|
# Returns a Sequel::SQL::Function with this as the function name,
|
172
|
-
# and the given arguments.
|
173
|
-
|
179
|
+
# and the given arguments. This is aliased as Symbol#[] if ruby 1.9
|
180
|
+
# is not being used. ruby 1.9 includes Symbol#[], and Sequel
|
181
|
+
# doesn't override methods defined by ruby itself.
|
182
|
+
def sql_function(*args)
|
174
183
|
Sequel::SQL::Function.new(self, *args)
|
175
184
|
end
|
185
|
+
alias_method(:[], :sql_function) if RUBY_VERSION < '1.9.0'
|
176
186
|
|
177
187
|
# If the given argument is an Integer or an array containing an Integer, returns
|
178
188
|
# a Sequel::SQL::Subscript with this column and the given arg.
|
data/lib/sequel_core/database.rb
CHANGED
@@ -14,7 +14,7 @@ module Sequel
|
|
14
14
|
include Schema::SQL
|
15
15
|
|
16
16
|
# Array of supported database adapters
|
17
|
-
ADAPTERS = %w'ado db2 dbi informix jdbc mysql odbc openbase oracle postgres sqlite'.collect{|x| x.to_sym}
|
17
|
+
ADAPTERS = %w'ado db2 dbi do firebird informix jdbc mysql odbc openbase oracle postgres sqlite'.collect{|x| x.to_sym}
|
18
18
|
|
19
19
|
SQL_BEGIN = 'BEGIN'.freeze
|
20
20
|
SQL_COMMIT = 'COMMIT'.freeze
|
@@ -22,22 +22,25 @@ module Sequel
|
|
22
22
|
|
23
23
|
# Hash of adapters that have been used
|
24
24
|
@@adapters = Hash.new
|
25
|
+
|
26
|
+
# The identifier input method to use by default
|
27
|
+
@@identifier_input_method = nil
|
28
|
+
|
29
|
+
# The identifier output method to use by default
|
30
|
+
@@identifier_output_method = nil
|
25
31
|
|
26
32
|
# Whether to use the single threaded connection pool by default
|
27
33
|
@@single_threaded = false
|
28
34
|
|
29
35
|
# Whether to quote identifiers (columns and tables) by default
|
30
|
-
@@quote_identifiers =
|
31
|
-
|
32
|
-
# Whether to upcase identifiers (columns and tables) by default
|
33
|
-
@@upcase_identifiers = nil
|
36
|
+
@@quote_identifiers = nil
|
34
37
|
|
35
38
|
# The default schema to use
|
36
39
|
attr_accessor :default_schema
|
37
40
|
|
38
41
|
# Array of SQL loggers to use for this database
|
39
42
|
attr_accessor :loggers
|
40
|
-
|
43
|
+
|
41
44
|
# The options for this database
|
42
45
|
attr_reader :opts
|
43
46
|
|
@@ -46,12 +49,6 @@ module Sequel
|
|
46
49
|
|
47
50
|
# The prepared statement objects for this database, keyed by name
|
48
51
|
attr_reader :prepared_statements
|
49
|
-
|
50
|
-
# Whether to quote identifiers (columns and tables) for this database
|
51
|
-
attr_writer :quote_identifiers
|
52
|
-
|
53
|
-
# Whether to upcase identifiers (columns and tables) for this database
|
54
|
-
attr_writer :upcase_identifiers
|
55
52
|
|
56
53
|
# Constructs a new instance of a database connection with the specified
|
57
54
|
# options hash.
|
@@ -61,21 +58,26 @@ module Sequel
|
|
61
58
|
# Takes the following options:
|
62
59
|
# * :default_schema : The default schema to use, should generally be nil
|
63
60
|
# * :disconnection_proc: A proc used to disconnect the connection.
|
61
|
+
# * :identifier_input_method: A string method symbol to call on identifiers going into the database
|
62
|
+
# * :identifier_output_method: A string method symbol to call on identifiers coming from the database
|
64
63
|
# * :loggers : An array of loggers to use.
|
65
64
|
# * :quote_identifiers : Whether to quote identifiers
|
66
65
|
# * :single_threaded : Whether to use a single-threaded connection pool
|
66
|
+
# * :upcase_identifiers : Whether to upcase identifiers going into the database
|
67
67
|
#
|
68
68
|
# All options given are also passed to the ConnectionPool. If a block
|
69
69
|
# is given, it is used as the connection_proc for the ConnectionPool.
|
70
70
|
def initialize(opts = {}, &block)
|
71
|
-
@opts
|
71
|
+
@opts ||= opts
|
72
72
|
|
73
|
-
@quote_identifiers = opts.include?(:quote_identifiers) ? opts[:quote_identifiers] : @@quote_identifiers
|
74
73
|
@single_threaded = opts.include?(:single_threaded) ? opts[:single_threaded] : @@single_threaded
|
75
74
|
@schemas = nil
|
76
|
-
@default_schema = opts[:default_schema]
|
75
|
+
@default_schema = opts.include?(:default_schema) ? opts[:default_schema] : default_schema_default
|
77
76
|
@prepared_statements = {}
|
78
77
|
@transactions = []
|
78
|
+
if opts.include?(:upcase_identifiers)
|
79
|
+
@identifier_input_method = opts[:upcase_identifiers] ? :upcase : ""
|
80
|
+
end
|
79
81
|
@pool = (@single_threaded ? SingleThreadedPool : ConnectionPool).new(connection_pool_default_options.merge(opts), &block)
|
80
82
|
@pool.connection_proc = proc{|server| connect(server)} unless block
|
81
83
|
@pool.disconnection_proc = proc{|conn| disconnect_connection(conn)} unless opts[:disconnection_proc]
|
@@ -119,6 +121,9 @@ module Sequel
|
|
119
121
|
if conn_string =~ /\Ajdbc:/
|
120
122
|
c = adapter_class(:jdbc)
|
121
123
|
opts = {:uri=>conn_string}.merge(opts)
|
124
|
+
elsif conn_string =~ /\Ado:/
|
125
|
+
c = adapter_class(:do)
|
126
|
+
opts = {:uri=>conn_string}.merge(opts)
|
122
127
|
else
|
123
128
|
uri = URI.parse(conn_string)
|
124
129
|
scheme = uri.scheme
|
@@ -150,6 +155,26 @@ module Sequel
|
|
150
155
|
c.new(opts)
|
151
156
|
end
|
152
157
|
end
|
158
|
+
|
159
|
+
# The method to call on identifiers going into the database
|
160
|
+
def self.identifier_input_method
|
161
|
+
@@identifier_input_method
|
162
|
+
end
|
163
|
+
|
164
|
+
# Set the method to call on identifiers going into the database
|
165
|
+
def self.identifier_input_method=(v)
|
166
|
+
@@identifier_input_method = v || ""
|
167
|
+
end
|
168
|
+
|
169
|
+
# The method to call on identifiers coming from the database
|
170
|
+
def self.identifier_output_method
|
171
|
+
@@identifier_output_method
|
172
|
+
end
|
173
|
+
|
174
|
+
# Set the method to call on identifiers coming from the database
|
175
|
+
def self.identifier_output_method=(v)
|
176
|
+
@@identifier_output_method = v || ""
|
177
|
+
end
|
153
178
|
|
154
179
|
# Sets the default quote_identifiers mode for new databases.
|
155
180
|
# See Sequel.quote_identifiers=.
|
@@ -166,7 +191,7 @@ module Sequel
|
|
166
191
|
# Sets the default quote_identifiers mode for new databases.
|
167
192
|
# See Sequel.quote_identifiers=.
|
168
193
|
def self.upcase_identifiers=(value)
|
169
|
-
|
194
|
+
self.identifier_input_method = value ? :upcase : nil
|
170
195
|
end
|
171
196
|
|
172
197
|
### Private Class Methods ###
|
@@ -262,6 +287,12 @@ module Sequel
|
|
262
287
|
execute(sql, opts, &block)
|
263
288
|
end
|
264
289
|
|
290
|
+
# Method that should be used when issuing a INSERT
|
291
|
+
# statement. By default, calls execute_dui.
|
292
|
+
def execute_insert(sql, opts={}, &block)
|
293
|
+
execute_dui(sql, opts, &block)
|
294
|
+
end
|
295
|
+
|
265
296
|
# Fetches records for an arbitrary SQL statement. If a block is given,
|
266
297
|
# it is used to iterate over the records:
|
267
298
|
#
|
@@ -296,11 +327,49 @@ module Sequel
|
|
296
327
|
# DB.get(1) #=> 1
|
297
328
|
#
|
298
329
|
# # SELECT version()
|
299
|
-
# DB.get(:version
|
330
|
+
# DB.get(:version.sql_function) #=> ...
|
300
331
|
def get(expr)
|
301
332
|
dataset.get(expr)
|
302
333
|
end
|
303
334
|
|
335
|
+
# The method to call on identifiers going into the database
|
336
|
+
def identifier_input_method
|
337
|
+
case @identifier_input_method
|
338
|
+
when nil
|
339
|
+
@identifier_input_method = @opts.include?(:identifier_input_method) ? @opts[:identifier_input_method] : (@@identifier_input_method.nil? ? identifier_input_method_default : @@identifier_input_method)
|
340
|
+
@identifier_input_method == "" ? nil : @identifier_input_method
|
341
|
+
when ""
|
342
|
+
nil
|
343
|
+
else
|
344
|
+
@identifier_input_method
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
# Set the method to call on identifiers going into the database
|
349
|
+
def identifier_input_method=(v)
|
350
|
+
reset_schema_utility_dataset
|
351
|
+
@identifier_input_method = v || ""
|
352
|
+
end
|
353
|
+
|
354
|
+
# The method to call on identifiers coming from the database
|
355
|
+
def identifier_output_method
|
356
|
+
case @identifier_output_method
|
357
|
+
when nil
|
358
|
+
@identifier_output_method = @opts.include?(:identifier_output_method) ? @opts[:identifier_output_method] : (@@identifier_output_method.nil? ? identifier_output_method_default : @@identifier_output_method)
|
359
|
+
@identifier_output_method == "" ? nil : @identifier_output_method
|
360
|
+
when ""
|
361
|
+
nil
|
362
|
+
else
|
363
|
+
@identifier_output_method
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
# Set the method to call on identifiers coming from the database
|
368
|
+
def identifier_output_method=(v)
|
369
|
+
reset_schema_utility_dataset
|
370
|
+
@identifier_output_method = v || ""
|
371
|
+
end
|
372
|
+
|
304
373
|
# Returns a string representation of the database object including the
|
305
374
|
# class name and the connection URI (or the opts if the URI
|
306
375
|
# cannot be constructed).
|
@@ -336,9 +405,16 @@ module Sequel
|
|
336
405
|
dataset.query(&block)
|
337
406
|
end
|
338
407
|
|
408
|
+
# Whether to quote identifiers (columns and tables) for this database
|
409
|
+
def quote_identifiers=(v)
|
410
|
+
reset_schema_utility_dataset
|
411
|
+
@quote_identifiers = v
|
412
|
+
end
|
413
|
+
|
339
414
|
# Returns true if the database quotes identifiers.
|
340
415
|
def quote_identifiers?
|
341
|
-
@quote_identifiers
|
416
|
+
return @quote_identifiers unless @quote_identifiers.nil?
|
417
|
+
@quote_identifiers = @opts.include?(:quote_identifiers) ? @opts[:quote_identifiers] : (@@quote_identifiers.nil? ? quote_identifiers_default : @@quote_identifiers)
|
342
418
|
end
|
343
419
|
|
344
420
|
# Returns a new dataset with the select method invoked.
|
@@ -348,7 +424,7 @@ module Sequel
|
|
348
424
|
|
349
425
|
# Default serial primary key options.
|
350
426
|
def serial_primary_key_options
|
351
|
-
{:primary_key => true, :type =>
|
427
|
+
{:primary_key => true, :type => Integer, :auto_increment => true}
|
352
428
|
end
|
353
429
|
|
354
430
|
# Returns true if the database is using a single-threaded connection pool.
|
@@ -485,11 +561,15 @@ module Sequel
|
|
485
561
|
value
|
486
562
|
end
|
487
563
|
end
|
564
|
+
|
565
|
+
# Set whether to upcase identifiers going into the database.
|
566
|
+
def upcase_identifiers=(v)
|
567
|
+
self.identifier_input_method = v ? :upcase : nil
|
568
|
+
end
|
488
569
|
|
489
570
|
# Returns true if the database upcases identifiers.
|
490
571
|
def upcase_identifiers?
|
491
|
-
|
492
|
-
@upcase_identifiers = @opts.include?(:upcase_identifiers) ? @opts[:upcase_identifiers] : (@@upcase_identifiers.nil? ? upcase_identifiers_default : @@upcase_identifiers)
|
572
|
+
identifier_input_method == :upcase
|
493
573
|
end
|
494
574
|
|
495
575
|
# Returns the URI identifying the database.
|
@@ -511,7 +591,11 @@ module Sequel
|
|
511
591
|
uri.password = @opts[:password] if uri.user
|
512
592
|
uri.to_s
|
513
593
|
end
|
514
|
-
|
594
|
+
|
595
|
+
# Explicit alias of uri for easier subclassing.
|
596
|
+
def url
|
597
|
+
uri
|
598
|
+
end
|
515
599
|
|
516
600
|
private
|
517
601
|
|
@@ -530,6 +614,31 @@ module Sequel
|
|
530
614
|
{}
|
531
615
|
end
|
532
616
|
|
617
|
+
# The default value for default_schema.
|
618
|
+
def default_schema_default
|
619
|
+
nil
|
620
|
+
end
|
621
|
+
|
622
|
+
# The method to apply to identifiers going into the database by default.
|
623
|
+
# Should be overridden in subclasses for databases that fold unquoted
|
624
|
+
# identifiers to lower case instead of uppercase, such as
|
625
|
+
# MySQL, PostgreSQL, and SQLite.
|
626
|
+
def identifier_input_method_default
|
627
|
+
:upcase
|
628
|
+
end
|
629
|
+
|
630
|
+
# The method to apply to identifiers coming the database by default.
|
631
|
+
# Should be overridden in subclasses for databases that fold unquoted
|
632
|
+
# identifiers to lower case instead of uppercase, such as
|
633
|
+
# MySQL, PostgreSQL, and SQLite.
|
634
|
+
def identifier_output_method_default
|
635
|
+
:downcase
|
636
|
+
end
|
637
|
+
|
638
|
+
def quote_identifiers_default
|
639
|
+
true
|
640
|
+
end
|
641
|
+
|
533
642
|
# SQL to ROLLBACK a transaction.
|
534
643
|
def rollback_transaction_sql
|
535
644
|
SQL_ROLLBACK
|
@@ -576,14 +685,6 @@ module Sequel
|
|
576
685
|
def transaction_error(e, *classes)
|
577
686
|
raise_error(e, :classes=>classes) unless Error::Rollback === e
|
578
687
|
end
|
579
|
-
|
580
|
-
# Sets whether to upcase identifiers by default. Should be
|
581
|
-
# overridden in subclasses for databases that fold unquoted
|
582
|
-
# identifiers to lower case instead of uppercase, such as
|
583
|
-
# MySQL, PostgreSQL, and SQLite.
|
584
|
-
def upcase_identifiers_default
|
585
|
-
true
|
586
|
-
end
|
587
688
|
end
|
588
689
|
end
|
589
690
|
|