Subject Re: [IBO] IB_Import and Primary Key problem
Author Helen Borrie
At 06:20 AM 11/11/2005 +0000, you wrote:
> > Show us your INSERT statement.
>
>Helen,
>
>Thanks for your reply.
>
>I'm not sure what you mean by 'my' insert statement.

Yeah, OK, I see what's going on.



>AIU, IB_Import prepares the insert statement
>based upon the fieldlist I provide it, and as I step
>through IB_Import.MakeInsertStatement I can see it
>being prepared, but it is indeed prepared without the
>needed first field which is the primary key.

Yes, because it's not in the source set, so there is nothing to map it
to. Which is fine, let the database do this for you.


>So, am I supposed to somehow prepare IB_Import
>to add the primary key as the first field?
You should have a BI trigger on the destination table, as

create trigger bi_mytable
active before insert
as
begin
if (new.MyPK is null) then
new.MyPK = gen_id(MyGenerator, 1);
end

>It does not seem to work if I add the primary
>key to the start of the fieldlist.

It would if it was in the destination fieldlist. Then provided its
identifier was exactly the same as the one in your GeneratorLinks, IBO will
included it. But, for this kind of batch importing it's
inefficient. Leave the dest fieldlist as it is and let the trigger do the
work.

>Am supposed to prepare the insert statement directly
>for IB_Import?

Depends whether you and I mean the same thing by "Prepare". Prepare is a
method of a statement, that sets up things like fields and parameters. It
should only be called once. It's likely that TIB_Import does it itself if
needed, as part of its Execute sequence.


>Perhaps through an IB_Table for the table to used
>by IB_Import?

Not clear what this question asks. There is no "IB_Table". Basically, an
import consists of file reads (from the source file) and either inserts to
a table (executes a parameterised INSERT statement) or executes a
parameterised stored procedure. So, if you are using a table, you need at
least all of your non-nullable columns "covered" by the structure that
tib_import makes out of your source specifications.

Helen