Ir para conteúdo
  • Cadastre-se

dev botao

"You have an error in your SQl syntax; check the manual that corresponds to your MySQL server version


johnbh3
Ver Solução Respondido por johnbh3,
  • Este tópico foi criado há 842 dias atrás.
  • Talvez seja melhor você criar um NOVO TÓPICO do que postar uma resposta aqui.

Recommended Posts


Sabem me dizer onde esta meu erro? 

 

[FireDAC][Phys][MySQL] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'vunitario= ?
vrtotalitem= ?
where id= ?' at line 5

 

Depurando os valores estão todos sendo passado para os parametrôs. 

O erro esta dando  na função function TItemPedido.incluir_Alter_ItemPedido no QryInserir.ExecSQL;

 

        QryInserir.ParamByName('pidproduto').AsInteger   :=fidproduto;
        QryInserir.ParamByName('pidpedido').AsInteger :=fidpedido;
        QryInserir.ParamByName('pqtde').AsFloat:=fqtde;
        QryInserir.ParamByName('pvunitario').AsFloat:=fvunitario;
        QryInserir.ParamByName('pvrtotalitem').AsFloat:=fvrtotalitem;

        QryInserir.ExecSQL;

 

 

unit classe.itemPedido;

interface

uses
  FireDAC.Comp.Client, Vcl.Dialogs, System.SysUtils;

type
  TItemPedido = class
    private
       fConexao      : TFDConnection;
       fid           :integer;
       fidpedido     :integer;
       fidproduto    :integer;
       fqtde         :Real;
       fvunitario   :Real;
       fvrtotalitem  :Real;
    public
      property  Conexao      : TFDConnection read fConexao write fConexao;
      property  id           : integer read fid write fid;
      property  idpedido     : integer read fidpedido write fidpedido;
      property  qtde         : Real read fqtde write fqtde;
      property  vunitario   : Real read fvunitario write  fvunitario;
      property  vrtotalitem  : Real read fvrtotalitem write  fvrtotalitem;
      property  idproduto    : Integer read fidproduto write  fidproduto;


      constructor Create (conexao : TFDconnection);
      destructor Destroy ; override;

      function incluir_Alter_ItemPedido (TipoOperacao: string; out erro: string) : boolean;
      procedure excluirPedido(numeroPedido: integer);
      function consultarItensPedido (idPedido : integer) : TFDQuery;
      function somaItensPedido (idPedido: integer): Real;
  end;

implementation

var
  Qry : TFDQuery;

{ TItemPedido }

function TItemPedido.consultarItensPedido(idPedido: integer): TFDQuery;
begin
  try
    //fConexao.Connected :=false;
    //fConexao.Connected :=true;
    Qry.Close;
    Qry.SQL.Clear;
    Qry.sql.Add('SELECT');
    Qry.sql.Add('  itempedido.id,');
    Qry.sql.Add('  itempedido.idpedido,');
    Qry.sql.Add('  itempedido.idproduto,');
    Qry.sql.Add('  itempedido.qtde,');
    Qry.sql.Add('  itempedido.vrtotalitem,');
    Qry.sql.Add('  itempedido.vunitario,');
    Qry.sql.Add('  produto.nome  as nome_produto,');
    Qry.sql.Add('  produto.vrproduto');
    Qry.sql.Add('FROM ');
    Qry.sql.Add(' itempedido');
    Qry.sql.Add('   INNER JOIN produto ON itempedido.idproduto = produto.id');
    Qry.SQL.Add('Where itempedido.idpedido='+QuotedStr(IntToStr(idPedido)));
    Qry.sql.Add(' ORDER BY itempedido.id');

    Qry.Open();

  finally
     Result :=Qry;
  end;

end;

constructor TItemPedido.Create(conexao: TFDconnection);
begin
   fConexao  := conexao;

   Qry :=TFDQuery.Create(nil);
   Qry.Connection  :=fConexao;

end;

destructor TItemPedido.Destroy;
begin
  Qry.Destroy;
  inherited;
end;

procedure TItemPedido.excluirPedido(numeroPedido: integer);
begin
    fConexao.Connected :=false;
    fConexao.Connected :=true;

    fConexao.ExecSQL('delete from pedido where id=:numeroPedido',[numeroPedido]);
    consultarItensPedido(0);

end;

function TItemPedido.incluir_Alter_ItemPedido(TipoOperacao: string;
  out erro: string): boolean;
var
  QryInserir :TFDQuery;
begin
    try
      try
        fConexao.Connected :=false;
        fConexao.Connected :=true;

        QryInserir :=TFDQuery.Create(nil);
        QryInserir.Connection  :=fConexao;
        QryInserir.SQL.Clear;


        if TipoOperacao='INSERIR' then begin
             QryInserir.SQL.Add('INSERT INTO pedido (dtaemissao, vrtotpedido, codcliente)');
             QryInserir.sql.Add('VALUES (:pdtaemissao, :pvrtotpedido, :pcodcliente)');

        end else
        begin
             QryInserir.SQL.Add('update itempedido set');
             QryInserir.SQL.Add('idproduto= :pidproduto,');
             QryInserir.SQL.Add('idpedido= :pidpedido,');
             QryInserir.SQL.Add('qtde= :pqtde');
             QryInserir.SQL.Add('vunitario= :pvunitario');
             QryInserir.SQL.Add('vrtotalitem= :pvrtotalitem');
             QryInserir.SQL.Add('where id= :pid');


             QryInserir.ParamByName('pid').AsInteger :=fid;
        end;

        QryInserir.ParamByName('pidproduto').AsInteger   :=fidproduto;
        QryInserir.ParamByName('pidpedido').AsInteger :=fidpedido;
        QryInserir.ParamByName('pqtde').AsFloat:=fqtde;
        QryInserir.ParamByName('pvunitario').AsFloat:=fvunitario;
        QryInserir.ParamByName('pvrtotalitem').AsFloat:=fvrtotalitem;

        QryInserir.ExecSQL;

        Result :=true;

      except
      on E : Exception do begin
          erro := E.Message;
          Result :=false;
        end;
      end;
    finally
      QryInserir.Destroy;
    end;

end;

function TItemPedido.somaItensPedido(idPedido: integer): Real;
begin
  try
    //fConexao.Connected :=false;
    //fConexao.Connected :=true;
    Qry.Close;
    Qry.SQL.Clear;
    Qry.sql.Add('SELECT');
    Qry.sql.Add('  sum(qtde*vunitario) AS TOTAL_PEDIDO');
    Qry.sql.Add('FROM');
    Qry.sql.Add('  itempedido');
    Qry.sql.Add('Where idpedido='+QuotedStr(IntToStr(idPedido)));
    Qry.Open();

  finally
     Result :=Qry.FieldByName('TOTAL_PEDIDO').AsFloat;
  end;

end;

end.

 

Editado por johnbh3
faltou dados
Link para o comentário
Compartilhar em outros sites

  • Este tópico foi criado há 842 dias atrás.
  • Talvez seja melhor você criar um NOVO TÓPICO do que postar uma resposta aqui.
Visitante
Este tópico está agora fechado para novas respostas
×
×
  • Criar Novo...

Informação Importante

Colocamos cookies em seu dispositivo para ajudar a tornar este site melhor. Você pode ajustar suas configurações de cookies, caso contrário, assumiremos que você está bem para continuar.

The popup will be closed in 10 segundos...