public void AppendType(TypeUsage typeUsage, bool isNullable, bool isIdentity)
        {
            var isTimestamp = false;

            var sqliteTypeName = typeUsage.EdmType.Name;
            var sqliteLength   = "";

            switch (sqliteTypeName)
            {
            case "decimal":
            case "numeric":
                sqliteLength = string.Format(System.Globalization.CultureInfo.InvariantCulture, "({0}, {1})",
                                             typeUsage.GetPrecision(), typeUsage.GetScale());
                break;

            case "binary":
            case "varbinary":
            case "varchar":
            case "nvarchar":
            case "char":
            case "nchar":
                sqliteLength = string.Format("({0})", typeUsage.GetMaxLength());
                break;
            }

            this.AppendSql(sqliteTypeName);
            this.AppendSql(sqliteLength);
            this.AppendSql(isNullable ? " null" : " not null");

            if (isTimestamp)
            {
                ; // nothing to generate for identity
            }
            else if (isIdentity && sqliteTypeName == "guid")
            {
                this.AppendSql(" default GenGUID()");
            }
            else if (isIdentity)
            {
                this.AppendSql(" constraint primary key autoincrement");
            }
        }
Esempio n. 2
0
        private void AppendType(EdmProperty column)
        {
            TypeUsage type = column.TypeUsage;

            // check for rowversion-like configurations
            Facet storeGenFacet;
            bool  isTimestamp = false;

            if (type.EdmType.Name == "binary" &&
                8 == type.GetMaxLength() &&
                column.TypeUsage.Facets.TryGetValue("StoreGeneratedPattern", false, out storeGenFacet) &&
                storeGenFacet.Value != null &&
                StoreGeneratedPattern.Computed == (StoreGeneratedPattern)storeGenFacet.Value)
            {
                isTimestamp = true;
                AppendIdentifier("rowversion");
            }
            else
            {
                string typeName = type.EdmType.Name;
                // Special case: the EDM treats 'nvarchar(max)' as a type name, but SQL Server treats
                // it as a type 'nvarchar' and a type qualifier. As such, we can't escape the entire
                // type name as the EDM sees it.
                const string maxSuffix = "(max)";
                if (type.EdmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType && typeName.EndsWith(maxSuffix, StringComparison.Ordinal))
                {
                    //Debug.Assert(new[] { "nvarchar(max)", "varchar(max)", "varbinary(max)" }.Contains(typeName),
                    //    "no other known SQL Server primitive types types accept (max)");
                    AppendIdentifier(typeName.Substring(0, typeName.Length - maxSuffix.Length));
                    AppendSql("(max)");
                }
                else
                {
                    AppendIdentifier(typeName);
                }
                switch (type.EdmType.Name)
                {
                case "decimal":
                case "numeric":
                    AppendSqlInvariantFormat("({0}, {1})", type.GetPrecision(), type.GetScale());
                    break;

                case "datetime2":
                case "datetimeoffset":
                case "time":
                    AppendSqlInvariantFormat("({0})", type.GetPrecision());
                    break;

                case "binary":
                case "varbinary":
                case "nvarchar":
                case "varchar":
                case "char":
                case "nchar":
                    AppendSqlInvariantFormat("({0})", type.GetMaxLength());
                    break;

                default:
                    break;
                }
            }
            AppendSql(column.Nullable ? " null" : " not null");

            if (!isTimestamp && column.TypeUsage.Facets.TryGetValue("StoreGeneratedPattern", false, out storeGenFacet) &&
                storeGenFacet.Value != null)
            {
                StoreGeneratedPattern storeGenPattern = (StoreGeneratedPattern)storeGenFacet.Value;
                if (storeGenPattern == StoreGeneratedPattern.Identity)
                {
                    if (type.EdmType.Name == "uniqueidentifier")
                    {
                        AppendSql(" default newid()");
                    }
                    else
                    {
                        AppendSql(" identity");
                    }
                }
            }
        }
