Subject Re: Is some API to get generator value?
Author karolbieniaszewski
--- In firebird-support@yahoogroups.com, Fulvio Senore <mailing@...> wrote:
>
>
>
> Il 12/04/2011 7.50, karolbieniaszewski ha scritto:
> >
> > --- In firebird-support@yahoogroups.com, Ann Harrison<aharrison@> wrote:
> >>
> >>> --- In firebird-support@yahoogroups.com, "karolbieniaszewski"<liviuslivius@> wrote:
> >>>>
> >>>> is some API to get generator value?
> >>>> or only possible way is
> >>>> select GEN_ID(gen_name, 0) from RDB$Database
> >>>>
> >>>> i ask because this is stupid to start transaction to get non transactional object value
> >>
> >>
> >> On Mon, Apr 11, 2011 at 3:56 PM, emb_blaster<EMB_Blaster@> wrote:
> >>
> >>> AFAICR, no. There's not.
> >>>
> >>> If you are using ISQL, you could use "SHOW GENERATOR xxxxx;" or "SHOW SEQUENCE xxxxxx;", or yet "SHOW GENERATORS;" or "SHOW SEQUENCES;" to list all. (see http://www.firebirdsql.org/refdocs/langrefupd21-ddl-sequence.html)
> >>
> >> Any of those statements will either open a transaction or use the DDL
> >> transaction.
> >>>
> >>> Also, I can agree that seems make no sense at all that. But I've learned to do not call stupid something I did not understand at all. Maybe in the time it was made, a "no transaction request" would make no sense too.
> >>> So, if someone else could explain, I would be glad to learn too. But don't think this is a bug or a missing feature at all. :)
> >>>
> >>
> >> Since you can neither write nor read the contents of the database
> >> without an open
> >> transaction, it may be that the designers assumed that there would be
> >> a transaction
> >> started or about to start when someone wanted the current contents of
> >> a generator.
> >> Note that in a multi-user application, the value returned by GEN_ID
> >> (<generator>,0)
> >> may well not be the value most recently stored by the transaction that
> >> gets the value.
> >>
> >> Good luck,
> >>
> >> Ann
> >>
> >
> > Generator is non transactional and next unique value is generated by mutex locking for multiuser use. And starting database context transaction is unnecessary, time costs, resource costs ..
> >
> > and i say "stupid" in condition as "unnecessary"
> > may English is bad so sorry for some mistakes..
> >
> > Karol Bieniaszewski
> >
>
> As far as I know, generators are used to get primary keys values for new
> rows. Inserting a row requires a transaction, so you will need it anyway.
>
> Are there real situations when you might need to know a generator value
> without using it in a transaction?
>
> Fulvio Senore
>

Generator can be used for some other conditions
1. as database settings
2. as replacement for events - you can inc generator value in some conditions eg. some client interest tables are modified.
Client read in some interval generator value if is different then previous then data should be refreshed
3 ..
4..

i suppose more examples can other users show

Karol Bieniaszewski