From: Holger Levsen Date: Fri, 12 Oct 2012 15:21:30 +0000 (+0200) Subject: fix timestamp handling X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=cc15cd59505814ef95a73b1b24ba2ece43613097;p=profitbricks%2Fjenkins-build-scripts.git fix timestamp handling --- diff --git a/db_add.py b/db_add.py index 934668b..edafca7 100755 --- a/db_add.py +++ b/db_add.py @@ -32,9 +32,9 @@ def db_add_job(con, name): def db_add_build(con, db_id, number, start, end, status): cur = con.cursor() cur.execute("SAVEPOINT a") - if start != 'NULL': + if start != 'NULL' and start.isdigit(): start = "to_timestamp('%s')" % start - if end != 'NULL': + if end != 'NULL' and end.isdigit(): end = "to_timestamp('%s')" % end try: cur.execute("INSERT INTO jenkins_build(jenkins_job_id, jenkins_build_number, build_start, build_end, status) VALUES(%s, %s, %s, %s, '%s') RETURNING id" % (db_id, number, start, end, status)) @@ -47,12 +47,14 @@ def db_add_build(con, db_id, number, start, end, status): def db_update_build(con, db_id, end, status): cur = con.cursor() cur.execute("SAVEPOINT a") + if end != 'NULL' and end.isdigit(): + end = "to_timestamp('%s')" % end try: - cur.execute("UPDATE jenkins_build SET build_end = to_timestamp('%s'), status = '%s' WHERE id = %s RETURNING id" % (end, status, db_id)) + cur.execute("UPDATE jenkins_build SET build_end = '%s', status = '%s' WHERE id = %s RETURNING id" % (end, status, db_id)) con.commit() except psycopg2.DatabaseError as e: cur.execute("ROLLBACK TO a") # have to rollback after failed command - logger.debug("UPDATE jenkins_build SET build_end = to_timestamp('%s'), status = '%s' WHERE id = %s RETURNING id" % (end, status, db_id)) + logger.debug("UPDATE jenkins_build SET build_end = '%s', status = '%s' WHERE id = %s RETURNING id" % (end, status, db_id)) return cur.fetchone()[0] def db_add_origin(con, origin):