Changeset: c9e133975c85 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c9e133975c85
Modified Files:
        sql/server/rel_select.c
        sql/test/BugTracker/Tests/between_with_column.SF-1959410.stable.err
        sql/test/SQLancer/Tests/sqlancer07.sql
        sql/test/SQLancer/Tests/sqlancer07.stable.out
Branch: Oct2020
Log Message:

Making SQLancer happy. Look for prepared statement parameters at between 
expressions


diffs (167 lines):

diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -2067,6 +2067,35 @@ negate_symbol_tree(mvc *sql, symbol *sc)
        return sc;
 }
 
+static int
+exp_between_check_types(sql_subtype *res, sql_subtype *t1, sql_subtype *t2, 
sql_subtype *t3)
+{
+       bool type_found = false;
+       sql_subtype super;
+
+       if (t1 && t2) {
+               supertype(&super, t2, t1);
+               type_found = true;
+       } else if (t1) {
+               super = *t1;
+               type_found = true;
+       } else if (t2) {
+               super = *t2;
+               type_found = true;
+       }
+       if (t3) {
+               if (type_found)
+                       supertype(&super, t3, &super);
+               else
+                       super = *t3;
+               type_found = true;
+       }
+       if (!type_found)
+               return -1;
+       *res = super;
+       return 0;
+}
+
 sql_exp *
 rel_logical_value_exp(sql_query *query, sql_rel **rel, symbol *sc, int f, 
exp_kind ek)
 {
@@ -2256,17 +2285,14 @@ rel_logical_value_exp(sql_query *query, 
                if (!(re2 = rel_value_exp(query, rel, ro2, f, ek)))
                        return NULL;
 
-               supertype(&super, exp_subtype(re1), exp_subtype(le));
-               supertype(&super, exp_subtype(re2), &super);
+               if (exp_between_check_types(&super, exp_subtype(le), 
exp_subtype(re1), exp_subtype(re2)) < 0) 
+                       return sql_error(sql, 01, SQLSTATE(42000) "Cannot have 
a parameter (?) on both sides of an expression");
 
                if ((le = exp_check_type(sql, &super, rel ? *rel:NULL, le, 
type_equal)) == NULL ||
                    (re1 = exp_check_type(sql, &super, rel ? *rel:NULL, re1, 
type_equal)) == NULL ||
                    (re2 = exp_check_type(sql, &super, rel ? *rel:NULL, re2, 
type_equal)) == NULL)
                        return NULL;
 
-               if (!re1 || !re2)
-                       return NULL;
-
                le = exp_compare2(sql->sa, le, re1, re2, 3|CMP_BETWEEN);
                if (sc->token == SQL_NOT_BETWEEN)
                        set_anti(le);
@@ -2502,7 +2528,7 @@ rel_logical_exp(sql_query *query, sql_re
                symbol *ro1 = sc->data.lval->h->next->next->data.sym;
                symbol *ro2 = sc->data.lval->h->next->next->next->data.sym;
                sql_exp *le, *re1, *re2;
-               sql_subtype *t1, *t2, *t3;
+               sql_subtype super;
                int flag = (symmetric)?CMP_SYMMETRIC:0;
 
                assert(sc->data.lval->h->next->type == type_int);
@@ -2514,22 +2540,12 @@ rel_logical_exp(sql_query *query, sql_re
                if (!(re2 = rel_value_exp(query, &rel, ro2, f, ek)))
                        return NULL;
 
-               t1 = exp_subtype(le);
-               t2 = exp_subtype(re1);
-               t3 = exp_subtype(re2);
-
-               if (!t1 && (t2 || t3) && rel_binop_check_types(sql, rel, le, t2 
? re1 : re2, 0) < 0)
-                       return NULL;
-               if (!t2 && (t1 || t3) && rel_binop_check_types(sql, rel, le, t1 
? le : re2, 0) < 0)
-                       return NULL;
-               if (!t3 && (t1 || t2) && rel_binop_check_types(sql, rel, le, t1 
? le : re1, 0) < 0)
-                       return NULL;
-
-               if (rel_convert_types(sql, rel, rel, &le, &re1, 1, type_equal) 
< 0 ||
-                   rel_convert_types(sql, rel, rel, &le, &re2, 1, type_equal) 
< 0)
-                       return NULL;
-
-               if (!re1 || !re2)
+               if (exp_between_check_types(&super, exp_subtype(le), 
exp_subtype(re1), exp_subtype(re2)) < 0) 
+                       return sql_error(sql, 01, SQLSTATE(42000) "Cannot have 
a parameter (?) on both sides of an expression");
+
+               if ((le = exp_check_type(sql, &super, rel, le, type_equal)) == 
NULL ||
+                   (re1 = exp_check_type(sql, &super, rel, re1, type_equal)) 
== NULL ||
+                   (re2 = exp_check_type(sql, &super, rel, re2, type_equal)) 
== NULL)
                        return NULL;
 
                return rel_compare_exp_(query, rel, le, re1, re2, 
3|CMP_BETWEEN|flag, sc->token == SQL_NOT_BETWEEN ? 1 : 0, 0, f);
diff --git 
a/sql/test/BugTracker/Tests/between_with_column.SF-1959410.stable.err 
b/sql/test/BugTracker/Tests/between_with_column.SF-1959410.stable.err
--- a/sql/test/BugTracker/Tests/between_with_column.SF-1959410.stable.err
+++ b/sql/test/BugTracker/Tests/between_with_column.SF-1959410.stable.err
@@ -14,7 +14,7 @@ stderr of test 'between_with_column.SF-1
 
 MAPI  = (monetdb) /var/tmp/mtest-27483/.s.monetdb.35395
 QUERY = select yea from t1959410d, t1959410e where age between 0.03 and id < 
30 ;
-ERROR = !types boolean(1,0) and double(53,0) are not equal
+ERROR = !types boolean(1,0) and double(53,2) are not equal
 CODE  = 42000
 
 # 10:53:08 >  
diff --git a/sql/test/SQLancer/Tests/sqlancer07.sql 
b/sql/test/SQLancer/Tests/sqlancer07.sql
--- a/sql/test/SQLancer/Tests/sqlancer07.sql
+++ b/sql/test/SQLancer/Tests/sqlancer07.sql
@@ -59,6 +59,14 @@ SELECT CAST(t1.c1 AS INT) FROM t1, t0 RI
 ROLLBACK;
 
 START TRANSACTION;
+CREATE TABLE "t0" ("c0" DATE,"c2" INTEGER);
+CREATE TABLE "t1" ("c1" TIMESTAMP,"c2" INTEGER);
+CREATE TABLE "t2" ("c0" DATE,"c1" TIMESTAMP,"c2" INTEGER);
+PREPARE (SELECT ?, t1.c2 FROM t1, t0 WHERE (SELECT DISTINCT (t1.c2) BETWEEN 
ASYMMETRIC (?) AND (t1.c2) FROM t1 CROSS JOIN 
+((SELECT DISTINCT 6.9089063E7, TRUE FROM t2 WHERE TRUE) EXCEPT (SELECT ALL 
0.4, FALSE FROM t2, t0, t1 INNER JOIN t0 ON FALSE)) AS sub0 WHERE FALSE)) 
INTERSECT DISTINCT (SELECT DISTINCT 0.2, ? FROM t0, t2 WHERE ?);
+ROLLBACK;
+
+START TRANSACTION;
 CREATE TABLE "t0" ("c0" CHAR(315));
 INSERT INTO "t0" VALUES ('(y/l'), (''), ('*J');
 CREATE TABLE "t1" ("c0" VARCHAR(512), "c1" DOUBLE PRECISION);
diff --git a/sql/test/SQLancer/Tests/sqlancer07.stable.out 
b/sql/test/SQLancer/Tests/sqlancer07.stable.out
--- a/sql/test/SQLancer/Tests/sqlancer07.stable.out
+++ b/sql/test/SQLancer/Tests/sqlancer07.stable.out
@@ -78,6 +78,36 @@ stdout of test 'sqlancer07` in directory
 % int # type
 % 1 # length
 #ROLLBACK;
+#START TRANSACTION;
+#CREATE TABLE "t0" ("c0" DATE,"c2" INTEGER);
+#CREATE TABLE "t1" ("c1" TIMESTAMP,"c2" INTEGER);
+#CREATE TABLE "t2" ("c0" DATE,"c1" TIMESTAMP,"c2" INTEGER);
+#PREPARE (SELECT ?, t1.c2 FROM t1, t0 WHERE (SELECT DISTINCT (t1.c2) BETWEEN 
ASYMMETRIC (?) AND (t1.c2) FROM t1 CROSS JOIN 
+#((SELECT DISTINCT 6.9089063E7, TRUE FROM t2 WHERE TRUE) EXCEPT (SELECT ALL 
0.4, FALSE FROM t2, t0, t1 INNER JOIN t0 ON FALSE)) AS sub0 WHERE FALSE)) 
INTERSECT DISTINCT (SELECT DISTINCT 0.2, ? FROM t0, t2 WHERE ?);
+#PREPARE (SELECT ?, t1.c2 FROM t1, t0 WHERE (SELECT DISTINCT (t1.c2) BETWEEN 
ASYMMETRIC (?) AND (t1.c2) FROM t1 CROSS JOIN 
+#((SELECT DISTINCT 6.9089063E7, TRUE FROM t2 WHERE TRUE) EXCEPT (SELECT ALL 
0.4, FALSE FROM t2, t0, t1 INNER JOIN t0 ON FALSE)) AS sub0 WHERE FALSE)) 
INTERSECT DISTINCT (SELECT DISTINCT 0.2, ? FROM t0, t2 WHERE ?);
+% .prepare,    .prepare,       .prepare,       .prepare,       .prepare,       
.prepare # table_name
+% type,        digits, scale,  schema, table,  column # name
+% varchar,     int,    int,    str,    str,    str # type
+% 7,   3,      1,      0,      3,      3 # length
+[ "decimal",   2,      1,      "",     "%26",  "%20"   ]
+[ "int",       32,     0,      "",     "%26",  "c2"    ]
+[ "decimal",   2,      1,      NULL,   NULL,   NULL    ]
+[ "int",       32,     0,      NULL,   NULL,   NULL    ]
+[ "int",       32,     0,      NULL,   NULL,   NULL    ]
+[ "boolean",   1,      0,      NULL,   NULL,   NULL    ]
+#ROLLBACK;
+#START TRANSACTION;
+#CREATE TABLE "t0" ("c0" CHAR(315));
+#INSERT INTO "t0" VALUES ('(y/l'), (''), ('*J');
+[ 3    ]
+#CREATE TABLE "t1" ("c0" VARCHAR(512), "c1" DOUBLE PRECISION);
+#INSERT INTO "t1" VALUES ('0.9295919173154146', NULL);
+[ 1    ]
+#CREATE TABLE "t2" ("c0" CHAR(315));
+#INSERT INTO "t2" VALUES ('1753268987.000'), ('(y/l'), ('(y/l'), ('');
+[ 4    ]
+#ROLLBACK;
 
 # 10:16:14 >  
 # 10:16:14 >  "Done."
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to