Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Go Back   Foros Club Delphi > Bases de datos > MySQL
Register FAQ Members List Calendar Guía de estilo Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08/06/2011
duilioisola's Avatar
[duilioisola] duilioisola is offline
Miembro Premium
 
Join Date: Aug 2007
Location: Barcelona, España
Posts: 1,806
Poder: 22
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
Errores de acceso a MySQL DBExpress

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
  //Conecto si no está conectada
  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';
                 //PrepareStatement;
                 Params.FindParam('desde1').Value := Desde;
                 Params.FindParam('hasta1').Value := Hasta;
                 Open; // <----------------------------------------- AQUI DA EL ERROR
                 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;

Last edited by duilioisola : 08/06/2011 at 11:59.
Reply With Quote
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Errores con mi formulario de acceso.... Kenobi Varios 4 17/04/2007 17:11
Control y captura de errores in acceso BBDD Interbasse con ibExpress radiohead Conexión con bases de datos 1 05/11/2004 11:13
errores y excepciones en acceso a BBDD (dbExpress - Interbase) radiohead Firebird e Interbase 1 29/07/2004 17:14
Gestión Errores en DBEXPRESS asirvent Conexión con bases de datos 0 21/11/2003 12:39
Capturar errores con dbExpress Gisela Conexión con bases de datos 2 23/07/2003 17:37


All times are GMT +2. The time now is 21:10.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi