[icinga-checkins] icinga.org: icinga-core/mfriedrich/ido: idoutils: explicitely set 0 time values to NULL as from_unixtime only supports that

git at icinga.org git at icinga.org
Sat Aug 25 18:10:41 CEST 2012


Module: icinga-core
Branch: mfriedrich/ido
Commit: f78b5b0619613425f9c69c0f6fecae3e253b0ff5
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=f78b5b0619613425f9c69c0f6fecae3e253b0ff5

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Sat Aug 25 18:10:05 2012 +0200

idoutils: explicitely set 0 time values to NULL as from_unixtime only supports that

refs #3008

---

 module/idoutils/src/db.c        |   11 ++++++++++-
 module/idoutils/src/dbqueries.c |    2 ++
 2 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/module/idoutils/src/db.c b/module/idoutils/src/db.c
index 035c6c5..54b68fd 100644
--- a/module/idoutils/src/db.c
+++ b/module/idoutils/src/db.c
@@ -2470,8 +2470,17 @@ char *ido2db_db_timet_to_sql(ido2db_idi *idi, time_t t) {
 
 	switch (idi->dbinfo.server_type) {
 	case IDO2DB_DBSERVER_MYSQL:
-		if (asprintf(&buf, "FROM_UNIXTIME(%lu)", (unsigned long) t) == -1)
+		/* 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.
+		 */
+		if (t == 0) {
+			if (asprintf(&buf, "FROM_UNIXTIME(NULL)") == -1)
 			buf = NULL;
+		} else {
+			if (asprintf(&buf, "FROM_UNIXTIME(%lu)", (unsigned long) t) == -1)
+				buf = NULL;
+		}
 		break;
 	case IDO2DB_DBSERVER_PGSQL:
 		/* from_unixtime is a PL/SQL function (defined in db/pgsql.sql) */
diff --git a/module/idoutils/src/dbqueries.c b/module/idoutils/src/dbqueries.c
index 849f01b..2636a3e 100644
--- a/module/idoutils/src/dbqueries.c
+++ b/module/idoutils/src/dbqueries.c
@@ -1971,6 +1971,8 @@ int ido2db_query_insert_or_update_commentdata_add(ido2db_idi *idi, void **data)
                 result = ido2db_db_query(idi, query1);
                 free(query1);
 
+		ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_commentdata_add() dbi_result_get_numrows_affected=%lu\n", dbi_result_get_numrows_affected(idi->dbinfo.dbi_result));
+
                 /* check result if update was ok */
                 if (dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
                         /* try insert instead */





More information about the icinga-checkins mailing list