473,570 Members | 2,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3825
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*******@elec trictoolbox.com >
Newsgroups: mailing.databas e.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**********@i nnodb.com> wrote in message news:<jj******* *****@read3.ine t.fi>...
Jayson,

----- Original Message -----
From: "Chris Hope" <bl*******@elec trictoolbox.com >
Newsgroups: mailing.databas e.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*******@yaho o.com> kirjoitti
viestissä:85*** *************** ********@postin g.google.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**********@i nnodb.com> wrote in message
news:<jj******* *****@read3.ine t.fi>...
Jayson,

----- Original Message -----
From: "Chris Hope" <bl*******@elec trictoolbox.com >
Newsgroups: mailing.databas e.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**********@i nnodb.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*******@yaho o.com> kirjoitti
viestissä:85*** *************** ********@postin g.google.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**********@i nnodb.com> wrote in message
news:<jj******* *****@read3.ine t.fi>...
Jayson,

----- Original Message -----
From: "Chris Hope" <bl*******@elec trictoolbox.com >
Newsgroups: mailing.databas e.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
4982
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 cust_no, ded_type_cd, chk_no)
29
3138
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. Anything out there in Php?
3
5581
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 completely different. Hash joins are used and the select without update returns fairly quickly, while the select for update involves large nested loop...
1
3654
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 "access_log", the referential integrity triggers generate these queries: SELECT 1 FROM ONLY "public"."application_type" x
0
1508
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 update commands set. The gridview is part of a "admin" page where the admin will view the data, then use the gridview edit/update buttons to update...
16
2734
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 screen appearance of the Select List grows for the first 5 rows then the scroll bar appears if there's more). So far so good. . . The problem is...
9
4384
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 with only one of the duplicates issue, but I got to the point where an update query with a nested select subquery would work wonderfully, if only it...
3
2142
by: db2db2db2 | last post by:
it is a common question,not for db2,thank u very much
5
2252
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 created with a consistent error in a single field. I can identify those easily records with a select statement. I'd *really* rather not have to change...
0
7724
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7633
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7944
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5523
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5247
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3681
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2131
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 we have to send another system
0
971
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.