diff --git a/src/Sql/Predicate/In.php b/src/Sql/Predicate/In.php index 97e5d5b4..c42623e5 100644 --- a/src/Sql/Predicate/In.php +++ b/src/Sql/Predicate/In.php @@ -111,29 +111,22 @@ public function getSQL(DriverInterface $driver = null, Params $params = null): s } $values = []; - $hasNull = false; + $has_null = false; foreach ($this->valueList as $value) { if (null === $value) { - $hasNull = true; + $has_null = true; continue; } $values[] = $this->getValueSQL($params, $value, null, 'in'); } - $ivl_sql = "(" . (empty($values) ? Sql::NULL : implode(", ", $values)) . ")"; + $in_value_list = empty($values) ? Sql::NULL : implode(", ", $values); - $null_sql = ""; - if ($hasNull) { - $null_sql = " " . ( - static::$not - ? Sql::AND . " {$identifier} " . Sql::IS_NOT . " " . Sql::NULL - : Sql::OR . " {$identifier} " . Sql::IS . " " . Sql::NULL - ); - } + $sql = "{$identifier} {$operator} ({$in_value_list})"; - $sql = "{$identifier} {$operator} {$ivl_sql}{$null_sql}"; - if ($hasNull) { - $sql = "({$sql})"; + if ($has_null) { + $null_sql = static::$not ? "AND {$identifier} IS NOT NULL" : "OR {$identifier} IS NULL"; + $sql = "({$sql} {$null_sql})"; } return $this->sql = $sql; diff --git a/src/Sql/Statement/Delete.php b/src/Sql/Statement/Delete.php index fda97da9..da230ed7 100644 --- a/src/Sql/Statement/Delete.php +++ b/src/Sql/Statement/Delete.php @@ -80,8 +80,7 @@ public function getSQL(DriverInterface $driver = null, Params $params = null): s ); } - $this->sql = Sql::DELETE . " " . Sql::FROM . " {$table} {$where_sql}"; - return $this->sql; + return $this->sql = "DELETE FROM {$table} {$where_sql}"; } /** diff --git a/src/Sql/Statement/Insert.php b/src/Sql/Statement/Insert.php index 4310b0a5..bdab6e8f 100644 --- a/src/Sql/Statement/Insert.php +++ b/src/Sql/Statement/Insert.php @@ -334,7 +334,7 @@ public function getSQL(DriverInterface $driver = null, Params $params = null): s protected function generateSQL(DriverInterface $driver, Params $params): string { - $insert = $this->ignore ? Sql::INSERT_IGNORE : Sql::INSERT; + $INSERT = $this->ignore ? Sql::INSERT_IGNORE : Sql::INSERT; $table = $driver->quoteIdentifier($this->table); $columns = $this->getColumnsSQL($driver); $values = $this->getValuesSQL($driver, $params); @@ -351,10 +351,10 @@ protected function generateSQL(DriverInterface $driver, Params $params): string $column_list = empty($columns) ? "" : "{$columns} "; if ($this->select instanceof Select) { - return "{$insert} " . Sql::INTO . " {$table} {$column_list}{$values}"; + return "{$INSERT} INTO {$table} {$column_list}{$values}"; } - return "{$insert} " . Sql::INTO . " {$table} {$column_list}" . Sql::VALUES . " {$values}"; + return "{$INSERT} INTO {$table} {$column_list}VALUES {$values}"; } private function getColumnsSQL(DriverInterface $driver): string diff --git a/src/Sql/Statement/Select.php b/src/Sql/Statement/Select.php index 47c4f863..d98f6059 100644 --- a/src/Sql/Statement/Select.php +++ b/src/Sql/Statement/Select.php @@ -572,10 +572,11 @@ private function getFromSQL(DriverInterface $driver, Params $params, bool $prett } if (!empty($this->alias)) { - $from = trim("{$from} " . $driver->quoteAlias($this->alias)); + $from = "{$from} {$driver->quoteAlias($this->alias)}"; + $from = trim($from); } - return Sql::FROM . " {$from}"; + return "FROM {$from}"; } /** @@ -794,7 +795,9 @@ private function getGroupBySQL(DriverInterface $driver): string $groupBy[$key] = $this->getIdentifierSQL($identifier, $driver); } - $this->sqls['group'] = $sql = Sql::GROUP_BY . " " . implode(", ", $groupBy); + $grouping_element_list = implode(", ", $groupBy); + + $this->sqls['group'] = $sql = "GROUP BY {$grouping_element_list}"; return $sql; } @@ -902,7 +905,9 @@ private function getOrderBySQL(DriverInterface $driver): string $sqls[] = $this->getIdentifierSQL($identifier, $driver) . " {$direction}"; } - $this->sqls['order'] = $sql = Sql::ORDER_BY . " " . implode(", ", $sqls); + $sort_specification_list = implode(", ", $sqls); + + $this->sqls['order'] = $sql = "ORDER BY {$sort_specification_list}"; return $sql; } @@ -955,15 +960,15 @@ private function getLimitSQL(DriverInterface $driver, Params $params): string // PostgreSQL also supports OFFSET without LIMIT if (isset($this->limit)) { $limit = $params->create($this->limit, PDO::PARAM_INT, 'limit'); - $sql = Sql::LIMIT . " {$limit}"; + $sql = "LIMIT {$limit}"; } if (isset($this->offset) && $this->offset > 0) { if (!isset($sql)) { - $sql = Sql::LIMIT . " " . PHP_INT_MAX; + $sql = "LIMIT " . PHP_INT_MAX; } $offset = $params->create($this->offset, PDO::PARAM_INT, 'offset'); - $sql .= " " . Sql::OFFSET . " {$offset}"; + $sql .= " OFFSET {$offset}"; } return $sql ?? ''; @@ -1195,7 +1200,7 @@ public function __get(string $name) } if ('where' === $name) { - if (!isset($this->where)) { + if ($this->where === null) { $this->where = new Where(); $this->where->setParent($this); } @@ -1207,7 +1212,7 @@ public function __get(string $name) } if ('having' === $name) { - if (!isset($this->having)) { + if ($this->having === null) { $this->having = new Having(); $this->having->setParent($this); } diff --git a/src/Sql/Statement/Update.php b/src/Sql/Statement/Update.php index 330c7709..a89d4978 100644 --- a/src/Sql/Statement/Update.php +++ b/src/Sql/Statement/Update.php @@ -161,7 +161,9 @@ private function getBaseSQL(DriverInterface $driver, Params $params): string $set[] = "{$column} = {$marker}"; } - return Sql::UPDATE . " {$table} " . Sql::SET . " " . implode(", ", $set); + $set_clause_list = implode(", ", $set); + + return "UPDATE {$table} SET {$set_clause_list}"; } /** @@ -178,7 +180,7 @@ public function __get(string $name) } if ('where' === $name) { - if (!isset($this->where)) { + if ($this->where === null) { $this->where = new Where(); $this->where->setParent($this); } @@ -191,7 +193,7 @@ public function __get(string $name) public function __clone() { parent::__clone(); - if (isset($this->where)) { + if ($this->where instanceof Where) { $this->where = clone $this->where; $this->where->setParent($this); }