Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
102 changes: 48 additions & 54 deletions src/Database/Query/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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)
Expand Down Expand Up @@ -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
*/
Expand All @@ -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];
}

Expand All @@ -97,17 +96,19 @@ 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";
}

/**
* Compile an update statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param Builder $query
* @param array $values
* @return string
*/
Expand All @@ -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)
Expand All @@ -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;
}

Expand All @@ -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
*/
Expand All @@ -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;
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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.
*
Expand Down
34 changes: 18 additions & 16 deletions src/Database/Schema/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class Grammar extends IlluminateGrammar
* @var array
*/
protected $modifiers = [
'Increment',
'Nullable',
'Default',
'Increment', 'Nullable', 'Default',
];

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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';
}
}
Expand Down