From d4625b17abeb8218c3911969fa366bbe9415652c Mon Sep 17 00:00:00 2001 From: Daniel Chaves Date: Thu, 28 Aug 2025 15:16:54 -0300 Subject: [PATCH] enhance: update composer.json for Laravel 12 compatibility and update Grammar method compileTableExists --- composer.json | 9 ++- src/Database/Query/Grammar.php | 102 +++++++++++++++----------------- src/Database/Schema/Grammar.php | 34 ++++++----- 3 files changed, 70 insertions(+), 75 deletions(-) diff --git a/composer.json b/composer.json index 9014b9e..e1ff621 100644 --- a/composer.json +++ b/composer.json @@ -24,15 +24,14 @@ "wiki": "https://github.com/uepg/laravel-sybase/wiki" }, "require": { - "php": ">=8.1", + "php": ">=8.1 | ^8.2", "doctrine/dbal": "^3.5.1", - "illuminate/database": ">=8.0", - "illuminate/support": ">=8.0", "ext-pdo": "*" }, "require-dev": { - "orchestra/testbench": "^8.5", - "nunomaduro/collision": "^7.4" + "orchestra/testbench": "*", + "nunomaduro/collision": "*", + "laravel/framework": "12.*" }, "extra": { "laravel": { diff --git a/src/Database/Query/Grammar.php b/src/Database/Query/Grammar.php index b743c2c..2ab8fe4 100644 --- a/src/Database/Query/Grammar.php +++ b/src/Database/Query/Grammar.php @@ -13,22 +13,21 @@ class Grammar extends IlluminateGrammar * @var array */ protected $operators = [ - '=', '<', '>', '<=', '>=', '!<', '!>', '<>', '!=', - 'like', 'not like', 'between', 'ilike', - '&', '&=', '|', '|=', '^', '^=', + '=', '<', '>', '<=', '>=', '!<', '!>', '<>', '!=', 'like', 'not like', 'between', 'ilike', '&', '&=', '|', '|=', + '^', '^=', ]; /** * Builder for query. * - * @var \Illuminate\Database\Query\Builder + * @var Builder */ protected $builder; /** * Get the builder. * - * @return \Illuminate\Database\Query\Builder + * @return Builder */ public function getBuilder() { @@ -38,7 +37,7 @@ public function getBuilder() /** * Compile a select query into SQL. * - * @param \Illuminate\Database\Query\Builder $query + * @param Builder $query * @return string */ public function compileSelect(Builder $query) @@ -70,7 +69,7 @@ public function compileSelect(Builder $query) /** * Compile an insert statement into SQL. * - * @param \Illuminate\Database\Query\Builder $query + * @param Builder $query * @param array $values * @return string */ @@ -88,7 +87,7 @@ public function compileInsert(Builder $query, array $values) return "insert into {$table} default values"; } - if (! is_array(reset($values))) { + if (!is_array(reset($values))) { $values = [$values]; } @@ -97,9 +96,11 @@ public function compileInsert(Builder $query, array $values) // We need to build a list of parameter place-holders of values that are bound // to the query. Each insert should have the exact same number of parameter // bindings so we will loop through the record and parameterize them all. - $parameters = collect($values)->map(function ($record) { - return 'SELECT '.$this->parameterize($record); - })->implode(' UNION ALL '); + $parameters = collect($values) + ->map(function ($record) { + return 'SELECT '.$this->parameterize($record); + }) + ->implode(' UNION ALL '); return "insert into $table ($columns) $parameters"; } @@ -107,7 +108,7 @@ public function compileInsert(Builder $query, array $values) /** * Compile an update statement into SQL. * - * @param \Illuminate\Database\Query\Builder $query + * @param Builder $query * @param array $values * @return string */ @@ -124,17 +125,14 @@ public function compileUpdate(Builder $query, array $values) $where = $this->compileWheres($query); - return trim( - isset($query->joins) - ? $this->compileUpdateWithJoins($query, $table, $columns, $where) - : $this->compileUpdateWithoutJoins($query, $table, $columns, $where) - ); + return trim(isset($query->joins) ? $this->compileUpdateWithJoins($query, $table, $columns, + $where) : $this->compileUpdateWithoutJoins($query, $table, $columns, $where)); } /** * Compile a delete statement into SQL. * - * @param \Illuminate\Database\Query\Builder $query + * @param Builder $query * @return string */ public function compileDelete(Builder $query) @@ -145,23 +143,43 @@ public function compileDelete(Builder $query) $where = $this->compileWheres($query); - return trim( - isset($query->joins) - ? $this->compileDeleteWithJoins($query, $table, $where) - : $this->compileDeleteWithoutJoins($query, $table, $where) - ); + return trim(isset($query->joins) ? $this->compileDeleteWithJoins($query, $table, + $where) : $this->compileDeleteWithoutJoins($query, $table, $where)); + } + + /** + * Compile a truncate table statement into SQL. + * + * @param Builder $query + * @return array + */ + public function compileTruncate(Builder $query) + { + return [ + 'truncate table '.$this->wrapTable($query->from) => [], + ]; + } + + /** + * Get the format for database stored dates. + * + * @return string + */ + public function getDateFormat() + { + return 'Y-m-d H:i:s.000'; } /** * Compile the "select *" portion of the query. * - * @param \Illuminate\Database\Query\Builder $query + * @param Builder $query * @param array $columns * @return string */ protected function compileColumns(Builder $query, $columns) { - if (! is_null($query->aggregate)) { + if (!is_null($query->aggregate)) { return; } @@ -181,7 +199,7 @@ protected function compileColumns(Builder $query, $columns) /** * Compile the "from" portion of the query. * - * @param \Illuminate\Database\Query\Builder $query + * @param Builder $query * @param string $table * @return string */ @@ -193,9 +211,8 @@ protected function compileFrom(Builder $query, $table) return $from.' '.$query->lock; } - if (! is_null($query->lock)) { - return $from.' with(rowlock,'. - ($query->lock ? 'updlock,' : '').'holdlock)'; + if (!is_null($query->lock)) { + return $from.' with(rowlock,'.($query->lock ? 'updlock,' : '').'holdlock)'; } return $from; @@ -204,7 +221,7 @@ protected function compileFrom(Builder $query, $table) /** * Compile the "limit" portions of the query. * - * @param \Illuminate\Database\Query\Builder $query + * @param Builder $query * @param int $limit * @return string */ @@ -216,7 +233,7 @@ protected function compileLimit(Builder $query, $limit) /** * Compile the "offset" portions of the query. * - * @param \Illuminate\Database\Query\Builder $query + * @param Builder $query * @param int $offset * @return string */ @@ -229,29 +246,6 @@ protected function compileOffset(Builder $query, $offset) return ''; } - /** - * Compile a truncate table statement into SQL. - * - * @param \Illuminate\Database\Query\Builder $query - * @return array - */ - public function compileTruncate(Builder $query) - { - return [ - 'truncate table '.$this->wrapTable($query->from) => [], - ]; - } - - /** - * Get the format for database stored dates. - * - * @return string - */ - public function getDateFormat() - { - return 'Y-m-d H:i:s.000'; - } - /** * Wrap a single string in keyword identifiers. * diff --git a/src/Database/Schema/Grammar.php b/src/Database/Schema/Grammar.php index 764b57f..6f20482 100644 --- a/src/Database/Schema/Grammar.php +++ b/src/Database/Schema/Grammar.php @@ -13,9 +13,7 @@ class Grammar extends IlluminateGrammar * @var array */ protected $modifiers = [ - 'Increment', - 'Nullable', - 'Default', + 'Increment', 'Nullable', 'Default', ]; /** @@ -24,19 +22,27 @@ class Grammar extends IlluminateGrammar * @var array */ protected array $serials = [ - 'bigInteger', - 'integer', - 'numeric', + 'bigInteger', 'integer', 'numeric', ]; /** * Compile the query to determine if a table exists. - * + * @param string|null $schema + * @param string $table * @return string */ - public function compileTableExists() + public function compileTableExists($schema, $table) { - return "SELECT * FROM sysobjects WHERE type = 'U' AND name = ?"; + return sprintf(' + SELECT + COUNT(*) AS [exists] + FROM + sysobjects + WHERE + type = \'U\' + AND + name = \'%s\'; + ', $schema ? $schema.'.'.$table : $table); } /** @@ -277,8 +283,7 @@ public function compileDropColumn(Blueprint $blueprint, Fluent $command) $table = $this->wrapTable($blueprint); - return 'ALTER TABLE '.$table. - ' DROP COLUMN '.implode(', ', $columns); + return 'ALTER TABLE '.$table.' DROP COLUMN '.implode(', ', $columns); } /** @@ -660,7 +665,7 @@ protected function modifyNullable(Blueprint $blueprint, Fluent $column) */ protected function modifyDefault(Blueprint $blueprint, Fluent $column) { - if (! is_null($column->default)) { + if (!is_null($column->default)) { return ' default '.$this->getDefaultValue($column->default); } } @@ -674,10 +679,7 @@ protected function modifyDefault(Blueprint $blueprint, Fluent $column) */ protected function modifyIncrement(Blueprint $blueprint, Fluent $column) { - if ( - in_array($column->type, $this->serials) && - $column->autoIncrement - ) { + if (in_array($column->type, $this->serials) && $column->autoIncrement) { return ' identity primary key'; } }