7fda5e7f44c7a140729f4ca67df93761bffff4d5
[sip-router] / utils / kamctl / kamctl.mysql
1 #
2 #
3 # control tool for maintaining Kamailio
4 #
5 #===================================================================
6
7 ##### ----------------------------------------------- #####
8 ### MySQL 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 "$MYSQL" ] ; then
24         locate_tool mysql
25         if [ -z "$TOOLPATH" ] ; then
26                 echo "error: 'mysql' tool not found: set MYSQL variable to correct tool path"
27                 exit
28         fi
29         MYSQL="$TOOLPATH"
30 fi
31
32 # input: sql query, optional mysql command-line params
33 mysql_query() {
34         # if password not yet queried, query it now
35         prompt_pw "MySQL password for user '$DBRWUSER@$DBHOST'"
36         $MYSQL $2 -h $DBHOST -u $DBRWUSER "-p$DBRWPW" -e "$1 ;" $DBNAME
37 }
38
39 # input: sql query, optional mysql command-line params
40 mysql_ro_query() {
41         $MYSQL $2 -h $DBHOST -u $DBROUSER "-p$DBROPW" -e "$1 ;" $DBNAME
42 }
43
44 mysql_connect() {
45         # if password not yet queried, query it now
46         prompt_pw "MySQL password for user '$DBRWUSER@$DBHOST'"
47         $MYSQL $2 -h $DBHOST -u $DBRWUSER "-p$DBRWPW" $DBNAME
48 }
49
50 DBCMD=mysql_query
51 DBROCMD=mysql_ro_query
52 DBRAWPARAMS="-B"
53 DBCMDCONNECT=mysql_connect
54