Commit b346106c authored by Martin Prebio's avatar Martin Prebio

RunSqlCommand: Adding --fetch-result option

parent 4a9119b8
......@@ -48,7 +48,8 @@ class RunSqlCommand extends Command
->setDescription('Executes arbitrary SQL directly from the command line.')
->setDefinition(array(
new InputArgument('sql', InputArgument::REQUIRED, 'The SQL statement to execute.'),
new InputOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of result set.', 7)
new InputOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of result set.', 7),
new InputOption('fetch-result', null, InputOption::VALUE_NONE, 'Forces fetching the result.'),
))
->setHelp(<<<EOT
Executes arbitrary SQL directly from the command line.
......@@ -73,7 +74,7 @@ EOT
throw new \LogicException("Option 'depth' must contains an integer value");
}
if (stripos($sql, 'select') === 0) {
if (stripos($sql, 'select') === 0 || $input->getOption('fetch-result')) {
$resultSet = $conn->fetchAll($sql);
} else {
$resultSet = $conn->executeUpdate($sql);
......
......@@ -106,4 +106,18 @@ class RunSqlCommandTest extends \PHPUnit_Framework_TestCase
->expects($this->exactly(1))
->method('fetchAll');
}
public function testStatementsWithFetchResultPrintsResult()
{
$this->expectConnectionFetchAll();
$this->commandTester->execute(array(
'command' => $this->command->getName(),
'sql' => '"WITH bar as (SELECT 1) SELECT * FROM bar',
'--fetch-result' => true,
));
$this->assertRegExp('@int.*1.*@', $this->commandTester->getDisplay());
$this->assertRegExp('@array.*1.*@', $this->commandTester->getDisplay());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment