Skip to content

Commit 8dac1ac

Browse files
committed
future: support
1 parent 01e9a83 commit 8dac1ac

8 files changed

Lines changed: 207 additions & 163 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
image: 'mysql:5.7'
2020
- name: 'MySQL 8.0'
2121
image: 'mysql:8.0'
22+
- name: 'MySQL 9.0'
23+
image: 'mysql:9.0'
2224
- name: 'MariaDB 10.3'
2325
image: 'mariadb:10.3'
2426
- name: 'MariaDB 10.6'

src/Interface/StatementInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ interface StatementInterface
1919
* @return static
2020
*/
2121
public function execute(array $params = []): static;
22+
23+
/**
24+
* @return void
25+
*/
26+
public function close(): void;
2227
}

src/MySQL/Client.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -768,12 +768,12 @@ protected function sendAuthSwitchResponse(): void
768768
* 一次完整请求流程
769769
* @param string $command
770770
* @param string $query 要发送的数据包
771-
* @param BufferInterface $heap 数据堆, 用于存储响应结果
772-
* @return ResultSet 服务器响应结果
771+
* @param ?BufferInterface $heap 数据堆, 用于存储响应结果
772+
* @return ?ResultSet 服务器响应结果
773773
* @throws ConnectionException
774774
* @throws MySQLException
775775
*/
776-
public function request(string $command, string $query, BufferInterface $heap): ResultSet
776+
public function request(string $command, string $query, ?BufferInterface $heap = null): ?ResultSet
777777
{
778778
try {
779779
// 获得唯一所
@@ -785,7 +785,7 @@ public function request(string $command, string $query, BufferInterface $heap):
785785
// 发送数据包
786786
$this->connection->send("{$command}{$query}");
787787

788-
while (1) {
788+
while ($heap) {
789789
try {
790790
$payload = $this->connection->waitPayload();
791791
} catch (Throwable $e) {
@@ -814,7 +814,7 @@ public function request(string $command, string $query, BufferInterface $heap):
814814
}
815815
}
816816

817-
return new ResultSet($heap);
817+
return $heap ? new ResultSet($heap) : null;
818818
} finally {
819819
$this->mutex->unlock();
820820
}

src/MySQL/Data/Buffer/Statement.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use function is_string;
3737
use function preg_replace_callback;
3838
use function is_int;
39+
use function pack;
3940

4041
class Statement implements BufferInterface, StatementInterface
4142
{
@@ -75,14 +76,14 @@ class Statement implements BufferInterface, StatementInterface
7576
protected OkPacket $okPacket;
7677

7778
/**
78-
* @var ?Binary
79+
* @var array
7980
*/
80-
protected ?Binary $resultSet;
81+
private array $placeholders = [];
8182

8283
/**
83-
* @var array
84+
* @var ?Binary
8485
*/
85-
private array $placeholders = [];
86+
public ?Binary $resultSet;
8687

8788
/**
8889
* @param string $sql
@@ -251,7 +252,7 @@ public function execute(array $params = []): static
251252
}
252253

253254
$correctType = Type::fromValue($value) ?: $this->params[$key]->type;
254-
$header .= Encode::FixedLengthInteger($correctType->value, 2);
255+
$header .= Encode::FixedLengthInteger($correctType->value, 2);
255256
$body .= ProtocolBinary::encode($value, $correctType);
256257
}
257258

@@ -267,6 +268,14 @@ public function execute(array $params = []): static
267268
return $this;
268269
}
269270

271+
/**
272+
* @return void
273+
*/
274+
public function close(): void
275+
{
276+
$this->connection->request("\x19", pack('V', $this->statementOk->stmtId));
277+
}
278+
270279
/**
271280
* @param string $content
272281
* @return void

src/PDO.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class PDO extends PDOAlias
3131
/**
3232
* @var ClientInterface 数据库客户端
3333
*/
34-
private readonly ClientInterface $client;
34+
public readonly ClientInterface $client;
3535

3636
/**
3737
* PDO 构造
@@ -41,10 +41,10 @@ class PDO extends PDOAlias
4141
* @param array|null $options
4242
*/
4343
public function __construct(
44-
private readonly string $dsn,
45-
private readonly ?string $username = null,
46-
private readonly ?string $password = null,
47-
private ?array $options = null
44+
public readonly string $dsn,
45+
public readonly ?string $username = null,
46+
public readonly ?string $password = null,
47+
public ?array $options = []
4848
) {
4949
$config = Config::formString($this->dsn, $this->username, $this->password);
5050
$this->client = match (strtolower($config->driver)) {
@@ -70,7 +70,7 @@ public function __destruct()
7070
*/
7171
public function prepare(string $query, array $options = []): PDOStatementAlias|false
7272
{
73-
return new PDOStatement($this->client->prepare($query), $this->options);
73+
return new PDOStatement($query, fn () => $this);
7474
}
7575

7676
/**
@@ -82,7 +82,7 @@ public function prepare(string $query, array $options = []): PDOStatementAlias|f
8282
*/
8383
public function query(string $query, ?int $fetchMode = null, ...$fetchModeArgs): PDOStatementAlias
8484
{
85-
return new ResultStatement($this->client->query($query), $this->options);
85+
return new PDOStatement($query, fn () => $this, $this->client->query($query));
8686
}
8787

8888
/**
@@ -208,6 +208,7 @@ public function quote(mixed $string, int $type = PDOAlias::PARAM_STR): string|fa
208208
return $string ? '1' : '0';
209209
case PDOAlias::PARAM_STR:
210210
default:
211+
$string = (string)$string;
211212
$escaped = '';
212213
$len = strlen($string);
213214
for ($i = 0; $i < $len; $i++) {
@@ -228,6 +229,7 @@ public function quote(mixed $string, int $type = PDOAlias::PARAM_STR): string|fa
228229
$escaped .= $c;
229230
}
230231
}
232+
231233
return "'$escaped'";
232234
}
233235
}

src/PDOPool.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ public function quote(mixed $string, int $type = PDOAlias::PARAM_STR): string|fa
488488
return $string ? '1' : '0';
489489
case PDOAlias::PARAM_STR:
490490
default:
491+
$string = (string)$string;
491492
$escaped = '';
492493
$len = strlen($string);
493494
for ($i = 0; $i < $len; $i++) {

0 commit comments

Comments
 (0)