From: Michael D. <mik...@us...> - 2004-04-16 14:12:18
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9135/Dialect Modified Files: Dialect.cs MsSql2000Dialect.cs Log Message: Updated comments in Dialect to better explain the Quoting and removed commented out methods from MsSql2000Dialect because the base class' implementation of those methods is just fine. Index: Dialect.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect/Dialect.cs,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Dialect.cs 15 Apr 2004 21:07:18 -0000 1.27 --- Dialect.cs 16 Apr 2004 14:12:09 -0000 1.28 *************** *** 425,429 **** /// The opening quote for a quoted identifier. /// </summary> - //[Obsolete("Should use Quote functions")] protected virtual char OpenQuote { --- 425,428 ---- *************** *** 434,438 **** /// The closing quote for a quoted identifier. /// </summary> - //[Obsolete("Should use Quote functions")] protected virtual char CloseQuote { --- 433,436 ---- *************** *** 731,761 **** /// <remarks> /// The default implementation is to compare the first character ! /// to Dialect.OpenQuote. /// </remarks> public virtual bool IsQuoted(string name) { ! //TODO: should we use regex here - performance implications ! // or just live with the bug that if the first char in the name ! // ! return name[0]==OpenQuote; } /// <summary> ! /// Unquotes an already quoted name /// </summary> /// <param name="quoted">Quoted string</param> /// <returns>Unquoted string</returns> /// <remarks> ! /// The Default implementation checks the first char to see if it is ! /// == to OpenQuote and if so then it returns the string without the ! /// first and last char. If this implementation is not sufficient for ! /// your Dialect then it needs to be overridden. /// </remarks> public virtual string UnQuote(string quoted) { if (IsQuoted(quoted)) ! return quoted.Substring(1, quoted.Length - 2); ! return quoted; } --- 729,781 ---- /// <remarks> /// The default implementation is to compare the first character ! /// to Dialect.OpenQuote and the last char to Dialect.CloseQuote /// </remarks> public virtual bool IsQuoted(string name) { ! return (name[0]==OpenQuote && name[name.Length-1]==CloseQuote); } /// <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; } *************** *** 781,818 **** - - /// <summary> - /// Quotes a name for being used as a tablename - /// </summary> - /// <param name="tableName">Name of the table</param> - /// <returns>A Quoted name in the format of OpenQuote + tableName + CloseQuote</returns> - /// <remarks></remarks> - public virtual string QuoteForTableName(string tableName) - { - return IsQuoted(tableName) ? - tableName : - Quote(tableName); - - } - - /// <summary> - /// Quotes a name for being used as a columnname - /// </summary> - /// <remarks>Original implementation calls <see cref="QuoteForTableName"/></remarks> - /// <param name="columnName">Name of the column</param> - /// <returns>A Quoted name in the format of OpenQuote + columnName + CloseQuote</returns> - public virtual string QuoteForColumnName(string columnName) - { - return IsQuoted(columnName) ? - columnName : - Quote(columnName); - - } - /// <summary> /// Quotes a name. /// </summary> ! /// <param name="name">The string to Quote</param> /// <returns>A QuotedName </returns> protected virtual string Quote(string name) { --- 801,816 ---- /// <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) { *************** *** 836,839 **** --- 834,845 ---- /// <param name="columnName">Name of the alias</param> /// <returns>A Quoted name in the format of OpenQuote + aliasName + CloseQuote</returns> + /// <remarks> + /// <p> + /// If the aliasName is already enclosed in the OpenQuote and CloseQuote then this + /// method will return the aliasName that was passed in without going through any + /// Quoting process. So if aliasName is passed in already Quoted make sure that + /// you have escaped all of the chars according to your DataBase's specifications. + /// </p> + /// </remarks> public virtual string QuoteForAliasName(string aliasName) { *************** *** 844,848 **** --- 850,897 ---- } + /// <summary> + /// Quotes a name for being used as a columnname + /// </summary> + /// <remarks>Original implementation calls <see cref="QuoteForTableName"/></remarks> + /// <param name="columnName">Name of the column</param> + /// <returns>A Quoted name in the format of OpenQuote + columnName + CloseQuote</returns> + /// <remarks> + /// <p> + /// If the columnName is already enclosed in the OpenQuote and CloseQuote then this + /// method will return the columnName that was passed in without going through any + /// Quoting process. So if columnName is passed in already Quoted make sure that + /// you have escaped all of the chars according to your DataBase's specifications. + /// </p> + /// </remarks> + public virtual string QuoteForColumnName(string columnName) + { + return IsQuoted(columnName) ? + columnName : + Quote(columnName); + + } + + /// <summary> + /// Quotes a name for being used as a tablename + /// </summary> + /// <param name="tableName">Name of the table</param> + /// <returns>A Quoted name in the format of OpenQuote + tableName + CloseQuote</returns> + /// <remarks> + /// <p> + /// If the tableName is already enclosed in the OpenQuote and CloseQuote then this + /// method will return the tableName that was passed in without going through any + /// Quoting process. So if tableName is passed in already Quoted make sure that + /// you have escaped all of the chars according to your DataBase's specifications. + /// </p> + /// </remarks> + public virtual string QuoteForTableName(string tableName) + { + return IsQuoted(tableName) ? + tableName : + Quote(tableName); + + } + public class CountQueryFunctionInfo : IQueryFunctionInfo { Index: MsSql2000Dialect.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** MsSql2000Dialect.cs 15 Apr 2004 21:07:18 -0000 1.10 --- MsSql2000Dialect.cs 16 Apr 2004 14:12:10 -0000 1.11 *************** *** 92,122 **** } - // /// <summary> - // /// MsSql ov - // /// </summary> - // /// <param name="tableName"></param> - // /// <returns></returns> - // /// <remarks> - // /// MsSql needs to override it because it allows the ] to be a valid char - // /// in a table name. - // /// </remarks> - // public override string QuoteForTableName(string tableName) - // { - // if ( IsQuoted(tableName) ) return tableName; - // return Quote(tableName); // return OpenQuote + tableName.Replace(CloseQuote.ToString(), new string(CloseQuote, 2) ) + CloseQuote; - // } - // - // public override string QuoteForAliasName(string aliasName) - // { - // if ( IsQuoted(aliasName) ) return aliasName; - // return Quote(tableName); // return OpenQuote + aliasName.Replace(CloseQuote.ToString(), new string(CloseQuote, 2) ) + CloseQuote; - // } - // - // public override string QuoteForColumnName(string columnName) - // { - // if ( IsQuoted(columnName) ) return columnName; - // return Quote(tableName); // return OpenQuote + columnName.Replace(CloseQuote.ToString(), new string(CloseQuote, 2) ) + CloseQuote; - // } - public override string UnQuote(string quoted) { --- 92,95 ---- |