testdb3

¿Has encontrado un error? ¿Tienes la solución? Deja tu correción ;-)

Antes de comentar: Gran parte de los ejercicios propuestos no tienen librerías debido a que Wordpress las eliminó al verlas como etiquetas HTML. Si sabes/tienes/conoces las librerías que hacen falta, déjalo en los comentarios. Y lo mas importante: Todos los ejemplos fueron realizados por estudiante con únicamente conocimiento básico del lenguaje, no de programación.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
program testdb3;
 
uses
  mysql3;
 Const
  DataBase : Pchar = 'testdb';
  Query    : Pchar = 'Select * from FPdev';
 
var  count,num : longint;
  code : integer;
  sock : PMYSQL;
  qmysql : TMYSQL;
  qbuf : string [160];  rowbuf : TMYSQL_ROW;
  dummy : string;
  recbuf : PMYSQL_RES;
 
begin  if paramcount=1 then
    begin
    Dummy:=Paramstr(1)+#0;
    DataBase:=@Dummy[1];
    end;  Write ('Connecting to MySQL...');
  sock :=  mysql_connect(PMysql(@qmysql),'cvs.freepascal.org','michael','geen');
  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.
  $Log: testdb3.pp,v $  Revision 1.3  2005/02/14 17:13:19  peter
    * truncate log
 
}

Punto importante: Si vas a sugerir un segmento de código en algún lenguaje debes hacerlo así:

  • Si es lenguaje C <code lang="c">Código en C</code>
  • Si es lenguaje Pascal <code lang="pascal">Aquí dentro el código de Pascal</code>.

De esta manera el código coloreas el código.

Deja un comentario

Suscribirse a los comentarios.