Subject SV: SV: SV: [IBO] Refrasing my question about TIBOTable (prettyprinted)
Author Jacob Havkrog
Thanks - but isn't

CREATE SEQUENCE AddressNo_ADDRESS_GEN
SET GENERATOR AddressNo_ADDRESS_GEN TO 180;

Enough to create the generator and initialize it to 180?

The script code that my pump makes looks like this:

SELECT MAX(AddressNo) FROM ADDRESS
CREATE SEQUENCE AddressNo_ADDRESS_GEN
SET GENERATOR AddressNo_ADDRESS_GEN TO 180;

And while I understand what the first line does in itself, my feeling here is that it is of no consequence to the making of the generator?

Jacob


Fra: IBObjects@yahoogroups.com [mailto:IBObjects@yahoogroups.com] På vegne af Helen Borrie
Sendt: 16. maj 2011 23:32
Til: IBObjects@yahoogroups.com; IBObjects@yahoogroups.com
Emne: Re: SV: SV: [IBO] Refrasing my question about TIBOTable (prettyprinted)



At 07:26 AM 17/05/2011, Jacob Havkrog wrote:
>Thanks!
>
>My triggers and the rest of the database generation script is produced by a datapump Delphi app, that I didn't write myself.
>
>I'll change the trigger generation code!
>
>In relation to this I have another question. The datapump app generates this SEQUENCE script code:
>
>SELECT MAX(AddressNo) FROM ADDRESS
>CREATE SEQUENCE AddressNo_ADDRESS_GEN
>SET GENERATOR AddressNo_ADDRESS_GEN TO 180;
>
>I'm just wondering if there is a bug here? The AddressNo generator is initialized to 180, which is the max AddressNo from my BDE database I'm pumping from. It works fine, but what's the point of the first part of the script code "SELECT MAX(AddressNo) FROM ADDRESS"? It looks wrong to me.

Its purpose would be to find the highest autoinc value, since (like Firebird sequences/generators), the Paradox engine never generates the same autoinc number for a column.

The sequence (a.k.a. generator) stores the last generated number. The next time a value is requested, that number is incremented by the specified increment value and the new number is stored for the next time. Generators (sequences), unlike everything else in Firebird, exist and are maintained independently from any user transaction.

The pump is taking the max autoinc value from the Pdox table and hard-coding it, on the assumption that you will do this pump exactly once and will never create any more new ADDRESS records in Pdox.

While this technique is OK for your one-off data conversion from Pdox to Fb, you should NEVER use a similar technique for incrementing key values in Firebird.

Helen



[Non-text portions of this message have been removed]