From: Michael D. <mik...@us...> - 2004-05-27 18:49:55
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Hql In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28170/NHibernate/Hql Modified Files: QueryTranslator.cs WhereParser.cs Log Message: Fixed the broken parameter parsing. Does not just check for "=" anymore, it now uses the booleanOperators in WhereParser. Index: WhereParser.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Hql/WhereParser.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** WhereParser.cs 20 May 2004 21:07:58 -0000 1.13 --- WhereParser.cs 27 May 2004 18:49:44 -0000 1.14 *************** *** 31,35 **** private static StringCollection expressionTerminators = new StringCollection(); //tokens that close a sub expression private static StringCollection expressionOpeners = new StringCollection(); //tokens that open a sub expression ! private static StringCollection booleanOperators = new StringCollection(); //tokens that would indicate a sub expression is a boolean expression private static IDictionary negations = new Hashtable(); private Dialect.Dialect d; --- 31,36 ---- private static StringCollection expressionTerminators = new StringCollection(); //tokens that close a sub expression private static StringCollection expressionOpeners = new StringCollection(); //tokens that open a sub expression ! //TODO: HACK to make this internal for QueryTranslator... ! internal static StringCollection booleanOperators = new StringCollection(); //tokens that would indicate a sub expression is a boolean expression private static IDictionary negations = new Hashtable(); private Dialect.Dialect d; Index: QueryTranslator.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Hql/QueryTranslator.cs,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** QueryTranslator.cs 20 May 2004 21:05:29 -0000 1.28 --- QueryTranslator.cs 27 May 2004 18:49:43 -0000 1.29 *************** *** 1248,1253 **** /// </para> /// <para> ! /// This should not be considered a permanent solution because it is not very smart - it splits on ! /// a <c>?</c> as long as the previous token ends with <c>"="</c> or <c>"= "</c>. /// </para> /// <para> --- 1248,1253 ---- /// </para> /// <para> ! /// This should not be considered a permanent solution. While parsing the HQL we should be building ! /// a SqlString, not a string that contains sql... /// </para> /// <para> *************** *** 1323,1327 **** if(token.Equals(StringHelper.SqlParameter) ! && ( previousToken.EndsWith("=") || previousToken.EndsWith("= ") ) ) { Parameter param = Parameter.GenerateParameters(session.Factory, new string[]{paramIndex.ToString()}, paramTypes[paramIndex])[0]; --- 1323,1327 ---- if(token.Equals(StringHelper.SqlParameter) ! && ( EndsWithBoolOperator( previousToken ) ) ) //.EndsWith("=") || previousToken.EndsWith("= ") ) ) { Parameter param = Parameter.GenerateParameters(session.Factory, new string[]{paramIndex.ToString()}, paramTypes[paramIndex])[0]; *************** *** 1340,1343 **** --- 1340,1361 ---- } + + /// <summary> + /// Temp method to help us figure out if the string ends with character that indicate that + /// a parameter is likely to follow. + /// </summary> + /// <param name="sqlFragment">A string that contains sql.</param> + /// <returns>true when a Parameter might follow this sql.</returns> + private bool EndsWithBoolOperator(string sqlFragment) + { + string sql = sqlFragment.Trim(); + + for(int i = 0; i < WhereParser.booleanOperators.Count; i++) + { + if( sql.EndsWith(WhereParser.booleanOperators[i]) ) return true; + } + + return false; + } } } \ No newline at end of file |