Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit020be62

Browse files
committed
Well, here's the first pass on regression
tests for the Foreign Key support in 7.0 whichwas made against a CVS copy from thisafternoon.This modifies src/test/regress/sql/run_check.tests src/test/regress/sql/alter_table.sql src/test/regress/expected/alter_table.out src/test/regress/sql/foreign_key.sql src/test/regress/expected/foreign_key.outsszabo@bigpanda.co
1 parent991b974 commit020be62

File tree

5 files changed

+152
-1
lines changed

5 files changed

+152
-1
lines changed

‎doc/src/sgml/release.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Add Win1250 (Czech) support (Pavel Behal)
179179
<surname>Momjian</surname>
180180
</author>
181181
</authorgroup>
182-
<date>1998-06-09</date>
182+
<date>1999-06-09</date>
183183
</docinfo>
184184
-->
185185

‎src/test/regress/expected/alter_table.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,27 @@ SELECT unique1 FROM tenk1 WHERE unique1 < 5;
269269
4
270270
(5 rows)
271271

272+
-- FOREIGN KEY CONSTRAINT adding TEST
273+
CREATE TABLE tmp2 (a int primary key);
274+
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'tmp2_pkey' for table 'tmp2'
275+
CREATE TABLE tmp3 (a int, b int);
276+
-- Insert rows into tmp2 (pktable)
277+
INSERT INTO tmp2 values (1);
278+
INSERT INTO tmp2 values (2);
279+
INSERT INTO tmp2 values (3);
280+
INSERT INTO tmp2 values (4);
281+
-- Insert rows into tmp3
282+
INSERT INTO tmp3 values (1,10);
283+
INSERT INTO tmp3 values (1,20);
284+
INSERT INTO tmp3 values (5,50);
285+
-- Try (and fail) to add constraint due to invalid data
286+
ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
287+
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
288+
ERROR: <unnamed> referential integrity violation - key referenced from tmp3 not found in tmp2
289+
-- Delete failing row
290+
DELETE FROM tmp3 where a=5;
291+
-- Try (and succeed)
292+
ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
293+
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
294+
DROP TABLE tmp3
295+
DROP TABLE tmp2

‎src/test/regress/sql/alter_table.sql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,33 @@ ALTER TABLE ten_k RENAME TO tenk1;
163163
-- 5 values, sorted
164164
SELECT unique1FROM tenk1WHERE unique1<5;
165165

166+
-- FOREIGN KEY CONSTRAINT adding TEST
167+
168+
CREATETABLEtmp2 (aintprimary key);
169+
170+
CREATETABLEtmp3 (aint, bint);
171+
172+
-- Insert rows into tmp2 (pktable)
173+
INSERT INTO tmp2values (1);
174+
INSERT INTO tmp2values (2);
175+
INSERT INTO tmp2values (3);
176+
INSERT INTO tmp2values (4);
177+
178+
-- Insert rows into tmp3
179+
INSERT INTO tmp3values (1,10);
180+
INSERT INTO tmp3values (1,20);
181+
INSERT INTO tmp3values (5,50);
182+
183+
-- Try (and fail) to add constraint due to invalid data
184+
ALTERTABLE tmp3 addconstraint tmpconstrforeign key (a)references tmp2 match full;
185+
186+
-- Delete failing row
187+
DELETEFROM tmp3where a=5;
188+
189+
-- Try (and succeed)
190+
ALTERTABLE tmp3 addconstraint tmpconstrforeign key (a)references tmp2 match full;
191+
192+
DROPTABLE tmp3
193+
194+
DROPTABLE tmp2
195+

‎src/test/regress/sql/run_check.tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ parallelgroup5
119119
testalter_table
120120
testportals_p2
121121
testrules
122+
testforeign_key
122123
endparallel
123124

124125
# ----------

‎src/tools/pgcvslog

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
:
2+
# This utility is used to generate a compact list of changes for each
3+
# release, bjm 2000-02-22
4+
5+
# Usage $0 [-r 'revision pattern'] file
6+
7+
# cvs log -d '>1999-06-14 00:00:00 GMT' > log
8+
# pgcvslog -r '\.2\.[0-9]*$' log
9+
10+
if [ "X$1" = "X-r" ]
11+
thenREV="$2"
12+
shift 2
13+
elseREV=".*"
14+
fi
15+
16+
cat "$@" |
17+
18+
# mark each line with a datetime and line number, for sorting and merging
19+
# we don't print anything from the -- or == line and the date:
20+
21+
awk '
22+
$0 ~ /^Working file:/{workingfile = $0}
23+
24+
$1 == "revision" && $2 !~ /'"$REV"'/ {skip = "Y"}
25+
26+
($0 ~ /^====*$/ || $0 ~ /^----*$/) && skip == "N" \
27+
{
28+
/* print blank line separating entries */
29+
if (datetime != "")
30+
{
31+
printf ("%s| %10d|%s\n", datetime, NR, "");
32+
printf ("%s| %10d|%s\n", datetime, NR, "---");
33+
printf ("%s| %10d|%s\n", datetime, NR+1, "");
34+
}
35+
}
36+
37+
$0 ~ /^====*$/ || $0 ~ /^----*$/ \
38+
{
39+
datetime="";
40+
skip="N";
41+
}
42+
43+
datetime != "" && skip == "N" \
44+
{printf ("%s| %10d| %s\n", datetime, NR, $0);}
45+
46+
$1 == "date:"\
47+
{
48+
/* get entry date */
49+
datetime=$2"-"$3
50+
if (workingfile != "" && skip == "N")
51+
{
52+
printf ("%s| %10d|%s\n", datetime, NR-1, workingfile);
53+
printf ("%s| %10d|%s\n", datetime, NR, $0);
54+
printf ("%s| %10d|%s\n", datetime, NR+1, "");
55+
}
56+
}
57+
58+
$0 ~ /^====*$/ {workingfile=""}' |
59+
60+
sort | cut -d'|' -f3 | cat |
61+
62+
# collect duplicate narratives
63+
awk 'BEGIN{ slot = 0;}
64+
{
65+
if ($0 ~ /^Working file:/)
66+
{
67+
if (slot != oldslot)
68+
same = 0;
69+
else
70+
{
71+
same = 1;
72+
for (i=1; i <= slot; i++)
73+
{
74+
if (oldnarr[i] != narr[i])
75+
same = 0;
76+
}
77+
}
78+
79+
if (oldslot && !same)
80+
for (i=1; i <= oldslot; i++)
81+
print oldnarr[i];
82+
for (i=1; i <= slot; i++)
83+
oldnarr[i] = narr[i];
84+
oldslot = slot;
85+
slot = 0;
86+
print save_working;
87+
save_working = $0;
88+
}
89+
else if ($1 != "date:")
90+
narr[++slot] = $0;
91+
}
92+
END{
93+
print save_working;
94+
for (i=1; i <= slot; i++)
95+
print narr[i];
96+
}'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp