diff --git a/app/Database/Db2/Db2Connection.php.bak-20261111-095053 b/app/Database/Db2/Db2Connection.php.bak-20261111-095053 deleted file mode 100644 index 41ef160..0000000 --- a/app/Database/Db2/Db2Connection.php.bak-20261111-095053 +++ /dev/null @@ -1,79 +0,0 @@ - $value) { - if ($value === Db2QueryGrammar::NULL_TIMESTAMP_SENTINEL) { - $row->{$key} = null; - continue; - } - - if ( - in_array($key, [ - 'two_factor_secret', - 'two_factor_recovery_codes', - ], true) - && $value === Db2QueryGrammar::NULL_STRING_SENTINEL - ) { - $row->{$key} = null; - } - } - } - - return $rows; - } - - protected function getDefaultQueryGrammar() - { - return new Db2QueryGrammar($this); - } - - protected function getDefaultSchemaGrammar() - { - return new Db2SchemaGrammar($this); - } - - public function getSchemaBuilder() - { - if (is_null($this->schemaGrammar)) { - $this->useDefaultSchemaGrammar(); - } - - return new Db2SchemaBuilder($this); - } - - protected function getDefaultPostProcessor() - { - return new Db2Processor; - } - - -} diff --git a/app/Database/Db2/Db2QueryGrammar.php.bak-20261111-095053 b/app/Database/Db2/Db2QueryGrammar.php.bak-20261111-095053 deleted file mode 100644 index 7723df5..0000000 --- a/app/Database/Db2/Db2QueryGrammar.php.bak-20261111-095053 +++ /dev/null @@ -1,179 +0,0 @@ -columnize($aggregate['columns']); - - if (is_array($query->distinct)) { - $column = 'distinct '.$this->columnize($query->distinct); - } elseif ($query->distinct && $column !== '*') { - $column = 'distinct '.$column; - } - - $function = strtolower($aggregate['function']); - - $expression = "{$function}({$column})"; - - // PDO_ODBC may return Db2 integer aggregates as binary data. - // Cast only the migration batch aggregate to VARCHAR. - if ( - $function === 'max' && - count($aggregate['columns']) === 1 && - $aggregate['columns'][0] === 'batch' && - $query->from === 'migrations' - ) { - $expression = "CAST(COALESCE({$expression}, 0) AS VARCHAR(20))"; - } - - return 'select '.$expression.' as aggregate'; - } - - protected function compileLimit($query, $limit) - { - return 'fetch first '.(int) $limit.' rows only'; - } - - public function compileExists( - \Illuminate\Database\Query\Builder $query - ) { - $select = $this->compileSelect($query); - - return sprintf( - 'SELECT CASE WHEN EXISTS (%s) THEN 1 ELSE 0 END AS "exists" FROM SYSIBM.SYSDUMMY1', - $select - ); - } - - /** A non-NULL value used only for nullable TIMESTAMP result columns. */ - public const NULL_TIMESTAMP_SENTINEL = '__DB2_NULL_TIMESTAMP__'; - - public function compileSelect(\Illuminate\Database\Query\Builder $query) - { - if ( - ! is_string($query->from) || - ! preg_match('/^(?:"[^"]+"|[A-Za-z_][A-Za-z0-9_]*)(?:\.(?:"[^"]+"|[A-Za-z_][A-Za-z0-9_]*))?$/', $query->from) || - ! empty($query->joins) || ! empty($query->unions) || - ! empty($query->groups) || ! empty($query->havings) || - $query->aggregate !== null || $query->distinct - ) { - return parent::compileSelect($query); - } - - $table = $query->from; - if (! isset($this->db2ColumnCache[$table])) { - $this->db2ColumnCache[$table] = $this->connection - ->getSchemaBuilder()->getColumns($table); - } - - $metadata = []; - foreach ($this->db2ColumnCache[$table] as $column) { - $metadata[strtolower($column['name'])] = $column; - } - - $columns = $query->columns ?? ['*']; - if ($columns === ['*']) { - $columns = array_column($this->db2ColumnCache[$table], 'name'); - } - - $ordinary = []; - $lobs = []; - $changed = false; - - foreach ($columns as $column) { - // Expressions and partial wildcards cannot be safely rearranged. - if (! is_string($column) || ! preg_match( - '/^((?:"[^"]+"|[A-Za-z_][A-Za-z0-9_]*)(?:\.(?:"[^"]+"|[A-Za-z_][A-Za-z0-9_]*))?)(?:\s+as\s+("[^"]+"|[A-Za-z_][A-Za-z0-9_]*))?$/i', - $column, $matches - )) { - return parent::compileSelect($query); - } - - $identifier = $matches[1]; - $parts = explode('.', $identifier); - $name = trim(end($parts), '"'); - $info = $metadata[strtolower($name)] ?? null; - if ($info === null) { - return parent::compileSelect($query); - } - - $type = strtoupper($info['type_name']); - $selected = $column; - - // Work around PDO_ODBC attempting a 4 GiB allocation -// when fetching NULL Fortify VARCHAR(4096) columns. - if ( - ($info['nullable'] ?? false) - && $type === 'VARCHAR' - && in_array($name, [ - 'two_factor_secret', - 'two_factor_recovery_codes', - ], true) - ) { - $alias = isset($matches[2]) - ? trim($matches[2], '"') - : $name; - - $wrapped = $this->wrap($identifier); - - $selected = new Expression( - 'COALESCE(' - . $wrapped - . ", CAST('__DB2_NULL_STRING__' AS VARCHAR(4096))) AS " - . $this->wrap($alias) - ); - - $changed = true; - } - - if (($info['nullable'] ?? false) && in_array($type, ['TIMESTAMP', 'DATE', 'TIME'], true)) { - // Never return a SQL NULL date/time to the broken PDO_ODBC - // retrieval path. Use a non-NULL character expression instead. - $format = match ($type) { - 'DATE' => 'YYYY-MM-DD', - 'TIME' => 'HH24:MI:SS', - default => 'YYYY-MM-DD HH24:MI:SS.FF6', - }; - $alias = isset($matches[2]) ? trim($matches[2], '"') : $name; - $wrapped = $this->wrap($identifier); - $selected = new Expression( - 'CASE WHEN '.$wrapped.' IS NULL THEN '. - "'".self::NULL_TIMESTAMP_SENTINEL."'". - ' ELSE VARCHAR_FORMAT('.$wrapped.", '".$format."') END AS ". - $this->wrap($alias) - ); - $changed = true; - } - - if (in_array($type, ['CLOB', 'BLOB', 'DBCLOB'], true)) { - $lobs[] = $selected; - } else { - $ordinary[] = $selected; - } - } - - if ($lobs !== [] && $ordinary !== [] && $columns !== array_merge( - array_filter($ordinary, 'is_string'), - array_filter($lobs, 'is_string') - )) { - $changed = true; - } - - if (! $changed && $lobs === []) { - return parent::compileSelect($query); - } - - $modified = clone $query; - $modified->columns = array_merge($ordinary, $lobs); - return parent::compileSelect($modified); - } -}