From: Michael D. <mik...@us...> - 2004-07-19 03:21:54
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14833/NHibernate/SqlCommand Modified Files: Parameter.cs ParameterLength.cs ParameterPrecisionScale.cs SqlString.cs Log Message: Preparer is now using the Driver to built the IDbCommand instead of having the SqlString build an IDbCommand. Index: Parameter.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/Parameter.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Parameter.cs 25 Jun 2004 20:31:32 -0000 1.7 --- Parameter.cs 19 Jul 2004 03:21:33 -0000 1.8 *************** *** 1,6 **** using System; ! using System.Data; ! using NHibernate.Driver; using NHibernate.Engine; using NHibernate.SqlTypes; --- 1,6 ---- using System; ! //using System.Data; ! //using NHibernate.Driver; using NHibernate.Engine; using NHibernate.SqlTypes; *************** *** 16,30 **** public class Parameter: ICloneable { - private DbType dbType; - private string tableAlias; private string name; ! ! public System.Data.DbType DbType { ! get {return dbType;} ! set {this.dbType = value;} ! } ! ! public string Name { get{ return name;} set{ this.name = value;} --- 16,25 ---- public class Parameter: ICloneable { private string tableAlias; private string name; ! private SqlType _sqlType; ! ! public string Name ! { get{ return name;} set{ this.name = value;} *************** *** 32,72 **** ! public string TableAlias { get {return tableAlias;} set {this.tableAlias = value;} } ! /// <summary> ! /// Returns a string version of the Parameter that is in the correct ! /// format for the SQL in the CommandText. ! /// </summary> ! /// <param name="driver">The Driver that knows how to format the name.</param> ! /// <param name="name">The name to format for SQL.</param> ! /// <returns>A valid SQL string for this Parameter.</returns> ! public string GetSqlName(IDriver driver, string name) ! { ! return driver.FormatNameForSql(name); ! } ! ! /// <summary> ! /// Returns a string version of the Parameter that is in the correct ! /// format for the IDbDataParameter.Name ! /// </summary> ! /// <param name="driver">The Driver that knows how to format the name.</param> ! /// <param name="name">The name to format for the IDbDataParameter.</param> ! /// <returns>A valid IDbDataParameter Name for this Parameter.</returns> ! public string GetParameterName(IDriver driver, string name) { ! return driver.FormatNameForParameter(name); } - public virtual IDbDataParameter GetIDbDataParameter(IDbCommand command, IDriver driver, string name) - { - IDbDataParameter param = command.CreateParameter(); - param.DbType = dbType; - param.ParameterName = GetParameterName(driver, name); - - return param; - } /// <summary> --- 27,43 ---- ! public string TableAlias ! { get {return tableAlias;} set {this.tableAlias = value;} } ! ! public SqlType SqlType { ! get { return _sqlType; } ! set { _sqlType = value; } } /// <summary> *************** *** 76,80 **** /// <param name="type">The IType to turn into Parameters</param> /// <returns>An Array of IParameter objects</returns> ! public static Parameter[] GenerateParameters(ISessionFactoryImplementor factory, string[] columnNames, IType type) { return Parameter.GenerateParameters(factory, null, columnNames, type); } --- 47,52 ---- /// <param name="type">The IType to turn into Parameters</param> /// <returns>An Array of IParameter objects</returns> ! public static Parameter[] GenerateParameters(ISessionFactoryImplementor factory, string[] columnNames, IType type) ! { return Parameter.GenerateParameters(factory, null, columnNames, type); } *************** *** 89,93 **** /// <param name="type">The IType to turn into Parameters</param> /// <returns>An Array of IParameter objects</returns> ! public static Parameter[] GenerateParameters(ISessionFactoryImplementor factory, string tableAlias, string[] columnNames, IType type) { SqlType[] sqlTypes = type.SqlTypes(factory); --- 61,66 ---- /// <param name="type">The IType to turn into Parameters</param> /// <returns>An Array of IParameter objects</returns> ! public static Parameter[] GenerateParameters(ISessionFactoryImplementor factory, string tableAlias, string[] columnNames, IType type) ! { SqlType[] sqlTypes = type.SqlTypes(factory); *************** *** 111,116 **** parameters[i].Name = columnNames[i]; - parameters[i].DbType = sqlTypes[i].DbType; parameters[i].TableAlias = tableAlias; } --- 84,90 ---- parameters[i].Name = columnNames[i]; parameters[i].TableAlias = tableAlias; + parameters[i].SqlType = sqlTypes[i]; + } *************** *** 135,139 **** // these 2 fields will not be null so compare them... ! if(this.DbType.Equals(rhs.DbType)==false || this.Name.Equals(rhs.Name)==false) return false; // becareful with TableAlias being null --- 109,117 ---- // these 2 fields will not be null so compare them... ! if( this.SqlType.Equals(rhs.SqlType)==false ! || this.Name.Equals(rhs.Name)==false) ! { ! return false; ! } // becareful with TableAlias being null *************** *** 158,162 **** unchecked { ! hashCode = dbType.GetHashCode() + name.GetHashCode(); if(tableAlias!=null) { --- 136,140 ---- unchecked { ! hashCode = _sqlType.GetHashCode() + name.GetHashCode(); if(tableAlias!=null) { *************** *** 187,195 **** } ! object ICloneable.Clone() { return Clone(); } #endregion } --- 165,176 ---- } ! object ICloneable.Clone() ! { return Clone(); } #endregion + + } Index: SqlString.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/SqlString.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SqlString.cs 25 Jun 2004 20:31:32 -0000 1.7 --- SqlString.cs 19 Jul 2004 03:21:33 -0000 1.8 *************** *** 1,8 **** using System; - using System.Data; using System.Text; - using NHibernate.Driver; - namespace NHibernate.SqlCommand { --- 1,5 ---- *************** *** 52,92 **** } - /// <summary> - /// Builds an IDbCommand using the Driver to help format the Sql and Parameters - /// </summary> - /// <param name="driver">The Driver to use to create the Sql and Parameters.</param> - /// <returns>An IDbCommand with its CommandText and ParametersCollection populated.</returns> - public IDbCommand BuildCommand(IDriver driver) - { - int paramIndex = 0; - IDbCommand cmd = driver.CreateCommand(); - - StringBuilder builder = new StringBuilder(sqlParts.Length * 15); - for(int i = 0; i < sqlParts.Length; i++) - { - object part = sqlParts[i]; - Parameter parameter = part as Parameter; - - if(parameter!=null) - { - string paramName = "p" + paramIndex; - builder.Append( parameter.GetSqlName(driver, paramName) ); - IDbDataParameter dbParam = parameter.GetIDbDataParameter(cmd, driver, paramName); - cmd.Parameters.Add(dbParam); - - paramIndex++; - } - else - { - builder.Append((string)part); - } - } - - cmd.CommandText = builder.ToString(); - - return cmd; - } - - #region System.Object Members --- 49,52 ---- Index: ParameterLength.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/ParameterLength.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ParameterLength.cs 25 Jun 2004 20:31:32 -0000 1.5 --- ParameterLength.cs 19 Jul 2004 03:21:33 -0000 1.6 *************** *** 1,8 **** using System; - using System.Data; - - using NHibernate.Driver; - using NHibernate.Engine; - using NHibernate.Type; namespace NHibernate.SqlCommand --- 1,3 ---- *************** *** 10,15 **** /// <summary> /// Extension to the Parameter class that supports Parameters with ! /// a Length /// </summary> public class ParameterLength : Parameter { --- 5,15 ---- /// <summary> /// Extension to the Parameter class that supports Parameters with ! /// a Length. /// </summary> + /// <remarks> + /// This should only be used when the property needs to be mapped with + /// a <c>type="String(200)"</c> because for some reason the default parameter + /// generation of <c>nvarchar(4000)</c> (MsSql specific) is not good enough. + /// </remarks> public class ParameterLength : Parameter { *************** *** 22,32 **** } - public override IDbDataParameter GetIDbDataParameter(IDbCommand command, IDriver driver, string name) - { - IDbDataParameter param = base.GetIDbDataParameter (command, driver, name); - param.Size = length; - - return param; - } #region System.Object Members --- 22,25 ---- Index: ParameterPrecisionScale.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/ParameterPrecisionScale.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ParameterPrecisionScale.cs 25 Jun 2004 20:31:32 -0000 1.5 --- ParameterPrecisionScale.cs 19 Jul 2004 03:21:33 -0000 1.6 *************** *** 1,8 **** using System; - using System.Data; - - using NHibernate.Driver; - using NHibernate.Engine; - using NHibernate.Type; namespace NHibernate.SqlCommand --- 1,3 ---- *************** *** 12,15 **** --- 7,15 ---- /// a Precision and a Scale /// </summary> + /// <remarks> + /// This should only be used when the property needs to be mapped with + /// a <c>type="Decimal(20,4)"</c> because for some reason the default parameter + /// generation of <c>decimal(19,5)</c> (MsSql specific) is not good enough. + /// </remarks> public class ParameterPrecisionScale : Parameter { *************** *** 29,40 **** } - public override IDbDataParameter GetIDbDataParameter(IDbCommand command, IDriver driver, string name) - { - IDbDataParameter param = base.GetIDbDataParameter (command, driver, name); - param.Precision = precision; - param.Scale = scale; - - return param; - } #region System.Object Members --- 29,32 ---- |