lib/sequel/adapters/shared/mysql.rb in sequel-3.10.0 vs lib/sequel/adapters/shared/mysql.rb in sequel-3.11.0
- old
+ new
@@ -129,13 +129,13 @@
super
end
# Use MySQL specific syntax for engine type and character encoding
def create_table_sql(name, generator, options = {})
- engine = options.include?(:engine) ? options[:engine] : Sequel::MySQL.default_engine
- charset = options.include?(:charset) ? options[:charset] : Sequel::MySQL.default_charset
- collate = options.include?(:collate) ? options[:collate] : Sequel::MySQL.default_collate
+ engine = options.fetch(:engine, Sequel::MySQL.default_engine)
+ charset = options.fetch(:charset, Sequel::MySQL.default_charset)
+ collate = options.fetch(:collate, Sequel::MySQL.default_collate)
generator.columns.each do |c|
if t = c.delete(:table)
generator.foreign_key([c[:name]], t, c.merge(:name=>nil, :type=>:foreign_key))
end
end
@@ -248,10 +248,15 @@
else
super(op, args)
end
end
+ # Use GROUP BY instead of DISTINCT ON if arguments are provided.
+ def distinct(*args)
+ args.empty? ? super : group(*args)
+ end
+
# Return a cloned dataset which will use LOCK IN SHARE MODE to lock returned rows.
def for_share
lock_style(:share)
end
@@ -286,59 +291,56 @@
when :natural_inner then 'NATURAL LEFT JOIN'
else super
end
end
- # Sets up multi_insert or import to use INSERT IGNORE.
+ # Sets up the insert methods to use INSERT IGNORE.
# Useful if you have a unique key and want to just skip
# inserting rows that violate the unique key restriction.
#
- # Example:
- #
- # dataset.insert_ignore.multi_insert(
- # [{:name => 'a', :value => 1}, {:name => 'b', :value => 2}]
- # )
- #
- # INSERT IGNORE INTO tablename (name, value) VALUES (a, 1), (b, 2)
- #
+ # dataset.insert_ignore.multi_insert(
+ # [{:name => 'a', :value => 1}, {:name => 'b', :value => 2}]
+ # )
+ # # INSERT IGNORE INTO tablename (name, value) VALUES (a, 1), (b, 2)
def insert_ignore
clone(:insert_ignore=>true)
end
- # Sets up multi_insert or import to use ON DUPLICATE KEY UPDATE
+ # Sets up the insert methods to use ON DUPLICATE KEY UPDATE
# If you pass no arguments, ALL fields will be
# updated with the new values. If you pass the fields you
# want then ONLY those field will be updated.
#
# Useful if you have a unique key and want to update
# inserting rows that violate the unique key restriction.
#
- # Examples:
+ # dataset.on_duplicate_key_update.multi_insert(
+ # [{:name => 'a', :value => 1}, {:name => 'b', :value => 2}]
+ # )
+ # # INSERT INTO tablename (name, value) VALUES (a, 1), (b, 2)
+ # # ON DUPLICATE KEY UPDATE name=VALUES(name), value=VALUES(value)
#
- # dataset.on_duplicate_key_update.multi_insert(
- # [{:name => 'a', :value => 1}, {:name => 'b', :value => 2}]
- # )
- #
- # INSERT INTO tablename (name, value) VALUES (a, 1), (b, 2)
- # ON DUPLICATE KEY UPDATE name=VALUES(name), value=VALUES(value)
- #
- # dataset.on_duplicate_key_update(:value).multi_insert(
- # [{:name => 'a', :value => 1}, {:name => 'b', :value => 2}]
- # )
- #
- # INSERT INTO tablename (name, value) VALUES (a, 1), (b, 2)
- # ON DUPLICATE KEY UPDATE value=VALUES(value)
- #
+ # dataset.on_duplicate_key_update(:value).multi_insert(
+ # [{:name => 'a', :value => 1}, {:name => 'b', :value => 2}]
+ # )
+ # # INSERT INTO tablename (name, value) VALUES (a, 1), (b, 2)
+ # # ON DUPLICATE KEY UPDATE value=VALUES(value)
def on_duplicate_key_update(*args)
clone(:on_duplicate_key_update => args)
end
# MySQL specific syntax for inserting multiple values at once.
def multi_insert_sql(columns, values)
[insert_sql(columns, LiteralString.new('VALUES ' + values.map {|r| literal(Array(r))}.join(COMMA_SEPARATOR)))]
end
+ # MySQL uses the number of rows actually modified in the update,
+ # instead of the number of matched by the filter.
+ def provides_accurate_rows_matched?
+ false
+ end
+
# MySQL uses the nonstandard ` (backtick) for quoting identifiers.
def quoted_identifier(c)
"`#{c}`"
end
@@ -346,12 +348,13 @@
# insert if it doesn't).
def replace_sql(*values)
clone(:replace=>true).insert_sql(*values)
end
- # does not support DISTINCT ON
+ # MySQL can emulate DISTINCT ON with its non-standard GROUP BY implementation,
+ # though the rows returned cannot be made deterministic through ordering.
def supports_distinct_on?
- false
+ true
end
# MySQL does not support INTERSECT or EXCEPT
def supports_intersect_except?
false