public function getSqlStatement() { $statement = new \database\MSQL(); $statement->setTables($this->classMap->getDeleteSql()); // Add 'WHERE' clause to the select statement if (($whereCondition = $this->whereCondition->getSql()) != '') { $statement->setWhere($whereCondition); } return $statement; }
public function getNextValue($sequence = '', $tableGenerator = 'manager_sequence') { $sql = new \database\MSQL("value", $tableGenerator, "(sequence='" . $sequence . "')"); $sql->setDb($this->db); $result = $this->db->query($sql->select()); $value = $result[0][0]; $sql = new \database\MSQL("value", $tableGenerator, "(sequence='" . $sequence . "')"); $sql->setDb($this->db); $result = $this->db->query($sql->update(':value + 1')); return $value; }
private function _getNextValue($sequence = 'admin') { $transaction = $this->db->beginTransaction(); $table = $this->db->getConfig('sequence.table'); $name = $this->db->getConfig('sequence.name'); $field = $this->db->getConfig('sequence.value'); $sql = new \database\MSQL($field, $table, "({$name} = '{$sequence}')"); $sql->setForUpdate(true); $result = $this->db->query($sql); $value = $result[0][0]; $nextValue = $value + 1; $this->db->execute($sql->update($nextValue), $nextValue); $transaction->commit(); return $value; }
public function getSqlStatement() { $statement = new \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; }
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; }
public function getUpdateStatementId($object, $id, $value = NULL) { // $id = array com PK dos objetos associados $statement = new \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(); }