| Module | Sequel::MySQL::DatasetMethods |
| In: |
lib/sequel/adapters/shared/mysql.rb
|
| BOOL_TRUE | = | '1'.freeze |
| BOOL_FALSE | = | '0'.freeze |
| COMMA_SEPARATOR | = | ', '.freeze |
| FOR_SHARE | = | ' LOCK IN SHARE MODE'.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 lock') |
| 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 302
302: def complex_expression_sql(op, args)
303: case op
304: when :~, '!~''!~', '~*''~*', '!~*''!~*', :LIKE, 'NOT LIKE''NOT LIKE', :ILIKE, 'NOT ILIKE''NOT ILIKE'
305: "(#{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))})"
306: when '||''||'
307: if args.length > 1
308: "CONCAT(#{args.collect{|a| literal(a)}.join(', ')})"
309: else
310: literal(args.at(0))
311: end
312: when 'B~''B~'
313: "CAST(~#{literal(args.at(0))} AS SIGNED INTEGER)"
314: else
315: super(op, args)
316: end
317: end
Use GROUP BY instead of DISTINCT ON if arguments are provided.
# File lib/sequel/adapters/shared/mysql.rb, line 320
320: def distinct(*args)
321: args.empty? ? super : group(*args)
322: end
Return a cloned dataset which will use LOCK IN SHARE MODE to lock returned rows.
# File lib/sequel/adapters/shared/mysql.rb, line 325
325: def for_share
326: lock_style(:share)
327: end
Adds full text filter
# File lib/sequel/adapters/shared/mysql.rb, line 330
330: def full_text_search(cols, terms, opts = {})
331: filter(full_text_sql(cols, terms, opts))
332: end
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.
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 370
370: def insert_ignore
371: clone(:insert_ignore=>true)
372: 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 346
346: def join_table(type, table, expr=nil, table_alias={})
347: type = :inner if (type == :cross) && !expr.nil?
348: raise(Sequel::Error, "MySQL doesn't support FULL OUTER JOIN") if type == :full_outer
349: super(type, table, expr, table_alias)
350: end
Transforms :natural_inner to NATURAL LEFT JOIN and straight to STRAIGHT_JOIN.
# File lib/sequel/adapters/shared/mysql.rb, line 354
354: def join_type_sql(join_type)
355: case join_type
356: when :straight then 'STRAIGHT_JOIN'
357: when :natural_inner then 'NATURAL LEFT JOIN'
358: else super
359: end
360: end
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.
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 393
393: def on_duplicate_key_update(*args)
394: clone(:on_duplicate_key_update => args)
395: 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 438
438: def supports_timestamp_usecs?
439: false
440: end