Commit faa2eec3 authored by Taylor Otwell's avatar Taylor Otwell

consolidate database methods into db::query.

parent 42b9d1e0
...@@ -140,49 +140,22 @@ class Connection { ...@@ -140,49 +140,22 @@ class Connection {
{ {
list($statement, $result) = $this->execute($sql, $bindings); list($statement, $result) = $this->execute($sql, $bindings);
return $statement->fetchAll(PDO::FETCH_CLASS, 'stdClass'); // 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.
* Execute a SQL UPDATE query and return the affected row count. if (stripos($sql, 'select') === 0)
* {
* @param string $sql return $statement->fetchAll(PDO::FETCH_CLASS, 'stdClass');
* @param array $bindings }
* @return int elseif (stripos($sql, 'update') === 0 or stripos($sql, 'delete') === 0)
*/ {
public function update($sql, $bindings = array()) return $statement->rowCount();
{ }
list($statement, $result) = $this->execute($sql, $bindings); else
{
return $statement->rowCount(); return $result;
} }
/**
* 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())
{
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;
} }
/** /**
......
...@@ -717,7 +717,7 @@ class Query { ...@@ -717,7 +717,7 @@ class Query {
$sql = $this->grammar->insert($this, $values); $sql = $this->grammar->insert($this, $values);
return $this->connection->statement($sql, $bindings); return $this->connection->query($sql, $bindings);
} }
/** /**
...@@ -731,7 +731,7 @@ class Query { ...@@ -731,7 +731,7 @@ class Query {
{ {
$sql = $this->grammar->insert($this, $values); $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 // Some database systems (Postgres) require a sequence name to be
// given when retrieving the auto-incrementing ID, so we'll pass // given when retrieving the auto-incrementing ID, so we'll pass
...@@ -797,7 +797,7 @@ class Query { ...@@ -797,7 +797,7 @@ class Query {
$sql = $this->grammar->update($this, $values); $sql = $this->grammar->update($this, $values);
return $this->connection->update($sql, $bindings); return $this->connection->query($sql, $bindings);
} }
/** /**
...@@ -820,7 +820,7 @@ class Query { ...@@ -820,7 +820,7 @@ class Query {
$sql = $this->grammar->delete($this); $sql = $this->grammar->delete($this);
return $this->connection->delete($sql, $this->bindings); return $this->connection->query($sql, $this->bindings);
} }
/** /**
......
...@@ -89,7 +89,7 @@ class Schema { ...@@ -89,7 +89,7 @@ class Schema {
// needs multiple queries to complete. // needs multiple queries to complete.
foreach ((array) $statements as $statement) foreach ((array) $statements as $statement)
{ {
$connection->statement($statement); $connection->query($statement);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment