kamctl.pgsql 1.7 KB

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