本文整理汇总了PHP中Driver::buildSQL方法的典型用法代码示例。如果您正苦于以下问题:PHP Driver::buildSQL方法的具体用法?PHP Driver::buildSQL怎么用?PHP Driver::buildSQL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Driver
的用法示例。
在下文中一共展示了Driver::buildSQL方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param Driver $driver
* @param Table $table
* @param Query $query
* @param bool $asArray
*/
public function __construct(Driver $driver, Table $table, Query $query, $asArray = false)
{
$this->asArray = $asArray;
$this->table = $table;
$params = [];
$this->tableName = $table->getName();
if (!$this->asArray) {
$this->recordClasses = [$this->tableName => $table->getDatabase()->getClassMapper()->getClassForRecord($this->tableName)];
}
$sql = $query->getRawSql();
if ($sql === null) {
$sql = $driver->buildSQL($table, $query, $params);
$this->fetchStyle = \PDO::FETCH_NUM;
foreach ($table->getColumns() as $column) {
if ($column->isPrimaryKey()) {
$this->primaryKeyOrdinals[$this->tableName][$column->getOrdinal()] = true;
}
$this->columnOrdinalMap[$this->tableName][$column->getOrdinal()] = $column->getName();
}
$offset = count($table->getColumns());
foreach ($query->getJoins() as $join) {
if (isset($join['cardinality'])) {
$joinedTableName = $join['table'];
$joinedTable = $table->getDatabase()->getTable($joinedTableName);
$this->joinedTables[$joinedTableName] = $joinedTable;
if (!$this->asArray) {
$this->recordClasses[$joinedTableName] = $joinedTable->getDatabase()->getClassMapper()->getClassForRecord($joinedTableName);
}
foreach ($joinedTable->getColumns() as $column) {
if ($column->isPrimaryKey()) {
$this->primaryKeyOrdinals[$joinedTableName][$offset + $column->getOrdinal()] = true;
}
$this->columnOrdinalMap[$joinedTableName][$offset + $column->getOrdinal()] = $column->getName();
}
$this->cardinalities[$joinedTableName] = $join['cardinality'];
if ($join['cardinality'] === Query::CARDINALITY_ONE_TO_MANY) {
$this->properties[$joinedTableName] = $joinedTableName;
} else {
$this->properties[$joinedTableName] = array_keys($join['on']);
}
$offset += count($joinedTable->getColumns());
}
}
} else {
$this->fetchStyle = \PDO::FETCH_ASSOC;
$this->rawSql = true;
}
$this->result = $driver->query($sql, $params);
$this->fetchNextRow();
}