예제 #1
0
    public static IDisposable OverrideOptions(ObjectNameOptions options)
    {
        var old = optionsVariable.Value;

        optionsVariable.Value = options;
        return(new Disposable(() => optionsVariable.Value = old));
    }
예제 #2
0
        /// <summary>
        /// Quotes the name of the SQL object in square brackets to allow Special characters in the object name.
        /// This function implements System.Data.SqlClient.SqlCommandBuilder.QuoteIdentifier() with an additional
        /// validation which is missing from the SqlCommandBuilder version.
        /// </summary>
        /// <param name="objectName">Name of the object to quote.</param>
        /// <param name="objectNameOptions">The settings which indicate if the whitespace should be dropped or not.</param>
        /// <returns>The quoted object name</returns>
        public static string QuoteSqlObjectName(string objectName, ObjectNameOptions objectNameOptions)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException();
            }

            if (ObjectNameOptions.Trim == objectNameOptions)
            {
                objectName = objectName.Trim();
            }

            const int SqlSysnameLength = 128;

            if (objectName.Length > SqlSysnameLength)
            {
                throw new ArgumentOutOfRangeException(@"objectName", "A SQL server object name is maximum 128 characters long");
            }

            // The ] in the string need to be doubled up so it means we always need an un-even number of ]
            if (objectName.StartsWith("[") && objectName.EndsWith("]") && objectName.Count(x => x == ']') % 2 == 1)
            {
                return(objectName);
            }

            return(string.Concat("[", objectName.Replace("]", "]]"), "]"));
        }
예제 #3
0
        public ManualEntryViewModel()
        {
            if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                return;
            }
            ObjectTypeOptions = new List <SqlServerObjectType>
            {
                new SqlServerObjectType("U", "Table"),
                new SqlServerObjectType("P", "Stored Procedure"),
                new SqlServerObjectType("V", "View"),
                new SqlServerObjectType("TF", "Table Function"),
                new SqlServerObjectType("FN", "Scalar Function")
            };

            Labels = new ObservableCollection <ProjectLabel>();
            Labels.AddRange(_rogueProjectRepository.GetProjectLabels().Select(x => new ProjectLabel(x)));
            Labels.Insert(0, new ProjectLabel {
                Name = "Select a Label"
            });
            SelectedLabel = Labels.FirstOrDefault();

            SelectedSqlServerObjectType = ObjectTypeOptions.Single(x => x.TypeCode == "P");
            SelectedDatabase            = DatabaseOptions.SingleOrDefault(x => x.DatabaseName.Equals("StoneEdgeRogue") && x.Environment == "NA");
            ObjectSchemaOptions         = _utilityRepository.GetDatabaseSchemaNames(SelectedDatabase?.DatabaseName);
            SelectedObjectSchema        = ObjectSchemaOptions.SingleOrDefault(x => x == "dbo");
            SelectedDeveloper           = DeveloperOptions.SingleOrDefault(x => x.DomainUserName.Equals(Environment.UserName));
            ReleaseDate = DateHelper.GetNextWeekday(DateTime.Now, DayOfWeek.Thursday);
            if (SelectedDatabase != null && SelectedObjectSchema != null)
            {
                ObjectNameOptions = _utilityRepository.GetObjectNames(SelectedDatabase.DatabaseName, SelectedObjectSchema, SelectedSqlServerObjectType.TypeCode);
            }
            SelectedObjectName = ObjectNameOptions.FirstOrDefault();
        }
예제 #4
0
 private void RefreshObjects(object o)
 {
     try {
         ActionMessage      = null;
         ObjectNameOptions  = _utilityRepository.GetObjectNames(SelectedDatabase.DatabaseName, SelectedObjectSchema, SelectedSqlServerObjectType.TypeCode);
         SelectedObjectName = ObjectNameOptions.FirstOrDefault();
     }
     catch (Exception e)
     {
         MessageBox.Show("Error in RefreshObjects: " + e.Message);
     }
 }
