Skip to content

Commit e7cb4ac

Browse files
committed
enhance: add support for Grammar.php
1 parent 0df0728 commit e7cb4ac

File tree

8 files changed

+56
-133
lines changed

8 files changed

+56
-133
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"require-dev": {
3232
"orchestra/testbench": "*",
3333
"nunomaduro/collision": "*",
34-
"laravel/framework": "12.*"
34+
"laravel/framework": "12.*",
35+
"laravel/pint": "^1.24"
3536
},
3637
"extra": {
3738
"laravel": {

src/Database/Connection.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class Connection extends IlluminateConnection
2020
{
2121
/**
2222
* All types without quotes in Sybase's query.
23-
*
24-
* @var array
2523
*/
2624
private array $numeric = [
2725
'int', 'numeric', 'bigint', 'integer', 'smallint', 'tinyint', 'decimal', 'double', 'float', 'real', 'bit',
@@ -31,7 +29,6 @@ class Connection extends IlluminateConnection
3129
/**
3230
* Execute a Closure within a transaction.
3331
*
34-
* @param Closure $callback
3532
* @param int $attempts
3633
* @return mixed
3734
*
@@ -54,9 +51,9 @@ public function transaction(Closure $callback, $attempts = 1)
5451
$this->pdo->exec('COMMIT TRAN');
5552
}
5653

57-
// If we catch an exception, we will roll back so nothing gets messed
58-
// up in the database. Then we'll re-throw the exception so it can
59-
// be handled how the developer sees fit for their applications.
54+
// If we catch an exception, we will roll back so nothing gets messed
55+
// up in the database. Then we'll re-throw the exception so it can
56+
// be handled how the developer sees fit for their applications.
6057
catch (Exception $e) {
6158
$this->pdo->exec('ROLLBACK TRAN');
6259

@@ -101,7 +98,7 @@ public function select($query, $bindings = [], $useReadPdo = true)
10198
$result = [...$result];
10299

103100
$application_encoding = config('database.sybase.application_encoding');
104-
if (!$application_encoding) {
101+
if (! $application_encoding) {
105102
return $result;
106103
}
107104
$database_charset = config('database.sybase.database_charset');
@@ -129,39 +126,37 @@ public function select($query, $bindings = [], $useReadPdo = true)
129126
*
130127
* @link http://stackoverflow.com/questions/2718628/pdoparam-for-type-decimal
131128
*
132-
* @param string $query
133-
* @param array $bindings
134129
* @return string $query
130+
*
135131
* @throws Exception
136132
*/
137133
private function compileNewQuery(string $query, array $bindings)
138134
{
139135
$bindings = $this->compileBindings($query, $bindings);
140136
$partQuery = explode('?', $query);
141137

142-
$bindings = array_map(fn($v) => gettype($v) === 'string' ? str_replace('\'', '\'\'', $v) : $v, $bindings);
143-
$bindings = array_map(fn($v) => gettype($v) === 'string' ? "'{$v}'" : $v, $bindings);
144-
$bindings = array_map(fn($v) => gettype($v) === 'NULL' ? 'NULL' : $v, $bindings);
138+
$bindings = array_map(fn ($v) => gettype($v) === 'string' ? str_replace('\'', '\'\'', $v) : $v, $bindings);
139+
$bindings = array_map(fn ($v) => gettype($v) === 'string' ? "'{$v}'" : $v, $bindings);
140+
$bindings = array_map(fn ($v) => gettype($v) === 'NULL' ? 'NULL' : $v, $bindings);
145141

146-
$newQuery = join(array_map(fn($k1, $k2) => $k1.$k2, $partQuery, $bindings));
142+
$newQuery = implode(array_map(fn ($k1, $k2) => $k1.$k2, $partQuery, $bindings));
147143
$newQuery = str_replace('[]', '', $newQuery);
148144
$application_encoding = config('database.sybase.application_encoding');
149-
if (!$application_encoding) {
145+
if (! $application_encoding) {
150146
return $newQuery;
151147
}
152148
$database_charset = config('database.sybase.database_charset');
153149
$application_charset = config('database.sybase.application_charset');
154150
if (is_null($database_charset) || is_null($application_charset)) {
155151
throw new Exception('[SYBASE] Database Charset and App Charset not set');
156152
}
153+
157154
return mb_convert_encoding($newQuery, $database_charset, $application_charset);
158155
}
159156

160157
/**
161158
* Set new bindings with specified column types to Sybase.
162159
*
163-
* @param string $query
164-
* @param array $bindings
165160
* @return array $newBinds
166161
*/
167162
private function compileBindings(string $query, array $bindings)
@@ -183,15 +178,14 @@ private function compileBindings(string $query, array $bindings)
183178
/**
184179
* Compile the bindings for select/insert/update/delete.
185180
*
186-
* @param Builder $builder
187181
* @return array
188182
*/
189183
private function compile(Builder $builder)
190184
{
191185
$arrTables = [];
192186

193187
$arrTables[] = $builder->from;
194-
if (!empty($builder->joins)) {
188+
if (! empty($builder->joins)) {
195189
foreach ($builder->joins as $join) {
196190
$arrTables[] = $join->table;
197191
}
@@ -223,7 +217,7 @@ private function compile(Builder $builder)
223217
}
224218

225219
if ($cache) {
226-
$cacheTime = key_exists('cache_time',
220+
$cacheTime = array_key_exists('cache_time',
227221
$builder->connection->config) ? $builder->connection->config['cache_time'] : 3600;
228222
$aux = cache()->remember("sybase_columns.$tables.columns_info", $cacheTime, function () use ($tables) {
229223
$queryString = $this->queryString($tables);
@@ -243,7 +237,7 @@ private function compile(Builder $builder)
243237
$types[strtolower($row['name'])] = $row['type'];
244238
$types[strtolower($tables.'.'.$row['name'])] = $row['type'];
245239

246-
if (!empty($alias['alias'])) {
240+
if (! empty($alias['alias'])) {
247241
$types[strtolower($alias['alias'].'.'.$row['name'])] = $row['type'];
248242
}
249243
}
@@ -312,15 +306,14 @@ private function compile(Builder $builder)
312306
/**
313307
* Query string.
314308
*
315-
* @param string $tables
316309
* @return string
317310
*/
318311
private function queryString(string $tables)
319312
{
320313
$tables = str_replace('..', '.dbo.', $tables);
321314
$explicitDB = explode('.dbo.', $tables);
322315

323-
// Has domain.table
316+
// Has domain.table
324317
if (isset($explicitDB[1])) {
325318
return <<<SQL
326319
SELECT
@@ -451,7 +444,6 @@ protected function getDefaultPostProcessor()
451444
*
452445
* @param string $query
453446
* @param array $bindings
454-
* @param Closure $callback
455447
* @return mixed
456448
*
457449
* @throws QueryException
@@ -469,6 +461,7 @@ protected function runQueryCallback($query, $bindings, Closure $callback)
469461
throw new PDOException($finalErrorMessage, (int) $errorInfo[1]);
470462
}
471463
}
464+
472465
return $result;
473466

474467
} catch (Throwable $e) {

src/Database/Query/Grammar.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public function getBuilder()
3737
/**
3838
* Compile a select query into SQL.
3939
*
40-
* @param Builder $query
4140
* @return string
4241
*/
4342
public function compileSelect(Builder $query)
@@ -69,8 +68,6 @@ public function compileSelect(Builder $query)
6968
/**
7069
* Compile an insert statement into SQL.
7170
*
72-
* @param Builder $query
73-
* @param array $values
7471
* @return string
7572
*/
7673
public function compileInsert(Builder $query, array $values)
@@ -87,7 +84,7 @@ public function compileInsert(Builder $query, array $values)
8784
return "insert into {$table} default values";
8885
}
8986

90-
if (!is_array(reset($values))) {
87+
if (! is_array(reset($values))) {
9188
$values = [$values];
9289
}
9390

@@ -108,8 +105,6 @@ public function compileInsert(Builder $query, array $values)
108105
/**
109106
* Compile an update statement into SQL.
110107
*
111-
* @param Builder $query
112-
* @param array $values
113108
* @return string
114109
*/
115110
public function compileUpdate(Builder $query, array $values)
@@ -132,7 +127,6 @@ public function compileUpdate(Builder $query, array $values)
132127
/**
133128
* Compile a delete statement into SQL.
134129
*
135-
* @param Builder $query
136130
* @return string
137131
*/
138132
public function compileDelete(Builder $query)
@@ -150,7 +144,6 @@ public function compileDelete(Builder $query)
150144
/**
151145
* Compile a truncate table statement into SQL.
152146
*
153-
* @param Builder $query
154147
* @return array
155148
*/
156149
public function compileTruncate(Builder $query)
@@ -173,13 +166,12 @@ public function getDateFormat()
173166
/**
174167
* Compile the "select *" portion of the query.
175168
*
176-
* @param Builder $query
177169
* @param array $columns
178170
* @return string
179171
*/
180172
protected function compileColumns(Builder $query, $columns)
181173
{
182-
if (!is_null($query->aggregate)) {
174+
if (! is_null($query->aggregate)) {
183175
return;
184176
}
185177

@@ -199,7 +191,6 @@ protected function compileColumns(Builder $query, $columns)
199191
/**
200192
* Compile the "from" portion of the query.
201193
*
202-
* @param Builder $query
203194
* @param string $table
204195
* @return string
205196
*/
@@ -211,7 +202,7 @@ protected function compileFrom(Builder $query, $table)
211202
return $from.' '.$query->lock;
212203
}
213204

214-
if (!is_null($query->lock)) {
205+
if (! is_null($query->lock)) {
215206
return $from.' with(rowlock,'.($query->lock ? 'updlock,' : '').'holdlock)';
216207
}
217208

@@ -221,7 +212,6 @@ protected function compileFrom(Builder $query, $table)
221212
/**
222213
* Compile the "limit" portions of the query.
223214
*
224-
* @param Builder $query
225215
* @param int $limit
226216
* @return string
227217
*/
@@ -233,7 +223,6 @@ protected function compileLimit(Builder $query, $limit)
233223
/**
234224
* Compile the "offset" portions of the query.
235225
*
236-
* @param Builder $query
237226
* @param int $offset
238227
* @return string
239228
*/

src/Database/Query/Processor.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public function processIndexes($results)
2929
}
3030

3131
/**
32-
* @param $results
33-
* @param $indexName
3432
* @return array
3533
* Helper function for building index vector
3634
*/

src/Database/Schema/Blueprint.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ class Blueprint extends IlluminateBlueprint
1010
/**
1111
* Function for numeric type.
1212
*
13-
* @param $column
14-
* @param int $total
15-
* @param bool $autoIncrement
1613
* @return ColumnDefinition
1714
*/
1815
public function numeric($column, int $total = 8, bool $autoIncrement = false)

0 commit comments

Comments
 (0)