private void UseConnections(Action <NpgsqlConnection, PostgreSqlConnection> action) { using (var sqlConnection = ConnectionUtils.CreateConnection()) using (var connection = new PostgreSqlConnection(sqlConnection, _providers, _options)) { action(sqlConnection, connection); } }
private void UseConnection(Action <PostgreSqlConnection> action) { using (var connection = new PostgreSqlConnection( ConnectionUtils.CreateConnection(), _providers)) { action(connection); } }
public void Dispose_DoesNotDisposeTheConnection_IfNotOwned() { using (var sqlConnection = ConnectionUtils.CreateConnection()) { var connection = new PostgreSqlConnection(sqlConnection, _providers, ownsConnection: false, options: _options); connection.Dispose(); Assert.Equal(ConnectionState.Open, sqlConnection.State); } }
public void Dispose_DisposesTheConnection_IfOwned() { using (var sqlConnection = ConnectionUtils.CreateConnection()) { var connection = new PostgreSqlConnection(sqlConnection, _providers, _options); connection.Dispose(); Assert.Equal(ConnectionState.Closed, sqlConnection.State); } }
public void Dispose_DoesNotDisposeTheConnection_IfNotOwned() { using (var sqlConnection = ConnectionUtils.CreateConnection()) { var connection = new PostgreSqlConnection(sqlConnection, _providers, ownsConnection: false, options: _options); connection.Dispose(); Assert.Equal(ConnectionState.Open, sqlConnection.State); } }
public void Dispose_DisposesTheConnection_IfOwned() { using (var sqlConnection = ConnectionUtils.CreateConnection()) { var connection = new PostgreSqlConnection(sqlConnection, _providers, _options); connection.Dispose(); Assert.Equal(ConnectionState.Closed, sqlConnection.State); } }
/// <summary> /// this function will log a given action /// </summary> /// <param name="Action">the given action</param> /// <param name="connection">the open connection received from the caller</param> public static void LogAction(String Action, PostgreSqlConnection connection) { String QueryCommand = "INSERT INTO log.log_actiuni(actiune) VALUES(:p_action)"; NpgsqlParameter QueryParameter = new NpgsqlParameter("p_action", Action); if (!(connection.connection.State == System.Data.ConnectionState.Open) && !connection.OpenConnection()) { return; } connection.ExecuteNonQuery(QueryCommand, QueryParameter); }
/// <summary> /// this fucntion will log a given action to a specific user /// </summary> /// <param name="Action">the given action</param> /// <param name="User">the specific user</param> /// <param name="connection">the open connection received from the caller</param> public static void LogAction(String Action, User User, PostgreSqlConnection connection) { String QueryCommand = "INSERT INTO log.log_actiuni(actiune,utilizator_id) VALUES(:p_action,:p_user_id)"; NpgsqlParameter[] QueryParameters = { new NpgsqlParameter("p_action", Action), new NpgsqlParameter("p_user_id", User.ID) }; if (!(connection.connection.State == System.Data.ConnectionState.Open) && !connection.OpenConnection()) { return; } connection.ExecuteNonQuery(QueryCommand, QueryParameters); }
/// <summary> /// this function will log a given action to a specific IP Adress with the database command /// </summary> /// <param name="Action">the given action</param> /// <param name="IP">the ip adress</param> /// <param name="Command">the database command</param> /// <param name="connection">the open connection received from the caller</param> public static void LogAction(String Action, String IP, String Command, PostgreSqlConnection connection) { String QueryCommand = "INSERT INTO log.log_actiuni(actiune,ip_actiune,comanda) VALUES(:p_action,:p_ip,:p_command)"; NpgsqlParameter[] QueryParameters = { new NpgsqlParameter("p_action", Action), new NpgsqlParameter("p_ip", IP), new NpgsqlParameter("p_command", Command) }; if (!(connection.connection.State == System.Data.ConnectionState.Open) && !connection.OpenConnection()) { return; } connection.ExecuteNonQuery(QueryCommand, QueryParameters); }
private void UseConnection(Action<PostgreSqlConnection> action) { using (var connection = new PostgreSqlConnection( ConnectionUtils.CreateConnection(), _providers, _options)) { action(connection); } }
private void UseConnections(Action<NpgsqlConnection, PostgreSqlConnection> action) { using (var sqlConnection = ConnectionUtils.CreateConnection()) using (var connection = new PostgreSqlConnection(sqlConnection, _providers, _options)) { action(sqlConnection, connection); } }
/// <summary> /// this function will add a new bank account to a given seller by piggy-backing on an already active connection /// </summary> /// <param name="seller">the given seller</param> /// <param name="bankAccount">the bank account controller</param> /// <param name="posgreSqlConnection">the active connection</param> public static void AddNewBankAccountForSeller(ObjectStructures.Invoice.Seller seller, BankAccount bankAccount, PostgreSqlConnection posgreSqlConnection) { #region ActionLog //we generate the log Action String LogAction = $"Adaugat un nou cont bancar la banca {bankAccount.Bank} pentru societatea {seller.Name}"; //we also generate the command String LogCommand = "INSERT INTO seller.conturi_bancare_furnizori(furnizor_id,cont,banca) " + $"VALUES({seller.ID}, {bankAccount.Account}, {bankAccount.Bank}) " + "ON CONFLICT(cont) " + $"DO UPDATE SET banca= {bankAccount.Bank} RETURNING id"; //and get the instance IP String IP = MentorBilling.Miscellaneous.IPFunctions.GetWANIp(); #endregion //we generate the query command string String QueryCommand = "INSERT INTO seller.conturi_bancare_furnizori(furnizor_id,cont,banca) " + "VALUES(:p_seller_id, :p_account, :p_bank) " + "ON CONFLICT(cont) " + "DO UPDATE SET banca= :p_bank, activ = true " + "RETURNING id"; //and then set the parameters for the query List <NpgsqlParameter> QueryParameters = new List <NpgsqlParameter>() { new NpgsqlParameter(":p_seller_id", seller.ID), new NpgsqlParameter(":p_account", bankAccount.Account), new NpgsqlParameter(":p_bank", bankAccount.Bank) }; //we execute the command returning the ID over an already active connection bankAccount.ID = (Int32)posgreSqlConnection.ExecuteScalar(QueryCommand, QueryParameters); //and log the command ActionLog.LogAction(LogAction, LogCommand, IP, PgSqlConnection); }
/// <summary> /// the main function dor closing a connection on error /// </summary> /// <returns>false</returns> public static Boolean ErrorConnectionClose(PostgreSqlConnection DatabaseConnection) { DatabaseConnection.CloseConnection(); return(false); }
/// <summary> /// the main function for closing a connection on success /// </summary> /// <returns>true</returns> public static Boolean NormalConnectionClose(PostgreSqlConnection DatabaseConnection) { DatabaseConnection.CloseConnection(); return(true); }