Skip to content

Commit b587476

Browse files
author
Serghey Rodin
committed
RACK911LABS.COM: safer mysql/pgsql query
1 parent 4c751ab commit b587476

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

func/db.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ mysql_connect() {
4747
}
4848

4949
mysql_query() {
50-
mysql --defaults-file=$mycnf -e "$1" 2>/dev/null
50+
sql_tmp=$(mktemp)
51+
echo "$1" > $sql_tmp
52+
mysql --defaults-file=$mycnf < "$sql_tmp" 2>/dev/null
53+
rm -f "$sql_tmp"
5154
}
5255

5356
mysql_dump() {
@@ -89,7 +92,10 @@ psql_connect() {
8992
}
9093

9194
psql_query() {
92-
psql -h $HOST -U $USER -c "$1" 2>/dev/null
95+
sql_tmp=$(mktemp)
96+
echo "$1" > $sql_tmp
97+
psql -h $HOST -U $USER -f "$sql_tmp" 2>/dev/null
98+
rm -f $sql_tmp
9399
}
94100

95101
psql_dump() {

0 commit comments

Comments
 (0)