Example #1
0
        internal static string GetVersionHint(EFOracleVersion version)
        {
            switch (version)
            {
            case EFOracleVersion.Oracle11gR1:
                return("11.1");

            case EFOracleVersion.Oracle11gR2:
                return("11.2");

            case EFOracleVersion.Oracle12cR1:
                return("12.1");

            case EFOracleVersion.Oracle12cR2:
                return("12.2");

            case EFOracleVersion.Oracle9iR2:
                return("9.2");

            case EFOracleVersion.Oracle10gR1:
                return("10.1");

            case EFOracleVersion.Oracle10gR2:
                return("10.2");

            default:
                throw new ArgumentException(EFProviderSettings.Instance.GetErrorMessage(-1202, "ProviderManifestToken"));
            }
        }
 internal ExpressionTranslator(StringBuilder commandText, DbModificationCommandTree commandTree, bool preserveMemberValues, EFOracleVersion version)
 {
     this._commandText  = commandText;
     this._commandTree  = commandTree;
     this._version      = version;
     this._parameters   = new List <OracleParameter>();
     this._memberValues = preserveMemberValues ? new Dictionary <EdmMember, OracleParameter>() : (Dictionary <EdmMember, OracleParameter>)null;
 }
Example #3
0
 internal static bool IsVersionX(EFOracleVersion storageVersion)
 {
     if (storageVersion != EFOracleVersion.Oracle10gR1 && storageVersion != EFOracleVersion.Oracle10gR2 && (storageVersion != EFOracleVersion.Oracle11gR1 && storageVersion != EFOracleVersion.Oracle11gR2) && (storageVersion != EFOracleVersion.Oracle12cR1 && storageVersion != EFOracleVersion.Oracle12cR2))
     {
         return(storageVersion == EFOracleVersion.Oracle9iR2);
     }
     return(true);
 }
        public EFOracleProviderManifest(string manifestToken)
            : base(EFOracleProviderManifest.GetProviderManifest())
        {
            if (EFProviderSettings.s_tracingEnabled)
            {
                EFProviderSettings.Instance.Trace(EFProviderSettings.EFTraceLevel.Entry, " (ENTRY) EFOracleProviderManifest::EFOracleProviderManifest()\n");
            }
            this._version = EFOracleVersionUtils.GetStorageVersion(manifestToken);
            this._token   = manifestToken;
            ODTSettings.FireEdmInUseEvent();
            EFOracleProviderManifest.m_bMapNumberToBoolean = false;
            int maxPrecision1;

            if ((maxPrecision1 = EFProviderSettings.Instance.GetMaxPrecision("BOOL", true)) > 0)
            {
                EFOracleProviderManifest.m_edmMappingMaxBOOL   = maxPrecision1;
                EFOracleProviderManifest.m_bMapNumberToBoolean = true;
            }
            else
            {
                EFOracleProviderManifest.m_edmMappingMaxBOOL = 1;
            }
            EFOracleProviderManifest.m_bMapNumberToByte = false;
            int maxPrecision2;

            if ((maxPrecision2 = EFProviderSettings.Instance.GetMaxPrecision("BYTE", true)) > 0)
            {
                EFOracleProviderManifest.m_edmMappingMaxBYTE = maxPrecision2;
                EFOracleProviderManifest.m_bMapNumberToByte  = true;
            }
            else
            {
                EFOracleProviderManifest.m_edmMappingMaxBYTE = 3;
            }
            int maxPrecision3;

            EFOracleProviderManifest.m_edmMappingMaxINT16 = (maxPrecision3 = EFProviderSettings.Instance.GetMaxPrecision("INT16", true)) <= 0 ? 5 : maxPrecision3;
            int maxPrecision4;

            EFOracleProviderManifest.m_edmMappingMaxINT32 = (maxPrecision4 = EFProviderSettings.Instance.GetMaxPrecision("INT32", true)) <= 0 ? 10 : maxPrecision4;
            int maxPrecision5;

            EFOracleProviderManifest.m_edmMappingMaxINT64 = (maxPrecision5 = EFProviderSettings.Instance.GetMaxPrecision("INT64", true)) <= 0 ? 19 : maxPrecision5;
            if (!EFProviderSettings.s_tracingEnabled)
            {
                return;
            }
            EFProviderSettings.Instance.Trace(EFProviderSettings.EFTraceLevel.Entry, " (EXIT)  EFOracleProviderManifest::EFOracleProviderManifest()\n");
        }
        internal static string GenerateInsertSql(DbInsertCommandTree tree, EFOracleProviderManifest providerManifest, EFOracleVersion sqlVersion, out List <OracleParameter> parameters)
        {
            StringBuilder commandText = new StringBuilder(256);

            DmlSqlGenerator.ExpressionTranslator translator = new DmlSqlGenerator.ExpressionTranslator(commandText, (DbModificationCommandTree)tree, null != tree.Returning, sqlVersion);
            commandText.Append("insert into ");
            tree.Target.Expression.Accept((DbExpressionVisitor)translator);
            if (0 < tree.SetClauses.Count)
            {
                commandText.Append("(");
                bool flag1 = true;
                foreach (DbSetClause setClause in (IEnumerable <DbModificationClause>)tree.SetClauses)
                {
                    if (flag1)
                    {
                        flag1 = false;
                    }
                    else
                    {
                        commandText.Append(", ");
                    }
                    setClause.Property.Accept((DbExpressionVisitor)translator);
                }
                commandText.AppendLine(")");
                bool flag2 = true;
                commandText.Append("values (");
                foreach (DbSetClause setClause in (IEnumerable <DbModificationClause>)tree.SetClauses)
                {
                    if (flag2)
                    {
                        flag2 = false;
                    }
                    else
                    {
                        commandText.Append(", ");
                    }
                    setClause.Value.Accept((DbExpressionVisitor)translator);
                    translator.RegisterMemberValue(setClause.Property, setClause.Value);
                }
                commandText.AppendLine(")");
            }
            else
            {
                commandText.AppendLine().AppendLine(" values (default)");
            }
            DmlSqlGenerator.GenerateReturningSql(commandText, (DbModificationCommandTree)tree, translator, tree.Returning, providerManifest, sqlVersion, false);
            parameters = translator.Parameters;
            return(commandText.ToString());
        }
        internal static string GenerateDeleteSql(DbDeleteCommandTree tree, EFOracleProviderManifest providerManifest, EFOracleVersion sqlVersion, out List <OracleParameter> parameters)
        {
            StringBuilder commandText = new StringBuilder(256);

            DmlSqlGenerator.ExpressionTranslator expressionTranslator = new DmlSqlGenerator.ExpressionTranslator(commandText, (DbModificationCommandTree)tree, false, sqlVersion);
            commandText.Append("delete ");
            tree.Target.Expression.Accept((DbExpressionVisitor)expressionTranslator);
            commandText.AppendLine();
            commandText.Append("where ");
            tree.Predicate.Accept((DbExpressionVisitor)expressionTranslator);
            parameters = expressionTranslator.Parameters;
            return(commandText.ToString());
        }
        internal static string GenerateUpdateSql(DbUpdateCommandTree tree, EFOracleProviderManifest providerManifest, EFOracleVersion sqlVersion, out List <OracleParameter> parameters)
        {
            StringBuilder commandText = new StringBuilder(256);

            DmlSqlGenerator.ExpressionTranslator translator = new DmlSqlGenerator.ExpressionTranslator(commandText, (DbModificationCommandTree)tree, null != tree.Returning, sqlVersion);
            int count = tree.SetClauses.Count;

            commandText.Append("update ");
            tree.Target.Expression.Accept((DbExpressionVisitor)translator);
            commandText.AppendLine();
            bool flag = true;

            commandText.Append("set ");
            foreach (DbSetClause setClause in (IEnumerable <DbModificationClause>)tree.SetClauses)
            {
                if (flag)
                {
                    flag = false;
                }
                else
                {
                    commandText.Append(", ");
                }
                setClause.Property.Accept((DbExpressionVisitor)translator);
                commandText.Append(" = ");
                setClause.Value.Accept((DbExpressionVisitor)translator);
            }
            if (flag)
            {
                commandText.Append("[place_holder] ");
            }
            commandText.AppendLine();
            commandText.Append("where ");
            tree.Predicate.Accept((DbExpressionVisitor)translator);
            if (flag)
            {
                string str      = commandText.ToString();
                int    num      = str.IndexOf("where ");
                string newValue = str.Substring(num + "where ".Length).Replace("(", "").Replace(")", "").Replace(" and ", " ,");
                commandText.Replace("[place_holder]", newValue);
            }
            commandText.AppendLine();
            DmlSqlGenerator.GenerateReturningSql(commandText, (DbModificationCommandTree)tree, translator, tree.Returning, providerManifest, sqlVersion, true);
            parameters = translator.Parameters;
            return(commandText.ToString());
        }
        private static void GenerateReturningSql(StringBuilder commandText, DbModificationCommandTree tree, DmlSqlGenerator.ExpressionTranslator translator, DbExpression returning, EFOracleProviderManifest providerManifest, EFOracleVersion sqlVersion, bool isUpdate)
        {
            if (returning == null)
            {
                return;
            }
            EntitySetBase target        = ((DbScanExpression)tree.Target.Expression).Target;
            StringBuilder stringBuilder = new StringBuilder(50);

            stringBuilder.Append("declare\n");
            Dictionary <EdmMember, string> dictionary = new Dictionary <EdmMember, string>();

            foreach (EdmMember member in target.ElementType.Members)
            {
                ReadOnlyMetadataCollection <Facet> facets = ((TypeUsage)member.MetadataProperties["TypeUsage"].Value).Facets;
                string empty = string.Empty;
                if (facets.Contains("StoreGeneratedPattern"))
                {
                    string str = facets["StoreGeneratedPattern"].Value.ToString();
                    if (!string.IsNullOrEmpty(str))
                    {
                        if (isUpdate && str.ToUpperInvariant() == "COMPUTED")
                        {
                            dictionary[member] = str;
                        }
                        else if (!isUpdate && (str.ToUpperInvariant() == "COMPUTED" || str.ToUpperInvariant() == "IDENTITY"))
                        {
                            dictionary[member] = str;
                        }
                    }
                }
                if (dictionary.ContainsKey(member))
                {
                    stringBuilder.Append(DmlSqlGenerator.GenerateMemberTSql(member));
                    stringBuilder.Append(" ");
                    stringBuilder.Append(SqlGenerator.GetSqlPrimitiveType((DbProviderManifest)providerManifest, sqlVersion, member.TypeUsage));
                    stringBuilder.Append(";\n");
                }
            }
            stringBuilder.Append("begin\n");
            commandText.Insert(0, stringBuilder.ToString());
            OracleParameter parameter = translator.CreateParameter(OracleDbType.RefCursor, ParameterDirection.Output);

            commandText.Append("returning\n");
            string str1 = string.Empty;

            foreach (EdmMember member in target.ElementType.Members)
            {
                if (dictionary.ContainsKey(member))
                {
                    commandText.Append(str1);
                    commandText.Append(DmlSqlGenerator.GenerateMemberTSql(member));
                    str1 = ", ";
                }
            }
            commandText.Append(" into\n");
            string str2 = string.Empty;

            foreach (EdmMember member in target.ElementType.Members)
            {
                if (dictionary.ContainsKey(member))
                {
                    commandText.Append(str2);
                    commandText.Append(DmlSqlGenerator.GenerateMemberTSql(member));
                    str2 = ", ";
                }
            }
            commandText.Append(";\n");
            commandText.Append("open ");
            commandText.Append(parameter.ParameterName);
            commandText.Append(" for select\n");
            string str3 = string.Empty;

            foreach (EdmMember member in target.ElementType.Members)
            {
                if (dictionary.ContainsKey(member))
                {
                    commandText.Append(str3);
                    commandText.Append(DmlSqlGenerator.GenerateMemberTSql(member));
                    commandText.Append(" as ");
                    commandText.Append(DmlSqlGenerator.GenerateMemberTSql(member));
                    str3 = ", ";
                }
            }
            commandText.Append(" from dual;\n");
            commandText.Append("end;");
        }