Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-04

MySQL50 unit in freepascal

9 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Chris

Hi,

I am a newbie in freepascal but I have used turbo pascal and Delphi extensively for the last 7 years or so; I want to write an application for my linux box to do some crude form of replication of mysql databases. I am just trying to figure out how to use the mysql50 unit, but cannot find heads or tails of how to do it; it seems all version have different connecting methods etc etc etc

Does anyone have a simple (very simple) and basic way of connecting to a mysql database, reading a record and writing a record into a table? That's all I need to get started; or if there is some documentation somewhere on how to use the unit id be grateful.

J

PO Box 627 00502 Karen,
Nairobi, Kenya.
Mobile: +254 722 996532

Michael Van Canneyt
to Chris
Chris wrote 13 lines
Hi, I am a newbie in freepascal but I have used turbo pascal and Delphi extensively for the last 7 years or so; I want to write an application for my linux box to do some crude form of replication of mysql databases. I am just trying to figure out how to use the mysql50 unit, but cannot find heads or tails of how to do it; it seems all version have different connecting methods etc etc etc Does anyone have a simple (very simple) and basic way of connecting to a mysql database, reading a record and writing a record into a table? That's all I need to get started; or if there is some documentation somewhere on how to use the unit id be grateful.

The easiest is to use the TMySQLConnection class and TSQLQuery. It takes care of most of the details, and uses standard mechanisms to read/write data.

Michael.

Chris
to Michael Van Canneyt

Thanks,

Where can I get these classes?

PO Box 627 00502 Karen,
Nairobi, Kenya.

Earlier message 32 lines
-----Original Message----- From: On Behalf Of Michael Van Canneyt Sent: 22 April 2008 1:52 p To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] MySQL50 unit in freepascal On Tue, 22 Apr 2008, Chris wrote: > Hi, > > I am a newbie in freepascal but I have used turbo pascal and Delphi > extensively for the last 7 years or so; I want to write an application for > my linux box to do some crude form of replication of mysql databases. I am > just trying to figure out how to use the mysql50 unit, but cannot find heads > or tails of how to do it; it seems all version have different connecting > methods etc etc etc > > Does anyone have a simple (very simple) and basic way of connecting to a > mysql database, reading a record and writing a record into a table? That's > all I need to get started; or if there is some documentation somewhere on > how to use the unit id be grateful. The easiest is to use the TMySQLConnection class and TSQLQuery. It takes care of most of the details, and uses standard mechanisms to read/write data. Michael.
Carsten Bager
to Chris: I am a newbie in freepascal but I have used turbo pascal and Delphi extensively for the…
Does anyone have a simple (very simple) and basic way of connecting to a mysql database, reading a record and writing a record into a table? That's all I need to get started; or if there is some documentation somewhere on how to use the unit id be grateful.

Here is an example I found somewhere. It works, I have tested it on my MySql database server (Novel Netware).

Carsten

---------------------------------------------------------

program qtest;
uses
  mysql50;
Const
  DataBase : Pchar = 'time_sedler';
  Query    : Pchar = 'Select * from maanedstabel';
var
  count,num : longint;
  code : integer;
  sock : PMYSQL;
  qmysql : st_mysql;
  qbuf : string [160];
  rowbuf : MYSQL_ROW;
  dummy : string;
  recbuf : PMYSQL_RES;
begin
  if paramcount=1 then
    begin
    Dummy:=Paramstr(1)+#0;
    ;
    end;
  Write ('Connecting to MySQL...');
  mysql_init(PMySQL(@qmysql));
  sock :=
mysql_real_connect(PMysql(@qmysql),'80.80.80.80','root','password',nil,33
06,nil,0);
  if sock=Nil then
    begin
    Writeln (stderr,'Couldn''t connect to MySQL.');
    Writeln (stderr,mysql_error(@qmysql));
    halt(1);
    end;
  Writeln ('Done.');
  Writeln ('Connection data:');
{$ifdef Unix}
  writeln ('Mysql_port      : ',mysql_port);
  writeln ('Mysql_unix_port : ',mysql_unix_port);
{$endif}
  writeln ('Host info       : ',mysql_get_host_info(sock));
  writeln ('Server info     : ',mysql_stat(sock));
  writeln ('Client info     : ',mysql_get_client_info);
  Writeln ('Selecting Database ',DataBase,'...');
  if mysql_select_db(sock,DataBase) < 0 then
    begin
    Writeln (stderr,'Couldn''t select database ',Database);
    Writeln (stderr,mysql_error(sock));
    halt (1);
    end;
  writeln ('Executing query : ',Query,'...');
    if (mysql_query(sock,Query) < 0) then
      begin
      Writeln (stderr,'Query failed ');
      writeln (stderr,mysql_error(sock));
      Halt(1);
      end;
  recbuf := mysql_store_result(sock);
  if RecBuf=Nil then
    begin
    Writeln ('Query returned nil result.');
    mysql_close(sock);
    halt (1);
    end;
  Writeln ('Number of records returned  : ',mysql_num_rows (recbuf));
  Writeln ('Number of fields per record : ',mysql_num_fields(recbuf));
  rowbuf := mysql_fetch_row(recbuf);
  while (rowbuf nil) do
       begin
       Write  ('(Id: ', rowbuf[0]);
       Write  (', Name: ', rowbuf[1]);
       Writeln(', Email : ', rowbuf[2],')');
       rowbuf := mysql_fetch_row(recbuf);
       end;
  Writeln ('Freeing memory occupied by result set...');
  mysql_free_result (recbuf);
  Writeln ('Closing connection with MySQL.');
  mysql_close(sock);
  halt(0);
