-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
159 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,17 +30,26 @@ class Connection | |
private ?SqlPreprocessor $preprocessor; | ||
|
||
/** @var callable(array, ResultSet): array */ | ||
private $rowNormalizer; | ||
private TypeConverter $typeConverter; | ||
Check failure on line 33 in src/Database/Connection.php
|
||
private ?string $sql = null; | ||
private int $transactionDepth = 0; | ||
|
||
|
||
public function __construct( | ||
\Closure|string $connector, | ||
) { | ||
$this->typeConverter = new TypeConverter; | ||
|
||
if (is_string($connector)) { // compatibility with version 3.x | ||
//trigger_error('Passing DSN as string is deprecated, use Nette\Database\Factory::createFromDsn() instead.', E_USER_DEPRECATED); | ||
[$dsn, $user, $password, $options] = func_get_args() + [null, null, null, []]; | ||
|
||
foreach (['convertBoolean', 'convertDateTime', 'convertDecimal'] as $opt) { | ||
if (isset($options[$opt])) { | ||
$this->typeConverter->$opt = (bool) $options[$opt]; | ||
unset($options[$opt]); | ||
} | ||
} | ||
$lazy = $options['lazy'] ?? false; | ||
unset($options['newDateTime'], $options['lazy']); | ||
$this->connector = (new Factory)->createConnectorFromDsn($dsn, $user, $password, $options); | ||
|
@@ -126,10 +135,15 @@ public function getReflection(): Reflection | |
} | ||
|
||
|
||
public function setRowNormalizer(?callable $normalizer): static | ||
public function setRowNormalizer(): static | ||
{ | ||
throw new Nette\DeprecatedException(__METHOD__ . '() is deprecated, use getTypeConverter() instead.'); | ||
} | ||
|
||
|
||
public function getTypeConverter(): TypeConverter | ||
{ | ||
$this->rowNormalizer = $normalizer; | ||
return $this; | ||
return $this->typeConverter; | ||
} | ||
|
||
|
||
|
@@ -213,7 +227,7 @@ public function query(#[Language('SQL')] string $sql, #[Language('GenericSQL')] | |
$time = microtime(true); | ||
$result = $this->connection->query($this->sql, $params); | ||
$time = microtime(true) - $time; | ||
$resultSet = new ResultSet($result, new SqlLiteral($this->sql, $params), $this->rowNormalizer, $time); | ||
$resultSet = new ResultSet($this, $result, new SqlLiteral($this->sql, $params), $time); | ||
} catch (DriverException $e) { | ||
Arrays::invoke($this->onQuery, $this, $e); | ||
throw $e; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.