Subject Re: SV: SV: [IBO] Refrasing my question about TIBOTable (prettyprinted)
Author Helen Borrie
At 07:26 AM 17/05/2011, Jacob Havkrog wrote:
>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:
>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.