Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Perl Modules

    MySQL::Packet 0.2007054

    Download button

    No screenshots available
    Downloads: 378  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    Fair (2.0/5)
    1 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Tavin Cole | More programs
    Perl Artistic License / FREE
    November 9th, 2007, 03:05 GMT
    ROOT / Programming / Perl Modules

     Read user reviews (0)  Refer to a friend  Subscribe

    MySQL::Packet description

    MySQL::Packet allows to encode and decode the MySQL binary protocol.

    MySQL::Packet allows to encode and decode the MySQL binary protocol.

    SYNOPSIS

    Sorry for the absurdly verbose synopsis. I don't have a proper example script for you at the moment.

    use MySQL::Packet qw(:debug); # dumping packet contents etc.
    use MySQL::Packet qw(:test :decode); # decoding subs
    use MySQL::Packet qw(:encode); # encoding subs

    use MySQL::Packet qw(:COM :CLIENT :SERVER); # constants

    my $packet;
    my $greeting;
    my $result;
    my $field_end;

    my $mysql_socket = whatever_i_do_to_connect();

    while (read $mysql_socket, $_, 1000, length) {
    if (not $packet) {
    my $_packet = {};
    my $rc = mysql_decode_header $_packet;
    if ($rc < 0) {
    die 'bad header';
    }
    elsif ($rc > 0) {
    $packet = $_packet;
    redo;
    }
    }
    elsif (not $greeting) {
    my $rc = mysql_decode_greeting $_packet;
    if ($rc < 0) {
    die 'bad greeting';
    }
    elsif ($rc > 0) {
    mysql_debug_packet $packet;
    $greeting = $packet;
    undef $packet;
    send_client_auth();
    redo;
    }
    }
    elsif (not $result) {
    my $rc = mysql_decode_result $packet;
    if ($rc < 0) {
    die 'bad result';
    }
    elsif ($rc > 0) {
    mysql_debug_packet $packet;
    if ($packet->{error}) {
    die 'the server hates me';
    }
    elsif ($packet->{end}) {
    die 'this should never happen';
    }
    else {
    if ($packet->{field_count}) {
    $result = $packet;
    # fields and rows to come
    }
    elsif (not $packet->{server_status} & SERVER_MORE_RESULTS_EXISTS) {
    # that's that..
    send_some_query();
    }
    }
    undef $packet;
    redo;
    }
    }
    elsif (not $field_end) {
    my $rc = do {
    (mysql_test_var $packet}) ? (mysql_decode_field $packet)
    : (mysql_decode_result $packet)
    };
    if ($rc < 0) {
    die 'bad field packet';
    }
    elsif ($rc > 0) {
    mysql_debug_packet $packet;
    if ($packet->{error}) {
    die 'the server hates me';
    }
    elsif ($packet->{end}) {
    $field_end = $packet;
    }
    else {
    do_something_with_field_metadata($packet);
    }
    undef $packet;
    redo;
    }
    }
    else {
    my $rc = do {
    (mysql_test_var $packet ? (mysql_decode_row $packet)
    : (mysql_decode_result $packet)
    };
    if ($rc < 0) {
    die 'bad row packet';
    }
    elsif ($rc > 0) {
    mysql_debug_packet $packet;
    if ($packet->{error}) {
    die 'the server hates me';
    }
    elsif ($packet->{end}) {
    undef $result;
    undef $field_end;
    unless ($packet->{server_status} & SERVER_MORE_RESULTS_EXISTS) {
    # that's that..
    send_some_query();
    }
    }
    else {
    my @row = @{ $packet->{row} };
    do_something_with_row_data(@row);
    }
    undef $packet;
    redo;
    }
    }
    }

    sub send_client_auth {
    my $flags = CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | CLIENT_PROTOCOL_41 | CLIENT_TRANSACTIONS | CLIENT_SECURE_CONNECTION;
    $flags |= CLIENT_CONNECT_WITH_DB if $i_want_to;
    my $pw_crypt = mysql_crypt 'my_password', $greeting->{crypt_seed};
    my $packet_body = mysql_encode_client_auth (
    $flags, # $client_flags
    0x01000000, # $max_packet_size
    $greeting->{server_lang}, # $charset_no
    'my_username', # $username
    $pw_crypt, # $pw_crypt
    'my_database', # $database
    );
    my $packet_head = mysql_encode_header $packet_body, 1;
    print $mysql_socket $packet_head, $packet_body;
    }

    sub send_some_query {
    my $packet_body = mysql_encode_com_query 'SELECT * FROM foo';
    my $packet_head = mysql_encode_header $packet_body;
    print $mysql_socket $packet_head, $packet_body;
    }

    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    encode MySQL binary | decode MySQL binary | Perl module | encode | decode | MySQL

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM