Solved

TTable Update

Posted on 2004-08-24
3
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month6 days, 5 hours left to enroll

627 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