CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: DBI:
Cannot make query to work on blob

 



ningji
User

Feb 27, 2015, 8:31 AM

Post #1 of 1 (8287 views)
Cannot make query to work on blob Can't Post

Hi everyone, i'm learning sqlite3/DBI/blob, can someone help me with the query on blob data ?

1. in our c code, we insert blob data to the table,
memcpy(pBuf, lpBlob->lpb, iLen);
printf("\n----------dbgdbg---------------\n");
for(int i=0; i<iLen; i++) printf(" %x", pBuf);
printf("\n-------------------------\n");

rc = sqlite3_bind_blob(pStmt, idxParam, pBuf, iLen, SQLITE_STATIC);

so i do see this
----------dbgdbg---------------
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22

should be 40 bytes.

2. Now my 1st script,
after exec "select * from table", i convert this field to readable string.
$myData =~ s/(.)/sprintf("%02x", ord($rawDataFromSqlSelect))/eg;

so i see this
00000000......000022
which is what i expected.

3. Now the problem is i want to run a query,
sth. like "select * from table where field1 = hex22", just cannot make it work. Basically gets nothing back. No compile error.

Following is my code for your review,

my $binaryData = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x22";
my $cmd = "select * from ".$argTbl." where CHUID = ?";
#my $cmd = "select * from ".$argTbl." where CHUID like ?";

print $cmd."\n";

my $sth = $dbh->prepare($cmd);
#$sth->bind_param(1, $binaryData, {TYPE=>DBI::SQL_BLOB} );
#$sth->bind_param(1, $binaryData, {TYPE=>DBI::SQL_VARCHAR} );
#$sth->bind_param(1, $binaryData, DBI::SQL_VARCHAR);
$sth->bind_param(1, $binaryData, DBI::SQL_BLOB);

$sth->execute();
my $result = $sth->fetchall_arrayref;
foreach my $row (@$result) {
print "@$row\n";
}


Any suggestions pls ? Thank you !


(This post was edited by ningji on Feb 27, 2015, 10:30 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives