#
# $Id$
#
# control tool for maintaining Kamailio
#
#===================================================================

##### ----------------------------------------------- #####
### MySQL specific variables and functions
#

##### ----------------------------------------------- #####
### load SQL base
#
if [ -f "$MYLIBDIR/kamctl.sqlbase" ]; then
	. "$MYLIBDIR/kamctl.sqlbase"
else
	echo "Cannot load SQL core functions '$MYLIBDIR/kamctl.sqlbase' - exiting ..."
	exit -1
fi

##### ----------------------------------------------- #####
### binaries
if [ -z "$MYSQL" ] ; then
	locate_tool mysql
	if [ -z "$TOOLPATH" ] ; then
		echo "error: 'mysql' tool not found: set MYSQL variable to correct tool path"
		exit
	fi
	MYSQL="$TOOLPATH"
fi

# input: sql query, optional mysql command-line params
mysql_query() {
	# if password not yet queried, query it now
	prompt_pw "MySQL password for user '$DBRWUSER@$DBHOST'"
	$MYSQL $2 -h $DBHOST -u $DBRWUSER "-p$DBRWPW" -e "$1 ;" $DBNAME
}

# input: sql query, optional mysql command-line params
mysql_ro_query() {
	$MYSQL $2 -h $DBHOST -u $DBROUSER "-p$DBROPW" -e "$1 ;" $DBNAME
}

DBCMD=mysql_query
DBROCMD=mysql_ro_query
DBRAWPARAMS="-B"