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-o mcr;
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"?????????
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/
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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-o mcr; Delete from omcr.AlarmNotification where alarmLifecycleId=50; COMMIT;"
[/code]
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/
[/code]
ASKER
the function() contains multiple SQL statements.