Additional
dbCAP
AnyDAC
ThinDAC
NCOCI8
Topic: How to Update a record
How to Update a record
Posted: 2003/02/05 15:28
 
Hi,
Im usign TOCI8 components. It's kool.
But i have a problem updating records in Oracle.
Mode 1:
DBUpdate.SQLUpdate.Text := 'UPDATE COLORS SET ICON_COLOR=''icon1'', ICONO_ACT=''icon2'' WHERE COLOR=''color1''';
DBUpdate.ExecSQL(skUpdate);
DB1.Commit;

This mode works very well. But I dont want to use Update SQL Queries. I need to edit field by field, such as this:

with DBQuery do begin
SQL.Text := 'SELECT * FROM COLORS';
Open;
Locate('COLOR','color1',[loCaseInsensitive]);
Edit;
FieldByName('ICON_COLOR').AsString := 'icon1';
FieldByName('ICON_ACT').AsString := 'icon2';
Post;
DB1.Commit;
end;

It does not work, because there apears an error:

Can't execute query. Undefined key fields.

And that's the problem!
How can I define the Key Fields??? The Primari Key field is the column COLOR, and the oracle contraint is PK_COLORS.

What i need to do to work fine???
Is there another way to update a record better than those???

Thaks for advanced!
RE: How to Update a record
Posted: 2003/04/30 12:49
 
You don't need to use OCIUpdateSQL at all. All you need is to properly construct SQL of OCIQuery such as to include rowid. Example: "select places.*,places.rowid from places". Then add these fields as persistant and your worries are over.
RE: How to Update a record
Posted: 2003/05/05 15:36
 
If you don't want to select ROWID, you still can update records, but you have to define key field(s).
Consider TField.ProviderFlags property.
In your case
DBQuery.FieldByName('COLOR').ProviderFlags :=
DBQuery.FieldByName('COLOR').ProviderFlags+[pfInKey];
Or you can set this at design-time.