Source for file Preparator.php
Documentation is available at Preparator.php
require_once RDFAPI_INCLUDE_DIR .
'sparql/SparqlEngineDb/Offsetter.php';
* This class takes care of prepared statements:
* Preparing them in the database, replacing
* @author Christian Weiske <cweiske@cweiske.de>
public function __construct(Query $query, ADOConnection $dbConn)
$this->arPrefixes =
$this->query->getPrefixes();
}//public function __construct(Query $query, ADOConnection $dbConn)
* Converts the given queries into sql prepared statments,
* calls the prepare command in the database and returns
* an array consisting of subarrays. They contain
* the db's prepared statement as first value, and an array
* of variable positions as second value (key is the position,
* the sparql variable is the value).
* @param array $arQueries Array of sql queries part arrays
* @param array $arPlaceholders Array of sparql (variable name =>
* placeholder name) pairs
* @return array Array of (prepared statment, variable positions) pairs
public function prepareInDb($arQueries, $arPlaceholders)
$arDbStatements =
array();
foreach ($arQueries as $arQuery) {
if (count($arQueries) ==
1) {
//I currently haven't seens one case in which the count was > 1
//if that happens, we will need to add a fix
$stmt =
$this->dbConn->Prepare($strPrepared);
$arDbStatements[] =
array(
}//public function prepareInDb($arQueries, $arPlaceholders)
* Replaces the placeholders in the given SQL statement with real
* SQL prepared statements placeholders.
* @param string $strQuery SQL query with placeholders
* @param array $arPlaceholders Array of sparql (variable name =>
* placeholder name) pairs
* @return array (prepared sql query string, variable positions) pair
$arVariablePositions =
array();
$this->arTmpVariablePositions =
array();
$this->arTmpPlaceholders =
$arPlaceholders;
'/@\\$%_PLACEHOLDER_[0-9]+_%\\$@/',
array($this, 'replacePlaceholdersCb'),
return array($strQuery, $this->arTmpVariablePositions);
}//protected function replacePlaceholders($strQuery, $arPlaceholders)
* Callback method internally used by replacePlaceholders() method.
$strPlaceholder =
$matches[0];
$strDbPlaceholder =
$this->dbConn->Param($strSparqlVariable);
$this->arTmpVariablePositions[] =
$strSparqlVariable;
return $strDbPlaceholder;
}//protected function replacePlaceholdersCb($matches)
* Executes the given prepared statments, filling the placeholders
* @param array $arDbStatements Return value of prepareInDb()
* @param array $arVariableValues Array of (variable name, value) pairs
* @return array Array of database results as returned by Execute()
public function execute($arDbStatements, $arVariableValues)
$oldmode =
$this->dbConn->SetFetchMode(ADODB_FETCH_ASSOC);
foreach ($arDbStatements as $arStatement) {
list
($stmt, $arVariablePositions) =
$arStatement;
$arResults[] =
$this->dbConn->Execute($stmt, $arVariables);
$this->dbConn->SetFetchMode($oldmode);
}//public function execute($arDbStatements, $arVariableValues)
* Creates an array full of variables to be passed to the Execute() method
* of the database connection object.
* Uses the variable positions array to get the positions of the variables
* in the result array, and the variable value array to get the actual
* values for the prepared statement.
* @param array $arVariablePositions Positions of the variables as returned
* by replacePlaceholders().
* @param array $arVariableValues Array of (variable name, value) pairs
* @return array Array of variable values
foreach ($arVariablePositions as $nPos =>
$strVariable) {
if (!isset
($arVariableValues[$strVariable])) {
throw
new Exception('No value for variable "' .
$strVariable .
'" in prepared statement');
$strValue =
self::replacePrefix(
$arVariableValues[$strVariable],
$arVariables[$nPos] =
$strValue;
}//protected function createVariableArray($arVariablePositions, $arVariableValues)
* Replaces all placeholders with their actual values.
$this->arTmpPlaceholders =
$arPlaceholders;
$this->arTmpVariableValues =
$arVariableValues;
'/@\\$%_PLACEHOLDER_[0-9]+_%\\$@/',
array($this, 'replacePlaceholdersWithVariablesCb'),
}//public function replacePlaceholdersWithVariables($strQuery, $arPlaceholders, $arVariableValues)
* Callback method internally used by
* replacePlaceholdersWithVariables() method.
$strPlaceholder =
$matches[0];
return $this->dbConn->qstr(
$this->arTmpVariableValues[$strSparqlVariable],
}//protected function replacePlaceholdersWithVariablesCb($matches)
if (isset
($arPrefixes[$arParts[0]])) {
$strValue =
$arPrefixes[$arParts[0]] .
$arParts[1];
}//protected static function replacePrefix($strValue, $arPrefixes)
}//class SparqlEngineDb_Preparator
Documentation generated on Fri, 1 Jun 2007 16:50:25 +0200 by phpDocumentor 1.3.2