Author: gbayon
Date: Tue Apr 29 21:53:42 2008
New Revision: 652259

URL: http://svn.apache.org/viewvc?rev=652259&view=rev
Log:
Fix IBATISNET-253       

Modified:
    ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Domain/LineItem.cs
    
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
    
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ParameterMapTest.cs
    
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/StatementTest.cs
    
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config
    
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper/TypeHandlers/ByteArrayTypeHandler.cs
    
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/LineItem.cs
    
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/ParameterMapTest.cs
    
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs
    
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
    
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper/TypeHandlers/ByteArrayTypeHandler.cs

Modified: ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Domain/LineItem.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Domain/LineItem.cs?rev=652259&r1=652258&r2=652259&view=diff
==============================================================================
--- ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Domain/LineItem.cs 
(original)
+++ ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Domain/LineItem.cs Tue Apr 
29 21:53:42 2008
@@ -86,7 +86,14 @@
                {
                        set
                        {
-                               _pictureData = LineItem.ConvertToByteArray( 
value ); 
+                if (value!=null)
+                {
+                                   _pictureData = LineItem.ConvertToByteArray( 
value ); 
+                }
+                else
+                {
+                    _pictureData = null;
+                }
                        }
                        get
                        { 

Modified: 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml?rev=652259&r1=652258&r2=652259&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
 (original)
+++ 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
 Tue Apr 29 21:53:42 2008
@@ -668,7 +668,14 @@
                        resultMap="indexed-account-result">
                        where Account_ID between #lowID# and #hightID#
                </select>
-               
+
+    <select id="GetDummy"
+      extends="GetAllAccounts"
+      parameterClass="Hashtable"
+      resultMap="indexed-account-result">
+      where Account_ID between #?lowID# and #?hightID#
+    </select>
+    
                <select id="SelectAccountJIRA29" parameterClass="map" 
resultClass="Account">
                        select
                                Account_ID as Id,

Modified: 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ParameterMapTest.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ParameterMapTest.cs?rev=652259&r1=652258&r2=652259&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ParameterMapTest.cs
 (original)
+++ 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ParameterMapTest.cs
 Tue Apr 29 21:53:42 2008
@@ -260,13 +260,61 @@
 
                        item = 
sqlMap.QueryForObject("GetSpecificLineItemWithPicture", param) as LineItem;
 
-                       Assert.IsNotNull( item.Id );
+                       Assert.IsNotNull( item );
                        Assert.IsNotNull( item.Picture );
                        Assert.AreEqual( GetSize(item.Picture), this.GetSize( 
this.GetPicture() ));
                }
 
 
-               /// <summary>
+        [Test]
+        [Category("JIRA")]
+        [Category("JIRA-253")]
+        public void Null_byte_array_should_return_null()
+        {
+            Account account = NewAccount6();
+
+            sqlMap.Insert("InsertAccountViaParameterMap", account);
+
+            Order order = new Order();
+            order.Id = 99;
+            order.CardExpiry = "09/11";
+            order.Account = account;
+            order.CardNumber = "154564656";
+            order.CardType = "Visa";
+            order.City = "Lyon";
+            order.Date = DateTime.MinValue;
+            order.PostalCode = "69004";
+            order.Province = "Rhone";
+            order.Street = "rue Durand";
+
+            sqlMap.Insert("InsertOrderViaParameterMap", order);
+
+            LineItem item = new LineItem();
+            item.Id = 99;
+            item.Code = "test";
+            item.Price = -99.99m;
+            item.Quantity = 99;
+            item.Order = order;
+            item.Picture = null;
+
+            // Check insert
+            sqlMap.Insert("InsertLineItemWithPicture", item);
+
+            // select
+            item = null;
+
+            Hashtable param = new Hashtable();
+            param.Add("LineItem_ID", 99);
+            param.Add("Order_ID", 99);
+
+            item = sqlMap.QueryForObject("GetSpecificLineItemWithPicture", 
param) as LineItem;
+            Assert.IsNotNull(item);
+            Assert.IsNull(item.Picture);
+
+        }
+
+
+           /// <summary>
                /// Test extend parameter map capacity
                /// (Support Requests 1043181)
                /// </summary>

Modified: 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/StatementTest.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/StatementTest.cs?rev=652259&r1=652258&r2=652259&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/StatementTest.cs
 (original)
+++ 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/StatementTest.cs
 Tue Apr 29 21:53:42 2008
@@ -832,6 +832,22 @@
             Assert.AreEqual(4, ((Account)list[2]).Id);
         }
 
