示例#1
0
 public function getSqlStatement()
 {
     $statement = new \Maestro\Database\MSQL();
     $statement->setTables($this->classMap->getDeleteSql());
     // Add 'WHERE' clause to the select statement
     if (($whereCondition = $this->whereCondition->getSql()) != '') {
         $statement->setWhere($whereCondition);
     }
     return $statement;
 }
示例#2
0
 public function getSqlStatement()
 {
     $statement = new \Maestro\Database\MSQL();
     $statement->setDb($this->getClassMap()->getDb());
     $statement->setTables($this->classMap->getUpdateSql());
     if (count($this->columnAttributes)) {
         $i = 0;
         $columns = '';
         foreach ($this->columnAttributes as $column) {
             if ($i++) {
                 $columns .= ',';
             }
             $columns .= $this->getOperand($column)->getSql();
         }
         $statement->setColumns($columns);
     }
     // Add 'WHERE' clause to update statement
     if (($whereCondition = $this->whereCondition->getSql()) != '') {
         $statement->setWhere($whereCondition);
     }
     return $statement;
 }
示例#3
0
 public function getQueryCommand($command)
 {
     try {
         $query = new MQuery();
         $query->setDb($this);
         $msql = new MSQL();
         $msql->setCommand($command);
         $query->setSQL($msql);
         return $query;
     } catch (\Exception $e) {
         throw EDBException::query($e->getMessage());
     }
 }
示例#4
0
 public function getUpdateStatementId($object, $id, $value = NULL)
 {
     // $id = array com PK dos objetos associados
     $statement = new \Maestro\Database\MSQL();
     $statement->setDb($this->fromClassMap->getDb());
     $statement->setTables($this->toClassMap->getTableName());
     $a = new OperandArray($id);
     $statement->setColumns($this->toAttributeMap->getName());
     $whereCondition = $this->toClassMap->getKeyAttributeName() . ' IN ' . $a->getSql();
     $statement->setWhere($whereCondition);
     //$statement->setParameters($object->getOIDValue());
     $statement->setParameters($value);
     return $statement->update();
 }
示例#5
0
 public function getSqlStatement()
 {
     $statement = new \Maestro\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);
     }
     $hasJoin = false;
     $joins = $this->getForcedJoin();
     if (count($joins)) {
         $hasJoin = true;
         foreach ($joins as $join) {
             $statement->join[] = $join;
         }
     }
     $joins = $this->getAssociationsJoin();
     if (count($joins)) {
         $hasJoin = true;
         foreach ($joins as $join) {
             $statement->join[] = $join;
         }
     }
     if (!$hasJoin) {
         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;
 }