I am converting a application from Delphi 5 to Delphi XE2 and came across a situation using the BDE.
In Delphi XE2 he does not accept pass null for a field that is a foreign key that follows is how this currently working in Delphi 5:
ParamByName('id').datatype: = ftInteger;
Error that occurs in Delphi XE2 with BDE: In the primary key value for foreign key 'XX' in table YY
Tested in the following ways with the same error:
ParamByName('id').datatype: = ftInteger;
ParamByName('id').value: = NULL;
ParamByName('id').DataType: = ftstring;
ParamByName('id').clear;
ParamByName('id').DataType: = ftstring;
ParamByName('id').Bound: = true;
ParamByName('id').Value: = null;
ParamByName('id').IsNull;
How to pass a field with null value?
UPDATE:
Database:
CREATE TABLE TEST_1 (
ID_1 INTEGER NOT NULL,
ID_TEST_2 INTEGER NULL,
DESC_1 VARCHAR(10) NULL,
PRIMARY KEY (ID_1)
);
CREATE TABLE TEST_2 (
ID_2 INTEGER NOT NULL,
DESC_2 VARCHAR(10) NULL,
PRIMARY KEY (ID_2)
);
ALTER TABLE TEST_1 ADD FOREIGN KEY FK_TEST(ID_TEST_2) REFERENCES TEST_2(ID_2);
Delphi XE2:
Close;
SQL.Clear;
SQL.Add('insert into test_1 (id_1, id_test_2, desc_1) values (:id_1, :id_test_2, :desc_1)');
ParamByName('ID_1').AsInteger := 1;
ParamByName('ID_TEST_2').DataType := ftInteger;
ParamByName('ID_TEST_2').Clear;
ParamByName('ID_TEST_2').Bound := True;
ParamByName('DESC_1').AsString := 'DESCRIPTION TEST';
ExecSQL;
Result: Key violation.