Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: MySQL DBI dealing with hex blob field

by edimusrex (Monk)
on Apr 20, 2015 at 15:44 UTC ( [id://1124043]=note: print w/replies, xml ) Need Help??


in reply to Re: MySQL DBI dealing with hex blob field
in thread MySQL DBI dealing with hex blob field

Yea, that code is wrong, looks like I pasted it from the wrong script I was working on. I am testing a few things and if I have no luck I will repost the current code. Thanks
  • Comment on Re^2: MySQL DBI dealing with hex blob field

Replies are listed 'Best First'.
Re^3: MySQL DBI dealing with hex blob field
by edimusrex (Monk) on Apr 20, 2015 at 16:31 UTC
    unpack was the key to this. I figured it out. The following code is working as expected. Thank you. Here's a snippet
    #!/usr/bin/perl use warnings; use strict; use IO::Async::Loop; use Net::Async::CassandraCQL; use Protocol::CassandraCQL qw( CONSISTENCY_QUORUM ); use DBI(); use DateTime qw(); use Getopt::Long; use feature qw(say); use MIME::Lite; use File::Basename; use Term::ANSIColor; use utf8; use Text::Unidecode; use bigint; my $database = "xxxx"; my $host = "xxxx"; my $port = xxxx; my $user = "xxxx"; my $password = "xxxx"; my $mysqlTable = "xxxx"; my $dsn = "DBI:mysql:database=$database;host=$host;port=$port"; my $dbh = DBI->connect( $dsn, $user, $password ) || warn "Failed to co +nnect to the database: " . DBI->errstr; my $table = "accounts"; my $keyspace = "loop_non_hadoop_test"; my $loop = IO::Async::Loop->new; my $cass = Net::Async::CassandraCQL->new( host => $host, keyspace => $keyspace, default_consistency => CONSISTENCY_QUORUM, ); $loop->add( $cass ); $cass->connect->get; my $sql = "SELECT `key` FROM `users`"; my $keys = &retrieveData($sql,1); foreach my $get (@{$keys}) { my $hex = unpack('H*', $get->{key}); my $get_stmt = $cass->prepare( 'SELECT "accessedDt" FROM accounts +WHERE key =0x'.$hex )->get; my ( undef, $result ) = $get_stmt->execute( [] )->get; foreach my $row ($result->rows_hash) { my $key_find = ($row->{"accessedDt"}); if (defined $key_find) { say "I found this date --- $key_find"; } } } sub retrieveData { my $value; my $sth = $dbh->prepare($_[0]); $sth->execute(); if ($_[1]) { $value = $sth->fetchall_arrayref({}); } else { $value = $sth->fetchrow_array(); } return $value; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1124043]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-25 18:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found