From 8850598da94c7935026506e1977a707989f8c053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Ratay=20/=20=C5=A0imon=20Rataj?= Date: Tue, 27 Apr 2021 13:52:04 +0200 Subject: [PATCH] Update smysql.php --- smysql.php | 102 ++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/smysql.php b/smysql.php index 0e1f4ed..40bd01b 100644 --- a/smysql.php +++ b/smysql.php @@ -240,40 +240,40 @@ public function changeDB($newDB) { public function select($table, $order = "", $cols = "*", $limit = NULL, $flags = 129, $name = "select") { if(is_array($cols)) { foreach($cols as $k => $v) { - if(gettype($k)!="integer") - $cols[$k] = "`" . $v . "`" . " AS " . "`" . $k . "`"; + if(gettype($k)!="integer") + $cols[$k] = "`" . $v . "`" . " AS " . "`" . $k . "`"; else $cols[$k] = "`" . $v . "`"; - }; + }; $colsValue = implode(", ", $cols); } else $colsValue = strval($cols); - $limitString = ($limit===NULL || $limit==="") ? "" : " LIMIT " . intval($this->escape($limit)); - if(!empty($order)) - $order = " ORDER BY `" . $order . "`" . (boolval($flags & self::ORDER_DESC) ? "DESC" : "ASC"); + $limitString = ($limit===NULL || $limit==="") ? "" : " LIMIT " . intval($this->escape($limit)); + if(!empty($order)) + $order = " ORDER BY `" . $order . "`" . (boolval($flags & self::ORDER_DESC) ? " DESC" : " ASC"); return $this->query(" SELECT $colsValue FROM `$table`$limitString$order ", $flags, $name); } public function selectWhere($table, $cond, $order = "", $cols = "*", $limit = NULL, $flags = 129, $name = "selectWhere") { - $all = !boolval($cond & self::COND_OR); + $all = !boolval($flags & self::COND_OR); if(is_array($cols)) { foreach($cols as $k => $v) { - if(gettype($k)!="integer") - $cols[$k] = "`" . $v . "`" . " AS " . "`" . $k . "`"; + if(gettype($k)!="integer") + $cols[$k] = "`" . $v . "`" . " AS " . "`" . $k . "`"; else $cols[$k] = "`" . $v . "`"; - }; + }; $colsValue = implode(", ", $cols); } else $colsValue = strval($cols); $condString = $this->getCondString($cond, $all); - $limitString = ($limit===NULL || $limit==="") ? "" : " LIMIT " . intval($this->escape($limit)); + $limitString = ($limit===NULL || $limit==="") ? "" : " LIMIT " . intval($this->escape($limit)); if(!empty($order)) - $order = " ORDER BY `" . $order . "`" . (boolval($flags & self::ORDER_DESC) ? "DESC" : "ASC"); + $order = " ORDER BY `" . $order . "`" . (boolval($flags & self::ORDER_DESC) ? " DESC" : " ASC"); return $this->query(" SELECT $colsValue FROM `$table` WHERE $condString$limitString$order ", $flags, $name); @@ -289,19 +289,19 @@ public function selectJoin($table, $join, $on, $order = "", $cols = "*", $limit }; if(is_array($cols)) { foreach($cols as $k => $v) { - if(gettype($k)!="integer") - $cols[$k] = "`" . $v . "`" . " AS " . "`" . $k . "`"; + if(gettype($k)!="integer") + $cols[$k] = "`" . $v . "`" . " AS " . "`" . $k . "`"; else $cols[$k] = "`" . $v . "`"; - }; + }; $colsValue = implode(", ", $cols); } else $colsValue = strval($cols); $onString = $this->getCondString($on, $all, true); - $limitString = ($limit===NULL || $limit==="") ? "" : " LIMIT " . intval($this->escape($limit)); - if(!empty($order)) - $order = " ORDER BY `" . $order . "` " . (boolval($flags & self::ORDER_DESC) ? "DESC" : "ASC"); + $limitString = ($limit===NULL || $limit==="") ? "" : " LIMIT " . intval($this->escape($limit)); + if(!empty($order)) + $order = " ORDER BY `" . $order . "` " . (boolval($flags & self::ORDER_DESC) ? " DESC" : " ASC"); return $this->query(" SELECT $colsValue FROM `$table` @@ -319,20 +319,20 @@ public function selectJoinWhere($table, $join, $on, $cond, $order = "", $cols = }; if(is_array($cols)) { foreach($cols as $k => $v) { - if(gettype($k)!="integer") - $cols[$k] = "`" . $v . "`" . " AS " . "`" . $k . "`"; + if(gettype($k)!="integer") + $cols[$k] = "`" . $v . "`" . " AS " . "`" . $k . "`"; else $cols[$k] = "`" . $v . "`"; - }; + }; $colsValue = implode(", ", $cols); } else $colsValue = strval($cols); $onString = $this->getCondString($on, $all, true); $condString = $this->getCondString($cond, $all); - $limitString = ($limit===NULL || $limit==="") ? "" : " LIMIT " . intval($this->escape($limit)); - if(!empty($order)) - $order = " ORDER BY `" . $order . "` " . (boolval($flags & self::ORDER_DESC) ? "DESC" : "ASC"); + $limitString = ($limit===NULL || $limit==="") ? "" : " LIMIT " . intval($this->escape($limit)); + if(!empty($order)) + $order = " ORDER BY `" . $order . "` " . (boolval($flags & self::ORDER_DESC) ? " DESC" : " ASC"); return $this->query(" SELECT $colsValue FROM `$table` @@ -597,20 +597,20 @@ private function getCondString($a, $and, $on = false) { }; if(!is_numeric($v2)) $v3 = $this->escape($v2); - if(is_numeric($k)) - $r.= $v; - else { - $r.= "`" . $this->escape($k) . "`"; - $r.= " = "; - if(is_numeric($v3)) - $v3 = intval($v3); - if($v3===NULL) - $r.= "IS NULL"; - elseif(is_numeric($v3)) - $r.= $v; - else - $r.= ($on || $col) ? "`$v3`" : "'$v3'"; - }; + if(is_numeric($k)) + $r.= $v; + else { + $r.= "`" . $this->escape($k) . "`"; + $r.= " = "; + if(is_numeric($v3)) + $v3 = intval($v3); + if($v3===NULL) + $r.= "IS NULL"; + elseif(is_numeric($v3)) + $r.= $v; + else + $r.= ($on || $col) ? "`$v3`" : "'$v3'"; + }; $r.= $and ? " AND " : " OR "; }; return rtrim($r, $and ? " AND " : " OR "); @@ -625,18 +625,18 @@ private function getCondString($a, $and, $on = false) { }; if(!is_numeric($v)) $v = $this->escape($v); - if(is_numeric($k)) - $r.= $v; - else { - $r.= "`" . $this->escape($k) . "`"; - $r.= " = "; - if(is_numeric($v)) - $v = intval($v); - if(is_numeric($v)) - $r.= $v; - else - $r.= ($on || $col) ? "`$v`" : "'$v'"; - }; + if(is_numeric($k)) + $r.= $v; + else { + $r.= "`" . $this->escape($k) . "`"; + $r.= " = "; + if(is_numeric($v)) + $v = intval($v); + if(is_numeric($v)) + $r.= $v; + else + $r.= ($on || $col) ? "`$v`" : "'$v'"; + }; $r.= $and ? " AND " : " OR "; }; }; @@ -682,7 +682,7 @@ public function getColumns() { switch($meta['pdo_type']) { case PDO::PARAM_BOOL: $columns[bcsub($i, 1)]->type = "BOOL"; break; case PDO::PARAM_INT: $columns[bcsub($i, 1)]->type = "INT"; break; - case PDO::PARAM_STR: $columns[bcsub($i, 1)]->type = $meta['native_type']=="VAR_STRING" ? "VARCHAR" : "CHAR"; break; + case PDO::PARAM_STR: $columns[bcsub($i, 1)]->type = $meta['native_type']=="VAR_STRING" ? "VARCHAR" : ($meta['native_type']=="LONGLONG" ? "BIGINT" : "CHAR"); break; default: $columns[bcsub($i, 1)]->type = NULL; }; if($meta['native_type']=="TINY")