【问题标题】:C++ Connector : Inserting datetime with MariaDBC++ 连接器:使用 MariaDB 插入日期时间
【发布时间】:2020-03-19 08:16:14
【问题描述】:

我正在尝试通过 C++ 连接器将日期时间从 C++ 应用程序插入 MariaDB 服务器:

MYSQL_TIME  ts;
MYSQL_TIME *timestamps[]= {&ts};
char timestamps_ind[]= {STMT_INDICATOR_NTS};
bind[1].buffer= timestamps;
bind[1].buffer_type= MYSQL_TYPE_DATETIME;
bind[1].u.indicator= timestamps_ind;

ts.year = 2020;
ts.month = 3;
ts.day = 19;
ts.hour = 8;
ts.minute = 5;

执行后将 NULL 发送到 DateTime 列。如果我将 bind[1].buffer_type= MYSQL_TYPE_TIMESTAMP; 更改为 MYSQL_TYPE_DATE 它会将正确的值发送到数据库,但由于 DATE 只有年月日。

有什么我想念的以日期时间发送的吗?

【问题讨论】:

  • MYSQL_TYPE_DATETIME 那么呢?
  • Buf 如果我将buffer_type 设置为 MYSQL_TIME_DATETIME,则数据库中的结果为 NULL。

标签: c++ mysql mariadb


【解决方案1】:

已解决: 要使用日期时间,我需要设置 MYSQL_TIME 的所有属性。我错过了secondsecond_part

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    相关资源
    最近更新 更多