/**
  * @param string|\Zend\Db\Adapter\StatementContainerInterface $target
  * @return mixed
  */
 public function profilerStart($target)
 {
     $this->queries[] = ['start' => microtime(true), 'end' => null, 'sql' => $target->getSql()];
     if ($this->proxy) {
         call_user_func_array([$this->proxy, 'profilerStart'], func_get_args());
     }
 }
 /**
  * {@inheritDoc}
  *
  * @return StatementContainerInterface
  */
 public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer)
 {
     $parameterContainer = $statementContainer->getParameterContainer();
     if (!$parameterContainer instanceof ParameterContainer) {
         $parameterContainer = new ParameterContainer();
         $statementContainer->setParameterContainer($parameterContainer);
     }
     $statementContainer->setSql($this->buildSqlString($adapter->getPlatform(), $adapter->getDriver(), $parameterContainer));
     return $statementContainer;
 }
Exemple #3
0
 /**
  * @param string|StatementContainerInterface $target
  * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
  * @return Profiler
  */
 public function profilerStart($target)
 {
     $profileInformation = array('sql' => '', 'parameters' => null, 'start' => microtime(true), 'end' => null, 'elapse' => null);
     if ($target instanceof StatementContainerInterface) {
         $profileInformation['sql'] = $target->getSql();
         $profileInformation['parameters'] = clone $target->getParameterContainer();
     } elseif (is_string($target)) {
         $profileInformation['sql'] = $target;
     } else {
         throw new Exception\InvalidArgumentException(__FUNCTION__ . ' takes either a StatementContainer or a string');
     }
     $this->profiles[$this->currentIndex] = $profileInformation;
     return $this;
 }
Exemple #4
0
 /**
  * Prepare statement
  *
  * @param AdapterInterface $adapter
  * @param StatementContainerInterface $statementContainer
  * @return void
  */
 public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer)
 {
     // ensure statement has a ParameterContainer
     $parameterContainer = $statementContainer->getParameterContainer();
     if (!$parameterContainer instanceof ParameterContainer) {
         $parameterContainer = new ParameterContainer();
         $statementContainer->setParameterContainer($parameterContainer);
     }
     $sqls = array();
     $sqls[self::SHOW] = sprintf($this->specifications[static::SHOW], $this->show);
     $likePart = $this->processLike($adapter->getPlatform(), $adapter->getDriver(), $parameterContainer);
     if (is_array($likePart)) {
         $sqls[self::LIKE] = $this->createSqlFromSpecificationAndParameters($this->specifications[static::LIKE], $likePart);
     }
     $sql = implode(' ', $sqls);
     $statementContainer->setSql($sql);
     return;
 }
Exemple #5
0
 /**
  * Prepare statement
  *
  * @param  Adapter $adapter
  * @param  StatementContainerInterface $statementContainer
  * @return void
  */
 public function prepareStatement(Adapter $adapter, StatementContainerInterface $statementContainer)
 {
     $driver = $adapter->getDriver();
     $platform = $adapter->getPlatform();
     $parameterContainer = $statementContainer->getParameterContainer();
     if (!$parameterContainer instanceof ParameterContainer) {
         $parameterContainer = new ParameterContainer();
         $statementContainer->setParameterContainer($parameterContainer);
     }
     $table = $platform->quoteIdentifier($this->table);
     $columns = array();
     $values = array();
     foreach ($this->columns as $cIndex => $column) {
         $columns[$cIndex] = $platform->quoteIdentifier($column);
         if ($this->values[$cIndex] instanceof Expression) {
             $exprData = $this->processExpression($this->values[$cIndex], $platform, $adapter);
             $values[$cIndex] = $exprData->getSql();
             $parameterContainer->merge($exprData->getParameterContainer());
         } else {
             $values[$cIndex] = $driver->formatParameterName($column);
             $parameterContainer->offsetSet($column, $this->values[$cIndex]);
         }
     }
     $sql = sprintf($this->specifications[self::SPECIFICATION_INSERT], $table, implode(', ', $columns), implode(', ', $values));
     $statementContainer->setSql($sql);
 }
Exemple #6
0
 /**
  * Prepare statement
  *
  * @param \Zend\Db\Adapter\Adapter $adapter
  * @param \Zend\Db\Adapter\Driver\StatementInterface $statementContainer
  * @return void
  */
 public function prepareStatement(Adapter $adapter, StatementContainerInterface $statementContainer)
 {
     // ensure statement has a ParameterContainer
     $parameterContainer = $statementContainer->getParameterContainer();
     if (!$parameterContainer instanceof ParameterContainer) {
         $parameterContainer = new ParameterContainer();
         $statementContainer->setParameterContainer($parameterContainer);
     }
     $sqls = array();
     $parameters = array();
     $platform = $adapter->getPlatform();
     foreach ($this->specifications as $name => $specification) {
         $parameters[$name] = $this->{'process' . $name}($platform, $adapter, $parameterContainer, $sqls, $parameters);
         if ($specification && is_array($parameters[$name])) {
             $sqls[$name] = $this->createSqlFromSpecificationAndParameters($specification, $parameters[$name]);
         }
     }
     $sql = implode(' ', $sqls);
     $statementContainer->setSql($sql);
     return;
 }
