首页 > 代码库 > XML Schema格式的"日期型数据”数据库存取
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‘;即可
XML Schema格式的"日期型数据”数据库存取
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。