Skip to content

mysqlnd: Fractional seconds truncated in prepared statements, if value of decimals is AUTO_SEC_PART_DIGITS (=39). #16910

Open
@9EOR9

Description

@9EOR9

Description

This issue was initially reported for MariaDB Connector/C (which uses part of mysqlnd):

In some cases both MySQL and MariaDB server will send the value 39 (=AUTO_SEC_PART_DIGITS) for datetime and time decimals. The binary protocol implementation however will only set fractional seconds if decimals is <= 6.

The following code:

<?php

$link= mysqli_connect("localhost", "georg", null, "test", 0, "/tmp/mysql.sock");

$stmt = $link->prepare("select FROM_UNIXTIME('1992.1'), FROM_UNIXTIME('1992.0')");
$stmt->execute();
$stmt->bind_result($binval[0],$binval[1]);
$stmt->fetch();
$stmt->close();

$result = $link->query("select FROM_UNIXTIME('1992.1'), FROM_UNIXTIME('1992.0')");
$txtval = $result->fetch_row();
$result->close();
$err_cnt= 0;

for ($i=0; $i < 2; $i++)
    if ($txtval[$i] != $binval[$i])
        printf("[%03d] Expected '%s' (text protocol), got '%s' (binary protocol)\n",
               $err_cnt++, $txtval[$i], $binval[$i]);

printf("Done!\n");
?>

Resulted in this output:

[000] Expected '1970-01-01 01:33:12.100000' (text protocol), got '1970-01-01 01:33:12' (binary protocol)
Done!

But I expected this output instead:

Done!

Metadata sent by server:

$> mariadb --column-type-info -e"select from_unixtime('1922.1')"
Field   1:  `from_unixtime('1922.1')`
Org_field:  ``
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       DATETIME
Collation:  binary (63)
Length:     26
Max_length: 26
Decimals:   39
Flags:      BINARY 

PHP Version

PHP 8.4.0-dev

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions