~ubuntu-branches/ubuntu/lucid/fpc/lucid-proposed

« back to all changes in this revision

Viewing changes to fpcsrc/packages/mysql/tests/testdb4.pp

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-10-09 23:29:00 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081009232900-553f61m37jkp6upv
Tags: 2.2.2-4
[ Torsten Werner ]
* Update ABI version in fpc-depends automatically.
* Remove empty directories from binary package fpc-source.

[ Mazen Neifer ]
* Removed leading path when calling update-alternatives to remove a Linitian
  error.
* Fixed clean target.
* Improved description of packages. (Closes: #498882)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
program qtest;
 
2
 
 
3
uses
 
4
  mysql4;
 
5
 
 
6
Const
 
7
  DataBase : Pchar = 'testdb';
 
8
  Query    : Pchar = 'Select * from FPdev';
 
9
 
 
10
var
 
11
  count,num : longint;
 
12
  code : integer;
 
13
  sock : PMYSQL;
 
14
  qmysql : TMYSQL;
 
15
  qbuf : string [160];
 
16
  rowbuf : TMYSQL_ROW;
 
17
  dummy : string;
 
18
  recbuf : PMYSQL_RES;
 
19
 
 
20
begin
 
21
  if paramcount=1 then
 
22
    begin
 
23
    Dummy:=Paramstr(1)+#0;
 
24
    DataBase:=@Dummy[1];
 
25
    end;
 
26
  Write ('Connecting to MySQL...');
 
27
  mysql_init(PMySQL(@qmysql));
 
28
  sock :=  mysql_real_connect(PMysql(@qmysql),nil,'michael','geen',nil,0,nil,0);
 
29
  if sock=Nil then
 
30
    begin
 
31
    Writeln (stderr,'Couldn''t connect to MySQL.');
 
32
    Writeln (stderr,mysql_error(@qmysql));
 
33
    halt(1);
 
34
    end;
 
35
  Writeln ('Done.');
 
36
  Writeln ('Connection data:');
 
37
{$ifdef Unix}
 
38
  writeln ('Mysql_port      : ',mysql_port);
 
39
  writeln ('Mysql_unix_port : ',mysql_unix_port);
 
40
{$endif}
 
41
  writeln ('Host info       : ',mysql_get_host_info(sock));
 
42
  writeln ('Server info     : ',mysql_stat(sock));
 
43
  writeln ('Client info     : ',mysql_get_client_info);
 
44
 
 
45
  Writeln ('Selecting Database ',DataBase,'...');
 
46
  if mysql_select_db(sock,DataBase) < 0 then
 
47
    begin
 
48
    Writeln (stderr,'Couldn''t select database ',Database);
 
49
    Writeln (stderr,mysql_error(sock));
 
50
    halt (1);
 
51
    end;
 
52
 
 
53
  writeln ('Executing query : ',Query,'...');
 
54
    if (mysql_query(sock,Query) < 0) then
 
55
      begin
 
56
      Writeln (stderr,'Query failed ');
 
57
      writeln (stderr,mysql_error(sock));
 
58
      Halt(1);
 
59
      end;
 
60
 
 
61
  recbuf := mysql_store_result(sock);
 
62
  if RecBuf=Nil then
 
63
    begin
 
64
    Writeln ('Query returned nil result.');
 
65
    mysql_close(sock);
 
66
    halt (1);
 
67
    end;
 
68
  Writeln ('Number of records returned  : ',mysql_num_rows (recbuf));
 
69
  Writeln ('Number of fields per record : ',mysql_num_fields(recbuf));
 
70
 
 
71
  rowbuf := mysql_fetch_row(recbuf);
 
72
  while (rowbuf <>nil) do
 
73
       begin
 
74
       Write  ('(Id: ', rowbuf[0]);
 
75
       Write  (', Name: ', rowbuf[1]);
 
76
       Writeln(', Email : ', rowbuf[2],')');
 
77
       rowbuf := mysql_fetch_row(recbuf);
 
78
       end;
 
79
  Writeln ('Freeing memory occupied by result set...');
 
80
  mysql_free_result (recbuf);
 
81
 
 
82
  Writeln ('Closing connection with MySQL.');
 
83
  mysql_close(sock);
 
84
  halt(0);
 
85
end.