+        [Test]
+        public void TestDummy()
+        {
+            Hashtable param = new Hashtable();
+            param.Add("?lowID", 2);
+            param.Add("?hightID", 4);
+
+            IList list = sqlMap.QueryForList("GetDummy", param);
+
+            Assert.AreEqual(3, list.Count);
+
+            Assert.AreEqual(2, ((Account)list[0]).Id);
+            Assert.AreEqual(3, ((Account)list[1]).Id);
+            Assert.AreEqual(4, ((Account)list[2]).Id);
+        }
+
         #endregion
 
         #region Update tests

Modified: 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config?rev=652259&r1=652258&r2=652259&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config
 (original)
+++ 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config
 Tue Apr 29 21:53:42 2008
@@ -30,19 +30,20 @@
 
        <iBATIS>
                <logging>
-<!--
+<!-- 
        <logFactoryAdapter 
type="IBatisNet.Common.Logging.Impl.ConsoleOutLoggerFA, IBatisNet.Common">
                                <arg key="showLogName" value="true" />
                                <arg key="showDataTime" value="true" />
                                <arg key="level" value="ALL" />
                                <arg key="dateTimeFormat" value="yyyy/MM/dd 
HH:mm:ss:SSS" />
-                       </logFactoryAdapter>    --> 
+                       </logFactoryAdapter>    
+  --> 
  <!--      <logFactoryAdapter 
type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA, 
IBatisNet.Common.Logging.Log4Net">
         <arg key="configType" value="inline" />
       </logFactoryAdapter> 
 -->
 
-      
+     
      <logFactoryAdapter type="IBatisNet.Common.Logging.Impl.NoOpLoggerFA, 
IBatisNet.Common" />
 
       

Modified: 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper/TypeHandlers/ByteArrayTypeHandler.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V1/src/IBatisNet.DataMapper/TypeHandlers/ByteArrayTypeHandler.cs?rev=652259&r1=652258&r2=652259&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper/TypeHandlers/ByteArrayTypeHandler.cs
 (original)
+++ 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper/TypeHandlers/ByteArrayTypeHandler.cs
 Tue Apr 29 21:53:42 2008
