File tree Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -84,19 +84,21 @@ public function addOrUpdate($field, $value) {
84
84
85
85
/**
86
86
* @param string $str
87
+ * @param string ...$params
87
88
* @return $this
88
89
*/
89
90
public function addExpr ($ str ) {
90
- $ this ->fields [] = $ str ;
91
+ $ this ->fields [] = func_get_args () ;
91
92
return $ this ;
92
93
}
93
94
94
95
/**
95
96
* @param string $str
97
+ * @param string ...$params
96
98
* @return $this
97
99
*/
98
100
public function updateExpr ($ str ) {
99
- $ this ->update [] = $ str ;
101
+ $ this ->update [] = func_get_args () ;
100
102
return $ this ;
101
103
}
102
104
@@ -105,8 +107,8 @@ public function updateExpr($str) {
105
107
* @return $this
106
108
*/
107
109
public function addOrUpdateExpr ($ str ) {
108
- $ this ->addExpr ( $ str );
109
- $ this ->updateExpr ( $ str );
110
+ $ this ->fields [] = func_get_args ( );
111
+ $ this ->update [] = func_get_args ( );
110
112
return $ this ;
111
113
}
112
114
@@ -285,4 +287,17 @@ private function clearValues(array $values) {
285
287
286
288
return $ result ;
287
289
}
290
+
291
+ /**
292
+ * @param string $expression
293
+ * @param array $args
294
+ * @return string
295
+ */
296
+ private function formatExtraArgs ($ expression , $ args ) {
297
+ if (count ($ args ) > 1 ) {
298
+ $ args = array_slice ($ args , 1 );
299
+ $ expression = $ this ->db ()->quoteExpression ($ expression , $ args );
300
+ }
301
+ return $ expression ;
302
+ }
288
303
}
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ public function aliasReplacer() {
50
50
}
51
51
52
52
/**
53
- * @return Database
53
+ * @return MySQL
54
54
*/
55
55
protected function db () {
56
56
return $ this ->db ;
Original file line number Diff line number Diff line change @@ -139,4 +139,14 @@ public function testMask() {
139
139
->asString ();
140
140
$ this ->assertEquals ("INSERT INTO \n\ttest \nSET \n\t`field1`='1' \nON DUPLICATE KEY UPDATE \n\t`field1`='1' \n" , $ sql );
141
141
}
142
+
143
+ public function testExprWithParams () {
144
+ $ sql = TestInsert::create ()
145
+ ->into ('test ' )
146
+ ->addExpr ('a=? ' , 'a ' )
147
+ ->updateExpr ('b=? ' , 'b ' )
148
+ ->addOrUpdateExpr ('c=? ' , 'c ' )
149
+ ->asString ();
150
+ $ this ->assertEquals ("INSERT INTO \n\ttest \nSET \n\ta='a', \n\tb='b' \n" , $ sql );
151
+ }
142
152
}
You can’t perform that action at this time.
0 commit comments