public static string getById(int id) { NpgsqlConnection connection = DBConnectionService.getFreeConnection(); NpgsqlCommand command = new NpgsqlCommand(getByIdCommand, connection); command.Parameters.AddWithValue("@id", NpgsqlTypes.NpgsqlDbType.Integer, id); NpgsqlDataReader reader = command.ExecuteReader(); string result; if (reader.HasRows) { reader.Read(); result = reader.GetString(0); } else { result = null; } reader.Close(); DBConnectionService.returnConnection(connection); return(result); }
public static void updateUser(User user) { NpgsqlConnection connection = DBConnectionService.getFreeConnection(); NpgsqlCommand command = new NpgsqlCommand(updateUsersCommand, connection); // cmd.Parameters.Add(new NpgsqlParameter("pw", tb2.Text)); command.Parameters.AddWithValue("@id", NpgsqlTypes.NpgsqlDbType.Integer, user.id); command.Parameters.AddWithValue("@login", NpgsqlTypes.NpgsqlDbType.Text, user.login); command.Parameters.AddWithValue("@pass", NpgsqlTypes.NpgsqlDbType.Text, user.password); command.Parameters.AddWithValue("@nicename", NpgsqlTypes.NpgsqlDbType.Text, user.nicename); command.Parameters.AddWithValue("@email", NpgsqlTypes.NpgsqlDbType.Text, user.email); command.Parameters.AddWithValue("@url", NpgsqlTypes.NpgsqlDbType.Text, user.url); command.Parameters.AddWithValue("@registered", NpgsqlTypes.NpgsqlDbType.TimestampTZ, user.registered); command.Parameters.AddWithValue("@activation_key", NpgsqlTypes.NpgsqlDbType.Text, user.activationKey); command.Parameters.AddWithValue("@status", NpgsqlTypes.NpgsqlDbType.Integer, user.status); command.Parameters.AddWithValue("@display_name", NpgsqlTypes.NpgsqlDbType.Text, user.viewName); int result = command.ExecuteNonQuery(); if (result != 1) { throw new Exception("Error on user update"); } DBConnectionService.returnConnection(connection); }
public static string getPosts() { NpgsqlConnection connection = DBConnectionService.getFreeConnection(); NpgsqlCommand command = new NpgsqlCommand(getPostsCommand, connection); NpgsqlDataReader reader = command.ExecuteReader(); reader.Read(); string result = reader.GetString(5); reader.Close(); DBConnectionService.returnConnection(connection); return(result); }
public static void deleteUser(int id) { NpgsqlConnection connection = DBConnectionService.getFreeConnection(); NpgsqlCommand command = new NpgsqlCommand(deleteUserCommand, connection); // cmd.Parameters.Add(new NpgsqlParameter("pw", tb2.Text)); command.Parameters.AddWithValue("@id", NpgsqlTypes.NpgsqlDbType.Integer, id); int result = command.ExecuteNonQuery(); if (result != 1) { throw new Exception("Error on user update"); } DBConnectionService.returnConnection(connection); }
public static string getAllUsers() { NpgsqlConnection connection = DBConnectionService.getFreeConnection(); NpgsqlCommand command = new NpgsqlCommand(getAllUsersCommand, connection); NpgsqlDataReader reader = command.ExecuteReader(); string result; if (reader.HasRows) { reader.Read(); result = reader.GetString(0); } else { result = "[]"; } reader.Close(); DBConnectionService.returnConnection(connection); return(result); }