Esempio n. 1
0
 /// <summary>
 /// Cria a instancia com os dados do comando.
 /// </summary>
 /// <param name="command"></param>
 /// <param name="rowsAffects">Quantidade de linhas afetadas.</param>
 /// <param name="executionTime">Tempo de execução do comando.</param>
 public CommandExecutionInfo(System.Data.IDbCommand command, TimeSpan executionTime, int rowsAffects)
 {
     if (command == null)
     {
         throw new ArgumentNullException("command");
     }
     _commandText = command.CommandText;
     _commandType = command.CommandType;
     if (command.Parameters != null)
     {
         var parameters = new System.Data.IDataParameter[command.Parameters.Count];
         var enumerator = command.Parameters.GetEnumerator();
         for (var i = 0; enumerator.MoveNext(); i++)
         {
             parameters[i] = (System.Data.IDataParameter)enumerator.Current;
         }
         _parameters = parameters;
     }
     else
     {
         _parameters = new System.Data.IDataParameter[0];
     }
     _timeout     = command.CommandTimeout;
     _rowsAffects = rowsAffects;
     _elapsedTime = executionTime;
     _success     = true;
 }
Esempio n. 2
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="parameter"></param>
 public DataParameter(System.Data.IDataParameter parameter)
 {
     if (parameter == null)
     {
         throw new ArgumentNullException("parameter");
     }
     ParameterName = parameter.ParameterName;
     Value         = parameter.Value;
 }
Esempio n. 3
0
        public override void Set(System.Data.IDbCommand cmd, object value, int index)
        {
            System.Data.IDataParameter parameter = (System.Data.IDataParameter)cmd.Parameters[index];
            Int64?nullableValue = (Int64?)value;

            if (nullableValue.HasValue)
            {
                parameter.Value = nullableValue.Value;
            }
            else
            {
                parameter.Value = DBNull.Value;
            }
        }
Esempio n. 4
0
 public override System.Data.IDataParameter CreateProcParameter(string name, object value, System.Data.ParameterDirection direction)
 {
     System.Data.IDataParameter dp = base.CreateProcParameter(name, value, direction);
     if (direction == System.Data.ParameterDirection.Output)
     {
         if (value != null && value.GetType() == typeof(OracleProcCursor))
         {
             OracleParameter op = (OracleParameter)dp;
             op.OracleType = OracleType.Cursor;
             op.Value      = DBNull.Value;
         }
     }
     return(dp);
 }
        // Study implementation of skip/take.
        public List <Movie> GetMovies(int skip, int take)
        {
            List <Movie> movie = new List <Movie>();

            AssuredConnected();
            using (System.Data.IDbCommand command = connection.CreateCommand())
            {
                // Demonstrate a text command.
                // Be leary - but valid.
                // Safe with int only.
                // string text = $"select * from movies";
                // command.CommandText = text;
                // command.CommandType = System.Data.CommandType.Text;

                command.CommandText = "[stored proc]";
                command.CommandType = System.Data.CommandType.StoredProcedure;

                System.Data.IDataParameter P_skip = command.CreateParameter();
                System.Data.IDataParameter P_take = command.CreateParameter();

                P_skip.Direction     = System.Data.ParameterDirection.Input;
                P_skip.ParameterName = "@skip";
                P_skip.DbType        = System.Data.DbType.Int32;
                P_skip.Value         = skip;

                P_take.Direction     = System.Data.ParameterDirection.Input;
                P_take.ParameterName = "@take";
                P_take.DbType        = System.Data.DbType.Int32;
                P_take.Value         = take;

                command.Parameters.Add(P_skip);
                command.Parameters.Add(P_take);

                // Study the implementation.
                using (System.Data.IDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        movie.Add(MapMovie(reader));
                    }
                }
            }

            return(movie);
        }
Esempio n. 6
0
        public int getDatabaseMajorVersion()
        {
            System.Data.IDbConnection dbConnection = null;

            try
            {
                dbConnection = new System.Data.SqlClient.SqlConnection(Configuration.Configuration.GetDBConnectionString());
                string queryString = "usp_GetVersionMajor";
                System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();

                dbConnection.Open();

                dbCommand.CommandText = queryString;
                dbCommand.CommandType = System.Data.CommandType.StoredProcedure;
                dbCommand.Connection  = dbConnection;

                System.Data.IDataParameter dbParam_number = new System.Data.SqlClient.SqlParameter();
                dbParam_number.ParameterName = "@smiMajor";
                dbParam_number.Direction     = System.Data.ParameterDirection.Output;
                dbParam_number.DbType        = System.Data.DbType.Int16;
                dbCommand.Parameters.Add(dbParam_number);

                dbCommand.ExecuteNonQuery();
                System.Data.IDataParameter dbParam_result =
                    (System.Data.IDataParameter)dbCommand.Parameters["@smiMajor"];
                string returnValue = dbParam_result.Value.ToString();
                dbConnection.Close();
                dbConnection.Dispose();

                return(Int32.Parse(returnValue));
            }
            catch (Exception e)
            {
                if (dbConnection != null)
                {
                    dbConnection.Close();
                    dbConnection.Dispose();
                }

                // Log the exception
                log.Error("Failed to get database major version", e);
                throw e;
            }
        }
 public override System.Data.DataSet ExecuteDataSet(String commandText, System.Data.CommandType commandType)
 {
     System.Data.IDataParameter[] empty = new System.Data.IDataParameter[] { };
     return ExecuteDataSet(commandText, commandType, ref empty, this.default_commandTimeOut);
 }
 public override Object ExecuteScalar(String commandText)
 {
     System.Data.IDataParameter[] empty = new System.Data.IDataParameter[] { };
     return ExecuteScalar(commandText, System.Data.CommandType.Text, ref empty, this.default_commandTimeOut);
 }
 public override Int32 ExecuteNonQuery(String commandText)
 {
     System.Data.IDataParameter[] empty = new System.Data.IDataParameter[] { };
     return ExecuteNonQuery(commandText, System.Data.CommandType.Text, ref empty, this.default_commandTimeOut);
 }
 public override System.Data.DataTable ExecuteDataTable(String commandText)
 {
     System.Data.IDataParameter[] empty = new System.Data.IDataParameter[] { };
     return ExecuteDataTable(commandText, System.Data.CommandType.Text, ref empty, this.default_commandTimeOut);
 }