If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > use mysql as a queue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-08-04, 13:55
chucklarge chucklarge is offline
Registered User
 
Join Date: Oct 2004
Posts: 2
use mysql as a queue

Hi,
I want to find the best method to use mysql as a queue. So what I would want to do with existing mysql functions, add entries to the table at the back(ok that already happens on insert) then I want to read the first item easily, not have to put all the entrees into an array and just read the first. then delete the first entry easily.

Any help is appreciated.

Thanks,
Chuck
Reply With Quote
  #2 (permalink)  
Old 10-11-04, 05:55
snorp snorp is offline
Registered User
 
Join Date: Apr 2004
Location: Europe->Sweden->Stockholm
Posts: 71
If you have an AUTO_INCREMENT column, the last inserted row will have the highest id and the first inserted will have the lowest.

When you want to remove an element from the queue, do ("ai_col" = the name of the AUTO_INCREMENT column)
Code:
SELECT ... FROM tab WHERE id=MIN(ai_col);
DELETE FROM tab WHERE id=MIN(ai_col);
If there are many clients accessing the "queue" at the same time, use some locking mechanism to avoid race conditions and other weird stuff.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On