473,887 Members | 2,327 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 3855
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
5040
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
3200
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
5590
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 joins. Am I missing some obvious point about why a hj would not be used in a select for update?
1
3695
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
1528
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 the data.......that all works great.
16
2757
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 that none of the rows I'm inserting appear on the screen until I have RETURNed from my function; so If...
9
4401
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 would work! I have several fields in a master Access 2000 table, some of which are id, fname,...
3
2158
by: db2db2db2 | last post by:
it is a common question,not for db2,thank u very much
5
2268
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 them all manually. I do have access to run a simple update query to correct only the field in...
0
9957
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9799
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10875
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9593
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7141
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5809
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4632
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
2
4238
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3245
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.