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
Code: Select all
CD_PESSOA INT(11)
NM_PESSOA VARCHAR(60)
DT_NASCIMENTO DATETIME
...
DS_ESTADO CHAR(2)
The second TZQuery component of the Form is named qryMunicipios with SQL property:
Code: Select all
SELECT * FROM MUNICIPIOS WHERE UF = :DS_ESTADO
Code: Select all
CD_MUNICIPIO INT(11)
UF CHAR(2)
DS_MUNICIPIO VARCHAR(120)
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;
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;
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);
Code: Select all
ftFixedChar:
Statement.SetPChar(I + 1, Param.AsString);
Josimar Zimermann