Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warningCount to QueryResult #82

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Commands/QueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class QueryCommand extends AbstractCommand
public $fields;
public $insertId;
public $affectedRows;
public $warningCount;

public function getId()
{
Expand Down
3 changes: 3 additions & 0 deletions src/Io/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public function query($sql, array $params = array())
$result = new QueryResult();
$result->resultFields = $command->resultFields;
$result->resultRows = $rows;
$result->warningCount = $command->warningCount;

$rows = array();

$deferred->resolve($result);
Expand All @@ -96,6 +98,7 @@ public function query($sql, array $params = array())
$result = new QueryResult();
$result->affectedRows = $command->affectedRows;
$result->insertId = $command->insertId;
$result->warningCount = $command->warningCount;

$deferred->resolve($result);
});
Expand Down
8 changes: 4 additions & 4 deletions src/Io/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Parser extends EventEmitter

public $seq = 0;

public $warnCount;
public $warningCount;
public $message;

protected $serverVersion;
Expand Down Expand Up @@ -197,11 +197,11 @@ public function parse($data)
$this->affectedRows = $this->buffer->readIntLen();
$this->insertId = $this->buffer->readIntLen();
$this->serverStatus = $this->buffer->readInt2();
$this->warnCount = $this->buffer->readInt2();
$this->warningCount = $this->buffer->readInt2();

$this->message = $this->buffer->read($this->pctSize - $len + $this->buffer->length());

$this->debug(sprintf("AffectedRows: %d, InsertId: %d, WarnCount:%d", $this->affectedRows, $this->insertId, $this->warnCount));
$this->debug(sprintf("AffectedRows: %d, InsertId: %d, WarningCount:%d", $this->affectedRows, $this->insertId, $this->warningCount));
$this->onSuccess();
$this->nextRequest();
} elseif ($fieldCount === 0xFE) {
Expand Down Expand Up @@ -307,7 +307,7 @@ protected function onSuccess()
if ($command instanceof QueryCommand) {
$command->affectedRows = $this->affectedRows;
$command->insertId = $this->insertId;
$command->warnCount = $this->warnCount;
$command->warningCount = $this->warningCount;
$command->message = $this->message;
}
$command->emit('success');
Expand Down
6 changes: 6 additions & 0 deletions src/QueryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ class QueryResult
* @var array|null
*/
public $resultRows;

/**
* number of warnings (if any)
* @var int|null
*/
public $warningCount;
}
23 changes: 23 additions & 0 deletions tests/NoResultQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ public function testUpdateSimpleReportsAffectedRow()
$loop->run();
}

public function testCreateTableAgainWillAddWarning()
{
$loop = \React\EventLoop\Factory::create();
$connection = $this->createConnection($loop);

$sql = '
CREATE TABLE IF NOT EXISTS `book` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`isbn` VARCHAR(255) NULL,
`author` VARCHAR(255) NULL,
`created` INT(11) NULL,
PRIMARY KEY (`id`)
)';

$connection->query($sql)->then(function (QueryResult $command) {
$this->assertEquals(1, $command->warningCount);
});

$connection->quit();
$loop->run();
}

public function testPingMultipleWillBeExecutedInSameOrderTheyAreEnqueuedFromHandlers()
{
$this->expectOutputString('123');
Expand Down