Page 1 of 1

SQLite : Why do I get 'Incorrect parameter count' error ?

Posted: Thu 12 Mar 2015 07:42
by swierzbicki
I don't understand why I'm getting this :

Exception 'first chance' at $753D812F. Exception class Exception with a message 'Incorrect parameter count. Expected: 9; Actual: 8'. Process Gestion_MultiCN.exe (5140)

As you can see, there is 8 Unique parameters in my query but ":Ordre_Fabrication" is declared twice.

Code: Select all

var

  FUniQuery: TuniQuery;
begin
  FUniQuery := TuniQuery.Create(nil);
  FUniQuery.Connection := FConnection;
  try
    FUniQuery.SpecificOptions.Values['PostgreSQL.UseParamTypes'] := 'True';
    FUniQuery.SQL.Text := OrdreFabrication_Update;

    FUniQuery.ParamByName('Ordre_Fabrication').AsString :=
      Value.Ordre_Fabrication;
    FUniQuery.ParamByName('Date_Production').AsDateTime := now;
    FUniQuery.ParamByName('Ligne').AsString := FLigne.Id_ligne;
    FUniQuery.ParamByName('Compteur_Produit').AsInteger :=
      Value.Compteur_Produit;
    FUniQuery.ParamByName('Id_Poste').AsInteger := FPoste.Id_Poste;
    FUniQuery.ParamByName('Date_Poste').AsDate := FPoste.Date_Poste;
    FUniQuery.ParamByName('Id_Pilote_1').AsString := FPoste.Id_Pilote_1;
    FUniQuery.ParamByName('Id_Pilote_2').AsString := FPoste.Id_Pilote_2;
    FUniQuery.Prepare;
    FUniQuery.Execute;
  finally
    FUniQuery.Free;
  end;

Code: Select all

Update Productions_Ordres_Fabrications set Ordre_Fabrication= :Ordre_Fabrication, Ligne=:ligne, Date_Poste=:Date_Poste, Compteur_Produit=:Compteur_Produit, Date_Production=:Date_Production,Id_Poste=:Id_Poste,Id_Pilote_1=:Id_Pilote_1,Id_Pilote_2=:Id_Pilote_2 WHERE Ligne = :Ligne  AND Ordre_Fabrication =:Ordre_Fabrication;

Re: SQLite : Why do I get 'Incorrect parameter count' error ?

Posted: Thu 12 Mar 2015 09:16
by AlexP
Hello,

This is due to that the SQLite sqlite3_bind_parameter_count API method is case-sensitive, and, in Delphi, parameters are case-insensitive. Since in your query, the "ligne" parameter name is used for the first time, and "Ligne" - for the second time, then SQLite treats them as different parameters. To solve the problem, you should use the same case of parameters with the same name.

Re: SQLite : Why do I get 'Incorrect parameter count' error ?

Posted: Thu 12 Mar 2015 19:55
by swierzbicki
:D ... that was that !
Thank you

Re: SQLite : Why do I get 'Incorrect parameter count' error ?

Posted: Fri 13 Mar 2015 05:53
by AlexP
You are welcome. Feel free to contact us if you have any further questions.