Skip to content

Commit

Permalink
rename fetchStatement() to perform()
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed Feb 20, 2014
1 parent 209963f commit 1e3f74e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
30 changes: 15 additions & 15 deletions src/ExtendedPdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ public function prepare($statement, $options = array())
* Connects to the database and prepares an SQL statement to be executed,
* using values that been bound for the next query.
*
* This override only binds values that have named placeholders in the
* This method only binds values that have named placeholders in the
* statement, thereby avoiding errors from PDO regarding too many bound
* values; it also binds all sequential (question-mark) placeholders.
* values. It also binds all sequential (question-mark) placeholders.
*
* If a placeholder value is an array, the array is converted to a string
* of comma-separated quoted values; e.g., for an `IN (...)` condition.
Expand All @@ -377,7 +377,7 @@ public function prepare($statement, $options = array())
* @see http://php.net/manual/en/pdo.prepare.php
*
*/
protected function prepareFetch($statement)
protected function performPrepare($statement)
{
// are there any bind values?
if (! $this->bind_values) {
Expand Down Expand Up @@ -626,7 +626,7 @@ public function lastInsertId($name = null)
*/
public function fetchAll($statement, array $values = array(), $callable = null)
{
$sth = $this->fetchStatement($statement, $values);
$sth = $this->perform($statement, $values);
$data = $sth->fetchAll(self::FETCH_ASSOC);
if ($callable) {
foreach ($data as $key => $row) {
Expand Down Expand Up @@ -657,7 +657,7 @@ public function fetchAll($statement, array $values = array(), $callable = null)
*/
public function fetchAssoc($statement, array $values = array(), $callable = null)
{
$sth = $this->fetchStatement($statement, $values);
$sth = $this->perform($statement, $values);
$data = array();
if ($callable) {
while ($row = $sth->fetch(self::FETCH_ASSOC)) {
Expand Down Expand Up @@ -689,7 +689,7 @@ public function fetchAssoc($statement, array $values = array(), $callable = null
*/
public function fetchCol($statement, array $values = array(), $callable = null)
{
$sth = $this->fetchStatement($statement, $values);
$sth = $this->perform($statement, $values);
$data = $sth->fetchAll(self::FETCH_COLUMN, 0);
if ($callable) {
foreach ($data as $key => $val) {
Expand Down Expand Up @@ -727,7 +727,7 @@ public function fetchObject(
$class_name = 'StdClass',
array $ctor_args = array()
) {
$sth = $this->fetchStatement($statement, $values);
$sth = $this->perform($statement, $values);
return $sth->fetchObject($class_name, $ctor_args);
}

Expand Down Expand Up @@ -761,7 +761,7 @@ public function fetchObjects(
$class_name = 'StdClass',
array $ctor_args = array()
) {
$sth = $this->fetchStatement($statement, $values);
$sth = $this->perform($statement, $values);
return $sth->fetchAll(self::FETCH_CLASS, $class_name, $ctor_args);
}

Expand All @@ -778,7 +778,7 @@ public function fetchObjects(
*/
public function fetchOne($statement, array $values = array())
{
$sth = $this->fetchStatement($statement, $values);
$sth = $this->perform($statement, $values);
return $sth->fetch(self::FETCH_ASSOC);
}

Expand All @@ -799,7 +799,7 @@ public function fetchOne($statement, array $values = array())
*/
public function fetchPairs($statement, array $values = array(), $callable = null)
{
$sth = $this->fetchStatement($statement, $values);
$sth = $this->perform($statement, $values);
if ($callable) {
$data = array();
while ($row = $sth->fetch(self::FETCH_NUM)) {
Expand All @@ -816,19 +816,19 @@ public function fetchPairs($statement, array $values = array(), $callable = null

/**
*
* Fetches the result as a PDOStatement.
* Performs a query and returns a PDOStatement.
*
* @param string $statement The SQL statement to prepare and execute.
* @param string $statement The SQL statement to perform.
*
* @param array $values Values to bind to the query.
*
* @return PDOStatement
*
*/
public function fetchStatement($statement, array $values = array())
public function perform($statement, array $values = array())
{
$this->bind_values = $values;
$sth = $this->prepareFetch($statement);
$sth = $this->performPrepare($statement);
$this->beginProfile(__FUNCTION__);
$sth->execute();
$this->endProfile($sth->queryString);
Expand All @@ -849,7 +849,7 @@ public function fetchStatement($statement, array $values = array())
*/
public function fetchValue($statement, array $values = array())
{
$sth = $this->fetchStatement($statement, $values);
$sth = $this->perform($statement, $values);
return $sth->fetchColumn(0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ExtendedPdoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function fetchPairs($statement, array $values = array(), $callable = null
* @return PDOStatement
*
*/
public function fetchStatement($statement, array $values = array());
public function perform($statement, array $values = array());

/**
*
Expand Down
12 changes: 6 additions & 6 deletions tests/src/ExtendedPdoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function insert(array $data)
$cols = implode(', ', $cols);
$vals = implode(', ', $vals);
$stm = "INSERT INTO pdotest ({$cols}) VALUES ({$vals})";
$this->pdo->fetchStatement($stm, $data);
$this->pdo->perform($stm, $data);
}

public function testGetDriver()
Expand Down Expand Up @@ -124,10 +124,10 @@ public function testQuery()
$this->assertEquals($expect, $actual);
}

public function testFetchStatement()
public function testperform()
{
$stm = "SELECT * FROM pdotest WHERE id <= :val";
$sth = $this->pdo->fetchStatement($stm, array('val' => '5'));
$sth = $this->pdo->perform($stm, array('val' => '5'));
$this->assertInstanceOf('PDOStatement', $sth);
$result = $sth->fetchAll(Pdo::FETCH_ASSOC);
$expect = 5;
Expand All @@ -139,7 +139,7 @@ public function testQueryWithArrayValues()
{
$stm = "SELECT * FROM pdotest WHERE id IN (:list) OR id = :id";

$sth = $this->pdo->fetchStatement($stm, array(
$sth = $this->pdo->perform($stm, array(
'list' => array(1, 2, 3, 4),
'id' => 5
));
Expand Down Expand Up @@ -195,7 +195,7 @@ public function testPrepareWithQuotedStringsAndData()
AND id IN (:list)
AND \"leave '':bar' alone\"";

$sth = $this->pdo->fetchStatement($stm, array(
$sth = $this->pdo->perform($stm, array(
'list' => array('1', '2', '3', '4', '5'),
'foo' => 'WRONG',
'bar' => 'WRONG',
Expand Down Expand Up @@ -489,7 +489,7 @@ public function testProfiling()
'bind_values' => array(),
),
2 => array(
'function' => 'fetchStatement',
'function' => 'perform',
'statement' => 'SELECT 3 FROM pdotest',
'bind_values' => array(
'zim' => 'gir',
Expand Down

0 comments on commit 1e3f74e

Please sign in to comment.