Exemple #1
0
 /// <summary>
 /// Creates and runs a command to execute a command text
 /// </summary>
 /// <param name="connection">Database connection</param>
 /// <param name="commandText">Command text</param>
 /// <param name="isStoredProcedure">Indicates if the command text is a stored procedure name</param>
 /// <param name="parameters">Bind parameters</param>
 /// <returns>Number of affected rows</returns>
 internal static int ExecuteNonQuery(DBOracleConnection connection, string commandText, bool isStoredProcedure, params DBOracleParameter[] parameters)
 {
     try
     {
         using (var command = new DBOracleCommand(connection: connection, commandText: commandText, isStoredProcedure: isStoredProcedure, parameters: parameters))
         {
             return(command.Command.ExecuteNonQuery());
         }
     }
     catch (Exception ex)
     {
         ex.ConvertOracleException(isConnecting: false);
         throw;
     }
 }
 /// <summary>
 /// Create a new prepared statement (used by DBOracleBaseDAL)
 /// </summary>
 /// <param name="connection">Database connection</param>
 /// <param name="commandText">Command text</param>
 /// <param name="isStoredProcedure">Indicates if the command text is a stored procedure name</param>
 /// <param name="parameters">Bind parameters</param>
 internal DBOraclePreparedStatement(DBOracleConnection connection, string commandText, bool isStoredProcedure, params DBOracleParameter[] parameters)
 {
     try
     {
         Command = DBOracleCommand.CreatePreparedStatement(
             connection: connection,
             commandText: commandText,
             isStoredProcedure: isStoredProcedure,
             parameters: parameters);
     }
     catch (Exception ex)
     {
         ex.ConvertOracleException(isConnecting: false);
         throw;
     }
 }
Exemple #3
0
        /// <summary>
        /// Creates a new prepared statement (used by DBOraclePreparedStatement)
        /// </summary>
        /// <param name="connection">Database connection</param>
        /// <param name="commandText">Command text</param>
        /// <param name="isStoredProcedure">Indicates if the command text is a stored procedure name</param>
        /// <param name="parameters">Bind parameters</param>
        internal static DBOracleCommand CreatePreparedStatement(DBOracleConnection connection, string commandText, bool isStoredProcedure, params DBOracleParameter[] parameters)
        {
            DBOracleCommand command = null;

            try
            {
                command = new DBOracleCommand(connection: connection, commandText: commandText, isStoredProcedure: isStoredProcedure, parameters: parameters);

                command.Command.Prepare();

                return(command);
            }
            catch (Exception ex)
            {
                command?.Close();
                ex.ConvertOracleException(isConnecting: false);
                throw;
            }
        }
