1
|
#!/bin/bash -e
|
2
|
# links to locally-available resources
|
3
|
. "$(dirname "${BASH_SOURCE[0]}")"/util.run
|
4
|
|
5
|
if self_not_included; then
|
6
|
|
7
|
root_dir="$(dirname "${BASH_SOURCE[0]}")"/../..
|
8
|
bin_dir="$root_dir"/bin
|
9
|
|
10
|
export PATH="$bin_dir:$PATH"
|
11
|
|
12
|
log_sql () { test "$verbosity" -ge 2; }
|
13
|
|
14
|
mysql ()
|
15
|
{
|
16
|
echo_func "$@"
|
17
|
echo_run mysql_bien --database="$schema" --verbose "$@"
|
18
|
}
|
19
|
|
20
|
psql () # usage: ([file=...] [dir=...]; self)
|
21
|
{
|
22
|
echo_func "$@"
|
23
|
local dir="$dir"
|
24
|
if test -n "$file"; then
|
25
|
set -- --file "$file" "$@"
|
26
|
: "${dir:=$(dirname "$file")}"
|
27
|
fi
|
28
|
: "${dir:=$top_dir}"
|
29
|
|
30
|
local psql_cmd="psql_$(if log_sql; then echo verbose; else echo script; fi)_vegbien"
|
31
|
(cat <<EOF
|
32
|
\cd $dir
|
33
|
\set schema "$schema"
|
34
|
\set table "$table"
|
35
|
\set table_str '''"$table"'''
|
36
|
SET search_path TO "$schema", util;
|
37
|
EOF
|
38
|
cat)|
|
39
|
echo_run env no_search_path=1 "$psql_cmd" "$@"
|
40
|
}
|
41
|
|
42
|
fi
|