tools/kamctl.pgsql
7872a0d8
 #
 # $Id$
 #
860c33c5
 # control tool for maintaining Kamailio
7872a0d8
 #
 #===================================================================
 
 ##### ----------------------------------------------- #####
 ### PGSQL specific variables and functions
 #
 
 ##### ----------------------------------------------- #####
 ### load SQL base
 #
de1a4247
 if [ -f "$MYLIBDIR/kamctl.sqlbase" ]; then
 	. "$MYLIBDIR/kamctl.sqlbase"
7872a0d8
 else
de1a4247
 	echo "Cannot load SQL core functions '$MYLIBDIR/kamctl.sqlbase' - exiting ..."
7872a0d8
 	exit -1
 fi
 
 ##### ----------------------------------------------- #####
 ### binaries
 if [ -z "$PGSQL" ] ; then
a74ffe9b
 	locate_tool psql
 	if [ -z "$TOOLPATH" ] ; then
 		echo "error: 'psql' tool not found: set PGSQL variable to correct tool path"
 		exit
 	fi
54c04785
 	PGSQL="$TOOLPATH"
7872a0d8
 fi
 
 
 # input: sql query, optional pgsql command-line params
 pgsql_query() {
 	# if password not yet queried, query it now
5f72f337
 	prompt_pw "PgSQL password for user '$DBRWUSER@$DBHOST'"
7872a0d8
 	mecho "pgsql_query: $PGSQL $2 -A -q -t -P fieldsep='	' -h $DBHOST -U $DBRWUSER $DBNAME -c '$1'"
 	PGPASSWORD="$DBRWPW" $PGSQL $2 \
 		-A -q -t \
 		-P fieldsep="	" \
 		-h $DBHOST \
 		-U $DBRWUSER \
 		$DBNAME \
 		-c "$1"
 }
 
 # input: sql query, optional pgsql command-line params
 pgsql_ro_query() {
 	mdbg "pgsql_ro_query: $PGSQL $2 -h $DBHOST -U $DBROUSER $DBNAME -c '$1'"
 	PGPASSWORD="$DBROPW" $PGSQL $2 \
 		-h $DBHOST \
 		-U $DBROUSER \
 		$DBNAME \
 		-c "$1"
 }
 
 DBCMD=pgsql_query
 DBROCMD=pgsql_ro_query
 DBRAWPARAMS="-A -q -t"