|
From: Michael D. <mik...@us...> - 2004-04-10 05:19:27
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Collection In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28379/NHibernate/Collection Modified Files: CollectionPersister.cs Log Message: Fixed to support Quoted Tables and Columns - ie in MsSql the use of [ and ] to surround table names/columns. Index: CollectionPersister.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Collection/CollectionPersister.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** CollectionPersister.cs 9 Apr 2004 16:18:00 -0000 1.15 --- CollectionPersister.cs 10 Apr 2004 05:06:01 -0000 1.16 *************** *** 33,38 **** private SqlString sqlDeleteRowString; ! private string sqlOrderByString; private string sqlWhereString; private bool hasOrder; --- 33,40 ---- private SqlString sqlDeleteRowString; ! private string sqlOrderByString; ! private string sqlOrderByStringTemplate; private string sqlWhereString; + private string sqlWhereStringTemplate; private bool hasOrder; *************** *** 78,81 **** --- 80,84 ---- sqlOrderByString = collection.OrderBy; + hasOrder = sqlOrderByString!=null; sqlWhereString = collection.Where; *************** *** 89,93 **** int k=0; foreach(Column col in collection.Key.ColumnCollection) { ! keyColumnNames[k] = col.Name; k++; } --- 92,96 ---- int k=0; foreach(Column col in collection.Key.ColumnCollection) { ! keyColumnNames[k] = col.GetQuotedName(dialect); k++; } *************** *** 106,118 **** int j=0; foreach(Column col in associatedClass.Key.ColumnCollection) { ! elementColumnNames[j] = col.Name; j++; } Table table = associatedClass.Table; ! qualifiedTableName = table.GetQualifiedName( factory.DefaultSchema ); enableJoinedFetch = OuterJoinLoaderType.Eager; } else { Table table = collection.Table; ! qualifiedTableName = table.GetQualifiedName( factory.DefaultSchema ); elementType = collection.Element.Type; span = collection.Element.ColumnSpan; --- 109,121 ---- int j=0; foreach(Column col in associatedClass.Key.ColumnCollection) { ! elementColumnNames[j] = col.GetQuotedName(dialect); j++; } Table table = associatedClass.Table; ! qualifiedTableName = table.GetQualifiedName( dialect, factory.DefaultSchema ); enableJoinedFetch = OuterJoinLoaderType.Eager; } else { Table table = collection.Table; ! qualifiedTableName = table.GetQualifiedName( dialect, factory.DefaultSchema ); elementType = collection.Element.Type; span = collection.Element.ColumnSpan; *************** *** 122,126 **** int i=0; foreach(Column col in collection.Element.ColumnCollection) { ! elementColumnNames[i] = col.Name; i++; } --- 125,129 ---- int i=0; foreach(Column col in collection.Element.ColumnCollection) { ! elementColumnNames[i] = col.GetQuotedName(dialect); i++; } *************** *** 136,140 **** int i=0; foreach(Column indexCol in indexedMap.Index.ColumnCollection) { ! indexColumnNames[i++] = indexCol.Name; } rowSelectColumnNames = indexColumnNames; --- 139,143 ---- int i=0; foreach(Column indexCol in indexedMap.Index.ColumnCollection) { ! indexColumnNames[i++] = indexCol.GetQuotedName(dialect); } rowSelectColumnNames = indexColumnNames; *************** *** 210,250 **** } ! public string GetSQLWhereString(string alias) { ! string[] tokens = sqlWhereString.Split( ' ', '=', '>', '<', '!' ); ! StringBuilder result = new StringBuilder(); ! foreach(string token in tokens) { ! if (token.Length == 0) ! continue; ! if (char.IsLetter(token[0]) && !keywords.Contains(token) ) { ! //todo: handle and, or, not ! result.Append(alias).Append(StringHelper.Dot).Append(token); ! } else { ! result.Append(token); ! } ! } ! return result.ToString(); ! } - private static readonly IList keywords = new ArrayList(); ! static CollectionPersister() { ! keywords.Add("and"); ! keywords.Add("or"); ! keywords.Add("not"); ! keywords.Add("like"); ! keywords.Add("is"); ! keywords.Add("null"); } ! public string GetSQLOrderByString(string alias) { ! string[] tokens = sqlOrderByString.Split(','); ! StringBuilder result = new StringBuilder(); ! int i=0; ! foreach(string token in tokens) { ! i++; ! result.Append(alias).Append(StringHelper.Dot).Append( token.Trim() ); ! if (i<tokens.Length) result.Append(StringHelper.CommaSpace); ! } ! return result.ToString(); } --- 213,266 ---- } ! public string GetSQLWhereString(string alias) ! { ! if(sqlWhereStringTemplate!=null) ! return StringHelper.Replace(sqlWhereStringTemplate, Template.PlaceHolder, alias); ! else ! return null; ! // string[] tokens = sqlWhereString.Split( ' ', '=', '>', '<', '!' ); ! // StringBuilder result = new StringBuilder(); ! // foreach(string token in tokens) { ! // if (token.Length == 0) ! // continue; ! // if (char.IsLetter(token[0]) && !keywords.Contains(token) ) { ! // //todo: handle and, or, not ! // result.Append(alias).Append(StringHelper.Dot).Append(token); ! // } else { ! // result.Append(token); ! // } ! // } ! // return result.ToString(); } ! // private static readonly IList keywords = new ArrayList(); ! // ! // static CollectionPersister() { ! // keywords.Add("and"); ! // keywords.Add("or"); ! // keywords.Add("not"); ! // keywords.Add("like"); ! // keywords.Add("is"); ! // keywords.Add("null"); ! // } ! ! public string GetSQLOrderByString(string alias) ! { ! if(sqlOrderByStringTemplate!=null) ! return StringHelper.Replace(sqlOrderByStringTemplate, Template.PlaceHolder, alias); ! else ! return null; ! ! // string[] tokens = sqlOrderByString.Split(','); ! // StringBuilder result = new StringBuilder(); ! // int i=0; ! // foreach(string token in tokens) { ! // i++; ! // result.Append(alias).Append(StringHelper.Dot).Append( token.Trim() ); ! // if (i<tokens.Length) result.Append(StringHelper.CommaSpace); ! // } ! // return result.ToString(); } |