Exemple #7
0
 /**
  * Prepare statement
  *
  * @param  AdapterInterface $adapter
  * @param  StatementContainerInterface $statementContainer
  * @return void
  */
 public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer)
 {
     $driver = $adapter->getDriver();
     $platform = $adapter->getPlatform();
     $parameterContainer = $statementContainer->getParameterContainer();
     if (!$parameterContainer instanceof ParameterContainer) {
         $parameterContainer = new ParameterContainer();
         $statementContainer->setParameterContainer($parameterContainer);
     }
     $table = $this->table;
     $schema = null;
     // create quoted table name to use in insert processing
     if ($table instanceof TableIdentifier) {
         list($table, $schema) = $table->getTableAndSchema();
     }
     $table = $platform->quoteIdentifier($table);
     if ($schema) {
         $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table;
     }
     $columns = array();
     $values = array();
     foreach ($this->columns as $cIndex => $column) {
         $columns[$cIndex] = $platform->quoteIdentifier($column);
         if (isset($this->values[$cIndex]) && $this->values[$cIndex] instanceof Expression) {
             $exprData = $this->processExpression($this->values[$cIndex], $platform, $driver);
             $values[$cIndex] = $exprData->getSql();
             $parameterContainer->merge($exprData->getParameterContainer());
         } else {
             $values[$cIndex] = $driver->formatParameterName($column);
             if (isset($this->values[$cIndex])) {
                 $parameterContainer->offsetSet($column, $this->values[$cIndex]);
             } else {
                 $parameterContainer->offsetSet($column, null);
             }
         }
     }
     $sql = sprintf($this->specifications[self::SPECIFICATION_INSERT], $table, implode(', ', $columns), implode(', ', $values));
     $statementContainer->setSql($sql);
 }
Exemple #8
0
 /**
  * Prepare statement
  *
  * @param AdapterInterface $adapter
  * @param StatementContainerInterface $statementContainer
  * @return void
  */
 public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer)
 {
     $driver = $adapter->getDriver();
     $platform = $adapter->getPlatform();
     $parameterContainer = $statementContainer->getParameterContainer();
     if (!$parameterContainer instanceof ParameterContainer) {
         $parameterContainer = new ParameterContainer();
         $statementContainer->setParameterContainer($parameterContainer);
     }
     $table = $this->table;
     $schema = null;
     // create quoted table name to use in update processing
     if ($table instanceof TableIdentifier) {
         list($table, $schema) = $table->getTableAndSchema();
     }
     $table = $platform->quoteIdentifier($table);
     if ($schema) {
         $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table;
     }
     $set = $this->set;
     if (is_array($set)) {
         $setSql = array();
         foreach ($set as $column => $value) {
             if ($value instanceof Expression) {
                 $exprData = $this->processExpression($value, $platform, $driver);
                 $setSql[] = $platform->quoteIdentifier($column) . ' = ' . $exprData->getSql();
                 $parameterContainer->merge($exprData->getParameterContainer());
             } else {
                 $setSql[] = $platform->quoteIdentifier($column) . ' = ' . $driver->formatParameterName($column);
                 $parameterContainer->offsetSet($column, $value);
             }
         }
         $set = implode(', ', $setSql);
     }
     $sql = sprintf($this->specifications[static::SPECIFICATION_UPDATE], $table, $set);
     // process where
     if ($this->where->count() > 0) {
         $whereParts = $this->processExpression($this->where, $platform, $driver, 'where');
         $parameterContainer->merge($whereParts->getParameterContainer());
         $sql .= ' ' . sprintf($this->specifications[static::SPECIFICATION_WHERE], $whereParts->getSql());
     }
     $statementContainer->setSql($sql);
 }
Exemple #9
0
 /**
  * Prepare the delete statement
  *
  * @param  Adapter $adapter
  * @param  StatementContainerInterface $statementContainer
  * @return void
  */
 public function prepareStatement(Adapter $adapter, StatementContainerInterface $statementContainer)
 {
     $platform = $adapter->getPlatform();
     $parameterContainer = $statementContainer->getParameterContainer();
     if (!$parameterContainer instanceof ParameterContainer) {
         $parameterContainer = new ParameterContainer();
         $statementContainer->setParameterContainer($parameterContainer);
     }
     $table = $platform->quoteIdentifier($this->table);
     $sql = sprintf($this->specifications[self::SPECIFICATION_DELETE], $table);
     // process where
     if ($this->where->count() > 0) {
         $whereParts = $this->processExpression($this->where, $platform, $adapter, 'where');
         $parameterContainer->merge($whereParts->getParameterContainer());
         $sql .= ' ' . sprintf($this->specifications[self::SPECIFICATION_WHERE], $whereParts->getSql());
     }
     $statementContainer->setSql($sql);
 }
