[fpc-pascal]MySQL under Windows
Fernando Lozano
fsl at centroin.com.br
Wed Jul 24 16:31:48 CEST 2002
Hi there,
I am using FPC 1.0.6 under Windows 98 and MySQL 3.23.49.
The simple test program bellow generates a run-time error 103 on the first write/writeln call unless I define the variable filler. Looks like binary incompatibilities between the pre-compiled Units and the MySQL DLL. Maybe you should distribute the libmysql.dll used when compiling FPC alongside the binaries. :-)
But when I tried to build a test program using FCL, I get an Internal Error when I try to open the Dataset. This other test program is also included so you can check what I've done wrong or help me find a workaround like the filler variable on the first test.
Please let me also ask what's the proper way to check for error (can't connect, wrong password, SQL syntax, no rights, ...) when using the FCL database classes.
[]s, Fernando Lozano
// first test program
program testemysql;
uses mysql;
const
host = 'linuxfs';
banco = 'poo';
login = 'teste';
senha = 'senha';
var
bd : PMYSQL;
qmysql : TMYSQL;
filler : string;
sql : ansistring;
res : PMYSQL_RES;
row : TMYSQL_ROW;
procedure erro (bd : PMYSQL; msg : string);
begin
writeln (stderr, msg);
writeln (stderr, mysql_error(bd));
readln;
halt(1);
end;
begin
filler := '';
bd := mysql_connect (PMysql (@qmysql), host, login, senha);
if bd = Nil then
erro (PMysql (@qmysql), 'Can't conect to MySQL server');
if mysql_select_db (bd, banco) < 0 then
erro (bd, 'Can't select the database ' + banco);
sql := 'SELECT name, e_mail FROM addressbook';
if mysql_query (bd, PChar (sql)) < 0 then
erro (bd, 'Error on SELECT');
res := mysql_store_result (bd);
if (res = nil) then
writeln ('There are no records')
else begin
row := mysql_fetch_row (res);
while (row <> nil) do begin
write ('name: ', row[0], ', ');
write ('e-mail: ', row[1]);
writeln;
row := mysql_fetch_row (res);
end;
mysql_free_result (res);
end;
mysql_close (bd);
readln;
end.
// second test
program testedbmysql;
uses db, mysqldb;
const
host = 'linuxfs';
banco = 'poo';
login = 'teste';
senha = 'senha';
var
bd : TMysqlDataset;
filler : string;
procedure erro (bd : TMysqlDataset; msg : string);
begin
//writeln (stderr, msg);
//writeln (stderr, mysql_error(bd));
writeln (msg);
//writeln (mysql_error(bd));
readln;
halt(1);
end;
begin
//filler := '';
bd := TMysqlDataset.Create (nil);
bd.Host := host;
bd.Database := banco;
bd.User := login;
bd.Password := senha;
bd.SQL.text := 'SELECT numero, saldo FROM conta_corrente';
bd.Open;
while not bd.EOF do begin
write ('numero: ', bd.Fields[0].AsString, ', ');
write ('saldo: ', bd.Fields[1].AsString);
writeln;
bd.Next;
end;
bd.Close;
bd.Free;
readln;
end.
More information about the fpc-pascal
mailing list