473,506 Members | 16,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mod python - mysql lock

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 to use LOCK with
which I can prevent other users accessing the table. I tried excuting
"LOCK" command of mysql through python code, but it is not locking the
database. Any ideas why this isn't working and how can I do the same.

//python code
sql = "LOCK TABLES card WRITE"
cursor.execute(sql)
Regards
Roopesh

Mar 5 '07 #1
2 3419
Roopesh wrote:
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 to use LOCK with
which I can prevent other users accessing the table. I tried excuting
"LOCK" command of mysql through python code, but it is not locking the
database. Any ideas why this isn't working and how can I do the same.

//python code
sql = "LOCK TABLES card WRITE"
cursor.execute(sql)
How have you verified that the lock isn't actually working?

From http://dev.mysql.com/doc/refman/5.0/...k-tables.html:

"UNLOCK TABLES explicitly releases any locks held by the current
thread. All tables that are locked by the current thread are implicitly
unlocked when the thread issues another LOCK TABLES, or when the
connection to the server is closed."

Note the last part -- the lock is apparently released when the
connection is closed. Is that perhaps what is happening? Remember that
once your request is done in mod_python, it will (probably) release any
allocated resources, which means that your connection will be closed,
and your lock released, if it wasn't previously.

Database locks are, generally, bad. Avoid them, and only use them
when they really are the only solution.

From what little information you supply, it seems that what you need
is simply automatic id generation. Essentially you to do this:

INSERT INTO foobar (title) VALUES ('yuck')

SELECT LAST_INSERTED_ID()

foobar needs to have an auto_increment column, and LAST_INSERTED_ID()
is probably called something else (long time since I used MySQL).

This is actually more of a MySQL question. Or even a generic database
design question. I would suggest you try asking in a more appropriate forum.

--
Kind regards,
Jan Danielsson
Mar 5 '07 #2
If you use MySQL 5, you get atomic transactions. The old
"LOCK" thing is becoming obsolete. Suggest getting a newer
MySQL and a newer MySQL book.

John Nagle

Jan Danielsson wrote:
Roopesh wrote:
>>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 to use LOCK with
which I can prevent other users accessing the table. I tried excuting
"LOCK" command of mysql through python code, but it is not locking the
database. Any ideas why this isn't working and how can I do the same.

//python code
sql = "LOCK TABLES card WRITE"
cursor.execute(sql)
Mar 5 '07 #3

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

Similar topics

4
6191
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
1218
by: Christopher DeMarco | last post by:
Hi all... ...I've got a Python script running on a bunch of boxen sharing some common NFS-exported space. I need (not want :) to lock files for writing, and I need (not want :) to do it safely...
1
3358
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...
1
3680
by: Jerry Fleming | last post by:
Hi, I have wrote a game with python curses. The problem is that I want to confirm before quitting, while my implementation doesn't seem to work. Anyone can help me? #!/usr/bin/python # #...
4
3681
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
3085
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
15369
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
11684
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...
0
7307
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
7370
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...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.