Clover.NET coverage report - Coverage

Coverage timestamp: Friday, May 20, 2005 9:17:00 PM

File Stats: LOC: 227   Methods: 1
NCLOC: 142 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Commands\EmbedParamsPreparedCommand.cs 0.0 % 0.0 % 0.0 % 0.0 %
coverage
1   #region Apache Notice
2  
3   /*****************************************************************************
4   * $Header: $
5   * $Revision: $
6   * $Date: $
7   *
8   * iBATIS.NET Data Mapper
9   * Copyright (C) 2005 - Gilles Bayon
10   *
11   *
12   * Licensed under the Apache License, Version 2.0 (the "License");
13   * you may not use this file except in compliance with the License.
14   * You may obtain a copy of the License at
15   *
16   * http://www.apache.org/licenses/LICENSE-2.0
17   *
18   * Unless required by applicable law or agreed to in writing, software
19   * distributed under the License is distributed on an "AS IS" BASIS,
20   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   * See the License for the specific language governing permissions and
22   * limitations under the License.
23   *
24   ********************************************************************************/
25  
26   #endregion
27  
28   #region Imports
29  
30   using System;
31   using System.Data;
32   using System.Collections;
33   using IBatisNet.Common;
34   using IBatisNet.Common.Utilities.Objects;
35   using IBatisNet.DataMapper.Configuration.Statements;
36   using IBatisNet.DataMapper.Configuration.ParameterMapping;
37   using IBatisNet.DataMapper.Exceptions;
38   using IBatisNet.DataMapper.Scope;
39  
40   #endregion
41  
42   namespace IBatisNet.DataMapper.Commands
43   {
44   /// <summary>
45   /// Summary description for EmbedParamsPreparedCommand.
46   /// </summary>
47   internal class EmbedParamsPreparedCommand : DefaultPreparedCommand
48   {
49   #region EmbedParamsPreparedCommand Members
50  
51   /// <summary>
52   ///
53   /// </summary>
54   /// <param name="session"></param>
55   /// <param name="command"></param>
56   /// <param name="request"></param>
57   /// <param name="statement"></param>
58   /// <param name="parameterObject"></param>
59 0 protected override void ApplyParameterMap
60   (IDalSession session, IDbCommand command,
61   RequestScope request, IStatement statement, object parameterObject)
62   {
63   ArrayList properties = request.PreparedStatement.DbParametersName;
64   ArrayList parameters = request.PreparedStatement.DbParameters;
65   object parameterValue = null;
66  
67   for (int i = 0; i < properties.Count; ++i)
68   {
69   IDataParameter sqlParameter = (IDataParameter) parameters[i];
70   string propertyName = (string) properties[i];
71  
72   if (command.CommandType == CommandType.Text)
73   {
74   if (propertyName != "value") // Inline Parameters && Parameters via ParameterMap
75   {
76   ParameterProperty property = request.ParameterMap.GetProperty(i);
77  
78   // parameterValue = request.ParameterMap.GetValueOfProperty(parameterObject,
79   // property.PropertyName);
80   }
81   else // 'value' parameter
82   {
83   parameterValue = parameterObject;
84   }
85   }
86   else // CommandType.StoredProcedure
87   {
88   // A store procedure must always use a ParameterMap
89   // to indicate the mapping order of the properties to the columns
90   if (request.ParameterMap == null) // Inline Parameters
91   {
92   throw new DataMapperException("A procedure statement tag must alway have a parameterMap attribute, which is not the case for the procedure '" + statement.Id + "'.");
93   }
94   else // Parameters via ParameterMap
95   {
96   ParameterProperty property = request.ParameterMap.GetProperty(i);
97  
98   if (property.DirectionAttribute.Length == 0)
99   {
100   property.Direction = sqlParameter.Direction;
101   }
102  
103   // IDbDataParameter dataParameter = (IDbDataParameter)parameters[i];
104   // property.Precision = dataParameter.Precision;
105   // property.Scale = dataParameter.Scale;
106   // property.Size = dataParameter.Size;
107  
108   sqlParameter.Direction = property.Direction;
109   // parameterValue = request.ParameterMap.GetValueOfProperty(parameterObject, property.PropertyName);
110   }
111   }
112  
113   IDataParameter parameterCopy = command.CreateParameter();
114   // Fix JIRA 20
115   sqlParameter.Value = parameterValue;
116   parameterCopy.Value = parameterValue;
117  
118   parameterCopy.Direction = sqlParameter.Direction;
119  
120   // With a ParameterMap, we could specify the ParameterDbTypeProperty
121   if (statement.ParameterMap != null)
122   {
123   if (request.ParameterMap.GetProperty(i).DbType != null &&
124   request.ParameterMap.GetProperty(i).DbType.Length >0)
125   {
126   string dbTypePropertyName = session.DataSource.Provider.ParameterDbTypeProperty;
127  
128   ObjectProbe.SetPropertyValue(parameterCopy, dbTypePropertyName, ObjectProbe.GetPropertyValue(sqlParameter, dbTypePropertyName));
129   }
130   else
131   {
132   //parameterCopy.DbType = sqlParameter.DbType;
133   }
134   }
135   else
136   {
137   //parameterCopy.DbType = sqlParameter.DbType;
138   }
139  
140   // JIRA-49 Fixes (size, precision, and scale)
141   if (session.DataSource.Provider.SetDbParameterSize)
142   {
143   if (((IDbDataParameter)sqlParameter).Size > 0)
144   {
145   ((IDbDataParameter)parameterCopy).Size = ((IDbDataParameter)sqlParameter).Size;
146   }
147   }
148  
149   if (session.DataSource.Provider.SetDbParameterPrecision)
150   {
151   ((IDbDataParameter)parameterCopy).Precision = ((IDbDataParameter)sqlParameter).Precision;
152   }
153  
154   if (session.DataSource.Provider.SetDbParameterScale)
155   {
156   ((IDbDataParameter)parameterCopy).Scale = ((IDbDataParameter)sqlParameter).Scale;
157   }
158  
159   parameterCopy.ParameterName = sqlParameter.ParameterName;
160  
161   command.Parameters.Add(parameterCopy);
162  
163  
164   // NOTE:
165   // Code from Oleksa Borodie to embed parameter values
166   // into command text/sql statement.
167   // NEED TO MERGE WITH ABOVE AFTER INITIAL TESTING
168   // TO REMOVE REDUNDANT LOOPING!
169  
170   // replace parameter names with parameter values
171   // only for parameters with names, parameterMaps will be ignored
172   IDataParameter p;
173   for (int iCnt = command.Parameters.Count - 1; iCnt >= 0; iCnt--)
174   {
175   p = (IDataParameter) command.Parameters[iCnt];
176   if (p.Direction == ParameterDirection.Input &&
177   command.CommandText.IndexOf(p.ParameterName) > 0)
178   {
179   switch (p.DbType)
180   {
181   case DbType.String:
182   case DbType.AnsiString:
183   case
184   DbType.AnsiStringFixedLength:
185   case DbType.StringFixedLength:
186   command.CommandText =
187   command.CommandText.Replace(p.ParameterName,
188   "\'" + p.Value.ToString().Replace("\'", "\'\'") + "\'");
189   break;
190   case DbType.Date:
191   case DbType.DateTime:
192   DateTime v =
193   Convert.ToDateTime(p.Value);
194   command.CommandText =
195   command.CommandText.Replace(p.ParameterName,
196   String.Format("\'{0}.{1}.{2} {3}:{4}:{5}.{6}\'", v.Year, v.Month,
197   v.Day, v.Hour, v.Minute, v.Second, v.Millisecond));
198   // command.CommandText =
199   command.CommandText.Replace(p.ParameterName,
200   "\'" + p.Value.ToString() + "\'");
201   break;
202   case DbType.Double:
203   case DbType.Decimal:
204   case DbType.Currency:
205   case DbType.Single:
206   command.CommandText =
207   command.CommandText.Replace(p.ParameterName,
208   p.Value.ToString().Replace(',', '.'));
209   break;
210   default:
211   command.CommandText =
212   command.CommandText.Replace(p.ParameterName, p.Value.ToString());
213   break;
214   }
215   command.Parameters.RemoveAt(iCnt);
216   }
217   }
218  
219  
220   }
221   }
222  
223   #endregion
224   }
225   }
226  
227