Hello. I''ve asked about poor performance with MS SQL sp_executesql procedure and query with parameters. I've wrote some piece of code that will test if there any parameters with names in the command.Parameters and if so - replace paramter name with it value. The replace algorithm is very simple. This procedure is calling after ApplyParameterMap in the MappedStatement.CreatePreparedCommand. As far as I understood only MS SQL server has sp_executesql performance luck. Is it possible in the runtime to know - what database is iBATIS work with? Should this code be implemented into the trunk?
[code] /// <summary> /// replace parameter names with parameter values /// only for parameters with names, parameterMaps will be igonred /// </summary> /// <param name="session"></param> /// <param name="command"></param> private void EmbedParameters(IDalSession session, IDbCommand command) { IDataParameter p; for(int i = command.Parameters.Count - 1; i >= 0; i--) { p = (IDataParameter)command.Parameters[i]; if(p.Direction == ParameterDirection.Input && command.CommandText.IndexOf(p.ParameterName) > 0) { switch(p.DbType) { case DbType.String: case DbType.AnsiString: case DbType.AnsiStringFixedLength: case DbType.StringFixedLength: command.CommandText = command.CommandText.Replace(p.ParameterName, "\'"+p.Value.ToString().Replace("\'", "\'\'")+"\'"); break; case DbType.Date: case DbType.DateTime: DateTime v = Convert.ToDateTime(p.Value); command.CommandText = command.CommandText.Replace(p.ParameterName, String.Format("\'{0}.{1}.{2} {3}:{4}:{5}.{6}\'", v.Year, v.Month, v.Day, v.Hour, v.Minute, v.Second, v.Millisecond)); // command.CommandText = command.CommandText.Replace(p.ParameterName, "\'"+p.Value.ToString()+"\'"); break; case DbType.Double: case DbType.Decimal: case DbType.Currency: case DbType.Single: command.CommandText = command.CommandText.Replace(p.ParameterName, p.Value.ToString().Replace(',', '.')); break; default: command.CommandText = command.CommandText.Replace(p.ParameterName, p.Value.ToString()); break; } command.Parameters.RemoveAt(i); } } } [/code]