/**
  * Returns a series of strings concatinated
  *
  * concat() accepts an arbitrary number of parameters. Each parameter
  * must contain an expression or an array with expressions.
  *
  * @throws ezcQueryVariableException if no parameters are provided
  * @param string|array(string) $... strings that will be concatinated.
  * @return string
  */
 public function concat()
 {
     $args = func_get_args();
     $cols = ezcQuery::arrayFlatten($args);
     if (count($cols) < 1) {
         throw new ezcQueryVariableParameterException('concat', count($args), 1);
     }
     $cols = $this->getIdentifiers($cols);
     return join(' || ', $cols);
 }
 /**
  * Binds the value $value to the specified variable name $placeHolder.
  *
  * This method uses ezcQuery::bindParam() from the ezcQuery class in which
  * the subSelect was called. Info about bound parameters are stored in
  * the parent ezcQuery object that is stored in the $outer property.
  *
  * The parameter $value specifies the value that you want to bind. If
  * $placeholder is not provided bindValue() will automatically create a
  * placeholder for you. An automatic placeholder will be of the name
  * 'ezcValue1', 'ezcValue2' etc.
  *
  * Example:
  * <code>
  * <?php
  * $value = 2;
  * $subSelect = $q->subSelect();
  * $subSelect->select( name )
  *          ->from( 'table2' )
  *          ->where(  $subSelect->expr->in(
  *                'id', $subSelect->bindValue( $value )
  *                 )
  *            );
  *
  * $q->select( '*' )
  *   ->from( 'table1' )
  *   ->where ( $q->expr->eq( 'name', $subSelect ) );
  *
  * $stmt = $q->prepare(); // the $value is bound to the query.
  * $value = 4;
  * $stmt->execute(); // subselect executed with 'id = 2'
  * ?>
  * </code>
  *
  * @see ezcQuery::bindValue()
  *
  * @param mixed $value
  * @param string $placeHolder the name to bind with. The string must start with a colon ':'.
  * @return string the placeholder name used.
  */
 public function bindValue($value, $placeHolder = null, $type = PDO::PARAM_STR)
 {
     return $this->outerQuery->bindValue($value, $placeHolder, $type);
 }
示例#3
0
 /**
  * Constructs a new ezcQueryDelete that works on the database $db and with the aliases $aliases.
  *
  * The paramters are passed directly to ezcQuery.
  * @param PDO $db
  * @param array(string=>string) $aliases
  */
 public function __construct(PDO $db, array $aliases = array())
 {
     parent::__construct($db, $aliases);
 }
示例#4
0
 public function __construct()
 {
     parent::__construct(ezcDbInstance::get());
 }
示例#5
0
 /**
  * Sets find query value for many-to-many related objects. 
  *
  * Manipulates the find $query for objects related to the object defined in
  * $objectState, defined my the relation $relation.
  * 
  * @param ezcQuery $query 
  * @param ezcPersistentObjectDefinition $def
  * @param ezcPersistentManyToManyRelation $relation 
  * @param array $objectState 
  */
 private function createComplexRelationFindQuery(ezcQuery $query, ezcPersistentObjectDefinition $def, ezcPersistentManyToManyRelation $relation, array $objectState)
 {
     $db = $this->database;
     $relationTableQuoted = $db->quoteIdentifier($relation->relationTable);
     // Join with relation table.
     $query->from($relationTableQuoted);
     foreach ($relation->columnMap as $map) {
         $query->where($query->expr->eq($relationTableQuoted . "." . $db->quoteIdentifier($map->relationSourceColumn), $query->bindValue($objectState[$def->columns[$map->sourceColumn]->propertyName], null, $def->columns[$map->sourceColumn]->databaseType)), $query->expr->eq($relationTableQuoted . "." . $db->quoteIdentifier($map->relationDestinationColumn), $db->quoteIdentifier($relation->destinationTable) . "." . $db->quoteIdentifier($map->destinationColumn)));
     }
 }
 /**
  * Limits the given $query to the subtree starting at $rootLocationId
  *
  * @param \ezcQuery $query
  * @param string $rootLocationId
  *
  * @return void
  */
 protected function applySubtreeLimitation(\ezcQuery $query, $rootLocationId)
 {
     $query->where($query->expr->like($this->handler->quoteColumn('path_string', 'ezcontentobject_tree'), $query->bindValue('%/' . $rootLocationId . '/%')));
 }
 /**
  * Performs the given query.
  *
  * Performs the $query, checks for errors and throws an exception in case.
  * Returns the generated statement object on success. If the $transaction
  * parameter is set to true, the query is excuted transaction save.
  * 
  * @param ezcQuery $q 
  * @param bool $transaction
  * @return PDOStatement
  *
  * @access private
  */
 public function performQuery(ezcQuery $q, $transaction = false)
 {
     if ($transaction) {
         $this->database->beginTransaction();
     }
     try {
         $stmt = $q->prepare();
         $stmt->execute();
         if (($errCode = $stmt->errorCode()) != 0) {
             if ($transaction) {
                 $this->database->rollback();
             }
             throw new ezcPersistentQueryException("The query returned error code {$errCode}.", $q);
         }
         if ($transaction) {
             $this->database->commit();
         }
         return $stmt;
     } catch (PDOException $e) {
         if ($transaction) {
             $this->database->rollback();
         }
         throw new ezcPersistentQueryException($e->getMessage(), $q);
     }
 }