Answer the question
In order to leave comments, you need to log in
for some reas" />
Hack preventing re-insertion of data in PostgreSQL?
There is a very crooked project. In it, a request is sent from a web form to insert data into the PostgreSQL database.
After execution: ` command.ExecuteNonQuery(); ` for some reason, there are two instances of data in the database, although the function is called once.
public void Start()
{
NpgsqlConnection conn = new NpgsqlConnection("Server=localhost;Port=5432;User Id=postgres;Password=123;Database=test;");
conn.Open();
NpgsqlCommand command = new NpgsqlCommand("insert into zayav.\"REQUESTS\" (time_beg, time_end, sol_angle_min, sol_angle_max, priority, fl_ready, prod_type_id, customer_id) values(" + "'" + Beg_Planir_s + "','" + End_planir_s + "','" + Sol_angl_min_s + "','" + Sol_angl_max_s + "','" + Priority_s + "','" + Fl_ready_s + "','" + Prod_type_id_s + "','" + Customer_id_s + "')", conn);
command.ExecuteNonQuery();
conn.Close();
}
Answer the question
In order to leave comments, you need to log in
What exactly does "help" mean? There is most likely no unequivocal hack that will solve everything by itself. The dirtiest hack you can think of offhand is to add a constraint to the database for the uniqueness of the combination of all inserted fields, like:
CREATE TABLE example (
a integer,
b integer,
c integer,
UNIQUE (a, c)
);
I would advise not to look for dirty hacks, but to find the cause and eliminate it. First, insert the logging into the method.
PS What a terrible code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question