You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2005/05/06 14:44:25 UTC

svn commit: r168596 - /incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug /incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements

Author: gbayon
Date: Fri May  6 05:44:23 2005
New Revision: 168596

URL: http://svn.apache.org/viewcvs?rev=168596&view=rev
Log:
- Correction in PreparedStatementFactory.cs for CreateParameter*

Modified:
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/providers.config
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatement.cs
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs

Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/providers.config
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/providers.config?rev=168596&r1=168595&r2=168596&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/providers.config (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/providers.config Fri May  6 05:44:23 2005
@@ -127,7 +127,7 @@
 	<provider
 		name="ByteFx"
 		description="MySQL, ByteFx provider V0.7.6.15073"
-		enabled="false"
+		enabled="true"
 		assemblyName="ByteFX.MySqlClient, Version=0.7.6.15073, Culture=neutral, PublicKeyToken=f2fef6fed1732fc1"
 		connectionClass="ByteFX.Data.MySqlClient.MySqlConnection" 
 		commandClass="ByteFX.Data.MySqlClient.MySqlCommand"

Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatement.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatement.cs?rev=168596&r1=168595&r2=168596&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatement.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatement.cs Fri May  6 05:44:23 2005
@@ -24,8 +24,11 @@
  ********************************************************************************/
 #endregion
 
-using System;
+#region Using
+
 using System.Collections;
+
+#endregion 
 
 namespace IBatisNet.DataMapper.Configuration.Statements
 {

Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs?rev=168596&r1=168595&r2=168596&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs Fri May  6 05:44:23 2005
@@ -96,7 +96,7 @@
 			{
 				if (_request.ParameterMap != null) 
 				{
-					CreateParametersForStatementText();
+					CreateParametersForTextCommand();
 					EvaluateParameterMap();
 				}
 			}
@@ -114,8 +114,8 @@
 					}
 					else
 					{
-						CreateParametersForStatementText();
-						EvaluateParameterMap();
+						CreateParametersForProcedureCommand();
+						// EvaluateParameterMap(); // Did we need that ? I don't think for the procedure
 					}
 				}
 
@@ -188,9 +188,9 @@
 
 
 		/// <summary>
-		/// Create IDataParameters for statement Text.
+		/// Create IDataParameters for command text statement.
 		/// </summary>
-		private void CreateParametersForStatementText()
+		private void CreateParametersForTextCommand()
 		{
 			string sqlParamName = string.Empty;
 			string dbTypePropertyName = _session.DataSource.Provider.ParameterDbTypeProperty;
@@ -209,38 +209,92 @@
 
 			foreach(ParameterProperty property in list)
 			{
-				// Check if property is part of a parameterMap for naming purposes
-				// used when retrieving output parameters (stored procs/input/output).
-				// property.ColumnName is used when retrieving output parameters,
-				// so it has to be used here as the parameter name!
-				if (_statement.ParameterMap != null && 
-					(property.Direction == ParameterDirection.Output || 
-					property.Direction == ParameterDirection.InputOutput)) 
+				// From Ryan Yao: JIRA-27, used "param" + i++ for sqlParamName
+				sqlParamName = _parameterPrefix + "param" + i++;
+
+				IDataParameter dataParameter = _session.CreateCommand(_statement.CommandType).CreateParameter();
+
+				// Manage dbType attribut if any
+				if (property.DbType.Length >0) 
 				{
-					if (_session.DataSource.Provider.UseParameterPrefixInParameter)
-					{
-						sqlParamName = _parameterPrefix + property.ColumnName;
-					}
-					else //obdc/oledb
-					{
-						sqlParamName =  property.ColumnName;
-					}
+					// Exemple : Enum.parse(System.Data.SqlDbType, 'VarChar')
+					object dbType = Enum.Parse( enumDbType, property.DbType, true );
+
+					// Exemple : ObjectHelper.SetProperty(sqlparameter, 'SqlDbType', SqlDbType.Int);
+					ObjectProbe.SetPropertyValue(dataParameter, dbTypePropertyName, dbType);
 				}
-				else 
+
+				// Set IDbDataParameter
+				// JIRA-49 Fixes (size, precision, and scale)
+				if (_session.DataSource.Provider.SetDbParameterSize) 
 				{
-					if (_session.DataSource.Provider.UseParameterPrefixInParameter )
-					{
-						// From Ryan Yao: JIRA-27
-						// sqlParamName = _parameterPrefix + paramName;
-						sqlParamName = _parameterPrefix + "param" + i++;
-					}
-					else //obdc/oledb
+					if (property.Size != -1)
 					{
-						// sqlParamName = paramName;
-						sqlParamName = "param" + i++;
+						((IDbDataParameter)dataParameter).Size = property.Size;
 					}
 				}
 
+				if (_session.DataSource.Provider.SetDbParameterPrecision) 
+				{
+					((IDbDataParameter)dataParameter).Precision = property.Precision;
+				}
+				
+				if (_session.DataSource.Provider.SetDbParameterScale) 
+				{
+					((IDbDataParameter)dataParameter).Scale = property.Scale;
+				}
+				
+				// Set as direction parameter
+				dataParameter.Direction = property.Direction;
+
+				dataParameter.ParameterName = sqlParamName;
+
+				_preparedStatement.DbParametersName.Add( property.PropertyName );
+				_preparedStatement.DbParameters.Add( dataParameter );	
+
+				if ( _session.DataSource.Provider.UsePositionalParameters == false)
+				{
+					_propertyDbParameterMap.Add(property, dataParameter);
+				}
+			}
+		}
+
+
+		/// <summary>
+		/// Create IDataParameters for procedure statement.
+		/// </summary>
+		private void CreateParametersForProcedureCommand()
+		{
+			string sqlParamName = string.Empty;
+			string dbTypePropertyName = _session.DataSource.Provider.ParameterDbTypeProperty;
+			Type enumDbType = _session.DataSource.Provider.ParameterDbType;
+			IList list = null;
+
+			if (_session.DataSource.Provider.UsePositionalParameters) //obdc/oledb
+			{
+				list = _request.ParameterMap.Properties;
+			}
+			else 
+			{
+				list = _request.ParameterMap.PropertiesList;
+			}
+
+			// ParemeterMap are required for procedure and we tested existance in Prepare() method
+			// so we don't have to test existence here.
+			// A ParameterMap used in CreateParametersForProcedureText must
+			// have property and column attributes set.
+			// The column attribute is the name of a procedure parameter.
+			foreach(ParameterProperty property in list)
+			{
+				if (_session.DataSource.Provider.UseParameterPrefixInParameter)
+				{
+					sqlParamName = _parameterPrefix + property.ColumnName;
+				}
+				else //obdc/oledb
+				{
+					sqlParamName =  property.ColumnName;
+				}
+
 				IDataParameter dataParameter = _session.CreateCommand(_statement.CommandType).CreateParameter();
 
 				// Manage dbType attribut if any
@@ -264,7 +318,7 @@
 				}
 
 				if (_session.DataSource.Provider.SetDbParameterPrecision) 
-                {
+				{
 					((IDbDataParameter)dataParameter).Precision = property.Precision;
 				}
 				
@@ -285,7 +339,6 @@
 				{
 					_propertyDbParameterMap.Add(property, dataParameter);
 				}
-				
 			}
 		}