Link to home
Start Free TrialLog in
Avatar of pvinodp
pvinodp

asked on

sql transaction in bash linux

Hi,
I have a function in shell script which executes sql statements.
I want to use transactions for it.

function()
{
Begin transaction # i want SQL equivalent of this in shell scripting

source /etc/ipaccess/omcr-server/ipaccess-omcr;
mysql -u${MYSQL_ROOT_USER} -p${MYSQL_ROOT_PASSWORD} -e "Delete from omcr.AlarmNotification where alarmLifecycleId=50;"
 
commit transaction # i want SQL equivalent of this in shell scripting
}

How to execute the lines for "Begin transaction" and "commit"?????????
SOLUTION
Avatar of RealRaven
RealRaven
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pvinodp
pvinodp

ASKER

hi raven
the function() contains multiple SQL statements.
SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As woolmilkporc points out a script file is always possible but it doesn't look like a good solution in this case.

You would have to write to a temporary file, send that to mysql and then delete it. It's possible but not pretty.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pvinodp

ASKER

Thanks all.
Finally i did put in the solution by mwiercin :

$ mysql -u${MYSQL_ROOT_USER} -p${MYSQL_ROOT_PASSWORD} -e "BEGIN; SOURCE /etc/ipaccess/omcr-server/ipaccess-omcr; Delete from omcr.AlarmNotification where alarmLifecycleId=50; COMMIT;"
[/code]