// check grouping arguments against null internal static QueryTalkException IsGroupingNull(this GroupingArgument[] arguments, string method) { QueryTalkException exception = null; // check collection if (arguments == null || arguments.Length == 0) { exception = new QueryTalkException( "Sys.GroupingId", QueryTalkExceptionType.CollectionNullOrEmpty, "arguments = undefined", method); } // check each item if (arguments != null && arguments.Where(argument => argument == null).Any()) { exception = new QueryTalkException( "Sys.GroupingId", QueryTalkExceptionType.CollectionNullOrEmpty, "argument = undefined", method); } return(exception); }
internal void TryTakeException(QueryTalkException from) { if (chainException == null && from != null) { chainException = from; } }
internal SysFn(Func <BuildContext, BuildArgs, string> buildMethod, QueryTalkException exception = null) : base(null) { chainException = exception; Build = buildMethod; }
private QueryTalkException JoinerColumnNotBoundException(DbColumn column) { QueryTalkException exception; var col = (column.IsAuto) ? Text.Asterisk : column.ColumnMap.Name.Sql; if (column.OfAlias != null) { exception = new QueryTalkException(this, QueryTalkExceptionType.ColumnNotBound, String.Format("mapped column = {0}.{1}.Of({2})", column.Parent.Name, col, column.OfAlias), Text.Method.Of); } else { exception = new QueryTalkException(this, QueryTalkExceptionType.ColumnNotBound, String.Format("mapped column = {0}.{1}", column.Parent.Name, col)); } if (_buildContext.Current is SelectChainer && ((SelectChainer)_buildContext.Current).IsCollect) { exception.SetExtra("Mapped columns cannot be used in the .Collect method."); } return(exception); }
internal static bool CheckTransactionName(string nameOrVariable, Designer root, out QueryTalkException exception) { exception = null; if (nameOrVariable != null) { var check = Common.CheckIdentifier(nameOrVariable); if ((check != IdentifierValidity.RegularIdentifier && check != IdentifierValidity.Variable) || nameOrVariable.Length > 32) { exception = new QueryTalkException("Common.CheckTransactionName", QueryTalkExceptionType.InvalidTransactionName, String.Format("nameOrVariable = {0}", nameOrVariable)); return(false); } if (check == IdentifierValidity.Variable) { if (root.VariableExists(nameOrVariable) == false) { exception = new QueryTalkException("Common.CheckTransactionName", QueryTalkExceptionType.ParamOrVariableNotDeclared, String.Format("nameOrvariable = {0}", nameOrVariable)); return(false); } } else { if (!CheckReservedName("Common.CheckTransactionName", nameOrVariable, out exception)) { return(false); } } } return(true); }
internal Variable TryGetVariable(Designer root, out QueryTalkException exception) { exception = null; if (root == null) { return(null); } string variableName = null; if (Original != null) { if (Original is System.String) { variableName = (string)Original; } else if (Original is ColumnAsChainer) { variableName = ((IColumnName)Original).ColumnName; } } if (variableName == null) { return(null); } return(root.TryGetVariable(variableName, out exception)); }
// Checks if a given type is QueryTalk compliant CLR type and if it matches the given SQL type. internal static bool CheckSqlCompliance(Type type, DT sqlType, out QueryTalkException exception) { exception = null; Type clrType; var clrCheck = CheckClrCompliance(type, out clrType, out exception); if (clrCheck != ClrTypeMatch.ClrMatch) { return(false); } // sql_variant can map to any supported CLR type if (sqlType == DT.Sqlvariant) { return(true); } if (Mapping.SqlMapping[sqlType].ClrSubTypes.Contains(clrType)) { return(true); } SqlMappingInfo info = SqlMapping[sqlType]; if (info.ClrType != clrType) { exception = new QueryTalkException("TypeMapping.CheckSqlCompliance", QueryTalkExceptionType.ParamArgumentTypeMismatch, null); return(false); } return(true); }
// Checks if argument's type matches the parameter's data type. internal static bool CheckArgument(Variable param, Type argumentType, out QueryTalkException exception) { exception = null; if (param.DT.IsNameType()) { return(true); } if (argumentType == null) { return(true); } if (param.DT.IsInliner()) { CheckInlineType(argumentType, param.DT, out exception); } else { CheckSqlCompliance(argumentType, param.DT, out exception); } return(exception == null); }
// infer param from param argument internal static Variable InferParam(Designer root, ParameterArgument argument, out QueryTalkException exception, string name = null) { exception = null; Variable param; long variableIndex = 0; if (argument.DT.IsDataType()) { param = new Variable(argument.DataType); } else { if (argument.DT.IsTable()) { var view = (View)argument.Original; if (view.UserDefinedType == null) { exception = new QueryTalkException("Variable.InferParam", QueryTalkExceptionType.MissingDataViewUdt, null); return(null); } var udt = view.UserDefinedType; variableIndex = Designer.GetVariableGuid(); // important! param = new Variable(variableIndex, name, argument.DT, udt, IdentifierType.Param); } else { var dataType = DbInferenceBaseType; if (!argument.IsUndefined() && argument.ArgType != null) { // special handling of a variable passed by .Output if (argument.IsArgumentOutput) { dataType = DT.VarcharMax.ToDataType(); } // other data type else { dataType = Mapping.ClrMapping[argument.ArgType].DefaultDataType; } } param = new Variable(dataType, name); argument.DataType = dataType; } } if (name == null) { if (variableIndex == 0) { variableIndex = root.GetVariableIndex(); // cannot be mistaken with guid method } param.SetNameByOrdinal(variableIndex); } param.IsOutput = argument.IsArgumentOutput; return(param); }
internal static QueryTalkException ClrException(System.Exception ex, string name, string method, string arguments = null) { QueryTalkException exception = new QueryTalkException("Crud", QueryTalkExceptionType.ClrException, name, method, arguments); exception.ClrException = ex; return(exception); }
internal static void TryThrowException(QueryTalkException exception, Connectable connectable) { if (exception != null) { exception.ObjectName = ((IName)connectable.Executable).Name; exception.Method = Text.Method.Go; throw exception; } }
private static QueryTalkException ClrException(System.Exception ex) { var exception = new QueryTalkException("TestingForm", QueryTalkExceptionType.ClrException, null, Wall.Text.Method.Test); exception.ClrException = ex; return(exception); }
private static QueryTalkException MissingConnectionFuncException(Assembly client) { var exception = new QueryTalkException( "ConnectionManager.InvokeConnectionFunc", QueryTalkExceptionType.MissingConnectionFunc, String.Format("assembly = {0}", client), Text.Method.SetConnection); throw exception; }
// Throw InvalidSqlOperationException if SQL error number is 305 or 402. // SQL server does not allow that the following data types: // - xml // - text // - ntext // - image // are used in the predicates (e.g. equal operator). internal static void TryThrowInvalidSqlOperationException(QueryTalkException ex, string objectName, string method = null) { var errorNumber = ex.SqlErrorNumber; if (errorNumber == 305 || errorNumber == 402) { throw new QueryTalkException("Loader", QueryTalkExceptionType.InvalidSqlOperationException, objectName, method ?? ex.Method, null); } }
internal bool CheckNullOrEmpty(Tuple <string, ICollection> arg, string method = null) { if (arg.Item2.IsUndefined(true) || arg.Item2.Count == 0) { chainException = new QueryTalkException(this, QueryTalkExceptionType.CollectionNullOrEmpty, String.Format("{0}", arg.Item1)); chainException.Method = method ?? Method; return(false); } return(true); }
internal SysFn(string sql, QueryTalkException exception = null) : base(null) { chainException = exception; Build = (buildContext, buildArgs) => { return(sql); }; DebugValue = sql; }
internal bool CheckNull(Tuple <string, object> arg, string method = null) { if (arg.Item2.IsUndefined(true)) { chainException = new QueryTalkException(this, QueryTalkExceptionType.ArgumentNull, String.Format("{0}", arg.Item1)); chainException.Method = method ?? Method; return(false); } return(true); }
internal bool CheckNullOrEmptyAlias(string alias, string method = null) { if (String.IsNullOrEmpty(alias)) { chainException = new QueryTalkException(this, QueryTalkExceptionType.AliasNullOrEmpty, "alias = null/empty", method ?? Method); return(false); } return(true); }
// checks if param allows null argument internal bool ParamNullCheck(out QueryTalkException exception) { exception = null; if (DT.IsTable() || !IsNullable) { exception = new QueryTalkException("Variable.NullCheck", QueryTalkExceptionType.ParamArgumentNull, null); return(false); } return(true); }
// 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('.')); }
internal static bool CheckNameFormat(string variable, out QueryTalkException exception) { exception = null; if (Regex.IsMatch(variable, @"^@\d+$")) { exception = new QueryTalkException("Variable.TryValidateName", QueryTalkExceptionType.InvalidVariableName, String.Format("param/variable = {0}", variable)); return(false); } return(true); }
internal static string BuildDrop(string table, Designer root, out QueryTalkException exception) { exception = null; // check if a temp table exists - prevent dropping persistent tables if (root != null && !root.TempTableExists(table, true)) { exception = new QueryTalkException("DropTempTableChainer.BuildDrop", QueryTalkExceptionType.UnknownTempTable, String.Format("temp table = {0}", table)); return(null); } return(BuildDropNoCheck(table)); }
internal static bool CheckReservedName(object exceptionCreator, string paramName, out QueryTalkException exception) { exception = null; if (Regex.IsMatch(Regex.Replace(paramName, "^@+", "").ToLower(System.Globalization.CultureInfo.InvariantCulture), "^" + Text.Reserved.ReservedPreffix)) { exception = new QueryTalkException(exceptionCreator, QueryTalkExceptionType.ReservedNamePrefix, String.Format("name = {0}", paramName)); return(false); } return(true); }
// try get variable from build context // Note: // The snippet object must be handled on different root (ParamRoot) than the procedure // since the params are not declared on the snippet's root but rather on the master proc's root. internal Variable TryGetVariable( string variableName, out QueryTalkException exception, Variable.SearchType searchType = Variable.SearchType.Any) { if (Root.CompilableType.IsViewOrSnippet()) { return(ParamRoot.TryGetVariable(variableName, out exception, searchType)); } else { return(Root.TryGetVariable(variableName, out exception, searchType)); } }
internal void TryThrow(QueryTalkException exception, string method = null) { if (exception != null) { chainException = exception; if (chainException.Method == null) { chainException.Method = method ?? Method; } chainException.ObjectName = chainException.ObjectName ?? ((Root is IName) ? ((IName)Root).Name : null); throw chainException; } }
internal static QueryTalkException ClrException( System.Exception ex, string readerName, Connectable connectable, string method, string arguments = null) { QueryTalkException exception = new QueryTalkException(String.Format("{0}.{1}", Text.Free.Reader, readerName), QueryTalkExceptionType.ClrException, ((IName)connectable).Name, method, arguments); exception.ClrException = ex; return(exception); }
internal static string BuildUnchecked(object value, out QueryTalkException exception) { exception = null; if (value == null) { return(Text.Null); } Type type = value.GetType(); if (type == typeof(DBNull) || type == typeof(System.Object)) { return(Text.Null); } if (type == typeof(View)) { return(((View)value).Sql); } if (type == typeof(Value)) { var data = (Value)value; if (data == Designer.Null) { return(Text.Null); } type = data.ClrType; value = data.Original; } Type clrType; if (Mapping.CheckClrCompliance(type, out clrType, out exception) == ClrTypeMatch.ClrMatch) { if (clrType == typeof(System.Object)) { return(Text.Null); } return(Build(value, clrType)); } else { return(null); } }
internal TopChainer(Chainer prev, string topVariable, bool isWithTies) : base(prev) { var variable = GetRoot().TryGetVariable(topVariable, out chainException); // check inliner: disallowed if (variable.IsInliner()) { chainException = new QueryTalkException("Ctop..ctor", QueryTalkExceptionType.InvalidInliner, String.Format("inliner = {0}", topVariable)); } TryThrow(); GetPrev <SelectChainer>().SetTop(variable, isWithTies); }
internal static string ProcessVariable( string argument, BuildContext buildContext, BuildArgs buildArgs, out QueryTalkException exception) { exception = null; var variable = buildContext.TryGetVariable(argument, out exception); if (exception != null) { return(null); } if (variable == null) { if (Variable.Detect(argument)) { if (buildContext.Root.CompilableType.IsProc() || (buildContext.Root.CompilableType == Compilable.ObjectType.View && buildContext.Query.Master.Root.CompilableType.IsProc())) { buildContext.Exception = new QueryTalkException("Variable.ProcessVariable", QueryTalkExceptionType.ParamOrVariableNotDeclared, String.Format("variable = {0}", argument)); return(null); } } return(null); } buildContext.TryTakeException(variable.DisallowedInliningException()); if (buildContext.Exception != null) { return(null); } if (variable.IsConcatenator()) { return(Argument.BuildConcatenator(buildContext, buildArgs, variable)); } buildContext.TryAddParamToConcatRoot(variable); return(null); }
// regular ctor // isInternal : indicates that the alias is assigned internally - as an integer number (e.g. by SEMQ) internal AliasAs(Chainer prev, string alias, bool isInternal = false) : base(prev) { if (IsTableAlias && alias == null) { IsDefault = true; } if (!isInternal && Common.CheckIdentifier(alias) != IdentifierValidity.RegularIdentifier) { chainException = new QueryTalkException("Alias.ctor", QueryTalkExceptionType.InvalidAlias, ArgVal(() => alias, alias)); } _value = alias; }