Subject | Re: [IBO] IB_Datapump sample code |
---|---|
Author | mspencewasunavailable |
Post date | 2006-08-09T21:54:35Z |
--- In IBObjects@yahoogroups.com, Helen Borrie <helebor@...> wrote:
reference, but it's pretty vague in a lot of places. For example,
the property DstIsSingleton is described like this:
"If the destination is a dataset with a select statement it will
normally consider that it needs to perform an Insert but if the
select is a singleton then it should bind to the parameters and
perform a singleton fetch upon execution of each item."
This implies to me that if DstIsSingleton is false, then one would
set up the dest. dataset as a TIB_Query with a Select statement
describing the fields to be changed, and that the TIB_DataPump code
knows that it should use the InsertSQL ("it needs to perform an
Insert").
There's also not very much information on exactly what happens to
the fields and who does things (me or the pump) when the data is
being pumped. Of the four modes (Direct, Assigned, Customized Item
Handling and AfterFetchRow Event Handling), I'd've thought that
Direct (and maybe Assigned) would be something that would just
happen. But the help file never clearly spells this out one way or
the other. It does say "Use the AfterFetchRow event to finish
assigning values...", which implies that the other three modes would
proceed on their own.
Hence my question about sample code <g>.
the appropriate number of inserts occurred, but the strings were
null and the integers were zero (not null).
It's like the mapping doesn't get done, even though the property
DPItemActions said they were all DIRECT. From the help file, I
gather that when a column is DIRECT, the dest. dataset just gets the
value directly from the buffer of the source, without any
intervention required on my part.
INSERT INTO CUSTG1
("Def Status", "Name", ID,
....
"Week Tax") VALUES (
:P1,
:P2,
:P3,
....
:P12
)
That gives the same error (still refers to "Def Status"), which
implies that it's objecting to the quoted field names, not the
params.
I'll try using a pair of tables with less exotic names and see what
happens.
result of a query as a table, so it can be further manipulated.
couple of hundred rows a lot, so I guess I'm safe enough with one
big commit.
>of
> At 10:24 PM 9/08/2006, you wrote:
> >Is there sample code for this component somewhere?
>
> You might like to browse through the Files area at
> http://www.yahoogroups.com/community/ibobjects. There's all sorts
> stuff there.'Course I am. I'm sure the section on TIB_DataPump is fine as a
>
> Are you referring to the IBO Help at all?
>
reference, but it's pretty vague in a lot of places. For example,
the property DstIsSingleton is described like this:
"If the destination is a dataset with a select statement it will
normally consider that it needs to perform an Insert but if the
select is a singleton then it should bind to the parameters and
perform a singleton fetch upon execution of each item."
This implies to me that if DstIsSingleton is false, then one would
set up the dest. dataset as a TIB_Query with a Select statement
describing the fields to be changed, and that the TIB_DataPump code
knows that it should use the InsertSQL ("it needs to perform an
Insert").
There's also not very much information on exactly what happens to
the fields and who does things (me or the pump) when the data is
being pumped. Of the four modes (Direct, Assigned, Customized Item
Handling and AfterFetchRow Event Handling), I'd've thought that
Direct (and maybe Assigned) would be something that would just
happen. But the help file never clearly spells this out one way or
the other. It does say "Use the AfterFetchRow event to finish
assigning values...", which implies that the other three modes would
proceed on their own.
Hence my question about sample code <g>.
> >Status" ".
> >For the dest. query, if I try setting the SQL to an insert, then
> >when I do the Prepare, I get "Invalid dml column reference: "Def
> >property
> >If I try setting the SQL to a select, then using the TIB_Query's
> >editor to generate the insert SQL, I don't get the error abovebut nothing
> >happens, either.if
>
> Don't try that. Use a properly parameterised Insert statement or,
> you have one, an EXECUTE PROCEDURE with input parameters. Butwhat
> you can do before you scrub the TIB_query is copy the generatedSee above for why I tried a select. BTW, when I did use a select,
> InsertSQL and use it as the basis for your dest dml statement.
>
the appropriate number of inserts occurred, but the strings were
null and the integers were zero (not null).
It's like the mapping doesn't get done, even though the property
DPItemActions said they were all DIRECT. From the help file, I
gather that when a column is DIRECT, the dest. dataset just gets the
value directly from the buffer of the source, without any
intervention required on my part.
>If you mean like this:
> It's not the database column name that's the issue. In your code,
> Params are column objects too. But, unlike database columns, they
> are not passed across the API by name, but by statement
> position. Parameter names are a local invention, subject to local
> (Delphi) law. Replace the parameter names with legal Delphi
> identifiers, e.g. GrandTotal, etc., and map the parameters
> individually to the columns in the input list.
INSERT INTO CUSTG1
("Def Status", "Name", ID,
....
"Week Tax") VALUES (
:P1,
:P2,
:P3,
....
:P12
)
That gives the same error (still refers to "Def Status"), which
implies that it's objecting to the quoted field names, not the
params.
I'll try using a pair of tables with less exotic names and see what
happens.
>ISTM that
> >Also, it isn't evident to me how one handles transactions here.
> >by default, AutoCommit is used.transaction
>
> Unless you're mixing up TIBO and TIB_ components, you shouldn't be
> seeing Autocommit as a default setting of the
> DefaultTransaction. TIBODatabase *is* a legal TIB_Connection
> descendant and so is compatible with TIB_ components. However, it
> has the BDE's defaults, including defaulting its embedded
> to Autocommit. TIB_Connection creates its own DefaultTransactionif
> you don't do it explicitly and it defaults Autocommit to Falseunless
> something has changed.Whups! Guilty. I'm using a TIBODatabase to connect.
>
> -- What are you using as the connection object[s] for the sourceand
> target database[s]? (The plurals here are because you have saidBoth tables are in the same database. In BDE terms, I'm saving the
> anything about the source and dest.)
result of a query as a table, so it can be further manipulated.
> -- I strongly recommend using a dedicated transaction for thiskind
> of task (TIBOTransaction for TIBODatabase, TIB_Transaction forTIB_Connection).
>time to
> > But suppose I have a very large dataset to move, and I want
> to batch the commits. May use OnAfterFetchRow to do a commit from
> time?waiting
>
> Well, OnAfterFetchRow is at a point where the latest row is
> to be mapped to the input parameters for the insert or storedto
> procedure. This data hasn't been posted into dest yet. Use that
> map the dest parameters to the source output. AfterExecuteItemsvia
> would be the place to test some counter that you are maintaining
> your OnAfterFetchRow handler and call CommitRetaining if the countis
> 8000 since the last time it was reset. (You need CommitRetainingif
> you are going to break a single pump execution into chunks,because
> you need to hold the cursor on the source output. Just don'tforget
> to call a hard Commit on the last record, e.g. in AfterExecute.)inserts
>
> If the whole datapump isn't going to be larger than around 8000
> records, don't bother to batch. The optimum size for batched
> is in the range of 8000-10,000, though it will be less if there'sa
> lot of other stuff happening at the same time.Oh. Well, AFAICT, all of the code that uses this would consider a
>
couple of hundred rows a lot, so I guess I'm safe enough with one
big commit.
> You might also like to refer to the DstStatement's events. TheI'll look at those things. Thanks, Helen.
> DstStatement is a TIB_Statement. AfterExecDML could be useful, I
> suspect, if it precedes the datapump's own AfterExecuteItems.