end.
Michael Van Canneyt
to Chris: Where can I get these classes? Nairobi, Kenya. -----Original Message----- From: On Behalf…
Chris wrote
Thanks, Where can I get these classes?

Directories

packages/fcl-db/src/sqldb

and below.

Michael.

Show quoted text 45 lines
PO Box 627 00502 Karen, Nairobi, Kenya. -----Original Message----- From: On Behalf Of Michael Van Canneyt Sent: 22 April 2008 1:52 p To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] MySQL50 unit in freepascal On Tue, 22 Apr 2008, Chris wrote: > Hi, > > I am a newbie in freepascal but I have used turbo pascal and Delphi > extensively for the last 7 years or so; I want to write an application for > my linux box to do some crude form of replication of mysql databases. I am > just trying to figure out how to use the mysql50 unit, but cannot find heads > or tails of how to do it; it seems all version have different connecting > methods etc etc etc > > Does anyone have a simple (very simple) and basic way of connecting to a > mysql database, reading a record and writing a record into a table? That's > all I need to get started; or if there is some documentation somewhere on > how to use the unit id be grateful. The easiest is to use the TMySQLConnection class and TSQLQuery. It takes care of most of the details, and uses standard mechanisms to read/write data. Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Chris Kirkpatrick
to Michael Van Canneyt

You may find some useful information in the Lazarus Wiki. See the following pages and browse for others:

http://wiki.lazarus.freepascal.org/Lazarus_Database_Tutorial http://wiki.lazarus.freepascal.org/MySQLDatabases
http://wiki.lazarus.freepascal.org/Databases
http://wiki.lazarus.freepascal.org/Lazarus_DB_Faq

Regards - Chris

Michael Van Canneyt wrote 70 lines
On Tue, 22 Apr 2008, Chris wrote: > Thanks, > > Where can I get these classes? > Directories packages/fcl-db/src/sqldb and below. Michael. > PO Box 627 00502 Karen, > Nairobi, Kenya. > > -----Original Message----- > From: > On Behalf Of Michael Van > Canneyt > Sent: 22 April 2008 1:52 p > To: FPC-Pascal users discussions > Subject: Re: [fpc-pascal] MySQL50 unit in freepascal > > > > On Tue, 22 Apr 2008, Chris wrote: > > >> Hi, >> >> I am a newbie in freepascal but I have used turbo pascal and Delphi >> extensively for the last 7 years or so; I want to write an application for >> my linux box to do some crude form of replication of mysql databases. I am >> just trying to figure out how to use the mysql50 unit, but cannot find >> > heads > >> or tails of how to do it; it seems all version have different connecting >> methods etc etc etc >> >> Does anyone have a simple (very simple) and basic way of connecting to a >> mysql database, reading a record and writing a record into a table? That's >> all I need to get started; or if there is some documentation somewhere on >> how to use the unit id be grateful. >> > The easiest is to use the TMySQLConnection class and TSQLQuery. > It takes care of most of the details, and uses standard mechanisms > to read/write data. > > Michael. > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Chris
to Chris Kirkpatrick

Also please note that I am writing a daemon that will be cron'd so I wont be using lazarus. Let me see what I can come up with. Thanks all.

PO Box 627 00502 Karen,
Nairobi, Kenya.

