Example #1
0
 public function build(Sabel_Db_Statement $stmt)
 {
     $num = ++self::$counter;
     $stmt->setBindValue("param{$num}", $this->value);
     $column = $this->getQuotedColumn($stmt);
     if ($this->isNot) {
         $column = "NOT " . $column;
     }
     return $column . " = @param{$num}@";
 }
Example #2
0
 public function build(Sabel_Db_Statement $stmt)
 {
     $f = ++self::$counter;
     $t = ++self::$counter;
     $val = $this->value;
     $stmt->setBindValue("param{$f}", $val[0]);
     $stmt->setBindValue("param{$t}", $val[1]);
     $column = $this->getQuotedColumn($stmt);
     if ($this->isNot) {
         $column = "NOT " . $column;
     }
     return $column . " BETWEEN @param{$f}@ AND @param{$t}@";
 }
Example #3
0
 public function getProjection(Sabel_Db_Statement $stmt)
 {
     $projection = array();
     $name = $this->hasAlias() ? strtolower($this->aliasName) : $this->getName(false);
     foreach ($this->columns as $column) {
         $as = "{$name}.{$column}";
         if (strlen($as) > 30) {
             $as = Sabel_Db_Join_ColumnHash::toHash($as);
         }
         $p = $stmt->quoteIdentifier($name) . "." . $stmt->quoteIdentifier($column);
         $projection[] = $p . " AS " . $stmt->quoteIdentifier($as);
     }
     return $projection;
 }
Example #4
0
 public function execute($bindValues = array(), $additionalParameters = array(), $query = null)
 {
     $query = $this->getQuery();
     if (!empty($this->binaries)) {
         for ($i = 0, $c = count($this->binaries); $i < $c; $i++) {
             $query = str_replace("__sbl_binary" . ($i + 1), $this->binaries[$i]->getData(), $query);
         }
     }
     $result = parent::execute($bindValues, $additionalParameters, $query);
     if (!$this->isSelect() || empty($result)) {
         return $result;
     }
     $binaryColumns = array();
     foreach ($this->metadata->getColumns() as $column) {
         if ($column->isBinary()) {
             $binaryColumns[] = $column->name;
         }
     }
     if (!empty($binaryColumns)) {
         foreach ($result as &$row) {
             foreach ($binaryColumns as $colName) {
                 if (isset($row[$colName])) {
                     $row[$colName] = pg_unescape_bytea($row[$colName]);
                 }
             }
         }
     }
     return $result;
 }
Example #5
0
 public function execute($bindValues = array(), $additionalParameters = array(), $query = null)
 {
     $query = $this->getQuery();
     if (!empty($this->binaries)) {
         for ($i = 0, $c = count($this->binaries); $i < $c; $i++) {
             $query = str_replace("__sbl_binary" . ($i + 1), $this->binaries[$i]->getData(), $query);
         }
     }
     return parent::execute($bindValues, $additionalParameters, $query);
 }
Example #6
0
 public function createInsertSql()
 {
     if (($column = $this->seqColumn) !== null) {
         $seqName = strtoupper("{$this->table}_{$column}_seq");
         $rows = $this->driver->execute("SELECT GEN_ID({$seqName}, 1) AS id FROM RDB\$DATABASE");
         $this->values[$column] = $id = $rows[0]["id"];
         $this->appendBindValues(array($column => $id));
         $this->driver->setLastInsertId($id);
     }
     return parent::createInsertSql();
 }
Example #7
0
 public function values(array $values)
 {
     if ($this->isInsert()) {
         foreach ($this->metadata->getColumns() as $colName => $column) {
             if (!isset($values[$colName]) && $this->isVarcharOfDefaultNull($column)) {
                 $values[$colName] = null;
             }
         }
     }
     return parent::values($values);
 }
Example #8
0
 public function execute($bindValues = array(), $additionalParameters = array())
 {
     $this->query = preg_replace('/@([a-zA-Z0-9_]+)@/', ':$1', $this->getQuery());
     if (empty($bindValues)) {
         if (empty($this->bindValues)) {
             $bindValues = array();
         } else {
             $bindValues = $this->escape($this->bindValues);
             foreach ($bindValues as $k => $v) {
                 $bindValues[":{$k}"] = $v;
                 unset($bindValues[$k]);
             }
         }
     }
     return parent::execute($bindValues, $additionalParameters);
 }
