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 > global variable

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-14-07, 06:00
erix erix is offline
Registered User
 
Join Date: Mar 2007
Posts: 1
Question global variable

Hi all,

Can someone tell me how to set our own global variable that share
same value for each client connected to mysql server?

i tried this :

Select max(invoiceNumber) + 1 from invoiceMaster into @no;

but @no is only available at current session.
How to set this @no to be global so when each client "Select @no;"
they will share the same value?

I think this solution to solve invoiceNumber problem.
If there is 2 client connected to mysql server and suppose
currently on invoiceMaster, there are 1 row with invoiceNumber 1.
When they open invoice form using "Select max(invoiceNumber) + 1 from invoiceMaster", each client will get same invoiceNumber which is 2.

And if they try to save the invoice, there will be problem because
invoiceNumber is a primary key.

So, i think there should be some global variable on the server.

So, when client A open the invoice form, this global variable(@no) will be set to max(invoiceNumber) + 1 which is 2;

If client B try to get the currently available invoiceNumber, @no
will be set to @no+1 which is now 3.

If one of them cancel the transaction, @no will be set to @no-1.

Do you guys know other solution?

Thanks folks.

Oh ya, i use mysql 5.0.27

PSorry if i put this question on wrong section.
Reply With Quote
  #2 (permalink)  
Old 03-15-07, 09:11
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
last_insert_id is most likely the direction you should be looking.
Reply With Quote
  #3 (permalink)  
Old 03-15-07, 09:57
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
to expand on what guelphdad said, you should not be using the MAX+1 technique if the invoiceNumber is an auto_increment
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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