Skip to content

Commit

Permalink
fix namespace for Drush command sql-query with option "--db-prefix" i…
Browse files Browse the repository at this point in the history
…n use (#2882)
  • Loading branch information
deminy authored and weitzman committed Aug 21, 2017
1 parent 05ae7a7 commit 7759930
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Drush/Sql/SqlBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drush\Sql;

use Drupal\Core\Database\Database;

This comment has been minimized.

Copy link
@Hesse

Hesse May 15, 2018

Change this to use Drupal\Database;

and the above will work with D7.

use Drush\Log\LogLevel;
use Webmozart\PathUtil\Path;

Expand Down Expand Up @@ -201,7 +202,7 @@ public function query_prefix($query) {
// Enable prefix processing which can be dangerous so off by default. See http://drupal.org/node/1219850.
if (drush_get_option('db-prefix')) {
if (drush_drupal_major_version() >= 7) {
$query = \Database::getConnection()->prefixTables($query);
$query = Database::getConnection()->prefixTables($query);
}
else {
$query = db_prefix_tables($query);
Expand Down

1 comment on commit 7759930

@Hesse
Copy link

@Hesse Hesse commented on 7759930 May 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks sqlsan on D7.
When I run drush sqlsan I get the following error:
WD php: Error: Class 'Drupal\Core\Database\Database' not found in Drush\Sql\SqlBase->query_prefix() (line 205 of /var/www/html/sites/all/composer/vendor/drush/drush/lib/Drush/Sql/SqlBase.php). [0.28 sec, 13.44 MB] [error] Error: Class 'Drupal\Core\Database\Database' not found in Drush\Sql\SqlBase->query_prefix() (line 205 of /var/www/html/sites/all/composer/vendor/drush/drush/lib/Drush/Sql/SqlBase.php). Drush command terminated abnormally due to an unrecoverable error. [0.28 sec, 13.5 MB]
If you change the include to
use Drupal\Database;
It works in D7.

Please sign in to comment.