Re: Updating a database w/pro *C
Date: 12 Jan 1994 03:35:33 -0600
Message-ID: <CJIFts.KM6_at_uk.ac.brookes>
Andrew Ryan (genanr_at_amiserv.xnet.com) wrote:
> Is the a quick way to do a update/append rows in a table using host
> arrays in pro*c. I would like it to change data if the key is already in
> the table and add a new row if the key is not in the table. From look at
> the book it looks like I can do either an insert or and update but it looks
> like I cannot make it append if the data was not found other than doing it
> in two steps. Which I could do, but would rather to it in one step.
> Andy
I think what you're currently doing is:
SELECT data FROM table;
if (NOT_FOUND) {
INSERT new_data INTO table;
} else {
UPDATE table SET columns=new_data;
}
The alternative is, assuming that you have a unique index on the table:
INSERT new_data INTO table;
or something like that...
if (DUPLICATE_VALUE_IN_INDEX) {
SELECT data FROM table;
UPDATE table SET columns=new_data;
}
--
_________________________ _______________________________
/ Tommy Wareing \ / 'Happy, happy. Joy, joy!' \
| p0070621_at_brookes.ac.uk X said Ren & Stimpy |
\ 0865-483389 / \ (Supplied by Simone, not me!) /
~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Received on Wed Jan 12 1994 - 10:35:33 CET