Input parameter count is less then expected

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
Khaoz
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 18.04.2009, 21:01

Input parameter count is less then expected

Post by Khaoz »

I'm using the following code to inser some data using execSQL from a query:

Code: Select all

INSERT INTO avisos_troca_oleo(veiculos_id,proxima_troca) VALUES(:veiculos_id,:proxima_troca)
My table structure (postgresql) is:

Code: Select all

id - not null - autoinc
veiculos_id - not null
proxima_troca - not null
data_troca - allows null
But when i try to do a execSQL i get the message:

Code: Select all

Input parameter count is less then expected
what is going wrong ?
Khaoz
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 18.04.2009, 21:01

Post by Khaoz »

Seems a problem in ZDbcPostgresqlStatement.pas function:

Code: Select all

function TZPostgreSQLPreparedStatement.PrepareSQLParam(ParamIndex: Integer): string;
line 339:

Code: Select all

if InParamCount <= ParamIndex then
  raise EZSQLException.Create(SInvalidInputParameterCount);
InParamCount is equals to ParamIndex. I don't know if i need to change <= to < or check why InParamCount does not has the value of 2 (which are my number of parameters).

Some tips ?

Ty
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

I can't really believe there's something wrong with the input parameter processing in itself. That would break the test suite within a second.
So I'm afraid you'll have to give more details on the way you provide these parameters. Seems like the error is telling you they are trying to fill one of the parameters but you didn't provide a value.

Mark
Image
Khaoz
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 18.04.2009, 21:01

Post by Khaoz »

I will post the full code which is used in my application:

Database.pas

Code: Select all

procedure TDatabase.ExecCommand(const Sql: string;
  Params: array of String; Values: array of Variant);
var
  qry: TZQuery;
  i: integer;
  Param: TParam;
begin
  qry := TZQuery.Create(nil);
  qry.Connection := fConnection;

  try
    qry.Close;
    qry.SQL.Text := Sql;
    
    for i := 0 to High(Params) do
    begin
      Param:= qry.Params.FindParam(Params[i]);
      if Assigned(Param) then
        Param.Value := Values[i];
    end;

    qry.ExecSQL;
  finally
    FreeAndNil(qry);
  end;
end;
another_unit.pas

Code: Select all

(...)
Database.ExecCommand('INSERT INTO avisos_troca_oleo(veiculos_id,proxima_troca) VALUES(:veiculos_id,:proxima_troca)', ['veiculos_id', 'proxima_troca'], [1, 10000.00]);
(...)
If you need more info, let me know :)
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Khaoz,

Is the code in your for loop effectively executed? And are the assignments effectively done? (checked by setting debug point)

If you want me to check, please attach a 'ready to compile' test project with a table reation/data fill script.

Mark
Image
Khaoz
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 18.04.2009, 21:01

Post by Khaoz »

mdaems wrote:Khaoz,

Is the code in your for loop effectively executed? And are the assignments effectively done? (checked by setting debug point)
It's always my first shot, but everything seems to be ok.
mdaems wrote: If you want me to check, please attach a 'ready to compile' test project with a table reation/data fill script.
Ok i will do. Let me just finish my app (next week, i think) and i will post the entire code, with the database script and a some data to use.
For now i'm using queries with updatesql to do some insert/update operation like that.
seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Post by seawolf »

I noted your table has 3 field set as not null, and you insert has only 2 params. I know autoinc should not be passed as parameter, but Have you tried pass 3 params?
JWBokx
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: 24.03.2009, 11:52

Post by JWBokx »

I got this error message too on Firebird.
Somehow the names of the parameters, in your case :veiculos_id,:proxima_troca, where different from the names shown in the Params property editor.
olehs
Zeos Dev Team
Zeos Dev Team
Posts: 118
Joined: 09.11.2009, 21:05

Post by olehs »

I guess, first parameter causes the problem. 1 is treated as byte, but ftByte is not supported by TZAbstractRODataset.SetStatementParams
Post Reply