Skip to content

Commit 193594c

Browse files
committed
Implementing Connection::query() and added test
1 parent 83a878f commit 193594c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/Cake/Model/Datasource/Database/Connection.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function execute($query, array $params = array(), array $types = array())
118118
$this->_bindValues($statement, $params, $types);
119119
$result = $statement->execute();
120120
} else {
121-
$result = $this->query($query);
121+
$statement = $this->query($query);
122122
}
123123
return $statement;
124124
}
@@ -129,7 +129,10 @@ public function execute($query, array $params = array(), array $types = array())
129129
* @return Cake\Model\Datasource\Database\Statement
130130
**/
131131
public function query($sql) {
132-
132+
$this->connect();
133+
$statement = $this->prepare($sql);
134+
$statement->execute();
135+
return $statement;
133136
}
134137

135138
/**

lib/Cake/Test/TestCase/Model/Datasource/Database/ConnectionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,17 @@ public function testExecuteWithMissingType() {
153153
$statement = $this->connection->execute($sql, array(new \DateTime('2012-01-01')), array('bar'));
154154
}
155155

156+
/**
157+
* Tests executing a qury with no params also works
158+
*
159+
* @return void
160+
**/
161+
public function testExecuteWithNoParams() {
162+
$sql = 'SELECT 1';
163+
$statement = $this->connection->execute($sql);
164+
$result = $statement->fetch();
165+
$this->assertCount(1, $result);
166+
$this->assertEquals(array(1), $result);
167+
}
156168

157169
}

0 commit comments

Comments
 (0)