* 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 -
This commit is contained in:
joost 2009-10-29 21:18:54 +00:00
parent 6264145aa6
commit f546247481
2 changed files with 23 additions and 2 deletions

View File

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

View File

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