Ejemplo n.º 1
0
 /**
  * @param Query $query
  * @return mixed
  */
 protected function executeQuery(Query $query)
 {
     $stmt = $this->connection->prepare($query->getQueryAsText());
     //        var_dump($query, $params);
     if (!$stmt->execute($query->getValues())) {
         //            echo my_backtrace();
         var_dump($stmt->errorInfo(), $query);
         exit;
     }
     $result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     if (empty($result)) {
         if (preg_match('/^\\s* INSERT \\s+/six', $query)) {
             $result = $this->connection->lastInsertId();
         }
         if (preg_match('/^\\s* DELETE|UPDATE \\s+/six', $query)) {
             $result = $stmt->rowCount();
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * @param Query $query
  * @return mixed
  */
 protected function executeQuery(Query $query)
 {
     $stmt = $this->getPreparedStatement($query->getQueryAsText());
     if ($stmt === false) {
         $errorInfo = $this->connection->errorInfo();
         $this->registerNewError($errorInfo[1], $errorInfo[2]);
         return false;
     }
     if (!$stmt->execute($query->getValues())) {
         $errorInfo = $stmt->errorInfo();
         $this->registerNewError($errorInfo[1], $errorInfo[2]);
         return false;
     }
     $result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     if ($result === false) {
         $errorInfo = $stmt->errorInfo();
         $this->registerNewError($errorInfo[1], $errorInfo[2]);
         return false;
     }
     $this->rowsCountAffected = $stmt->rowCount();
     return $result;
 }
Ejemplo n.º 3
0
 public function getQuery($sql)
 {
     $query = Query::createByArray(func_get_args());
     return $this->transformQuery($query, true)->getQueryAsText();
 }
Ejemplo n.º 4
0
 /**
  * @param Query $query
  * @param bool $isForceExpandValues
  * @return Query
  */
 public function transformQuery(Query $query, $isForceExpandValues = false)
 {
     $this->isForceExpandValues = $isForceExpandValues;
     $this->values = $query->getValues();
     $this->preparedValues = [];
     $this->numberPlaceholder = 0;
     $this->isHookSkipValue = false;
     $transformQueryAsText = preg_replace_callback($this->getRegexpMain(), [$this, 'transformCallback'], $query->getQueryAsText());
     return Query::create($transformQueryAsText, $this->preparedValues);
 }
Ejemplo n.º 5
0
 public function testTransformQuery_CustomAdapterCustomPlaceholderWithCommonNativePlaceholderWithoutExpandValueFewValues()
 {
     $myAdapter = Helper::getMockCustomAdapter();
     $placeholders = new PlaceholderCollection();
     $placeholders->addPlaceholder(Helper::getMockCustomPlaceholder('?m'));
     $transformer = new QueryTransformer($myAdapter, $placeholders);
     $result = $transformer->transformQuery(Query::create('SQL_TEXT ?m, ?m SQL_TEXT', ['in1']), false);
     $this->assertEquals('SQL_TEXT ?, ERROR_NO_VALUE SQL_TEXT', $result->getQueryAsText());
     $this->assertSame(['out1'], $result->getValues());
 }