// <summary>
        // Generates function definition or returns a cached one.
        // Guarantees type match of declaration and generated parameters.
        // Guarantees return type match.
        // Throws internal error for functions without definition.
        // Passes thru exceptions occured during definition generation.
        // </summary>
        internal DbLambda GenerateFunctionDefinition(EdmFunction function)
        {
            Debug.Assert(function.IsModelDefinedFunction, "Function definition can be requested only for user-defined model functions.");
            if (!function.HasUserDefinedBody)
            {
                throw new InvalidOperationException(Strings.Cqt_UDF_FunctionHasNoDefinition(function.Identity));
            }

            DbLambda generatedDefinition;

            // Generate the body
            generatedDefinition = ExternalCalls.CompileFunctionDefinition(
                function.CommandTextAttribute,
                function.Parameters,
                this);

            // Ensure the result type of the generated definition matches the result type of the edm function (the declaration)
            if (!TypeSemantics.IsStructurallyEqual(function.ReturnParameter.TypeUsage, generatedDefinition.Body.ResultType))
            {
                throw new InvalidOperationException(
                          Strings.Cqt_UDF_FunctionDefinitionResultTypeMismatch(
                              function.ReturnParameter.TypeUsage.ToString(),
                              function.FullName,
                              generatedDefinition.Body.ResultType.ToString()));
            }

            Debug.Assert(generatedDefinition != null, "generatedDefinition != null");

            return(generatedDefinition);
        }
 internal static void AppendEscapedName(StringBuilder builder, string name)
 {
     if (CqlWriter._wordIdentifierRegex.IsMatch(name) && !ExternalCalls.IsReservedKeyword(name))
     {
         builder.Append(name);
     }
     else
     {
         string str = name.Replace("]", "]]");
         builder.Append('[').Append(str).Append(']');
     }
 }
Example #3
0
            public void setup()
            {
                // Set external state so the data is not stored localy
                ExternalCalls.setIsInIFrame(true);
                ExternalCalls.setIsInAuthor(false);

                _testMessagePipe = new TestMessagePipe();
                _transporter     = new Transporter(_testMessagePipe);

                Transporter.setSingleton(_transporter);
                TestHelpers.setUpTransporterInConnectedState(_transporter, _testMessagePipe);
            }
Example #4
0
        internal DbLambda GenerateFunctionDefinition(EdmFunction function)
        {
            if (!function.HasUserDefinedBody)
            {
                throw new InvalidOperationException(Strings.Cqt_UDF_FunctionHasNoDefinition((object)function.Identity));
            }
            DbLambda dbLambda = ExternalCalls.CompileFunctionDefinition(function.CommandTextAttribute, (IList <FunctionParameter>)function.Parameters, this);

            if (!TypeSemantics.IsStructurallyEqual(function.ReturnParameter.TypeUsage, dbLambda.Body.ResultType))
            {
                throw new InvalidOperationException(Strings.Cqt_UDF_FunctionDefinitionResultTypeMismatch((object)function.ReturnParameter.TypeUsage.ToString(), (object)function.FullName, (object)dbLambda.Body.ResultType.ToString()));
            }
            return(dbLambda);
        }
Example #5
0
        void longMethod(int param)
        {
            int i;
            int sum = 0;

            // ....
            // ....
            // ....
            for (i = 0; i < param * 45; i++)
            {
                if (i < 12 + param)
                {
                    sum = sum + i;
                }
                else
                {
                    sum = sum + 5;
                }
            }

            // ....
            // ....
            // ....

            for (i = 0; i < param * param; i++)
            {
                for (int j = 0; j < param; j++)
                {
                    if (i < getSomethingFromDB(globalVariable) + 50)
                    {
                        sum = sum + i;
                    }
                    else
                    {
                        sum = sum + param;
                    }
                }
            }
            // ....
            // ....
            // ....
            if (sum < param)
            {
                sum = sum + param;
                ExternalCalls.updateDB(sum);
            }
            // ....
            // ....
            // ....
        }
Example #6
0
 // effects: Modifies builder to contain an escaped version of "name"
 internal static void AppendEscapedName(StringBuilder builder, string name)
 {
     if (s_wordIdentifierRegex.IsMatch(name) && false == ExternalCalls.IsReservedKeyword(name))
     {
         // We do not need to escape the name if it is a simple name and it is not a keyword
         builder.Append(name);
     }
     else
     {
         string newName = name.Replace("]", "]]");
         builder.Append('[')
         .Append(newName)
         .Append(']');
     }
 }