예제 #5
0
        /// <summary>
        /// Quotes the name of the SQL object in square brackets to allow Special characters in the object name.
        /// This function implements System.Data.SqlClient.SqlCommandBuilder.QuoteIdentifier() with an additional
        /// validation which is missing from the SqlCommandBuilder version.
        /// </summary>
        /// <param name="objectName">Name of the object to quote.</param>
        /// <param name="objectNameOptions">The settings which indicate if the whitespace should be dropped or not.</param>
        /// <returns>The quoted object name</returns>
        public static string QuoteSqlObjectName(string objectName, ObjectNameOptions objectNameOptions)
        {
            if (string.IsNullOrEmpty(objectName))
                throw new ArgumentNullException();

            if (ObjectNameOptions.Trim == objectNameOptions)
                objectName = objectName.Trim();

            const int SqlSysnameLength = 128;
            if (objectName.Length > SqlSysnameLength)
                throw new ArgumentOutOfRangeException(@"objectName", "A SQL server object name is maximum 128 characters long");

            // The ] in the string need to be doubled up so it means we always need an un-even number of ]
            if (objectName.StartsWith("[") && objectName.EndsWith("]") && objectName.Count(x => x == ']') % 2 == 1)
                return objectName;

            return string.Concat("[", objectName.Replace("]", "]]"), "]");
        }
예제 #6
0
        /// <summary>
        /// Quotes the name of the SQLite object in square brackets to allow Special characters in the object name.
        /// </summary>
        /// <param name="objectName">Name of the object to quote.</param>
        /// <param name="objectNameOptions">The settings which indicate if the whitespace should be dropped or not.</param>
        /// <returns>The quoted object name</returns>
        public static string QuoteSqlObjectName(string objectName, ObjectNameOptions objectNameOptions)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException();
            }

            if (ObjectNameOptions.Trim == objectNameOptions)
            {
                objectName = objectName.Trim();
            }

            // The ] in the string need to be doubled up so it means we always need an un-even number of ]
            if (objectName.StartsWith("[") && objectName.EndsWith("]") && objectName.Count(x => x == ']') % 2 == 1)
            {
                return(objectName);
            }

            return(string.Concat("[", objectName.Replace("]", "]]"), "]"));
        }
예제 #7
0
        /// <summary>
        /// Quotes the SQL object/identifier to allow Special characters in the object name.
        /// </summary>
        /// <param name="objectName">Name of the object / identifier to quote.</param>
        /// <param name="objectNameOptions">The settings which indicate if the whitespace should be dropped or not.</param>
        /// <returns>The quoted object name</returns>
        public virtual string QuoteIdentifier(string objectName, ObjectNameOptions objectNameOptions)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }

            if (objectNameOptions == ObjectNameOptions.Trim)
            {
                objectName = objectName.Trim();
            }

            // Don't double quote
            if (matchQuotes.IsMatch(objectName))
            {
                return(objectName);
            }

            return($"{quotePrefix}{objectName}{quoteSuffix}");
        }
예제 #8
0
        /// <summary>
        /// Quotes the name of the SQLite object in square brackets to allow Special characters in the object name.
        /// </summary>
        /// <param name="objectName">Name of the object to quote.</param>
        /// <param name="objectNameOptions">The settings which indicate if the whitespace should be dropped or not.</param>
        /// <returns>The quoted object name</returns>
        public virtual string QuoteIdentifier(string objectName, ObjectNameOptions objectNameOptions)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException();
            }

            if (ObjectNameOptions.Trim == objectNameOptions)
            {
                objectName = objectName.Trim();
            }

            // Don't double quote
            if (matchQuotes.IsMatch(objectName))
            {
                return(objectName);
            }

            // defer to sqlite command implementation.
            return($"{quotePrefix}{objectName}{quoteSuffix}");
        }
예제 #9
0
 private QueryFormatter()
 {
     objectNameOptions = ObjectName.CurrentOptions;
 }
예제 #10
0
 private QueryFormatter() 
 {
     objectNameOptions = ObjectName.CurrentOptions;
 }