forked from bviktor/redmine-digest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.sh
32 lines (27 loc) · 837 Bytes
/
query.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh
# Perform a db query
# dir locations
ROOT_DIR=`dirname $0`
# source the config file
. ${ROOT_DIR}/config.sh
# perform the relevant SQL query
case ${DB_TYPE} in
postgresql)
# unformatted rows without column names
PGPASSWORD=${DB_PASS} psql --host=${DB_HOST} --port=${DB_PORT} --dbname=${DB_NAME} --username=${DB_USER} --field-separator='|' --tuples-only --no-align --command "`cat $1`"
# unformatted rows with column names
#PGPASSWORD=${DB_PASS} psql --host=${DB_HOST} --port=${DB_PORT} --dbname=${DB_NAME} --username=${DB_USER} --command "COPY (`cat $1`) TO STDOUT CSV HEADER DELIMITER '|'"
;;
sqlite)
sqlite3 -separator '|' ${DB_FILE} "`cat $1`"
;;
mysql|mssql)
echo 'Unimplemented database type, sorry.'
exit 1
;;
*)
echo 'Invalid database type, check your config.sh.'
exit 1
;;
esac
exit 0