60cbd92f06b0c3db186b76b0d45811b6a49cc7ba
[sip-router] / utils / kamctl / kamctl.pgsql
1 #
2 #
3 # control tool for maintaining Kamailio
4 #
5 #===================================================================
6
7 ##### ----------------------------------------------- #####
8 ### PGSQL specific variables and functions
9 #
10
11 ##### ----------------------------------------------- #####
12 ### load SQL base
13 #
14 if [ -f "$MYLIBDIR/kamctl.sqlbase" ]; then
15         . "$MYLIBDIR/kamctl.sqlbase"
16 else
17         echo "Cannot load SQL core functions '$MYLIBDIR/kamctl.sqlbase' - exiting ..."
18         exit -1
19 fi
20
21 ##### ----------------------------------------------- #####
22 ### binaries
23 if [ -z "$PGSQL" ] ; then
24         locate_tool psql
25         if [ -z "$TOOLPATH" ] ; then
26                 echo "error: 'psql' tool not found: set PGSQL variable to correct tool path"
27                 exit
28         fi
29         PGSQL="$TOOLPATH"
30 fi
31
32
33 # input: sql query, optional pgsql command-line params
34 pgsql_query() {
35         # if password not yet queried, query it now
36         prompt_pw "PgSQL password for user '$DBRWUSER@$DBHOST'"
37         mecho "pgsql_query: $PGSQL $2 -A -q -t -P fieldsep='    ' -h $DBHOST -U $DBRWUSER $DBNAME -c '$1'"
38         PGPASSWORD="$DBRWPW" $PGSQL $2 \
39                 -A -q -t \
40                 -P fieldsep="   " \
41                 -h $DBHOST \
42                 -U $DBRWUSER \
43                 $DBNAME \
44                 -c "$1"
45 }
46
47 # input: sql query, optional pgsql command-line params
48 pgsql_ro_query() {
49         mdbg "pgsql_ro_query: $PGSQL $2 -h $DBHOST -U $DBROUSER $DBNAME -c '$1'"
50         PGPASSWORD="$DBROPW" $PGSQL $2 \
51                 -h $DBHOST \
52                 -U $DBROUSER \
53                 $DBNAME \
54                 -c "$1"
55 }
56
57 DBCMD=pgsql_query
58 DBROCMD=pgsql_ro_query
59 DBRAWPARAMS="-A -q -t"
60