Ejemplo n.º 1
0
 public static bool IsString(DatabaseColumn column, string dataType)
 {
     //all aliases for CHAR and VARCHAR. there's also a LONG VARCHAR
     if (DataTypeConverter.IsVariableString(dataType) ||
         DataTypeConverter.IsFixedLengthString(dataType))
     {
         return(true);
     }
     if (column.DataType == null)
     {
         return(false);
     }
     return(column.DataType.IsString);
 }
Ejemplo n.º 2
0
        protected override string WriteDataType(DatabaseColumn column)
        {
            var type = new DataTypeWriter().WriteDataType(column);

            type += (!column.Nullable ? " NOT NULL" : string.Empty);

            var defaultValue = column.DefaultValue;

            if (!string.IsNullOrEmpty(defaultValue))
            {
                defaultValue = FixDefaultValue(defaultValue);
                const string defaultConstraint = " DEFAULT ";

                var dbDataType = column.DbDataType.ToUpperInvariant();
                if (DataTypeConverter.IsVariableString(dbDataType))
                {
                    type += defaultConstraint + "'" + defaultValue + "'";
                }
                else //numeric default
                {
                    type += defaultConstraint + defaultValue;
                }
            }

            //cannot detect the "GENERATED BY DEFAULT" vs "GENERATED ALWAYS" version?
            if (column.IsAutoNumber)
            {
                type += " GENERATED BY DEFAULT AS IDENTITY";
            }
            if (column.IsPrimaryKey && Table.PrimaryKey.Columns.Count == 1)
            {
                type += " PRIMARY KEY";
            }

            return(type);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }