Hi,
I'm trying to develop a script file that can manipulate a mysql database. I can query the db no problem... That is until I try to create a function that will do the work for me. I've tested several scenarios to try to get around it. But I can't seem to find anything that will work when passing queries via a function. The basic code included below has testing provisions that can be uncommented.
Also, when running this with ksh -x. The input to mysql is identical whether or not the function is being used. The read statement fails when run withing a function.
Any Ideas???
Thanks
#! /bin/ksh
#
mysql -u root -D ftp_files -ss -n -q |&
################################################################################
# Fucntions
################################################################################
# Query db: Perform a database query.
################################################################################
query_db(){
print -p -- "$query"
read -p "$get_row_count1"
}
################################################################################
# End Fucntions
################################################################################
################################################################################
# Testing w/wo variable and no function. WORKS
################################################################################
# Use these two...
################################################################################
#query="$2"
#print -p -- "$query"
################################################################################
# or this one with the read and echo below.
################################################################################
#print -p -- "select * from usr where id='1';"
################################################################################
#echo "Testing w/wo variable and no function."
#read -p get_row_count1
#echo $get_row_count1
#exit
################################################################################
# Main DOESN'T WORK
################################################################################
if [ ! "$#" -eq "2" ]
then
echo "Usage: $0 \"query string\""
exit
fi
query="$2"
$1 "$query"
echo "$get_row_count1"
exit
################################################################################
# END
################################################################################