public ParameterEditorScintillaSection(ParameterRefactorer refactorer, int lineStart, int lineEnd, ISqlParameter parameter, bool editable, string originalText) { _refactorer = refactorer; LineStart = lineStart; LineEnd = lineEnd; Parameter = parameter; Editable = editable; _querySyntaxHelper = parameter.GetQuerySyntaxHelper(); var prototype = ConstantParameter.Parse(originalText, _querySyntaxHelper); if (prototype.Value != parameter.Value) { throw new ArgumentException("Parameter " + parameter + " was inconsistent with the SQL passed to us based on QueryBuilder.DeconstructStringIntoParameter, they had different Values"); } if (prototype.ParameterSQL != parameter.ParameterSQL) { throw new ArgumentException("Parameter " + parameter + " was inconsistent with the SQL passed to us based on QueryBuilder.DeconstructStringIntoParameter, they had different ParameterSQL"); } if (prototype.Comment != parameter.Comment) { throw new ArgumentException("Parameter " + parameter + " was inconsistent with the SQL passed to us based on QueryBuilder.DeconstructStringIntoParameter, they had different Comment"); } }
/// <summary> /// Checks to ensure char based parameters contains a value, are not longer than the expected length and contain either single quotes or an @ symbol before performing bracket parity checks /// </summary> /// <param name="parameter"></param> public void CheckSyntax(ISqlParameter parameter) { if (string.IsNullOrWhiteSpace(parameter.Value)) { throw new SyntaxErrorException("Parameter " + parameter.ParameterName + " does not have a value"); } bool isCharBased = parameter.ParameterSQL.ToLower().Contains("char"); if (isCharBased && parameter.Value.Trim().StartsWith("'")) { Match matchValue = Regex.Match(parameter.Value, "'[^']*'"); Match matchLength = Regex.Match(parameter.ParameterSQL, "\\([0-9]*\\)"); if (matchValue.Success && matchLength.Success) { int userSpecifiedLength = Int32.Parse(matchLength.Value.Substring(1, matchLength.Value.Length - 2)); int actualLength = matchValue.Value.Trim().Length - 2; if (actualLength > userSpecifiedLength) { throw new SyntaxErrorException("You created a parameter of length " + userSpecifiedLength + " (" + parameter.ParameterName + ") but then put a value in it that is " + actualLength + " characters long, the parameter with the problem was:" + parameter.ParameterName); } } } if (isCharBased && !(parameter.Value.Contains("'") || parameter.Value.Contains("@"))) { throw new SyntaxErrorException("Parameter " + parameter.ParameterName + " looks like it is character based but it's value does not contain any single quotes (or at least a reference to another variable)"); } try { ParityCheckCharacterPairs(new[] { '(', '[', '\'' }, new[] { ')', ']', '\'' }, parameter.ParameterSQL); ParityCheckCharacterPairs(new[] { '(', '[', '\'' }, new[] { ')', ']', '\'' }, parameter.Value); } catch (SyntaxErrorException exception) { throw new SyntaxErrorException("Failed to validate the bracket parity of parameter " + parameter, exception); } if (!parameter.GetQuerySyntaxHelper().IsValidParameterName(parameter.ParameterSQL)) { throw new SyntaxErrorException("parameterSQL is not valid \"" + parameter.ParameterSQL + "\""); } }