AnyEvent-MySQL

 view release on metacpan or  search on metacpan

lib/AnyEvent/MySQL/Imp.pm  view on Meta::CPAN

    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
};

use constant {
    MYSQL_TYPE_BIT                  => 16,
    MYSQL_TYPE_BLOB                 => 252,
    MYSQL_TYPE_DATE                 => 10,
    MYSQL_TYPE_DATETIME             => 12,
    MYSQL_TYPE_DECIMAL              => 0,
    MYSQL_TYPE_DOUBLE               => 5,
    MYSQL_TYPE_ENUM                 => 247,
    MYSQL_TYPE_FLOAT                => 4,
    MYSQL_TYPE_GEOMETRY             => 255,
    MYSQL_TYPE_INT24                => 9,
    MYSQL_TYPE_LONG                 => 3,
    MYSQL_TYPE_LONGLONG             => 8,
    MYSQL_TYPE_LONG_BLOB            => 251,
    MYSQL_TYPE_MEDIUM_BLOB          => 250,
    MYSQL_TYPE_NEWDATE              => 14,
    MYSQL_TYPE_NEWDECIMAL           => 246,
    MYSQL_TYPE_NULL                 => 6,
    MYSQL_TYPE_SET                  => 248,
    MYSQL_TYPE_SHORT                => 2,
    MYSQL_TYPE_STRING               => 254,
    MYSQL_TYPE_TIME                 => 11,
    MYSQL_TYPE_TIMESTAMP            => 7,
    MYSQL_TYPE_TINY                 => 1,
    MYSQL_TYPE_TINY_BLOB            => 249,
    MYSQL_TYPE_VARCHAR              => 15,
    MYSQL_TYPE_VAR_STRING           => 253,
    MYSQL_TYPE_YEAR                 => 13,
};

use constant {
    NOT_NULL_FLAG           => 1,                 # Field can't be NULL
    PRI_KEY_FLAG            => 2,                 # Field is part of a primary key
    UNIQUE_KEY_FLAG         => 4,                 # Field is part of a unique key
    MULTIPLE_KEY_FLAG       => 8,                 # Field is part of a key
    BLOB_FLAG               => 16,                # Field is a blob
    UNSIGNED_FLAG           => 32,                # Field is unsigned
    ZEROFILL_FLAG           => 64,                # Field is zerofill
    BINARY_FLAG             => 128,               # Field is binary
    ENUM_FLAG               => 256,               # Field is an enum
    AUTO_INCREMENT_FLAG     => 512,               # Field is a autoincrement field
    TIMESTAMP_FLAG          => 1024,              # Field is a timestamp
    SET_FLAG                => 2048,              # Field is a set
    NO_DEFAULT_VALUE_FLAG   => 4096,              # Field doesn't have default value
    ON_UPDATE_NOW_FLAG      => 8192,              # Field is set to NOW on UPDATE
    NUM_FLAG                => 32768,             # Field is num (for clients)
    PART_KEY_FLAG           => 16384,             # Intern; Part of some key
    GROUP_FLAG              => 32768,             # Intern: Group field
    UNIQUE_FLAG             => 65536,             # Intern: Used by sql_yacc
    BINCMP_FLAG             => 131072,            # Intern: Used by sql_yacc
    GET_FIXED_FIELDS_FLAG   => (1<<18),           # Used to get fields in item tree
    FIELD_IN_PART_FUNC_FLAG => (1<<19),           # Field part of partition func
    FIELD_IN_ADD_INDEX      => (1<<20),           # Intern: Field used in ADD INDEX
    FIELD_IS_RENAMED        => (1<<21),           # Intern: Field is being renamed
};

use constant {
    RES_OK => 0,
    RES_ERROR => 255,
    RES_RESULT => 1,
    RES_PREPARE => 2,
};

=head2 $str = take_zstring($data(modified))
null terminated string
=cut
sub take_zstr {
    $_[0] =~ s/(.*?)\x00//s;
    return $1;
}

=head2 $num = take_lcb($data(modifed))
length coded binary
=cut
sub take_lcb {
    my $fb = substr($_[0], 0, 1, '');
    if( $fb le "\xFA" ) { # 0-250
        return ord($fb);
    }
    if( $fb eq "\xFB" ) { # 251
        return undef;
    }
    if( $fb eq "\xFC" ) { # 252
        return unpack('v', substr($_[0], 0, 2, ''));
    }
    if( $fb eq "\xFD" ) { # 253
        return unpack('V', substr($_[0], 0, 3, '')."\x00");
    }
    if( $fb eq "\xFE" ) { # 254
        return unpack('Q<', substr($_[0], 0, 8, ''));
    }
    return undef; # error
}

=head2 $str = take_lcs($data(modified))
length coded string
=cut
sub take_lcs {
    my $len = &take_lcb;
    if( defined $len ) {
        return substr($_[0], 0, $len, '');
    }
    else {
        return undef;
    }
}

=head2 $num = take_num($data(modified), $len)
=cut
sub take_num {
    return unpack('V', substr($_[0], 0, $_[1], '')."\x00\x00\x00");
}

=head2 $str = take_str($data(modified), $len)



( run in 1.548 second using v1.01-cache-2.11-cpan-39bf76dae61 )