* Patch from Luiz Americo to implement SQL_NULL params on firebird (bug ID 37646)

git-svn-id: trunk@46756 -
This commit is contained in:
michael 2020-09-03 09:40:44 +00:00
parent c7628c11c6
commit 24ea912ff5
2 changed files with 29 additions and 2 deletions

View File

@ -164,6 +164,7 @@ uses
const
SQL_BOOLEAN_INTERBASE = 590;
SQL_BOOLEAN_FIREBIRD = 32764;
SQL_NULL = 32767;
INVALID_DATA = -1;
procedure TIBConnection.CheckError(ProcName : string; Status : PISC_STATUS);
@ -834,7 +835,7 @@ begin
begin
if ((SQLType and not 1) = SQL_VARYING) then
SQLData := AllocMem(in_SQLDA^.SQLVar[x].SQLLen+2)
else
else if SQLType <> SQL_NULL then
SQLData := AllocMem(in_SQLDA^.SQLVar[x].SQLLen);
// Always force the creation of slqind for parameters. It could be
// that a database trigger takes care of inserting null values, so
@ -1211,7 +1212,8 @@ begin
SQL_BOOLEAN_FIREBIRD:
PByte(VSQLVar^.SQLData)^ := Byte(AParam.AsBoolean);
else
DatabaseErrorFmt(SUnsupportedParameter,[FieldTypeNames[AParam.DataType]],self);
if (VSQLVar^.sqltype <> SQL_NULL) then
DatabaseErrorFmt(SUnsupportedParameter,[FieldTypeNames[AParam.DataType]],self);
end {case}
end;
end;

View File

@ -62,6 +62,7 @@ type
procedure TestMacros;
Procedure TestPrepareCount;
Procedure TestPrepareCount2;
Procedure TestNullTypeParam;
end;
{ TTestTSQLConnection }
@ -839,6 +840,30 @@ begin
end;
end;
procedure TTestTSQLQuery.TestNullTypeParam;
begin
if not (SQLServerType in [ssSQLite, ssFirebird]) then
Ignore(STestNotApplicable);
CreateAndFillIDField;
try
With SQLDBConnector.Query do
begin
UsePrimaryKeyAsKey:=False; // Disable server index defs etc
SQL.Text:='Select ID from FPDEV2 where (:ID IS NULL or ID = :ID)';
Open;
AssertEquals('Correct record count param NULL',10,RecordCount);
Close;
ParamByname('ID').AsInteger:=1;
Open;
AssertEquals('Correct record count param 1',1,RecordCount);
AssertEquals('Correct field value: ',1,Fields[0].AsInteger);
Close;
end;
finally
SQLDBConnector.Connection.OnLog:=Nil;
end;
end;
{ TTestTSQLConnection }