473,386 Members | 1,823 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,386 software developers and data experts.

Select .. for update question

Hi,

I need to implement a counter and i face problem of locking so hope
that u guys can help me.

I try to do test like this :

1st connection
SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update;
(when i execute this statement and i guess that this will lock the
record and prevent other connection to update that record right?)
2nd connection
Update nextkey SET inextkey = inextkey + 1 WHERE tblname = 'PLCN';
(I execute this in another connection after i have executed the
select for update statement in the first connection. However, this
statement does update the record!!!)

My major concern is that how can i prevent 2 ppl getting the same
counter. TQ!!!!!!!!
I am using InnoDb table + Mysql 4.0.17
Jul 20 '05 #1
5 3808
jayson_13 wrote:
Hi,

I need to implement a counter and i face problem of locking so hope
that u guys can help me.

I try to do test like this :

1st connection
SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update;
(when i execute this statement and i guess that this will lock the
record and prevent other connection to update that record right?)
2nd connection
Update nextkey SET inextkey = inextkey + 1 WHERE tblname = 'PLCN';
(I execute this in another connection after i have executed the
select for update statement in the first connection. However, this
statement does update the record!!!)

My major concern is that how can i prevent 2 ppl getting the same
counter. TQ!!!!!!!!
I am using InnoDb table + Mysql 4.0.17


Google is your friend:
http://www.google.com/search?q=mysql+lock+table

The first entry is the page you want from the MySQL manual.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 20 '05 #2
Jayson,

----- Original Message -----
From: "Chris Hope" <bl*******@electrictoolbox.com>
Newsgroups: mailing.database.mysql
Sent: Friday, October 22, 2004 4:02 AM
Subject: Re: Select .. for update question
jayson_13 wrote:
Hi,

I need to implement a counter and i face problem of locking so hope
that u guys can help me.

I try to do test like this :

1st connection
SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update;
(when i execute this statement and i guess that this will lock the
record and prevent other connection to update that record right?)
2nd connection
Update nextkey SET inextkey = inextkey + 1 WHERE tblname = 'PLCN';
(I execute this in another connection after i have executed the
select for update statement in the first connection. However, this
statement does update the record!!!)

My major concern is that how can i prevent 2 ppl getting the same
counter. TQ!!!!!!!!
you have probably not set

SET AUTOCOMMIT=0

and the lock by the 1st connection is released in the autocommit immediately
after you execute the SELECT ... FOR UPDATE.
I am using InnoDb table + Mysql 4.0.17
Google is your friend:
http://www.google.com/search?q=mysql+lock+table

The first entry is the page you want from the MySQL manual.


Using LOCK TABLES is not a very good method for InnoDB tables, because
MySQL's table locking mechanism does not have deadlock detection in
combination with row locks inside InnoDB. We will soon implement LOCK TABLES
TRANSACTIONAL that will work like in DB2, SQL Server, Oracle, and will be
the recommended method for locking InnoDB type tables.
--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/


Best regards,

Heikki Tuuri
Innobase Oy
Foreign keys, transactions, and row level locking for MySQL
InnoDB Hot Backup - a hot backup tool for InnoDB which also backs up MyISAM
tables
http://www.innodb.com/order.php

Order MySQL technical support from https://order.mysql.com/
Jul 20 '05 #3
Hi Turri,

I am testing it using mysql front 2.2. The following is how i
test... please tell me what the hell i have done wrong... TQ !

1st Connection
SET Autocommit=0;
SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update;
(if i am not mistaken, at this point, the transaction is not yet
completed. so the record supposed to be locked right?)

2nd Connection
Update nextkey SET inextkey = inextkey + 1 WHERE tblname =
'PLCN';

The 2nd connection still manage to update the record!

Please help... i don't know what i did wrong ...

TQ!!!!!!!


"Heikki Tuuri" <He**********@innodb.com> wrote in message news:<jj************@read3.inet.fi>...
Jayson,

----- Original Message -----
From: "Chris Hope" <bl*******@electrictoolbox.com>
Newsgroups: mailing.database.mysql
Sent: Friday, October 22, 2004 4:02 AM
Subject: Re: Select .. for update question
jayson_13 wrote:
Hi,

I need to implement a counter and i face problem of locking so hope
that u guys can help me.

I try to do test like this :

1st connection
SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update;
(when i execute this statement and i guess that this will lock the
record and prevent other connection to update that record right?)
2nd connection
Update nextkey SET inextkey = inextkey + 1 WHERE tblname = 'PLCN';
(I execute this in another connection after i have executed the
select for update statement in the first connection. However, this
statement does update the record!!!)

