English 中文(简体)
把MySQL的警告化为错误
原标题:Converting MySQL warning into an error

是否有办法将MySQL发出的关于无效日期的警告转化为硬错误? 我利用<代码>SET sql_mode=TRADITIONAL ;进行了尝试,显然应当将(有些)警告变成错误,但在此没有任何效果。 这是MySQL.1.56。 在届会一级开展这项工作是理想的,但我不胜感激。

mysql> describe test_table2;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| value    | int(11)     | YES  |     | NULL    |       |
| name     | varchar(16) | YES  |     | NULL    |       |
| sometime | datetime    | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> select * from test_table2;
+-------+-------+---------------------+
| value | name  | sometime            |
+-------+-------+---------------------+
|     1 | one   | 2002-09-01 10:00:00 |
|     2 | two   | 2002-09-02 11:00:00 |
|     3 | three | 2002-09-03 12:00:00 |
|     4 | four  | 2002-01-04 13:00:00 |
|     5 | five  | 2002-01-05 14:00:00 |
+-------+-------+---------------------+
5 rows in set (0.00 sec)

mysql> select * from test_table2 where sometime =  foo ;
Empty set, 2 warnings (0.00 sec)

Warning (Code 1292): Incorrect datetime value:  foo  for column  sometime  at row 1
Warning (Code 1292): Incorrect datetime value:  foo  for column  sometime  at row 1
最佳回答

, 填写了< INSERT/code>,其生效日期为错误,但填写了<代码>SlectT, 有效期为无效。 您可以通过将(可能无效的)日期价值传至这一查询点来引发错误:

CREATE TEMPORARY TABLE IF NOT EXISTS date_guard (date DATE) SELECT  foo  AS date;

如果 f是你想要确认的日期价值。

问题回答

谁应该看到错误?

如果这是一种固定的扼杀,只是试图将oo改成日期,看看你是否能够取得有效结果(即不是00-00-000)。 检查日期是否有效,然后继续进行。

我未能使MySQL在这一案件中产生错误(甚至将无效日期改为全国人民党——它坚持将其00-00-0000)。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签