Exemple #10
0
 /**
  * Prepare the delete statement
  *
  * @param  AdapterInterface $adapter
  * @param  StatementContainerInterface $statementContainer
  * @return void
  */
 public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer)
 {
     $driver = $adapter->getDriver();
     $platform = $adapter->getPlatform();
     $parameterContainer = $statementContainer->getParameterContainer();
     if (!$parameterContainer instanceof ParameterContainer) {
         $parameterContainer = new ParameterContainer();
         $statementContainer->setParameterContainer($parameterContainer);
     }
     $table = $this->table;
     $schema = null;
     // create quoted table name to use in delete processing
     if ($table instanceof TableIdentifier) {
         list($table, $schema) = $table->getTableAndSchema();
     }
     $table = $platform->quoteIdentifier($table);
     if ($schema) {
         $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table;
     }
     $sql = sprintf($this->specifications[static::SPECIFICATION_DELETE], $table);
     // process where
     if ($this->where->count() > 0) {
         $whereParts = $this->processExpression($this->where, $platform, $driver, 'where');
         $parameterContainer->merge($whereParts->getParameterContainer());
         $sql .= ' ' . sprintf($this->specifications[static::SPECIFICATION_WHERE], $whereParts->getSql());
     }
     $statementContainer->setSql($sql);
 }
Exemple #11
0
 /**
  * @param   AdapterInterface            $adapter
  * @param   StatementContainerInterface $statementContainer
  * @return  void
  */
 public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer)
 {
     $driver = $adapter->getDriver();
     $platform = $adapter->getPlatform();
     $parameterContainer = $statementContainer->getParameterContainer();
     if (!$parameterContainer instanceof ParameterContainer) {
         $parameterContainer = new ParameterContainer();
         $statementContainer->setParameterContainer($parameterContainer);
     }
     $function = $platform->quoteIdentifierChain($this->function);
     $resultKey = $platform->quoteIdentifier($this->resultKey);
     $arguments = array();
     $i = 0;
     foreach ($this->arguments as $argument) {
         if ($argument instanceof Expression) {
             $exprData = $this->processExpression($argument, $platform, $driver);
             $arguments[] = $exprData->getSql();
             $parameterContainer->merge($exprData->getParameterContainer());
         } else {
             $parameterName = 'func_arg_' . $i++;
             $arguments[] = $driver->formatParameterName($parameterName);
             $parameterContainer->offsetSet($parameterName, $argument);
         }
     }
     $sql = sprintf($this->specifications[$this->mode], $function, implode(', ', $arguments), $resultKey);
     $statementContainer->setSql($sql);
 }
Exemple #12
0
 /**
  * Prepare statement
  *
  * @param  AdapterInterface $adapter
  * @param  StatementContainerInterface $statementContainer
  * @return void
  */
 public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer)
 {
     $driver = $adapter->getDriver();
     $platform = $adapter->getPlatform();
     $parameterContainer = $statementContainer->getParameterContainer();
     if (!$parameterContainer instanceof ParameterContainer) {
         $parameterContainer = new ParameterContainer();
         $statementContainer->setParameterContainer($parameterContainer);
     }
     $table = $this->table;
     $table = $platform->quoteIdentifier($table);
     $set = $this->set;
     $setSql = array();
     foreach ($set as $column => $value) {
         if ($value instanceof Predicate\Expression) {
             $exprData = $this->processExpression($value, $platform, $driver);
             $setSql[] = $platform->quoteIdentifier($column) . ' = ' . $exprData->getSql();
             $parameterContainer->merge($exprData->getParameterContainer());
         } else {
             $setSql[] = $platform->quoteIdentifier($column) . ' = ' . $driver->formatParameterName($column);
             $parameterContainer->offsetSet($column, $value);
         }
     }
     $set = implode(', ', $setSql);
     $sql = sprintf($this->specifications[self::SPECIFICATION_UPDATE], $table, $set);
     // Process where
     if ($this->where->count() > 0) {
         $whereParts = $this->processExpression($this->where, $platform, $driver, 'where');
         $parameterContainer->merge($whereParts->getParameterContainer());
         $sql .= ' ' . sprintf($this->specifications[self::SPECIFICATION_WHERE], $whereParts->getSql());
     }
     // Process option
     $optionParts = $this->processOption($platform, $driver, $parameterContainer);
     if (is_array($optionParts)) {
         $sql .= ' ' . $this->createSqlFromSpecificationAndParameters($this->specifications[self::SPECIFICATION_OPTION], $optionParts);
     }
     $statementContainer->setSql($sql);
 }