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 315 315: def call(type, bind_arguments={}, *values, &block) 316: ps = to_prepared_statement(type, values) 317: ps.extend(CallableStatementMethods) 318: ps.call(bind_arguments, &block) 319: end
Delete rows matching this dataset
# File lib/sequel/adapters/mysql.rb, line 322 322: def delete 323: execute_dui(delete_sql){|c| return c.affected_rows} 324: 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 329 329: def fetch_rows(sql, &block) 330: execute(sql) do |r| 331: i = -1 332: cols = r.fetch_fields.map do |f| 333: # Pretend tinyint is another integer type if its length is not 1, to 334: # avoid casting to boolean if Sequel::MySQL.convert_tinyint_to_bool 335: # is set. 336: type_proc = f.type == 1 && f.length != 1 ? MYSQL_TYPES[2] : MYSQL_TYPES[f.type] 337: [output_identifier(f.name), type_proc, i+=1] 338: end 339: @columns = cols.map{|c| c.first} 340: if opts[:split_multiple_result_sets] 341: s = [] 342: yield_rows(r, cols){|h| s << h} 343: yield s 344: else 345: yield_rows(r, cols, &block) 346: end 347: end 348: self 349: end
Don‘t allow graphing a dataset that splits multiple statements
# File lib/sequel/adapters/mysql.rb, line 352 352: def graph(*) 353: raise(Error, "Can't graph a dataset that splits multiple result sets") if opts[:split_multiple_result_sets] 354: super 355: end
Insert a new value into this dataset
# File lib/sequel/adapters/mysql.rb, line 358 358: def insert(*values) 359: execute_dui(insert_sql(*values)){|c| return c.insert_id} 360: end
Store the given type of prepared statement in the associated database with the given name.
# File lib/sequel/adapters/mysql.rb, line 364 364: def prepare(type, name=nil, *values) 365: ps = to_prepared_statement(type, values) 366: ps.extend(PreparedStatementMethods) 367: if name 368: ps.prepared_statement_name = name 369: db.prepared_statements[name] = ps 370: end 371: ps 372: 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 388 388: def split_multiple_result_sets 389: raise(Error, "Can't split multiple statements on a graphed dataset") if opts[:graph] 390: ds = clone(:split_multiple_result_sets=>true) 391: ds.row_proc = proc{|x| x.map{|h| row_proc.call(h)}} if row_proc 392: ds 393: end