public object ExecuteOracleScalar(OracleCommand command)
 {
     PrepareCommand(command);
     try
     {
         object result = command.ExecuteOracleScalar();
     #if DEBUG
         DatabaseLog.WriteInfo(command);
     #endif
         return result;
     }
     catch (Exception e)
     {
         DatabaseLog.WriteError(e.Message, command);
         throw;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 执行一个OracleCommand(返回一个结果object)        /// </summary>   
        /// <param name="connection">有效的 OracleConnection</param>   
        /// <param name="sqlString">SQL</param> 
        /// <param name="parameterValues">以一个数组的形式返回OracleParameters ,如果没有参数即为null</param>
        /// <returns></returns>
        public  object ExecuteScalarByTransaction(OracleConnection connObjection, string sqlString, OracleParameter[] parameterValues)
        {
            OracleCommand cmd = new OracleCommand();
            try
            {
                if (connObjection.State != ConnectionState.Open)
                {
                    connObjection.Open();
                }
                cmd.Connection = connObjection;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = sqlString;
                if (Transaction != null)
                {
                    cmd.Transaction = Transaction;
                    //Transaction = connObjection.BeginTransaction(IsolationLevel.ReadCommitted);
                }

                if (parameterValues != null)
                {
                    AttachParameters(cmd, parameterValues);
                }
                return cmd.ExecuteOracleScalar();
            }
            catch (System.Exception e)
            {
                if (cmd.Transaction != null)
                {
                    cmd.Transaction.Rollback();
                    LogHelper.WriteLog("MsOracle.ExecuteScalarByTransaction(OracleConnection connObjection, string sqlString, params OracleParameter[] parameterValues)", "回滚事务", e);
                }
                throw new System.Exception(e.Message);
            }
        }