in reply to Queues, not the usual problem

I would suggest having a table with an autoincrement field, so your query would be
SELECT * FROM table ORDER BY row LIMIT x;
where x is how many lines you want to process...

To handle row locking you could add a status field, and then do your insert, anything else you need to do, then do an
UPDATE table SET status = 1 WHERE row = LAST_INSERT_ID();
and then change the select to check for status = 1...
but I think as long as your insert is only a single simple insert that it is not a problem...

Update bad suaveant, didn't read the post right... use the row id from autoincrement to key into your second table, and then do the update to set the status = 1 in the main table... that should do you good. So do main insert, then
SELECT LAST_INSERT_ID() FROM table1;
and use that key to populate table2 with the proper key, then
UPDATE table SET status = 1 WHERE key = $key;

Should work great

                - Ant

Replies are listed 'Best First'.
Re: Re: Queues, not the usual problem
by arhuman (Vicar) on Jul 09, 2001 at 17:33 UTC
    I'd alternatively suggest (from the MySQL manual) :

    • If you mainly mix INSERT and SELECT statements, the DELAYED attribute to INSERT will probably solve your problems.

    • If you have problems with SELECT and DELETE, the LIMIT option to DELETE may help.


    "Only Bad Coders Code Badly In Perl" (OBC2BIP)