Solved

TTable Update

Posted on 2004-08-24
3
331 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add combobox item based on numbers 9 154
Help on project with Soap 10 57
Dev Express grid collapse 2 45
TEMBEDDEDWB how can i change its user agent ? 8 70
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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