Example #7
0
 private static bool TryParseView(
     string eSQL,
     bool isUserSpecified,
     EntitySetBase extent,
     StorageMappingItemCollection mappingItemCollection,
     ConfigViewGenerator config,
     out DbQueryCommandTree commandTree,
     out DiscriminatorMap discriminatorMap,
     out Exception parserException)
 {
     commandTree      = (DbQueryCommandTree)null;
     discriminatorMap = (DiscriminatorMap)null;
     parserException  = (Exception)null;
     config.StartSingleWatch(PerfType.ViewParsing);
     try
     {
         ParserOptions.CompilationMode compilationMode = ParserOptions.CompilationMode.RestrictedViewGenerationMode;
         if (isUserSpecified)
         {
             compilationMode = ParserOptions.CompilationMode.UserViewGenerationMode;
         }
         commandTree = (DbQueryCommandTree)ExternalCalls.CompileView(eSQL, mappingItemCollection, compilationMode);
         commandTree = ViewSimplifier.SimplifyView(extent, commandTree);
         if (extent.BuiltInTypeKind == BuiltInTypeKind.EntitySet)
         {
             DiscriminatorMap.TryCreateDiscriminatorMap((EntitySet)extent, commandTree.Query, out discriminatorMap);
         }
     }
     catch (Exception ex)
     {
         if (ex.IsCatchableExceptionType())
         {
             parserException = ex;
         }
         else
         {
             throw;
         }
     }
     finally
     {
         config.StopSingleWatch(PerfType.ViewParsing);
     }
     return(parserException == null);
 }
