internal static string DropDatabaseScript(string databaseName, StoreItemCollection itemCollection)
        {
            EFOracleDdlBuilder oracleDdlBuilder = new EFOracleDdlBuilder();

            foreach (EntityContainer entityContainer in itemCollection.GetItems <EntityContainer>())
            {
                entityContainer.BaseEntitySets.OfType <EntitySet>().OrderBy <EntitySet, string>((Func <EntitySet, string>)(s => s.Name));
                foreach (EntitySet entitySet in (IEnumerable <EntitySet>)entityContainer.BaseEntitySets.OfType <EntitySet>().OrderBy <EntitySet, string>((Func <EntitySet, string>)(s => s.Name)))
                {
                    oracleDdlBuilder.AppendSql("drop table ");
                    oracleDdlBuilder.AppendIdentifier(entitySet);
                    oracleDdlBuilder.AppendSql(" cascade constraints \n\n");
                    oracleDdlBuilder.AppendSql("drop sequence ");
                    oracleDdlBuilder.AppendIdentifier(EFOracleDdlBuilder.GetSchemaName(entitySet));
                    oracleDdlBuilder.AppendSql(".");
                    string str = OracleMigrationSqlGenerator.SequencePrefix + OracleMigrationSqlGenerator.NameSeparator + EFOracleDdlBuilder.GetTableName(entitySet);
                    if (Encoding.UTF8.GetByteCount(str) > OracleMigrationSqlGenerator.MaxIdentifierLengthBytes)
                    {
                        str = OracleMigrationSqlGenerator.DeriveObjectName((string)null, str, 30);
                    }
                    oracleDdlBuilder.AppendIdentifier(str);
                    oracleDdlBuilder.AppendSql("\n\n");
                }
            }
            oracleDdlBuilder.AppendSql("drop table ");
            oracleDdlBuilder.AppendIdentifier("__MigrationHistory");
            oracleDdlBuilder.AppendSql(" cascade constraints \n\n");
            oracleDdlBuilder.AppendSql("drop table ");
            oracleDdlBuilder.AppendIdentifier("EdmMetadata");
            oracleDdlBuilder.AppendSql(" cascade constraints \n\n");
            return(oracleDdlBuilder.stringBuilder.ToString());
        }
        internal static string CreateDatabaseExistsScript(string databaseName)
        {
            EFOracleDdlBuilder oracleDdlBuilder = new EFOracleDdlBuilder();

            oracleDdlBuilder.AppendSql("select count(*) from dual where upper(sys_context('userenv', 'db_name')) = ");
            oracleDdlBuilder.AppendStringLiteral(databaseName.ToUpper());
            return(oracleDdlBuilder.stringBuilder.ToString());
        }
        internal static string CreateTrigger(string TableName, EdmProperty column, string Operation, string SequencName)
        {
            EFOracleDdlBuilder oracleDdlBuilder = new EFOracleDdlBuilder();
            string             name             = column.TypeUsage.EdmType.Name;
            string             text             = (TableName.Length <= 14 ? TableName : TableName.Substring(0, 14)) + "_" + (column.Name.Length <= 13 ? column.Name : column.Name.Substring(0, 13));

            oracleDdlBuilder.AppendSql("create or replace trigger ");
            oracleDdlBuilder.AppendSql("\"");
            oracleDdlBuilder.AppendSql(text);
            oracleDdlBuilder.AppendSql("_");
            oracleDdlBuilder.AppendSql(Operation.Substring(0, 1));
            oracleDdlBuilder.AppendSql("\" \n");
            oracleDdlBuilder.AppendSql("before ");
            oracleDdlBuilder.AppendSql(Operation);
            oracleDdlBuilder.AppendSql(" on ");
            oracleDdlBuilder.AppendSql("\"");
            oracleDdlBuilder.AppendSql(TableName);
            oracleDdlBuilder.AppendSql("\"");
            oracleDdlBuilder.AppendSql(" for each row \n");
            oracleDdlBuilder.AppendSql("begin \n");
            if (Operation == "insert")
            {
                oracleDdlBuilder.AppendSql("  if :new.");
                oracleDdlBuilder.AppendSql("\"");
                oracleDdlBuilder.AppendSql(column.Name);
                oracleDdlBuilder.AppendSql("\"");
                oracleDdlBuilder.AppendSql(" is NULL then \n");
            }
            oracleDdlBuilder.AppendSql("    select ");
            if (name.ToLowerInvariant() == "guid")
            {
                oracleDdlBuilder.AppendSql("SYS_GUID ");
            }
            else if (name.ToLowerInvariant() == "date")
            {
                oracleDdlBuilder.AppendSql("SYSDATE ");
            }
            else
            {
                oracleDdlBuilder.AppendSql(SequencName);
                oracleDdlBuilder.AppendSql(".nextval ");
            }
            oracleDdlBuilder.AppendSql("into ");
            oracleDdlBuilder.AppendSql(":new.");
            oracleDdlBuilder.AppendSql("\"");
            oracleDdlBuilder.AppendSql(column.Name);
            oracleDdlBuilder.AppendSql("\"");
            oracleDdlBuilder.AppendSql(" from dual; \n ");
            if (Operation == "insert")
            {
                oracleDdlBuilder.AppendSql("  end if; \n");
            }
            oracleDdlBuilder.AppendSql("end;\n\n");
            return(oracleDdlBuilder.GetCommandText());
        }
        internal static string CreateTableExistsScript(StoreItemCollection itemCollection, out int count)
        {
            int num = 0;
            EFOracleDdlBuilder oracleDdlBuilder = new EFOracleDdlBuilder();

            oracleDdlBuilder.AppendSql("select count(*) from ");
            oracleDdlBuilder.AppendSql("all_tables");
            oracleDdlBuilder.AppendSql(" where ");
            foreach (EntityContainer entityContainer in itemCollection.GetItems <EntityContainer>())
            {
                entityContainer.BaseEntitySets.OfType <EntitySet>().OrderBy <EntitySet, string>((Func <EntitySet, string>)(s => s.Name));
                foreach (EntitySet entitySet in (IEnumerable <EntitySet>)entityContainer.BaseEntitySets.OfType <EntitySet>().OrderBy <EntitySet, string>((Func <EntitySet, string>)(s => s.Name)))
                {
                    string schemaName = EFOracleDdlBuilder.GetSchemaName(entitySet);
                    ++num;
                    if (num > 1)
                    {
                        oracleDdlBuilder.AppendSql(" or ");
                    }
                    oracleDdlBuilder.AppendSql("(");
                    oracleDdlBuilder.AppendSql("owner=");
                    if (entitySet.Name != "HistoryRow" || entitySet.Name == "HistoryRow" && schemaName != "dbo")
                    {
                        oracleDdlBuilder.AppendSql("'");
                        oracleDdlBuilder.AppendSql(schemaName);
                        oracleDdlBuilder.AppendSql("'");
                    }
                    else
                    {
                        oracleDdlBuilder.AppendSql("user");
                    }
                    oracleDdlBuilder.AppendSql(" and ");
                    oracleDdlBuilder.AppendSql("table_name=");
                    oracleDdlBuilder.AppendSql("'");
                    oracleDdlBuilder.AppendSql(EFOracleDdlBuilder.GetTableName(entitySet));
                    oracleDdlBuilder.AppendSql("'");
                    oracleDdlBuilder.AppendSql(")");
                }
            }
            count = num;
            return(oracleDdlBuilder.GetCommandText());
        }
        internal static string CreateObjectsScript(StoreItemCollection itemCollection, string providerManifestToken)
        {
            EFOracleDdlBuilder oracleDdlBuilder = new EFOracleDdlBuilder();

            foreach (EntityContainer entityContainer in itemCollection.GetItems <EntityContainer>())
            {
                entityContainer.BaseEntitySets.OfType <EntitySet>().OrderBy <EntitySet, string>((Func <EntitySet, string>)(s => s.Name));
                foreach (EntitySet entitySet in (IEnumerable <EntitySet>)entityContainer.BaseEntitySets.OfType <EntitySet>().OrderBy <EntitySet, string>((Func <EntitySet, string>)(s => s.Name)))
                {
                    oracleDdlBuilder.AppendCreateTable(entitySet, providerManifestToken);
                }
                foreach (AssociationSet associationSet in (IEnumerable <AssociationSet>)entityContainer.BaseEntitySets.OfType <AssociationSet>().OrderBy <AssociationSet, string>((Func <AssociationSet, string>)(s => s.Name)))
                {
                    oracleDdlBuilder.AppendCreateForeignKeys(associationSet);
                }
                for (int index = 0; index < EFOracleDdlBuilder.SequenceAndTriggerList.Count; ++index)
                {
                    oracleDdlBuilder.AppendSql(EFOracleDdlBuilder.SequenceAndTriggerList[index]);
                }
                EFOracleDdlBuilder.SequenceAndTriggerList.Clear();
            }
            return(oracleDdlBuilder.GetCommandText());
        }
        private void AppendIdentifier(EntitySet table, Action <string> AppendIdentifierEscape)
        {
            string tableName = EFOracleDdlBuilder.GetTableName(table);

            AppendIdentifierEscape(tableName);
        }
 private void AppendCreateTable(EntitySet entitySet, string providerManifestToken)
 {
     if (entitySet.MetadataProperties["DefiningQuery"].Value != null)
     {
         this.AppendSql("-- Ignoring entity set with defining query: ");
         this.AppendIdentifier(entitySet, new Action <string>(this.AppendIdentifierEscapeNewLine));
         this.ignoredEntitySets.Add(entitySet);
     }
     else
     {
         this.AppendSql("create table ");
         this.AppendIdentifier(entitySet);
         this.AppendSql(" (");
         this.AppendNewLine();
         foreach (EdmProperty property in entitySet.ElementType.Properties)
         {
             this.AppendSql("    ");
             this.AppendIdentifier(property.Name);
             this.AppendSql(" ");
             this.AppendType(property, providerManifestToken);
             this.AppendSql(",");
             this.AppendNewLine();
             if (EFOracleDdlBuilder.m_bCreateSequenceAndTrigger)
             {
                 string             tableName         = EFOracleDdlBuilder.GetTableName(entitySet);
                 string             text              = (tableName.Length <= 12 ? tableName : tableName.Substring(0, 12)) + "_" + (property.Name.Length <= 11 ? property.Name : property.Name.Substring(0, 11));
                 EFOracleDdlBuilder oracleDdlBuilder1 = new EFOracleDdlBuilder();
                 oracleDdlBuilder1.AppendSql("\"");
                 oracleDdlBuilder1.AppendSql(text);
                 oracleDdlBuilder1.AppendSql("_");
                 oracleDdlBuilder1.AppendSql(property.TypeUsage.EdmType.Name.Substring(0, 2));
                 oracleDdlBuilder1.AppendSql("_");
                 oracleDdlBuilder1.AppendSql("sq");
                 oracleDdlBuilder1.AppendSql("\"");
                 EFOracleDdlBuilder oracleDdlBuilder2 = new EFOracleDdlBuilder();
                 if (property.TypeUsage.EdmType.Name.ToLowerInvariant() != "guid" && property.TypeUsage.EdmType.Name.ToLowerInvariant() != "date")
                 {
                     oracleDdlBuilder2.AppendSql("create sequence ");
                     oracleDdlBuilder2.AppendSql(oracleDdlBuilder1.GetCommandText());
                     oracleDdlBuilder2.AppendSql(" start with 1");
                     oracleDdlBuilder2.AppendSql(";\n\n");
                 }
                 oracleDdlBuilder2.AppendSql(EFOracleDdlBuilder.CreateTrigger(EFOracleDdlBuilder.GetTableName(entitySet), property, "insert", oracleDdlBuilder1.GetCommandText()));
                 EFOracleDdlBuilder.m_bCreateSequenceAndTrigger = false;
                 if (EFOracleDdlBuilder.m_bStoreGeneratedPatternComputed)
                 {
                     oracleDdlBuilder2.AppendSql(EFOracleDdlBuilder.CreateTrigger(EFOracleDdlBuilder.GetTableName(entitySet), property, "update", oracleDdlBuilder1.GetCommandText()));
                 }
                 EFOracleDdlBuilder.m_bStoreGeneratedPatternComputed = false;
                 EFOracleDdlBuilder.SequenceAndTriggerList.Add(oracleDdlBuilder2.GetCommandText());
             }
         }
         this.AppendSql("CONSTRAINT \"PK_");
         this.AppendSql(EFOracleDdlBuilder.GetTableName(entitySet));
         this.AppendSql("\" primary key (");
         this.AppendJoin <EdmMember>((IEnumerable <EdmMember>)entitySet.ElementType.KeyMembers, (Action <EdmMember>)(k => this.AppendIdentifier(k.Name)), ", ");
         this.AppendSql(")");
         this.AppendNewLine();
         if (EFOracleDdlBuilder.GetTableName(entitySet) == "__MigrationHistory")
         {
             this.AppendSql(")\n\n");
         }
         else
         {
             this.AppendSql(");\n\n");
         }
     }
     this.AppendNewLine();
 }