Changeset: 576f8bb3782a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/576f8bb3782a
Modified Files:
sql/server/rel_schema.c
sql/test/miscellaneous/Tests/simple_selects.test
Branch: Jan2022
Log Message:
Disable foreign keys between temp and non temp tables. Fixes crash
diffs (52 lines):
diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c
--- a/sql/server/rel_schema.c
+++ b/sql/server/rel_schema.c
@@ -433,6 +433,14 @@ column_constraint_type(mvc *sql, const c
}
if (!rt)
return SQL_ERR;
+ if (!rt->s) { /* disable foreign key on declared table */
+ (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
FOREIGN KEY: cannot create foreign key with declared tables");
+ return res;
+ }
+ if (isTempSchema(t->s) != isTempSchema(rt->s)) { /* disable
foreign key between temp and non temp */
+ (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
FOREIGN KEY: cannot create foreign key between temporary and non temporary
tables");
+ return res;
+ }
if (!ns || !*ns) { /* add this to be safe */
(void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
FOREIGN KEY: key name name cannot be empty");
return res;
@@ -679,6 +687,14 @@ table_foreign_key(mvc *sql, const char *
int ref_actions = n->next->next->next->next->data.i_val;
assert(n->next->next->next->next->type == type_int);
+ if (!ft->s) { /* disable foreign key on declared table */
+ (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
FOREIGN KEY: cannot create foreign key with declared tables");
+ return SQL_ERR;
+ }
+ if (isTempSchema(t->s) != isTempSchema(ft->s)) { /* disable
foreign key between temp and non temp */
+ (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
FOREIGN KEY: cannot create foreign key between temporary and non temporary
tables");
+ return SQL_ERR;
+ }
if (!ns || !*ns) { /* add this to be safe */
(void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
FOREIGN KEY: key name name cannot be empty");
return SQL_ERR;
diff --git a/sql/test/miscellaneous/Tests/simple_selects.test
b/sql/test/miscellaneous/Tests/simple_selects.test
--- a/sql/test/miscellaneous/Tests/simple_selects.test
+++ b/sql/test/miscellaneous/Tests/simple_selects.test
@@ -939,3 +939,15 @@ CREATE INDEX ups ON tmp.x (x)
statement ok
drop table x
+
+statement ok
+START TRANSACTION
+
+statement ok
+create temp table foo (i int primary key) on commit preserve rows
+
+statement error 42000!CONSTRAINT FOREIGN KEY: cannot create foreign key
between temporary and non temporary tables
+create table bar (i int, FOREIGN KEY (i) REFERENCES foo(i))
+
+statement ok
+ROLLBACK
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]