Example #8
0
        // <summary>
        // Given an extent and its corresponding view, invokes the parser to check if the view definition is syntactically correct.
        // Iff parsing succeeds: <paramref name="commandTree" /> and <paramref name="discriminatorMap" /> are set to the parse result and method returns true,
        // otherwise if parser has thrown a catchable exception, it is returned via <paramref name="parserException" /> parameter,
        // otherwise exception is re-thrown.
        // </summary>
        private static bool TryParseView(
            string eSQL,
            bool isUserSpecified,
            EntitySetBase extent,
            StorageMappingItemCollection mappingItemCollection,
            ConfigViewGenerator config,
            out DbQueryCommandTree commandTree,
            out DiscriminatorMap discriminatorMap,
            out Exception parserException)
        {
            commandTree      = null;
            discriminatorMap = null;
            parserException  = null;

            // We do not catch any internal exceptions any more
            config.StartSingleWatch(PerfType.ViewParsing);
            try
            {
                // If it is a user specified view, allow all queries. Otherwise parse the view in the restricted mode.
                var compilationMode = ParserOptions.CompilationMode.RestrictedViewGenerationMode;
                if (isUserSpecified)
                {
                    compilationMode = ParserOptions.CompilationMode.UserViewGenerationMode;
                }

                Debug.Assert(!String.IsNullOrEmpty(eSQL), "eSQL query is not specified");
                commandTree = (DbQueryCommandTree)ExternalCalls.CompileView(eSQL, mappingItemCollection, compilationMode);

                commandTree = ViewSimplifier.SimplifyView(extent, commandTree);

                // See if the view matches the "discriminated" pattern (allows simplification of generated store commands)
                if (extent.BuiltInTypeKind
                    == BuiltInTypeKind.EntitySet)
                {
                    if (DiscriminatorMap.TryCreateDiscriminatorMap((EntitySet)extent, commandTree.Query, out discriminatorMap))
                    {
                        Debug.Assert(discriminatorMap != null, "discriminatorMap == null after it has been created");
                    }
                }
            }
            catch (Exception e)
            {
                // Catching all the exception types since Query parser seems to be throwing a variety of
                // exceptions - EntityException, ArgumentException, ArgumentNullException etc.
                if (e.IsCatchableExceptionType())
                {
                    parserException = e;
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                config.StopSingleWatch(PerfType.ViewParsing);
            }

            Debug.Assert(commandTree != null || parserException != null, "Either commandTree or parserException is expected.");
            // Note: m_commandTree might have been initialized by a previous call to this method, so in consequent calls it might occur that
            // both m_commandTree and parserException are not null - this would mean that the last parse attempt failed, but m_commandTree value is
            // preserved from the previous call.

            return(parserException == null);
        }
Example #9
0
        public static IPAddress[] ResolveAll(String hostname)
        {
            IPAddress lAddress = TryStringAsIPAddress(hostname);

            if (lAddress != null)
            {
                return(new IPAddress[] { lAddress });
            }

                        #if echoes
            IPHostEntry lEntry = System.Net.Dns.GetHostEntry(hostname);
            return(lEntry.AddressList);
                        #elif cooper
            var lTemp      = java.net.InetAddress.getAllByName(hostname);
            var lAddresses = new IPAddress[lTemp.length];
            for (int i = 0; i < lTemp.length; i++)
            {
                lAddresses[i] = new IPAddress(lTemp[i].Address);
            }
            return(lAddresses);
                        #else
            var    lString    = (RemObjects.Elements.System.String)hostname;
            Byte[] lBytes     = new Byte[16];
            Byte[] lBytesIPv4 = new Byte[4];
            var    lAll       = new List <IPAddress>();

                        #if island && windows
            rtl.ADDRINFOW *  lAddrInfo;
            rtl.ADDRINFOW *  lPtr;
            rtl.ADDRINFOW    lJenson;
            rtl.SOCKADDR_IN *lSockAddrIPv4;
            sockaddr_in6 *   lSockAddr;
                        #elif posix || toffee
            rtl.__struct_addrinfo *    lAddrInfo;
            rtl.__struct_addrinfo *    lPtr;
            rtl.__struct_sockaddr_in * lSockAddrIPv4;
            rtl.__struct_sockaddr_in6 *lSockAddr;
                        #endif
                        #if toffee
            if (rtl.getaddrinfo(lString.UTF8String, null, null, &lAddrInfo) == 0)
                        #elif posix
            AnsiChar[] lHost = lString.ToAnsiChars(true);
            if (rtl.getaddrinfo(&lHost[0], null, null, &lAddrInfo) == 0)
            //if (rtl.getaddrinfo((AnsiChar *)lString.FirstChar, null, null, &lAddrInfo) == 0)
                        #elif island
            char[] lHost = lString.ToCharArray(true);
            ExternalCalls.memset(&lJenson, 0, sizeof(rtl.ADDRINFOW));
            lJenson.ai_family   = AddressFamily.Unspecified;
            lJenson.ai_socktype = rtl.SOCK_STREAM;
            lJenson.ai_protocol = ProtocolType.Tcp;
            rtl.WSADATA data;
            rtl.WSAStartup(rtl.WINSOCK_VERSION, &data);

            if (rtl.GetAddrInfoW(&lHost[0], null, null, &lAddrInfo) == 0)
                        #endif
            {
                                #if posix || toffee
                for (lPtr = lAddrInfo; lPtr != null; lPtr = (rtl.__struct_addrinfo *)lPtr->ai_next)
                                #else
                for (lPtr = lAddrInfo; lPtr != null; lPtr = (rtl.ADDRINFOW *)lPtr->ai_next)
                                #endif
                {
                    switch (lPtr->ai_family)
                    {
                    case AddressFamily.InterNetwork:
                                                        #if posix || toffee
                        lSockAddrIPv4 = (rtl.__struct_sockaddr_in *)(*lPtr).ai_addr;
                        lBytesIPv4[0] = (Byte)((*lSockAddrIPv4).sin_addr.s_addr);
                        lBytesIPv4[1] = (Byte)((*lSockAddrIPv4).sin_addr.s_addr >> 8);
                        lBytesIPv4[2] = (Byte)((*lSockAddrIPv4).sin_addr.s_addr >> 16);
                        lBytesIPv4[3] = (Byte)((*lSockAddrIPv4).sin_addr.s_addr >> 24);
                                                        #elif island && windows
                        lSockAddrIPv4 = (rtl.sockaddr_in *)(*lPtr).ai_addr;
                        lBytesIPv4[0] = (*lSockAddrIPv4).sin_addr.S_un.S_un_b.s_b1;
                        lBytesIPv4[1] = (*lSockAddrIPv4).sin_addr.S_un.S_un_b.s_b2;
                        lBytesIPv4[2] = (*lSockAddrIPv4).sin_addr.S_un.S_un_b.s_b3;
                        lBytesIPv4[3] = (*lSockAddrIPv4).sin_addr.S_un.S_un_b.s_b4;
                                                        #endif
                        lAll.Add(new IPAddress(lBytesIPv4));
                        break;

                    case AddressFamily.InterNetworkV6:
                                                        #if posix || toffee
                        lSockAddr = (rtl.__struct_sockaddr_in6 *)(*lPtr).ai_addr;
                                                        #elif island && windows
                        lSockAddr = (sockaddr_in6 *)(*lPtr).ai_addr;
                                                        #endif
                        for (int i = 0; i < 16 /*IPv6Length*/; i++)
                                                                #if posix
                        { lBytes[i] = (*lSockAddr).sin6_addr.__in6_u.__u6_addr8[i]; }
                                                                #elif toffee
                        { lBytes[i] = (*lSockAddr).sin6_addr.__u6_addr.__u6_addr8[i]; }
                                                                #else
                        { lBytes[i] = (*lSockAddr).sin6_addr.u.Byte[i]; }
                                                                #endif

                        var lNewAddress = new IPAddress(lBytes, (*lSockAddr).sin6_scope_id);
                        lAll.Add(lNewAddress);
                        break;
                    }
                }
                return(lAll.ToArray());
            }
            else
            {
                return(null);
            }
                        #endif
        }