AnyEvent-MySQL
view release on metacpan or search on metacpan
lib/AnyEvent/MySQL.pm view on Meta::CPAN
$wwdbh->{_}[CONN_STATEi] = IDLE_CONN;
_report_error($wwdbh, '', 2013, 'Lost connection to MySQL server during query');
if( $wwdbh->{_}[FALLBACKi] ) {
$wwdbh->{_}[FALLBACKi]();
}
}
},
);
AnyEvent::MySQL::Imp::do_auth($wdbh->{_}[HDi], $wdbh->{Username}, $wdbh->{_}[AUTHi], $param->{database}, sub {
my($success, $err_num_and_msg, $thread_id) = @_;
return if !$wdbh;
if( $success ) {
$wdbh->{mysql_thread_id} = $thread_id;
$cb->($wdbh, guard {
_process_task($wdbh) if $wdbh;
});
}
else {
warn "MySQL auth error: $err_num_and_msg retry later.";
undef $wdbh->{_}[HDi];
undef $wdbh->{_}[CONNi];
_reconnect($wdbh) if $wdbh;
}
lib/AnyEvent/MySQL/Imp.pm view on Meta::CPAN
CLIENT_SSL => 2048, # Switch to SSL after handshake *
CLIENT_IGNORE_SIGPIPE => 4096, # IGNORE sigpipes
CLIENT_TRANSACTIONS => 8192, # Client knows about transactions +
CLIENT_RESERVED => 16384, # Old flag for 4.1 protocol
CLIENT_SECURE_CONNECTION => 32768, # New 4.1 authentication * +
CLIENT_MULTI_STATEMENTS => 65536, # Enable/disable multi-stmt support * +
CLIENT_MULTI_RESULTS => 131072, # Enable/disable multi-results * +
};
use constant {
COM_SLEEP => "\x00", # (none, this is an internal thread state)
COM_QUIT => "\x01", # mysql_close
COM_INIT_DB => "\x02", # mysql_select_db
COM_QUERY => "\x03", # mysql_real_query
COM_FIELD_LIST => "\x04", # mysql_list_fields
COM_CREATE_DB => "\x05", # mysql_create_db (deprecated)
COM_DROP_DB => "\x06", # mysql_drop_db (deprecated)
COM_REFRESH => "\x07", # mysql_refresh
COM_SHUTDOWN => "\x08", # mysql_shutdown
COM_STATISTICS => "\x09", # mysql_stat
COM_PROCESS_INFO => "\x0a", # mysql_list_processes
COM_CONNECT => "\x0b", # (none, this is an internal thread state)
COM_PROCESS_KILL => "\x0c", # mysql_kill
COM_DEBUG => "\x0d", # mysql_dump_debug_info
COM_PING => "\x0e", # mysql_ping
COM_TIME => "\x0f", # (none, this is an internal thread state)
COM_DELAYED_INSERT => "\x10", # (none, this is an internal thread state)
COM_CHANGE_USER => "\x11", # mysql_change_user
COM_BINLOG_DUMP => "\x12", # sent by the slave IO thread to request a binlog
COM_TABLE_DUMP => "\x13", # LOAD TABLE ... FROM MASTER (deprecated)
COM_CONNECT_OUT => "\x14", # (none, this is an internal thread state)
COM_REGISTER_SLAVE => "\x15", # sent by the slave to register with the master (optional)
COM_STMT_PREPARE => "\x16", # mysql_stmt_prepare
COM_STMT_EXECUTE => "\x17", # mysql_stmt_execute
COM_STMT_SEND_LONG_DATA => "\x18", # mysql_stmt_send_long_data
COM_STMT_CLOSE => "\x19", # mysql_stmt_close
COM_STMT_RESET => "\x1a", # mysql_stmt_reset
COM_SET_OPTION => "\x1b", # mysql_set_server_option
COM_STMT_FETCH => "\x1c", # mysql_stmt_fetch
};
lib/AnyEvent/MySQL/Imp.pm view on Meta::CPAN
push @row, \@cell;
$fetch_row->();
}
});
};
$fetch_row->();
}
});
}
=head2 do_auth($hd, $username, [$password, [$database,]] $cb->($success, $err_num_and_msg, $thread_id))
=cut
sub do_auth {
my $cb = ref($_[-1]) eq 'CODE' ? pop : sub {};
my($hd, $username, $password, $database) = @_;
recv_packet($hd, sub {
if( DEV ) {
my $hex = $_[0];
$hex =~ s/(.)/sprintf"%02X ",ord$1/ges;
my $ascii = $_[0];
$ascii =~ s/([^\x20-\x7E])/./g;
warn $hex, $ascii;
}
my $proto_ver = take_num($_[0], 1); warn "proto_ver:$proto_ver" if DEV;
my $server_ver = take_zstr($_[0]); warn "server_ver:$server_ver" if DEV;
my $thread_id = take_num($_[0], 4); warn "thread_id:$thread_id" if DEV;
my $scramble_buff = take_str($_[0], 8).substr($_[0], 19, 12); warn "scramble_buff:$scramble_buff" if DEV;
my $filler = take_num($_[0], 1); warn "filler:$filler" if DEV;
my $server_cap = take_num($_[0], 2);
my $server_lang = take_num($_[0], 1); warn "server_lang:$server_lang" if DEV;
my $server_status = take_num($_[0], 2); warn "server_status:$server_status" if DEV;
$server_cap += take_num($_[0], 2) << 16;
if( DEV ) {
warn "server_cap:";
warn " CLIENT_LONG_PASSWORD" if( $server_cap & CLIENT_LONG_PASSWORD );
warn " CLIENT_FOUND_ROWS" if( $server_cap & CLIENT_FOUND_ROWS );
lib/AnyEvent/MySQL/Imp.pm view on Meta::CPAN
}
else {
my $stage1_hash = sha1($password);
put_lcs($packet, sha1($scramble_buff.sha1($stage1_hash)) ^ $stage1_hash); # scramble buff
}
put_zstr($packet, $database); # database name
send_packet($hd, 1, $packet);
recv_packet($hd, sub {
if( parse_ok($_[0]) ) {
$cb->(1, undef, $thread_id);
}
else {
my($errno, $sqlstate, $message) = parse_error($_[0]);
warn "$errno [$sqlstate] $message" if DEV;
$cb->(0, dualvar($errno, $message));
}
});
});
}
( run in 0.410 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )