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

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

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

Post by swierzbicki » Thu 12 Mar 2015 07:42

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;

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

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

Post by AlexP » Thu 12 Mar 2015 09:16

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.

swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

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

Post by swierzbicki » Thu 12 Mar 2015 19:55

:D ... that was that !
Thank you

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

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

Post by AlexP » Fri 13 Mar 2015 05:53

You are welcome. Feel free to contact us if you have any further questions.

Post Reply