esolm has asked for the wisdom of the Perl Monks concerning the following question:

$sessionid = $logquery->fetchrow_array; $sessionid = '0' if not defined $sessionid; $sessionid++;
This works great until $sessionid = 10, then $sessionid++; does not increment to 11. Later in the code I insert $sessionid into a database and after 10 I get a PK violation. How do I make $sessionid increment larger than 10.

2001-05-14 Edit by Corion : Changed the title to be more descriptive. See SQL unique IDs and Sessions (was: yesterday I posted this and you all aksed for more info so ........) for the refined question with more data and more answers.

Replies are listed 'Best First'.
(tye)Re: an easy one
by tye (Sage) on May 10, 2001 at 02:33 UTC

    Sounds to me like you've defined the session ID field in your database to be a single character.

            - tye (but my friends call me "Tye")
Re: an easy one
by arturo (Vicar) on May 10, 2001 at 01:40 UTC

    I suspect there's something else going wrong here in code that you haven't posted. There's no reason ++ wouldn't increment beyond 10. Try printing or checking the value of $sessionid right after you issue the ++ ... my stab in the dark is that somewhere else in your code you're accidentally setting $sessionid to 10

    BTW, you might try this more "perlish" way of writing the first two lines:

    $sessionid = $logquery->fetchrow_array() || 0; $sessionid++;

    HTH

Re: an easy one
by no_slogan (Deacon) on May 10, 2001 at 01:43 UTC
    Hurm, it would help if we could see what the query was. Is the sessionid a varchar that's getting alphabetized in a way you didn't expect?

    BTW, you probably want to say

    ($sessionid) = $logquery->fetchrow_array()
    to make sure that list-to-scalar conversion doesn't bite you.