| 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 233
233: def complex_expression_sql(op, args)
234: case op
235: when :~, '!~''!~', '~*''~*', '!~*''!~*', :LIKE, 'NOT LIKE''NOT LIKE', :ILIKE, 'NOT ILIKE''NOT ILIKE'
236: "(#{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))})"
237: when '||''||'
238: if args.length > 1
239: "CONCAT(#{args.collect{|a| literal(a)}.join(', ')})"
240: else
241: literal(args.at(0))
242: end
243: else
244: super(op, args)
245: end
246: end
Use GROUP BY instead of DISTINCT ON if arguments are provided.
# File lib/sequel/adapters/shared/mysql.rb, line 249
249: def distinct(*args)
250: args.empty? ? super : group(*args)
251: end
Return a cloned dataset which will use LOCK IN SHARE MODE to lock returned rows.
# File lib/sequel/adapters/shared/mysql.rb, line 254
254: def for_share
255: lock_style(:share)
256: end
Adds full text filter
# File lib/sequel/adapters/shared/mysql.rb, line 259
259: def full_text_search(cols, terms, opts = {})
260: filter(full_text_sql(cols, terms, opts))
261: 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 299
299: def insert_ignore
300: clone(:insert_ignore=>true)
301: 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 275
275: def join_table(type, table, expr=nil, table_alias={})
276: type = :inner if (type == :cross) && !expr.nil?
277: raise(Sequel::Error, "MySQL doesn't support FULL OUTER JOIN") if type == :full_outer
278: super(type, table, expr, table_alias)
279: end
Transforms :natural_inner to NATURAL LEFT JOIN and straight to STRAIGHT_JOIN.
# File lib/sequel/adapters/shared/mysql.rb, line 283
283: def join_type_sql(join_type)
284: case join_type
285: when :straight then 'STRAIGHT_JOIN'
286: when :natural_inner then 'NATURAL LEFT JOIN'
287: else super
288: end
289: 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 322
322: def on_duplicate_key_update(*args)
323: clone(:on_duplicate_key_update => args)
324: 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 367
367: def supports_timestamp_usecs?
368: false
369: end