private string[] buildInsertColumnNamesAndValues(IDictionary <string, string> csvColumnDataTypesDictionary, XVar data) { string[] returnStrings = new string[2]; StringBuilder csvColumns = new StringBuilder(); StringBuilder csvValues = new StringBuilder(); foreach (KeyValuePair <string, string> kvp in csvColumnDataTypesDictionary) { if (data.KeyExists(kvp.Key)) { if (csvColumns.Length > 0) { csvColumns.Append(","); csvValues.Append(","); } csvColumns.Append(kvp.Key); if (data.GetArrayItem(kvp.Key).Length() == 0) { csvValues.Append("NULL"); } else if (kvp.Value.Equals("STRING")) { string valueString = data.GetArrayItem(kvp.Key).Replace("'", "''"); csvValues.AppendFormat("{0}{1}{2}", "'", valueString, "'"); } else if (kvp.Value.Equals("NUMBER")) { csvValues.Append(data.GetArrayItem(kvp.Key).ToString()); } else if (kvp.Value.Equals("DATE")) { csvValues.AppendFormat("{0}{1}{2}", "TO_DATE('", data.GetArrayItem(kvp.Key).ToString(), "', 'YYYYMMDD')"); // csvValues.AppendFormat("{0}{1}{2}", "'", data[kvp.Key], "'"); } else { throw new Exception("Could not file datatype of " + kvp.Value); } } } returnStrings[0] = csvColumns.ToString(); returnStrings[1] = csvValues.ToString(); return(returnStrings); }
private string[] buildUpdateColumnNamesAndValues(IDictionary <string, string> csvColumnDataTypesDictionary, XVar data) { string[] returnStrings = new string[1]; StringBuilder updateStmtBuilder = new StringBuilder(); foreach (KeyValuePair <string, string> kvp in csvColumnDataTypesDictionary) { if (data.KeyExists(kvp.Key)) { if (data.GetArrayItem(kvp.Key).Length() == 0) { updateStmtBuilder.AppendFormat("{0} = NULL", kvp.Key); } else if (kvp.Value.Equals("STRING")) { string valueString = data.GetArrayItem(kvp.Key).Replace("'", "''"); updateStmtBuilder.AppendFormat("{0}={1}{2}{3}", kvp.Key, "'", valueString, "'"); } else if (kvp.Value.Equals("NUMBER")) { updateStmtBuilder.AppendFormat("{0}={1}", kvp.Key, data.GetArrayItem(kvp.Key).ToString()); } else if (kvp.Value.Equals("DATE")) { updateStmtBuilder.AppendFormat("{0} = {1}{2}{3}", kvp.Key, "TO_DATE('", data.GetArrayItem(kvp.Key).ToString(), "', 'YYYYMMDD')"); } else { throw new Exception("Could not file datatype of " + kvp.Value); } } } returnStrings[0] = updateStmtBuilder.ToString(); return(returnStrings); }