private void PrepareTypesDataTable() { foreach (var databaseColumn in _databaseTable.Columns) { var key = databaseColumn.Name; if (!_dataTable.Columns.Contains(key)) { _columnTypes.Add(key, typeof(object)); continue; } var columnType = _dataTable.Columns[key].DataType; _columnTypes.Add(key, columnType); if (columnType == typeof(DateTime)) { //get the original database type (datetime2, date, time, timestamp etc) _dateTypes.Add(key, databaseColumn.DbDataType.ToUpperInvariant()); } if (columnType == typeof(object)) { _nullColumns.Add(key); } if (!IncludeBlobs && DataTypeConverter.IsBlob(databaseColumn.DbDataType.ToUpperInvariant(), databaseColumn.Length)) { _nullColumns.Add(key); } } }
private static string OtherDatabaseTypesToDb2(string dataType, DatabaseColumn column) { //string types if (DataTypeConverter.IsFixedLengthString(dataType)) { return("CHAR"); } if (DataTypeConverter.IsLongString(dataType)) { return(dataType == "CLOB" ? "CLOB" : "DBCLOB"); } if (DataTypeConverter.IsVariableString(dataType)) { if (column.Length == -1) { return("DBCLOB"); } return("VARCHAR"); } //numeric types if (dataType == "SMALLINT") { return(dataType); } if (dataType == "BIGINT") { return(dataType); } if (dataType == "INTEGER") { return(dataType); } if (dataType == "INT") { return("INTEGER"); } if (dataType == "NUM") { return("NUMERIC"); //DB2 alias } if (dataType == "DEC") { return("DECIMAL"); //DB2 alias } if (dataType == "MONEY") { return("DECIMAL(19,4)"); } if (dataType == "BIT") { return("SMALLINT"); //could be CHAR(1) but nicer with an integer } if (dataType == "NUMBER") { return(DataTypeConverter.OracleNumberConversion(column.Precision, column.Scale)); } //date times //SqlServer Timestamp is a binary if (DataTypeConverter.IsSqlServerTimestamp(dataType, column)) { return("GRAPHIC"); } if (DataTypeConverter.IsDateTime(dataType)) { return("TIMESTAMP"); } //bytes if (DataTypeConverter.IsBlob(dataType, column)) { return("BLOB"); } if (DataTypeConverter.IsBinary(dataType)) { if (dataType == "LONG VARGRAPHIC") { return(dataType); } if (dataType == "GRAPHIC") { return(dataType); } return("VARGRAPHIC"); } //other types if (dataType == "XMLTYPE") { return("XML"); } if (dataType == "UNIQUEIDENTIFIER") { return("CHAR(16) FOR BIT DATA"); } return(dataType); }
private static string OtherDatabaseTypesToPostgreSql(string dataType, DatabaseColumn column) { //string types //character(n) (aka char(n)) character varying(n) aka varchar(n) and text if (DataTypeConverter.IsFixedLengthString(dataType)) { return("CHAR"); } if (DataTypeConverter.IsLongString(dataType)) { return("TEXT"); } if (DataTypeConverter.IsVariableString(dataType)) { if (column.Length == -1) { return("TEXT"); } return("VARCHAR"); } //numeric types if (dataType == "INT") { return("INTEGER"); } if (dataType == "INT4") { return("INTEGER"); //this is a PostgreSql alias, we'll use standard SQL } //else if (dataType == "SERIAL") return "INTEGER"; //this is a PostgreSql alias, we'll use standard SQL //else if (dataType == "BIGSERIAL") return "BIGINT"; //this is a PostgreSql alias, we'll use standard SQL if (dataType == "INT8") { return("BIGINT"); //this is a PostgreSql alias, we'll use standard SQL } if (dataType == "INT2") { return("SMALLINT"); //this is a PostgreSql alias, we'll use standard SQL } if (dataType == "TINYINT") { return("SMALLINT"); //this is a MsSql alias, we'll use standard SQL } if (dataType == "NUMBER") { return(DataTypeConverter.OracleNumberConversion(column.Precision, column.Scale)); } //float and real if (dataType == "FLOAT4") { return("REAL"); //this is a PostgreSql alias, we'll use standard SQL } if (dataType == "FLOAT") { return("DOUBLE PRECISION"); } //date times //SqlServer Timestamp is a binary if (DataTypeConverter.IsSqlServerTimestamp(dataType, column)) { return("BYTEA"); //this is just a byte array- functionally you should redesign the table and perhaps use the system extension columns } if (DataTypeConverter.IsDateTime(dataType)) { return("TIMESTAMP"); } //bytes if (DataTypeConverter.IsBlob(dataType, column)) { return("OID");//blobs become object ids } if (DataTypeConverter.IsBinary(dataType)) { return("BYTEA"); } //there is a native BIT(n) type in Postgresql, but in conversion we probably mean boolean. if (dataType == "BIT" && !column.Length.HasValue) { return("BOOLEAN"); } //other types if (dataType == "XMLTYPE") { return("XML"); } if (dataType == "UNIQUEIDENTIFIER") { return("UUID"); } return(dataType); }