Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16804/NHibernate/SqlCommand
Modified Files:
InFragment.cs
Log Message:
Fixed bug with "null" being a discriminator and the sql string generated
having an extra comma at the end of the in list.
Index: InFragment.cs
===================================================================
RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/SqlCommand/InFragment.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** InFragment.cs 16 Aug 2004 05:18:52 -0000 1.1
--- InFragment.cs 16 Dec 2004 21:51:08 -0000 1.2
***************
*** 35,45 ****
public SqlString ToFragmentString()
{
! SqlStringBuilder buf = new SqlStringBuilder(values.Count + 5);
! buf.Add(columnName);
! if (values.Count > 1)
{
bool allowNull = false;
! buf.Add(" in (");
! for(int i=0; i<values.Count; i++)
{
if("null".Equals(values[i]))
--- 35,53 ----
public SqlString ToFragmentString()
{
! SqlStringBuilder buf = new SqlStringBuilder( values.Count * 5 );
! buf.Add( columnName );
!
! if( values.Count > 1 )
{
+ // is a comma needed before the value that's about to be added - it
+ // defaults to false because we don't need a comma right away.
+ bool commaNeeded = false;
+
+ // if a "null" is in the list of values then we need to manipulate
+ // the SqlString a little bit more at the end.
bool allowNull = false;
!
! buf.Add( " in (" );
! for( int i=0; i<values.Count; i++ )
{
if("null".Equals(values[i]))
***************
*** 47,62 ****
allowNull = true;
}
-
else
{
buf.Add( (string)values[i] );
! if ( i<values.Count-1) buf.Add(StringHelper.CommaSpace);
}
}
buf.Add(StringHelper.ClosedParen);
! if(allowNull)
{
-
buf.Insert(0, " is null or ")
.Insert(0, columnName)
--- 55,78 ----
allowNull = true;
}
else
{
+ if( commaNeeded )
+ {
+ buf.Add( StringHelper.CommaSpace );
+ }
buf.Add( (string)values[i] );
!
! // a value has been added into the IN clause so the next
! // one needs a comma before it
! commaNeeded = true;
}
}
buf.Add(StringHelper.ClosedParen);
!
! // if "null" is in the list of values then add to the beginning of the
! // SqlString "is null or [column] (" + [rest of sqlstring here] + ")"
! if( allowNull )
{
buf.Insert(0, " is null or ")
.Insert(0, columnName)
|