Esempio n. 3
0
        public void AppendType(TypeUsage typeUsage, bool isNullable, bool isIdentity, string defaultValueSql)
        {
            bool isTimestamp = false;

            JetDataTypeAlias alias;

            JetDataTypeAliasCollection.Instance.TryGetValue(typeUsage.EdmType.Name, out alias);

            if (alias == null)
            {
                throw new NotSupportedException(string.Format("Type {0} unsupported", typeUsage.EdmType.Name));
            }

            string jetTypeName = alias.Alias;
            string jetLength   = "";


            switch (jetTypeName)
            {
            case "decimal":
            case "numeric":
                jetLength = string.Format(System.Globalization.CultureInfo.InvariantCulture, "({0}, {1})", typeUsage.GetPrecision(), typeUsage.GetScale());
                break;

            case "binary":
            case "varbinary":
            case "varchar":
            case "char":
                jetLength = string.Format("({0})", typeUsage.GetMaxLength());
                break;

            default:
                break;
            }

            AppendSql(jetTypeName);
            AppendSql(jetLength);
            if (!string.IsNullOrWhiteSpace(defaultValueSql))
            {
                AppendSql(" default " + defaultValueSql);
                if (!isNullable)
                {
                    AppendSql(" not null");
                }
            }
            else
            {
                AppendSql(isNullable ? " null" : " not null");
            }

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (isTimestamp)
            {
                ;// nothing to generate for identity
            }
            else if (isIdentity && jetTypeName == "guid")
            {
                AppendSql(" default GenGUID()");
            }
            //AppendSql(" counter");
            //AppendSql(" autoincrement");
            else if (isIdentity)
            {
                AppendSql(" identity(1,1)");
            }
        }
        private void AppendType(EdmProperty column, string providerManifestToken)
        {
            TypeUsage typeUsage = column.TypeUsage;
            bool      flag      = false;
            Facet     facet;

            if (typeUsage.EdmType.Name == "binary" && 8 == typeUsage.GetMaxLength() && (column.TypeUsage.Facets.TryGetValue("StoreGeneratedPattern", false, out facet) && facet.Value != null) && StoreGeneratedPattern.Computed == (StoreGeneratedPattern)facet.Value)
            {
                flag = true;
                this.AppendIdentifier("rowversion");
            }
            else
            {
                string name = typeUsage.EdmType.Name;
                if (name.ToLowerInvariant() == "guid")
                {
                    this.AppendSql("raw(16)");
                }
                else if (name.ToLowerInvariant() == "pl/sql boolean")
                {
                    this.AppendSql("number(1, 0)");
                }
                else
                {
                    this.AppendSql(name);
                }
                switch (typeUsage.EdmType.Name)
                {
                case "number":
                    this.AppendSqlInvariantFormat("({0}, {1})", (object)typeUsage.GetPrecision(), (object)typeUsage.GetScale());
                    break;

                case "float":
                    this.AppendSqlInvariantFormat("({0})", (object)typeUsage.GetPrecision());
                    break;

                case "char":
                case "nchar":
                case "varchar2":
                case "nvarchar2":
                case "raw":
                    this.AppendSqlInvariantFormat("({0})", (object)typeUsage.GetMaxLength());
                    break;
                }
            }
            if (!flag && column.TypeUsage.Facets.TryGetValue("StoreGeneratedPattern", false, out facet) && facet.Value != null)
            {
                switch ((StoreGeneratedPattern)facet.Value)
                {
                case StoreGeneratedPattern.Identity:
                    if (EFOracleVersionUtils.GetStorageVersion(providerManifestToken) >= EFOracleVersion.Oracle12cR1)
                    {
                        this.AppendSql(" generated by default as identity");
                        break;
                    }
                    EFOracleDdlBuilder.m_bCreateSequenceAndTrigger = true;
                    break;

                case StoreGeneratedPattern.Computed:
                    EFOracleDdlBuilder.m_bCreateSequenceAndTrigger      = true;
                    EFOracleDdlBuilder.m_bStoreGeneratedPatternComputed = true;
                    break;
                }
            }
            this.AppendSql(column.Nullable ? " null" : " not null");
        }
        public void AppendType(TypeUsage typeUsage, bool isNullable, bool isIdentity)
        {
            bool isTimestamp = false;

            string db2TypeName = typeUsage.EdmType.Name;
            string db2Length   = "";


            switch (db2TypeName)
            {
            case "decimal":
            case "numeric":
                db2Length = string.Format(System.Globalization.CultureInfo.InvariantCulture, "({0}, {1})", typeUsage.GetPrecision(), typeUsage.GetScale());
                break;

            case "binary":
            case "varbinary":
            case "varchar":
            case "char":
                db2Length = string.Format("({0})", typeUsage.GetMaxLength());
                break;

            default:
                break;
            }

            AppendSql(db2TypeName);
            AppendSql(db2Length);
            AppendSql(isNullable ? " null" : " not null");

            if (isTimestamp)
#pragma warning disable 642
            {
                ;// nothing to generate for identity
            }
#pragma warning restore 642
            else if (isIdentity && db2TypeName == "guid")
            {
                AppendSql(" default GenGUID()");
            }
            else if (isIdentity)
            {
                AppendSql(" GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1)");
            }
        }
Esempio n. 6
0
        private void AppendType(EdmProperty column)
        {
            TypeUsage typeUsage = column.TypeUsage;
            bool      flag      = false;
            Facet     facet;

            if (typeUsage.EdmType.Name == "binary" && 8 == typeUsage.GetMaxLength() && (column.TypeUsage.Facets.TryGetValue("StoreGeneratedPattern", false, out facet) && facet.Value != null) && StoreGeneratedPattern.Computed == (StoreGeneratedPattern)facet.Value)
            {
                flag = true;
                this.AppendIdentifier("rowversion");
            }
            else
            {
                string name = typeUsage.EdmType.Name;
                if (typeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType && name.EndsWith("(max)", StringComparison.Ordinal))
                {
                    this.AppendIdentifier(name.Substring(0, name.Length - "(max)".Length));
                    this.AppendSql("(max)");
                }
                else
                {
                    this.AppendIdentifier(name);
                }
                switch (typeUsage.EdmType.Name)
                {
                case "decimal":
                case "numeric":
                    this.AppendSqlInvariantFormat("({0}, {1})", (object)typeUsage.GetPrecision(), (object)typeUsage.GetScale());
                    break;

                case "datetime2":
                case "datetimeoffset":
                case "time":
                    this.AppendSqlInvariantFormat("({0})", (object)typeUsage.GetPrecision());
                    break;

                case "binary":
                case "varbinary":
                case "nvarchar":
                case "varchar":
                case "char":
                case "nchar":
                    this.AppendSqlInvariantFormat("({0})", (object)typeUsage.GetMaxLength());
                    break;
                }
            }
            this.AppendSql(column.Nullable ? " null" : " not null");
            if (flag || !column.TypeUsage.Facets.TryGetValue("StoreGeneratedPattern", false, out facet) || (facet.Value == null || (StoreGeneratedPattern)facet.Value != StoreGeneratedPattern.Identity))
            {
                return;
            }
            if (typeUsage.EdmType.Name == "uniqueidentifier")
            {
                this.AppendSql(" default newid()");
            }
            else
            {
                this.AppendSql(" identity");
            }
        }