add option to trim text

This commit is contained in:
Paul Trowbridge 2018-08-23 13:38:58 -04:00
parent 8c8df89cf8
commit 80cddb08bc

View File

@ -15,6 +15,7 @@ namespace test
string dcs = ""; //= "Host=ushcc10091;Port=5432;Username=ptrowbridge;Password=qqqx53!026;Database=ubm;ApplicationName=runner"; string dcs = ""; //= "Host=ushcc10091;Port=5432;Username=ptrowbridge;Password=qqqx53!026;Database=ubm;ApplicationName=runner";
string sq = ""; //= System.IO.File.ReadAllText(@"C:\Users\ptrowbridge\Documents\runner\osm.sql"); string sq = ""; //= System.IO.File.ReadAllText(@"C:\Users\ptrowbridge\Documents\runner\osm.sql");
string dt = ""; //= "rlarp.omsi"; string dt = ""; //= "rlarp.omsi";
Boolean trim = false;
int r = 0; int r = 0;
int t = 0; int t = 0;
string sql = ""; string sql = "";
@ -23,11 +24,12 @@ namespace test
string nl = Environment.NewLine; string nl = Environment.NewLine;
string msg = "Help:"; string msg = "Help:";
msg = msg + nl + "version 0.16"; msg = msg + nl + "version 0.17";
msg = msg + nl + "-scs source connection string"; msg = msg + nl + "-scs source connection string";
msg = msg + nl + "-dcs destination connection string"; msg = msg + nl + "-dcs destination connection string";
msg = msg + nl + "-sq path to source query"; msg = msg + nl + "-sq path to source query";
msg = msg + nl + "-dt fully qualified name of destination table"; msg = msg + nl + "-dt fully qualified name of destination table";
msg = msg + nl + "-t trim text";
msg = msg + nl + "--help info"; msg = msg + nl + "--help info";
//---------------------------------------parse args into variables------------------------------------------------- //---------------------------------------parse args into variables-------------------------------------------------
@ -50,6 +52,9 @@ namespace test
case "-dt": case "-dt":
dt = "INSERT INTO " + args[i+1] + " VALUES "; dt = "INSERT INTO " + args[i+1] + " VALUES ";
break; break;
case "-t":
trim = true;
break;
case "--help": case "--help":
Console.Write(Environment.NewLine); Console.Write(Environment.NewLine);
Console.Write(msg); Console.Write(msg);
@ -132,9 +137,21 @@ namespace test
if (getv[i] != null) { if (getv[i] != null) {
switch (dtn[i]){ switch (dtn[i]){
case "VARCHAR": case "VARCHAR":
if (trim) {
nc = "'" + getv[i].ToString().Replace("'","''").Trim() + "'";
}
else {
nc = "'" + getv[i].ToString().Replace("'","''") + "'";
}
nc = "'" + getv[i].ToString().Replace("'","''") + "'"; nc = "'" + getv[i].ToString().Replace("'","''") + "'";
break; break;
case "CHAR": case "CHAR":
if (trim) {
nc = "'" + getv[i].ToString().Replace("'","''").Trim() + "'";
}
else {
nc = "'" + getv[i].ToString().Replace("'","''") + "'";
}
nc = "'" + getv[i].ToString().Replace("'","''") + "'"; nc = "'" + getv[i].ToString().Replace("'","''") + "'";
break; break;
case "DATE": case "DATE":