barnarp
asked on
TTable Update
Hi,
I am struggling with a real easy concept. Any help please.
I am using a TTable component to insert a blob into an Oracle database. the insert works fine, but when I want to update the table, I get a unique constraint error as the table want to insert another record with the same unique key,. instead of updating the BLOB of the existing key. I am not sure how to perform the update.
Teh database table only consist of two columns, one for a primary key and one for the blob.
My code are as follows:
with dm.tblBLOB do
begin
dm.Maximo.StartTransaction ;
Open;
if blobexist = 'Y' then Insert else Update;
FieldByName('DOCUMENT').As String := docid;
TBlobField(FieldByName('CP LANT_BLOB' )).LoadFro mFile(file 2blobname) ;
Post;
dm.Maximo.Commit;
I am struggling with a real easy concept. Any help please.
I am using a TTable component to insert a blob into an Oracle database. the insert works fine, but when I want to update the table, I get a unique constraint error as the table want to insert another record with the same unique key,. instead of updating the BLOB of the existing key. I am not sure how to perform the update.
Teh database table only consist of two columns, one for a primary key and one for the blob.
My code are as follows:
with dm.tblBLOB do
begin
dm.Maximo.StartTransaction
Open;
if blobexist = 'Y' then Insert else Update;
FieldByName('DOCUMENT').As
TBlobField(FieldByName('CP
Post;
dm.Maximo.Commit;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
with dm.tblBLOB do
begin
dm.Maximo.StartTransaction ;
Open;
if Locate('DOCUMENT', VarArrayOf([docid]), []) then Edit else Insert;
FieldByName('DOCUMENT').As String := docid;
TBlobField(FieldByName('CP LANT_BLOB' )).LoadFro mFile(file 2blobname) ;
Post;
dm.Maximo.Commit;
That's the code with locate. Didn't test it, though...
begin
dm.Maximo.StartTransaction
Open;
if Locate('DOCUMENT', VarArrayOf([docid]), []) then Edit else Insert;
FieldByName('DOCUMENT').As
TBlobField(FieldByName('CP
Post;
dm.Maximo.Commit;
That's the code with locate. Didn't test it, though...
>>if blobexist = 'Y' then Insert else Update;
should be
if blobexist = 'Y' then Update else insert;
or
if blobexist = 'Y' then Insert else Edit;
or
if blobexist = 'Y' then Edit else Insert;