From f5462474815948f1b5e1ac001645fb2758862132 Mon Sep 17 00:00:00 2001 From: joost Date: Thu, 29 Oct 2009 21:18:54 +0000 Subject: [PATCH] * Raise an exception when a query is executed with a parameter set to null when this is not allowed + test git-svn-id: trunk@13969 - --- .../src/sqldb/interbase/ibconnection.pp | 5 +++-- packages/fcl-db/tests/testfieldtypes.pas | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/fcl-db/src/sqldb/interbase/ibconnection.pp b/packages/fcl-db/src/sqldb/interbase/ibconnection.pp index ced5ffe524..bb0792ffae 100644 --- a/packages/fcl-db/src/sqldb/interbase/ibconnection.pp +++ b/packages/fcl-db/src/sqldb/interbase/ibconnection.pp @@ -779,8 +779,9 @@ begin VSQLVar := @in_sqlda^.SQLvar[SQLVarNr]; if AParams[ParNr].IsNull then begin - If Assigned(VSQLVar^.SQLInd) then - VSQLVar^.SQLInd^ := -1; + If not Assigned(VSQLVar^.SQLInd) then + DatabaseErrorFmt(SNullParamNotAllowed,[AParams[ParNr].Name],Self); + VSQLVar^.SQLInd^ := -1; end else begin diff --git a/packages/fcl-db/tests/testfieldtypes.pas b/packages/fcl-db/tests/testfieldtypes.pas index caef93ac38..a163bfe54c 100644 --- a/packages/fcl-db/tests/testfieldtypes.pas +++ b/packages/fcl-db/tests/testfieldtypes.pas @@ -48,6 +48,7 @@ type procedure TestSetBlobAsMemoParam; procedure TestSetBlobAsBlobParam; procedure TestSetBlobAsStringParam; + procedure TestNonNullableParams; procedure TestGetIndexDefs; procedure TestDblQuoteEscComments; procedure TestpfInUpdateFlag; // bug 7565 @@ -929,6 +930,25 @@ begin TSQLDBConnector(DBConnector).Connection.ExecuteDirect('update FPDEV set name=''nothing'' where (1=0)'); end; +procedure TTestFieldTypes.TestNonNullableParams; +var ASQLQuery : TSQLQuery; +begin + // Check for an exception when a null value is stored into a non-nullable + // field using a parameter + // There was a bug in IBConnection so that in this case the last used value + // for the parameter was used. + + // To make sure that any changes are cancelled in the case the test fails + TSQLDBConnector(DBConnector).GetNDataset(true,5); + + ASQLQuery := TSQLDBConnector(DBConnector).Query; + ASQLQuery.SQL.text := 'update fpdev set ID=:ID1 where id = :ID2'; + ASQLQuery.Params[0].Clear; + ASQLQuery.Params[1].AsInteger := 1; + AssertTrue(ASQLQuery.Params[0].IsNull); + AssertException(EDatabaseError, @ASQLQuery.ExecSQL); +end; + procedure TTestFieldTypes.TestStringLargerThen8192; var