Page 1 of 1

Input parameter count is less then expected

Posted: 20.04.2009, 16:04
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 ?

Posted: 20.04.2009, 16:23
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

Posted: 20.04.2009, 22:11
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

Posted: 20.04.2009, 22:59
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 :)

Posted: 20.04.2009, 23:31
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

Posted: 21.04.2009, 19:55
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.

Posted: 27.04.2009, 22:13
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?

Posted: 28.04.2009, 11:06
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.

Posted: 22.07.2012, 07:54
by olehs
I guess, first parameter causes the problem. 1 is treated as byte, but ftByte is not supported by TZAbstractRODataset.SetStatementParams