Пример #1
0
 /**
  * Returns a select query object.
  *
  * @param string $table_name Name of the main table you're selecting from (= first table in the from clause).
  * @param GlueDB_Fragment_Aliased_Table $alias Table alias object you may use to refer to the table columns.
  *
  * @return GlueDB_Fragment_Query_Select
  */
 public static function select($table_name = null, &$alias = null)
 {
     $f = new GlueDB_Fragment_Query_Select();
     if (func_num_args() > 0) {
         $args = func_get_args();
         return $f->from($table_name, $alias);
     } else {
         return $f;
     }
 }
Пример #2
0
 /**
  * Compiles GlueDB_Fragment_Query_Select fragments into an SQL string.
  *
  * @param GlueDB_Fragment_Query_Select $fragment
  *
  * @return string
  */
 public function compile_query_select(GlueDB_Fragment_Query_Select $fragment)
 {
     // Get data from fragment :
     $selectsql = $fragment->get()->sql($this);
     $fromsql = $fragment->from()->sql($this);
     $wheresql = $fragment->where()->sql($this);
     $groupbysql = $fragment->groupby()->sql($this);
     $havingsql = $fragment->having()->sql($this);
     $orderbysql = $fragment->orderby()->sql($this);
     $limit = $fragment->limit();
     $offset = $fragment->offset();
     // Mandatory :
     $sql = 'SELECT ' . (empty($selectsql) ? '*' : $selectsql) . ' FROM ' . $fromsql;
     // Optional :
     if (!empty($wheresql)) {
         $sql .= ' WHERE ' . $wheresql;
     }
     if (!empty($groupbysql)) {
         $sql .= ' GROUP BY ' . $groupbysql;
     }
     if (!empty($havingsql)) {
         $sql .= ' HAVING ' . $havingsql;
     }
     if (!empty($orderbysql)) {
         $sql .= ' ORDER BY ' . $orderbysql;
     }
     if (isset($limit)) {
         $sql .= ' LIMIT ' . $limit;
     }
     if (isset($offset)) {
         $sql .= ' OFFSET ' . $offset;
     }
     return $sql;
 }