Example #9
0
 public function getJoinQuery(Sabel_Db_Statement $stmt, $joinType)
 {
     $name = $stmt->quoteIdentifier($this->tblName);
     $keys = $this->joinKey;
     $query = array(" {$joinType} JOIN {$name} ");
     if ($this->hasAlias()) {
         $name = $stmt->quoteIdentifier(strtolower($this->aliasName));
         $query[] = $name . " ";
     }
     $query[] = "ON {$name}." . $stmt->quoteIdentifier($keys["id"]) . " = " . $stmt->quoteIdentifier(strtolower($this->childName)) . "." . $stmt->quoteIdentifier($keys["fkey"]);
     foreach ($this->objects as $object) {
         $query[] = $object->getJoinQuery($stmt, $joinType);
     }
     return implode("", $query);
 }
Example #10
0
 public function getJoinQuery(Sabel_Db_Statement $stmt, $joinType)
 {
     $name = $stmt->quoteIdentifier(XOOPS_DB_PREFIX . "_" . $this->tblName);
     $keys = $this->joinKey;
     $query = array(" {$joinType} JOIN {$name} ");
     if ($this->hasAlias()) {
         $name = $stmt->quoteIdentifier(strtolower($this->aliasName));
         $query[] = $name . " ";
     } else {
         $name = $stmt->quoteIdentifier($this->tblName);
         $query[] = $name . " ";
     }
     $query[] = "ON {$name}." . $stmt->quoteIdentifier($keys["id"]) . " = " . $stmt->quoteIdentifier(strtolower($this->childName)) . "." . $stmt->quoteIdentifier($keys["fkey"]);
     return implode("", $query);
 }
Example #11
0
 public function execute($bindValues = array(), $additionalParameters = array())
 {
     $result = parent::execute($bindValues);
     if (!$this->isSelect() || empty($result) || !extension_loaded("mbstring")) {
         return $result;
     }
     $fromEnc = defined("SDB_MSSQL_ENCODING") ? SDB_MSSQL_ENCODING : "SJIS";
     $toEnc = mb_internal_encoding();
     $columns = $this->metadata->getColumns();
     foreach ($result as &$row) {
         foreach ($columns as $name => $column) {
             if (isset($row[$name]) && ($column->isString() || $column->isText())) {
                 $row[$name] = mb_convert_encoding($row[$name], $toEnc, $fromEnc);
             }
         }
     }
     return $result;
 }
Example #12
0
 public function execute($bindValues = array(), $additionalParameters = array())
 {
     $result = parent::execute($bindValues, $additionalParameters);
     if (!$this->isSelect() || empty($result)) {
         return $result;
     }
     $binaryColumns = array();
     foreach ($this->metadata->getColumns() as $column) {
         if ($column->isBinary()) {
             $binaryColumns[] = $column->name;
         }
     }
     if (!empty($binaryColumns)) {
         foreach ($result as &$row) {
             foreach ($binaryColumns as $colName) {
                 if (isset($row[$colName])) {
                     $row[$colName] = pg_unescape_bytea($row[$colName]);
                 }
             }
         }
     }
     return $result;
 }
Example #13
0
 public function createInsertSql()
 {
     if (($column = $this->seqColumn) !== null) {
         $seqName = strtoupper("{$this->table}_{$column}_seq");
         $rows = $this->driver->execute("SELECT {$seqName}.NEXTVAL AS id FROM DUAL");
         $this->values[$column] = $id = $rows[0]["id"];
         $this->bind($column, $id);
         $this->driver->setLastInsertId($id);
     }
     return parent::createInsertSql();
 }
Example #14
0
 /**
  * @param Sabel_Db_Statement $stmt
  *
  * @return string
  */
 protected function getQuotedColumn($stmt)
 {
     if (strpos($this->column, ".") === false) {
         return $stmt->quoteIdentifier($this->column);
     } else {
         list($tbl, $col) = explode(".", $this->column);
         return $stmt->quoteIdentifier($tbl) . "." . $stmt->quoteIdentifier($col);
     }
 }
Example #15
0
 private function __getJoinQuery(Sabel_Db_Statement $stmt, $on)
 {
     return $stmt->quoteIdentifier($on["id"]) . " = " . $stmt->quoteIdentifier(strtolower($this->childName)) . "." . $stmt->quoteIdentifier($on["fkey"]);
 }
Example #16
0
 public function execute($bindValues = array(), $additionalParameters = array(), $query = null)
 {
     $query = preg_replace('/@([a-zA-Z0-9_]+)@/', ':$1', $this->getQuery());
     return parent::execute($bindValues, $additionalParameters, $query);
 }
Example #17
0
 /**
  * @param Sabel_Db_Statement $stmt
  *
  * @return Sabel_Db_Statement
  */
 protected function prepareDelete(Sabel_Db_Statement $stmt)
 {
     return $stmt->where($this->getCondition()->build($stmt));
 }