pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Shavonne Marietta Wijesinghe <shavonne.marietta@studioform.it>
To: pgsql-sql@postgresql.org
Subject: Check before INSERT INTO
Date: Mon, 11 Feb 2008 13:04:18 +0100
Message-ID: <010901c86ca6$3b66e870$3102a8c0@dream> (raw)

My table structure

CREATE TABLE my_shevi
(
  id text,
  n_gen serial NOT NULL,
  n_sheet serial NOT NULL,
  tot_sheet serial NOT NULL,
  CONSTRAINT my_shevi_pkey PRIMARY KEY (n_gen, n_sheet, tot_sheet)
) 
WITH OIDS;
ALTER TABLE my_shevi OWNER TO postgres;

The user updates the DB via ASP. When 2 users click on the submit button at the same time, only 1 record is inserted. (ERROR:  duplicate key violates unique constraint "my_shevi_pkey")

For example they both send a string like below.
strSQL = INSERT INTO my_shevi VALUES ('a', 4, 1, 1);

I thought of adding a test before executing the insert into. 

Set SQLN_GEN = oConn.Execute("SELECT upper(N_GEN), upper(N_SHEET), upper(TOT_N_SHEET) FROM " & TableName & " WHERE N_GEN='" & n_gen & "' AND N_SHEET='" & n_sheet & "' AND TOT_N_SHEET='" & tot_n_sheet & "'")

if (not SQLN_GEN.eof) then
     ***** set n_gen + 1  
else
     ***** leave n_gen the way it is
end if

conn.Execute strSQL

But how can i ask it to change the n_gen value??? (The part with the *****) 

Thanks

Shavonne Wijesinghe

view thread (10+ messages)  latest in thread

Message-ID: <010901c86ca6$3b66e870$3102a8c0@dream>
Permalink:  ../010901c86ca6$3b66e870$3102a8c0@dream/
Also on:    postgresql.org/message-id/010901c86ca6$3b66e870$3102a8c0@dream

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: shavonne.marietta@studioform.it
  Subject: Re: Check before INSERT INTO
  In-Reply-To: <010901c86ca6$3b66e870$3102a8c0@dream>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox