41 $quote = $this->db->quote;
43 $count = \count ( $this->instances );
44 $modelField = \str_repeat (
' WHEN ? THEN ? ', $count );
46 $keys = \array_keys ( $this->instances );
49 foreach ( $this->instances as $k => $instance ) {
50 $_rest [$k] = $instance->_rest;
55 foreach ( $this->fields as $field ) {
56 $caseFields [] =
"{$quote}{$field}{$quote} = (CASE {$quote}{$pk}{$quote} {$modelField} ELSE {$quote}{$field}{$quote} END)";
57 foreach ( $_rest as $pkv => $_restInstance ) {
64 return "UPDATE {$quote}{$this->tableName}{$quote} SET " . \implode (
',', $caseFields ) .
" WHERE {$quote}{$pk}{$quote} IN (" . \str_repeat (
'?,', $count - 1 ) .
'?)';
68 $quote = $this->db->quote;
69 $fieldCount = \count ( $this->fields );
72 $modelFields =
'(' . \implode (
',', \array_fill ( 0, $fieldCount,
'?' ) ) .
')';
73 foreach ( $this->instances as $instance ) {
75 $values [] = $modelFields;
78 foreach ( $this->fields as $field ) {
79 $duplicateKey [] =
"{$quote}{$field}{$quote} = VALUES({$quote}{$field}{$quote})";
82 return "INSERT INTO {$quote}{$this->tableName}{$quote} (" . $this->insertFields .
') VALUES ' . \implode (
',', $values ) .
' ON DUPLICATE KEY UPDATE ' . \implode (
',', $duplicateKey );
95 $quote = $this->db->quote;
96 $groups = \array_chunk ( $this->instances, $count );
98 $updateTable =
"UPDATE {$quote}{$this->tableName}{$quote} SET ";
99 foreach ( $groups as $group ) {
101 foreach ( $group as $instance ) {
103 $sql .= $updateTable . $this->db->getUpdateFieldsKeyAndValues ( $instance->_rest, $this->fields ) .
' WHERE ' . $this->db->getCondition ( $kv ) .
';';
107 $this->instances = [ ];
108 $this->parameters = [ ];