My major concern is that how can i prevent 2 ppl getting the same
counter. TQ!!!!!!!!
you have probably not set

SET AUTOCOMMIT=0

and the lock by the 1st connection is released in the autocommit immediately
after you execute the SELECT ... FOR UPDATE.
I am using InnoDb table + Mysql 4.0.17


Google is your friend:
http://www.google.com/search?q=mysql+lock+table

The first entry is the page you want from the MySQL manual.


Using LOCK TABLES is not a very good method for InnoDB tables, because
MySQL's table locking mechanism does not have deadlock detection in
combination with row locks inside InnoDB. We will soon implement LOCK TABLES
TRANSACTIONAL that will work like in DB2, SQL Server, Oracle, and will be
the recommended method for locking InnoDB type tables.
--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/


Best regards,

Heikki Tuuri
Innobase Oy
Foreign keys, transactions, and row level locking for MySQL
InnoDB Hot Backup - a hot backup tool for InnoDB which also backs up MyISAM
tables
http://www.innodb.com/order.php

Order MySQL technical support from https://order.mysql.com/

Jul 20 '05 #4
Jayson,

maybe MySQL-Front terminates the connection and commits the transaction
after EVERY SQL statement that you run?

Please test with the mysql command-line SQL client.

Best regards,

Heikki Tuuri
Innobase Oy
Foreign keys, transactions, and row level locking for MySQL
InnoDB Hot Backup - a hot backup tool for InnoDB which also backs up MyISAM
tables
http://www.innodb.com/order.php

Order MySQL technical support from https://order.mysql.com/

"jayson_13" <ja*******@yahoo.com> kirjoitti
viestissä:85**************************@posting.goo gle.com...
Hi Turri,

I am testing it using mysql front 2.2. The following is how i
test... please tell me what the hell i have done wrong... TQ !

1st Connection
SET Autocommit=0;
SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update;
(if i am not mistaken, at this point, the transaction is not yet
completed. so the record supposed to be locked right?)

2nd Connection
Update nextkey SET inextkey = inextkey + 1 WHERE tblname =
'PLCN';

The 2nd connection still manage to update the record!

Please help... i don't know what i did wrong ...

TQ!!!!!!!


"Heikki Tuuri" <He**********@innodb.com> wrote in message
news:<jj************@read3.inet.fi>...
Jayson,

----- Original Message -----
From: "Chris Hope" <bl*******@electrictoolbox.com>
Newsgroups: mailing.database.mysql
Sent: Friday, October 22, 2004 4:02 AM
Subject: Re: Select .. for update question
> jayson_13 wrote:
>
>> Hi,
>>
>> I need to implement a counter and i face problem of locking so hope
>> that u guys can help me.
>>
>> I try to do test like this :
>>
>> 1st connection
>> SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update;
>> (when i execute this statement and i guess that this will lock the
>> record and prevent other connection to update that record right?)
>>
>>
>> 2nd connection
>> Update nextkey SET inextkey = inextkey + 1 WHERE tblname = 'PLCN';
>> (I execute this in another connection after i have executed the
>> select for update statement in the first connection. However, this
>> statement does update the record!!!)
>>
>> My major concern is that how can i prevent 2 ppl getting the same
>> counter. TQ!!!!!!!!


you have probably not set

SET AUTOCOMMIT=0

and the lock by the 1st connection is released in the autocommit
immediately
after you execute the SELECT ... FOR UPDATE.
>> I am using InnoDb table + Mysql 4.0.17
>
> Google is your friend:
> http://www.google.com/search?q=mysql+lock+table
>
> The first entry is the page you want from the MySQL manual.


Using LOCK TABLES is not a very good method for InnoDB tables, because
MySQL's table locking mechanism does not have deadlock detection in
combination with row locks inside InnoDB. We will soon implement LOCK
TABLES
TRANSACTIONAL that will work like in DB2, SQL Server, Oracle, and will be
the recommended method for locking InnoDB type tables.
> --
> Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/


Best regards,

Heikki Tuuri
Innobase Oy
Foreign keys, transactions, and row level locking for MySQL
InnoDB Hot Backup - a hot backup tool for InnoDB which also backs up
MyISAM
tables
http://www.innodb.com/order.php

Order MySQL technical support from https://order.mysql.com/

Jul 20 '05 #5
Hi Turri,

TQ! i got it work now !!! so stupid i am... :)



