Explorar o código

- fix: allow empty mysql password and better handle the DB=""case inside
sql_query

Andrei Pelinescu-Onciul %!s(int64=18) %!d(string=hai) anos
pai
achega
17afb55bcf
Modificáronse 1 ficheiros con 19 adicións e 7 borrados
  1. 19 7
      scripts/mysql/ser_mysql.sh

+ 19 - 7
scripts/mysql/ser_mysql.sh

@@ -201,13 +201,25 @@ prompt_pw()
 #
 sql_query()
 {
-    if [ $# -gt 1 ] ; then
-	DB=$1
-	shift
-	$CMD "$PW" $MYSQL_OPTS "$DB" -e "$@"
-    else
-	$CMD "$PW" $MYSQL_OPTS "$@"
-    fi
+	if [ $# -gt 1 ] ; then
+		if [ -n "$1" ]; then
+			DB=\"$1\"
+		else
+			DB=""
+		fi
+		shift
+		if [ -n "$PW" ]; then
+			$CMD "$PW" $MYSQL_OPTS $DB -e "$@"
+		else
+			$CMD $MYSQL_OPTS $DB -e "$@"
+		fi
+	else
+		if [ -n "$PW" ]; then
+			$CMD "$PW" $MYSQL_OPTS "$@"
+		else
+			$CMD $MYSQL_OPTS "$@"
+		fi
+	fi
 }
 
 # Drop SER database