Subject | Data Lost after altering table |
---|---|
Author | Ed Dressel |
Post date | 2004-01-22T16:13:25Z |
Environment: Delphi 7, IBO 4.3Aa, FB 1.5 RC 7
I have a Delphi routine to alter a table structure. In this
particular instance I add an address field as a blob, copy data from
2 string fields into the blob field and then drop the string fields.
My code looks something like this (simplified):
//Add new street address field
ExecSQL(lTx, 'Alter Table ClientInfo Add StreetAddress BLOB SUB_TYPE
1');
//Move data from existing to new field
lQ := CreateQuery(lTx, `Select StreetAddress, Address_1, Addrss_2
from ClientInfo');
while not lQ.EOF do
begin
lQ.Edit;
lQ.Field[0].AsString := lQ.Field[1]AsString + #13#10 + lQ.Field
[2].AsString;
lQ.Post;
end;
//lTx.Commit // un-remming this does not fix the problem
//drop fields no longer used
ExecSQL(lTx, 'Alter Table ClientInfo drop Address_1, drop Address_2');
lTx.Commit;
After I do this, the value for "StreetAddress" is null. If I remove
the final alter table, the value of StreetAddress is correct. I tried
calling lTx.Commit just before dropping the ClientInfo fields but
that did not fix the problem.
Why would dropping other fields null out StreetAddress? Shouldn't
calling `.commit' fix that? Am I doing something wrong?
Thanks
Ed Dressel
I have a Delphi routine to alter a table structure. In this
particular instance I add an address field as a blob, copy data from
2 string fields into the blob field and then drop the string fields.
My code looks something like this (simplified):
//Add new street address field
ExecSQL(lTx, 'Alter Table ClientInfo Add StreetAddress BLOB SUB_TYPE
1');
//Move data from existing to new field
lQ := CreateQuery(lTx, `Select StreetAddress, Address_1, Addrss_2
from ClientInfo');
while not lQ.EOF do
begin
lQ.Edit;
lQ.Field[0].AsString := lQ.Field[1]AsString + #13#10 + lQ.Field
[2].AsString;
lQ.Post;
end;
//lTx.Commit // un-remming this does not fix the problem
//drop fields no longer used
ExecSQL(lTx, 'Alter Table ClientInfo drop Address_1, drop Address_2');
lTx.Commit;
After I do this, the value for "StreetAddress" is null. If I remove
the final alter table, the value of StreetAddress is correct. I tried
calling lTx.Commit just before dropping the ClientInfo fields but
that did not fix the problem.
Why would dropping other fields null out StreetAddress? Shouldn't
calling `.commit' fix that? Am I doing something wrong?
Thanks
Ed Dressel