"Heikki Tuuri" <He**********@innodb.com> wrote in message news:<9Q****************@read3.inet.fi>...
Jayson,

maybe MySQL-Front terminates the connection and commits the transaction
after EVERY SQL statement that you run?

Please test with the mysql command-line SQL client.

Best regards,

Heikki Tuuri
Innobase Oy
Foreign keys, transactions, and row level locking for MySQL
InnoDB Hot Backup - a hot backup tool for InnoDB which also backs up MyISAM
tables
http://www.innodb.com/order.php

Order MySQL technical support from https://order.mysql.com/

"jayson_13" <ja*******@yahoo.com> kirjoitti
viestissä:85**************************@posting.goo gle.com...
Hi Turri,

I am testing it using mysql front 2.2. The following is how i
test... please tell me what the hell i have done wrong... TQ !

1st Connection
SET Autocommit=0;
SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update;
(if i am not mistaken, at this point, the transaction is not yet
completed. so the record supposed to be locked right?)

2nd Connection
Update nextkey SET inextkey = inextkey + 1 WHERE tblname =
'PLCN';

The 2nd connection still manage to update the record!

Please help... i don't know what i did wrong ...

TQ!!!!!!!


"Heikki Tuuri" <He**********@innodb.com> wrote in message
news:<jj************@read3.inet.fi>...
Jayson,

----- Original Message -----
From: "Chris Hope" <bl*******@electrictoolbox.com>
Newsgroups: mailing.database.mysql
Sent: Friday, October 22, 2004 4:02 AM
Subject: Re: Select .. for update question

> jayson_13 wrote:
>
>> Hi,
>>
>> I need to implement a counter and i face problem of locking so hope
>> that u guys can help me.
>>
>> I try to do test like this :
>>
>> 1st connection
>> SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update;
>> (when i execute this statement and i guess that this will lock the
>> record and prevent other connection to update that record right?)
>>
>>
>> 2nd connection
>> Update nextkey SET inextkey = inextkey + 1 WHERE tblname = 'PLCN';
>> (I execute this in another connection after i have executed the
>> select for update statement in the first connection. However, this
>> statement does update the record!!!)
>>
>> My major concern is that how can i prevent 2 ppl getting the same
>> counter. TQ!!!!!!!!

you have probably not set

SET AUTOCOMMIT=0

and the lock by the 1st connection is released in the autocommit
immediately
after you execute the SELECT ... FOR UPDATE.

>> I am using InnoDb table + Mysql 4.0.17
>
> Google is your friend:
> http://www.google.com/search?q=mysql+lock+table
>
> The first entry is the page you want from the MySQL manual.

Using LOCK TABLES is not a very good method for InnoDB tables, because
MySQL's table locking mechanism does not have deadlock detection in
combination with row locks inside InnoDB. We will soon implement LOCK
TABLES
TRANSACTIONAL that will work like in DB2, SQL Server, Oracle, and will be
the recommended method for locking InnoDB type tables.

> --
> Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

Best regards,

Heikki Tuuri
Innobase Oy
Foreign keys, transactions, and row level locking for MySQL
InnoDB Hot Backup - a hot backup tool for InnoDB which also backs up
MyISAM
tables
http://www.innodb.com/order.php

Order MySQL technical support from https://order.mysql.com/

Jul 20 '05 #6

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

Similar topics

17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
29
by: Mainlander | last post by:
An ISP I belong to uses Majordomo for their mailing list system. I'd like to encourage them to move to a system that uses a database, preferably psql which they already run on their server....
3
by: charles | last post by:
I've got maybe a stupid question, concerning the difference between a simple select and a select for update ( otherwise identical ). The plan for such selects - in a DPF enviropnment - are...
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
0
by: jmacduff | last post by:
Big question: How to enable edit/update commands to work when setting the sqldatasource select command from code behind. Details: I have a GridView using a sqldatasouce with the select and...
16
by: Richard Maher | last post by:
Hi, I have this Applet-hosted Socket connection to my server and in an ONevent/function I am retrieving all these lovely rows from the server and inserting them into the Select-List. (The on...
9
by: P3Eddie | last post by:
Hello all! I don't know if this can even be done, but I'm sure you will either help or suggest another avenue to accomplish the same. My problem may be a simple find duplicates / do something...
3
by: db2db2db2 | last post by:
it is a common question,not for db2,thank u very much
5
by: Chris Cowles | last post by:
I use an application that uses Oracle 8.1.7. All functions of the application are completed with calls to stored procedures. A data entry error occurred that caused thousands of records to be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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.