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