1

Well, the situation is: I have 1 TComboBox called cboTipDocIden and 1 TEdit called txtDocIdenSolic.

The values of cboTipDocIden are: "1.DNI","2.RUC".

The component TUniQuery is called q_DetSolicitante.

The SQL Sentence target is:

SELECT oper_solicitante.id_solicitante, oper_solicitante.ape_pat, oper_solicitante.ape_mat,
       oper_solicitante.nombre, oper_solicitante.direcc_idtipcalle, oper_solicitante.direcc_nombrecalle,
       oper_solicitante.direcc_nro, oper_solicitante.idvinculo_fk
FROM oper_solicitante
WHERE oper_solicitante.tipDocIden = :TipDocIden AND
      oper_solicitante.nroDocIden = :NroDocIden

The SQL is executed on OnExit event of txtDocIdenSolic, here the code:

procedure TForm1.txtDocIdenSolicExit(Sender: TObject);
var
  TipDocIden, NroDocIden:string;
begin
  if(length(txtDocIdenSolic.Text)>0) then
  begin
    TipDocIden:=chr(39)+copy(cboTipDocIden.Text,1,1)+chr(39);
    NroDocIden:=chr(39)+trim(txtDocIdenSolic.Text)+chr(39);
    q_DetSolicitante.Close;
    q_DetSolicitante.Params[0].AsString:=TipDocIden;
    q_DetSolicitante.Params[1].AsString:=NroDocIden;
    q_DetSolicitante.Open;

    if(length(q_DetSolicitante.FieldByName('id_solicitante').AsString)=0) then
    begin
      stbar.Panels[0].text:='Nuevo Solicitante...';
      txtApePat.SetFocus;
    end
    else
    begin
      stbar.Panels[0].Text:='Solicitante Reiterativo...';
      txtApePat.Text:=q_DetSolicitante.FieldByName('ape_pat').AsString;
      txtApeMat.Text:=q_DetSolicitante.FieldByName('ape_mat').AsString;
      txtNombre.Text:=q_DetSolicitante.FieldByName('nombre').AsString;
    end;
  end
  else
    msg1.Execute;
end;

Finally, the table structure is:

CREATE TABLE `oper_solicitante` (
  `id_solicitante` int(11) NOT NULL,
  `tipDocIden` char(1) NOT NULL,
  `nroDocIden` varchar(11) NOT NULL,
  `ape_pat` varchar(50) NOT NULL,
  `ape_mat` varchar(50) NOT NULL,
  `nombre` varchar(50) NOT NULL,
  `direcc_idtipcalle` int(11) NOT NULL,
  `direcc_nombrecalle` varchar(80) NOT NULL,
  `direcc_nro` varchar(15) NOT NULL,
  `idvinculo_fk` int(11) NOT NULL,
  PRIMARY KEY (`id_solicitante`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Well, the SQL returns zero rows inside Delphi but when i change the parameters for literal values the SQL works.

Thanks for your useful help.

1
  • Bienvenido a StackOverflow. Edité tu pregunta para añadir formato a tu sentencia CREATE TABLE y para eliminar tu firma, ya que aquí no están permitidas. Un saludo y disfruta de la estancia. Commented Jan 14, 2013 at 5:32

1 Answer 1

2

Remove the chr(39) characters around your parameter values. Using Params[].AsString allows the database driver to properly quote them, and you're adding (doubling) them and thus causing the query to fail.

TipDocIden:= copy(cboTipDocIden.Text,1,1);
NroDocIden:= trim(txtDocIdenSolic.Text);
q_DetSolicitante.Close;
q_DetSolicitante.Params[0].AsString := TipDocIden;
q_DetSolicitante.Params[1].AsString := NroDocIden;
q_DetSolicitante.Open;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.