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 +} 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() {} }