Solved

TTable Update

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…

785 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