• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/db/oracledbconnection.php
  • Класс: BitrixMainDBOracleDbConnection
  • Вызов: OracleDbConnection::queryInternal
protected function queryInternal($sql, array $arBinds = null, $offset = 0, $limit = 0, BitrixMainDiagSqlTrackerQuery $trackerQuery = null)
{
	$this->connectInternal();

	$offset = intval($offset);
	$limit = intval($limit);

	if ($offset > 0 && $limit <= 0)
		throw new BitrixMainArgumentException("Limit should be set if offset is set");

	$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 ($limit > 0)
	{
		if (preg_match("#\sROWNUM\W#i", $sql))
			throw new BitrixMainArgumentException("Duplicate limit settings");

		if ($offset <= 0)
		{
			$sql =
				"SELECT * ".
				"FROM (".$sql.") ".
				"WHERE ROWNUM <= ".$limit."";
		}
		else
		{
			$sql =
				"SELECT * ".
				"FROM (".
				"   SELECT rownum_query_alias.*, ROWNUM rownum_alias ".
				"   FROM (".$sql.") rownum_query_alias ".
				"   WHERE ROWNUM <= ".($offset + $limit - 1)." ".
				") ".
				"WHERE rownum_alias >= ".$offset."";
		}
	}

	if ($trackerQuery != null)
		$trackerQuery->startQuery($sql, $arBinds);

	$result = oci_parse($this->resource, $sql);

	if (!$result)
	{
		if ($trackerQuery != null)
			$trackerQuery->finishQuery();

		throw new SqlException("", $this->getErrorMessage());
	}

	$executionMode = $this->transaction;
	$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 SqlException("", $this->getErrorMessage());
	}

	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;
}