473,804 Members | 3,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comiting changes(?) With MySQL

Hi,

I have a function to update some data, I run a set of 6 queries, ( all
updates and all on the same table).
I seem to run into problems where the data does not seem to be updated
properly or the update appears to be wrong.

What the function is doing, (try to do anyway), is

given some ID numbers A, B and the same table
I need to swap the values for both items...

C is a arbitrary number used for swapping the values...

update tablex set ID_NUMBER = C where ID_NUMBER = A
update tablex set SUBID_NUMBER= C where SUBID_NUMBER = A

update tablex set ID_NUMBER = A where ID_NUMBER = B
update tablex set SUBID_NUMBER =A where SUBID_NUMBER = B

update ID_NUMBER = B where ID_NUMBER = C
update SUBID_NUMBER =B where SUBID_NUMBER = C

To me that is not a very efficient way of doing things, would there be a
better query for swapping ID_NUMER/SUBIDNUMBER like code above?

Would I need to 'COMIT' the changes to ensure that they do not get mangled
by another query using the same table, (straight after that function)?

Many thanks

Sims
Jul 17 '05 #1
1 1461
"Sims" <si*********@ho tmail.com> wrote in message
news:<2f******* *****@uni-berlin.de>...

I have a function to update some data, I run a set of 6 queries, ( all
updates and all on the same table).
I seem to run into problems where the data does not seem to be updated
properly or the update appears to be wrong.

What the function is doing, (try to do anyway), is
given some ID numbers A, B and the same table
I need to swap the values for both items...

To me that is not a very efficient way of doing things, would there be a
better query for swapping ID_NUMER/SUBIDNUMBER like code above?
Not off the top of my head...
Would I need to 'COMIT' the changes to ensure that they do not get mangled
by another query using the same table, (straight after that function)?


The purpose of transactions is not to prevent "mangling by another
query". It is to ensure that either all queries in a batch are
executed or none is. In your case it seems to be a good idea to
do something like this:

BEGIN;
UPDATE tablex SET ID_NUMBER = C where ID_NUMBER = A;
UPDATE tablex SET SUBID_NUMBER = C where SUBID_NUMBER = A;
UPDATE tablex SET ID_NUMBER = A where ID_NUMBER = B;
UPDATE tablex SET SUBID_NUMBER = A where SUBID_NUMBER = B;
UPDATE tablex SET ID_NUMBER = B where ID_NUMBER = C;
UPDATE tablex SET SUBID_NUMBER = B where SUBID_NUMBER = C;
COMMIT;

Cheers,
NC
Jul 17 '05 #2

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

Similar topics

3
11768
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
8
2692
by: William Drew | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.databases.mysql This is an invitation to discuss the following proposal to create newsgroup comp.databases.mysql. Please note that YOU CANNOT VOTE NOW; you may be able to vote on a version of this proposal later. See the PROCEDURE section below if you need information about how the discussion works. PLEASE POST ANY FOLLOWUPS TO THE NEWSGROUP NEWS.GROUPS.
0
1683
by: kayra | last post by:
Hi all, I want to get your opinions on how to increase available/free memory and performance on a heavy volume database server. I have MySQL 4.0.13 running on RH 7.2 replicated to another RH 7.2 using same MySQL version. Recently our master database server (2 AMD Cpu + 2Gb memory + 2Gb swap space) started to suffer from memory outages because of heavy load. During day available free memory is changing from 200Mb to 5Mb and when...
4
18700
by: Gordon Burditt | last post by:
What's the easiest way to copy a row from one table to another (with the same schema), without knowing in advance the number and types of the columns? The problem: I have several sets of tables with a primary key of 'account', which contains an email address. If someone changes their email address, I need to change the 'account' field. Unfortunately, someone thought it would speed up lookups if instead of having one table 'settings',...
3
5774
by: eieiohh | last post by:
MySQL 3.23.49 PHP 4.3.8 Apache 2.0.51 Hi All! Newbie.. I had a CRM Open Source application installed and running. Windows Xp crashed. I was able to copy the contents of the entire hard drive onto a USB External Hard Drive. I have to assume I also copied the data. I
39
3237
by: windandwaves | last post by:
Hi Folk I have to store up to eight boolean bits of information about an item in my database. e.g. with restaurant drive-through facility yellow windows
4
3326
by: Bob Alston | last post by:
Anyone have experience with converting an access app from Jet database to Mysql? I am specifically looking for any changes I would have to make to my access forms, queries, modules, vba code, etc. I understand there are some data format differences in text field types and date types that need to be addressed if converting from Jet to Mysql. But other than things that have to be addressed when converting, what other changes must I make?...
3
3905
by: sp3d2orbit | last post by:
I've read the MySQL licensing material and what I've found online, but I'm still unclear about when I have to pay MySQL for a license. Scenario: I've created an application that stores some data in MySQL 5.0 (InnoDB table types). It connects to MySQL 5.0 via MyODBC. 1.) If I include MySQL 5.0 and MyODBC in the installer, do I have to buy a separate MySQL license for every copy of the installer I sell? 2.) If I include MySQL 5.0 and...
0
12902
Coldfire
by: Coldfire | last post by:
Since i cannot show the differences in a two-column like table. I am first putting MS SQL Server 2005 and then MySQL 5.x. MS SQL Server 2005 Brief Overview - SQL Server is a full-fledged database system developed specifically for large enterprise databases. All advanced features of a relational database are fully implemented. - Once you purchase the product, you are only limited to the Sybase-derived engine.
0
9572
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,...
0
10562
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10303
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
10070
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6845
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
5508
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...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2978
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.