[icinga-checkins] icinga.org: icinga-core/dev/core: idoutils: fix FROM_UNIXTIME(NULL) does not work with MySQL 5.0.x refs #3399 refs #3466

git at icinga.org git at icinga.org
Thu Jan 10 20:23:50 CET 2013


Module: icinga-core
Branch: dev/core
Commit: 1042107cd94ba3f0ee7fa247677129dcbbb3b882
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=1042107cd94ba3f0ee7fa247677129dcbbb3b882

Author: Michael Friedrich <michael.friedrich at gmail.com>
Date:   Wed Nov 28 15:53:21 2012 +0100

idoutils: fix FROM_UNIXTIME(NULL) does not work with MySQL 5.0.x refs #3399 refs #3466

basically, we treated the inner 0L as NULL, as otherwise out-of-range
warnings would be expected. since this workaround does not work with
with mysql 5.0.x we must learn it the hard way, replacing 0L directly
with the null timestamp like NULL in mysql >= 5.1.x would automatically
create on schema insert - 0000-00-00 00:00:00

kudos to Carl for the patch and fix.

---

 Changelog                |    1 +
 module/idoutils/src/db.c |    4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/Changelog b/Changelog
index 7a65d48..7346f7b 100644
--- a/Changelog
+++ b/Changelog
@@ -26,6 +26,7 @@ FIXES
 * idoutils: fix ORA-1461 writing data to varchar2 exceeding field size limit output, command_arg and commandline data written to Oracle #3324 #3325 - TD
 * idoutils: fix unsafe handling of dbi_conn_sequence_last, rewrite last_insert_id/sequence fetching #3408 - MF
 * idoutils: fix ido2db does not cleanly exit the client on wrong schema version check in db_hello #3419 - MF
+* idoutils: fix FROM_UNIXTIME(NULL) does not work with MySQL 5.0.x #3399 #3466 - CF
 
 * install: drop unused daemon-init-readhat script (spec uses daemon-init) #3402 - MF
 * install: fix broken configure ssl detection for idoutils on ubuntu/debian (Oliver Skibbe) #3413 - MF
diff --git a/module/idoutils/src/db.c b/module/idoutils/src/db.c
index 69acd4a..5010d6f 100644
--- a/module/idoutils/src/db.c
+++ b/module/idoutils/src/db.c
@@ -2437,10 +2437,10 @@ char *ido2db_db_timet_to_sql(ido2db_idi *idi, time_t t) {
 	case IDO2DB_DBSERVER_MYSQL:
 		/* mysql from_unixtime treats 0 as 'Out of range value for column '...' at row 1'
 		 * which basically is a mess, when doing updates at all. in order to stay sane, we
-		 * set the value explicitely to NULL. mysql, you suck hard.
+		 * set the value explicitely to the null timestamp. mysql, you suck hard.
 		 */
 		if (t == 0) {
-			if (asprintf(&buf, "FROM_UNIXTIME(NULL)") == -1)
+			if (asprintf(&buf, "'0000-00-00 00:00:00'") == -1)
 			buf = NULL;
 		} else {
 			if (asprintf(&buf, "FROM_UNIXTIME(%lu)", (unsigned long) t) == -1)





More information about the icinga-checkins mailing list