dbTalk Databases Forums  

Bug in BLOB on 64bit AMD

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss Bug in BLOB on 64bit AMD in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Erwin
 
Posts: n/a

Default Bug in BLOB on 64bit AMD - 03-20-2005 , 03:24 PM






Hello,

I've found a bug in mysql++, when a BLOB field is used which is not the
only field returned from a query. This happens only when the query is
run on a 64bit machine (AMD64 in my case). To demonstrate, use the following
table with the load_file and cgi_image examples:

CREATE TABLE fax ( id INTEGER AUTO_INCREMENT PRIMARY KEY,
fax BLOB );

execute load_file as usual.

Change cgi_image to return id and fax as a result of the select.

query << "SELECT " << MY_KEY << "," << MY_FIELD << " FROM " << MY_TABLE
<< " WHERE " << MY_KEY << " = " << argv[1];
ResUse res = query.use();
Row row = res.fetch_row();
long unsigned int *jj = res.fetch_lengths();
cout << "Content-length: " << jj[1] << endl << endl;
fwrite(row.raw_data(1), 1, jj[1], stdout);

jj[1] returns a proper length, but raw_data is not correct, and it looks
like a memory dump. I'm having difficulty debugging this, as I cannot
quite find where things go wrong.

Any ideas?

Grtz
Erwin

--
erwin (AT) leastwanted (DOT) nl
I pledge allegiance to the form of science fiction and fantasy and to
the promise for which it stands: one world, polycultural, genetically
engineered, with Internet access for all. -- Tonio Roque

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Chris Frey
 
Posts: n/a

Default Re: Bug in BLOB on 64bit AMD - 03-20-2005 , 04:38 PM






On Sun, Mar 20, 2005 at 10:25:30PM +0100, Erwin wrote:
Quote:
Hello,

I've found a bug in mysql++, when a BLOB field is used which is not the
only field returned from a query. This happens only when the query is
run on a 64bit machine (AMD64 in my case). To demonstrate, use the following
table with the load_file and cgi_image examples:

CREATE TABLE fax ( id INTEGER AUTO_INCREMENT PRIMARY KEY,
fax BLOB );

execute load_file as usual.

Change cgi_image to return id and fax as a result of the select.

query << "SELECT " << MY_KEY << "," << MY_FIELD << " FROM " << MY_TABLE
" WHERE " << MY_KEY << " = " << argv[1];
ResUse res = query.use();
Two things to try:

try query.store() and see if anything changes.

Also, try the plain mysql C API to make sure that this is not a bug in
mysql. Here's some sample code to get you started. It compiles but I've
not run it here. It is based on some code posted earlier on the list.

g++ -o mysql_blob mysql_blob.cc -I/usr/include/mysql -lmysqlclient

mysql_blob.cc:

#include <mysql.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
int rc;
int i;
MYSQL *mysql;

mysql_server_init(0, NULL, NULL);

mysql = mysql_init(NULL);
if (mysql_real_connect(mysql, NULL, NULL, NULL, "", 0, NULL, 0) == NULL) {
printf("error\n");
}
if (mysql_errno(mysql)) {
printf("Error 1: %s\n", mysql_error(mysql));
mysql_close(mysql);
exit(-1);
}

if( mysql_query(mysql, "SELECT fax FROM fax WHERE id = 1") ) {
printf("Error: %s\n", mysql_error(mysql));
mysql_close(mysql);
exit(2);
}

MYSQL_RES *res = mysql_store_result(mysql);
if( res ) {
printf("Error: %s\n", mysql_error(mysql));
mysql_close(mysql);
exit(2);
}

MYSQL_ROW d = mysql_fetch_row(res);
if( d ) {
printf("Error: %s\n", mysql_error(mysql));
mysql_close(mysql);
exit(2);
}

unsigned long *len = mysql_fetch_lengths(res);

printf("Content-length: %lu\n", len[0]);
if( d[0] )
fwrite(d[0], 1, len[0], stdout);
else
printf("NULL!\n");

mysql_free_result(res);

mysql_close(mysql);
mysql_server_end();
}


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #3  
Old   
Erwin
 
Posts: n/a

Default Re: Bug in BLOB on 64bit AMD - 03-21-2005 , 03:00 PM



Hello Chris,

Quote:
Two things to try:

try query.store() and see if anything changes.

Also, try the plain mysql C API to make sure that this is not a bug in
mysql. Here's some sample code to get you started. It compiles but I've
not run it here. It is based on some code posted earlier on the list.
Thanx, but I've solved the issue. There were some casts in connection.h
from unsigned long* to unsigned int* that went wrong. These casts were
already removed in 1.7.32 (I was using 1.7.28), so the issue has been
resolved.

Thank you for your time,
Erwin

--
erwin (AT) leastwanted (DOT) nl
We all enter the world in the same way: naked... screaming... soaked in
blood. But if you live your life right, that kind of thing doesn't have
to stop there.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.