Class: Sequel::MySQL::Dataset
- Defined in:
- lib/sequel/adapters/mysql.rb
Constant Summary collapse
- TRUE =
'1'- FALSE =
'0'
Constants inherited from Dataset
Dataset::NOTIMPL_MSG, Dataset::STOCK_TRANSFORMS
Constants included from Dataset::Convenience
Dataset::Convenience::COMMA_SEPARATOR, Dataset::Convenience::MAGIC_METHODS, Dataset::Convenience::MUTATION_RE, Dataset::Convenience::NAKED_HASH
Constants included from Dataset::SQL
Dataset::SQL::ALIASED_REGEXP, Dataset::SQL::AND_SEPARATOR, Dataset::SQL::COMMA_SEPARATOR, Dataset::SQL::DATE_FORMAT, Dataset::SQL::JOIN_TYPES, Dataset::SQL::NULL, Dataset::SQL::QUALIFIED_REGEXP, Dataset::SQL::QUESTION_MARK, Dataset::SQL::STOCK_COUNT_OPTS, Dataset::SQL::TIMESTAMP_FORMAT, Dataset::SQL::WILDCARD
Constants included from Dataset::Sequelizer
Dataset::Sequelizer::JOIN_AND, Dataset::Sequelizer::JOIN_COMMA
Instance Attribute Summary
Attributes inherited from Dataset
Attributes included from Dataset::Convenience
#current_page, #page_count, #page_size, #pagination_record_count
Instance Method Summary collapse
- #array_tuples_fetch_rows(sql, &block) ⇒ Object
- #delete(opts = nil) ⇒ Object
- #fetch_rows(sql) ⇒ Object
- #insert(*values) ⇒ Object
- #literal(v) ⇒ Object
- #match_expr(l, r) ⇒ Object
- #quote_column_ref(c) ⇒ Object
- #update(*args, &block) ⇒ Object
-
#update_sql(values, opts = nil) ⇒ Object
MySQL supports ORDER and LIMIT clauses in UPDATE statements.
Methods inherited from Dataset
#<<, #clone_merge, #columns, dataset_classes, #each, #extend_with_destroy, inherited, #initialize, #model_classes, #naked, #polymorphic_key, #remove_row_proc, #set, #set_model, #set_options, #set_row_proc, #transform, #transform_load, #transform_save, #update_each_method
Methods included from Dataset::Convenience
#[], #[]=, #avg, #create_or_replace_view, #create_view, #current_page_record_count, #current_page_record_range, #each_hash, #empty?, #first, #group_and_count, #interval, #last, #magic_method_missing, #map, #max, #method_missing, #min, #multi_insert, #next_page, #page_range, #paginate, #prev_page, #print, #query, #range, #set_pagination_info, #single_record, #single_value, #sum, #to_csv, #to_hash
Methods included from Dataset::SQL
#and, #column_list, #count, #delete_sql, #except, #exclude, #exists, #expression_list, #filter, #from, #full_outer_join, #group, #having, #inner_join, #insert_multiple, #insert_sql, #intersect, #invert_order, #join_expr, #join_table, #left_outer_join, #limit, #or, #order, #qualified_column_name, #reverse_order, #right_outer_join, #select, #select_sql, #source_list, #to_table_reference, #union, #uniq, #where
Methods included from Dataset::Sequelizer
#call_expr, #compare_expr, #eval_expr, #ext_expr, #fcall_expr, #iter_expr, #proc_to_sql, #pt_expr, #replace_dvars, #unfold_each_expr, #value_to_parse_tree, #vcall_expr
Methods included from Enumerable
Constructor Details
This class inherits a constructor from Sequel::Dataset
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Sequel::Dataset::Convenience
Instance Method Details
#array_tuples_fetch_rows(sql, &block) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/sequel/adapters/mysql.rb', line 255 def array_tuples_fetch_rows(sql, &block) @db.synchronize do r = @db.execute_select(sql) begin @columns = r.columns r.each_array(&block) ensure r.free end end self end |
#delete(opts = nil) ⇒ Object
238 239 240 |
# File 'lib/sequel/adapters/mysql.rb', line 238 def delete(opts = nil) @db.execute_affected(delete_sql(opts)) end |
#fetch_rows(sql) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/sequel/adapters/mysql.rb', line 242 def fetch_rows(sql) @db.synchronize do r = @db.execute_select(sql) begin @columns = r.columns r.each_hash {|row| yield row} ensure r.free end end self end |
#insert(*values) ⇒ Object
230 231 232 |
# File 'lib/sequel/adapters/mysql.rb', line 230 def insert(*values) @db.execute_insert(insert_sql(*values)) end |
#literal(v) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/sequel/adapters/mysql.rb', line 187 def literal(v) case v when LiteralString v when String "'#{v.gsub(/'|\\/, '\&\&')}'" when true TRUE when false FALSE else super end end |
#match_expr(l, r) ⇒ Object
202 203 204 205 206 207 208 209 210 211 |
# File 'lib/sequel/adapters/mysql.rb', line 202 def match_expr(l, r) case r when Regexp r.casefold? ? \ "(#{literal(l)} REGEXP #{literal(r.source)})" : "(#{literal(l)} REGEXP BINARY #{literal(r.source)})" else super end end |
#quote_column_ref(c) ⇒ Object
182 |
# File 'lib/sequel/adapters/mysql.rb', line 182 def quote_column_ref(c); "`#{c}`"; end |
#update(*args, &block) ⇒ Object
234 235 236 |
# File 'lib/sequel/adapters/mysql.rb', line 234 def update(*args, &block) @db.execute_affected(update_sql(*args, &block)) end |
#update_sql(values, opts = nil) ⇒ Object
MySQL supports ORDER and LIMIT clauses in UPDATE statements.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/sequel/adapters/mysql.rb', line 214 def update_sql(values, opts = nil) sql = super opts = opts ? @opts.merge(opts) : @opts if order = opts[:order] sql << " ORDER BY #{column_list(order)}" end if limit = opts[:limit] sql << " LIMIT #{limit}" end sql end |