Skip to content

Commit 59fa8c6

Browse files
committed
Fixed issue amphp#33
1 parent 939f135 commit 59fa8c6

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
],
1616
"require-dev": {
17-
"phpunit/phpunit": "~4.8"
17+
"phpunit/phpunit": "^5"
1818
},
1919
"autoload": {
2020
"psr-4": {

lib/Processor.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function startCommand($callback) {
221221

222222
public function setQuery($query) {
223223
$this->query = $query;
224-
$this->packetCallback = [$this, "handleQuery"];
224+
$this->parseCallback = [$this, "handleQuery"];
225225
}
226226

227227
public function setPrepare($query) {
@@ -322,6 +322,7 @@ public function execute($stmtId, $query, &$params, $prebound, $data = []) {
322322
$this->out[] = null;
323323
$this->deferreds[] = $deferred;
324324
$this->sendPacket($payload);
325+
// apparently LOAD DATA LOCAL INFILE requests are not supported via prepared statements
325326
$this->packetCallback = [$this, "handleExecute"];
326327
});
327328
return $deferred->promise(); // do not use $this->startCommand(), that might unexpectedly reset the seqId!
@@ -543,11 +544,32 @@ private function handleLocalInfileRequest($packet) {
543544

544545
/** @see 14.6.4.1.1 Text Resultset */
545546
private function handleQuery($packet) {
547+
switch (\ord($packet)) {
548+
case self::OK_PACKET:
549+
$this->parseOk($packet);
550+
if ($this->connInfo->statusFlags & StatusFlags::SERVER_MORE_RESULTS_EXISTS) {
551+
$this->getDeferred()->succeed(new ResultSet($this->connInfo, $result = new ResultProxy));
552+
$this->result = $result;
553+
$result->updateState(ResultProxy::COLUMNS_FETCHED);
554+
$this->successfulResultsetFetch();
555+
} else {
556+
$this->getDeferred()->succeed($this->getConnInfo());
557+
$this->ready();
558+
}
559+
return;
560+
case self::LOCAL_INFILE_REQUEST:
561+
$this->handleLocalInfileRequest($packet);
562+
return;
563+
case self::ERR_PACKET:
564+
$this->handleError($packet);
565+
return;
566+
}
567+
546568
$this->parseCallback = [$this, "handleTextColumnDefinition"];
547569
$this->getDeferred()->succeed(new ResultSet($this->connInfo, $result = new ResultProxy));
548570
/* we need to succeed before assigning vars, so that a when() handler won't have a partial result available */
549571
$this->result = $result;
550-
$this->result->setColumns(DataTypes::decodeInt($packet));
572+
$result->setColumns(DataTypes::decodeInt($packet));
551573
}
552574

553575
/** @see 14.7.1 Binary Protocol Resultset */
@@ -556,7 +578,7 @@ private function handleExecute($packet) {
556578
$this->getDeferred()->succeed(new ResultSet($this->connInfo, $result = new ResultProxy));
557579
/* we need to succeed before assigning vars, so that a when() handler won't have a partial result available */
558580
$this->result = $result;
559-
$this->result->setColumns(ord($packet));
581+
$result->setColumns(ord($packet));
560582
}
561583

562584
private function handleFieldList($packet) {
@@ -619,9 +641,9 @@ private function prepareParams($packet) {
619641
private function prepareFields($packet) {
620642
if (!$this->result->columnsToFetch--) {
621643
$this->parseCallback = null;
622-
$this->result->updateState(ResultProxy::COLUMNS_FETCHED);
623644
$this->query = null;
624645
$this->ready();
646+
$this->result->updateState(ResultProxy::COLUMNS_FETCHED);
625647

626648
return;
627649
}
@@ -694,17 +716,17 @@ private function parseColumnDefinition($packet) {
694716
private function successfulResultsetFetch() {
695717
$deferred = &$this->result->next;
696718
if ($this->connInfo->statusFlags & StatusFlags::SERVER_MORE_RESULTS_EXISTS) {
697-
$this->packetCallback = [$this, "handleQuery"];
719+
$this->parseCallback = [$this, "handleQuery"];
698720
$this->deferreds[] = $deferred ?: $deferred = new Deferred;
699721
} else {
700722
if (!$deferred) {
701723
$deferred = new Deferred;
702724
}
703725
$deferred->succeed();
726+
$this->parseCallback = null;
727+
$this->query = null;
728+
$this->ready();
704729
}
705-
$this->parseCallback = null;
706-
$this->query = null;
707-
$this->ready();
708730
$this->result->updateState(ResultProxy::ROWS_FETCHED);
709731
}
710732

@@ -1090,9 +1112,6 @@ private function parsePayload($packet) {
10901112
case self::OK_PACKET:
10911113
$this->handleOk($packet);
10921114
break;
1093-
case self::LOCAL_INFILE_REQUEST:
1094-
$this->handleLocalInfileRequest($packet);
1095-
break;
10961115
case self::ERR_PACKET:
10971116
$this->handleError($packet);
10981117
break;

lib/ResultProxy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ResultProxy {
77
public $columns = [];
88
public $params = [];
99
public $columnsToFetch;
10-
public $rows = null;
10+
public $rows = [];
1111
public $fetchedRows = 0;
1212
public $userFetched = 0;
1313
public $deferreds = [self::SINGLE_ROW_FETCH => [], self::COLUMNS_FETCHED => [], self::ROWS_FETCHED => []];
@@ -53,7 +53,7 @@ public function __debugInfo() {
5353
$tmp = clone $this;
5454
foreach ($tmp->deferreds as &$type) {
5555
foreach ($type as &$entry) {
56-
$entry[2] = null;
56+
unset($entry[0], $entry[2]);
5757
}
5858
}
5959

test/Mysql/ConnectionTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ function testMultiStmt() {
7474

7575
$db->query("DROP TABLE tmp"); // just in case it would exist...
7676
$db->query("CREATE TABLE tmp SELECT 1 AS a, 2 AS b");
77-
$db->query("INSERT INTO tmp VALUES (5, 6), (8, 9)");
7877

79-
$resultset = (yield $db->query("SELECT a FROM tmp; SELECT b FROM tmp WHERE a = 5; SELECT b AS d, a + 1 AS c FROM tmp WHERE b < 7"));
78+
$resultset = (yield $db->query("INSERT INTO tmp VALUES (5, 6), (8, 9); SELECT a FROM tmp; SELECT b FROM tmp WHERE a = 5; SELECT b AS d, a + 1 AS c FROM tmp WHERE b < 7"));
79+
$this->assertEquals((yield $resultset->rowCount()), 0);
80+
81+
$resultset = (yield $resultset->next());
8082
$this->assertEquals((yield $resultset->rowCount()), 3);
8183

8284
$resultset = (yield $resultset->next());

test/phpunit_bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
if (stripos(PHP_OS, "win") === 0) {
1414
shell_exec("Taskkill /PID ".file_get_contents($pidfile)." /F");
1515
} else {
16-
shell_exec("kill -9 `cat '$pidfile'`");
16+
shell_exec("kill -9 `cat '$pidfile'` 2>/dev/null");
1717
}
1818
sleep(1);
1919
}

0 commit comments

Comments
 (0)