@@ -52,12 +52,9 @@
                {
                        int index = dataReader.GetOrdinal(mapping.ColumnName);
 
-            // determine the buffer size
-                       int bufferLength = (int) dataReader.GetBytes(index, 0, 
null, 0, 0);
-
-            if (bufferLength == 0)
+            if (dataReader.IsDBNull(index) || dataReader.GetBytes(index, 0, 
null, 0, 0) == 0)
                        {
-                               return System.DBNull.Value;
+                               return DBNull.Value;
                        }
                        else
                        {
@@ -73,12 +70,9 @@
         /// <returns></returns>
                public override object GetValueByIndex(ResultProperty mapping, 
IDataReader dataReader) 
                {
-            // determine the buffer size
-            int bufferLength = (int)dataReader.GetBytes(mapping.ColumnIndex, 
0, null, 0, 0);
-
-            if (bufferLength == 0)
+            if (dataReader.IsDBNull(mapping.ColumnIndex) || 
dataReader.GetBytes(mapping.ColumnIndex, 0, null, 0, 0) == 0)
             {
-                               return System.DBNull.Value;
+                               return DBNull.Value;
                        }
                        else
                        {

Modified: 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/LineItem.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/LineItem.cs?rev=652259&r1=652258&r2=652259&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/LineItem.cs
 (original)
+++ 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/LineItem.cs
 Tue Apr 29 21:53:42 2008
@@ -86,7 +86,14 @@
                {
                        set
                        {
-                               _pictureData = LineItem.ConvertToByteArray( 
value ); 
+                if (value!=null)
+                {
+                                   _pictureData = LineItem.ConvertToByteArray( 
value ); 
+                }
+                else
+                {
+                    _pictureData = null;
+                }
                        }
                        get
                        { 

Modified: 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/ParameterMapTest.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/ParameterMapTest.cs?rev=652259&r1=652258&r2=652259&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/ParameterMapTest.cs
 (original)
+++ 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/ParameterMapTest.cs
 Tue Apr 29 21:53:42 2008
@@ -263,11 +263,57 @@
 
             item = dataMapper.QueryForObject("GetSpecificLineItemWithPicture", 
param) as LineItem;
 
-            Assert.IsNotNull( item.Id );
+            Assert.IsNotNull( item );
             Assert.IsNotNull( item.Picture );
             Assert.AreEqual( GetSize(item.Picture), this.GetSize( 
this.GetPicture() ));
         }
 
+        [Test]
+        [Category("JIRA")]
+        [Category("JIRA-253")]
+        public void Null_byte_array_should_return_null()
+        {
+            Account account = NewAccount6();
+
+            dataMapper.Insert("InsertAccountViaParameterMap", account);
+
+            Order order = new Order();
+            order.Id = 99;
+            order.CardExpiry = "09/11";
+            order.Account = account;
+            order.CardNumber = "154564656";
+            order.CardType = "Visa";
+            order.City = "Lyon";
+            order.Date = DateTime.MinValue;
+            order.PostalCode = "69004";
+            order.Province = "Rhone";
+            order.Street = "rue Durand";
+
+            dataMapper.Insert("InsertOrderViaParameterMap", order);
+
+            LineItem item = new LineItem();
+            item.Id = 99;
+            item.Code = "test";
+            item.Price = -99.99m;
+            item.Quantity = 99;
+            item.Order = order;
+            item.Picture = null;
+
+            // Check insert
+            dataMapper.Insert("InsertLineItemWithPicture", item);
+
+            // select
+            item = null;
+
+            Hashtable param = new Hashtable();
+            param.Add("LineItem_ID", 99);
+            param.Add("Order_ID", 99);
+
+            item = dataMapper.QueryForObject("GetSpecificLineItemWithPicture", 
param) as LineItem;
+            Assert.IsNotNull(item);
+            Assert.IsNull(item.Picture);
+
+        }
 
         /// <summary>
         /// Test extend parameter map capacity

Modified: 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs?rev=652259&r1=652258&r2=652259&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs
 (original)
+++ 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs
 Tue Apr 29 21:53:42 2008
@@ -640,6 +640,22 @@
             Assert.AreEqual(4, ((Account)list[2]).Id);
         }
 
+        [Test]
+        public void TestDummyAccount()
+        {
+            Hashtable param = new Hashtable();
+            param.Add("?lowID", 2);
+            param.Add("?hightID", 4);
+
+            IList list = dataMapper.QueryForList("GetDummy", param);
+
+            Assert.AreEqual(3, list.Count);
+
+            Assert.AreEqual(2, ((Account)list[0]).Id);
+            Assert.AreEqual(3, ((Account)list[1]).Id);
+            Assert.AreEqual(4, ((Account)list[2]).Id);
+        }
+
         #endregion
 
         #region Update tests

Modified: 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml?rev=652259&r1=652258&r2=652259&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
 (original)
+++ 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
 Tue Apr 29 21:53:42 2008
@@ -631,7 +631,14 @@
                        resultMap="indexed-account-result">
                        where Account_ID between #lowID# and #hightID#
                </select>
-               
+
+    <select id="GetDummy"
+      extends="GetAllAccounts"
+      parameterClass="Hashtable"
+      resultMap="indexed-account-result">
+      where Account_ID between #?lowID# and #?hightID#
+    </select>
+    
                <select id="SelectAccountJIRA29" parameterClass="map" 
resultClass="Account">
                        select
                                Account_ID as Id,

Modified: 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper/TypeHandlers/ByteArrayTypeHandler.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper/TypeHandlers/ByteArrayTypeHandler.cs?rev=652259&r1=652258&r2=652259&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper/TypeHandlers/ByteArrayTypeHandler.cs
 (original)
+++ 
ibatis/trunk/cs/V2/src/Apache.Ibatis.DataMapper/TypeHandlers/ByteArrayTypeHandler.cs
 Tue Apr 29 21:53:42 2008
@@ -50,10 +50,7 @@
                {
             int index = dataReader.GetOrdinal(mapping.ColumnName);
 
-            // determine the buffer size
-            int bufferLength = (int)dataReader.GetBytes(index, 0, null, 0, 0);
-
-            if (bufferLength == 0)
+            if (dataReader.IsDBNull(index) || dataReader.GetBytes(index, 0, 
null, 0, 0) == 0)
             {
                 return DBNull.Value;
             }
@@ -71,10 +68,7 @@
         /// <returns></returns>
                public override object GetValueByIndex(ResultProperty mapping, 
IDataReader dataReader) 
                {
-            // determine the buffer size
-            int bufferLength = (int)dataReader.GetBytes(mapping.ColumnIndex, 
0, null, 0, 0);
-
-            if (bufferLength == 0)
+            if (dataReader.IsDBNull(mapping.ColumnIndex) || 
dataReader.GetBytes(mapping.ColumnIndex, 0, null, 0, 0) == 0)
             {
                 return DBNull.Value;
             }


Reply via email to