If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > mysql multistatement query problem(if one query fail how we rollback)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-16-11, 09:22
rohitamitpathak rohitamitpathak is offline
Registered User
 
Join Date: Feb 2011
Location: india- new delhi
Posts: 31
mysql multistatement query problem(if one query fail how we rollback)

Hello all,
I am using Mysql c api for database interaction, I want to know that if one query of Mysql multi statement fail then how we roll back all query which successfully executed..
ex-
mysql_query(conn,"insert into t values(1);insert into t values(2);insert into t values('c')")
if there are a scenario where queries are dependent to each other and here if one query fail then related other query should be rollback for making database consistency,[ mysql multi statement execute query one by one so how we will check all query will be run , if all can be run, then only process continue]
Here in this example , second query is wrong, i want to do, if anyone query fail, no changes should be occour in database, is this possible?
__________________
Amit Pathak
S/w Developer
Zero Systems Pvt Ltd..

Last edited by rohitamitpathak; 03-17-11 at 03:54. Reason: code not justifying my prob//
Reply With Quote
  #2 (permalink)  
Old 03-16-11, 09:26
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
look up START TRANSACTION in da manual

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-17-11, 03:56
rohitamitpathak rohitamitpathak is offline
Registered User
 
Join Date: Feb 2011
Location: india- new delhi
Posts: 31
now i got one solution of this, i need to use transaction here, for reading transaction go-> Transactions in MySQL — DatabaseJournal.com
so my query will look like-
mysql_query(conn,"begin;insert into t values(1);insert into t values(2);insert into t values('c');commit")

and where in the code u got one query fail there we can write

mysql_query(conn,"rollback");

mysql_query(conn,"commit");

now if any query failed all query updation will be rollback.............
__________________
Amit Pathak
S/w Developer
Zero Systems Pvt Ltd..
Reply With Quote
Reply

Tags
multistatement query, mysql_query()

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On