Mailing List Archive



Back to the month index Back to the list index

A. R. M. (ali@cafe.sdc.uwo.ca)
Sun, 6 Apr 1997 18:03:32 -0400 (EDT)


Date: Sun, 6 Apr 1997 18:03:32 -0400 (EDT)
From: "A. R. M." <ali@cafe.sdc.uwo.ca>
Subject: [mSQL] Using _seq get sequential numbers?
Message-Id: <Pine.SGI.3.95.970406174630.20373A-100000@cafe.sdc.uwo.ca>

I'm trying to use the system variable _seq to automatically get sequential
numbers for a field.
_seq is defined to have a starting value of 1 with a step of 1. Here's how
I've written the Lite code for this purpose:

============== code ==================

        if (msqlQuery($sock,"SELECT _seq FROM testtable") < 0)
        {
                fatal("Error : $ERRMSG\n");
        }
        $res = msqlStoreResult();
        $job_number = $res;
        msqlFreeResult($res);
        if (msqlQuery($sock,"SELECT number FROM testtable WHERE number=$job_number") < 0)
        {
                fatal("Error : $ERRMSG\n");
        }
        $reslt = msqlStoreResult();
        if (msqlNumRows($reslt) != 0)
        {
                echo ("<H2><I>Addition Failed!!!<br>\n");
                echo ("A position with that number already exists.<br>\n");
        }
        else
        {
                [the rest of the code]
        }
        msqlFreeResult($reslt);
        msqlClose($sock);

================ end code ========================

Now, what happens is that the first time I run the progran, it runs fine.
A number (1) is assigned, it's passed to $job_number and is used to fill
the field called "number" in the testtable.
The second time around, the SELECT _seq statement works as it should. it's
incremented to 2, and I assume that $job_number is passed the value and
becomes 2.
But then I get the error message I defined and it returns to me:
"A Position with that number already exists!" blah blah
Also, if I do a search on job number 1, it returns nothing but if I browse
the table, job number 1 and all its entries exist!

Does anyone know why I should get this error? If it is an error in fact. I
know I cannot use _seq for a search or order etc. but I'm assigning the
value of _seq to another variable ($job_number).
Any idea how to fix it please?
Thanks.

--------------------------------------------------------------------------
To remove yourself from the Mini SQL mailing list send a message containing
"unsubscribe" to "unsubscribe" to msql-list-request@bunyip.com. Send a message containing
"info msql-list" to majordomo@bunyip.com for info on monthly archives of
the list. For more help, mail owner-msql-list@bunyip.com NOT the msql-list!