/
SQLWriteExpression.php
112 lines (106 loc) · 3.04 KB
/
SQLWriteExpression.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Represents a SQL expression which may have field values assigned
* (UPDATE/INSERT Expressions)
*
* @package framework
* @subpackage model
*/
interface SQLWriteExpression {
/**
* Adds assignments for a list of several fields.
*
* For multi-row objects this applies this to the current row.
*
* Note that field values must not be escaped, as these will be internally
* parameterised by the database engine.
*
* <code>
*
* // Basic assignments
* $query->addAssignments(array(
* '"Object"."Title"' => 'Bob',
* '"Object"."Description"' => 'Bob was here'
* ))
*
* // Parameterised assignments
* $query->addAssignments(array(
* '"Object"."Title"' => array('?' => 'Bob')),
* '"Object"."Description"' => array('?' => null))
* ))
*
* // Complex parameters
* $query->addAssignments(array(
* '"Object"."Score"' => array('MAX(?,?)' => array(1, 3))
* ));
*
* // 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())
* ));
*
* </code>
*
* @param array $assignments The list of fields to assign
* @return self Self reference
*/
public function addAssignments(array $assignments);
/**
* Sets the list of assignments to the given list
*
* For multi-row objects this applies this to the current row.
*
* @see SQLWriteExpression::addAssignments() for syntax examples
*
* @param array $assignments
* @return self Self reference
*/
public function setAssignments(array $assignments);
/**
* Retrieves the list of assignments in parameterised format
*
* For multi-row objects returns assignments for the current row.
*
* @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();
/**
* Set the value for a single field
*
* For multi-row objects this applies this to the current row.
*
* E.g.
* <code>
*
* // Literal assignment
* $query->assign('"Object"."Description"', 'lorum ipsum'));
*
* // Single parameter
* $query->assign('"Object"."Title"', array('?' => 'Bob'));
*
* // Complex parameters
* $query->assign('"Object"."Score"', array('MAX(?,?)' => array(1, 3));
* </code>
*
* @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);
/**
* Assigns a value to a field using the literal SQL expression, rather than
* a value to be escaped
*
* For multi-row objects this applies this to the current row.
*
* @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);
}