Author: gbayon
Date: Tue Nov 21 10:46:52 2006
New Revision: 477815
URL: http://svn.apache.org/viewvc?view=rev&rev=477815
Log:
Fix for IBATISNET-196
Added:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IDbDataParameterCollection.cs
(with props)
Removed:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/PreparedCommandProxy.cs
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Category.xml
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Category.xml
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatement.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/DictionaryStrategy.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapSession.cs
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Category.xml
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Category.xml?view=diff&rev=477815&r1=477814&r2=477815
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Category.xml
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Category.xml
Tue Nov 21 10:46:52 2006
@@ -157,13 +157,13 @@
<parameterMaps>
<parameterMap id="insertMap-params" class="Hashtable">
<parameter property="Id" column="Category_Id"
dbType="Int" /><!-- Int for SqlClient, Obdc; Integer for Oledb -->
- <parameter property="Name" column="Category_Name"/>
<parameter property="Guid" column="Category_Guid"
dbType="UniqueIdentifier"/><!--Guid for Oledb, UniqueIdentifier for
SqlClient,Odbc -->
+ <parameter property="Name" column="Category_Name"/>
</parameterMap>
<parameterMap id="insert-params" class="Category">
- <parameter property="Id" column="Category_Id"
dbType="Int" /><!-- Int for SqlClient, Obdc; Integer for Oledb -->
<parameter property="Name" column="Category_Name"/>
+ <parameter property="Id" column="Category_Id"
dbType="Int" /><!-- Int for SqlClient, Obdc; Integer for Oledb -->
<parameter property="Guid" column="Category_Guid"
dbType="UniqueIdentifier"/><!--Guid for Oledb, UniqueIdentifier for
SqlClient,Odbc -->
</parameterMap>
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Category.xml
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Category.xml?view=diff&rev=477815&r1=477814&r2=477815
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Category.xml
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Category.xml
Tue Nov 21 10:46:52 2006
@@ -162,13 +162,13 @@
<parameterMap id="insertMap-params" class="Hashtable">
<parameter property="Id" column="Category_Id"
dbType="Int" /><!-- Int for SqlClient, Obdc; Integer for Oledb -->
- <parameter property="Name" column="Category_Name"/>
<parameter property="Guid" column="Category_Guid"
dbType="UniqueIdentifier"/><!--Guid for Oledb, UniqueIdentifier for
SqlClient,Odbc -->
+ <parameter property="Name" column="Category_Name"/>
</parameterMap>
<parameterMap id="insert-params" class="Category">
- <parameter property="Id" column="Category_Id"
dbType="Int" /><!-- Int for SqlClient, Obdc; Integer for Oledb -->
<parameter property="Name" column="Category_Name"/>
+ <parameter property="Id" column="Category_Id"
dbType="Int" /><!-- Int for SqlClient, Obdc; Integer for Oledb -->
<parameter property="Guid" column="Category_Guid"
dbType="UniqueIdentifier"/><!--Guid for Oledb, UniqueIdentifier for
SqlClient,Odbc -->
</parameterMap>
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs?view=diff&rev=477815&r1=477814&r2=477815
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs
Tue Nov 21 10:46:52 2006
@@ -98,7 +98,7 @@
RequestScope request, IStatement statement, object
parameterObject )
{
StringCollection properties =
request.PreparedStatement.DbParametersName;
- IDataParameter[] parameters =
request.PreparedStatement.DbParameters;
+ IDbDataParameter[] parameters =
request.PreparedStatement.DbParameters;
#region Logging
if (_logger.IsDebugEnabled)
@@ -112,8 +112,8 @@
for ( int i = 0; i < count; ++i )
{
- IDataParameter sqlParameter = parameters[i];
- IDataParameter parameterCopy =
command.CreateParameter();
+ IDbDataParameter sqlParameter = parameters[i];
+ IDbDataParameter parameterCopy = command.CreateParameter();
ParameterProperty property =
request.ParameterMap.GetProperty(i);
#region Logging
@@ -143,11 +143,6 @@
property.Direction =
sqlParameter.Direction;
}
- // DbDataParameter
dataParameter = (IDbDataParameter)parameters[i];
- // property.Precision =
dataParameter.Precision;
- // property.Scale =
dataParameter.Scale;
- // property.Size =
dataParameter.Size;
-
sqlParameter.Direction =
property.Direction;
}
#endregion
@@ -168,8 +163,7 @@
// With a ParameterMap, we could specify the
ParameterDbTypeProperty
if (request.ParameterMap != null)
{
- if
(request.ParameterMap.GetProperty(i).DbType != null &&
-
request.ParameterMap.GetProperty(i).DbType.Length >0)
+ if (property.DbType != null && property.DbType.Length > 0)
{
string dbTypePropertyName =
session.DataSource.DbProvider.ParameterDbTypeProperty;
object propertyValue =
ObjectProbe.GetMemberValue(sqlParameter, dbTypePropertyName,
request.DataExchangeFactory.AccessorFactory);
@@ -220,20 +214,20 @@
// JIRA-49 Fixes (size, precision, and scale)
if
(session.DataSource.DbProvider.SetDbParameterSize)
{
- if
(((IDbDataParameter)sqlParameter).Size > 0)
+ if (sqlParameter.Size > 0)
{
-
((IDbDataParameter)parameterCopy).Size = ((IDbDataParameter)sqlParameter).Size;
+ parameterCopy.Size =
sqlParameter.Size;
}
}
if
(session.DataSource.DbProvider.SetDbParameterPrecision)
{
-
((IDbDataParameter)parameterCopy).Precision =
((IDbDataParameter)sqlParameter).Precision;
+ parameterCopy.Precision =
sqlParameter.Precision;
}
if
(session.DataSource.DbProvider.SetDbParameterScale)
{
- ((IDbDataParameter)parameterCopy).Scale
= ((IDbDataParameter)sqlParameter).Scale;
+ parameterCopy.Scale =
sqlParameter.Scale;
}
parameterCopy.ParameterName =
sqlParameter.ParameterName;
Added:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IDbDataParameterCollection.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IDbDataParameterCollection.cs?view=auto&rev=477815
==============================================================================
(empty)
Propchange:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IDbDataParameterCollection.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IDbDataParameterCollection.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatement.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatement.cs?view=diff&rev=477815&r1=477814&r2=477815
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatement.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatement.cs
Tue Nov 21 10:46:52 2006
@@ -43,7 +43,7 @@
private string _preparedSsql = string.Empty;
private StringCollection _dbParametersName = new
StringCollection ();
- private IDataParameter[] _dbParameters = null;
+ private IDbDataParameter[] _dbParameters = null;
#endregion
@@ -61,7 +61,7 @@
/// <summary>
/// The list of IDataParameter to use for the PreparedSql.
/// </summary>
- public IDataParameter[] DbParameters
+ public IDbDataParameter[] DbParameters
{
get { return _dbParameters;}
set { _dbParameters =value;}
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs?view=diff&rev=477815&r1=477814&r2=477815
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs
Tue Nov 21 10:46:52 2006
@@ -170,24 +170,62 @@
// (or discover them & populate the cache)
IDataParameter[] commandParameters =
DBHelperParameterCache.GetSpParameterSet(session, _commandText);
- _preparedStatement.DbParameters = new
IDataParameter[commandParameters.Length];
+ _preparedStatement.DbParameters = new
IDbDataParameter[commandParameters.Length];
int start =
session.DataSource.DbProvider.ParameterPrefix.Length;
for(int i=0; i< commandParameters.Length;i++)
{
- IDataParameter dataParameter =
commandParameters[i];
+ IDbDataParameter dataParameter =
(IDbDataParameter)commandParameters[i];
if
(session.DataSource.DbProvider.UseParameterPrefixInParameter == false)
{
- if
(dataParameter.ParameterName.StartsWith(session.DataSource.DbProvider.ParameterPrefix))
{
+ if
(dataParameter.ParameterName.StartsWith(session.DataSource.DbProvider.ParameterPrefix))
+ {
dataParameter.ParameterName =
dataParameter.ParameterName.Substring(start);
}
}
_preparedStatement.DbParametersName.Add(
dataParameter.ParameterName );
_preparedStatement.DbParameters[i] =
dataParameter;
}
+
+ // Re-sort DbParameters to match order used in the parameterMap
+ IDbDataParameter[] sortedDbParameters = new
IDbDataParameter[commandParameters.Length];
+ for (int i = 0; i < _statement.ParameterMap.Properties.Count; i++)
+ {
+ sortedDbParameters[i] = Search(session,
_preparedStatement.DbParameters, _statement.ParameterMap.Properties[i], i);
+ }
+ _preparedStatement.DbParameters = sortedDbParameters;
}
+ private IDbDataParameter Search(ISqlMapSession
session,IDbDataParameter[] parameters, ParameterProperty property, int index)
+ {
+ if (property.ColumnName.Length>0)
+ {
+ for (int i = 0; i < parameters.Length; i++)
+ {
+ string parameterName = parameters[i].ParameterName;
+ if
(session.DataSource.DbProvider.UseParameterPrefixInParameter)
+ {
+ if
(parameterName.StartsWith(session.DataSource.DbProvider.ParameterPrefix))
+ {
+ int prefixLength =
session.DataSource.DbProvider.ParameterPrefix.Length;
+ parameterName =
parameterName.Substring(prefixLength);
+ }
+ }
+ if (property.ColumnName.Equals(parameterName))
+ {
+ return parameters[i];
+ }
+ }
+ throw new IndexOutOfRangeException("The specified
IDbDataParameter '" + property.ColumnName + "' does not exist: ");
+ }
+ else
+ {
+ return parameters[index];
+ }
+
+ }
+
/// <summary>
/// Create IDataParameters for command text statement.
@@ -208,7 +246,7 @@
list = _request.ParameterMap.PropertiesList;
}
- _preparedStatement.DbParameters = new
IDataParameter[list.Count];
+ _preparedStatement.DbParameters = new IDbDataParameter[list.Count];
for(int i =0; i<list.Count; i++)
{
@@ -224,7 +262,7 @@
sqlParamName = "param" + i;
}
- IDataParameter dataParameter = _session.CreateDataParameter();
+ IDbDataParameter dataParameter =
_session.CreateDataParameter();
// Manage dbType attribute if any
if (property.DbType != null &&
property.DbType.Length >0)
@@ -244,18 +282,18 @@
{
if (property.Size != -1)
{
-
((IDbDataParameter)dataParameter).Size = property.Size;
+ dataParameter.Size =
property.Size;
}
}
if
(_session.DataSource.DbProvider.SetDbParameterPrecision)
{
-
((IDbDataParameter)dataParameter).Precision = property.Precision;
+ dataParameter.Precision =
property.Precision;
}
if
(_session.DataSource.DbProvider.SetDbParameterScale)
{
- ((IDbDataParameter)dataParameter).Scale
= property.Scale;
+ dataParameter.Scale = property.Scale;
}
// Set as direction parameter
@@ -293,7 +331,7 @@
list = _request.ParameterMap.PropertiesList;
}
- _preparedStatement.DbParameters = new
IDataParameter[list.Count];
+ _preparedStatement.DbParameters = new IDbDataParameter[list.Count];
// ParemeterMap are required for procedure and we
tested existance in Prepare() method
// so we don't have to test existence here.
@@ -313,7 +351,7 @@
sqlParamName = property.ColumnName;
}
- IDataParameter dataParameter =
_session.CreateCommand(_statement.CommandType).CreateParameter();
+ IDbDataParameter dataParameter =
_session.CreateCommand(_statement.CommandType).CreateParameter();
// Manage dbType attribute if any
if (property.DbType!=null &&
property.DbType.Length >0)
@@ -333,18 +371,18 @@
{
if (property.Size != -1)
{
-
((IDbDataParameter)dataParameter).Size = property.Size;
+ dataParameter.Size =
property.Size;
}
}
if
(_session.DataSource.DbProvider.SetDbParameterPrecision)
{
-
((IDbDataParameter)dataParameter).Precision = property.Precision;
+ dataParameter.Precision =
property.Precision;
}
if
(_session.DataSource.DbProvider.SetDbParameterScale)
{
- ((IDbDataParameter)dataParameter).Scale
= property.Scale;
+ dataParameter.Scale = property.Scale;
}
// Set as direction parameter
@@ -360,6 +398,7 @@
_propertyDbParameterMap.Add(property,
dataParameter);
}
}
+
}
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj?view=diff&rev=477815&r1=477814&r2=477815
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj
Tue Nov 21 10:46:52 2006
@@ -100,11 +100,9 @@
<Compile Include="Commands\DefaultPreparedCommand.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Commands\IDbDataParameterCollection.cs" />
<Compile Include="Commands\InMemoryDataReader.cs" />
<Compile Include="Commands\IPreparedCommand.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Commands\PreparedCommandProxy.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Commands\PreparedCommandFactory.cs">
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs?view=diff&rev=477815&r1=477814&r2=477815
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
Tue Nov 21 10:46:52 2006
@@ -830,7 +830,7 @@
{
rows = command.ExecuteNonQuery();
- ExecutePostSelect(request);
+ //ExecutePostSelect(request);
RetrieveOutputParameters(request, session, command,
parameterObject);
}
@@ -911,7 +911,7 @@
request.DataExchangeFactory.AccessorFactory);
}
- ExecutePostSelect(request);
+ //ExecutePostSelect(request);
RetrieveOutputParameters(request, session, command,
parameterObject);
}
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/DictionaryStrategy.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/DictionaryStrategy.cs?view=diff&rev=477815&r1=477814&r2=477815
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/DictionaryStrategy.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/DictionaryStrategy.cs
Tue Nov 21 10:46:52 2006
@@ -58,13 +58,14 @@
}
int count = reader.FieldCount;
+ IDictionary dictionary = (IDictionary) outObject;
for (int i = 0; i < count; i++)
{
ResultProperty property = new ResultProperty();
property.PropertyName = "value";
property.ColumnIndex = i;
property.TypeHandler =
request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(reader.GetFieldType(i));
- ((IDictionary) outObject).Add(
+ dictionary.Add(
reader.GetName(i),
property.GetDataBaseValue(reader));
}
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapSession.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapSession.cs?view=diff&rev=477815&r1=477814&r2=477815
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapSession.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapSession.cs Tue Nov 21
10:46:52 2006
@@ -260,10 +260,10 @@
}
else
{
- if (_connection == null || _connection.State !=
ConnectionState.Open)
+ if (_connection == null || _connection.State !=
ConnectionState.Open)
{
- throw new
DataMapperException("SqlMapSession could not invoke BeginTransaction(). A
Connection must be started. Call OpenConnection() first.");
- }
+ this.OpenConnection();
+ }
_transaction = _connection.BeginTransaction();
if (_logger.IsDebugEnabled)
{