Subject | Re: [IBO] Insert/Edit/DeleteRecord |
---|---|
Author | Frank Ingermann |
Post date | 2001-07-03T21:53:29Z |
Hi Kristy,
kristinnolan@... wrote:
thing is to make IBO aware of that identity (see KeyLinks):
- fill the SQL TStrings property with "select * from mytable"
(if possible, avoid "select *" unless you really need *all* the columns,
but that's just a performance issue)
when you use the "where filekey=:filekey" clause, you must do something
like:
with myquery do
begin
Prepare;
ParamByName('filekey').AsInteger := <myfilekey>;
Open;
end;
and you will get exactly one record (if any) - not sure if that's what
you wanted. If you know the filekey in advance, and only want that one row,
then that's the way to go.
- set KeyLinks to "mytable.filekey". Important, so IBO can uniquely identify
each row. Normally, when KeyLinksAutoDefine is True, ibo will figure this out
by itself, but afaik only when there is a declared PRIMARY KEY CONSTRAINT
on your table. Anyway good habit to explicitly set it.
- set RequestLive to TRUE (same effect as adding " for update" to your SQL)
If this is set up right, you will not need EditSQL/DeleteSQL etc.
Just use the usual Edit/Insert/Post/Cancel/Delete methods. IBO will build
the appropriate UPDATE / DELETE FROM / INSERT INTO sqls automagically
behind the scenes - in fact the IBO feature i like best <g>. You will find that
with IBO, you will (close to) never have to write any INSERT/UPDATE sqls
yourself.
The only situation where you *must* set e.g. EditSQL is when you do joins
across multiple tables, sthg like
select a.id, a.somefield, b.id_a, b.otherfield
from tablea a join tableb b on (a.id=b.id_a)
In this case, ibo can not tell which table to insert/update/delete from (a or
b),
so you must write an EditSQL like "update tablea set somefield=:somefield where
id=:old_id". (where "old_" is virtually the same as "old." in IB triggers: a
way to access the current row data)
As you are new to this, i would advise to take a look at the Getting Started
Guide (from ibobjects.com). Costs ~ 30$ and is worth every penny. Invaluable
source to get you going imho.
hth,
fingerman
kristinnolan@... wrote:
>assuming that filekey is the primary key of your table, the most important
> I have a query where I need to add a record, edit a record, and
> delete a record.
>
> The code below is what I am using to edit the record. Do I need to
> put this statement in the Edit SQL property? All the help
> information I have read says I don't need to use the Edit, Insert,
> and Delete SQL properties.
>
> select * from mytable
> where filekey = :filekey for update
thing is to make IBO aware of that identity (see KeyLinks):
- fill the SQL TStrings property with "select * from mytable"
(if possible, avoid "select *" unless you really need *all* the columns,
but that's just a performance issue)
when you use the "where filekey=:filekey" clause, you must do something
like:
with myquery do
begin
Prepare;
ParamByName('filekey').AsInteger := <myfilekey>;
Open;
end;
and you will get exactly one record (if any) - not sure if that's what
you wanted. If you know the filekey in advance, and only want that one row,
then that's the way to go.
- set KeyLinks to "mytable.filekey". Important, so IBO can uniquely identify
each row. Normally, when KeyLinksAutoDefine is True, ibo will figure this out
by itself, but afaik only when there is a declared PRIMARY KEY CONSTRAINT
on your table. Anyway good habit to explicitly set it.
- set RequestLive to TRUE (same effect as adding " for update" to your SQL)
If this is set up right, you will not need EditSQL/DeleteSQL etc.
Just use the usual Edit/Insert/Post/Cancel/Delete methods. IBO will build
the appropriate UPDATE / DELETE FROM / INSERT INTO sqls automagically
behind the scenes - in fact the IBO feature i like best <g>. You will find that
with IBO, you will (close to) never have to write any INSERT/UPDATE sqls
yourself.
The only situation where you *must* set e.g. EditSQL is when you do joins
across multiple tables, sthg like
select a.id, a.somefield, b.id_a, b.otherfield
from tablea a join tableb b on (a.id=b.id_a)
In this case, ibo can not tell which table to insert/update/delete from (a or
b),
so you must write an EditSQL like "update tablea set somefield=:somefield where
id=:old_id". (where "old_" is virtually the same as "old." in IB triggers: a
way to access the current row data)
As you are new to this, i would advise to take a look at the Getting Started
Guide (from ibobjects.com). Costs ~ 30$ and is worth every penny. Invaluable
source to get you going imho.
hth,
fingerman