Revision 8775
Added by Aaron Marcuse-Kubitza over 11 years ago
lib/runscripts/table.run | ||
---|---|---|
18 | 18 |
|
19 | 19 |
if self_not_included; then |
20 | 20 |
|
21 |
quote='"' |
|
22 |
|
|
23 |
esc_name () { echo "$quote${1//$quote/$quote$quote}$quote"; } |
|
24 |
|
|
25 |
mk_esc_name () { set_var "$1"_esc "$(esc_name "${!1}")"; } |
|
26 |
|
|
27 | 21 |
: "${schema="$(cd "$top_dir"/..; basename "$PWD")"}" |
28 | 22 |
mk_esc_name schema |
29 | 23 |
: "${table="$( cd "$top_dir" ; basename "$PWD")"}" |
30 | 24 |
mk_esc_name table |
31 | 25 |
export schema table |
32 | 26 |
|
33 |
mysql () |
|
34 |
{ |
|
35 |
echo_func "$@" |
|
36 |
echo_run "$bin_dir"/mysql_bien --database="$schema" --verbose "$@" |
|
37 |
} |
|
38 |
|
|
39 |
mysql_ANSI () |
|
40 |
{ |
|
41 |
echo_func "$@" |
|
42 |
(echo "SET sql_mode = 'ANSI';"; cat)|mysql "$@" |
|
43 |
} |
|
44 |
|
|
45 |
psql () # usage: ([file=...] [dir=...]; self) |
|
46 |
{ |
|
47 |
echo_func "$@" |
|
48 |
local dir="$dir" |
|
49 |
if test -n "$file"; then |
|
50 |
set -- --file "$file" "$@" |
|
51 |
: "${dir:=$(dirname "$file")}" |
|
52 |
fi |
|
53 |
: "${dir:=$top_dir}" |
|
54 |
|
|
55 |
(cat <<EOF |
|
56 |
\cd $dir |
|
57 |
\set schema "$schema" |
|
58 |
\set table "$table" |
|
59 |
\set table_str '''"$table"''' |
|
60 |
SET search_path TO "$schema", util; |
|
61 |
EOF |
|
62 |
cat)| |
|
63 |
echo_run env no_search_path=1 "$bin_dir"/psql_verbose_vegbien "$@" |
|
64 |
} |
|
65 |
|
|
66 | 27 |
input_make () |
67 | 28 |
{ |
68 | 29 |
echo_func "$@" |
lib/util.sh | ||
---|---|---|
119 | 119 |
alias zip_newer="zip -u" |
120 | 120 |
alias unzip_newer="unzip -u -o" # -o is safe b/c -u only extracts newer files |
121 | 121 |
|
122 |
#### databases |
|
123 |
|
|
124 |
quote='"' |
|
125 |
|
|
126 |
esc_name () { echo "$quote${1//$quote/$quote$quote}$quote"; } |
|
127 |
|
|
128 |
mk_esc_name () { set_var "$1"_esc "$(esc_name "${!1}")"; } |
|
129 |
|
|
130 |
mysql () |
|
131 |
{ |
|
132 |
echo_func "$@" |
|
133 |
echo_run "$bin_dir"/mysql_bien --database="$schema" --verbose "$@" |
|
134 |
} |
|
135 |
|
|
136 |
mysql_ANSI () |
|
137 |
{ |
|
138 |
echo_func "$@" |
|
139 |
(echo "SET sql_mode = 'ANSI';"; cat)|mysql "$@" |
|
140 |
} |
|
141 |
|
|
142 |
psql () # usage: ([file=...] [dir=...]; self) |
|
143 |
{ |
|
144 |
echo_func "$@" |
|
145 |
local dir="$dir" |
|
146 |
if test -n "$file"; then |
|
147 |
set -- --file "$file" "$@" |
|
148 |
: "${dir:=$(dirname "$file")}" |
|
149 |
fi |
|
150 |
: "${dir:=$top_dir}" |
|
151 |
|
|
152 |
(cat <<EOF |
|
153 |
\cd $dir |
|
154 |
\set schema "$schema" |
|
155 |
\set table "$table" |
|
156 |
\set table_str '''"$table"''' |
|
157 |
SET search_path TO "$schema", util; |
|
158 |
EOF |
|
159 |
cat)| |
|
160 |
echo_run env no_search_path=1 "$bin_dir"/psql_verbose_vegbien "$@" |
|
161 |
} |
|
162 |
|
|
122 | 163 |
fi |
Also available in: Unified diff
lib/runscripts/table.run: moved general DB commands to lib/util.sh