From d3937a0f8adf0693d905a214dc91e0c09617eb12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20=28Simon=29=20Rataj?= Date: Thu, 25 Nov 2021 19:45:40 +0100 Subject: [PATCH] Update ssql.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added `->put()` method as a shorthand for `->insert()`, `->update()` and `->delete()` --- ssql.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/ssql.php b/ssql.php index b2d2c78..2af30aa 100644 --- a/ssql.php +++ b/ssql.php @@ -396,7 +396,7 @@ public function truncate(string $table, int $flags = 0) { return $this->query($query, $flags, "truncate"); } - public function insert(string $table, array $values, int $flags = 0) { + public function insert(string $table, array $values, int $flags = 0, string $name = "insert") { $cols = [""]; $useCols = true; foreach($values as $k => $v) { @@ -430,19 +430,19 @@ public function insert(string $table, array $values, int $flags = 0) { }; $r = $this->query(" INSERT INTO {$table}{$colString} VALUES ({$valueString}) - ", $flags, "insert"); + ", $flags, $name); return (boolval($flags & self::INSERT_RETURN_ID) ? $this->connect->lastInsertId() : $r); } - public function delete(string $table, $cond, int $flags = 128) { + public function delete(string $table, $cond, int $flags = 128, string $name = "delete") { $all = !boolval($flags & self::COND_OR); $condString = $this->getCondString($cond, $all); return $this->query(" DELETE FROM `{$table}` WHERE {$condString} - ", $flags, "delete"); + ", $flags, $name); } - public function update(string $table, $cond, array $values, int $flags = 128) { + public function update(string $table, $cond, array $values, int $flags = 128, string $name = "update") { $all = !boolval($flags & self::COND_OR); $condString = $this->getCondString($cond, $all); $string = ""; @@ -461,7 +461,7 @@ public function update(string $table, $cond, array $values, int $flags = 128) { }; return $this->query(" UPDATE `{$table}` SET {$string} WHERE {$condString} - ", $flags, "update"); + ", $flags, $name); } public function add(string $table, string $name, string $type, int $length, bool $null, string $where, string$key, string $data = "", int $flags = 0) { @@ -639,6 +639,18 @@ public function get(string $table, $options = [], int $flags = 4096) { $result = $this->selectJoinWhere($table, $join, $on, $cond, $order, $cols, $limit, $flags | $jointype | $condtype | $ordertype, "get"); return $this->fetch($flags | $fetch); } + + public function put(string $table, $data, $cond = NULL, int $flags = 0) { + if(is_int($cond) && $flags==0) { + $flags = $cond; + $cond = NULL; + }; + if(empty($cond)) + return $this->insert($table, $data, $flags, "put"); + if($data===NULL) + return $this->delete($table, $cond, $flags, "put"); + return $this->update($table, $cond, $data, $flags, "put"); + } public function cond($cond = "") { return new SSQLCond($this, $cond);