Răsfoiți Sursa

* Better fix for r13969. Let the database-server handle invalid null-parameters. Tip from Martin Schreiber

git-svn-id: trunk@13971 -
joost 15 ani în urmă
părinte
comite
663a59e75b

+ 0 - 1
packages/fcl-db/src/base/dbconst.pas

@@ -95,7 +95,6 @@ Resourcestring
   SMaxIndexes              = 'The maximum amount of indexes is reached';
   SMinIndexes              = 'The minimum amount of indexes is 1';
   STooManyFields           = 'More fields specified then really exist';
-  SNullParamNotAllowed     = 'The parameter ''%s'' does not allow null-values';
 // These are added for Delphi-compatilility, but not used by the fcl:
   SFieldIndexError         = 'Field index out of range';
   SIndexFieldMissing       = 'Cannot access index field ''%s''';

+ 8 - 7
packages/fcl-db/src/sqldb/interbase/ibconnection.pp

@@ -555,7 +555,12 @@ begin
           SQLData := AllocMem(in_SQLDA^.SQLVar[x].SQLLen+2)
         else
           SQLData := AllocMem(in_SQLDA^.SQLVar[x].SQLLen);
-        if (sqltype and 1) = 1 then New(SQLInd);
+        // Always force the creation of slqind for parameters. It could be
+        // that a database-trigger takes care of inserting null-values, so
+        // it should always be possible to pass null-parameters. If that fails,
+        // the database-server will generate the appropiate error.
+        sqltype := sqltype or 1;
+        new(sqlind);
         end;
       {$R+}
       end
@@ -778,14 +783,10 @@ begin
     ParNr := ParamBinding[SQLVarNr];
     VSQLVar := @in_sqlda^.SQLvar[SQLVarNr];
     if AParams[ParNr].IsNull then
-      begin
-      If not Assigned(VSQLVar^.SQLInd) then
-        DatabaseErrorFmt(SNullParamNotAllowed,[AParams[ParNr].Name],Self);
-      VSQLVar^.SQLInd^ := -1;
-      end
+      VSQLVar^.SQLInd^ := -1
     else
       begin
-      if assigned(VSQLVar^.SQLInd) then VSQLVar^.SQLInd^ := 0;
+      VSQLVar^.SQLInd^ := 0;
 
       case (VSQLVar^.sqltype and not 1) of
         SQL_LONG :

+ 10 - 1
packages/fcl-db/tests/testfieldtypes.pas

@@ -932,6 +932,7 @@ end;
 
 procedure TTestFieldTypes.TestNonNullableParams;
 var ASQLQuery : TSQLQuery;
+    Passed: Boolean;
 begin
   // Check for an exception when a null value is stored into a non-nullable
   // field using a parameter
@@ -946,7 +947,15 @@ begin
   ASQLQuery.Params[0].Clear;
   ASQLQuery.Params[1].AsInteger := 1;
   AssertTrue(ASQLQuery.Params[0].IsNull);
-  AssertException(EDatabaseError, @ASQLQuery.ExecSQL);
+  Passed:=False;
+  try
+    @ASQLQuery.ExecSQL;
+  except
+    on E: Exception do
+      if E.ClassType.InheritsFrom(EDatabaseError) then
+        Passed := true;
+  end;
+  AssertTrue(Passed);
 end;
 
 procedure TTestFieldTypes.TestStringLargerThen8192;