Earlier message 93 lines
-----Original Message----- From: On Behalf Of Chris Kirkpatrick Sent: 22 April 2008 3:24 p To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] MySQL50 unit in freepascal You may find some useful information in the Lazarus Wiki. See the following pages and browse for others: http://wiki.lazarus.freepascal.org/Lazarus_Database_Tutorial http://wiki.lazarus.freepascal.org/MySQLDatabases http://wiki.lazarus.freepascal.org/Databases http://wiki.lazarus.freepascal.org/Lazarus_DB_Faq Regards - Chris Michael Van Canneyt wrote: > On Tue, 22 Apr 2008, Chris wrote: > > >> Thanks, >> >> Where can I get these classes? >> > > Directories > > packages/fcl-db/src/sqldb > > and below. > > Michael. > > >> PO Box 627 00502 Karen, >> Nairobi, Kenya. >> >> -----Original Message----- >> From: >> On Behalf Of Michael Van >> Canneyt >> Sent: 22 April 2008 1:52 p >> To: FPC-Pascal users discussions >> Subject: Re: [fpc-pascal] MySQL50 unit in freepascal >> >> >> >> On Tue, 22 Apr 2008, Chris wrote: >> >> >>> Hi, >>> >>> I am a newbie in freepascal but I have used turbo pascal and Delphi >>> extensively for the last 7 years or so; I want to write an application for >>> my linux box to do some crude form of replication of mysql databases. I am >>> just trying to figure out how to use the mysql50 unit, but cannot find >>> >> heads >> >>> or tails of how to do it; it seems all version have different connecting >>> methods etc etc etc >>> >>> Does anyone have a simple (very simple) and basic way of connecting to a >>> mysql database, reading a record and writing a record into a table? That's >>> all I need to get started; or if there is some documentation somewhere on >>> how to use the unit id be grateful. >>> >> The easiest is to use the TMySQLConnection class and TSQLQuery. >> It takes care of most of the details, and uses standard mechanisms >> to read/write data. >> >> Michael. >> _______________________________________________ >> fpc-pascal maillist - >> http://lists.freepascal.org/mailman/listinfo/fpc-pascal >> >> >> _______________________________________________ >> fpc-pascal maillist - >> http://lists.freepascal.org/mailman/listinfo/fpc-pascal >> >> > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > >
Michael Van Canneyt
to Chris
Chris wrote
Also please note that I am writing a daemon that will be cron'd so I wont be using lazarus. Let me see what I can come up with. Thanks all.

To use these components you do not need lazarus. It's just easier to do so. Note that lazarus has special wizards to create daemons.

Michael.

Show quoted text 106 lines
PO Box 627 00502 Karen, Nairobi, Kenya. -----Original Message----- From: On Behalf Of Chris Kirkpatrick Sent: 22 April 2008 3:24 p To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] MySQL50 unit in freepascal You may find some useful information in the Lazarus Wiki. See the following pages and browse for others: http://wiki.lazarus.freepascal.org/Lazarus_Database_Tutorial http://wiki.lazarus.freepascal.org/MySQLDatabases http://wiki.lazarus.freepascal.org/Databases http://wiki.lazarus.freepascal.org/Lazarus_DB_Faq Regards - Chris Michael Van Canneyt wrote: > On Tue, 22 Apr 2008, Chris wrote: > > >> Thanks, >> >> Where can I get these classes? >> > > Directories > > packages/fcl-db/src/sqldb > > and below. > > Michael. > > >> PO Box 627 00502 Karen, >> Nairobi, Kenya. >> >> -----Original Message----- >> From: >> On Behalf Of Michael Van >> Canneyt >> Sent: 22 April 2008 1:52 p >> To: FPC-Pascal users discussions >> Subject: Re: [fpc-pascal] MySQL50 unit in freepascal >> >> >> >> On Tue, 22 Apr 2008, Chris wrote: >> >> >>> Hi, >>> >>> I am a newbie in freepascal but I have used turbo pascal and Delphi >>> extensively for the last 7 years or so; I want to write an application for >>> my linux box to do some crude form of replication of mysql databases. I am >>> just trying to figure out how to use the mysql50 unit, but cannot find >>> >> heads >> >>> or tails of how to do it; it seems all version have different connecting >>> methods etc etc etc >>> >>> Does anyone have a simple (very simple) and basic way of connecting to a >>> mysql database, reading a record and writing a record into a table? That's >>> all I need to get started; or if there is some documentation somewhere on >>> how to use the unit id be grateful. >>> >> The easiest is to use the TMySQLConnection class and TSQLQuery. >> It takes care of most of the details, and uses standard mechanisms >> to read/write data. >> >> Michael. >> _______________________________________________ >> fpc-pascal maillist - >> http://lists.freepascal.org/mailman/listinfo/fpc-pascal >> >> >> _______________________________________________ >> fpc-pascal maillist - >> http://lists.freepascal.org/mailman/listinfo/fpc-pascal >> >> > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal