X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrush%2Fdrush%2Fsrc%2FSql%2FSqlSqlsrv.php;fp=vendor%2Fdrush%2Fdrush%2Fsrc%2FSql%2FSqlSqlsrv.php;h=d8707c110edb8a08c48dfcea4d74f98ca43540a3;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/drush/drush/src/Sql/SqlSqlsrv.php b/vendor/drush/drush/src/Sql/SqlSqlsrv.php new file mode 100644 index 000000000..d8707c110 --- /dev/null +++ b/vendor/drush/drush/src/Sql/SqlSqlsrv.php @@ -0,0 +1,71 @@ +getDbSpec(); + $database = empty($dbSpec['database']) ? 'master' : $dbSpec['database']; + // Host and port are optional but have defaults. + $host = empty($dbSpec['host']) ? '.\SQLEXPRESS' : $dbSpec['host']; + if ($dbSpec['username'] == '') { + return ' -S ' . $host . ' -d ' . $database; + } else { + return ' -S ' . $host . ' -d ' . $database . ' -U ' . $dbSpec['username'] . ' -P ' . $dbSpec['password']; + } + } + + public function dbExists() + { + // TODO: untested, but the gist is here. + $dbSpec = $this->getDbSpec(); + $database = $dbSpec['database']; + // Get a new class instance that has no 'database'. + $db_spec_no_db = $dbSpec; + unset($db_spec_no_db['database']); + $sql_no_db = new SqlSqlsrv($db_spec_no_db, $this->getOptions()); + $query = "if db_id('$database') IS NOT NULL print 1"; + drush_always_exec($sql_no_db->connect() . ' -Q %s', $query); + $output = drush_shell_exec_output(); + return $output[0] == 1; + } + + public function listTables() + { + $return = $this->alwaysQuery('SELECT TABLE_NAME FROM information_schema.tables'); + $tables = drush_shell_exec_output(); + if (!empty($tables)) { + // Shift off the header of the column of data returned. + array_shift($tables); + return $tables; + } + } + + // @todo $file is no longer provided. We are supposed to return bash that can be piped to gzip. + // Probably sqlsrv needs to override dump() entirely. + public function dumpCmd($table_selection) + { + $dbSpec = $this->getDbSpec(); + if (!$file) { + $file = $dbSpec['database'] . '_' . date('Ymd_His') . '.bak'; + } + $exec = "sqlcmd -U \"" . $dbSpec['username'] . "\" -P \"" . $dbSpec['password'] . "\" -S \"" . $dbSpec['host'] . "\" -Q \"BACKUP DATABASE [" . $dbSpec['database'] . "] TO DISK='" . $file . "'\""; + if ($option = $this->getOption('extra-dump', $this->queryExtra)) { + $exec .= " $option"; + } + return [$exec, $file]; + } +}