From 5a45e62c3fb7057e5bd14fcb4c144f0aba868be6 Mon Sep 17 00:00:00 2001 From: antonioribeiro Date: Tue, 15 Jan 2013 12:41:42 -0200 Subject: [PATCH 1/2] Update src/Illuminate/Database/Connection.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some DMBS DDL statements needs to be run unprepared, as shown in this issue: https://github.com/laravel/framework/issues/53. --- src/Illuminate/Database/Connection.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Connection.php b/src/Illuminate/Database/Connection.php index 2f36d913a4c9..0c1af58cff93 100644 --- a/src/Illuminate/Database/Connection.php +++ b/src/Illuminate/Database/Connection.php @@ -299,6 +299,24 @@ public function statement($query, $bindings = array()) }); } + /** + * Execute an unprepared SQL statement and return the boolean result. + * + * @param string $query + * @return bool + */ + public function execute($query) + { + return $this->run($query, array(), function($me, $query, $bindings) + { + // Since this is an unprepared statement, $bindings was kept in closure list + // of parameters just for compatibility with run()'s callback call. + if ($me->pretending()) return true; + + return $me->getPdo()->exec($query); + }); + } + /** * Run an SQL statement and get the number of rows affected. * @@ -664,4 +682,4 @@ public function withTablePrefix(Grammar $grammar) return $grammar; } -} \ No newline at end of file +} From 9e7bb71d46fa4148dfbfd5f99fc4f363ed3b2e8b Mon Sep 17 00:00:00 2001 From: antonioribeiro Date: Tue, 15 Jan 2013 15:16:07 -0200 Subject: [PATCH 2/2] Update tests/Database/DatabaseConnectionTest.php Creating test for proposed execute() method. --- tests/Database/DatabaseConnectionTest.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/Database/DatabaseConnectionTest.php b/tests/Database/DatabaseConnectionTest.php index 64f93e2b7ba4..9a53067eedca 100644 --- a/tests/Database/DatabaseConnectionTest.php +++ b/tests/Database/DatabaseConnectionTest.php @@ -203,6 +203,15 @@ public function testSchemaBuilderCanBeCreated() } + public function testExecuteMethod() + { + $connection = $this->getMockConnection(array('execute')); + $connection->expects($this->once())->method('execute')->with($this->equalTo('foo'))->will($this->returnValue(true)); + $results = $connection->execute('foo'); + $this->assertTrue($results); + } + + protected function getMockConnection($methods = array(), $pdo = null) { $pdo = $pdo ?: new DatabaseConnectionTestMockPDO; @@ -212,4 +221,4 @@ protected function getMockConnection($methods = array(), $pdo = null) } -class DatabaseConnectionTestMockPDO extends PDO { public function __construct() {} } \ No newline at end of file +class DatabaseConnectionTestMockPDO extends PDO { public function __construct() {} }