Are you tired of typing dbaccess and selecting it's "ring menu" options for executing simple SQL statements? If your answer is yes, you may copy and paste the following unix script into a file and fire a SQL in a different manner. For example you may paste this script to a file called D. Issue chmod 755 D to Change the attribute of this file and make it executable. Please change the database name to the active database in your server. Once you have done this you can invoke the script in the following manner from the Unix/Linux command line.
D "info tables" | pg
D "select * from employee" | pg
D "update employee set emp_sal=emp_sal+250 where emp_id=101"
D "info status for employee"
and so on ...
Features:
1. Data Manipulation Statements are marked for transaction.
2. Prompts for Commit/Rollback of transaction.
3. All the manipulation statements are dumped in a specific log file.
4. Warns for missing where clause for update and delete statements.
# Informix dbaccess usage enhancer.
# V.P. Shriyan
#
util=$INFORMIXDIR/bin/dbaccess
database="TestDB"
log="/tmp/dbaccess.log"
echo " "
$INFORMIXDIR/bin/onstat -V # Show the Database Server Version
echo " "
/usr/bin/uname -a # Show the OS version
echo " "
echo "$*" # Show the User Request String
echo " "
echo "$*" | egrep -i -q "insert|update|delete" # DML Statements
if [ $? -eq 0 ]
then
echo "$*" | egrep -i -q "insert"
if [ $? -ne 0 ]
then
echo "$*" | egrep -i -q "where"
if [ $? -ne 0 ]
then
echo "You have not specified the WHERE clause ! Please be careful."
exit 1
fi
fi
echo "$*" | egrep -i -q "begin"
if [ $? -eq 0 ]
then
echo "$*" | egrep -i -q "rollback|commit"
if [ $? -eq 0 ]
then
echo "$*" | egrep -i -q "commit"
if [ $? -eq 0 ]
then
echo "Sure You want to commit ? \c"
read ans
case $ans in
y|Y) echo "$*" | $util $database
echo "`date` :$LOGNAME: $*" >> $log
;;
*) echo "Job Aborted ..."
;;
esac
else
echo "$*" | $util $database
fi
else
echo "$* ; rollback " | $util $database
fi
else
echo "(C)ommit / (R)ollback : \c"
read ans
case $ans in
c|C) echo "begin ; $* ; commit" | $util $database
echo "`date` :$LOGNAME: $*" >> $log
;;
*) echo "begin ; $* ; rollback" | $util $database
;;
esac
fi
else
echo "$*" | $util $database
fi
D "info tables" | pg
D "select * from employee" | pg
D "update employee set emp_sal=emp_sal+250 where emp_id=101"
D "info status for employee"
and so on ...
Features:
1. Data Manipulation Statements are marked for transaction.
2. Prompts for Commit/Rollback of transaction.
3. All the manipulation statements are dumped in a specific log file.
4. Warns for missing where clause for update and delete statements.
# Informix dbaccess usage enhancer.
# V.P. Shriyan
#
util=$INFORMIXDIR/bin/dbaccess
database="TestDB"
log="/tmp/dbaccess.log"
echo " "
$INFORMIXDIR/bin/onstat -V # Show the Database Server Version
echo " "
/usr/bin/uname -a # Show the OS version
echo " "
echo "$*" # Show the User Request String
echo " "
echo "$*" | egrep -i -q "insert|update|delete" # DML Statements
if [ $? -eq 0 ]
then
echo "$*" | egrep -i -q "insert"
if [ $? -ne 0 ]
then
echo "$*" | egrep -i -q "where"
if [ $? -ne 0 ]
then
echo "You have not specified the WHERE clause ! Please be careful."
exit 1
fi
fi
echo "$*" | egrep -i -q "begin"
if [ $? -eq 0 ]
then
echo "$*" | egrep -i -q "rollback|commit"
if [ $? -eq 0 ]
then
echo "$*" | egrep -i -q "commit"
if [ $? -eq 0 ]
then
echo "Sure You want to commit ? \c"
read ans
case $ans in
y|Y) echo "$*" | $util $database
echo "`date` :$LOGNAME: $*" >> $log
;;
*) echo "Job Aborted ..."
;;
esac
else
echo "$*" | $util $database
fi
else
echo "$* ; rollback " | $util $database
fi
else
echo "(C)ommit / (R)ollback : \c"
read ans
case $ans in
c|C) echo "begin ; $* ; commit" | $util $database
echo "`date` :$LOGNAME: $*" >> $log
;;
*) echo "begin ; $* ; rollback" | $util $database
;;
esac
fi
else
echo "$*" | $util $database
fi