consolidate database methods into db::query.

This commit is contained in:
Taylor Otwell 2012-02-17 08:47:06 -06:00
parent 42b9d1e097
commit faa2eec3b9
3 changed files with 21 additions and 48 deletions

View File

@ -140,50 +140,23 @@ public function query($sql, $bindings = array())
{
list($statement, $result) = $this->execute($sql, $bindings);
// The result we return depends on the type of query executed against the
// database. On SELECT clauses, we will return the result set, for update
// and deletes we will return the affected row count. And for all other
// queries we'll just return the boolean result.
if (stripos($sql, 'select') === 0)
{
return $statement->fetchAll(PDO::FETCH_CLASS, 'stdClass');
}
/**
* Execute a SQL UPDATE query and return the affected row count.
*
* @param string $sql
* @param array $bindings
* @return int
*/
public function update($sql, $bindings = array())
elseif (stripos($sql, 'update') === 0 or stripos($sql, 'delete') === 0)
{
list($statement, $result) = $this->execute($sql, $bindings);
return $statement->rowCount();
}
/**
* Execute a SQL DELETE query and return the affected row count.
*
* @param string $sql
* @param array $bindings
* @return int
*/
public function delete($sql, $bindings = array())
else
{
list($statement, $result) = $this->execute($sql, $bindings);
return $statement->rowCount();
}
/**
* Execute an SQL query and return the boolean result of the PDO statement.
*
* @param string $sql
* @param array $bindings
* @return bool
*/
public function statement($sql, $bindings = array())
{
list($statement, $result) = $this->execute($sql, $bindings);
return $result;
}
}
/**
* Execute a SQL query against the connection.

View File

@ -717,7 +717,7 @@ public function insert($values)
$sql = $this->grammar->insert($this, $values);
return $this->connection->statement($sql, $bindings);
return $this->connection->query($sql, $bindings);
}
/**
@ -731,7 +731,7 @@ public function insert_get_id($values, $sequence = null)
{
$sql = $this->grammar->insert($this, $values);
$this->connection->statement($sql, array_values($values));
$this->connection->query($sql, array_values($values));
// Some database systems (Postgres) require a sequence name to be
// given when retrieving the auto-incrementing ID, so we'll pass
@ -797,7 +797,7 @@ public function update($values)
$sql = $this->grammar->update($this, $values);
return $this->connection->update($sql, $bindings);
return $this->connection->query($sql, $bindings);
}
/**
@ -820,7 +820,7 @@ public function delete($id = null)
$sql = $this->grammar->delete($this);
return $this->connection->delete($sql, $this->bindings);
return $this->connection->query($sql, $this->bindings);
}
/**

View File

@ -89,7 +89,7 @@ public static function execute($table)
// needs multiple queries to complete.
foreach ((array) $statements as $statement)
{
$connection->statement($statement);
$connection->query($statement);
}
}
}