473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

MySQL Lock ?

Hi,

Could someone please help me ?

I have to increase a counter for each record I insert into a table (the
value of the counter is stored in the record). I cannot use 'auto_increment'
because the counter has to start from 0 every new day. The question is : I
have to perform a SELECT query to get the current counter value and then an
INSERT to put my record, but what will happen if two (or more) users are
querying at the "same" time ??? Is there a way to "lock" the database during
the SELECT/INSERT routine ?

Thanks for your tips.

Matt.
Jul 17 '05 #1
5 3028
Matthias Ainsworth wrote:
... Is there a way to "lock" the database during
the SELECT/INSERT routine ?


goto http://www.mysql.com/

Find and select a 'search' text box

type "lock" (without the quotes) there

Click 'Go' (or press Enter)

choose a promising link and click it :)

Can't help you more; I've never needed to do something like
that, so I don't really know if it works ...

but sure looks like it does.
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
Matthias Ainsworth wrote:
Hi,

Could someone please help me ?

I have to increase a counter for each record I insert into a table (the
value of the counter is stored in the record). I cannot use 'auto_increment'
because the counter has to start from 0 every new day. The question is : I
have to perform a SELECT query to get the current counter value and then an
INSERT to put my record, but what will happen if two (or more) users are
querying at the "same" time ??? Is there a way to "lock" the database during
the SELECT/INSERT routine ?

Thanks for your tips.

Matt.


I was under the impression that MySQL has some sort of queue that
prevents corruption due to multiple concurrent writes.

~Cameron
Jul 17 '05 #3
On Sun, 08 Feb 2004 21:26:39 +0000, Cameron <fo*@bar.invalid> wrote:
Matthias Ainsworth wrote:
Hi,

Could someone please help me ?

I have to increase a counter for each record I insert into a table (the
value of the counter is stored in the record). I cannot use 'auto_increment'
because the counter has to start from 0 every new day. The question is : I
have to perform a SELECT query to get the current counter value and then an
INSERT to put my record, but what will happen if two (or more) users are
querying at the "same" time ??? Is there a way to "lock" the database during
the SELECT/INSERT routine ?

Thanks for your tips.

Matt.


I was under the impression that MySQL has some sort of queue that
prevents corruption due to multiple concurrent writes.


If he does

SELECT current value;
INSERT record with value;

it is possible, if more than one person is using the system, for
multiple users to read the same current value and so insert the same
value.

Without using triggers or subselects I'm not sure how you could do it
reliably.

--
David ( @priz.co.uk )
Jul 17 '05 #4
David Mackenzie writes:
On Sun, 08 Feb 2004 21:26:39 +0000, Cameron <fo*@bar.invalid> wrote:
Matthias Ainsworth wrote:
Hi,

Could someone please help me ?

I have to increase a counter for each record I insert into a table (the
value of the counter is stored in the record). I cannot use 'auto_increment'
because the counter has to start from 0 every new day. The question is : I
have to perform a SELECT query to get the current counter value and then an
INSERT to put my record, but what will happen if two (or more) users are
querying at the "same" time ??? Is there a way to "lock" the database during
the SELECT/INSERT routine ?

Thanks for your tips.

Matt.
I was under the impression that MySQL has some sort of queue that
prevents corruption due to multiple concurrent writes.

If he does SELECT current value;
INSERT record with value; it is possible, if more than one person is using the system, for
multiple users to read the same current value and so insert the same
value. Without using triggers or subselects I'm not sure how you could do it
reliably.


Um, LOCK TABLES?

http://www.mysql.com/doc/en/LOCK_TABLES.html

If you can't do that for some reason, you could always implement your
own locking mechanism around the PHP that executes the query.

--

__o Alex Farran
_`\<,_ Analyst / Programmer
(_)/ (_) www.alexfarran.com

Jul 17 '05 #5
On Mon, 09 Feb 2004 15:16:51 +0000, Alex Farran <al**@alexfarran.com>
wrote:
David Mackenzie writes:

Without using triggers or subselects I'm not sure how you could do it
reliably.


Um, LOCK TABLES?

http://www.mysql.com/doc/en/LOCK_TABLES.html


Oops! Didn't know about that.

--
David ( @priz.co.uk )
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Otto Haldi | last post by:
Hello to all, Could somebody tell me if it's possible to lock a record with PHP when I have a simple MySQL Database by a provider ? Many thanks in advance for your help. Best regards
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
1
by: Dave Crypto | last post by:
Hi there, SUMMARY: 1) When I use phpadmin to export a large database, the file created on my local PC never containes all the tables and information. It seems to max out at about 10mb. 2)...
11
by: Durai | last post by:
Hi All, I tested "concurrent testing" in MySQL. It works fine. But I couldn't do in PostgreSQL 7.3.4 on HPUX IPF. I got deadlock problem. I used the PHP script to update table( one script...
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
4
by: Robert Blackwell | last post by:
A while ago I had some help from here to make a batch file that would dump my db. Everything was working just fine until 2 days ago and I just found out. I checked my backup folder and found...
0
by: dboileau | last post by:
Can anyone help me out with this error, I am trying to compile mysql with gcc 3.4.6 (Compiled from source) using CC=gcc CFLAGS="-O3 -mcpu=v8 -Wa,-xarch=v8plusa" \ CXX=gcc CXXFLAGS="-O3...
1
by: Ike | last post by:
Recently, I began using a different MySQL verver (i.e. different machine as well as different version#, going from 4.12a to 4.1.9 max). The following query used to work: select firstname,...
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
2
by: Roopesh | last post by:
Hi, In my mod_python project I am using mysql as the database. There is table card in which unique cards are stored. When a user request comes he has to get a unique card. In this situation I want...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.