Page 1 of 2

[patch_done] Input parameter count is less then expected

Posted: 29.09.2010, 15:02
by josimarz
Hello!

I founded a error using TZQuery components:
Input parameter count is less then expected

In a Delphi Form, have two TZQuery components. The first component is named qryPessoas, with SQL property:

Code: Select all

SELECT * FROM PESSOAS
The PESSOAS table have the follows simplified structure:

Code: Select all

CD_PESSOA  INT(11)
NM_PESSOA  VARCHAR(60)
DT_NASCIMENTO  DATETIME
...
DS_ESTADO CHAR(2)
The TDataSource dsPessoas is linked with TZQuery qryPessoas.

The second TZQuery component of the Form is named qryMunicipios with SQL property:

Code: Select all

SELECT * FROM MUNICIPIOS WHERE UF = :DS_ESTADO
The simplified structure of MUNICIPIOS table:

Code: Select all

CD_MUNICIPIO  INT(11)
UF  CHAR(2)
DS_MUNICIPIO  VARCHAR(120)
The DS_ESTADO field of PESSOAS table is linked with UF field of the MUNICIPIOS table. Is a FOREIGN KEY.

When Open the TZQuery qryPessoas, the follows error is raised:
Input parameter count is less then expected

Debugging the component, checked that the error is raised in a follows code passage of the ZDbcMySqlStatement.pas unit (lines 395 - 474):

Code: Select all

function TZMySQLPreparedStatement.PrepareSQLParam(ParamIndex: Integer): string;
var
   ...
begin
  TempBytes := nil;
  if InParamCount <= ParamIndex then
    raise EZSQLException.Create(SInvalidInputParameterCount);
...
end;
This point, the InParamCount property is zero. However, the problem can be TZAbstractRODataset.SetStatementParams method of the ZAbstractRODataset.pas unit, in the follows code passage:

Code: Select all

if Param.IsNull then begin
         Statement.SetNull(I + 1, ConvertDatasetToDbcType(Param.DataType))
      end else begin
        case Param.DataType of
          ftBoolean:
            Statement.SetBoolean(I + 1, Param.AsBoolean);
          ftSmallInt:
            Statement.SetShort(I + 1, Param.AsSmallInt);
          ftInteger, ftAutoInc:
            Statement.SetInt(I + 1, Param.AsInteger);
          ftFloat:
            Statement.SetDouble(I + 1, Param.AsFloat);
          ftLargeInt:
            Statement.SetLong(I + 1, StrToInt64(Param.AsString));
          ftCurrency:
            Statement.SetBigDecimal(I + 1, Param.AsCurrency);
          ftString:
            Statement.SetString(I + 1, Param.AsString);
          ftBytes:
            Statement.SetString(I + 1, Param.AsString);
          ftDate:
            Statement.SetDate(I + 1, Param.AsDate);
          ftTime:
            Statement.SetTime(I + 1, Param.AsTime);
          ftDateTime{$IFNDEF VER130}, ftTimestamp{$ENDIF}:
            Statement.SetTimestamp(I + 1, Param.AsDateTime);
          ftMemo:
            begin
              Stream := TStringStream.Create(Param.AsMemo);
              try
                Statement.SetAsciiStream(I + 1, Stream);
              finally
                Stream.Free;
              end;
            end;
          ftBlob, ftGraphic:
            begin
              Stream := TStringStream.Create(Param.AsBlob);
              try
                Statement.SetBinaryStream(I + 1, Stream);
              finally
                Stream.Free;
              end;
            end;
        end;
This time, the DS_ESTADO parameter of the TZQuery qryMunicipios is typed as ftFixedChar, but ftFixedChar type don't expected for the CASE STATEMENT.

I changed the type of the fields DS_ESTADO and UF of the PESSOAS and MUNICIPIOS tables. Then the DS_ESTADO was typed as ftString.

I believe that the error can be fixed with the code change:

Code: Select all

ftString, ftFixedChar:
   Statement.SetString(I + 1, Param.AsString);
