zoukankan      html  css  js  c++  java
  • XML Schema格式的"日期型数据”数据库存取

    对于XML Schema格式的"日期型数据”在数据库中存于datetime字段的时候,出现错误

    mysql> select @@sql_mode;
    +--------------------------------------------+
    | @@sql_mode                                 |
    +--------------------------------------------+
    | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
    +--------------------------------------------+
    1 row in set (0.00 sec)
    
    mysql> insert into datetimetest(dt) values ('2013-08-26T12:00:00+00:00');
    ERROR 1292 (22007): Incorrect datetime value: '2013-08-26T12:00:00+00:00' for column 'dt' at row 1
    
    -- remove STRICT_TRANS_TABLES -- note that executing this only removes it for your
    -- current session -- it does not make a server-wide config change
    
    mysql> set @@sql_mode='no_engine_substitution';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> select @@sql_mode;
    +------------------------+
    | @@sql_mode             |
    +------------------------+
    | NO_ENGINE_SUBSTITUTION |
    +------------------------+
    1 row in set (0.00 sec)
    
    -- now MySQL will accept the invalid value, with a warning
    
    mysql> insert into datetimetest(dt) values ('2013-08-26T12:00:00+00:00');
    Query OK, 1 row affected, 1 warning (0.00 sec)
    
    mysql> show warnings;
    +---------+------+-----------------------------------------+
    | Level   | Code | Message                                 |
    +---------+------+-----------------------------------------+
    | Warning | 1265 | Data truncated for column 'dt' at row 1 |
    +---------+------+-----------------------------------------+
    1 row in set (0.00 sec)
    
    -- the value did get inserted, but the time zone information was lost:
    
    mysql> select * from datetimetest;
    +----+---------------------+
    | id | dt                  |
    +----+---------------------+
    |  1 | 2013-08-26 12:00:00 |
    +----+---------------------+
    1 row in set (0.00 sec)
    

      

    所以直接运行set @@sql_mode='no_engine_substitution';即可

  • 相关阅读:
    学习ASP.NET Web API框架揭秘之“HTTP方法重写”
    学习、摘录、目标——学习任务
    ASP.NET Core学习零散记录
    通过Nginx实现负载均衡
    通过IIS共享文件夹来实现静态资源"本地分布式"部署
    python2.7 django 错误汇总
    【心得】算法练习
    【数据结构】思维导图
    【算法】思维导图
    记录一次面试中二分查找的算法题
  • 原文地址:https://www.cnblogs.com/luxiaojun/p/7246322.html
Copyright © 2011-2022 走看看