Revision 8796
Added by Aaron Marcuse-Kubitza over 11 years ago
lib/runscripts/local.run | ||
---|---|---|
9 | 9 |
|
10 | 10 |
export PATH="$bin_dir:$PATH" |
11 | 11 |
|
12 |
log_sql () { test "$verbosity" -ge 2; } |
|
13 |
|
|
14 |
alias mk_schema_esc="local schema_esc; mk_esc_name schema" |
|
15 |
alias mk_table_esc="local table_esc; mk_esc_name table" |
|
16 |
|
|
17 |
fi # load new aliases |
|
18 |
if self_being_included; then |
|
19 |
|
|
20 | 12 |
mysql () |
21 | 13 |
{ |
22 | 14 |
echo_func "$@" |
... | ... | |
45 | 37 |
echo_run env no_search_path=1 "$psql_cmd" --output /dev/fd/3 "$@" 3>&1 >&2 |
46 | 38 |
} |
47 | 39 |
|
48 |
pg_copy_to () |
|
49 |
{ |
|
50 |
echo_func "$@" |
|
51 |
: "${table:?}"; mk_table_esc |
|
52 |
: "${pg_copy_format=CSV HEADER}" |
|
53 |
psql <<<"COPY $table_esc TO STDOUT $pg_copy_format;" |
|
54 |
} |
|
55 |
|
|
56 |
pg_header () |
|
57 |
{ |
|
58 |
echo_func "$@" |
|
59 |
local pg_copy_format="CSV HEADER" |
|
60 |
pg_copy_to|echo_stdin |
|
61 |
} |
|
62 |
|
|
63 |
pg_export_table_no_header () |
|
64 |
{ |
|
65 |
echo_func "$@" |
|
66 |
local pg_copy_format="CSV" |
|
67 |
pg_copy_to |
|
68 |
} |
|
69 |
|
|
70 |
pg_export_table_to_dir_no_header () |
|
71 |
{ |
|
72 |
echo_func "$@" |
|
73 |
local table="$1"; shift; mk_table_esc |
|
74 |
local cols="$(pg_header "$table")" |
|
75 |
pg_export_table_no_header "$@" >"$exports_dir/$table.no_header.cols=$cols.csv" |
|
76 |
} |
|
77 |
|
|
78 | 40 |
fi |
lib/util.sh | ||
---|---|---|
135 | 135 |
|
136 | 136 |
mk_esc_name () { set_var "$1"_esc "$(esc_name "${!1}")"; } |
137 | 137 |
|
138 |
alias mk_schema_esc="local schema_esc; mk_esc_name schema" |
|
139 |
alias mk_table_esc="local table_esc; mk_esc_name table" |
|
140 |
|
|
141 |
fi # load new aliases |
|
142 |
if self_being_included; then |
|
143 |
|
|
144 |
log_sql () { test "$verbosity" -ge 2; } |
|
145 |
|
|
146 |
### MySQL |
|
147 |
|
|
138 | 148 |
mysql () |
139 | 149 |
{ |
140 | 150 |
echo_func "$@" |
... | ... | |
147 | 157 |
(echo "SET sql_mode = 'ANSI';"; cat)|mysql "$@" |
148 | 158 |
} |
149 | 159 |
|
160 |
### PostgreSQL |
|
161 |
|
|
162 |
pg_copy_to () |
|
163 |
{ |
|
164 |
echo_func "$@" |
|
165 |
: "${table:?}"; mk_table_esc |
|
166 |
: "${pg_copy_format=CSV HEADER}" |
|
167 |
psql <<<"COPY $table_esc TO STDOUT $pg_copy_format;" |
|
168 |
} |
|
169 |
|
|
170 |
pg_header () |
|
171 |
{ |
|
172 |
echo_func "$@" |
|
173 |
local pg_copy_format="CSV HEADER" |
|
174 |
pg_copy_to|echo_stdin |
|
175 |
} |
|
176 |
|
|
177 |
pg_export_table_no_header () |
|
178 |
{ |
|
179 |
echo_func "$@" |
|
180 |
local pg_copy_format="CSV" |
|
181 |
pg_copy_to |
|
182 |
} |
|
183 |
|
|
184 |
pg_export_table_to_dir_no_header () |
|
185 |
{ |
|
186 |
echo_func "$@" |
|
187 |
local table="$1"; shift; mk_table_esc |
|
188 |
local cols="$(pg_header "$table")" |
|
189 |
pg_export_table_no_header "$@" >"$exports_dir/$table.no_header.cols=$cols.csv" |
|
190 |
} |
|
191 |
|
|
150 | 192 |
fi |
Also available in: Unified diff
lib/runscripts/local.run: moved log_sql (), pg_* () to lib/util.sh because these do not depend on local external scripts in bin/