using System;
using System.Text;
using NHibernate.Util;

namespace NHibernate.Sql {

	/// <summary>
	/// An SQL <c>DELETE</c> statement
	/// </summary>
	public class Delete {
		private string tableName;
		private string[] primaryKeyColumnNames;
		private string versionColumnName;
		private string where;

		public Delete SetTableName(string tableName) {
			this.tableName = tableName;
			return this;
		}

		public string ToStatementString() {
			StringBuilder buf = new StringBuilder( tableName.Length + 10 );
			buf.Append("delete from ")
				.Append(tableName)
				.Append(" where ")
				.Append( string.Join("=? and ", primaryKeyColumnNames) )
				.Append("=?");
			if (versionColumnName != null) {
				buf.Append(" and ")
					.Append(versionColumnName)
					.Append("=?");
				if(where!=null) {
					buf.Append(" and ")
						.Append(where);
				}
			}
			return buf.ToString();
		}

		public Delete SetWhere(string where) {
			this.where = where;
			return this;
		}

		public Delete SetPrimaryKeyColumnNames(string[] primaryKeyColumnNames) {
			this.primaryKeyColumnNames = primaryKeyColumnNames;
			return this;
		}

		public Delete SetVersionColumnName(string versionColumnName) {
			this.versionColumnName = versionColumnName;
			return this;
		}
	}
}

using System;
using System.Text;
using NHibernate.Util;

namespace NHibernate.Sql {

	/// <summary>
	/// An SQL <c>DELETE</c> statement
	/// </summary>
	public class Delete {
		private string tableName;
		private string[] primaryKeyColumnNames;
		private string versionColumnName;
		private string where;

		public Delete SetTableName(string tableName) {
			this.tableName = tableName;
			return this;
		}

		public string ToStatementString() {
			StringBuilder buf = new StringBuilder( tableName.Length + 10 );
			buf.Append("delete from ")
				.Append(tableName)
				.Append(" where ")
				.Append( string.Join("=? and ", primaryKeyColumnNames) )
				.Append("=?");
			if(where!=null) {
				buf.Append(" and ")
					.Append(where);
			}
			if (versionColumnName != null) {
				buf.Append(" and ")
					.Append(versionColumnName)
					.Append("=?");
			}
			return buf.ToString();
		}

		public Delete SetWhere(string where) {
			this.where = where;
			return this;
		}

		public Delete SetPrimaryKeyColumnNames(params string[] primaryKeyColumnNames) {
			this.primaryKeyColumnNames = primaryKeyColumnNames;
			return this;
		}

		public Delete SetVersionColumnName(string versionColumnName) {
			this.versionColumnName = versionColumnName;
			return this;
		}
	}
}

Fix bug in "where" if-statement
Fix bug in "where" if-statement


SVN: 488784591515bd4cdaa016be4ec9b172dc4e7caf@159
