瀏覽代碼

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

Andrei Pelinescu-Onciul 18 年之前
父節點
當前提交
17afb55bcf
共有 1 個文件被更改,包括 19 次插入7 次删除
  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