Class: RDBI::Driver::MySQL::Statement
- Inherits:
-
Statement
- Object
- Statement
- RDBI::Driver::MySQL::Statement
- Extended by:
- MethLab
- Defined in:
- lib/rdbi/driver/mysql.rb
Instance Attribute Summary collapse
-
#my_query ⇒ Object
readonly
Returns the value of attribute my_query.
Instance Method Summary collapse
-
#initialize(query, dbh) ⇒ Statement
constructor
A new instance of Statement.
- #new_execution(*binds) ⇒ Object
- #new_modification(*binds) ⇒ Object
Constructor Details
#initialize(query, dbh) ⇒ Statement
Returns a new instance of Statement.
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/rdbi/driver/mysql.rb', line 365 def initialize(query, dbh) super(query, dbh) ep = Epoxy.new(query) @index_map = ep.indexed_binds # FIXME straight c'n'p from postgres, not sure it's needed. query = ep.quote(@index_map.compact.inject({}) { |x,y| x.merge({ y => nil }) }) { |x| '?' } @my_query = dbh.my_conn.prepare(query) # FIXME type maps @output_type_map = RDBI::Type.create_type_hash( RDBI::Type::Out ) manipulate_type_maps prep_finalizer { @my_query.close rescue nil } end |
Instance Attribute Details
#my_query ⇒ Object (readonly)
Returns the value of attribute my_query.
363 364 365 |
# File 'lib/rdbi/driver/mysql.rb', line 363 def my_query @my_query end |
Instance Method Details
#new_execution(*binds) ⇒ Object
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/rdbi/driver/mysql.rb', line 398 def new_execution(*binds) # FIXME move to RDBI::Util or something. hashes, binds = binds.partition { |x| x.kind_of?(Hash) } hash = hashes.inject({}) { |x, y| x.merge(y) } hash.keys.each do |key| if index = @index_map.index(key) binds.insert(index, hash[key]) end end res = @my_query.execute(*binds) columns = [] = res. rescue nil if columns = res..fetch_fields.collect do |col| RDBI::Column.new( col.name.to_sym, map_type(col), map_type(col).to_sym, col.length, col.decimals, !col.is_not_null? ) end end schema = RDBI::Schema.new columns [ Cursor.new(res), schema, @output_type_map ] end |
#new_modification(*binds) ⇒ Object
383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/rdbi/driver/mysql.rb', line 383 def new_modification(*binds) # FIXME move to RDBI::Util or something. hashes, binds = binds.partition { |x| x.kind_of?(Hash) } hash = hashes.inject({}) { |x, y| x.merge(y) } hash.keys.each do |key| if index = @index_map.index(key) binds.insert(index, hash[key]) end end res = @my_query.execute(*binds) return res.affected_rows end |