Ejemplo n.º 1
0
        // Delimits a multi-part identifier or param (and sets the columnName argument).
        internal static string DelimitMultiPartOrParam(
            string identifier,
            IdentifierType identifierType,
            out QueryTalkException exception,
            out string columnName
            )
        {
            exception  = null;
            columnName = null;

            // leave variable/param as is
            if (Variable.TryValidateName(identifier, out exception))
            {
                return(identifier);
            }

            if (exception != null)
            {
                return(identifier);
            }

            StringBuilder parts = new StringBuilder();

            string[] names = identifier.Split('.');

            if (names.Length > 4)
            {
                exception = new QueryTalkException("Filter.DelimitMultiPartOrParam",
                                                   QueryTalkExceptionType.InvalidIdentifier,
                                                   String.Format("identifier = {0}", identifier));
                return(identifier);
            }

            if (identifierType == IdentifierType.ColumnOrParam && names.Length > 2)
            {
                exception = new QueryTalkException("Filter.DelimitMultiPartOrParam",
                                                   QueryTalkExceptionType.InvalidColumnIdentifier,
                                                   String.Format("identifier = {0}", identifier));
                return(identifier);
            }

            // valid column identifier:

            columnName = names[names.Length - 1];

            Array.ForEach(names, name =>
            {
                parts.Append(Filter.DelimitNonAsterix(name) + ".");
            });

            return(parts.ToString().TrimEnd('.'));
        }
Ejemplo n.º 2
0
        // check the variable name validity
        private void CheckAndThrow()
        {
            CheckNullAndThrow(Arg(() => _variableName, _variableName));

            bool check = Variable.TryValidateName(_variableName, out chainException);

            TryThrow();

            if (!check)
            {
                Throw(QueryTalkExceptionType.InvalidVariableName, ArgVal(() => _variableName, _variableName));
            }
        }
Ejemplo n.º 3
0
        internal static void CheckAndThrow(string variable, Designer root, string method, string[] variables = null)
        {
            QueryTalkException exception;

            root.CheckNull(Chainer.Arg(() => variable, variable), method);
            if (root.chainException != null)
            {
                if (variables != null)
                {
                    root.chainException.Arguments = String.Format("variable name = null{0}   variables = ({1})",
                                                                  Environment.NewLine,
                                                                  String.Join(", ", variables.Select(v => v ?? Text.ClrNull)));
                }
                else
                {
                    root.chainException.Arguments = "variable name = null";
                }

                root.TryThrow(root.chainException, method);
            }

            bool check = Variable.TryValidateName(variable, out exception);

            root.TryThrow(exception, method);

            if (!check)
            {
                exception = new QueryTalkException("SetChainer.CheckAndThrow",
                                                   QueryTalkExceptionType.InvalidVariableName,
                                                   Chainer.ArgVal(() => variable, variable));
                root.TryThrow(exception, method);
            }

            if (root.VariableExists(variable) == false)
            {
                root.Throw(QueryTalkExceptionType.ParamOrVariableNotDeclared,
                           Chainer.ArgVal(() => variable, variable),
                           method);
            }
        }