Skip to content

Commit d49697b

Browse files
committed
future: support
1 parent 01e9a83 commit d49697b

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

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: 10 additions & 1 deletion
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
{
@@ -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/PDOStatement.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function __construct(private readonly StatementInterface $statement, priv
4444
public function execute(?array $params = []): bool
4545
{
4646
$result = $this->statement->execute(array_merge($this->params, $params));
47+
$this->statement->close();
4748
return $result->rowCount() >= 0;
4849
}
4950

0 commit comments

Comments
 (0)