overall code refactoring.

This commit is contained in:
Taylor Otwell
2011-06-14 17:27:11 -05:00
parent af24e8db45
commit 30c83f265d
36 changed files with 720 additions and 559 deletions

View File

@@ -10,18 +10,30 @@ class Compiler {
*/
public static function select($query)
{
// ----------------------------------------------------
// Add the SELECT, FROM, and WHERE clause to the query.
// ----------------------------------------------------
$sql = $query->select.' '.$query->from.' '.$query->where;
// ----------------------------------------------------
// Add the ORDER BY clause to the query.
// ----------------------------------------------------
if (count($query->orderings) > 0)
{
$sql .= ' ORDER BY '.implode(', ', $query->orderings);
}
// ----------------------------------------------------
// Add the LIMIT clause to the query.
// ----------------------------------------------------
if ( ! is_null($query->limit))
{
$sql .= ' LIMIT '.$query->limit;
}
// ----------------------------------------------------
// Add the OFFSET clause to the query.
// ----------------------------------------------------
if ( ! is_null($query->offset))
{
$sql .= ' OFFSET '.$query->offset;
@@ -39,11 +51,14 @@ class Compiler {
*/
public static function insert($query, $values)
{
// -----------------------------------------------------
// Begin the INSERT statement.
// -----------------------------------------------------
$sql = 'INSERT INTO '.$query->table.' (';
// ---------------------------------------------------
// ----------------------------------------------------
// Wrap each column name in keyword identifiers.
// ---------------------------------------------------
// ----------------------------------------------------
$columns = array();
foreach (array_keys($values) as $column)
@@ -51,6 +66,9 @@ class Compiler {
$columns[] = $query->wrap($column);
}
// -----------------------------------------------------
// Concatenante the columns and values to the statement.
// -----------------------------------------------------
return $sql .= implode(', ', $columns).') VALUES ('.$query->parameterize($values).')';
}
@@ -63,10 +81,13 @@ class Compiler {
*/
public static function update($query, $values)
{
// ----------------------------------------------------
// Initialize the UPDATE statement.
// ----------------------------------------------------
$sql = 'UPDATE '.$query->table.' SET ';
// ---------------------------------------------------
// Add each column set the query.
// Add each column set the statement.
// ---------------------------------------------------
$columns = array();
@@ -75,6 +96,9 @@ class Compiler {
$columns[] = $query->wrap($column).' = ?';
}
// ---------------------------------------------------
// Concatenate the SETs to the statement.
// ---------------------------------------------------
return $sql .= implode(', ', $columns).' '.$query->where;
}