Skip to content

Commit

Permalink
Allow dumping SQL query when passing DQL on cli
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes committed Dec 24, 2014
1 parent 193e31f commit cdb62a7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ protected function configure()
new InputOption(
'depth', null, InputOption::VALUE_REQUIRED,
'Dumping depth of Entity graph.', 7
),
new InputOption(
'show-sql', null, InputOption::VALUE_NONE,
'Dump generated SQL instead of executing query'
)
))
->setHelp(<<<EOT
Expand Down Expand Up @@ -116,6 +120,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$query->setMaxResults((int) $maxResult);
}

if ($input->hasOption('show-sql')) {
Debug::dump($query->getSQL());
return;
}

$resultSet = $query->execute(array(), constant($hydrationMode));

Debug::dump($resultSet, $input->getOption('depth'));
Expand Down

4 comments on commit cdb62a7

@bobvandevijver
Copy link
Contributor

Choose a reason for hiding this comment

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

Great job, but you've broken the DQL command. The input always has the option show-sql, whether or not it is set or not, as it checks if the InputOption object exists in the InputDefinition. I will create an PR any minute.

@Ocramius
Copy link
Member

Choose a reason for hiding this comment

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

@bobvandevijver please be respectful of other contributor's work: nobody really meant to break it on purpose.

@bobvandevijver
Copy link
Contributor

Choose a reason for hiding this comment

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

I accidentally missed a word (but), so I've updated the comment. It was never meant to be disrespectful.

@Ocramius
Copy link
Member

Choose a reason for hiding this comment

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

@bobvandevijver thanks for clarifying. Wording is indeed much better now ;-)

Please sign in to comment.