Saludos
Sigo con mis pruebas y errores y leyendo los manuales básicos, pero entrenando con este mismo problema,,,
He seguido el código de nelson y lo he modificado a mi necesidad y ya he descubierto varias cosas, pero me falta mucho todabia
Este es mi código
Código Delphi
[-]unit testMysql;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DBCtrls, DB, StdCtrls, Mask, ZAbstractRODataset,
ZAbstractDataset, ZAbstractTable, ZDataset, ZAbstractConnection,
ZConnection, Grids, DBGrids, DBClient;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
ZConnection1: TZConnection;
ZQuery1: TZQuery;
ClientDataSet1: TClientDataSet;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
ADatabases : Array[0..2] of String = ('bd2.dyndns.org','bd3.dyndns.org','bd4.dyndns.org');
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Table : TClientDataset;
i : Integer;
begin
Table := TClientDataset.Create(Application);
Table.FieldDefs.Add('Nombre-bd2', ftString, 50, False);
Table.FieldDefs.Add('Clave-bd2', ftString, 50, False);
Table.FieldDefs.Add('Activo-bd2', ftString, 2, False);
Table.FieldDefs.Add('Nombre-bd3', ftString, 50, False);
Table.FieldDefs.Add('Clave-bd3', ftString, 50, False);
Table.FieldDefs.Add('Activo-bd3', ftString, 2, False);
Table.FieldDefs.Add('Nombre-bd4', ftString, 50, False);
Table.FieldDefs.Add('Clave-bd4', ftString, 50, False);
Table.FieldDefs.Add('Activo-bd4', ftString, 2, False);
Table.CreateDataset;
Table.Open;
for i :=0 to 2 do
begin
ZConnection1.HostName := ADatabases[i];
ZConnection1.Port := 6306;
ZConnection1.Database := 'mibd';
ZConnection1.User := 'user';
ZConnection1.Password := 'pass';
ZConnection1.Protocol := 'mysql-5';
ZQuery1.Connection := ZConnection1;
with ZQuery1 do
ZQuery1.Close;
ZQuery1.SQL.Clear;
ZQuery1.SQL.Text := ' Select nombre, clave, activo from tabla';
ZQuery1.Open;
while not Eof do
begin
if i=0 then
begin
Table.Append;
Table.FieldByName('nombre-bd2').AsInteger := ZQuery1.FieldByName('nombre').Value;
Table.FieldByName('clave-bd2').AsString := ZQuery1.FieldByName('clave').Value;
Table.FieldByName('activo-bd2').AsDateTime := ZQuery1.FieldByName('activo').Value;
Table.Post;
Next;
end
else if i=1 then
begin
Table.Append;
Table.FieldByName('nombre-bd3').AsInteger := ZQuery1.FieldByName('nombre').Value;
Table.FieldByName('clave-bd3').AsString := ZQuery1.FieldByName('clave').Value;
Table.FieldByName('activo-bd3').AsDateTime := ZQuery1.FieldByName('activo').Value;
Table.Post;
Next;
end
else
begin
Table.Append;
Table.FieldByName('nombre-bd4').AsInteger := ZQuery1.FieldByName('nombre').Value;
Table.FieldByName('clave-bd4').AsString := ZQuery1.FieldByName('clave').Value;
Table.FieldByName('activo-bd4').AsDateTime := ZQuery1.FieldByName('activo').Value;
Table.Post;
Next;
end;
end;
ZConnection1.Disconnect;
end;
DataSource1.DataSet := Table;
DBGrid1.DataSource := DataSource1;
for i := 0 to ZQuery1.Fields.Count - 1 do
DBGrid1.Columns.Items[i].Width := ZQuery1.Fields[i].DisplayWidth;
end;
end.
Pero me da error, lo compilo y todo le doy al boton para hacer la query y me da este error
Código Delphi
[-]raise exception class EInOutError 'I/O error 6'
en esta línea
Como que falla el Eof, no sé
Haber si alguien me dice en que estoy mal, de momento tratare de ver si lo puedo arreglar,,,
Otra cosa, hay manera de debuggear las variables si vienen con datos o que me imprima lo que viene, para ver como vienen los datos, así como un print $variable, algo así???
Saludos desde chile