| Module | Sequel::MySQL::DatasetMethods |
| In: |
lib/sequel/adapters/shared/mysql.rb
|
| BOOL_TRUE | = | '1'.freeze |
| BOOL_FALSE | = | '0'.freeze |
| COMMA_SEPARATOR | = | ', '.freeze |
| DELETE_CLAUSE_METHODS | = | Dataset.clause_methods(:delete, %w'from where order limit') |
| INSERT_CLAUSE_METHODS | = | Dataset.clause_methods(:insert, %w'ignore into columns values on_duplicate_key_update') |
| SELECT_CLAUSE_METHODS | = | Dataset.clause_methods(:select, %w'distinct columns from join where group having compounds order limit') |
| UPDATE_CLAUSE_METHODS | = | Dataset.clause_methods(:update, %w'table set where order limit') |
MySQL specific syntax for LIKE/REGEXP searches, as well as string concatenation.
# File lib/sequel/adapters/shared/mysql.rb, line 212
212: def complex_expression_sql(op, args)
213: case op
214: when :~, '!~''!~', '~*''~*', '!~*''!~*', :LIKE, 'NOT LIKE''NOT LIKE', :ILIKE, 'NOT ILIKE''NOT ILIKE'
215: "(#{literal(args.at(0))} #{'NOT ' if [:'NOT LIKE', :'NOT ILIKE', :'!~', :'!~*'].include?(op)}#{[:~, :'!~', :'~*', :'!~*'].include?(op) ? 'REGEXP' : 'LIKE'} #{'BINARY ' if [:~, :'!~', :LIKE, :'NOT LIKE'].include?(op)}#{literal(args.at(1))})"
216: when '||''||'
217: if args.length > 1
218: "CONCAT(#{args.collect{|a| literal(a)}.join(', ')})"
219: else
220: literal(args.at(0))
221: end
222: else
223: super(op, args)
224: end
225: end
Adds full text filter
# File lib/sequel/adapters/shared/mysql.rb, line 228
228: def full_text_search(cols, terms, opts = {})
229: filter(full_text_sql(cols, terms, opts))
230: end
Sets up multi_insert or import 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)
# File lib/sequel/adapters/shared/mysql.rb, line 272
272: def insert_ignore
273: clone(:insert_ignore=>true)
274: end
Transforms an CROSS JOIN to an INNER JOIN if the expr is not nil. Raises an error on use of :full_outer type, since MySQL doesn‘t support it.
# File lib/sequel/adapters/shared/mysql.rb, line 244
244: def join_table(type, table, expr=nil, table_alias={})
245: type = :inner if (type == :cross) && !expr.nil?
246: raise(Sequel::Error, "MySQL doesn't support FULL OUTER JOIN") if type == :full_outer
247: super(type, table, expr, table_alias)
248: end
Transforms :natural_inner to NATURAL LEFT JOIN and straight to STRAIGHT_JOIN.
# File lib/sequel/adapters/shared/mysql.rb, line 252
252: def join_type_sql(join_type)
253: case join_type
254: when :straight then 'STRAIGHT_JOIN'
255: when :natural_inner then 'NATURAL LEFT JOIN'
256: else super
257: end
258: end
Sets up multi_insert or import 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(: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)
# File lib/sequel/adapters/shared/mysql.rb, line 300
300: def on_duplicate_key_update(*args)
301: clone(:on_duplicate_key_update => args)
302: end
does not support DISTINCT ON
# File lib/sequel/adapters/shared/mysql.rb, line 321
321: def supports_distinct_on?
322: false
323: end
MySQL does support fractional timestamps in literal timestamps, but it ignores them. Also, using them seems to cause problems on 1.9. Since they are ignored anyway, not using them is probably best.
# File lib/sequel/adapters/shared/mysql.rb, line 333
333: def supports_timestamp_usecs?
334: false
335: end