Subject | Re: SET GENERATOR issue (from ib-support) |
---|---|
Author | Helen Borrie |
Post date | 2002-09-06T02:27:38Z |
At 01:34 AM 06-09-02 +0000, you wrote (in [ib-support]):
an IB_Cursor or even better an IB_DSQL, provided you clear and replace the
SQL property each time. Have your conversion app write the statements to a
TStringList and then, when you are ready, start the transaction and suck
the statements off in a loop. Here's an example:
...
public
property aStrings: TStringlist;
...
In the routine where you are collecting the BDE data:
var
..
GeneratorName: String;
NewGenValue: Integer;
...
begin
...
...
if aStrings = nil then
aStrings := TStringlist.Create;
...
// code that puts values into the variables
...
aStrings.Add('SET ' + GeneratorName + '=' + IntToStr(NewGenValue)');
...
end;
Then, when you are ready to fire off the DDL to set the generator values
using a TIB_Cursor or a TIB_DSQL, do this:
...
var
...
ii: Integer;
...
begin
...
if (aStrings.Assigned and (aStrings.Count > 0)) then
with myDSQLObject, aStrings do
begin
if not ib_transaction.TransactionIsActive then
ib_transaction.StartTransaction;
for ii := 0 to Strings.Count - 1 do
begin
SQL.Clear;
SQL.Add(Strings[ii]);
Prepare;
Execute;
end;
ib_transaction.Commit;
Strings.Clear;
end;
...
end;
Because this is DDL, it will be best if you do this job inside a separate
transaction.
btw, you don't need to add 1 to the highest imported value. Generators
store the *last generated* value so they do this incrementation themselves.
Helen
>Hello,I pointed you to TIB_Script in the ib-support list but you can do this with
>
>I'm in the process of writing my import routines for all the data in
>a bde app which I'm upszing to Firebird.
>
>I have generators for most tables, and once the data is imported,
>I'm getting the highest imported ID, and want to set the generators
>to this value+1, so they are ready for when data begins being
>inserted into the new db.
>
>I'm using an IB_Cursor to SET GENERATOR a_gen TO x
>
>This works fine for one, but when I try to have two lines, I get an
>unknown token SET error on line 2.
>
>I've tried putting a ; after the line but this does not help. Why
>can I not have two (or more) SET GENERATOR in the SQL.Strings of an
>ib_cursor?
>
>-Ryan
an IB_Cursor or even better an IB_DSQL, provided you clear and replace the
SQL property each time. Have your conversion app write the statements to a
TStringList and then, when you are ready, start the transaction and suck
the statements off in a loop. Here's an example:
...
public
property aStrings: TStringlist;
...
In the routine where you are collecting the BDE data:
var
..
GeneratorName: String;
NewGenValue: Integer;
...
begin
...
...
if aStrings = nil then
aStrings := TStringlist.Create;
...
// code that puts values into the variables
...
aStrings.Add('SET ' + GeneratorName + '=' + IntToStr(NewGenValue)');
...
end;
Then, when you are ready to fire off the DDL to set the generator values
using a TIB_Cursor or a TIB_DSQL, do this:
...
var
...
ii: Integer;
...
begin
...
if (aStrings.Assigned and (aStrings.Count > 0)) then
with myDSQLObject, aStrings do
begin
if not ib_transaction.TransactionIsActive then
ib_transaction.StartTransaction;
for ii := 0 to Strings.Count - 1 do
begin
SQL.Clear;
SQL.Add(Strings[ii]);
Prepare;
Execute;
end;
ib_transaction.Commit;
Strings.Clear;
end;
...
end;
Because this is DDL, it will be best if you do this job inside a separate
transaction.
btw, you don't need to add 1 to the highest imported value. Generators
store the *last generated* value so they do this incrementation themselves.
Helen