Exemple #4
0
        /// <summary>
        /// Creates and runs a command to retrieve a DataTable using a command text
        /// </summary>
        /// <param name="connection">Database connection</param>
        /// <param name="commandText">Command text</param>
        /// <param name="isStoredProcedure">Indicates if the command text is a stored procedure name</param>
        /// <param name="parameters">Bind parameters</param>
        /// <returns>DataTable with the command text results</returns>
        internal static DataTable GetDataTable(DBOracleConnection connection, string commandText, bool isStoredProcedure, params DBOracleParameter[] parameters)
        {
            try
            {
                using (var command = new DBOracleCommand(connection: connection, commandText: commandText, isStoredProcedure: isStoredProcedure, parameters: parameters))
                {
                    OracleDataAdapter dataAdapter;

                    try
                    {
                        dataAdapter = new OracleDataAdapter(command.Command);
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            Log.Debug(DBOracleLocalizedText.DBOracleCommand_GetDataSet_DataAdapterError, ex);
                        }
                        catch (Exception)
                        {
                            // Nothing to do
                        }

                        throw;
                    }

                    bool suppressDisposeException = false;

                    try
                    {
                        var dataTable = new DataTable();

                        dataAdapter.Fill(dataTable);

                        return(dataTable);
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            Log.Debug(DBOracleLocalizedText.DBOracleCommand_GetDataSet_DataRetrieveError, ex);
                        }
                        catch (Exception)
                        {
                            // Nothing to do
                        }

                        suppressDisposeException = true;
                        throw;
                    }
                    finally
                    {
                        try
                        {
                            dataAdapter.Dispose();
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                Log.Error(DBOracleLocalizedText.DBOracleCommand_DataAdapter_Disposal_Error, ex);
                            }
                            catch (Exception)
                            {
                                // Nothing to do
                            }

                            if (!suppressDisposeException)
                            {
                                throw;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ConvertOracleException(isConnecting: false);
                throw;
            }
        }
Exemple #5
0
        /// <summary>
        /// Creates and runs a command to execute a query command text that returns a single row
        /// </summary>
        /// <typeparam name="T">Return type</typeparam>
        /// <param name="connection">Database connection</param>
        /// <param name="dataFiller">Function to convert the returned row into the return type object</param>
        /// <param name="commandText">Command text</param>
        /// <param name="isStoredProcedure">Indicates if the command text is a stored procedure name</param>
        /// <param name="nullValue">Value to be returned if the query command text does not return any row</param>
        /// <param name="parameters">Bind parameters</param>
        /// <returns>Command text result, or nullValue if none</returns>
        internal static T RetrieveDataItem <T>(DBOracleConnection connection, Func <DBOracleDataReader, T> dataFiller, string commandText, bool isStoredProcedure, T nullValue = default(T), params DBOracleParameter[] parameters)
        {
            try
            {
                using (var command = new DBOracleCommand(connection: connection, commandText: commandText, isStoredProcedure: isStoredProcedure, parameters: parameters))
                {
                    var oracleDataReader = command.Command.ExecuteReader(behavior: CommandBehavior.SingleRow);

                    DBOracleDataReader dataReader = null;

                    try
                    {
                        dataReader = new DBOracleDataReader(oracleDataReader);

                        return((oracleDataReader.Read())
                            ? dataFiller(dataReader)
                            : nullValue);
                    }
                    finally
                    {
                        dataReader?.Cleanup();

                        try
                        {
                            oracleDataReader?.Close();
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                Log.Error(DBOracleLocalizedText.DBOracleCommand_CloseDataReader, ex);
                            }
                            catch (Exception)
                            {
                                // Nothing to do
                            }
                        }

                        try
                        {
                            oracleDataReader?.Dispose();
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                Log.Error(DBOracleLocalizedText.DBOracleCommand_DisposeDataReader, ex);
                            }
                            catch (Exception)
                            {
                                // Nothing to do
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ConvertOracleException(isConnecting: false);
                throw;
            }
        }
Exemple #6
0
        /// <summary>
        /// Creates and runs a command to execute a command text that returns multiple rows
        /// </summary>
        /// <typeparam name="T">Return type</typeparam>
        /// <param name="connection">Database connection</param>
        /// <param name="dataFiller">Function to convert the returned rows into the return type object</param>
        /// <param name="commandText">Command text</param>
        /// <param name="isStoredProcedure">Indicates if the command text is a stored procedure name</param>
        /// <param name="parameters">Bind parameters</param>
        /// <returns>List of objects of the return type</returns>
        internal static List <T> RetrieveDataList <T>(DBOracleConnection connection, Func <DBOracleDataReader, T> dataFiller, string commandText, bool isStoredProcedure, params DBOracleParameter[] parameters)
        {
            try
            {
                using (var command = new DBOracleCommand(connection: connection, commandText: commandText, isStoredProcedure: isStoredProcedure, parameters: parameters))
                {
                    var oracleDataReader = command.Command.ExecuteReader();

                    DBOracleDataReader dataReader = null;
                    List <T>           rowList    = null;

                    try
                    {
                        dataReader = new DBOracleDataReader(oracleDataReader);

                        rowList = new List <T>();

                        while (oracleDataReader.Read())
                        {
                            rowList.Add(dataFiller(dataReader));
                        }

                        return(rowList);
                    }
                    catch (Exception)
                    {
                        rowList?.Clear(); // This method fills the internal array with zeros to help the gc
                        throw;
                    }
                    finally
                    {
                        dataReader?.Cleanup();

                        try
                        {
                            oracleDataReader?.Close();
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                Log.Error(DBOracleLocalizedText.DBOracleCommand_CloseDataReader, ex);
                            }
                            catch (Exception)
                            {
                                // Nothing to do
                            }
                        }

                        try
                        {
                            oracleDataReader?.Dispose();
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                Log.Error(DBOracleLocalizedText.DBOracleCommand_DisposeDataReader, ex);
                            }
                            catch (Exception)
                            {
                                // Nothing to do
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ConvertOracleException(isConnecting: false);
                throw;
            }
        }
Exemple #7
0
 /// <summary>
 /// Creates and runs a command to retrieve a DataTable using a stored procedure
 /// </summary>
 /// <param name="commandText">Stored procedure name</param>
 /// <param name="parameters">Bind parameters</param>
 /// <returns>DataTable with the query results</returns>
 protected DataTable RetrieveDataTableSP(string commandText, params DBOracleParameter[] parameters)
 {
     return(DBOracleCommand.GetDataTable(connection: this, commandText: commandText, isStoredProcedure: true, parameters: parameters));
 }
Exemple #8
0
 /// <summary>
 /// Creates and runs a command to execute a stored procedure
 /// </summary>
 /// <param name="commandText">Stored procedure name</param>
 /// <param name="parameters">Bind parameters</param>
 /// <returns>Number of affected rows</returns>
 protected int ExecuteSP(string commandText, params DBOracleParameter[] parameters)
 {
     return(DBOracleCommand.ExecuteNonQuery(connection: this, commandText: commandText, isStoredProcedure: true, parameters: parameters));
 }
Exemple #9
0
 /// <summary>
 /// Creates and runs a command to execute a stored procedure that returns a single row
 /// </summary>
 /// <typeparam name="T">Return type</typeparam>
 /// <param name="dataFiller">Function to convert the returned row into the return type object</param>
 /// <param name="commandText">Stored procedure name</param>
 /// <param name="nullValue">Value to be returned if the stored procedure does not return any row</param>
 /// <param name="parameters">Bind parameters</param>
 /// <returns>Stored procedure result, or nullValue if none</returns>
 protected T RetrieveDataItemSP <T>(Func <DBOracleDataReader, T> dataFiller, string commandText, T nullValue = default(T), params DBOracleParameter[] parameters)
 {
     return(DBOracleCommand.RetrieveDataItem(connection: this, dataFiller: dataFiller, commandText: commandText, isStoredProcedure: true, nullValue: nullValue, parameters: parameters));
 }
Exemple #10
0
 /// <summary>
 /// Creates and runs a command to execute a stored procedure that returns multiple rows
 /// </summary>
 /// <typeparam name="T">Return type</typeparam>
 /// <param name="dataFiller">Function to convert the returned rows into the return type object</param>
 /// <param name="commandText">Stored procedure name</param>
 /// <param name="parameters">Bind parameters</param>
 /// <returns>List of objects of the return type</returns>
 protected List <T> RetrieveDataListSP <T>(Func <DBOracleDataReader, T> dataFiller, string commandText, params DBOracleParameter[] parameters)
 {
     return(DBOracleCommand.RetrieveDataList(connection: this, dataFiller: dataFiller, commandText: commandText, isStoredProcedure: true, parameters: parameters));
 }