Commit 8688270f authored by Taylor Otwell's avatar Taylor Otwell

fixed database bugs.

parent 15449c34
...@@ -43,16 +43,17 @@ return array( ...@@ -43,16 +43,17 @@ return array(
'sqlite' => function($config) 'sqlite' => function($config)
{ {
return new PDO('sqlite:'.DATABASE_PATH.'application.sqlite', null, null, $config['options']); return new PDO('sqlite:'.DATABASE_PATH.'application.sqlite', null, null, $config['options']);
} },
'mysql' => function($config) 'mysql' => function($config)
{ {
return new PDO('mysql:host=localhost;dbname=database', 'username', 'password', $config['options']); return new PDO('mysql:host=localhost;dbname=database', 'username', 'password', $config['options']);
} },
'pgsql' => array( 'pgsql' => function($config)
{
return new PDO('pgsql:host=localhost;dbname=database', 'username', 'password', $config['options']); return new PDO('pgsql:host=localhost;dbname=database', 'username', 'password', $config['options']);
), },
), ),
......
...@@ -105,7 +105,7 @@ class Connection { ...@@ -105,7 +105,7 @@ class Connection {
*/ */
public function table($table) public function table($table)
{ {
return new Query($this, $this->grammer(), $table); return new Query($this, $this->grammar(), $table);
} }
/** /**
...@@ -118,13 +118,13 @@ class Connection { ...@@ -118,13 +118,13 @@ class Connection {
switch ($this->driver()) switch ($this->driver())
{ {
case 'mysql': case 'mysql':
return new Queries\Grammars\MySQL; return new Grammars\MySQL;
case 'pgsql': case 'pgsql':
return new Queries\Grammars\Postgres; return new Grammars\Postgres;
default: default:
return new Queries\Grammars\Grammar; return new Grammars\Grammar;
} }
} }
......
<?php namespace Laravel\Database\Eloquent; <?php namespace Laravel\Database\Eloquent;
use Laravel\IoC;
use Laravel\Str; use Laravel\Str;
use Laravel\Inflector; use Laravel\Inflector;
......
...@@ -7,9 +7,6 @@ class Grammar { ...@@ -7,9 +7,6 @@ class Grammar {
/** /**
* Compile a SQL SELECT statment from a Query instance. * Compile a SQL SELECT statment from a Query instance.
* *
* This query instance will be examined and the proper SQL syntax will be returned as a string.
* This class may be overridden to accommodate syntax differences between various database systems.
*
* @param Query $query * @param Query $query
* @return string * @return string
*/ */
...@@ -37,26 +34,12 @@ class Grammar { ...@@ -37,26 +34,12 @@ class Grammar {
/** /**
* Compile the query SELECT clause. * Compile the query SELECT clause.
* *
* For convenience, the entire query object is passed to the method. This to account for
* database systems who put the LIMIT amount in the SELECT clause.
*
* @param Query $query * @param Query $query
* @return string * @return string
*/ */
public function compile_select(Query $query) protected function compile_select(Query $query)
{
return (($query->distinct) ? 'SELECT DISTINCT ' : 'SELECT ').$this->wrap_columns($query->select);
}
/**
* Wrap and comma-delimit a set of SELECT columns.
*
* @param array $columns
* @return string
*/
public function wrap_columns($columns)
{ {
return implode(', ', array_map(array($this, 'wrap'), $columns)); return (($query->distinct) ? 'SELECT DISTINCT ' : 'SELECT ').implode(', ', array_map(array($this, 'wrap'), $query->select));
} }
/** /**
...@@ -66,7 +49,7 @@ class Grammar { ...@@ -66,7 +49,7 @@ class Grammar {
* @param string $column * @param string $column
* @return string * @return string
*/ */
public function compile_aggregate($aggregator, $column) protected function compile_aggregate($aggregator, $column)
{ {
return 'SELECT '.$aggregator.'('.$this->wrap($column).') AS '.$this->wrap('aggregate'); return 'SELECT '.$aggregator.'('.$this->wrap($column).') AS '.$this->wrap('aggregate');
} }
...@@ -79,7 +62,7 @@ class Grammar { ...@@ -79,7 +62,7 @@ class Grammar {
* @param string $table * @param string $table
* @return string * @return string
*/ */
public function compile_from($table) protected function compile_from($table)
{ {
return 'FROM '.$this->wrap($table); return 'FROM '.$this->wrap($table);
} }
...@@ -90,7 +73,7 @@ class Grammar { ...@@ -90,7 +73,7 @@ class Grammar {
* @param array $joins * @param array $joins
* @return string * @return string
*/ */
public function compile_joins($joins) protected function compile_joins($joins)
{ {
foreach ($joins as $join) foreach ($joins as $join)
{ {
...@@ -108,28 +91,13 @@ class Grammar { ...@@ -108,28 +91,13 @@ class Grammar {
* @param array $wheres * @param array $wheres
* @return string * @return string
*/ */
public function compile_wheres($wheres) protected function compile_wheres($wheres)
{ {
$sql = array('WHERE 1 = 1'); $sql = array('WHERE 1 = 1');
foreach ($wheres as $where) foreach ($wheres as $where)
{ {
if (is_string($where)) $sql[] = (is_string($where)) ? $where : $where['connector'].' '.$this->{'compile_'.$where['type']}($where);
{
$sql[] = $where;
}
elseif ($where['type'] === 'where')
{
$sql[] = $where['connector'].' '.$this->compile_where($where);
}
elseif ($where['type'] === 'where_in')
{
$sql[] = $where['connector'].' '.$this->compile_where_in($where);
}
elseif ($where['type'] === 'where_null')
{
$sql[] = $where['connector'].' '.$this->compile_where_null($where);
}
} }
return implode(' ', $sql); return implode(' ', $sql);
...@@ -141,7 +109,7 @@ class Grammar { ...@@ -141,7 +109,7 @@ class Grammar {
* @param array $where * @param array $where
* @return string * @return string
*/ */
public function compile_where($where) protected function compile_where($where)
{ {
return $this->wrap($where['column']).' '.$where['operator'].' ?'; return $this->wrap($where['column']).' '.$where['operator'].' ?';
} }
...@@ -152,7 +120,7 @@ class Grammar { ...@@ -152,7 +120,7 @@ class Grammar {
* @param array $where * @param array $where
* @return string * @return string
*/ */
public function compile_where_in($where) protected function compile_where_in($where)
{ {
$operator = ($where['not']) ? 'NOT IN' : 'IN'; $operator = ($where['not']) ? 'NOT IN' : 'IN';
...@@ -165,7 +133,7 @@ class Grammar { ...@@ -165,7 +133,7 @@ class Grammar {
* @param array $where * @param array $where
* @return string * @return string
*/ */
public function compile_where_null($where) protected function compile_where_null($where)
{ {
$operator = ($where['not']) ? 'NOT NULL' : 'NULL'; $operator = ($where['not']) ? 'NOT NULL' : 'NULL';
...@@ -178,7 +146,7 @@ class Grammar { ...@@ -178,7 +146,7 @@ class Grammar {
* @param array $orderings * @param array $orderings
* @return string * @return string
*/ */
public function compile_orderings($orderings) protected function compile_orderings($orderings)
{ {
foreach ($orderings as $ordering) foreach ($orderings as $ordering)
{ {
...@@ -194,7 +162,7 @@ class Grammar { ...@@ -194,7 +162,7 @@ class Grammar {
* @param int $limit * @param int $limit
* @return string * @return string
*/ */
public function compile_limit($limit) protected function compile_limit($limit)
{ {
return 'LIMIT '.$limit; return 'LIMIT '.$limit;
} }
...@@ -205,7 +173,7 @@ class Grammar { ...@@ -205,7 +173,7 @@ class Grammar {
* @param int $offset * @param int $offset
* @return string * @return string
*/ */
public function compile_offset($offset) protected function compile_offset($offset)
{ {
return 'OFFSET '.$offset; return 'OFFSET '.$offset;
} }
......
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