Skip to content

Commit fb0cffa

Browse files
committed
cs
1 parent 7c4be75 commit fb0cffa

10 files changed

+82
-78
lines changed

src/Database/Driver.php

+30-26
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface Driver
1919
SupportSequence = 'sequence',
2020
SupportSelectUngroupedColumns = 'ungrouped_cols',
2121
SupportMultiInsertAsSelect = 'insert_as_select',
22-
SupportMultiColumnAsOrCond = 'multi_column_as_or',
22+
SupportMultiColumnAsOrCondition = 'multi_column_as_or',
2323
SupportSubselect = 'subselect',
2424
SupportSchema = 'schema';
2525

@@ -32,6 +32,12 @@ interface Driver
3232
SUPPORT_SUBSELECT = 'subselect',
3333
SUPPORT_SCHEMA = 'schema';
3434

35+
/**
36+
* Checks if the engine supports a specific feature.
37+
* @param self::Support* $feature
38+
*/
39+
function isSupported(string $feature): bool;
40+
3541
/**
3642
* Initializes connection.
3743
*/
@@ -42,56 +48,54 @@ function initialize(Connection $connection, array $options): void;
4248
*/
4349
function convertException(\PDOException $e): DriverException;
4450

45-
/**
46-
* Delimites identifier for use in a SQL statement.
47-
*/
51+
/********************* SQL utilities ****************d*g**/
52+
53+
/** Escapes an identifier for use in an SQL statement. */
4854
function delimite(string $name): string;
4955

50-
/**
51-
* Formats date-time for use in a SQL statement.
52-
*/
56+
/** Formats a date-time value for use in an SQL statement. */
5357
function formatDateTime(\DateTimeInterface $value): string;
5458

55-
/**
56-
* Formats date-time interval for use in a SQL statement.
57-
*/
59+
/** Formats a date-time interval for use in an SQL statement. */
5860
function formatDateInterval(\DateInterval $value): string;
5961

60-
/**
61-
* Encodes string for use in a LIKE statement.
62-
*/
62+
/** Encodes string for use in a LIKE statement. */
6363
function formatLike(string $value, int $pos): string;
6464

65-
/**
66-
* Injects LIMIT/OFFSET to the SQL query.
67-
*/
65+
/** Applies LIMIT and OFFSET clauses to an SQL query. */
6866
function applyLimit(string &$sql, ?int $limit, ?int $offset): void;
6967

7068
/********************* reflection ****************d*g**/
7169

72-
/** @return list<array{name: string, fullName: string, view: bool}> */
70+
/**
71+
* Returns a list of all tables in the database.
72+
* @return list<array{name: string, fullName: string, view: bool}>
73+
*/
7374
function getTables(): array;
7475

75-
/** @return list<array{name: string, table: string, nativetype: string, size: int|null, nullable: bool, default: mixed, autoincrement: bool, primary: bool, vendor: array}> */
76+
/**
77+
* Returns detailed information about columns in a table.
78+
* @return list<array{name: string, table: string, nativetype: string, size: int|null, nullable: bool, default: mixed, autoincrement: bool, primary: bool, vendor: array}>
79+
*/
7680
function getColumns(string $table): array;
7781

78-
/** @return list<array{name: string, columns: list<string>, unique: bool, primary: bool}> */
82+
/**
83+
* Returns information about indexes in a table.
84+
* @return list<array{name: string, columns: list<string>, unique: bool, primary: bool}>
85+
*/
7986
function getIndexes(string $table): array;
8087

81-
/** @return list<array{name: string, local: string, table: string, foreign: string}> */
88+
/**
89+
* Returns information about foreign keys in a table.
90+
* @return list<array{name: string, local: string, table: string, foreign: string}>
91+
*/
8292
function getForeignKeys(string $table): array;
8393

8494
/**
8595
* Returns associative array of detected types (IStructure::FIELD_*) in result set.
8696
* @return array<string, string>
8797
*/
8898
function getColumnTypes(\PDOStatement $statement): array;
89-
90-
/**
91-
* Cheks if driver supports specific property
92-
* @param self::Support* $item
93-
*/
94-
function isSupported(string $item): bool;
9599
}
96100

