Hola a todos!
Tengo un problema tratando de ejecutar un select que devuelve 2 campos.
Si ejecuto el select en phpMyAdmin, se ejecuta correctamente y devuelve todos los campos, por lo que descarto que sea un error de SQL.
Si ejecuto el select con
un solo campo, me devuelve la información, por lo que descarto un error de conexión.
Código SQL
[-]select p.id_product from ps_product p
left outer join ps_product_lang l
on p.id_product = l.id_product
where p.id_product >= :desde1 and p.id_product <= :hasta1
Esto funciona
Código SQL
[-]select p.id_product, l.id_lang from ps_product p
left outer join ps_product_lang l
on p.id_product = l.id_product
where p.id_product >= :desde1 and p.id_product <= :hasta1
Esto también funciona pero solo devuelve el primer campo (id_product).
Fields.Count=1 !!!
Código SQL
[-]select p.id_product, l.name from ps_product p
left outer join ps_product_lang l
on p.id_product = l.id_product
where p.id_product >= :desde1 and p.id_product <= :hasta1
Invalid field size
Nota:
p.id_product es int(10)
l.name es varchar(128)
Utilizo Delphi 6 y el driver dbxopenmysql50.dll que bajé de
JustSoftwareSolution
He probado con TSQLConnection, TSLDataSet y TSQLClientDataSet. Los tres me responden lo mismo en la instruccion
Componente.Open.
He hecho un programita de pruebas. Os dejo las dos funciones que utilizo para conectar y para ejecutar el SQL:
Código Delphi
[-]
procedure TFMMain.EstableceConexionMySQL;
var
oIni : TiniFile;
begin
with MYSQLConnection do
begin
try
if (not Connected) then
begin
oIni := TInifile.Create('G2k2Plus.ini');
try
DriverName := 'dbxmysql';
GetDriverFunc := 'getSQLDriverMYSQL50';
LibraryName := 'dbxopenmysql50.dll';
VendorLib := 'libmysql.dll';
LoginPrompt := False;
Params.Clear;
Params.Append('BlobSize=-1');
Params.Append('ErrorResourceFile=');
Params.Append('LocaleCode=0000');
Params.Append('Database=' + oIni.ReadString('TiendaVirtual', 'Database ', ''));
Params.Append('User_Name=' + oIni.ReadString('TiendaVirtual', 'User_Name ', ''));
Params.Append('Password=' + oIni.ReadString('TiendaVirtual', 'Password ', ''));
Params.Append('HostName=' + oIni.ReadString('TiendaVirtual', 'HostName ', ''));
finally
oIni.Free;
end;
Open;
end;
except
on e: Exception do
begin
MOutput.Lines.Add('Error al abrir conexion MySQL');
MOutput.Lines.Add(e.Message);
end;
end;
end;
end;
Código Delphi
[-]
procedure TFMMain.BTraerDatosSQLQueryClick(Sender: TObject);
var
Q : TSQLQuery;
i : integer;
Desde, Hasta : integer;
s : string;
begin
Desde := 0;
Hasta := 24;
BConectar.Click;
if (MYSQLConnection.Connected) then
begin
Q := TSQLQuery.Create(nil);
try
with Q do
begin
try
SQLConnection := MYSQLConnection;
if (Active) then
Close;
SQL.Text := 'select p.id_product, l.name from ps_product p ' +
'left outer join ps_product_lang l ' +
'on p.id_product = l.id_product ' +
'where p.id_product >= :desde1 and p.id_product <= :hasta1';
Params.FindParam('desde1').Value := Desde;
Params.FindParam('hasta1').Value := Hasta;
Open; MOutput.Lines.Add('Campos: ' + IntToStr(Fields.Count));
for i := 0 to Fields.Count -1 do
begin
MOutput.Lines.Add(' DisplayName '+Fields[i].DisplayName);
MOutput.Lines.Add(' FullName '+Fields[i].FullName);
MOutput.Lines.Add(' FieldName '+Fields[i].FieldName);
MOutput.Lines.Add(' Origin '+Fields[i].Origin);
end;
MOutput.Lines.Add('-----------');
s := '';
for i := 0 to Fields.Count -1 do
s := s + UpperCase(Fields[i].FieldName)+', ';
MOutput.Lines.Add(s);
while (not EOF) do
begin
s := '';
for i := 0 to Fields.Count -1 do
s := s + Fields[i].AsString+', ';
MOutput.Lines.Add(s);
Next;
end;
MOutput.Lines.Add('-----------');
Close;
except
on e: Exception do
begin
MOutput.Lines.Add('-----------');
MOutput.Lines.Add('EXCEPTION');
MOutput.Lines.Add(e.Message);
end;
end;
end;
finally
Q.Free;
end;
end;
end;