php / php/php-src

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

未关闭
#16,910 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Extension: mysqlnd
主要语言
C
星标
40.4k
派生
8.1k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 mysqlnd 对 DATETIME 和 TIME 元数据的二进制协议处理入手,使用提供的 mysqli 预处理语句复现以及其与文本协议的比较。检查服务器将小数报告为 39 (AUTO_SEC_PART_DIGITS) 的情况,然后添加或更新回归测试覆盖,以便保留小数秒,并让比较打印出“Done!”。 از

由索引模型根据 Issue 内容生成。

评估

技术栈
c, mysql, php
领域
databases
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。