0
require File.dirname(__FILE__) + '/asymy'
0
-# XXX for debugging --- ditch both these methods when we're done
0
-class Fixnum; def printable?; self >= 0x20 && self <= 0x7e; end; end
0
- if RUBY_VERSION[0..2] != '1.9'
0
- def hexdump(capture=false)
0
- pad = (15 - rem) if rem < 16
0
- sio.write(("0" * (8 - (x = off.to_s(16)).size)) + x + " ")
0
- sio.write(("0" * (2 - x.size)) + x + " ")
0
- sio.write(" ") if i == 7
0
- sio.write("-- " * pad) if pad > 0
0
- sio.write(" |#{ pbuf }|\n")
0
# I'm thinking, one per connection
0
@@ -82,8 +34,18 @@ module Asymy
0
# block argument that receives the results, in two arguments, fields (an array of hashes)
0
# and rows (an array of strings)
0
- @queue << [cmd.extend(StringX), block]
0
+ @queue << [cmd.extend(StringX), block, Commands::QUERY]
0
+ def prepare(cmd, &block)
0
+ @queue << [cmd.extend(StringX), block, Commands::STMT_PREPARE]
0
+ def execute_prepared(args, &block)
0
+ @queue << [args, block, Commands::STMT_EXECUTE]
0
# no user-servicable parts below (attrs used to communicate with module)
0
@@ -125,6 +87,9 @@ module Asymy
0
+ def packet.eof?; self[0].ord == 0xfe; end
0
+ def packet.ok?; self[0].ord == 0x00; end
0
handle_preauth(num, Packets::Greeting.new(packet))
0
@@ -145,23 +110,47 @@ module Asymy
0
# XXX just ignore for now
0
self.state = :awaiting_fields
0
- if packet
[0].ord == 0xfe0
self.state = :awaiting_rows
0
handle_field(num, Packets::Field.new(packet))
0
- if packet
[0].ord == 0xfe0
@cb.call(@fields, @rows)
0
# rows have a variable number of variable-length strings, and no other
0
# structure, so just hand the raw data off.
0
handle_row(num, packet)
0
+ when :awaiting_statement_handle
0
+ handle_statement_handle(num, Packets::PrepareOk.new(packet))
0
+ # XXX handle this case
0
+ when :awaiting_prepared_params
0
+ @state = :waiting_prepared_fields
0
+ # I cannot for the life of me figure out what I'm supposed
0
+ # to do with these --- using mysql-ruby, I can't get them
0
+ # to change based on their type. Why does MySQL send them?
0
+ # I figured it'd be to let me enforce types on the params.
0
+ when :awaiting_prepared_fields
0
+ @cb, @stmt, @expect_params, @expect_columns = nil, nil, nil, nil
0
+ # I guess I could cache these? But why bother? MySQL is just
0
+ # going to send them again. This protocol confuses and infuriates us!
0
@@ -169,14 +158,32 @@ module Asymy
0
+ def ready!; self.state = :ready; inject; end
0
+ # this is going to get untidy real fast XXX
0
if(now = self.queue.slice!(0))
0
- self.state = :awaiting_result_set
0
- p = Packets::Command.new
0
- p.command = Commands::QUERY
0
+ self.state = :awaiting_result_set
0
+ p = Packets::Command.new
0
+ p.command = Commands::QUERY
0
+ when Commands::STMT_PREPARE
0
+ self.state = :awaiting_statement_handle
0
+ p = Packets::Prepare.new
0
+ when Commands::STMT_EXECUTE
0
@@ -206,8 +213,7 @@ module Asymy
0
def handle_postauth(num, ok)
0
def handle_field(num, field)
0
@@ -233,11 +239,23 @@ module Asymy
0
+ def handle_statement_handle(num, ok)
0
+ @stmt = PreparedStatement.new(:backpointer => @bp,
0
+ :handle => ok.stmt_id)
0
+ @expect_params = @stmt.parameters
0
+ @expect_columns = @stmt.columns
0
+ @state = :awaiting_prepared_params
0
+ @state = :awaiting_prepared_columns
0
def method_missing(meth, *args); @bp.send(meth, *args); end
0
- EventMachine::connect(@target, @port, Session) {|c| c.bp = self
}
0
+ EventMachine::connect(@target, @port, Session) {|c| c.bp = self
; @fp = c;}
Comments
No one has commented yet.