UniLoader & Firebird - Defaults expected, NULLs found
Posted: Thu 30 May 2013 15:19
I'm not sure where the issue/fix may lie, please see what you think.
Seems that when using LOADFROMDATASET() under Firebird, integer fields that are
not explicitly given a value end up as NULL rather than 0 despite
the field being type INTEGER DEFAULT 0.
Specifically:
If you loop to execute SQL insert statements that
insert 2 data fields, all the INTEGER fields in the destination
table not specifically filled (having DEFAULT 0) do receive that default.
But if you select a dataset having only 2 data fields,
then do mUniloader.loadfromdataset(dset);
It seems that the not-filled INTEGER fields in the destination
table (having DEFAULT 0) contain NULLs.
Examples:
destination table:
create table CD_DENTAL (
id integer not null,
master_id integer default 0,
status integer default 0,
recip_hold default 0,
primary key(id));
A) Simple insertions:
q.sql.Add('select id, master_id from cd_med');
q.open;
q2.sql.add('insert into cd_dental(id, master_id)values(:id, :master_id)');
while not q.eof do
begin
q2.parambyname('id').asBCD:=q.fieldbyname('id').asinteger;
q2.parambyname('master_id').asBCD:=q.fieldbyname('master_id').asinteger;
q2.execsql;
q.Next;
end;
when I examine CD_DENTAL all the values in STATUS and RECIP_HOLD (not filled!)
contain 0s as expected
B)Loadfromdataset (CD_MED ->> CD_DENTAL):
mUniloader.TableName:='cd_dental';
q.sql.Add('select id, master_id from cd_med');
q.open;
mUniloader.createcolumns;
mUniloader.loadfromdataset(q);
When I examine CD_DENTAL all the values in STATUS and RECIP_HOLD (not-filled!)
contain NULL
Summary:
The issue is with those fields *not being specifically filled*
In one case they get the expected DEFAULT of 0,
In the other case they contain NULL.
version 4.0.2 for D2010
firebird 2.1
thanks,
tonyM
Seems that when using LOADFROMDATASET() under Firebird, integer fields that are
not explicitly given a value end up as NULL rather than 0 despite
the field being type INTEGER DEFAULT 0.
Specifically:
If you loop to execute SQL insert statements that
insert 2 data fields, all the INTEGER fields in the destination
table not specifically filled (having DEFAULT 0) do receive that default.
But if you select a dataset having only 2 data fields,
then do mUniloader.loadfromdataset(dset);
It seems that the not-filled INTEGER fields in the destination
table (having DEFAULT 0) contain NULLs.
Examples:
destination table:
create table CD_DENTAL (
id integer not null,
master_id integer default 0,
status integer default 0,
recip_hold default 0,
primary key(id));
A) Simple insertions:
q.sql.Add('select id, master_id from cd_med');
q.open;
q2.sql.add('insert into cd_dental(id, master_id)values(:id, :master_id)');
while not q.eof do
begin
q2.parambyname('id').asBCD:=q.fieldbyname('id').asinteger;
q2.parambyname('master_id').asBCD:=q.fieldbyname('master_id').asinteger;
q2.execsql;
q.Next;
end;
when I examine CD_DENTAL all the values in STATUS and RECIP_HOLD (not filled!)
contain 0s as expected
B)Loadfromdataset (CD_MED ->> CD_DENTAL):
mUniloader.TableName:='cd_dental';
q.sql.Add('select id, master_id from cd_med');
q.open;
mUniloader.createcolumns;
mUniloader.loadfromdataset(q);
When I examine CD_DENTAL all the values in STATUS and RECIP_HOLD (not-filled!)
contain NULL
Summary:
The issue is with those fields *not being specifically filled*
In one case they get the expected DEFAULT of 0,
In the other case they contain NULL.
version 4.0.2 for D2010
firebird 2.1
thanks,
tonyM