Class | Sequel::MySQL::Dataset |
In: |
lib/sequel/adapters/mysql.rb
|
Parent: | Sequel::Dataset |
MySQL is different in that it supports prepared statements but not bound variables outside of prepared statements. The default implementation breaks the use of subselects in prepared statements, so extend the temporary prepared statement that this creates with a module that fixes it.
# File lib/sequel/adapters/mysql.rb, line 306 306: def call(type, bind_arguments={}, *values, &block) 307: ps = to_prepared_statement(type, values) 308: ps.extend(CallableStatementMethods) 309: ps.call(bind_arguments, &block) 310: end
Delete rows matching this dataset
# File lib/sequel/adapters/mysql.rb, line 313 313: def delete 314: execute_dui(delete_sql){|c| c.affected_rows} 315: end
Yield all rows matching this dataset. If the dataset is set to split multiple statements, yield arrays of hashes one per statement instead of yielding results for all statements as hashes.
# File lib/sequel/adapters/mysql.rb, line 320 320: def fetch_rows(sql, &block) 321: execute(sql) do |r| 322: i = -1 323: cols = r.fetch_fields.map{|f| [output_identifier(f.name), MYSQL_TYPES[f.type], i+=1]} 324: @columns = cols.map{|c| c.first} 325: if opts[:split_multiple_result_sets] 326: s = [] 327: yield_rows(r, cols){|h| s << h} 328: yield s 329: else 330: yield_rows(r, cols, &block) 331: end 332: end 333: self 334: end
Don‘t allow graphing a dataset that splits multiple statements
# File lib/sequel/adapters/mysql.rb, line 337 337: def graph(*) 338: raise(Error, "Can't graph a dataset that splits multiple result sets") if opts[:split_multiple_result_sets] 339: super 340: end
Insert a new value into this dataset
# File lib/sequel/adapters/mysql.rb, line 343 343: def insert(*values) 344: execute_dui(insert_sql(*values)){|c| c.insert_id} 345: end
Store the given type of prepared statement in the associated database with the given name.
# File lib/sequel/adapters/mysql.rb, line 349 349: def prepare(type, name=nil, *values) 350: ps = to_prepared_statement(type, values) 351: ps.extend(PreparedStatementMethods) 352: if name 353: ps.prepared_statement_name = name 354: db.prepared_statements[name] = ps 355: end 356: ps 357: end
Makes each yield arrays of rows, with each array containing the rows for a given result set. Does not work with graphing. So you can submit SQL with multiple statements and easily determine which statement returned which results.
Modifies the row_proc of the returned dataset so that it still works as expected (running on the hashes instead of on the arrays of hashes). If you modify the row_proc afterward, note that it will receive an array of hashes instead of a hash.
# File lib/sequel/adapters/mysql.rb, line 373 373: def split_multiple_result_sets 374: raise(Error, "Can't split multiple statements on a graphed dataset") if opts[:graph] 375: ds = clone(:split_multiple_result_sets=>true) 376: ds.row_proc = proc{|x| x.map{|h| row_proc.call(h)}} if row_proc 377: ds 378: end