From: Michael D. <mik...@us...> - 2004-04-15 21:07:32
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22207/Dialect Modified Files: Dialect.cs MsSql2000Dialect.cs MySQLDialect.cs Log Message: Refactored the Dialect out of the StringHelper Index: MsSql2000Dialect.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** MsSql2000Dialect.cs 15 Apr 2004 13:21:18 -0000 1.9 --- MsSql2000Dialect.cs 15 Apr 2004 21:07:18 -0000 1.10 *************** *** 68,94 **** } ! public override string QuoteForTableName(string tableName) { ! if (tableName[0] == '[') return tableName; ! return "[" + tableName.Replace("]","]]") + "]"; } ! public override string QuoteForAliasName(string aliasName) { ! if (aliasName[0] == '[') return aliasName; ! return "[" + aliasName.Replace("]","]]") + "]"; } ! public override string QuoteForColumnName(string columnName) { ! if (columnName[0] == '[') return columnName; ! return "[" + columnName.Replace("]","]]") + "]"; } public override string UnQuote(string quoted) { ! if (quoted[0] == '[') quoted = quoted.Substring(1,quoted.Length - 2); ! return quoted.Replace("]]","]"); } --- 68,128 ---- } ! protected override char CloseQuote { ! get { return ']';} } ! protected override char OpenQuote { ! get { return '[';} } ! /// <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; } + // /// <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) { ! if ( IsQuoted(quoted) ) quoted = quoted.Substring(1,quoted.Length - 2); ! ! return quoted.Replace( new string(CloseQuote, 2), CloseQuote.ToString() ); } Index: Dialect.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect/Dialect.cs,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** Dialect.cs 15 Apr 2004 13:21:18 -0000 1.26 --- Dialect.cs 15 Apr 2004 21:07:18 -0000 1.27 *************** *** 52,57 **** /// Characters used for quoting sql identifiers /// </summary> ! public const string Quote = "`'\"["; ! public const string ClosedQuote = "`'\"]"; /// <summary> --- 52,57 ---- /// Characters used for quoting sql identifiers /// </summary> ! public const string PossibleQuoteChars = "`'\"["; ! public const string PossibleClosedQuoteChars = "`'\"]"; /// <summary> *************** *** 425,430 **** /// The opening quote for a quoted identifier. /// </summary> ! [Obsolete("Should use Quote functions")] ! public virtual char OpenQuote { get { return '"'; } --- 425,430 ---- /// The opening quote for a quoted identifier. /// </summary> ! //[Obsolete("Should use Quote functions")] ! protected virtual char OpenQuote { get { return '"'; } *************** *** 434,439 **** /// The closing quote for a quoted identifier. /// </summary> ! [Obsolete("Should use Quote functions")] ! public virtual char CloseQuote { get { return '"'; } --- 434,439 ---- /// The closing quote for a quoted identifier. /// </summary> ! //[Obsolete("Should use Quote functions")] ! protected virtual char CloseQuote { get { return '"'; } *************** *** 725,745 **** /// <summary> /// Unquotes an already quoted name /// </summary> /// <param name="quoted">Quoted string</param> /// <returns>Unquoted string</returns> public virtual string UnQuote(string quoted) { return quoted; } /// <summary> /// Quotes a name for being used as a tablename /// </summary> /// <param name="tableName">Name of the table</param> ! /// <returns>Quoted name</returns> public virtual string QuoteForTableName(string tableName) { ! return tableName; } --- 725,797 ---- /// <summary> + /// Checks to see if the name has been quoted. + /// </summary> + /// <param name="name">The name to check if it is quoted</param> + /// <returns>true if name is already quoted.</returns> + /// <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; } /// <summary> + /// Unquotes an array of Quoted Names. + /// </summary> + /// <param name="quoted">strings to Unquote</param> + /// <returns>an array of unquoted strings.</returns> + /// <remarks> + /// This use UnQuote(string) for each string in the quoted array so + /// it should not need to be overridden - only UnQuote(string) needs + /// to be overridden unless this implementation is not sufficient. + /// </remarks> + public virtual string[] UnQuote(string[] quoted) + { + string[] unquoted = new string[ quoted.Length ]; + + for (int i=0; i<quoted.Length; i++) + unquoted[i] = UnQuote(quoted[i]); + + return unquoted; + } + + + + /// <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); ! } *************** *** 749,756 **** /// <remarks>Original implementation calls <see cref="QuoteForTableName"/></remarks> /// <param name="columnName">Name of the column</param> ! /// <returns>Quoted name</returns> public virtual string QuoteForColumnName(string columnName) { ! return QuoteForTableName(columnName); } --- 801,831 ---- /// <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) ! { ! 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; } *************** *** 760,769 **** /// <remarks>Original implementation calls <see cref="QuoteForTableName"/></remarks> /// <param name="columnName">Name of the alias</param> ! /// <returns>Quoted name</returns> public virtual string QuoteForAliasName(string aliasName) { ! return QuoteForTableName(aliasName); } public class CountQueryFunctionInfo : IQueryFunctionInfo { --- 835,848 ---- /// <remarks>Original implementation calls <see cref="QuoteForTableName"/></remarks> /// <param name="columnName">Name of the alias</param> ! /// <returns>A Quoted name in the format of OpenQuote + aliasName + CloseQuote</returns> public virtual string QuoteForAliasName(string aliasName) { ! return IsQuoted(aliasName) ? ! aliasName : ! Quote(aliasName); ! } + public class CountQueryFunctionInfo : IQueryFunctionInfo { Index: MySQLDialect.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Dialect/MySQLDialect.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** MySQLDialect.cs 15 Apr 2004 11:36:35 -0000 1.14 --- MySQLDialect.cs 15 Apr 2004 21:07:18 -0000 1.15 *************** *** 51,54 **** --- 51,64 ---- + protected override char CloseQuote + { + get { return '`';} + } + + protected override char OpenQuote + { + get { return '`';} + } + public override string GetAddForeignKeyConstraintString(string constraintName, string[] foreignKey, string referencedTable, string[] primaryKey) { |