Skip to content

Commit 990c8ce

Browse files
authored
Merge pull request #105 from uepg/feature/104-compile-table-exists-function-compatible-with-laravel-12
enhance: update composer.json for Laravel 12 compatibility and update…
2 parents ff3c448 + d4625b1 commit 990c8ce

File tree

3 files changed

+70
-75
lines changed

3 files changed

+70
-75
lines changed

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@
2424
"wiki": "https://github.com/uepg/laravel-sybase/wiki"
2525
},
2626
"require": {
27-
"php": ">=8.1",
27+
"php": ">=8.1 | ^8.2",
2828
"doctrine/dbal": "^3.5.1",
29-
"illuminate/database": ">=8.0",
30-
"illuminate/support": ">=8.0",
3129
"ext-pdo": "*"
3230
},
3331
"require-dev": {
34-
"orchestra/testbench": "^8.5",
35-
"nunomaduro/collision": "^7.4"
32+
"orchestra/testbench": "*",
33+
"nunomaduro/collision": "*",
34+
"laravel/framework": "12.*"
3635
},
3736
"extra": {
3837
"laravel": {

src/Database/Query/Grammar.php

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,21 @@ class Grammar extends IlluminateGrammar
1313
* @var array
1414
*/
1515
protected $operators = [
16-
'=', '<', '>', '<=', '>=', '!<', '!>', '<>', '!=',
17-
'like', 'not like', 'between', 'ilike',
18-
'&', '&=', '|', '|=', '^', '^=',
16+
'=', '<', '>', '<=', '>=', '!<', '!>', '<>', '!=', 'like', 'not like', 'between', 'ilike', '&', '&=', '|', '|=',
17+
'^', '^=',
1918
];
2019

2120
/**
2221
* Builder for query.
2322
*
24-
* @var \Illuminate\Database\Query\Builder
23+
* @var Builder
2524
*/
2625
protected $builder;
2726

2827
/**
2928
* Get the builder.
3029
*
31-
* @return \Illuminate\Database\Query\Builder
30+
* @return Builder
3231
*/
3332
public function getBuilder()
3433
{
@@ -38,7 +37,7 @@ public function getBuilder()
3837
/**
3938
* Compile a select query into SQL.
4039
*
41-
* @param \Illuminate\Database\Query\Builder $query
40+
* @param Builder $query
4241
* @return string
4342
*/
4443
public function compileSelect(Builder $query)
@@ -70,7 +69,7 @@ public function compileSelect(Builder $query)
7069
/**
7170
* Compile an insert statement into SQL.
7271
*
73-
* @param \Illuminate\Database\Query\Builder $query
72+
* @param Builder $query
7473
* @param array $values
7574
* @return string
7675
*/
@@ -88,7 +87,7 @@ public function compileInsert(Builder $query, array $values)
8887
return "insert into {$table} default values";
8988
}
9089

91-
if (! is_array(reset($values))) {
90+
if (!is_array(reset($values))) {
9291
$values = [$values];
9392
}
9493

@@ -97,17 +96,19 @@ public function compileInsert(Builder $query, array $values)
9796
// We need to build a list of parameter place-holders of values that are bound
9897
// to the query. Each insert should have the exact same number of parameter
9998
// bindings so we will loop through the record and parameterize them all.
100-
$parameters = collect($values)->map(function ($record) {
101-
return 'SELECT '.$this->parameterize($record);
102-
})->implode(' UNION ALL ');
99+
$parameters = collect($values)
100+
->map(function ($record) {
101+
return 'SELECT '.$this->parameterize($record);
102+
})
103+
->implode(' UNION ALL ');
103104

104105
return "insert into $table ($columns) $parameters";
105106
}
106107

107108
/**
108109
* Compile an update statement into SQL.
109110
*
110-
* @param \Illuminate\Database\Query\Builder $query
111+
* @param Builder $query
111112
* @param array $values
112113
* @return string
113114
*/
@@ -124,17 +125,14 @@ public function compileUpdate(Builder $query, array $values)
124125

125126
$where = $this->compileWheres($query);
126127

127-
return trim(
128-
isset($query->joins)
129-
? $this->compileUpdateWithJoins($query, $table, $columns, $where)
130-
: $this->compileUpdateWithoutJoins($query, $table, $columns, $where)
131-
);
128+
return trim(isset($query->joins) ? $this->compileUpdateWithJoins($query, $table, $columns,
129+
$where) : $this->compileUpdateWithoutJoins($query, $table, $columns, $where));
132130
}
133131

134132
/**
135133
* Compile a delete statement into SQL.
136134
*
137-
* @param \Illuminate\Database\Query\Builder $query
135+
* @param Builder $query
138136
* @return string
139137
*/
140138
public function compileDelete(Builder $query)
@@ -145,23 +143,43 @@ public function compileDelete(Builder $query)
145143

146144
$where = $this->compileWheres($query);
147145

148-
return trim(
149-
isset($query->joins)
150-
? $this->compileDeleteWithJoins($query, $table, $where)
151-
: $this->compileDeleteWithoutJoins($query, $table, $where)
152-
);
146+
return trim(isset($query->joins) ? $this->compileDeleteWithJoins($query, $table,
147+
$where) : $this->compileDeleteWithoutJoins($query, $table, $where));
148+
}
149+
150+
/**
151+
* Compile a truncate table statement into SQL.
152+
*
153+
* @param Builder $query
154+
* @return array
155+
*/
156+
public function compileTruncate(Builder $query)
157+
{
158+
return [
159+
'truncate table '.$this->wrapTable($query->from) => [],
160+
];
161+
}
162+
163+
/**
164+
* Get the format for database stored dates.
165+
*
166+
* @return string
167+
*/
168+
public function getDateFormat()
169+
{
170+
return 'Y-m-d H:i:s.000';
153171
}
154172

