*/
public function getRows(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query) {
$statement = $this->parseQuery($query);
+// debug($statement, -2); // FIXME remove debug code
$result = $this->databaseHandle->sql_query($statement);
$this->checkSqlErrors();
if ($result) {
$statement = 'SELECT ' . implode(',', $sql['fields']) . ' FROM ' . implode(' ', $sql['tables']);
- $this->parseConstraint($query->getConstraint(), $source, $sql, $parameters, $query->getBoundVariableValues());
+ $this->parseConstraint($constraint, $source, $sql, $parameters, $query->getBoundVariableValues());
if (!empty($sql['where'])) {
$statement .= ' WHERE ' . implode('', $sql['where']);
$statement .= ' WHERE ' . implode(' AND ', $sql['additionalWhereClause']);
}
- $this->parseOrderings($query->getOrderings(), $source, $sql, $parameters, $query->getBoundVariableValues());
+ $this->parseOrderings($query->getOrderings(), $source, $sql);
if (!empty($sql['orderings'])) {
$statement .= ' ORDER BY ' . implode(', ', $sql['orderings']);
}
}
$this->replacePlaceholders($statement, $parameters);
-
+ // debug($statement,-2);
return $statement;
}
*
* @param array $properties The properties of the Value Object
* @param Tx_Extbase_Persistence_Mapper_DataMap $dataMap The Data Map
- * @return array The matching tuples
+ * @return array The matching uid
*/
public function hasValueObject(array $properties, Tx_Extbase_Persistence_Mapper_DataMap $dataMap) {
$fields = array();
$parameters = array();
foreach ($properties as $propertyName => $propertyValue) {
- if ($dataMap->isPersistableProperty($propertyName) && ($propertyName !== 'uid')) {
+ // FIXME We couple the Backend to the Entity implementation (uid, isClone); changes there breaks this method
+ if ($dataMap->isPersistableProperty($propertyName) && ($propertyName !== 'uid') && ($propertyName !== 'pid') && ($propertyName !== 'isClone')) {
$fields[] = $dataMap->getColumnMap($propertyName)->getColumnName() . '=?';
$parameters[] = $dataMap->convertPropertyValueToFieldValue($propertyValue);
}
}
- $fields[] = 'deleted!=1';
- $fields[] = 'hidden!=1';
+ $sql = array();
+ $sql['additionalWhereClause'] = array();
- $sqlString = 'SELECT * FROM ' . $dataMap->getTableName() . ' WHERE ' . implode(' AND ', $fields);
- $this->replacePlaceholders($sqlString, $parameters);
- $res = $this->databaseHandle->sql_query($sqlString);
+ $tableName = $dataMap->getTableName();
+ $this->addEnableFieldsStatement($tableName, $sql);
+
+ $statement = 'SELECT * FROM ' . $tableName;
+ $statement .= ' WHERE ' . implode(' AND ', $fields);
+ if (!empty($sql['additionalWhereClause'])) {
+ $statement .= ' AND ' . implode(' AND ', $sql['additionalWhereClause']);
+ }
+ $this->replacePlaceholders($statement, $parameters);
+ $res = $this->databaseHandle->sql_query($statement);
$this->checkSqlErrors();
$row = $this->databaseHandle->sql_fetch_assoc($res);
if ($row !== FALSE) {
}
}
} elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
- $this->parseJoin($query, $source, $sql, $parameters);
+ $this->parseJoin($query, $source, $sql);
}
}
/**
* Transforms a Join into SQL and parameter arrays
*
- * @param Tx_Extbase_Persistence_QOM_QueryObjectModel $query
- * @param Tx_Extbase_Persistence_QOM_JoinInterface $join
- * @param array &$sql
- * @param array &$parameters
+ * @param Tx_Extbase_Persistence_QOM_QueryObjectModel $query The Query Object Model
+ * @param Tx_Extbase_Persistence_QOM_JoinInterface $join The join
+ * @param array &$sql The query parts
* @return void
*/
- protected function parseJoin(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query, Tx_Extbase_Persistence_QOM_JoinInterface $join, array &$sql, array &$parameters) {
+ protected function parseJoin(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query, Tx_Extbase_Persistence_QOM_JoinInterface $join, array &$sql) {
$leftSource = $join->getLeft();
$leftTableName = $leftSource->getSelectorName();
$rightSource = $join->getRight();
$joinCondition = $join->getJoinCondition();
// TODO Check the parsing of the join
if ($joinCondition instanceof Tx_Extbase_Persistence_QOM_EquiJoinCondition) {
+ // TODO Discuss, if we should use $leftSource instead of $selector1Name
$column1Name = $this->dataMapper->convertPropertyNameToColumnName($joinCondition->getProperty1Name(), $leftSource->getNodeTypeName());
$column2Name = $this->dataMapper->convertPropertyNameToColumnName($joinCondition->getProperty2Name(), $rightSource->getNodeTypeName());
$sql['tables'][] = 'ON ' . $joinCondition->getSelector1Name() . '.' . $column1Name . ' = ' . $joinCondition->getSelector2Name() . '.' . $column2Name;
/**
* Transforms a constraint into SQL and parameter arrays
*
- * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint
+ * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint The constraint
* @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
- * @param array &$sql
- * @param array &$parameters
- * @param array $boundVariableValues
+ * @param array &$sql The query parts
+ * @param array &$parameters The parameters that will replace the markers
+ * @param array $boundVariableValues The bound variables in the query (key) and their values (value)
* @return void
*/
protected function parseConstraint(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint = NULL, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters, array $boundVariableValues) {
* @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand
* @param string $operator One of the JCR_OPERATOR_* constants
* @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
- * @param array &$sql SQL query parts to add to
- * @param array &$parameters
- * @param string $valueFunction an aoptional SQL function to apply to the operand value
+ * @param array &$sql The query parts
+ * @param array &$parameters The parameters that will replace the markers
+ * @param string $valueFunction an optional SQL function to apply to the operand value
* @return void
*/
protected function parseDynamicOperand(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand, $operator, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters, $valueFunction = NULL) {
if ($operand instanceof Tx_Extbase_Persistence_QOM_LowerCaseInterface) {
- $this->parseDynamicOperand($operand->getOperand(), $operator, $sql, $parameters, 'LOWER');
+ $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'LOWER');
} elseif ($operand instanceof Tx_Extbase_Persistence_QOM_UpperCaseInterface) {
- $this->parseDynamicOperand($operand->getOperand(), $operator, $sql, $parameters, 'UPPER');
+ $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'UPPER');
} elseif ($operand instanceof Tx_Extbase_Persistence_QOM_PropertyValueInterface) {
$tableName = $operand->getSelectorName();
// FIXME Discuss the translation from propertyName to columnName
if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
- $className = $source->getNodeTypeName();
+ $className = $source->getNodeTypeName();
} else {
$className = '';
}
* Replace query placeholders in a query part by the given
* parameters.
*
- * @param string $queryPart The query part with placeholders
+ * @param string $sqlString The query part with placeholders
* @param array $parameters The parameters
* @return string The query part with replaced placeholders
*/
protected function addEnableFieldsStatement($tableName, array &$sql) {
if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
if (TYPO3_MODE === 'FE') {
- $statement = substr($GLOBALS['TSFE']->sys_page->enableFields($tableName), 5);
+ $statement = $GLOBALS['TSFE']->sys_page->enableFields($tableName);
} else { // TYPO3_MODE === 'BE'
- $statement = substr(t3lib_BEfunc::BEenableFields($tableName), 5);
+ $statement = t3lib_BEfunc::deleteClause($tableName);
+ $statement .= t3lib_BEfunc::BEenableFields($tableName);
}
if(!empty($statement)) {
+ $statement = substr($statement, 5);
$sql['additionalWhereClause'][] = $statement;
}
}
}
/**
- * Transforms orderings into SQL
+ * Transforms orderings into SQL.
*
- * @param array $orderings
- * @param array &$sql
- * @param array &$parameters
- * @param array $boundVariableValues
+ * @param array $orderings Ann array of orderings (Tx_Extbase_Persistence_QOM_Ordering)
+ * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
+ * @param array &$sql The query parts
* @return void
*/
- protected function parseOrderings(array $orderings, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters, array $boundVariableValues) {
+ protected function parseOrderings(array $orderings, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql) {
foreach ($orderings as $ordering) {
$operand = $ordering->getOperand();
$order = $ordering->getOrder();
$order = 'DESC';
break;
default:
- throw new Tx_Extbase_Persistence_Exception('Unsupported order encountered.', 1242816074);
+ throw new Tx_Extbase_Persistence_Exception_UnsupportedOrder('Unsupported order encountered.', 1242816074);
+ }
+ $tableName = $operand->getSelectorName();
+ if ((strlen($tableName) == 0) && (source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface)) {
+ $tableName = $source->getSelectorName();
+ }
+ $columnName = $this->dataMapper->convertPropertyNameToColumnName($operand->getPropertyName(), $tableName);
+ if (strlen($tableName) > 0) {
+ $sql['orderings'][] = $tableName . '.' . $columnName . ' ' . $order;
+ } else {
+ $sql['orderings'][] = $columnName . ' ' . $order;
}
- $columnName = $this->dataMapper->convertPropertyNameToColumnName($ordering->getOperand()->getPropertyName(), $source->getNodeTypeName());
- $sql['orderings'][] = $columnName . ' ' . $order;
}
}
}
* workspace overlay before.
*
* @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source (selector od join)
- *
+ * @param resource &$sql The resource
* @return array The result as an array of rows (tuples)
*/
protected function getRowsFromResult(Tx_Extbase_Persistence_QOM_SourceInterface $source, $res) {