Esempio n. 1
0
 /**
  * @param $sql
  * @param array|null $arBinds
  * @param $offset
  * @param $limit
  * @param \Freetrix\Main\Diag\SqlTrackerQuery|null $trackerQuery
  * @return mixed
  * @throws SqlException|\Freetrix\Main\ArgumentException
  */
 protected function queryInternal($sql, array $arBinds = null, $offset = 0, $limit = 0, \Freetrix\Main\Diag\SqlTrackerQuery $trackerQuery = null)
 {
     $this->connectInternal();
     if ($limit > 0) {
         $sql = $this->getSqlHelper()->getTopSql($sql, $limit, $offset);
     }
     if ($trackerQuery != null) {
         $trackerQuery->startQuery($sql, $arBinds);
     }
     $result = sqlsrv_query($this->resource, $sql, array(), array("Scrollable" => 'forward'));
     if ($trackerQuery != null) {
         $trackerQuery->finishQuery();
     }
     $this->lastQueryResult = $result;
     if (!$result) {
         throw new SqlQueryException('MS Sql query error', $this->getErrorMessage(), $sql);
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * @param $sql
  * @param array|null $arBinds
  * @param $offset
  * @param $limit
  * @param \Freetrix\Main\Diag\SqlTrackerQuery|null $trackerQuery
  * @return resource
  * @throws SqlException|\Freetrix\Main\ArgumentException
  */
 protected function queryInternal($sql, array $arBinds = null, $offset = 0, $limit = 0, \Freetrix\Main\Diag\SqlTrackerQuery $trackerQuery = null)
 {
     $this->connectInternal();
     if ($limit > 0) {
         $sql = $this->getSqlHelper()->getTopSql($sql, $limit, $offset);
     }
     if ($trackerQuery != null) {
         $trackerQuery->startQuery($sql, $arBinds);
     }
     $result = mysql_query($sql, $this->resource);
     if ($trackerQuery != null) {
         $trackerQuery->finishQuery();
     }
     $this->lastQueryResult = $result;
     if (!$result) {
         throw new SqlQueryException('Mysql query error', mysql_error($this->resource), $sql);
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * @param $sql
  * @param array|null $arBinds
  * @param $offset
  * @param $limit
  * @param \Freetrix\Main\Diag\SqlTrackerQuery|null $trackerQuery
  * @return \mysqli_result
  * @throws SqlException|\Freetrix\Main\ArgumentException
  */
 protected function queryInternal($sql, array $arBinds = null, $offset = 0, $limit = 0, \Freetrix\Main\Diag\SqlTrackerQuery $trackerQuery = null)
 {
     $this->connectInternal();
     if ($limit > 0) {
         $sql = $this->getSqlHelper()->getTopSql($sql, $limit, $offset);
     }
     if ($trackerQuery != null) {
         $trackerQuery->startQuery($sql, $arBinds);
     }
     /** @var $con \mysqli */
     $con = $this->resource;
     $result = $con->query($sql, MYSQLI_STORE_RESULT);
     if ($trackerQuery != null) {
         $trackerQuery->finishQuery();
     }
     $this->lastQueryResult = $result;
     if (!$result) {
         throw new SqlQueryException('Mysql query error', $this->getErrorMessage(), $sql);
     }
     return $result;
 }
Esempio n. 4
0
 /**
  * @param $sql
  * @param array|null $arBinds
  * @param $offset
  * @param $limit
  * @param \Freetrix\Main\Diag\SqlTrackerQuery|null $trackerQuery
  * @return resource
  * @throws SqlException|\Freetrix\Main\ArgumentException
  */
 protected function queryInternal($sql, array $arBinds = null, $offset = 0, $limit = 0, \Freetrix\Main\Diag\SqlTrackerQuery $trackerQuery = null)
 {
     $this->connectInternal();
     if ($limit > 0) {
         $sql = $this->getSqlHelper()->getTopSql($sql, $limit, $offset);
     }
     $bindsKeys = array();
     if (!empty($arBinds)) {
         $binds1 = $binds2 = "";
         foreach ($arBinds as $key => $value) {
             if (strlen($value) > 0) {
                 if ($binds1 != "") {
                     $binds1 .= ",";
                     $binds2 .= ",";
                 }
                 $bindsKeys[] = $key;
                 $binds1 .= $key;
                 $binds2 .= ":" . $key;
             }
         }
         if ($binds1 != "") {
             $sql .= " RETURNING " . $binds1 . " INTO " . $binds2;
         }
     }
     if ($trackerQuery != null) {
         $trackerQuery->startQuery($sql, $arBinds);
     }
     $result = oci_parse($this->resource, $sql);
     if (!$result) {
         if ($trackerQuery != null) {
             $trackerQuery->finishQuery();
         }
         throw new SqlQueryException("", $this->getErrorMessage(), $sql);
     }
     $executionMode = $this->transaction;
     /** @var \OCI_Lob[] $clob */
     $clob = array();
     if (!empty($arBinds)) {
         $executionMode = OCI_DEFAULT;
         foreach ($bindsKeys as $key) {
             $clob[$key] = oci_new_descriptor($this->resource, OCI_D_LOB);
             oci_bind_by_name($result, ":" . $key, $clob[$key], -1, OCI_B_CLOB);
         }
     }
     if (!oci_execute($result, $executionMode)) {
         if ($trackerQuery != null) {
             $trackerQuery->finishQuery();
         }
         throw new SqlQueryException("", $this->getErrorMessage(), $sql);
     }
     if (!empty($arBinds)) {
         if (oci_num_rows($result) > 0) {
             foreach ($bindsKeys as $key) {
                 $clob[$key]->save($arBinds[$key]);
             }
         }
         if ($this->transaction == OCI_COMMIT_ON_SUCCESS) {
             oci_commit($this->resource);
         }
         foreach ($bindsKeys as $key) {
             $clob[$key]->free();
         }
     }
     if ($trackerQuery != null) {
         $trackerQuery->finishQuery();
     }
     $this->lastQueryResult = $result;
     return $result;
 }