swap out hardcoded lines for variables
This commit is contained in:
parent
7a53ebbc3b
commit
bcf199ed69
115
runner.cs
115
runner.cs
@ -10,59 +10,75 @@ namespace test
|
|||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
//var i = new Int32();
|
|
||||||
|
|
||||||
//-------------------------------------------establis connections-------------------------------------------------
|
string scs = ""; //= "Driver={iSeries Access ODBC Driver};System=S7830956;Uid=PTROWBRIDG;Pwd=QQQX53@027";
|
||||||
//var ibmc = new System.Data.Odbc.OdbcConnection("Driver={iSeries Access ODBC Driver};System=TEST400;Uid=tstdillen;Pwd=tstdillen");
|
//string scs = ""; //= "Driver={iSeries Access ODBC Driver};System=TEST400;Uid=tstdillen;Pwd=tstdillen"
|
||||||
var ibmc = new System.Data.Odbc.OdbcConnection("Driver={iSeries Access ODBC Driver};System=S7830956;Uid=PTROWBRIDG;Pwd=QQQX53@027");
|
string dcs = ""; //= "Host=ushcc10091;Port=5432;Username=ptrowbridge;Password=qqqx53!026;Database=ubm;ApplicationName=runner";
|
||||||
var pgc = new NpgsqlConnection("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");
|
||||||
ibmc.Open();
|
string dt = ""; //= "rlarp.omsi";
|
||||||
pgc.Open();
|
|
||||||
|
|
||||||
//----------------------------------------------setup commands---------------------------------------------------
|
|
||||||
var ibmcmd = new System.Data.Odbc.OdbcCommand();
|
|
||||||
ibmcmd.Connection = ibmc;
|
|
||||||
//ibmcmd.CommandText = "SELECT cast(ID as int) ID, TBLN, ACTN, TS, SU, COL, REPLACE(OLDV,X'00',CHR(32)) OLDV, REPLACE(NEWV,X'00',CHR(32)) NEWV, DTYPE, LENG, SCAL FROM QGPL.TRIG_LOG_EAV WHERE ID > 236832";
|
|
||||||
//ibmcmd.CommandText = "SELECT * FROM RLARP.OSM WHERE ITER >= '2018-08-15-11.23.42.009654'";
|
|
||||||
//ibmcmd.CommandText = "SELECT * FROM RLARP.OSMP";
|
|
||||||
//ibmcmd.CommandText = "SELECT * FROM LGDAT.GLDATE";
|
|
||||||
//ibmcmd.CommandText = "SELECT * FROM LGDAT.STKMM";
|
|
||||||
|
|
||||||
ibmcmd.CommandText = System.IO.File.ReadAllText(@"C:\Users\ptrowbridge\Documents\runner\osm.sql");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var pgcmd = new NpgsqlCommand();
|
|
||||||
pgcmd.Connection = pgc;
|
|
||||||
//pgcmd.CommandText = "SELECT * FROM rlarp.trig_log_eav WHERE 0=1";
|
|
||||||
pgcmd.CommandText = "SELECT * FROM rlarp.osmi WHERE 0=1";
|
|
||||||
//pgcmd.CommandText = "SELECT * FROM lgdat.gldate WHERE 0=1";
|
|
||||||
//pgcmd.CommandText = "SELECT * FROM lgdat.stkmm WHERE 0=1";
|
|
||||||
|
|
||||||
//---------------------------------------------setup adapters---------------------------------------------------------
|
|
||||||
//var ibmds = new System.Data.DataSet();
|
|
||||||
//var ibmda = new System.Data.Odbc.OdbcDataAdapter(ibmcmd);
|
|
||||||
//ibmda.Fill(ibmds);
|
|
||||||
|
|
||||||
|
|
||||||
var pgds = new System.Data.DataSet();
|
|
||||||
var pgda = new NpgsqlDataAdapter(pgcmd);
|
|
||||||
pgda.Fill(pgds);
|
|
||||||
//pgda.UpdateBatchSize = 100;
|
|
||||||
|
|
||||||
Console.Write("etl start:" + DateTime.Now.ToString());
|
|
||||||
Console.Write(Environment.NewLine);
|
|
||||||
NpgsqlTransaction pgt = pgc.BeginTransaction();
|
|
||||||
|
|
||||||
//--------------------------------------------move to target--------------------------------------------------------
|
|
||||||
var ibmdr = ibmcmd.ExecuteReader();
|
|
||||||
var getv = new object[ibmdr.FieldCount];
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
int t = 0;
|
int t = 0;
|
||||||
string sql = "";
|
string sql = "";
|
||||||
string nr = "";
|
string nr = "";
|
||||||
string nc = "";
|
string nc = "";
|
||||||
|
|
||||||
|
//---------------------------------------parse args into variables-------------------------------------------------
|
||||||
|
|
||||||
|
for (int i = 0; i < args.Length; i = i +1 ){
|
||||||
|
switch (args[i]) {
|
||||||
|
//source connection string
|
||||||
|
case "-scs":
|
||||||
|
scs = args[i+1];
|
||||||
|
break;
|
||||||
|
//destination connection string
|
||||||
|
case "-dcs":
|
||||||
|
dcs = args[i+1];
|
||||||
|
break;
|
||||||
|
//source query path
|
||||||
|
case "-sq":
|
||||||
|
sq = System.IO.File.ReadAllText(args[i+1]);
|
||||||
|
break;
|
||||||
|
//destination table name
|
||||||
|
case "-dt":
|
||||||
|
dt = "INSERT INTO " + args[i+1] + " VALUES ";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.Write(Environment.NewLine);
|
||||||
|
Console.Write(scs);
|
||||||
|
Console.Write(Environment.NewLine);
|
||||||
|
Console.Write(dcs);
|
||||||
|
Console.Write(Environment.NewLine);
|
||||||
|
Console.Write(sq);
|
||||||
|
Console.Write(Environment.NewLine);
|
||||||
|
Console.Write(dt);
|
||||||
|
|
||||||
|
//return;
|
||||||
|
|
||||||
|
//-------------------------------------------establish connections-------------------------------------------------
|
||||||
|
|
||||||
|
var ibmc = new System.Data.Odbc.OdbcConnection(scs);
|
||||||
|
var pgc = new NpgsqlConnection(dcs);
|
||||||
|
ibmc.Open();
|
||||||
|
pgc.Open();
|
||||||
|
|
||||||
|
//----------------------------------------------setup commands---------------------------------------------------
|
||||||
|
|
||||||
|
var ibmcmd = new System.Data.Odbc.OdbcCommand(sq,ibmc);
|
||||||
var pgcom = pgc.CreateCommand();
|
var pgcom = pgc.CreateCommand();
|
||||||
|
|
||||||
|
//---------------------------------------------begin transaction---------------------------------------------------------
|
||||||
|
|
||||||
|
Console.Write(Environment.NewLine);
|
||||||
|
Console.Write("etl start:" + DateTime.Now.ToString());
|
||||||
|
NpgsqlTransaction pgt = pgc.BeginTransaction();
|
||||||
|
var ibmdr = ibmcmd.ExecuteReader();
|
||||||
|
//setup getv object array dimensioned to number of columns for scenario
|
||||||
|
var getv = new object[ibmdr.FieldCount];
|
||||||
|
|
||||||
while (ibmdr.Read()) {
|
while (ibmdr.Read()) {
|
||||||
r = r + 1;
|
r = r + 1;
|
||||||
t = t +1 ;
|
t = t +1 ;
|
||||||
@ -114,9 +130,8 @@ namespace test
|
|||||||
sql = sql + "(" + nr + ")";
|
sql = sql + "(" + nr + ")";
|
||||||
if (r == 250) {
|
if (r == 250) {
|
||||||
r = 0;
|
r = 0;
|
||||||
sql = "INSERT INTO rlarp.osmi VALUES " + sql;
|
sql = dt + sql;
|
||||||
pgcom.CommandText = sql;
|
pgcom.CommandText = sql;
|
||||||
System.IO.File.WriteAllText(@"C:\Users\ptrowbridge\Downloads\"+ t.ToString()+".sql",sql);
|
|
||||||
try {
|
try {
|
||||||
pgcom.ExecuteNonQuery();
|
pgcom.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
@ -130,9 +145,8 @@ namespace test
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
sql = "INSERT INTO rlarp.osmi VALUES " + sql;
|
sql = dt + sql;
|
||||||
pgcom.CommandText = sql;
|
pgcom.CommandText = sql;
|
||||||
System.IO.File.WriteAllText(@"C:\Users\ptrowbridge\Downloads\"+ t.ToString()+".sql",sql);
|
|
||||||
try {
|
try {
|
||||||
pgcom.ExecuteNonQuery();
|
pgcom.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
@ -151,6 +165,7 @@ namespace test
|
|||||||
ibmc.Close();
|
ibmc.Close();
|
||||||
pgc.Close();
|
pgc.Close();
|
||||||
|
|
||||||
|
Console.Write(Environment.NewLine);
|
||||||
Console.Write("etl end:" + DateTime.Now.ToString());
|
Console.Write("etl end:" + DateTime.Now.ToString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user