or...

Code: Select all

ftFixedChar:
   Statement.SetPChar(I + 1, Param.AsString);
Thank you!
Josimar Zimermann

Posted: 13.10.2010, 23:38
by mdaems
Hi,

Can you tell in what Delphi versio ftFixedChar was introduced? I have to use the right contitionals to make sure the code also compiles on D7 and fpc.

Matk

Posted: 15.10.2010, 15:09
by josimarz
Hello,

I could not identify which version was introduced the ftFixedChar data type.

I'm using Delphi 2006 version.

Josimar

Posted: 20.10.2010, 18:06
by josimarz
Hello!

To solve the problem temporarily, in the field DS_ESTADO of the TZQuery qryPessoas, changed the property FixedChar to false.

I will create a project and submit to exemplify the problem.

Josimar

Posted: 20.10.2010, 19:17
by josimarz
Hello!

I faked the error. Attached the sample project. Change the connection information in the component ZConnection.

The script example.sql installs the database and records.

After generating the error, change the FixedChar property of field AC_COUNTRY to False in the qryPersons TZQuery.

Delphi: 2006 version
SGDB: MySQL 5.0.45

Posted: 08.11.2010, 01:08
by mdaems
Seems OK. ftFixedChar was already available in Delphi 5.

SVN Rev 843 (Testing branch)

Mark

Posted: 22.07.2012, 07:24
by olehs
How about TZStoredProc? Shouldn't it be fixed too?

Posted: 22.07.2012, 07:41
by olehs
By the way, the same error occurres, when passing Value as Variant of type ftByte (DELPHI12_UP)

Posted: 22.07.2012, 11:52
by EgonHugeist
olehs,

Here we are talking about 6.6 which is not made for D12_Up. Switch to Zeos7. Is that issue equal present there?

Michael

Posted: 23.07.2012, 14:20
by olehs
EgonHugeist,

Sorry, didn't see the topic's branch.

But yes. I am using latest test branch version from SVN and
ftByte is not supported neither in TZAbstractRODataset nor in TZStoredProc.

An error occurs just when you execute something like

Code: Select all

ZQuery1.SQL.Text := 'select * from orders where id = :id;';
ZQuery1.ParamByName('id').Value := 1;
ZQuery1.Open;
Should I create a separate topic in 7.0?

Posted: 23.07.2012, 16:07
by EgonHugeist
olehs,

Oh it might be possible you miss the latest updates. We've been moved on sf.net.

New download URL: http://svn.code.sf.net/p/zeoslib/code-0 ... es/testing

so in 157x i did fix all missing D12_UP types like ftShort, ftByte, ftLongword etc also i fixed the wrong defined BIT type for MySQL..

Please verify the issue again.

Michael

Posted: 23.07.2012, 16:20
by olehs
Yes, I just saw it.

But there is no fix for TZStroredProc, and I don't think it's right to treat ftByte just like ftBytes.
ftByte is more like Integer field.

Code: Select all

        {$IFDEF DELPHI12_UP}
        ftByte:
          Statement.SetByte(I + 1, Param.AsByte);
        {$ENDIF}

Posted: 23.07.2012, 16:25
by olehs
olehs wrote: ftByte is more like Integer field.

Code: Select all

        {$IFDEF DELPHI12_UP}
        ftByte:
          Statement.SetByte(I + 1, Param.AsByte);
        {$ENDIF}
Sorry, I'm not catching up with you. It's already fixed )

Posted: 23.07.2012, 16:30
by EgonHugeist
olehs,

Uff your're right i forgot to fix that on th TZStoreProcedure too. I fixed this in two places on the AbstractRODataset and on the TZSQLProzessor.

But this is slighlt a messy stuff. Would be better to introduce a procedure in the ZDataSetUtils unit where i've to fix it only once.

Thank you for your hint so click update tomorrow or tonight and you got your missing patch, ok?

Michael

Posted: 23.07.2012, 16:33
by olehs
EgonHugeist,
Ok, thanks a lot.