Recent

Author Topic: write once compile anywhere: mysqlclient  (Read 2850 times)

hakelm

  • Full Member
  • ***
  • Posts: 124
write once compile anywhere: mysqlclient
« on: April 10, 2014, 09:13:03 pm »
Using libmysqlclient I have written a program for querying a MySQL database.
It compiles and runs without flaws under Linux i386 (Ubuntu) and Windows xp, 7, 8.1. Under Ubuntu AMD-64 queries, however, truncates fields and also returns empty fields.
Has anyone else seen this behaviour?
For the mysql-unit I use mysql.pp (Copyright (C) 2000 MySQL AB). I have both tried cdecl and stdcall for the function prototypes but this doesn't seem to matter.
My AMD-64 library is /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 from 21/1 2014.
Any tip is appreciated.
H


Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1251
Re: write once compile anywhere: mysqlclient
« Reply #1 on: April 11, 2014, 03:02:10 am »
Both SQLDB and ZEOS provide working connections to MySQL.   I'm presuming you're writing your own for a reason, however you could look into their code, see how they do it...
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9020
  • FPC developer.
Re: write once compile anywhere: mysqlclient
« Reply #2 on: April 11, 2014, 11:41:04 am »
mysql protocol etc are highly versioned. Make sure your mysql unit is prepared for 64-bit mysql and for the correct version.

Or use one of the supported versions that Mike named.

LacaK

  • Hero Member
  • *****
  • Posts: 606
Re: write once compile anywhere: mysqlclient
« Reply #3 on: April 11, 2014, 11:48:59 am »

For the mysql-unit I use mysql.pp (Copyright (C) 2000 MySQL AB). I have both tried cdecl and stdcall for the

From where do you use mysql.pp ? It is your own unit ?
(Can you try units (depends on version of your libmysqlclinet) from packages/mysql/src ?)

hakelm

  • Full Member
  • ***
  • Posts: 124
Re: write once compile anywhere: mysqlclient
« Reply #4 on: April 13, 2014, 09:33:50 pm »
No it's not my own unit, it can still be found on the internet and is similar to mysql4.pp coming with Lazarus.
I have used it without problems for around 10 years.
I believe that I now have found the problem. The new libmysqlclient for AMD-64 seems to have a bug in mysql_fetch_lengths which returns erroneous values.
The code below doesn't work:
Code: [Select]
.............
row:=prow(mysql_fetch_row(fmysqlresult));
while row<>nil do
begin
fieldlengths:=plengths(mysql_fetch_lengths(fmysqlresult));
for x:=0 to fieldcount-1 do
begin
l:=fieldlengths^[x];
pf:=row^ [x];
s:=copy(pf,1,l);
result[x,y]:=s;
end;
inc(y);
row:=prow(mysql_fetch_row(fmysqlresult));
end;

But this seems to correct the problem:

Code: [Select]
row:=prow(mysql_fetch_row(fmysqlresult));
while row<>nil do
begin
for x:=0 to fieldcount-1 do
begin
pf:=row^[x];
if pf<>nil then
result[x,y]:=pf
else
result[x,y]:='';
end;
inc(y);
row:=prow(mysql_fetch_row(fmysqlresult));
end;

H
« Last Edit: April 13, 2014, 09:45:32 pm by hakelm »

 

TinyPortal © 2005-2018