diff --git a/src/MysqlDataType.php b/src/MysqlDataType.php index a31d19d..827caaa 100644 --- a/src/MysqlDataType.php +++ b/src/MysqlDataType.php @@ -163,7 +163,7 @@ public function decodeBinary(string $string, int &$offset = 0, int $flags = 0): default: throw new SqlException("Unexpected string length for date in binary protocol: " . ($length - 1)); } - + $offset += $length; return \str_pad((string) $year, 2, "0", \STR_PAD_LEFT) . "-" . \str_pad((string) $month, 2, "0", \STR_PAD_LEFT) . "-" . \str_pad((string) $day, 2, "0", \STR_PAD_LEFT) @@ -192,7 +192,7 @@ public function decodeBinary(string $string, int &$offset = 0, int $flags = 0): default: throw new SqlException("Unexpected string length for time in binary protocol: " . ($length - 1)); } - + $offset += $length; return ($negative ? "" : "-") . \str_pad((string) $day, 2, "0", \STR_PAD_LEFT) . "d " . \str_pad((string) $hour, 2, "0", \STR_PAD_LEFT) . ":" . \str_pad((string) $minute, 2, "0", \STR_PAD_LEFT) diff --git a/test/LinkTest.php b/test/LinkTest.php index ebda979..de6b684 100644 --- a/test/LinkTest.php +++ b/test/LinkTest.php @@ -145,7 +145,7 @@ public function testPrepared() $stmt = $db->prepare("SELECT * FROM main WHERE a = ? OR b = ?"); $result = $stmt->execute([1, 8]); $this->assertInstanceOf(MysqlResult::class, $result); - $this->assertSame(3, $result->getColumnCount()); + $this->assertSame(4, $result->getColumnCount()); $got = []; foreach ($result as $row) { $got[] = \array_values($row); @@ -155,7 +155,7 @@ public function testPrepared() $stmt = $db->prepare("SELECT * FROM main WHERE a = :a OR b = ?"); $result = $stmt->execute(["a" => 2, 5]); $this->assertInstanceOf(MysqlResult::class, $result); - $this->assertSame(3, $result->getColumnCount()); + $this->assertSame(4, $result->getColumnCount()); $got = []; foreach ($result as $row) { $got[] = \array_values($row); @@ -236,9 +236,9 @@ public function testExecute() $got[] = \array_values($row); } $this->assertCount(2, $got); - $this->assertSame([[2, 2, 3], [4, 4, 5]], $got); + $this->assertSame([[2, 2, 3, '1970-01-01 00:00:00.00000'], [4, 4, 5, '1970-01-01 00:00:00.00000']], $got); - $result = $db->execute("INSERT INTO main (a, b) VALUES (:a, :b)", ["a" => 10, "b" => 11]); + $result = $db->execute("INSERT INTO main (a, b) VALUES (:a, :b)", ["a" => 10, "b" => 11, "c" => '1970-01-01 00:00:00']); $this->assertInstanceOf(MysqlResult::class, $result); $this->assertGreaterThan(5, $result->getLastInsertId()); diff --git a/test/initialize.php b/test/initialize.php index 1754e6b..c5bdab1 100644 --- a/test/initialize.php +++ b/test/initialize.php @@ -6,8 +6,9 @@ function initialize(\mysqli $db): void { $db->query("CREATE DATABASE test"); - $db->query("CREATE TABLE test.main (id INT NOT NULL AUTO_INCREMENT, a INT, b INT, PRIMARY KEY (id))"); - $db->query("INSERT INTO test.main (a, b) VALUES (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)"); + $db->query("CREATE TABLE test.main (id INT NOT NULL AUTO_INCREMENT, a INT, b INT, c DATETIME, PRIMARY KEY (id))"); + $epoch = date('1970-01-01 00:00:00'); + $db->query("INSERT INTO test.main (a, b, c) VALUES (1, 2, '$epoch'), (2, 3, '$epoch'), (3, 4, '$epoch'), (4, 5, '$epoch'), (5, 6, '$epoch')"); $db->query("CREATE TABLE test.json (a JSON)"); $db->query("INSERT INTO test.json VALUES ('{\"key\": \"value\"}')");