コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="quoted"></param>
        /// <returns></returns>
        public override string UnQuote(string quoted)
        {
            if (IsQuoted(quoted))
            {
                quoted = quoted.Substring(1, quoted.Length - 2);
            }

            return(quoted.Replace(new string(CloseQuote, 2), CloseQuote.ToString()));
        }
コード例 #2
0
        public override string Qualify(string catalog, string schema, string table)
        {
            StringBuilder qualifiedName = new StringBuilder();
            bool          quoted        = false;

            if (!string.IsNullOrEmpty(catalog))
            {
                if (catalog.StartsWith(OpenQuote.ToString()))
                {
                    catalog = catalog.Substring(1, catalog.Length - 1);
                    quoted  = true;
                }
                if (catalog.EndsWith(CloseQuote.ToString()))
                {
                    catalog = catalog.Substring(0, catalog.Length - 1);
                    quoted  = true;
                }
                qualifiedName.Append(catalog).Append(StringHelper.Underscore);
            }
            if (!string.IsNullOrEmpty(schema))
            {
                if (schema.StartsWith(OpenQuote.ToString()))
                {
                    schema = schema.Substring(1, schema.Length - 1);
                    quoted = true;
                }
                if (schema.EndsWith(CloseQuote.ToString()))
                {
                    schema = schema.Substring(0, schema.Length - 1);
                    quoted = true;
                }
                qualifiedName.Append(schema).Append(StringHelper.Underscore);
            }

            if (table.StartsWith(OpenQuote.ToString()))
            {
                table  = table.Substring(1, table.Length - 1);
                quoted = true;
            }
            if (table.EndsWith(CloseQuote.ToString()))
            {
                table  = table.Substring(0, table.Length - 1);
                quoted = true;
            }

            string name = qualifiedName.Append(table).ToString();

            if (quoted)
            {
                return(OpenQuote + name + CloseQuote);
            }
            return(name);
        }
コード例 #3
0
        /// <summary>
        /// Quotes a name.
        /// </summary>
        /// <param name="name">The string that needs to be Quoted.</param>
        /// <returns>A QuotedName </returns>
        /// <remarks>
        /// <p>
        /// This method assumes that the name is not already Quoted.  So if the name passed
        /// in is <c>"name</c> then it will return <c>"""name"</c>.  It escapes the first char
        /// - the " with "" and encloses the escaped string with OpenQuote and CloseQuote.
        /// </p>
        /// </remarks>
        protected virtual string Quote(string name)
        {
            string quotedName = name.Replace(OpenQuote.ToString(), new string( OpenQuote, 2 ));

            // in some dbs the Open and Close Quote are the same chars - if they are
            // then we don't have to escape the Close Quote char because we already
            // got it.
            if (OpenQuote != CloseQuote)
            {
                quotedName = name.Replace(CloseQuote.ToString(), new string( CloseQuote, 2 ));
            }

            return(OpenQuote + quotedName + CloseQuote);
        }
コード例 #4
0
        public override string Qualify(string catalog, string schema, string table)
        {
            // SQL Server Compact doesn't support Schemas. So join schema name and table name with underscores
            // similar to the SQLLite dialect.

            var  qualifiedName = new StringBuilder();
            bool quoted        = false;

            if (!string.IsNullOrEmpty(catalog))
            {
                qualifiedName.Append(catalog).Append(StringHelper.Dot);
            }

            var tableName = new StringBuilder();

            if (!string.IsNullOrEmpty(schema))
            {
                if (schema.StartsWith(OpenQuote.ToString()))
                {
                    schema = schema.Substring(1, schema.Length - 1);
                    quoted = true;
                }
                if (schema.EndsWith(CloseQuote.ToString()))
                {
                    schema = schema.Substring(0, schema.Length - 1);
                    quoted = true;
                }
                tableName.Append(schema).Append(StringHelper.Underscore);
            }

            if (table.StartsWith(OpenQuote.ToString()))
            {
                table  = table.Substring(1, table.Length - 1);
                quoted = true;
            }
            if (table.EndsWith(CloseQuote.ToString()))
            {
                table  = table.Substring(0, table.Length - 1);
                quoted = true;
            }

            string name = tableName.Append(table).ToString();

            if (quoted)
            {
                name = OpenQuote + name + CloseQuote;
            }
            return(qualifiedName.Append(name).ToString());
        }
コード例 #5
0
        /// <summary>
        /// Unquotes and unescapes an already quoted name
        /// </summary>
        /// <param name="quoted">Quoted string</param>
        /// <returns>Unquoted string</returns>
        /// <remarks>
        /// <p>
        /// This method checks the string <c>quoted</c> to see if it is
        /// quoted.  If the string <c>quoted</c> is already enclosed in the OpenQuote
        /// and CloseQuote then those chars are removed.
        /// </p>
        /// <p>
        /// After the OpenQuote and CloseQuote have been cleaned from the string <c>quoted</c>
        /// then any chars in the string <c>quoted</c> that have been escaped by doubling them
        /// up are changed back to a single version.
        /// </p>
        /// <p>
        /// The following quoted values return these results
        /// "quoted" = quoted
        /// "quote""d" = quote"d
        /// quote""d = quote"d
        /// </p>
        /// <p>
        /// If this implementation is not sufficient for your Dialect then it needs to be overridden.
        /// MsSql2000Dialect is an example of where UnQuoting rules are different.
        /// </p>
        /// </remarks>
        public virtual string UnQuote(string quoted)
        {
            string unquoted;

            if (IsQuoted(quoted))
            {
                unquoted = quoted.Substring(1, quoted.Length - 2);
            }
            else
            {
                unquoted = quoted;
            }

            unquoted = unquoted.Replace(new string( OpenQuote, 2 ), OpenQuote.ToString());

            if (OpenQuote != CloseQuote)
            {
                unquoted = unquoted.Replace(new string( CloseQuote, 2 ), CloseQuote.ToString());
            }

            return(unquoted);
        }
コード例 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 /// <remarks>
 /// MsSql does not require the OpenQuote to be escaped as long as the first char
 /// is an OpenQuote.
 /// </remarks>
 protected override string Quote(string name)
 {
     return(OpenQuote + name.Replace(CloseQuote.ToString(), new string(CloseQuote, 2)) + CloseQuote);
 }
コード例 #7
0
 public string QuoteIdentifier(string s)
 {
     if (string.IsNullOrEmpty(s))
     {
         return(s);
     }
     if (s.StartsWith(OpenQuote.ToString(), StringComparison.OrdinalIgnoreCase) && s.EndsWith(CloseQuote.ToString(), StringComparison.OrdinalIgnoreCase))
     {
         return(s);
     }
     return(s);
 }