· 7 years ago · Sep 06, 2018, 09:16 AM
1SQL - Concurrent insert of keys into a table
2except
3 on E: EIBInterBaseError do
4 begin
5 if (E.SQLCode = -803) and (E.IBErrorCode = 335544349) then
6 begin
7 FKeysConnection.IBT.Rollback;
8 EnteredKeys := False;
9 end;
10 end;
11end;
12
13except
14 on E: EIBInterBaseError do
15 begin
16 if (E.SQLCode = -803) and (E.IBErrorCode = 335544349) then
17 begin
18 FKeysConnection.IBT.Rollback;
19 EnteredKeys := False;
20 end;
21 end;
22end;
23
24UPDATE OR INSERT INTO MY_TABLE (MY_KEY) VALUES (:MY_KEY) MATCHING (MY_KEY) RETURNING MY_ID
25
26insert into Table1 (KeyValue)
27select 'NewKey'
28where not exists (select *
29 from Table1
30 where KeyValue = 'NewKey')
31
32CREATE TABLE KEY_RESERVATIONS (
33 KEY INTEGER NOT NULL, /* This is the KEY you'd be reserving */
34 RESERVED_UNTIL TIMESTAMP NOT NULL /* We don't want to keep reservations for ever in case of failure */
35);