silverstripe-framework/model/queries/SQLWriteExpression.php

113 lines
3.0 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* Represents a SQL expression which may have field values assigned
* (UPDATE/INSERT Expressions)
2014-08-15 08:53:05 +02:00
*
* @package framework
* @subpackage model
*/
interface SQLWriteExpression {
2014-08-15 08:53:05 +02:00
/**
* Adds assignments for a list of several fields.
2014-08-15 08:53:05 +02:00
*
* For multi-row objects this applies this to the current row.
2014-08-15 08:53:05 +02:00
*
* Note that field values must not be escaped, as these will be internally
* parameterised by the database engine.
2014-08-15 08:53:05 +02:00
*
* <code>
2014-08-15 08:53:05 +02:00
*
* // Basic assignments
* $query->addAssignments(array(
* '"Object"."Title"' => 'Bob',
* '"Object"."Description"' => 'Bob was here'
* ))
2014-08-15 08:53:05 +02:00
*
* // Parameterised assignments
* $query->addAssignments(array(
* '"Object"."Title"' => array('?' => 'Bob')),
* '"Object"."Description"' => array('?' => null))
* ))
2014-08-15 08:53:05 +02:00
*
* // Complex parameters
* $query->addAssignments(array(
* '"Object"."Score"' => array('MAX(?,?)' => array(1, 3))
* ));
2014-08-15 08:53:05 +02:00
*
* // Assigment of literal SQL for a field. The empty array is
* // important to denote the zero-number paramater list
* $query->addAssignments(array(
* '"Object"."Score"' => array('NOW()' => array())
* ));
2014-08-15 08:53:05 +02:00
*
* </code>
2014-08-15 08:53:05 +02:00
*
* @param array $assignments The list of fields to assign
* @return self Self reference
*/
public function addAssignments(array $assignments);
2014-08-15 08:53:05 +02:00
/**
* Sets the list of assignments to the given list
2014-08-15 08:53:05 +02:00
*
* For multi-row objects this applies this to the current row.
2014-08-15 08:53:05 +02:00
*
* @see SQLWriteExpression::addAssignments() for syntax examples
2014-08-15 08:53:05 +02:00
*
* @param array $assignments
* @return self Self reference
*/
public function setAssignments(array $assignments);
2014-08-15 08:53:05 +02:00
/**
* Retrieves the list of assignments in parameterised format
2014-08-15 08:53:05 +02:00
*
* For multi-row objects returns assignments for the current row.
2014-08-15 08:53:05 +02:00
*
* @return array List of assigments. The key of this array will be the
* column to assign, and the value a parameterised array in the format
* array('SQL' => array(parameters));
*/
public function getAssignments();
2014-08-15 08:53:05 +02:00
/**
* Set the value for a single field
2014-08-15 08:53:05 +02:00
*
* For multi-row objects this applies this to the current row.
2014-08-15 08:53:05 +02:00
*
* E.g.
* <code>
2014-08-15 08:53:05 +02:00
*
* // Literal assignment
* $query->assign('"Object"."Description"', 'lorum ipsum'));
2014-08-15 08:53:05 +02:00
*
* // Single parameter
* $query->assign('"Object"."Title"', array('?' => 'Bob'));
2014-08-15 08:53:05 +02:00
*
* // Complex parameters
* $query->assign('"Object"."Score"', array('MAX(?,?)' => array(1, 3));
* </code>
2014-08-15 08:53:05 +02:00
*
* @param string $field The field name to update
* @param mixed $value The value to assign to this field. This could be an
* array containing a parameterised SQL query of any number of parameters,
* or a single literal value.
* @return self Self reference
*/
public function assign($field, $value);
2014-08-15 08:53:05 +02:00
/**
2014-08-15 08:53:05 +02:00
* Assigns a value to a field using the literal SQL expression, rather than
* a value to be escaped
2014-08-15 08:53:05 +02:00
*
* For multi-row objects this applies this to the current row.
2014-08-15 08:53:05 +02:00
*
* @param string $field The field name to update
* @param string $sql The SQL to use for this update. E.g. "NOW()"
* @return self Self reference
*/
public function assignSQL($field, $sql);
}