97101

src/Database/Drivers/MsSqlDriver.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public function initialize(Nette\Database\Connection $connection, array $options
2626
}
2727

2828

29+
public function isSupported(string $feature): bool
30+
{
31+
return $feature === self::SupportSubselect;
32+
}
33+
34+
2935
public function convertException(\PDOException $e): Nette\Database\DriverException
3036
{
3137
return Nette\Database\DriverException::from($e);
@@ -216,10 +222,4 @@ public function getColumnTypes(\PDOStatement $statement): array
216222
{
217223
return Nette\Database\Helpers::detectTypes($statement);
218224
}
219-
220-
221-
public function isSupported(string $item): bool
222-
{
223-
return $item === self::SupportSubselect;
224-
}
225225
}

src/Database/Drivers/MySqlDriver.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ public function initialize(Nette\Database\Connection $connection, array $options
4848
}
4949

5050

51+
public function isSupported(string $feature): bool
52+
{
53+
// MULTI_COLUMN_AS_OR_COND due to mysql bugs:
54+
// - http://bugs.mysql.com/bug.php?id=31188
55+
// - http://bugs.mysql.com/bug.php?id=35819
56+
// and more.
57+
return $feature === self::SupportSelectUngroupedColumns || $feature === self::SupportMultiColumnAsOrCondition;
58+
}
59+
60+
5161
public function convertException(\PDOException $e): Nette\Database\DriverException
5262
{
5363
$code = $e->errorInfo[1] ?? null;
@@ -211,14 +221,4 @@ public function getColumnTypes(\PDOStatement $statement): array
211221

212222
return $types;
213223
}
214-
215-
216-
public function isSupported(string $item): bool
217-
{
218-
// MULTI_COLUMN_AS_OR_COND due to mysql bugs:
219-
// - http://bugs.mysql.com/bug.php?id=31188
220-
// - http://bugs.mysql.com/bug.php?id=35819
221-
// and more.
222-
return $item === self::SupportSelectUngroupedColumns || $item === self::SupportMultiColumnAsOrCond;
223-
}
224224
}

src/Database/Drivers/OciDriver.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public function initialize(Nette\Database\Connection $connection, array $options
2828
}
2929

3030

31+
public function isSupported(string $feature): bool
32+
{
33+
return $feature === self::SupportSequence || $feature === self::SupportSubselect;
34+
}
35+
36+
3137
public function convertException(\PDOException $e): Nette\Database\DriverException
3238
{
3339
$code = $e->errorInfo[1] ?? null;
@@ -133,10 +139,4 @@ public function getColumnTypes(\PDOStatement $statement): array
133139
{
134140
return [];
135141
}
136-
137-
138-
public function isSupported(string $item): bool
139-
{
140-
return $item === self::SupportSequence || $item === self::SupportSubselect;
141-
}
142142
}

src/Database/Drivers/OdbcDriver.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public function initialize(Nette\Database\Connection $connection, array $options
2222
}
2323

2424

25+
public function isSupported(string $feature): bool
26+
{
27+
return $feature === self::SupportSubselect;
28+
}
29+
30+
2531
public function convertException(\PDOException $e): Nette\Database\DriverException
2632
{
2733
return Nette\Database\DriverException::from($e);
@@ -104,10 +110,4 @@ public function getColumnTypes(\PDOStatement $statement): array
104110
{
105111
return [];
106112
}
107-
108-
109-
public function isSupported(string $item): bool
110-
{
111-
return $item === self::SupportSubselect;
112-
}
113113
}

src/Database/Drivers/PgSqlDriver.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public function initialize(Nette\Database\Connection $connection, array $options
2626
}
2727

2828

