internal string CreateBulkInsertStatement(ITableData data, string tableName) { _sb.Clear(); GetSourceAndDestColumNames(data); AppendBeginSql(tableName); while (data.Read()) { List <string> values = new List <string>(); foreach (string destColumnName in DestColumnNames) { int colIndex = data.GetOrdinal(destColumnName); string dataTypeName = data.GetDataTypeName(colIndex); if (data.IsDBNull(colIndex)) { values.Add(NullValueSql(destColumnName)); } else { values.Add(ValueSql(destColumnName, data.GetString(colIndex))); } } AppendValueListSql(values, data.NextResult()); } AppendEndSql(); return(_sb.ToString()); }
internal string CreateBulkInsertStatementWithParameter(ITableData data, string tableName, List <OdbcParameter> parameters) { QueryText.Clear(); TableName = tableName; GetSourceAndDestColumnNames(data); AppendBeginSql(tableName); while (data.Read()) { QueryText.Append("("); string[] placeholder = new string[DestColumnNames.Count]; QueryText.Append(string.Join(",", placeholder.Select(s => s + "?"))); QueryText.AppendLine(")"); foreach (string destColumnName in DestColumnNames) { int colIndex = data.GetOrdinal(destColumnName); string dataTypeName = data.GetDataTypeName(colIndex); if (data.IsDBNull(colIndex)) { parameters.Add(new OdbcParameter(destColumnName, DBNull.Value)); } else { parameters.Add(new OdbcParameter(destColumnName, data.GetValue(colIndex))); } } if (data.NextResult()) { QueryText.Append(","); } } AppendEndSql(); return(QueryText.ToString()); }
private void ReadDataAndCreateQuery(ITableData data) { while (data.Read()) { List<string> values = new List<string>(); foreach (string destColumnName in DestColumnNames) { int colIndex = data.GetOrdinal(destColumnName); if (data.IsDBNull(colIndex)) AddNullValue(values, destColumnName); else AddNonNullValue(data, values, destColumnName, colIndex); } AppendValueListSql(values, data.NextResult()); } }