Browse Source

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

git-svn-id: trunk@46756 -
michael 4 years ago
parent
commit
24ea912ff5

+ 4 - 2
packages/fcl-db/src/sqldb/interbase/ibconnection.pp

@@ -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;

+ 25 - 0
packages/fcl-db/tests/testsqldb.pas

@@ -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 }