Skip to content

Commit 850c6a8

Browse files
committed
Add readonly driver property to Options
1 parent bb167ec commit 850c6a8

2 files changed

Lines changed: 24 additions & 20 deletions

File tree

src/Options.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,25 @@ class Options
3232
* The character used to quote identifiers.
3333
*/
3434
public string $identifierQuote = '"';
35+
36+
public function __construct(
37+
public readonly string $driver = '',
38+
) {
39+
if ($this->driver === 'sqlsrv') {
40+
// https://learn.microsoft.com/en-us/sql/sql-server/maximum-capacity-specifications-for-sql-server
41+
$this->maxBoundParams = 2100 - 1;
42+
$this->maxInsertRows = 1000;
43+
$this->affectedIsRowCount = false;
44+
$this->fetchNextSyntax = true;
45+
$this->sqlsrvBinaryEncoding = true;
46+
$this->multiRowset = true;
47+
} elseif ($this->driver === 'mysql') {
48+
$this->lastIdIsFirstOfBatch = true;
49+
$this->identifierQuote = '`'; // needed since not everyone uses ANSI mode
50+
} elseif ($this->driver === 'pgsql') {
51+
$this->binarySelectedAsStream = true;
52+
$this->nativeBoolColumns = true;
53+
$this->floatSelectedAsString = true;
54+
}
55+
}
3556
}

src/PeachySql.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,16 @@ class PeachySql
1616
{
1717
public Options $options;
1818
private PDO $conn;
19-
private bool $usedPrepare;
19+
private bool $usedPrepare = true;
2020

2121
public function __construct(PDO $connection, ?Options $options = null)
2222
{
2323
$this->conn = $connection;
24-
$this->usedPrepare = true;
2524

2625
if ($options === null) {
26+
/** @var string $driver */
2727
$driver = $connection->getAttribute(PDO::ATTR_DRIVER_NAME);
28-
$options = new Options();
29-
30-
if ($driver === 'sqlsrv') {
31-
// https://learn.microsoft.com/en-us/sql/sql-server/maximum-capacity-specifications-for-sql-server
32-
$options->maxBoundParams = 2100 - 1;
33-
$options->maxInsertRows = 1000;
34-
$options->affectedIsRowCount = false;
35-
$options->fetchNextSyntax = true;
36-
$options->sqlsrvBinaryEncoding = true;
37-
$options->multiRowset = true;
38-
} elseif ($driver === 'mysql') {
39-
$options->lastIdIsFirstOfBatch = true;
40-
$options->identifierQuote = '`'; // needed since not everyone uses ANSI mode
41-
} elseif ($driver === 'pgsql') {
42-
$options->binarySelectedAsStream = true;
43-
$options->nativeBoolColumns = true;
44-
$options->floatSelectedAsString = true;
45-
}
28+
$options = new Options($driver);
4629
}
4730

4831
$this->options = $options;

0 commit comments

Comments
 (0)