public function getSqlStatement()
 {
     $statement = new \database\MSQL();
     if (count($this->columns) == 0) {
         $this->select('*');
     }
     $sqlColumns = array();
     foreach ($this->columns as $column) {
         $sqlColumns[] = $this->getOperand($column)->getSql();
     }
     $columns = implode(',', $sqlColumns);
     $statement->setColumns($columns, $this->distinct);
     if (($where = $this->whereCondition->getSql()) != '') {
         $statement->setWhere($where);
     }
     if (count($this->groups)) {
         $sqlGroup = array();
         foreach ($this->groups as $group) {
             $sqlGroups[] = $this->getOperand($group)->getSqlGroup();
         }
         $groups = implode(',', $sqlGroups);
         $statement->setGroupBy($groups);
     }
     if (($having = $this->havingCondition->getSql()) != '') {
         $statement->setHaving($having);
     }
     if (count($this->orders)) {
         $sqlOrders = array();
         foreach ($this->orders as $order) {
             $o = explode(' ', $order);
             $sqlOrders[] = $this->getOperand($o[0])->getSqlOrder() . ' ' . $o[1];
         }
         $orders = implode(',', $sqlOrders);
         $statement->setOrderBy($orders);
     }
     if ($n = count($this->tableCriteria)) {
         for ($i = 0; $i < $n; $i++) {
             $tables .= ($i > 0 ? ", " : "") . '(' . $this->tableCriteria[$i][0] . ')' . ' ' . $this->tableCriteria[$i][1];
         }
         $statement->setTables($tables);
     }
     $joins = $this->getAssociationsJoin();
     if (count($joins)) {
         foreach ($joins as $join) {
             $statement->join[] = $join;
         }
     } else {
         if (count($this->classes)) {
             $sqlTables = array();
             foreach ($this->classes as $class) {
                 $sqlTables[] = $this->getTableName($class[0]) . ' ' . $class[1];
             }
             $tables = implode(',', $sqlTables);
             $statement->setTables($tables);
         }
     }
     // Set parameters to the select statement
     if (!is_null($this->parameters)) {
         $statement->setParameters($this->parameters);
     }
     // Add a range clause to the select statement
     if (!is_null($this->range)) {
         $statement->setRange($this->range);
     }
     // Add a FOR UPDATE clause to the select statement
     if ($this->forUpdate) {
         $statement->setForUpdate(TRUE);
     }
     // Add Set Operations
     if (count($this->setOperation)) {
         foreach ($this->setOperation as $s) {
             $statement->setSetOperation($s[0], $s[1]->getSqlStatement());
         }
     }
     return $statement;
 }