summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/sql/src/Update.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:38:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:38:04 +0000
commit1ff5c35de5dbd70a782875a91dd2232fd01b002b (patch)
tree77d9ce5e1bf78b3e6ef79f8f6e7861e2ced3c09b /vendor/ipl/sql/src/Update.php
parentInitial commit. (diff)
downloadicinga-php-library-upstream/0.10.1.tar.xz
icinga-php-library-upstream/0.10.1.zip
Adding upstream version 0.10.1.upstream/0.10.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ipl/sql/src/Update.php')
-rw-r--r--vendor/ipl/sql/src/Update.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/vendor/ipl/sql/src/Update.php b/vendor/ipl/sql/src/Update.php
new file mode 100644
index 0000000..356a610
--- /dev/null
+++ b/vendor/ipl/sql/src/Update.php
@@ -0,0 +1,100 @@
+<?php
+
+namespace ipl\Sql;
+
+use InvalidArgumentException;
+
+use function ipl\Stdlib\arrayval;
+
+/**
+ * SQL UPDATE query
+ */
+class Update implements CommonTableExpressionInterface, WhereInterface
+{
+ use CommonTableExpression;
+ use Where;
+
+ /** @var array|null The table for the UPDATE query */
+ protected $table;
+
+ /** @var array|null The columns to update in terms of column-value pairs */
+ protected $set = [];
+
+ /**
+ * Get the table for the UPDATE query
+ *
+ * @return array|null
+ */
+ public function getTable()
+ {
+ return $this->table;
+ }
+
+ /**
+ * Set the table for the UPDATE query
+ *
+ * Note that this method does NOT quote the table you specify for the UPDATE.
+ * If you allow user input here, you must protected yourself against SQL injection using
+ * {@link Connection::quoteIdentifier()} for the table names passed to this method.
+ * If you are using special table names, e.g. reserved keywords for your DBMS, you are required to use
+ * {@link Connection::quoteIdentifier()} as well.
+ *
+ * @param string|array $table The table to update. The table specification must be in one of the
+ * following formats: 'table', 'table alias', ['alias' => 'table']
+ *
+ * @return $this
+ */
+ public function table($table)
+ {
+ $this->table = is_array($table) ? $table : [$table];
+
+ return $this;
+ }
+
+ /**
+ * Get the columns to update in terms of column-value pairs
+ *
+ * @return array|null
+ */
+ public function getSet()
+ {
+ return $this->set;
+ }
+
+ /**
+ * Set the columns to update in terms of column-value pairs
+ *
+ * Values may either be plain or expressions or scalar subqueries.
+ *
+ * Note that this method does NOT quote the columns you specify for the UPDATE.
+ * If you allow user input here, you must protected yourself against SQL injection using
+ * {@link Connection::quoteIdentifier()} for the column names passed to this method.
+ * If you are using special column names, e.g. reserved keywords for your DBMS, you are required to use
+ * {@link Connection::quoteIdentifier()} as well.
+ *
+ * @param iterable $set Associative set of column-value pairs
+ *
+ * @return $this
+ *
+ * @throws InvalidArgumentException If set type is invalid
+ */
+ public function set($set)
+ {
+ $this->set = arrayval($set);
+
+ return $this;
+ }
+
+ public function __clone()
+ {
+ $this->cloneCte();
+ $this->cloneWhere();
+
+ foreach ($this->set as &$value) {
+ if ($value instanceof ExpressionInterface || $value instanceof Select) {
+ $value = clone $value;
+ }
+ }
+ unset($value);
+ }
+}