/// <summary> /// Build the PreparedStatement /// </summary> /// <param name="session"></param> /// <param name="sqlStatement"></param> public void BuildPreparedStatement(ISqlMapSession session, string sqlStatement) { RequestScope request = new RequestScope( _dataExchangeFactory, session, _statement); PreparedStatementFactory factory = new PreparedStatementFactory( session, request, _statement, sqlStatement); _preparedStatement = factory.Prepare(); }
/// <summary> /// Build the PreparedStatement /// </summary> /// <param name="session"></param> /// <param name="commandText"></param> /// <param name="request"></param> public PreparedStatement BuildPreparedStatement(ISqlMapSession session, RequestScope request, string commandText) { if ( _preparedStatement == null ) { lock(_synRoot) { if (_preparedStatement==null) { PreparedStatementFactory factory = new PreparedStatementFactory( session, request, _statement, commandText); _preparedStatement = factory.Prepare(); } } } return _preparedStatement; }
/// <summary> /// Create a list of IDataParameter for the statement and build the sql string. /// </summary> public PreparedStatement Prepare() { _preparedStatement = new PreparedStatement(); _parameterPrefix = _session.DataSource.DbProvider.ParameterPrefix; _preparedStatement.PreparedSql = _commandText; if (_statement.CommandType == CommandType.Text) { if (_request.ParameterMap != null) { CreateParametersForTextCommand(); EvaluateParameterMap(); } } else if (_statement.CommandType == CommandType.StoredProcedure) // StoredProcedure { if (_request.ParameterMap == null) // No parameterMap --> error { throw new DataMapperException("A procedure statement tag must have a parameterMap attribute, which is not the case for the procedure '"+_statement.Id+"."); } else // use the parameterMap { if (_session.DataSource.DbProvider.UseDeriveParameters) { DiscoverParameter(_session); } else { CreateParametersForProcedureCommand(); } } #region Fix for Odbc // Although executing a parameterized stored procedure using the ODBC .NET Provider // is slightly different from executing the same procedure using the SQL or // the OLE DB Provider, there is one important difference // -- the stored procedure must be called using the ODBC CALL syntax rather than // the name of the stored procedure. // For additional information on this CALL syntax, // see the page entitled "Procedure Calls" in the ODBC Programmer's Reference // in the MSDN Library. //http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q309486 if ( _session.DataSource.DbProvider.IsObdc == true ) { StringBuilder commandTextBuilder = new StringBuilder("{ call "); commandTextBuilder.Append( _commandText ); if (_preparedStatement.DbParameters.Length >0) { commandTextBuilder.Append(" ("); int supIndex = _preparedStatement.DbParameters.Length-1; for(int i=0;i<supIndex;i++) { commandTextBuilder.Append("?,"); } commandTextBuilder.Append("?) }"); } _preparedStatement.PreparedSql = commandTextBuilder.ToString(); } #endregion } if (_logger.IsDebugEnabled) { _logger.Debug("Statement Id: [" + _statement.Id + "] Prepared SQL: [" + _preparedStatement.PreparedSql + "]"); } return _preparedStatement; }
/// <summary> /// Create a list of IDataParameter for the statement and build the sql string. /// </summary> public PreparedStatement Prepare() { _preparedStatement = new PreparedStatement(); _parameterPrefix = _session.DataSource.DbProvider.ParameterPrefix; _preparedStatement.PreparedSql = _commandText; if (_statement.CommandType == CommandType.Text) { if (_request.ParameterMap != null) { CreateParametersForTextCommand(); EvaluateParameterMap(); } } else if (_statement.CommandType == CommandType.StoredProcedure) // StoredProcedure { if (_request.ParameterMap == null) // No parameterMap --> error { throw new DataMapperException("A procedure statement tag must have a parameterMap attribute, which is not the case for the procedure '" + _statement.Id + "."); } else // use the parameterMap { if (_session.DataSource.DbProvider.UseDeriveParameters) { DiscoverParameter(_session); } else { CreateParametersForProcedureCommand(); } } #region Fix for Odbc // Although executing a parameterized stored procedure using the ODBC .NET Provider // is slightly different from executing the same procedure using the SQL or // the OLE DB Provider, there is one important difference // -- the stored procedure must be called using the ODBC CALL syntax rather than // the name of the stored procedure. // For additional information on this CALL syntax, // see the page entitled "Procedure Calls" in the ODBC Programmer's Reference // in the MSDN Library. //http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q309486 if (_session.DataSource.DbProvider.IsObdc == true) { StringBuilder commandTextBuilder = new StringBuilder("{ call "); commandTextBuilder.Append(_commandText); if (_preparedStatement.DbParameters.Length > 0) { commandTextBuilder.Append(" ("); int supIndex = _preparedStatement.DbParameters.Length - 1; for (int i = 0; i < supIndex; i++) { commandTextBuilder.Append("?,"); } commandTextBuilder.Append("?) }"); } _preparedStatement.PreparedSql = commandTextBuilder.ToString(); } #endregion } if (_logger.IsDebugEnabled) { _logger.Debug("Statement Id: [" + _statement.Id + "] Prepared SQL: [" + _preparedStatement.PreparedSql + "]"); } return(_preparedStatement); }