possible problem on 64 bit machines with TMySQLStatement

From: Maximilien Fechner <maximilien.fechner_at_cea.fr>
Date: Thu, 26 Feb 2009 17:04:39 +0100


Dear Rooters,

I have identified what seems to be a bug in the TMySQLStatement code. In "TMySQLStatement::ConvertToString", I see the following lines (root 5.22 pro version):

 case MYSQL_TYPE_LONG:

         if (sig) snprintf(buf,100,"%ld",*((long*) addr));
             else snprintf(buf,100,"%lu",*((unsigned long*) addr));
         break;
      case MYSQL_TYPE_LONGLONG:
         if (sig) snprintf(buf,100,"%lld",*((long long*) addr)); else
                  snprintf(buf,100,"%llu",*((unsigned long long*) addr));

However, on my laptop (32 bits, Fedora10, gcc4.3), sizeof(long) is 4 bytes, while on a 64 bit machine (SL4, gcc 3.4.6), sizeof(long) is 8 bytes.
Hence the conversion from a "MYSQL_TYPE_LONG" to a string is quite different on 64 bit machines.
I have tested this with a very simple script (attached) on both architectures, and I do get different answers... the code seems to be meaningful only on 32 bit machines. The data base I tested this with had 3 fields and only the third one was meaningful in my example.
The call to GetString returns a wrong value for integers on the 64 bit machine I tested.
I used root 5.22 in both places.
Would it be possible for you to confirm this, and if confirmed, fix the problem ?
The "GetString" code is heavily used in the software that I was given and this is causing many problems.

Thanking you in advance,
Maximilien Fechner

Received on Thu Feb 26 2009 - 17:04:47 CET

This archive was generated by hypermail 2.2.0 : Thu Feb 26 2009 - 17:50:01 CET