示例#1
0
 /**
  * Returns the SQL JOIN clause
  *
  * @param \r8\iface\DB\Link $link The database connection this WHERE clause
  *      is being run against. This is being passed in for escaping purposes
  * @return String
  */
 public function toJoinSQL(\r8\iface\DB\Link $link)
 {
     $sql = $this->getJoinType() . " " . $this->table->toFromSQL($link);
     if ($this->on) {
         $sql .= " ON " . $this->on->toWhereSQL($link);
     }
     return $sql;
 }
示例#2
0
 /**
  * Returns the SQL this object represents
  *
  * @param \r8\iface\DB\Link $link The database link to use for escaping
  * @return String
  */
 public function toSQL(\r8\iface\DB\Link $link)
 {
     $sql = "SELECT ";
     if ($this->distinct) {
         $sql .= "DISTINCT ";
     }
     if ($this->foundRows) {
         $sql .= "SQL_CALC_FOUND_ROWS ";
     }
     if (count($this->fields) <= 0) {
         $sql .= "*";
     } else {
         $sql .= implode(", ", \r8\ary\invoke($this->fields, "toSelectSQL", $link));
     }
     if ($this->from) {
         $sql .= "\nFROM " . $this->from->toFromSQL($link);
     }
     foreach ($this->joins as $join) {
         $sql .= "\n" . $join->toJoinSQL($link);
     }
     if ($this->where) {
         $sql .= "\nWHERE " . $this->where->toWhereSQL($link);
     }
     if (count($this->order) > 0) {
         $sql .= "\nORDER BY " . implode(", ", \r8\ary\invoke($this->order, "toOrderedSQL", $link));
     }
     if (count($this->group) > 0) {
         $sql .= "\nGROUP BY " . implode(", ", \r8\ary\invoke($this->group, "toOrderedSQL", $link));
     }
     if ($this->having) {
         $sql .= "\nHAVING " . $this->having->toWhereSQL($link);
     }
     if ($this->limitExists()) {
         $sql .= "\nLIMIT " . ($this->offsetExists() ? $this->getOffset() : "0") . ", " . $this->getLimit();
     }
     return $sql;
 }