155173
/**
156174
* Compile the "select *" portion of the query.
157175
*
158-
* @param \Illuminate\Database\Query\Builder $query
176+
* @param Builder $query
159177
* @param array $columns
160178
* @return string
161179
*/
162180
protected function compileColumns(Builder $query, $columns)
163181
{
164-
if (! is_null($query->aggregate)) {
182+
if (!is_null($query->aggregate)) {
165183
return;
166184
}
167185

@@ -181,7 +199,7 @@ protected function compileColumns(Builder $query, $columns)
181199
/**
182200
* Compile the "from" portion of the query.
183201
*
184-
* @param \Illuminate\Database\Query\Builder $query
202+
* @param Builder $query
185203
* @param string $table
186204
* @return string
187205
*/
@@ -193,9 +211,8 @@ protected function compileFrom(Builder $query, $table)
193211
return $from.' '.$query->lock;
194212
}
195213

196-
if (! is_null($query->lock)) {
197-
return $from.' with(rowlock,'.
198-
($query->lock ? 'updlock,' : '').'holdlock)';
214+
if (!is_null($query->lock)) {
215+
return $from.' with(rowlock,'.($query->lock ? 'updlock,' : '').'holdlock)';
199216
}
200217

201218
return $from;
@@ -204,7 +221,7 @@ protected function compileFrom(Builder $query, $table)
204221
/**
205222
* Compile the "limit" portions of the query.
206223
*
207-
* @param \Illuminate\Database\Query\Builder $query
224+
* @param Builder $query
208225
* @param int $limit
209226
* @return string
210227
*/
@@ -216,7 +233,7 @@ protected function compileLimit(Builder $query, $limit)
216233
/**
217234
* Compile the "offset" portions of the query.
218235
*
219-
* @param \Illuminate\Database\Query\Builder $query
236+
* @param Builder $query
220237
* @param int $offset
221238
* @return string
222239
*/
@@ -229,29 +246,6 @@ protected function compileOffset(Builder $query, $offset)
229246
return '';
230247
}
231248

232-
/**
233-
* Compile a truncate table statement into SQL.
234-
*
235-
* @param \Illuminate\Database\Query\Builder $query
236-
* @return array
237-
*/
238-
public function compileTruncate(Builder $query)
239-
{
240-
return [
241-
'truncate table '.$this->wrapTable($query->from) => [],
242-
];
243-
}
244-
245-
/**
246-
* Get the format for database stored dates.
247-
*
248-
* @return string
249-
*/
250-
public function getDateFormat()
251-
{
252-
return 'Y-m-d H:i:s.000';
253-
}
254-
255249
/**
256250
* Wrap a single string in keyword identifiers.
257251
*

src/Database/Schema/Grammar.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ class Grammar extends IlluminateGrammar
1313
* @var array
1414
*/
1515
protected $modifiers = [
16-
'Increment',
17-
'Nullable',
18-
'Default',
16+
'Increment', 'Nullable', 'Default',
1917
];
2018

2119
/**
@@ -24,19 +22,27 @@ class Grammar extends IlluminateGrammar
2422
* @var array
2523
*/
2624
protected array $serials = [
27-
'bigInteger',
28-
'integer',
29-
'numeric',
25+
'bigInteger', 'integer', 'numeric',
3026
];
3127

3228
/**
3329
* Compile the query to determine if a table exists.
34-
*
30+
* @param string|null $schema
31+
* @param string $table
3532
* @return string
3633
*/
37-
public function compileTableExists()
34+
public function compileTableExists($schema, $table)
3835
{
39-
return "SELECT * FROM sysobjects WHERE type = 'U' AND name = ?";
36+
return sprintf('
37+
SELECT
38+
COUNT(*) AS [exists]
39+
FROM
40+
sysobjects
41+
WHERE
42+
type = \'U\'
43+
AND
44+
name = \'%s\';
45+
', $schema ? $schema.'.'.$table : $table);
4046
}
4147

4248
/**
@@ -277,8 +283,7 @@ public function compileDropColumn(Blueprint $blueprint, Fluent $command)
277283

278284
$table = $this->wrapTable($blueprint);
279285

280-
return 'ALTER TABLE '.$table.
281-
' DROP COLUMN '.implode(', ', $columns);
286+
return 'ALTER TABLE '.$table.' DROP COLUMN '.implode(', ', $columns);
282287
}
283288

284289
/**
@@ -660,7 +665,7 @@ protected function modifyNullable(Blueprint $blueprint, Fluent $column)
660665
*/
661666
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
662667
{
663-
if (! is_null($column->default)) {
668+
if (!is_null($column->default)) {
664669
return ' default '.$this->getDefaultValue($column->default);
665670
}
666671
}
@@ -674,10 +679,7 @@ protected function modifyDefault(Blueprint $blueprint, Fluent $column)
674679
*/
675680
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
676681
{
677-
if (
678-
in_array($column->type, $this->serials) &&
679-
$column->autoIncrement
680-
) {
682+
if (in_array($column->type, $this->serials) && $column->autoIncrement) {
681683
return ' identity primary key';
682684
}
683685
}

0 commit comments

Comments
 (0)