Solved

TTable Update

Posted on 2004-08-24
3
328 Views
Last Modified: 2010-04-05
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;

0
Comment
Question by:barnarp
  • 2
3 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 11879292
??

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

   

   
   
0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 50 total points
ID: 11881117
> if blobexist = 'Y' then Insert else Update;
Why insert mode if you're going to modify an existing record? Use just Edit...

with dm.tblBLOB do
  begin
    dm.Maximo.StartTransaction;
    Open;
    Edit;
    FieldByName('DOCUMENT').AsString := docid;
    TBlobField(FieldByName('CPLANT_BLOB')).LoadFromFile(file2blobname);
    Post;
    dm.Maximo.Commit;

Then again, this code would always modify the first record that's available after opening the table. You might want to navigate to the correct record first with e.g. a locate command. If you can't locate it, then you need to insert the record. Locate it based upon the DOCUMENT key only, btw.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11881141
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...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now