29+
public function isSupported(string $feature): bool
30+
{
31+
return $feature === self::SupportSequence || $feature === self::SupportSubselect || $feature === self::SupportSchema;
32+
}
33+
34+
2935
public function convertException(\PDOException $e): Nette\Database\DriverException
3036
{
3137
$code = $e->errorInfo[0] ?? null;
@@ -244,12 +250,6 @@ public function getColumnTypes(\PDOStatement $statement): array
244250
}
245251

246252

247-
public function isSupported(string $item): bool
248-
{
249-
return $item === self::SupportSequence || $item === self::SupportSubselect || $item === self::SupportSchema;
250-
}
251-
252-
253253
/**
254254
* Converts: schema.name => "schema"."name"
255255
*/

src/Database/Drivers/SqliteDriver.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public function initialize(Nette\Database\Connection $connection, array $options
2828
}
2929

3030

31+
public function isSupported(string $feature): bool
32+
{
33+
return $feature === self::SupportMultiInsertAsSelect || $feature === self::SupportSubselect || $feature === self::SupportMultiColumnAsOrCondition;
34+
}
35+
36+
3137
public function convertException(\PDOException $e): Nette\Database\DriverException
3238
{
3339
$code = $e->errorInfo[1] ?? null;
@@ -243,10 +249,4 @@ public function getColumnTypes(\PDOStatement $statement): array
243249

244250
return $types;
245251
}
246-
247-
248-
public function isSupported(string $item): bool
249-
{
250-
return $item === self::SupportMultiInsertAsSelect || $item === self::SupportSubselect || $item === self::SupportMultiColumnAsOrCond;
251-
}
252252
}

src/Database/Drivers/SqlsrvDriver.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public function initialize(Nette\Database\Connection $connection, array $options
2626
}
2727

2828

29+
public function isSupported(string $feature): bool
30+
{
31+
return $feature === self::SupportSubselect;
32+
}
33+
34+
2935
public function convertException(\PDOException $e): Nette\Database\DriverException
3036
{
3137
return Nette\Database\DriverException::from($e);
@@ -234,10 +240,4 @@ public function getColumnTypes(\PDOStatement $statement): array
234240

235241
return $types;
236242
}
237-
238-
239-
public function isSupported(string $item): bool
240-
{
241-
return $item === self::SupportSubselect;
242-
}
243243
}

src/Database/Table/SqlBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ protected function addConditionComposition(
808808
array &$conditionsParameters,
809809
): bool
810810
{
811-
if ($this->driver->isSupported(Driver::SupportMultiColumnAsOrCond)) {
811+
if ($this->driver->isSupported(Driver::SupportMultiColumnAsOrCondition)) {
812812
$conditionFragment = '(' . implode(' = ? AND ', $columns) . ' = ?) OR ';
813813
$condition = substr(str_repeat($conditionFragment, count($parameters)), 0, -4);
814814
return $this->addCondition($condition, [Nette\Utils\Arrays::flatten($parameters)], $conditions, $conditionsParameters);

src/Database/exceptions.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,39 @@
1111

1212

1313
/**
14-
* Server connection related errors.
14+
* Failed to connect to the database server.
1515
*/
1616
class ConnectionException extends DriverException
1717
{
1818
}
1919

2020

2121
/**
22-
* Base class for all constraint violation related exceptions.
22+
* A database constraint was violated.
2323
*/
2424
class ConstraintViolationException extends DriverException
2525
{
2626
}
2727

2828

2929
/**
30-
* Exception for a foreign key constraint violation.
30+
* The foreign key constraint check failed.
3131
*/
3232
class ForeignKeyConstraintViolationException extends ConstraintViolationException
3333
{
3434
}
3535

3636

3737
/**
38-
* Exception for a NOT NULL constraint violation.
38+
* The NOT NULL constraint check failed.
3939
*/
4040
class NotNullConstraintViolationException extends ConstraintViolationException
4141
{
4242
}
4343

4444

4545
/**
46-
* Exception for a unique constraint violation.
46+
* The unique constraint check failed.
4747
*/
4848
class UniqueConstraintViolationException extends ConstraintViolationException
4949
{

0 commit comments

Comments
 (0)