fixed database bugs.
This commit is contained in:
parent
15449c34b1
commit
8688270f22
|
@ -43,16 +43,17 @@
|
|||
'sqlite' => function($config)
|
||||
{
|
||||
return new PDO('sqlite:'.DATABASE_PATH.'application.sqlite', null, null, $config['options']);
|
||||
}
|
||||
},
|
||||
|
||||
'mysql' => function($config)
|
||||
{
|
||||
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']);
|
||||
),
|
||||
},
|
||||
|
||||
),
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ protected function execute(PDOStatement $statement, $bindings)
|
|||
*/
|
||||
public function table($table)
|
||||
{
|
||||
return new Query($this, $this->grammer(), $table);
|
||||
return new Query($this, $this->grammar(), $table);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,13 +118,13 @@ protected function grammar()
|
|||
switch ($this->driver())
|
||||
{
|
||||
case 'mysql':
|
||||
return new Queries\Grammars\MySQL;
|
||||
return new Grammars\MySQL;
|
||||
|
||||
case 'pgsql':
|
||||
return new Queries\Grammars\Postgres;
|
||||
return new Grammars\Postgres;
|
||||
|
||||
default:
|
||||
return new Queries\Grammars\Grammar;
|
||||
return new Grammars\Grammar;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php namespace Laravel\Database\Eloquent;
|
||||
|
||||
use Laravel\IoC;
|
||||
use Laravel\Str;
|
||||
use Laravel\Inflector;
|
||||
|
||||
|
|
|
@ -7,9 +7,6 @@ class Grammar {
|
|||
/**
|
||||
* 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
|
||||
* @return string
|
||||
*/
|
||||
|
@ -37,26 +34,12 @@ public function select(Query $query)
|
|||
/**
|
||||
* 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
|
||||
* @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 @@ public function wrap_columns($columns)
|
|||
* @param string $column
|
||||
* @return string
|
||||
*/
|
||||
public function compile_aggregate($aggregator, $column)
|
||||
protected function compile_aggregate($aggregator, $column)
|
||||
{
|
||||
return 'SELECT '.$aggregator.'('.$this->wrap($column).') AS '.$this->wrap('aggregate');
|
||||
}
|
||||
|
@ -79,7 +62,7 @@ public function compile_aggregate($aggregator, $column)
|
|||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public function compile_from($table)
|
||||
protected function compile_from($table)
|
||||
{
|
||||
return 'FROM '.$this->wrap($table);
|
||||
}
|
||||
|
@ -90,7 +73,7 @@ public function compile_from($table)
|
|||
* @param array $joins
|
||||
* @return string
|
||||
*/
|
||||
public function compile_joins($joins)
|
||||
protected function compile_joins($joins)
|
||||
{
|
||||
foreach ($joins as $join)
|
||||
{
|
||||
|
@ -108,28 +91,13 @@ public function compile_joins($joins)
|
|||
* @param array $wheres
|
||||
* @return string
|
||||
*/
|
||||
public function compile_wheres($wheres)
|
||||
protected function compile_wheres($wheres)
|
||||
{
|
||||
$sql = array('WHERE 1 = 1');
|
||||
|
||||
foreach ($wheres as $where)
|
||||
{
|
||||
if (is_string($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);
|
||||
}
|
||||
$sql[] = (is_string($where)) ? $where : $where['connector'].' '.$this->{'compile_'.$where['type']}($where);
|
||||
}
|
||||
|
||||
return implode(' ', $sql);
|
||||
|
@ -141,7 +109,7 @@ public function compile_wheres($wheres)
|
|||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
public function compile_where($where)
|
||||
protected function compile_where($where)
|
||||
{
|
||||
return $this->wrap($where['column']).' '.$where['operator'].' ?';
|
||||
}
|
||||
|
@ -152,7 +120,7 @@ public function compile_where($where)
|
|||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
public function compile_where_in($where)
|
||||
protected function compile_where_in($where)
|
||||
{
|
||||
$operator = ($where['not']) ? 'NOT IN' : 'IN';
|
||||
|
||||
|
@ -165,7 +133,7 @@ public function compile_where_in($where)
|
|||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
public function compile_where_null($where)
|
||||
protected function compile_where_null($where)
|
||||
{
|
||||
$operator = ($where['not']) ? 'NOT NULL' : 'NULL';
|
||||
|
||||
|
@ -178,7 +146,7 @@ public function compile_where_null($where)
|
|||
* @param array $orderings
|
||||
* @return string
|
||||
*/
|
||||
public function compile_orderings($orderings)
|
||||
protected function compile_orderings($orderings)
|
||||
{
|
||||
foreach ($orderings as $ordering)
|
||||
{
|
||||
|
@ -194,7 +162,7 @@ public function compile_orderings($orderings)
|
|||
* @param int $limit
|
||||
* @return string
|
||||
*/
|
||||
public function compile_limit($limit)
|
||||
protected function compile_limit($limit)
|
||||
{
|
||||
return 'LIMIT '.$limit;
|
||||
}
|
||||
|
@ -205,7 +173,7 @@ public function compile_limit($limit)
|
|||
* @param int $offset
|
||||
* @return string
|
||||
*/
|
||||
public function compile_offset($offset)
|
||||
protected function compile_offset($offset)
|
||||
{
|
||||
return 'OFFSET '.$offset;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue