public function build($sql='')
    {

        $sql .= "\n";
        if (!empty($this->selectParams[self::SELECT])) {
            $sql = "SELECT ".implode(",\n", $this->selectParams[self::SELECT]);
        }
        if (!empty($this->selectParams[self::FROM])) {
            $sql .= "\nFROM ".implode(",\n", $this->selectParams[self::FROM]);
        }
        if (!empty($this->selectParams[self::JOIN])) {
            $sql .= " ".implode("\n ", $this->selectParams[self::JOIN]);
        }
        if (!empty($this->selectParams[self::WHERE])) {
            $sql .= "\nWHERE (".implode(")\n\t AND (", $this->selectParams[self::WHERE]). ") ";
            $sql .= "\n";
        }
        if (!empty($this->selectParams[self::ORWHERE])) {
            if(!empty($this->selectParams[self::WHERE]))
                $sql .= " AND ";
            else
                $sql .= "\nWHERE ";
            $sql .= " (".implode(" OR ", $this->selectParams[self::ORWHERE]). ") ";
            $sql .= "\n";
        }
        if (!empty($this->selectParams[self::GROUPBY])) {
            $sql .= "\nGROUP BY ".implode(",", $this->selectParams[self::GROUPBY]);
        }
        if (!empty($this->selectParams[self::ORDERBY])) {
            $sql .= "\nORDER BY ".implode(",", $this->selectParams[self::ORDERBY]);
        }

        if (isset($this->selectParams[self::LIMIT])) {
            if ($this->selectParams[self::LIMIT] != 0) {
                $sql .= "\nLIMIT ";
                if (!empty($this->selectParams[self::OFFSET])) {
                    if ($this->selectParams[self::OFFSET] < 0) $this->selectParams[self::OFFSET] = 0;
                    $sql .= $this->selectParams[self::OFFSET] .",";
                }
                $sql .= $this->selectParams[self::LIMIT];
            }
        }

        if($this->forUpdate)
            $sql .= " FOR UPDATE";

        return $sql;
    }