summaryrefslogtreecommitdiff
path: root/vendor/fguillot/picodb/lib/PicoDb/Builder/UpdateBuilder.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/fguillot/picodb/lib/PicoDb/Builder/UpdateBuilder.php')
-rw-r--r--vendor/fguillot/picodb/lib/PicoDb/Builder/UpdateBuilder.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/vendor/fguillot/picodb/lib/PicoDb/Builder/UpdateBuilder.php b/vendor/fguillot/picodb/lib/PicoDb/Builder/UpdateBuilder.php
new file mode 100644
index 00000000..300ea9b0
--- /dev/null
+++ b/vendor/fguillot/picodb/lib/PicoDb/Builder/UpdateBuilder.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace PicoDb\Builder;
+
+/**
+ * Class UpdateBuilder
+ *
+ * @package PicoDb\Builder
+ * @author Frederic Guillot
+ */
+class UpdateBuilder extends BaseBuilder
+{
+ /**
+ * @var string[]
+ */
+ protected $sumColumns = array();
+
+ /**
+ * Set columns name
+ *
+ * @access public
+ * @param string[] $columns
+ * @return $this
+ */
+ public function withSumColumns(array $columns)
+ {
+ $this->sumColumns = $columns;
+ return $this;
+ }
+
+ /**
+ * Build SQL
+ *
+ * @access public
+ * @return string
+ */
+ public function build()
+ {
+ $columns = array();
+
+ foreach ($this->columns as $column) {
+ $columns[] = $this->db->escapeIdentifier($column).'=?';
+ }
+
+ foreach ($this->sumColumns as $column) {
+ $columns[] = $this->db->escapeIdentifier($column).'='.$this->db->escapeIdentifier($column).' + ?';
+ }
+
+ return sprintf(
+ 'UPDATE %s SET %s %s',
+ $this->db->escapeIdentifier($this->table),
+ implode(', ', $columns),
+ $this->conditionBuilder->build()
+ );
+ }
+}