From: Michael D. <mik...@us...> - 2004-08-19 17:48:44
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20239/NHibernate/Impl Modified Files: SessionFactoryImpl.cs SessionImpl.cs Log Message: removed AdoHack and all use of it - no longer needed. Index: SessionImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionImpl.cs,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** SessionImpl.cs 9 Aug 2004 18:28:04 -0000 1.38 --- SessionImpl.cs 19 Aug 2004 17:48:35 -0000 1.39 *************** *** 20,188 **** { - #warning Hack transaction and parameters - // Put all hacks to get SimpleTest to work into this class so we can trace it - // used by: - public class AdoHack { - - //TODO: DEISGNISSUE: come up with a good way to create named parameters instead of ? - // because IDbCommand has to use @Name and can't use ? - - // Force parametercollection to be created - // Of course this is not the right place, this really means the entire concept - // of named parameters should be revised!!! - public static void CreateParameters(Dialect.Dialect dialect, IDbCommand cmd) - { - string sql = cmd.CommandText; - - if (sql == null) - return; - //TODO: once this HACK class is removed get rid of the UseNamedParameters - // and the NamedParametersPrefix Properties in Dialect and all subclasses. - if (dialect.UseNamedParameters) - { - /* - * (?<param>\?) - * Capture to <param> - * ? - * - * "select a,b,c from a=? and b=? and c=?" - * Splitting: select a,b,c from a=? and b=? and c=? - * [0] => select a,b,c from a= - * [1] => ? - * [2] => and b= - * [3] => ? - * [4] => and c= - * [5] => ? - * [6] => - * (?<param>@\w*\b) -> actual string for Ms Sql 2000 Dialect (@=named param prefix - * Capture to <param> - * : - * Any word character - * * (zero or more times) - * Word boundy between //w and //W - * - * takes a string like "select a,b,c from a=@p1 and b=@p2 c='@'" - * and splits it into - * Splitting: select a,b,c from a=@p1 and b=@p2 and c='@' - * [0] => select a,b,c from a= - * [1] => @p1 - * [2] => and b= - * [3] => @p2 - * [4] => and c='@' - */ - Regex parser = new Regex("(?<param>" + dialect.NamedParametersPrefix + "\\w*\\b)", RegexOptions.None); //.Compiled); - string[] tokens = parser.Split(sql); - if (tokens.Length > 0) - { - for (int idx=0; idx < tokens.Length; idx++) - { - string token = tokens[idx]; - - if (token != null && token.Length > 1 && token.Substring(0, 1).Equals(dialect.NamedParametersPrefix)) - { - IDbDataParameter param; - - param = cmd.CreateParameter(); - param.ParameterName = token; - cmd.Parameters.Add(param); - } - } - } - } - else - { - int idx = 0; - int paramIdx = 0; - - while((idx=sql.IndexOf("?", idx)) != -1) - { - IDbDataParameter param; - - param = cmd.CreateParameter(); - param.ParameterName = dialect.UseNamedParameters ? dialect.NamedParametersPrefix + "p" + paramIdx.ToString() : paramIdx.ToString(); - cmd.Parameters.Add(param); - paramIdx++; - idx++; - } - } - } - - public static void ReplaceHqlParameters(Dialect.Dialect dialect, IDbCommand cmd) - { - /* - * (?<param>\[<\w*>\]) - * Capture to <param> - * [< - * Any word character - * *(zero or more times) - * >] - * - * select a,b,c from a=[<parama>] and b=[<paramb>] - * for the life of me I could not figure out why the params would be wrapped - * with a "[<" and ">]" - turns out in Hql.WhereParser.DoTokens one of the original - * developers changed it to that from "?" -> that is what I would prefer to use - * instead of this silly parameter and regexp use... - * - * Splitting: select a,b,c from a=[<parama>] and b=[<paramb>] - * [0] => select a,b,c from a= - * [1] => [<parama>] - * [2] => and b= - * [3] => [<paramb>] - * [4] => - * - */ - Regex parser = new Regex("(?<param>\\[<\\w*>\\])", RegexOptions.Compiled); - string[] tokens; - string sql = cmd.CommandText; - - if (sql == null) - return; - tokens = parser.Split(sql); - if (tokens.Length > 0) - { - StringBuilder sb = new StringBuilder(); - - for (int idx=0; idx < tokens.Length; idx++) - { - string token = tokens[idx]; - - if (token != null && token.Length > 1 && token.Substring(0, 2).Equals("[<")) - { - if (dialect.UseNamedParameters) - { - IDbDataParameter param; - - param = cmd.CreateParameter(); - param.ParameterName = dialect.NamedParametersPrefix + token.Substring(2, token.Length - 4); - cmd.Parameters.Add(param); - sb.Append(param.ParameterName); - } - else - { - throw new NotImplementedException("Hack not complete for this dialect"); - } - } - else - { - sb.Append(token); - } - } - cmd.CommandText = sb.ToString(); - } - } - - // parametercollection starts at 0 - public static int ParameterPos(int pos) - { - return pos - 1; - } - - } - // -- end of Hack - - - - - /// <summary> /// Concrete implementation of a Session, also the central, organizing component of --- 20,23 ---- Index: SessionFactoryImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** SessionFactoryImpl.cs 16 Aug 2004 05:09:30 -0000 1.26 --- SessionFactoryImpl.cs 19 Aug 2004 17:48:35 -0000 1.27 *************** *** 565,572 **** retVal.CommandType = CommandType.Text; ! // Hack: force parameters to be created ! Impl.AdoHack.CreateParameters(dialect, retVal); ! // end-of Hack ! // Hack: disable Prepare() as long as the parameters have no datatypes!! #if FALSE --- 565,569 ---- retVal.CommandType = CommandType.Text; ! // Hack: disable Prepare() as long as the parameters have no datatypes!! #if FALSE |