You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kamailio/test/unit/include/database

70 lines
2.2 KiB

# Copyright (C) 2008 1&1 Internet AG
#
# This file is part of kamailio, a free SIP server.
#
# kamailio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version
#
# kamailio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
MYSQL="mysql openser --show-warnings --batch --user=openser --password=openserrw -e"
export PGPASSWORD="openserrw"
PSQL="psql -A -t -n -q -h localhost -U openser openser -c"
ISQL="isql -b -v -d0x0 openser openser openserrw"
function check_mysql() {
$MYSQL "select * from location;" > /dev/null
if ! [ "$?" -eq 0 ] ; then
echo "can't read from database"
return -1
fi;
$MYSQL "insert into location (user_agent) values ('___test___');" > /dev/null
if ! [ "$?" -eq 0 ] ; then
echo "can't write to database"
return -1
fi;
$MYSQL "delete from location where user_agent ='___test___';" > /dev/null
return 0
}
function check_postgres() {
$PSQL "select * from location;" > /dev/null
if ! [ "$?" -eq 0 ] ; then
echo "can't read from database"
return -1
fi;
$PSQL "insert into location (user_agent) values ('___test___');" > /dev/null
if ! [ "$?" -eq 0 ] ; then
echo "can't write to database"
return -1
fi;
$PSQL "delete from location where user_agent ='___test___';" > /dev/null
return 0
}
function check_unixodbc() {
echo "select * from location;" | $ISQL > /dev/null
if ! [ "$?" -eq 0 ] ; then
echo "can't read from database"
return -1
fi;
echo "insert into location (id, user_agent) values ('$RANDOM', '___test___');" | $ISQL > /dev/null
if ! [ "$?" -eq 0 ] ; then
echo "can't write to database"
return -1
fi;
echo "delete from location where user_agent ='___test___';" | $ISQL > /dev/null
return 0
}