various refactoring and tweaks.

This commit is contained in:
Taylor Otwell
2011-10-20 21:44:18 -05:00
parent df9130dafa
commit af36cb3d5a
22 changed files with 140 additions and 110 deletions

View File

@@ -43,6 +43,36 @@ class Connection {
$this->config = $config;
}
/**
* Begin a fluent query against a table.
*
* @param string $table
* @return Query
*/
public function table($table)
{
return new Query($this, $this->grammar(), $table);
}
/**
* Create a new query grammar for the connection.
*
* @return Grammars\Grammar
*/
protected function grammar()
{
if (isset($this->grammar)) return $this->grammar;
switch (isset($this->config['grammar']) ? $this->config['grammar'] : $this->driver())
{
case 'mysql':
return $this->grammar = new Grammars\MySQL;
default:
return $this->grammar = new Grammars\Grammar;
}
}
/**
* Execute a SQL query against the connection and return a single column result.
*
@@ -109,18 +139,18 @@ class Connection {
*/
public function query($sql, $bindings = array())
{
// First we need to remove all expressions from the bindings
// since they will be placed into the query as raw strings.
// Remove expressions from the bindings since they injected into
// the query as raw strings and are not bound parameters.
foreach ($bindings as $key => $value)
{
if ($value instanceof Expression) unset($bindings[$key]);
}
$sql = $this->transform($sql, $bindings);
$sql = $this->transform(trim($sql), $bindings);
$this->queries[] = compact('sql', 'bindings');
return $this->execute($this->pdo->prepare(trim($sql)), $bindings);
return $this->execute($this->pdo->prepare($sql), $bindings);
}
/**
@@ -178,36 +208,6 @@ class Connection {
return $statement->rowCount();
}
/**
* Begin a fluent query against a table.
*
* @param string $table
* @return Query
*/
public function table($table)
{
return new Query($this, $this->grammar(), $table);
}
/**
* Create a new query grammar for the connection.
*
* @return Grammars\Grammar
*/
protected function grammar()
{
if (isset($this->grammar)) return $this->grammar;
switch (isset($this->config['grammar']) ? $this->config['grammar'] : $this->driver())
{
case 'mysql':
return $this->grammar = new Grammars\MySQL;
default:
return $this->grammar = new Grammars\Grammar;
}
}
/**
* Get the driver name for the database connection.
*