Link to home
Start Free TrialLog in
Avatar of barnarp
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').AsString := docid;
    TBlobField(FieldByName('CPLANT_BLOB')).LoadFromFile(file2blobname);
    Post;
    dm.Maximo.Commit;

Avatar of kretzschmar
kretzschmar
Flag of Germany image

??

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

   

   
   
ASKER CERTIFIED SOLUTION
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
with dm.tblBLOB do
  begin
    dm.Maximo.StartTransaction;
    Open;
    if Locate('DOCUMENT', VarArrayOf([docid]), []) then Edit else Insert;
    FieldByName('DOCUMENT').AsString := docid;
    TBlobField(FieldByName('CPLANT_BLOB')).LoadFromFile(file2blobname);
    Post;
    dm.Maximo.Commit;

That's the code with locate. Didn't test it, though...