You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by rg...@apache.org on 2006/03/30 05:00:29 UTC
svn commit: r389973 - in /ibatis/trunk/cs/mapper:
IBatisNet.DataMapper.Test/NUnit/SqlMapTests/DynamicPrependTest.cs
IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
Author: rgrabowski
Date: Wed Mar 29 19:00:27 2006
New Revision: 389973
URL: http://svn.apache.org/viewcvs?rev=389973&view=rev
Log:
Fix for IBATISNET-143: selectKey nodes may contain dynamic sql.
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/DynamicPrependTest.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/DynamicPrependTest.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/DynamicPrependTest.cs?rev=389973&r1=389972&r2=389973&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/DynamicPrependTest.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/DynamicPrependTest.cs Wed Mar 29 19:00:27 2006
@@ -432,6 +432,26 @@
Assert.AreEqual(1234, testAccount.Id);
Assert.AreEqual("#The Pound Signs#", testAccount.FirstName);
}
+
+ [Test]
+ public void TestSelectKeyWithDynamicSql()
+ {
+ Account account = new Account();
+ account.Id = 99998;
+ account.FirstName = "R";
+ account.LastName = "G";
+
+ Hashtable param = new Hashtable(2);
+ param["Account"] = account;
+ param["AccountsTableName"] = "Accounts";
+ object selectKeyValue = sqlMap.Insert("SelectKeyWithDynamicSql", param);
+
+ Assert.IsNotNull(selectKeyValue);
+ Assert.AreEqual(99998, Convert.ToInt32(selectKeyValue));
+
+ Assert.IsTrue(param.ContainsKey("AccountId"));
+ Assert.AreEqual(99998, (int)param["AccountId"]);
+ }
#endregion
}
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs?rev=389973&r1=389972&r2=389973&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs Wed Mar 29 19:00:27 2006
@@ -1166,6 +1166,9 @@
// Set sql statement SelectKey
if (insert.SelectKey != null)
{
+ _configScope.ErrorContext.MoreInfo = "loading selectKey tag";
+ _configScope.NodeContext = xmlNode.SelectSingleNode( ApplyMappingNamespacePrefix(XML_SELECTKEY), _configScope.XmlNamespaceManager);
+
insert.SelectKey.Id = insert.Id;
insert.SelectKey.Initialize( _configScope );
insert.SelectKey.Id += DOT + "SelectKey";
@@ -1174,13 +1177,8 @@
// of the parent <select> node
// insert.SelectKey.Initialize( _configScope );
// insert.SelectKey.Id = insert.Id + DOT + "SelectKey";
-
- string commandText = xmlNode.SelectSingleNode( ApplyMappingNamespacePrefix(XML_SELECTKEY), _configScope.XmlNamespaceManager).FirstChild.InnerText.Replace('\n', ' ').Replace('\r', ' ').Replace('\t', ' ').Trim();
- commandText = NodeUtils.ParsePropertyTokens(commandText, _configScope.Properties);
- StaticSql sql = new StaticSql(_configScope, insert.SelectKey);
- IDalSession session = new SqlMapSession( _configScope.SqlMapper );
- sql.BuildPreparedStatement( session, commandText );
- insert.SelectKey.Sql = sql;
+
+ ProcessSqlStatement(insert.SelectKey);
// Build MappedStatement
mappedStatement = new MappedStatement( _configScope.SqlMapper, insert.SelectKey);