Changeset: 8252d2b40904 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8252d2b40904
Added Files:
        sql/test/scoping/Tests/All
        sql/test/scoping/Tests/scoping01.sql
Removed Files:
        sql/test/miscellaneous/Tests/scoping.sql
Modified Files:
        sql/test/miscellaneous/Tests/All
Branch: scoping
Log Message:

Moved soping test to its own directory with an update


diffs (179 lines):

diff --git a/sql/test/miscellaneous/Tests/All b/sql/test/miscellaneous/Tests/All
--- a/sql/test/miscellaneous/Tests/All
+++ b/sql/test/miscellaneous/Tests/All
@@ -13,4 +13,3 @@ select_groupby
 groupings
 HAVE_PYMONETDB?pk_fk_stress
 deallocate
-scoping
diff --git a/sql/test/miscellaneous/Tests/scoping.sql 
b/sql/test/miscellaneous/Tests/scoping.sql
deleted file mode 100644
--- a/sql/test/miscellaneous/Tests/scoping.sql
+++ /dev/null
@@ -1,75 +0,0 @@
---TODO update rel_dump for schemas on variables
-
-declare i integer;
-set i = 1234;
-
-create table tmp1(i integer, s string);
-insert into tmp1 values(1,'hello'),(2,'world');
-select i from tmp1;
-
-select sys.i, i from tmp1; --we declare variables in a schema, so to reference 
them we add the schema
-       -- 1234 1
-       -- 1234 2
-
-declare table tmp2(i integer, s string); --the same for declared tables
-insert into tmp2 values(3,'another'),(4,'test');
-
-select tmp1.i, tmp2.i from sys.tmp1, sys.tmp2;
-       -- 1 3
-       -- 1 4
-       -- 2 3
-       -- 2 4
-
-SELECT MAX(i) FROM tmp1; --Table columns have precedence over global variables
-       -- 2
-
--- Create a function to test scoping order
-CREATE OR REPLACE FUNCTION tests_scopes(i INT) RETURNS INT 
-BEGIN
-       DECLARE i int;
-       SET i = 1;
-       IF i = 0 THEN
-               RETURN i;
-       ELSE
-               RETURN sys.i;
-       END IF;
-END;
-
-SELECT tests_scopes(vals) FROM (VALUES (0),(2),(3)) AS vals(vals);
-       -- 0 --Function parameters have precedence over declared variables, 
either local or global
-       -- 1 --Local variables have precedence over global ones
-       -- 1
-
-DROP TABLE tmp1;
-DROP TABLE tmp2;
-DROP FUNCTION tests_scopes(INT);
-------------------------------------------------------------------------------
-with a(a) as (select 1), a(a) as (select 2) select 1; --error, variable a 
already declared
-------------------------------------------------------------------------------
-CREATE OR REPLACE FUNCTION scoping(input INT) RETURNS INT 
-BEGIN
-       DECLARE x int;
-       SET x = 1;
-       IF input = 2 THEN
-               DECLARE x int;
-               SET x = 2;
-       ELSE
-               IF input = 3 THEN
-                       SET x = 3;
-               END IF;
-       END IF;
-       RETURN x;
-END;
-
-SELECT scoping(vals) FROM (VALUES (1),(2),(3)) AS vals(vals);
-       -- 1
-       -- 1 MonetDB outputs this one as 2, but the inner x shouldn't override 
the value of outer x variable
-       -- 3
-
-DROP FUNCTION scoping(INT);
-------------------------------------------------------------------------------
--- A table returning function or view to list the session's variables
-select "name", schemaname, "type", currentvalue, accessmode from sys.vars();
-------------------------------------------------------------------------------
--- Some syntax to allow users to view GDK variables (we will discuss this 
later)...
---GRANT WRITE ACCESS to gdk_debug TO PUBLIC;
diff --git a/sql/test/scoping/Tests/All b/sql/test/scoping/Tests/All
new file mode 100644
--- /dev/null
+++ b/sql/test/scoping/Tests/All
@@ -0,0 +1,1 @@
+scoping01
diff --git a/sql/test/scoping/Tests/scoping01.sql 
b/sql/test/scoping/Tests/scoping01.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/scoping/Tests/scoping01.sql
@@ -0,0 +1,80 @@
+--TODO update rel_dump for schemas on variables
+
+declare i integer;
+set i = 1234;
+
+create table tmp1(i integer, s string);
+insert into tmp1 values(1,'hello'),(2,'world');
+select i from tmp1;
+
+select sys.i, i from tmp1; --we declare variables in a schema, so to reference 
them we add the schema
+       -- 1234 1
+       -- 1234 2
+
+declare table tmp2(i integer, s string); --the same for declared tables
+insert into tmp2 values(3,'another'),(4,'test');
+
+select tmp1.i, tmp2.i from sys.tmp1, sys.tmp2;
+       -- 1 3
+       -- 1 4
+       -- 2 3
+       -- 2 4
+
+SELECT MAX(i) FROM tmp1; --Table columns have precedence over global variables
+       -- 2
+
+CREATE OR REPLACE FUNCTION tests_scopes1(i INT) RETURNS INT 
+BEGIN
+       DECLARE i int; --error, variable redeclaration;
+       RETURN i;
+END;
+
+SELECT tests_scopes1(vals) FROM (VALUES (1),(2),(3)) AS vals(vals); --will 
trigger error
+
+-- Create a function to test scoping order
+CREATE OR REPLACE FUNCTION tests_scopes2(i INT) RETURNS INT 
+BEGIN
+       DECLARE j int;
+       SET j = i;
+       RETURN j;
+END;
+
+SELECT tests_scopes2(vals) FROM (VALUES (1),(2),(3)) AS vals(vals);
+       -- 1 --Local variables have precedence over global ones
+       -- 2 
+       -- 3
+
+DROP TABLE tmp1;
+DROP TABLE tmp2;
+DROP FUNCTION tests_scopes1(INT);
+DROP FUNCTION tests_scopes2(INT);
+------------------------------------------------------------------------------
+with a(a) as (select 1), a(a) as (select 2) select 1; --error, variable a 
already declared
+------------------------------------------------------------------------------
+CREATE OR REPLACE FUNCTION scoping(input INT) RETURNS INT 
+BEGIN
+       DECLARE x int;
+       SET x = 1;
+       IF input = 2 THEN
+               DECLARE x int;
+               SET x = 2;
+       ELSE
+               IF input = 3 THEN
+                       SET x = 3;
+               END IF;
+       END IF;
+       RETURN x;
+END;
+
+SELECT scoping(vals) FROM (VALUES (1),(2),(3)) AS vals(vals);
+       -- 1
+       -- 1 MonetDB outputs this one as 2, but the inner x shouldn't override 
the value of outer x variable
+       -- 3
+
+DROP FUNCTION scoping(INT);
+------------------------------------------------------------------------------
+-- A table returning function or view to list the session's variables
+select "name", schemaname, "type", currentvalue, accessmode from sys.vars();
+------------------------------------------------------------------------------
+-- Some syntax to allow users to view GDK variables (we will discuss this 
later)...
+--GRANT WRITE ACCESS to gdk_debug TO PUBLIC;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to