Board index » delphi » generators in a multi-user system

generators in a multi-user system

I read that there may be problems using generators with a multi-user
system... can someone explain what I need to avoid?

I have a system that increments a reference number field to be posted in a
record. I don't increment it until right before I post it. I currently use a
table with a field that I programatically incremented (it has some date
stamping in it that I had to use) but the users get duplicate values
sometimes even though I call a refresh before every "read".

I was going to use a generator but some of the posts say that it won't work
in a multi-user system. So I was wondering what a better solution would be.

Thanks.

 

Re:generators in a multi-user system


Quote
Erick wrote:

> I read that there may be problems using generators with a multi-user
> system...

        Generators exist for the sole purpose of eliminating multi-user
conflicts.  The only "problem" you'll have is if you misuse them or
expect them to do something other than what they're designed for.
Here's what you need to know:

o  The purpose of a generator is to produce a UNIQUE number.  It may, or
may not be an unbroken sequence.  The only thing which is guaranteed is
that it will be unique.
o  Always get a generated ID by incrementing the generator.  Never
decrement a generator.  If you increment, you will always get a unique
value.

Quote
> can someone explain what I need to avoid?

        Decrementing them.

Quote
> I have a system that increments a reference number field to be posted in a
> record. I don't increment it until right before I post it. I currently use a
> table with a field that I programatically incremented (it has some date
> stamping in it that I had to use) but the users get duplicate values
> sometimes even though I call a refresh before every "read".

        A generator should fix this.  You just can't count on the reference
numbers being sequential.  Generators run outside of transaction
control, so if a user increments a generator and then rolls back their
transaction, the generator will increment but there will be no
corresponding record.

Quote
> I was going to use a generator but some of the posts say that it won't work
> in a multi-user system. So I was wondering what a better solution would be.

        A generator is the right solution, IMHO.

        -Craig

--
 Craig Stuntz (TeamB) Vertex Systems Corp. Columbus, OH
We're hiring: http://www.vertexsoftware.com/careerops.htm#sd
     Delphi/InterBase WebLog: http://delphi.weblogs.com

Re:generators in a multi-user system


Would it be better to use a query to get the generator value such as:

SELECT GEN_ID(MY_GENERATOR, 1) FROM  RDB$DATABASE

Or use a stored procedure and then wrap it with the TIBStoreProc? And which
one is more "efficient"?

"Craig Stuntz (TeamB)" <cstuntz@no_spam.vertexsoftware.com> wrote in message
news:3BF59741.A63FE1E0@no_spam.vertexsoftware.com...

Quote

> Erick wrote:

> > I read that there may be problems using generators with a multi-user
> > system...

> Generators exist for the sole purpose of eliminating multi-user
> conflicts.  The only "problem" you'll have is if you misuse them or
> expect them to do something other than what they're designed for.
> Here's what you need to know:

> o  The purpose of a generator is to produce a UNIQUE number.  It may, or
> may not be an unbroken sequence.  The only thing which is guaranteed is
> that it will be unique.
> o  Always get a generated ID by incrementing the generator.  Never
> decrement a generator.  If you increment, you will always get a unique
> value.

> > can someone explain what I need to avoid?

> Decrementing them.

> > I have a system that increments a reference number field to be posted in
a
> > record. I don't increment it until right before I post it. I currently
use a
> > table with a field that I programatically incremented (it has some date
> > stamping in it that I had to use) but the users get duplicate values
> > sometimes even though I call a refresh before every "read".

> A generator should fix this.  You just can't count on the reference
> numbers being sequential.  Generators run outside of transaction
> control, so if a user increments a generator and then rolls back their
> transaction, the generator will increment but there will be no
> corresponding record.

> > I was going to use a generator but some of the posts say that it won't
work
> > in a multi-user system. So I was wondering what a better solution would
be.

> A generator is the right solution, IMHO.

> -Craig

> --
>  Craig Stuntz (TeamB) Vertex Systems Corp. Columbus, OH
> We're hiring: http://www.vertexsoftware.com/careerops.htm#sd
>      Delphi/InterBase WebLog: http://delphi.weblogs.com

Re:generators in a multi-user system


Quote
Erick wrote:

> Would it be better to use a query to get the generator value such as:

> SELECT GEN_ID(MY_GENERATOR, 1) FROM  RDB$DATABASE

> Or use a stored procedure and then wrap it with the TIBStoreProc? And which
> one is more "efficient"?

        I would expect speed to be quite similar in either case.  Neither
should take a perceptable amount of time to run.

        -Craig

--
 Craig Stuntz (TeamB) Vertex Systems Corp. Columbus, OH
We're hiring: http://www.vertexsoftware.com/careerops.htm#sd
     Delphi/InterBase WebLog: http://delphi.weblogs.com

Other Threads