From: Kevin W. <kev...@us...> - 2004-12-31 22:25:45
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9289 Modified Files: SelectFragment.cs SqlBaseBuilder.cs SqlDeleteBuilder.cs SqlInsertBuilder.cs Log Message: fixing xml comments and letting ReSharper do reformatting Index: SqlDeleteBuilder.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/SqlDeleteBuilder.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SqlDeleteBuilder.cs 22 Nov 2004 03:56:08 -0000 1.4 --- SqlDeleteBuilder.cs 31 Dec 2004 22:25:33 -0000 1.5 *************** *** 1,32 **** - using System; using System.Collections; ! using System.Text; ! ! using NHibernate.Connection; ! using NHibernate.Dialect; using NHibernate.Engine; - using NHibernate.Util; using NHibernate.Type; ! namespace NHibernate.SqlCommand { /// <summary> /// A class that builds an <c>DELETE</c> sql statement. /// </summary> ! public class SqlDeleteBuilder: SqlBaseBuilder, ISqlStringBuilder { ! private static readonly log4net.ILog log = log4net.LogManager.GetLogger( typeof(SqlDeleteBuilder) ); ! string tableName; ! int versionFragmentIndex = -1; ! int identityFragmentIndex = -1; ! IList whereStrings = new ArrayList(); ! public SqlDeleteBuilder(ISessionFactoryImplementor factory): base(factory) { } ! public SqlDeleteBuilder SetTableName(string tableName) { this.tableName = tableName; --- 1,36 ---- using System.Collections; ! using log4net; using NHibernate.Engine; using NHibernate.Type; ! namespace NHibernate.SqlCommand { /// <summary> /// A class that builds an <c>DELETE</c> sql statement. /// </summary> ! public class SqlDeleteBuilder : SqlBaseBuilder, ISqlStringBuilder { ! private static readonly ILog log = LogManager.GetLogger( typeof( SqlDeleteBuilder ) ); ! private string tableName; ! private int versionFragmentIndex = -1; // not used !?! ! private int identityFragmentIndex = -1; // not used !?! ! private IList whereStrings = new ArrayList(); ! /// <summary> ! /// ! /// </summary> ! /// <param name="factory"></param> ! public SqlDeleteBuilder( ISessionFactoryImplementor factory ) : base( factory ) { } ! /// <summary> ! /// ! /// </summary> ! /// <param name="tableName"></param> ! /// <returns></returns> ! public SqlDeleteBuilder SetTableName( string tableName ) { this.tableName = tableName; *************** *** 41,49 **** /// <param name="identityType">The IType of the Identity Property.</param> /// <returns>The SqlDeleteBuilder.</returns> ! public SqlDeleteBuilder SetIdentityColumn(string[] columnNames, IType identityType) { ! Parameter[] parameters = Parameter.GenerateParameters( Factory, columnNames, identityType ); ! identityFragmentIndex = whereStrings.Add(ToWhereString(columnNames, parameters)); return this; --- 45,53 ---- /// <param name="identityType">The IType of the Identity Property.</param> /// <returns>The SqlDeleteBuilder.</returns> ! public SqlDeleteBuilder SetIdentityColumn( string[ ] columnNames, IType identityType ) { ! Parameter[ ] parameters = Parameter.GenerateParameters( Factory, columnNames, identityType ); ! identityFragmentIndex = whereStrings.Add( ToWhereString( columnNames, parameters ) ); return this; *************** *** 56,64 **** /// <param name="versionType">The IVersionType of the Version Property.</param> /// <returns>The SqlDeleteBuilder.</returns> ! public SqlDeleteBuilder SetVersionColumn(string[] columnNames, IVersionType versionType) { ! Parameter[] parameters = Parameter.GenerateParameters( Factory, columnNames, versionType ); ! versionFragmentIndex = whereStrings.Add(ToWhereString(columnNames, parameters)); return this; --- 60,68 ---- /// <param name="versionType">The IVersionType of the Version Property.</param> /// <returns>The SqlDeleteBuilder.</returns> ! public SqlDeleteBuilder SetVersionColumn( string[ ] columnNames, IVersionType versionType ) { ! Parameter[ ] parameters = Parameter.GenerateParameters( Factory, columnNames, versionType ); ! versionFragmentIndex = whereStrings.Add( ToWhereString( columnNames, parameters ) ); return this; *************** *** 72,79 **** /// <param name="op">The operator to put between the column name and value.</param> /// <returns>The SqlDeleteBuilder</returns> ! public SqlDeleteBuilder AddWhereFragment(string[] columnNames, IType type, string op) { ! Parameter[] parameters = Parameter.GenerateParameters( Factory, columnNames, type ); ! whereStrings.Add(ToWhereString(columnNames, parameters, op)); return this; --- 76,83 ---- /// <param name="op">The operator to put between the column name and value.</param> /// <returns>The SqlDeleteBuilder</returns> ! public SqlDeleteBuilder AddWhereFragment( string[ ] columnNames, IType type, string op ) { ! Parameter[ ] parameters = Parameter.GenerateParameters( Factory, columnNames, type ); ! whereStrings.Add( ToWhereString( columnNames, parameters, op ) ); return this; *************** *** 85,91 **** /// <param name="whereString">A well formed sql string with no parameters.</param> /// <returns>The SqlDeleteBuilder</returns> ! public SqlDeleteBuilder AddWhereFragment(string whereString) { ! whereStrings.Add( new SqlString(whereString) ); return this; } --- 89,95 ---- /// <param name="whereString">A well formed sql string with no parameters.</param> /// <returns>The SqlDeleteBuilder</returns> ! public SqlDeleteBuilder AddWhereFragment( string whereString ) { ! whereStrings.Add( new SqlString( whereString ) ); return this; } *************** *** 93,139 **** #region ISqlStringBuilder Members ! public SqlString ToSqlString() { // will for sure have 3 parts and then each item in the WhereStrings ! int initialCapacity = 3; // add an "AND" for each whereString except the first one. ! initialCapacity += (whereStrings.Count -1); ! for( int i=0; i<whereStrings.Count; i++ ) { ! initialCapacity += ((SqlString)whereStrings[i]).Count; } SqlStringBuilder sqlBuilder = new SqlStringBuilder( initialCapacity + 2 ); ! sqlBuilder.Add( "DELETE FROM " ) .Add( tableName ) ! .Add( " WHERE " ); ! ! if(whereStrings.Count > 1) { sqlBuilder.Add( ! (SqlString[])((ArrayList)whereStrings).ToArray(typeof(SqlString)), ! null, "AND", null, false); } ! else { ! sqlBuilder.Add((SqlString)whereStrings[0], null, null, null, false) ; } ! if(log.IsDebugEnabled) { ! if( initialCapacity < sqlBuilder.Count ) { ! log.Debug( "The initial capacity was set too low at: " + initialCapacity + " for the DeleteSqlBuilder " + ! "that needed a capacity of: " + sqlBuilder.Count + " for the table " + tableName ); } ! else if( initialCapacity > 16 && ((float)initialCapacity/sqlBuilder.Count) > 1.2 ) { log.Debug( "The initial capacity was set too high at: " + initialCapacity + " for the DeleteSqlBuilder " + ! "that needed a capacity of: " + sqlBuilder.Count + " for the table " + tableName); } } --- 97,144 ---- #region ISqlStringBuilder Members ! /// <summary></summary> ! public SqlString ToSqlString() { // will for sure have 3 parts and then each item in the WhereStrings ! int initialCapacity = 3; // add an "AND" for each whereString except the first one. ! initialCapacity += ( whereStrings.Count - 1 ); ! for( int i = 0; i < whereStrings.Count; i++ ) { ! initialCapacity += ( ( SqlString ) whereStrings[ i ] ).Count; } SqlStringBuilder sqlBuilder = new SqlStringBuilder( initialCapacity + 2 ); ! sqlBuilder.Add( "DELETE FROM " ) .Add( tableName ) ! .Add( " WHERE " ); ! ! if( whereStrings.Count > 1 ) { sqlBuilder.Add( ! ( SqlString[ ] ) ( ( ArrayList ) whereStrings ).ToArray( typeof( SqlString ) ), ! null, "AND", null, false ); } ! else { ! sqlBuilder.Add( ( SqlString ) whereStrings[ 0 ], null, null, null, false ); } ! if( log.IsDebugEnabled ) { ! if( initialCapacity < sqlBuilder.Count ) { ! log.Debug( "The initial capacity was set too low at: " + initialCapacity + " for the DeleteSqlBuilder " + ! "that needed a capacity of: " + sqlBuilder.Count + " for the table " + tableName ); } ! else if( initialCapacity > 16 && ( ( float ) initialCapacity/sqlBuilder.Count ) > 1.2 ) { log.Debug( "The initial capacity was set too high at: " + initialCapacity + " for the DeleteSqlBuilder " + ! "that needed a capacity of: " + sqlBuilder.Count + " for the table " + tableName ); } } *************** *** 143,145 **** #endregion } ! } --- 148,150 ---- #endregion } ! } \ No newline at end of file Index: SelectFragment.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/SelectFragment.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SelectFragment.cs 21 Sep 2004 09:58:25 -0000 1.6 --- SelectFragment.cs 31 Dec 2004 22:25:33 -0000 1.7 *************** *** 1,6 **** - using System; using System.Collections; using System.Text; - using NHibernate.Util; --- 1,4 ---- *************** *** 17,26 **** private Dialect.Dialect dialect; ! public SelectFragment(Dialect.Dialect d) { this.dialect = d; } ! public SelectFragment SetSuffix(string suffix) { this.suffix = suffix; --- 15,33 ---- private Dialect.Dialect dialect; ! /// <summary> ! /// ! /// </summary> ! /// <param name="d"></param> ! public SelectFragment( Dialect.Dialect d ) { this.dialect = d; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="suffix"></param> ! /// <returns></returns> ! public SelectFragment SetSuffix( string suffix ) { this.suffix = suffix; *************** *** 28,81 **** } ! public SelectFragment AddColumn(string columnName) { ! AddColumn(null, columnName); return this; } ! public SelectFragment AddColumns(string[] columnNames) { ! for (int i=0; i<columnNames.Length; i++) AddColumn(columnNames[i]); return this; } ! public SelectFragment AddColumn(string tableAlias, string columnName) { ! return AddColumn(tableAlias, columnName, columnName); } ! public SelectFragment AddColumn(string tableAlias, string columnName, string columnAlias) { ! if(tableAlias==null || tableAlias.Length == 0) { ! columns.Add(columnName); } ! else { ! columns.Add(tableAlias + StringHelper.Dot + columnName); } ! ! columnAliases.Add(columnAlias); return this; } ! public SelectFragment AddColumns(string tableAlias, string[] columnNames) { ! for (int i=0; i<columnNames.Length; i++) AddColumn(tableAlias, columnNames[i]); return this; } ! public SelectFragment AddColumns(string tableAlias, string[] columnNames, string[] columnAliases) { ! for (int i=0; i<columnNames.Length; i++) ! AddColumn(tableAlias, columnNames[i], columnAliases[i]); return this; } ! ! public SelectFragment AddFormulas(string tableAlias, string[] formulas, string[] formulaAliases) { ! for(int i=0; i < formulas.Length; i++) { ! AddFormula(tableAlias, formulas[i], formulaAliases[i]); } --- 35,139 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="columnName"></param> ! /// <returns></returns> ! public SelectFragment AddColumn( string columnName ) { ! AddColumn( null, columnName ); return this; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="columnNames"></param> ! /// <returns></returns> ! public SelectFragment AddColumns( string[ ] columnNames ) { ! for( int i = 0; i < columnNames.Length; i++ ) ! { ! AddColumn( columnNames[ i ] ); ! } return this; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="tableAlias"></param> ! /// <param name="columnName"></param> ! /// <returns></returns> ! public SelectFragment AddColumn( string tableAlias, string columnName ) { ! return AddColumn( tableAlias, columnName, columnName ); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="tableAlias"></param> ! /// <param name="columnName"></param> ! /// <param name="columnAlias"></param> ! /// <returns></returns> ! public SelectFragment AddColumn( string tableAlias, string columnName, string columnAlias ) { ! if( tableAlias == null || tableAlias.Length == 0 ) { ! columns.Add( columnName ); } ! else { ! columns.Add( tableAlias + StringHelper.Dot + columnName ); } ! ! columnAliases.Add( columnAlias ); return this; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="tableAlias"></param> ! /// <param name="columnNames"></param> ! /// <returns></returns> ! public SelectFragment AddColumns( string tableAlias, string[ ] columnNames ) { ! for( int i = 0; i < columnNames.Length; i++ ) ! { ! AddColumn( tableAlias, columnNames[ i ] ); ! } return this; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="tableAlias"></param> ! /// <param name="columnNames"></param> ! /// <param name="columnAliases"></param> ! /// <returns></returns> ! public SelectFragment AddColumns( string tableAlias, string[ ] columnNames, string[ ] columnAliases ) { ! for( int i = 0; i < columnNames.Length; i++ ) ! { ! AddColumn( tableAlias, columnNames[ i ], columnAliases[ i ] ); ! } return this; } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="tableAlias"></param> ! /// <param name="formulas"></param> ! /// <param name="formulaAliases"></param> ! /// <returns></returns> ! public SelectFragment AddFormulas( string tableAlias, string[ ] formulas, string[ ] formulaAliases ) { ! for( int i = 0; i < formulas.Length; i++ ) { ! AddFormula( tableAlias, formulas[ i ], formulaAliases[ i ] ); } *************** *** 83,120 **** } ! public SelectFragment AddFormula(string tableAlias, string formula, string formulaAlias) { - AddColumn( ! null, ! StringHelper.Replace(formula, Template.PlaceHolder, tableAlias), ! formulaAlias); return this; } ! ! public SqlString ToSqlStringFragment() { // this preserves the way this existing method works now. ! return ToSqlStringFragment(true); } ! public SqlString ToSqlStringFragment(bool includeLeadingComma) { ! StringBuilder buf = new StringBuilder(columns.Count * 10); ! for (int i=0; i<columns.Count; i++) { ! string col = columns[i] as string; ! if(i > 0 || includeLeadingComma) buf.Append(StringHelper.CommaSpace); ! ! string columnAlias = columnAliases[i] as string; ! buf.Append(col) ! .Append(" as ") ! .Append( new Alias(suffix).ToAliasString(columnAlias, dialect) ); } ! return new SqlString(buf.ToString()); } } ! } --- 141,192 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="tableAlias"></param> ! /// <param name="formula"></param> ! /// <param name="formulaAlias"></param> ! /// <returns></returns> ! public SelectFragment AddFormula( string tableAlias, string formula, string formulaAlias ) { AddColumn( ! null, ! StringHelper.Replace( formula, Template.PlaceHolder, tableAlias ), ! formulaAlias ); return this; } ! /// <summary></summary> ! public SqlString ToSqlStringFragment() { // this preserves the way this existing method works now. ! return ToSqlStringFragment( true ); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="includeLeadingComma"></param> ! /// <returns></returns> ! public SqlString ToSqlStringFragment( bool includeLeadingComma ) { ! StringBuilder buf = new StringBuilder( columns.Count*10 ); ! for( int i = 0; i < columns.Count; i++ ) { ! string col = columns[ i ] as string; ! if( i > 0 || includeLeadingComma ) ! { ! buf.Append( StringHelper.CommaSpace ); ! } ! ! string columnAlias = columnAliases[ i ] as string; ! buf.Append( col ) ! .Append( " as " ) ! .Append( new Alias( suffix ).ToAliasString( columnAlias, dialect ) ); } ! return new SqlString( buf.ToString() ); } } ! } \ No newline at end of file Index: SqlBaseBuilder.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/SqlBaseBuilder.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SqlBaseBuilder.cs 22 Nov 2004 03:56:08 -0000 1.4 --- SqlBaseBuilder.cs 31 Dec 2004 22:25:33 -0000 1.5 *************** *** 1,5 **** - using System; - using System.Text; - using NHibernate.Engine; using NHibernate.Util; --- 1,2 ---- *************** *** 10,24 **** /// The base class for all of the SqlBuilders. /// </summary> ! public abstract class SqlBaseBuilder { - private ISessionFactoryImplementor factory; ! protected SqlBaseBuilder(ISessionFactoryImplementor factory) { this.factory = factory; } ! protected ISessionFactoryImplementor Factory { get { return factory; } --- 7,25 ---- /// The base class for all of the SqlBuilders. /// </summary> ! public abstract class SqlBaseBuilder { private ISessionFactoryImplementor factory; ! /// <summary> ! /// ! /// </summary> ! /// <param name="factory"></param> ! protected SqlBaseBuilder( ISessionFactoryImplementor factory ) { this.factory = factory; } ! /// <summary></summary> ! protected ISessionFactoryImplementor Factory { get { return factory; } *************** *** 32,37 **** /// <returns>A SqlString that contains the WhereFragment</returns> /// <remarks>This just calls the overloaded ToWhereFragment() with the operator as " = " and the tableAlias null.</remarks> ! protected SqlString ToWhereString(string[] columnNames, object[] columnValues) { ! return ToWhereString(columnNames, columnValues, " = "); } --- 33,39 ---- /// <returns>A SqlString that contains the WhereFragment</returns> /// <remarks>This just calls the overloaded ToWhereFragment() with the operator as " = " and the tableAlias null.</remarks> ! protected SqlString ToWhereString( string[ ] columnNames, object[ ] columnValues ) ! { ! return ToWhereString( columnNames, columnValues, " = " ); } *************** *** 44,50 **** /// <returns>A SqlString that contains the WhereFragment</returns> /// <remarks>This defaults the op to " = "</remarks> ! protected SqlString ToWhereString(string tableAlias, string[] columnNames, object[] columnValues) { ! return ToWhereString(tableAlias, columnNames, columnValues, " = "); } --- 46,52 ---- /// <returns>A SqlString that contains the WhereFragment</returns> /// <remarks>This defaults the op to " = "</remarks> ! protected SqlString ToWhereString( string tableAlias, string[ ] columnNames, object[ ] columnValues ) { ! return ToWhereString( tableAlias, columnNames, columnValues, " = " ); } *************** *** 56,62 **** /// <param name="op">The operator to use between the names & values. For example " = " or "!="</param> /// <returns>A SqlString that contains the WhereFragment</returns> ! protected SqlString ToWhereString(string[] columnNames, object[] columnValues, string op) { ! return ToWhereString(null, columnNames, columnValues, op); } --- 58,64 ---- /// <param name="op">The operator to use between the names & values. For example " = " or "!="</param> /// <returns>A SqlString that contains the WhereFragment</returns> ! protected SqlString ToWhereString( string[ ] columnNames, object[ ] columnValues, string op ) { ! return ToWhereString( null, columnNames, columnValues, op ); } *************** *** 69,102 **** /// <param name="op">The operator to use between the names & values. For example " = " or "!="</param> /// <returns>A SqlString that contains the WhereFragment</returns> ! protected SqlString ToWhereString(string tableAlias, string[] columnNames, object[] columnValues, string op) { ! SqlStringBuilder sqlBuilder = new SqlStringBuilder((columnNames.Length * 2) + 5); bool andNeeded = false; ! ! for(int i = 0; i < columnNames.Length; i++) { ! if(andNeeded) sqlBuilder.Add(" AND "); andNeeded = true; string columnName; ! if(tableAlias!=null && tableAlias.Length > 0) { ! columnName = tableAlias + StringHelper.Dot + columnNames[i]; } ! else { ! columnName = columnNames[i]; } ! sqlBuilder.Add(columnName) ! .Add(op); ! if(columnValues[i] is Parameter) { ! sqlBuilder.Add((Parameter)columnValues[i]); } ! else { ! sqlBuilder.Add((string)columnValues[i]); } } --- 71,107 ---- /// <param name="op">The operator to use between the names & values. For example " = " or "!="</param> /// <returns>A SqlString that contains the WhereFragment</returns> ! protected SqlString ToWhereString( string tableAlias, string[ ] columnNames, object[ ] columnValues, string op ) { ! SqlStringBuilder sqlBuilder = new SqlStringBuilder( ( columnNames.Length*2 ) + 5 ); bool andNeeded = false; ! ! for( int i = 0; i < columnNames.Length; i++ ) { ! if( andNeeded ) ! { ! sqlBuilder.Add( " AND " ); ! } andNeeded = true; string columnName; ! if( tableAlias != null && tableAlias.Length > 0 ) { ! columnName = tableAlias + StringHelper.Dot + columnNames[ i ]; } ! else { ! columnName = columnNames[ i ]; } ! sqlBuilder.Add( columnName ) ! .Add( op ); ! if( columnValues[ i ] is Parameter ) { ! sqlBuilder.Add( ( Parameter ) columnValues[ i ] ); } ! else { ! sqlBuilder.Add( ( string ) columnValues[ i ] ); } } *************** *** 106,108 **** } } ! } --- 111,113 ---- } } ! } \ No newline at end of file Index: SqlInsertBuilder.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/SqlInsertBuilder.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SqlInsertBuilder.cs 4 Dec 2004 22:24:16 -0000 1.4 --- SqlInsertBuilder.cs 31 Dec 2004 22:25:33 -0000 1.5 *************** *** 1,34 **** - using System; using System.Collections; ! using System.Data; ! using System.Text; ! ! using NHibernate.Connection; using NHibernate.Engine; using NHibernate.Type; using NHibernate.Util; ! namespace NHibernate.SqlCommand { /// <summary> /// A class that builds an <c>INSERT</c> sql statement. /// </summary> ! public class SqlInsertBuilder: ISqlStringBuilder { ! private static readonly log4net.ILog log = log4net.LogManager.GetLogger( typeof(SqlInsertBuilder) ); ! private ISessionFactoryImplementor factory; ! string tableName; ! IList columnNames = new ArrayList(); ! IList columnValues = new ArrayList(); //SortedList columnValues = new SortedList(); //key=columName, value=string/IParameter ! public SqlInsertBuilder(ISessionFactoryImplementor factory) { this.factory = factory; } ! public SqlInsertBuilder SetTableName(string tableName) { this.tableName = tableName; --- 1,39 ---- using System.Collections; ! using log4net; using NHibernate.Engine; using NHibernate.Type; using NHibernate.Util; ! namespace NHibernate.SqlCommand { /// <summary> /// A class that builds an <c>INSERT</c> sql statement. /// </summary> ! public class SqlInsertBuilder : ISqlStringBuilder { ! private static readonly ILog log = LogManager.GetLogger( typeof( SqlInsertBuilder ) ); ! private ISessionFactoryImplementor factory; ! private string tableName; ! private IList columnNames = new ArrayList(); ! private IList columnValues = new ArrayList(); //SortedList columnValues = new SortedList(); //key=columName, value=string/IParameter ! /// <summary> ! /// ! /// </summary> ! /// <param name="factory"></param> ! public SqlInsertBuilder( ISessionFactoryImplementor factory ) { this.factory = factory; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="tableName"></param> ! /// <returns></returns> ! public SqlInsertBuilder SetTableName( string tableName ) { this.tableName = tableName; *************** *** 42,55 **** /// <param name="propertyType">The IType of the property.</param> /// <returns>The SqlInsertBuilder.</returns> ! public SqlInsertBuilder AddColumn(string[] columnNames, IType propertyType) { ! Parameter[] parameters = Parameter.GenerateParameters( factory, columnNames, propertyType ); ! for(int i = 0; i < columnNames.Length; i++) { ! this.columnNames.Add(columnNames[i]); ! columnValues.Add(parameters[i]); } ! return this; } --- 47,60 ---- /// <param name="propertyType">The IType of the property.</param> /// <returns>The SqlInsertBuilder.</returns> ! public SqlInsertBuilder AddColumn( string[ ] columnNames, IType propertyType ) { ! Parameter[ ] parameters = Parameter.GenerateParameters( factory, columnNames, propertyType ); ! for( int i = 0; i < columnNames.Length; i++ ) { ! this.columnNames.Add( columnNames[ i ] ); ! columnValues.Add( parameters[ i ] ); } ! return this; } *************** *** 62,68 **** /// <param name="literalType">The NHibernateType to use to convert the value to a sql string.</param> /// <returns>The SqlInsertBuilder.</returns> ! public SqlInsertBuilder AddColumn(string columnName, object val, ILiteralType literalType) { ! return AddColumn(columnName, literalType.ObjectToSQLString(val)); } --- 67,73 ---- /// <param name="literalType">The NHibernateType to use to convert the value to a sql string.</param> /// <returns>The SqlInsertBuilder.</returns> ! public SqlInsertBuilder AddColumn( string columnName, object val, ILiteralType literalType ) { ! return AddColumn( columnName, literalType.ObjectToSQLString( val ) ); } *************** *** 74,89 **** /// <param name="val">A valid sql string to set as the value of the column.</param> /// <returns>The SqlInsertBuilder.</returns> ! public SqlInsertBuilder AddColumn(string columnName, string val) ! { ! columnNames.Add(columnName); ! columnValues.Add(val); ! return this; } ! #region ISqlStringBuilder Members ! public SqlString ToSqlString() ! { // 5 = "INSERT INTO", tableName, " (" , ") VALUES (", and ")" int initialCapacity = 5; --- 79,95 ---- /// <param name="val">A valid sql string to set as the value of the column.</param> /// <returns>The SqlInsertBuilder.</returns> ! public SqlInsertBuilder AddColumn( string columnName, string val ) ! { ! columnNames.Add( columnName ); ! columnValues.Add( val ); ! return this; } ! #region ISqlStringBuilder Members ! /// <summary></summary> ! public SqlString ToSqlString() ! { // 5 = "INSERT INTO", tableName, " (" , ") VALUES (", and ")" int initialCapacity = 5; *************** *** 94,124 **** // eachColumn after the first one is 4 because of the ", ", columnName // and the ", " columnValue ! if( columnNames.Count > 0 ) { ! initialCapacity += ( (columnNames.Count-1) * 4); } SqlStringBuilder sqlBuilder = new SqlStringBuilder( initialCapacity + 2 ); - - sqlBuilder.Add("INSERT INTO ") - .Add(tableName); ! if(columnNames.Count == 0 ) { ! sqlBuilder.Add(" ").Add( factory.Dialect.NoColumnsInsertString ); ! } ! else { ! sqlBuilder.Add(" ("); // do we need a comma before we add the column to the INSERT list // when we get started the first column doesn't need one. bool commaNeeded = false; ! ! foreach(string columnName in columnNames) { // build up the column list ! if(commaNeeded) sqlBuilder.Add(StringHelper.CommaSpace); ! sqlBuilder.Add(columnName); commaNeeded = true; } --- 100,133 ---- // eachColumn after the first one is 4 because of the ", ", columnName // and the ", " columnValue ! if( columnNames.Count > 0 ) { ! initialCapacity += ( ( columnNames.Count - 1 )*4 ); } SqlStringBuilder sqlBuilder = new SqlStringBuilder( initialCapacity + 2 ); ! sqlBuilder.Add( "INSERT INTO " ) ! .Add( tableName ); ! ! if( columnNames.Count == 0 ) { ! sqlBuilder.Add( " " ).Add( factory.Dialect.NoColumnsInsertString ); ! } ! else { ! sqlBuilder.Add( " (" ); // do we need a comma before we add the column to the INSERT list // when we get started the first column doesn't need one. bool commaNeeded = false; ! ! foreach( string columnName in columnNames ) { // build up the column list ! if( commaNeeded ) ! { ! sqlBuilder.Add( StringHelper.CommaSpace ); ! } ! sqlBuilder.Add( columnName ); commaNeeded = true; } *************** *** 127,163 **** commaNeeded = false; ! ! foreach(object obj in columnValues) { ! if(commaNeeded) sqlBuilder.Add(StringHelper.CommaSpace); commaNeeded = true; Parameter param = obj as Parameter; ! if(param!=null) { ! sqlBuilder.Add(param); } ! else { ! sqlBuilder.Add((string)obj); } } ! sqlBuilder.Add(")"); } ! if(log.IsDebugEnabled) { ! if( initialCapacity < sqlBuilder.Count ) { ! log.Debug( "The initial capacity was set too low at: " + initialCapacity + " for the InsertSqlBuilder " + ! "that needed a capacity of: " + sqlBuilder.Count + " for the table " + tableName ); } ! else if( initialCapacity > 16 && ((float)initialCapacity/sqlBuilder.Count) > 1.2 ) { log.Debug( "The initial capacity was set too high at: " + initialCapacity + " for the InsertSqlBuilder " + ! "that needed a capacity of: " + sqlBuilder.Count + " for the table " + tableName ); } } --- 136,175 ---- commaNeeded = false; ! ! foreach( object obj in columnValues ) { ! if( commaNeeded ) ! { ! sqlBuilder.Add( StringHelper.CommaSpace ); ! } commaNeeded = true; Parameter param = obj as Parameter; ! if( param != null ) { ! sqlBuilder.Add( param ); } ! else { ! sqlBuilder.Add( ( string ) obj ); } } ! sqlBuilder.Add( ")" ); } ! if( log.IsDebugEnabled ) { ! if( initialCapacity < sqlBuilder.Count ) { ! log.Debug( "The initial capacity was set too low at: " + initialCapacity + " for the InsertSqlBuilder " + ! "that needed a capacity of: " + sqlBuilder.Count + " for the table " + tableName ); } ! else if( initialCapacity > 16 && ( ( float ) initialCapacity/sqlBuilder.Count ) > 1.2 ) { log.Debug( "The initial capacity was set too high at: " + initialCapacity + " for the InsertSqlBuilder " + ! "that needed a capacity of: " + sqlBuilder.Count + " for the table " + tableName ); } } *************** *** 168,170 **** #endregion } ! } --- 180,182 ---- #endregion } ! } \ No newline at end of file |