From 6b4fadb6718966e45241758433752b321dcb5047 Mon Sep 17 00:00:00 2001
From: Greg Anderson <greg.1.anderson@greenknowe.org>
Date: Wed, 3 Apr 2013 16:17:07 -0700
Subject: Issue #1957020 by Greg Anderson, JSCSJSCS, greg.1.anderson: drush
 sql-sync with --create-db does not work and can overwrite MySQL
 default databases

---
 commands/sql/sync.sql.inc |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/commands/sql/sync.sql.inc b/commands/sql/sync.sql.inc
index 56bcc25..7dcfbea 100644
--- a/commands/sql/sync.sql.inc
+++ b/commands/sql/sync.sql.inc
@@ -395,6 +395,17 @@ function drush_sql_sync($source = NULL, $destination = NULL) {
         $db_su_connect = _drush_sql_connect($create_db_su);
         $pre_import_sql = drush_sql_build_createdb_sql($target_db_url);
         $pre_import_commands = sprintf('echo "%s" | %s; ', $pre_import_sql, $db_su_connect);
+        // Linux requires quotes around echo statements. Windows generally supports
+        // quotes for echo statements, but will complain if they are present
+        // when piping echo statements as input to other commands. Also,
+        // Windows multi-commands normally work when separated by '&&', '&', or ';'
+        // but will not function with ';' in this case.(http://drupal.org/node/1957020)
+        if (drush_is_windows($target_os)) {
+          $pre_import_commands = sprintf('echo %s | %s && ', $pre_import_sql, $db_su_connect);
+        }
+        else {
+          $pre_import_commands = sprintf('echo "%s" | %s; ', $pre_import_sql, $db_su_connect);
+        }
       }

       // Generate the import command
--
1.7.9.5

