database 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright (C) 2008 1&1 Internet AG
  2. #
  3. # This file is part of kamailio, a free SIP server.
  4. #
  5. # kamailio is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version
  9. #
  10. # kamailio is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. MYSQL="mysql kamailio --show-warnings --batch --user=kamailio --password=kamailiorw -e"
  19. export PGPASSWORD="kamailiorw"
  20. PSQL="psql -A -t -n -q -h localhost -U kamailio kamailio -c"
  21. ISQL="isql -b -v -d0x0 kamailio kamailio kamailiorw"
  22. function check_mysql() {
  23. $MYSQL "select * from location;" > /dev/null
  24. if ! [ "$?" -eq 0 ] ; then
  25. echo "can't read from database"
  26. return 1
  27. fi;
  28. $MYSQL "insert into location (user_agent) values ('___test___');" > /dev/null
  29. if ! [ "$?" -eq 0 ] ; then
  30. echo "can't write to database"
  31. return 1
  32. fi;
  33. $MYSQL "delete from location where user_agent ='___test___';" > /dev/null
  34. return 0
  35. }
  36. function check_postgres() {
  37. $PSQL "select * from location;" > /dev/null
  38. if ! [ "$?" -eq 0 ] ; then
  39. echo "can't read from database"
  40. return 1
  41. fi;
  42. $PSQL "insert into location (user_agent) values ('___test___');" > /dev/null
  43. if ! [ "$?" -eq 0 ] ; then
  44. echo "can't write to database"
  45. return 1
  46. fi;
  47. $PSQL "delete from location where user_agent ='___test___';" > /dev/null
  48. return 0
  49. }
  50. function check_unixodbc() {
  51. echo "select * from location;" | $ISQL > /dev/null
  52. if ! [ "$?" -eq 0 ] ; then
  53. echo "can't read from database"
  54. return 1
  55. fi;
  56. echo "insert into location (id, user_agent) values ('$RANDOM', '___test___');" | $ISQL > /dev/null
  57. if ! [ "$?" -eq 0 ] ; then
  58. echo "can't write to database"
  59. return 1
  60. fi;
  61. echo "delete from location where user_agent ='___test___';" | $ISQL > /dev/null
  62. return 0
  63. }