From 855add36cffe6c6f6ec17d7ac936dafb28c9b859 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 16 Aug 2018 12:22:57 -0400 Subject: [PATCH] add better null handling on dates and excpetion handling on sql calls --- runner.cs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/runner.cs b/runner.cs index 722cea2..4913af9 100644 --- a/runner.cs +++ b/runner.cs @@ -77,11 +77,11 @@ namespace test nc = "'" + getv[i].ToString().Replace("'","''") + "'"; break; case "DATE": - if (getv[i].ToString() != "1/1/0001 12:00:00 AM") { - nc = "'" + getv[i].ToString() + "'"; + if (getv[i].ToString() == "1/1/0001 12:00:00 AM" || getv[i].ToString() == "") { + nc = "NULL"; } else { - nc = "NULL"; + nc = "'" + getv[i].ToString() + "'"; } break; case "TIME": @@ -117,7 +117,15 @@ namespace test sql = "INSERT INTO rlarp.osmi VALUES " + sql; pgcom.CommandText = sql; System.IO.File.WriteAllText(@"C:\Users\ptrowbridge\Downloads\"+ t.ToString()+".sql",sql); - pgcom.ExecuteNonQuery(); + try { + pgcom.ExecuteNonQuery(); + } + catch (Exception e) { + Console.Write(Environment.NewLine); + Console.Write(e.Message); + ibmc.Close(); + pgc.Close(); + } sql = ""; } } @@ -125,7 +133,15 @@ namespace test sql = "INSERT INTO rlarp.osmi VALUES " + sql; pgcom.CommandText = sql; System.IO.File.WriteAllText(@"C:\Users\ptrowbridge\Downloads\"+ t.ToString()+".sql",sql); - pgcom.ExecuteNonQuery(); + try { + pgcom.ExecuteNonQuery(); + } + catch (Exception e) { + Console.Write(Environment.NewLine); + Console.Write(e.Message); + ibmc.Close(); + pgc.Close(); + } sql = ""; }