Skip to content

Commit

Permalink
MySQL: supportBooleans renamed to convertBoolean
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 27, 2024
1 parent 9d4432a commit 451b33e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/Database/Drivers/MySqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class MySqlDriver implements Nette\Database\Driver
ERROR_DATA_TRUNCATED = 1265;

private Nette\Database\Connection $connection;
private bool $supportBooleans;
private bool $convertBoolean;


/**
* Driver options:
* - charset => character encoding to set (default is utf8mb4)
* - sqlmode => see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
* - supportBooleans => converts INT(1) to boolean
* - convertBoolean => converts INT(1) to boolean
*/
public function initialize(Nette\Database\Connection $connection, array $options): void
{
Expand All @@ -44,7 +44,7 @@ public function initialize(Nette\Database\Connection $connection, array $options
$connection->query('SET sql_mode=?', $options['sqlmode']);
}

$this->supportBooleans = (bool) ($options['supportBooleans'] ?? false);
$this->convertBoolean = (bool) ($options['convertBoolean'] ?? $options['supportBooleans'] ?? false);
}


Expand Down Expand Up @@ -202,7 +202,7 @@ public function getColumnTypes(\PDOStatement $statement): array
if (isset($meta['native_type'])) {
$types[$meta['name']] = match (true) {
$meta['native_type'] === 'NEWDECIMAL' && $meta['precision'] === 0 => Nette\Database\IStructure::FIELD_INTEGER,
$meta['native_type'] === 'TINY' && $meta['len'] === 1 && $this->supportBooleans => Nette\Database\IStructure::FIELD_BOOL,
$meta['native_type'] === 'TINY' && $meta['len'] === 1 && $this->convertBoolean => Nette\Database\IStructure::FIELD_BOOL,
$meta['native_type'] === 'TIME' => Nette\Database\IStructure::FIELD_TIME_INTERVAL,
default => Nette\Database\Helpers::detectType($meta['native_type']),
};
Expand Down
4 changes: 2 additions & 2 deletions tests/databases.github.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
dsn = "mysql:host=127.0.0.1;port=3306;dbname=nette_test"
username = root
password = root
options[supportBooleans] = yes
options[convertBoolean] = yes
options[newDateTime] = yes

[mysql 8.0]
dsn = "mysql:host=127.0.0.1;port=3307;dbname=nette_test"
username = root
password = root
options[supportBooleans] = yes
options[convertBoolean] = yes
options[newDateTime] = yes

[postgresql 9.6]
Expand Down

0 comments on commit 451b33e

Please sign in to comment.