Skip to content

Commit

Permalink
cs
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 4, 2024
1 parent cbd089e commit 358388a
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 52 deletions.
14 changes: 8 additions & 6 deletions src/Database/Drivers/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ interface Engine
SupportSubselect = 'subselect',
SupportSchema = 'schema';

/**
* Cheks if driver supports specific property
* @param self::Support* $item
*/
function isSupported(string $item): bool;

/**
* Suggests an appropriate class for the exception.
*/
function determineExceptionClass(DriverException $e): ?string;

/********************* SQL ****************d*g**/

/**
* Delimites identifier for use in a SQL statement.
*/
Expand Down Expand Up @@ -66,10 +74,4 @@ function getIndexes(string $table): array;
function getForeignKeys(string $table): array;

function resolveColumnConverter(array $meta, TypeConverter $converter): ?\Closure;

/**
* Cheks if driver supports specific property
* @param self::Support* $item
*/
function isSupported(string $item): bool;
}
12 changes: 6 additions & 6 deletions src/Database/Drivers/Engines/MSSQLEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public function __construct(
}


public function isSupported(string $item): bool
{
return $item === self::SupportSubselect;
}


public function determineExceptionClass(Nette\Database\DriverException $e): ?string
{
return null;
Expand Down Expand Up @@ -213,10 +219,4 @@ public function resolveColumnConverter(array $meta, TypeConverter $converter): ?
{
return $converter->resolve($meta);
}


public function isSupported(string $item): bool
{
return $item === self::SupportSubselect;
}
}
20 changes: 10 additions & 10 deletions src/Database/Drivers/Engines/MySQLEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public function __construct(
}


public function isSupported(string $item): bool
{
// MULTI_COLUMN_AS_OR_COND due to mysql bugs:
// - http://bugs.mysql.com/bug.php?id=31188
// - http://bugs.mysql.com/bug.php?id=35819
// and more.
return $item === self::SupportSelectUngroupedColumns || $item === self::SupportMultiColumnAsOrCond;
}


public function determineExceptionClass(Nette\Database\DriverException $e): ?string
{
$code = $e->getCode();
Expand Down Expand Up @@ -172,14 +182,4 @@ public function resolveColumnConverter(array $meta, TypeConverter $converter): ?
default => $converter->resolve($meta),
};
}


public function isSupported(string $item): bool
{
// MULTI_COLUMN_AS_OR_COND due to mysql bugs:
// - http://bugs.mysql.com/bug.php?id=31188
// - http://bugs.mysql.com/bug.php?id=35819
// and more.
return $item === self::SupportSelectUngroupedColumns || $item === self::SupportMultiColumnAsOrCond;
}
}
12 changes: 6 additions & 6 deletions src/Database/Drivers/Engines/ODBCEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
*/
class ODBCEngine implements Engine
{
public function isSupported(string $item): bool
{
return $item === self::SupportSubselect;
}


public function determineExceptionClass(Nette\Database\DriverException $e): ?string
{
return null;
Expand Down Expand Up @@ -96,10 +102,4 @@ public function resolveColumnConverter(array $meta, TypeConverter $converter): ?
{
return $converter->resolve($meta);
}


public function isSupported(string $item): bool
{
return $item === self::SupportSubselect;
}
}
12 changes: 6 additions & 6 deletions src/Database/Drivers/Engines/OracleEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public function __construct(
}


public function isSupported(string $item): bool
{
return $item === self::SupportSequence || $item === self::SupportSubselect;
}


public function determineExceptionClass(Nette\Database\DriverException $e): ?string
{
$code = $e->getCode();
Expand Down Expand Up @@ -125,10 +131,4 @@ public function resolveColumnConverter(array $meta, TypeConverter $converter): ?
{
return $converter->resolve($meta);
}


public function isSupported(string $item): bool
{
return $item === self::SupportSequence || $item === self::SupportSubselect;
}
}
12 changes: 6 additions & 6 deletions src/Database/Drivers/Engines/PostgreSQLEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public function __construct(
}


public function isSupported(string $item): bool
{
return $item === self::SupportSequence || $item === self::SupportSubselect || $item === self::SupportSchema;
}


public function determineExceptionClass(Nette\Database\DriverException $e): ?string
{
return match ($e->getSqlState()) {
Expand Down Expand Up @@ -234,12 +240,6 @@ public function resolveColumnConverter(array $meta, TypeConverter $converter): ?
}


public function isSupported(string $item): bool
{
return $item === self::SupportSequence || $item === self::SupportSubselect || $item === self::SupportSchema;
}


/**
* Converts: schema.name => "schema"."name"
*/
Expand Down
12 changes: 6 additions & 6 deletions src/Database/Drivers/Engines/SQLServerEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public function __construct(
}


public function isSupported(string $item): bool
{
return $item === self::SupportSubselect;
}


public function determineExceptionClass(Nette\Database\DriverException $e): ?string
{
return null;
Expand Down Expand Up @@ -224,10 +230,4 @@ public function resolveColumnConverter(array $meta, TypeConverter $converter): ?
default => $converter->resolve($meta),
};
}


public function isSupported(string $item): bool
{
return $item === self::SupportSubselect;
}
}
12 changes: 6 additions & 6 deletions src/Database/Drivers/Engines/SQLiteEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public function __construct(
}


public function isSupported(string $item): bool
{
return $item === self::SupportMultiInsertAsSelect || $item === self::SupportSubselect || $item === self::SupportMultiColumnAsOrCond;
}


public function determineExceptionClass(Nette\Database\DriverException $e): ?string
{
$message = $e->getMessage();
Expand Down Expand Up @@ -232,10 +238,4 @@ public function resolveColumnConverter(array $meta, TypeConverter $converter): ?
? (fn($value): \DateTimeInterface => is_int($value) ? (new DateTime)->setTimestamp($value) : new DateTime($value))
: $converter->resolve($meta);
}


public function isSupported(string $item): bool
{
return $item === self::SupportMultiInsertAsSelect || $item === self::SupportSubselect || $item === self::SupportMultiColumnAsOrCond;
}
}

0 comments on commit 358388a

Please sign in to comment.