Esempio n. 1
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;
 }