Changeset: 834adef227d0 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=834adef227d0
Added Files:
sql/test/BugTracker-2013/Tests/prepare-smallint.Bug-3297.sql
sql/test/BugTracker-2013/Tests/prepare-smallint.Bug-3297.stable.err
sql/test/BugTracker-2013/Tests/prepare-smallint.Bug-3297.stable.out
Modified Files:
sql/server/rel_select.c
sql/test/BugTracker-2010/Tests/prepare_statements_crash_server.Bug-2599.stable.out
sql/test/BugTracker-2013/Tests/All
Branch: Feb2013
Log Message:
fixed bug 3297. More general types are used in case of numerics.
diffs (262 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
@@ -1862,11 +1862,17 @@ exp_fix_scale(mvc *sql, sql_subtype *ct,
}
static int
-rel_set_type_param(mvc *sql, sql_subtype *type, sql_exp *param)
+rel_set_type_param(mvc *sql, sql_subtype *type, sql_exp *param, int upcast)
{
if (!type || !param || param->type != e_atom)
return -1;
+ /* use largest numeric types */
+ if (upcast && type->type->eclass == EC_NUM)
+ type = sql_bind_localtype("lng");
+ if (upcast && type->type->eclass == EC_FLT)
+ type = sql_bind_localtype("dbl");
+
if (set_type_param(sql, type, param->flag) == 0) {
param->tpe = *type;
return 0;
@@ -1928,7 +1934,7 @@ rel_check_type(mvc *sql, sql_subtype *t,
sql_exp* nexp = NULL;
sql_subtype *fromtype = exp_subtype(exp);
- if ((!fromtype || !fromtype->type) && rel_set_type_param(sql, t, exp)
== 0)
+ if ((!fromtype || !fromtype->type) && rel_set_type_param(sql, t, exp,
0) == 0)
return exp;
/* first try cheap internal (in-place) conversions ! */
@@ -2052,9 +2058,9 @@ rel_convert_types(mvc *sql, sql_exp **L,
return -1;
}
if (rt && (!lt || !lt->type))
- return rel_set_type_param(sql, rt, ls);
+ return rel_set_type_param(sql, rt, ls, 0);
if (lt && (!rt || !rt->type))
- return rel_set_type_param(sql, lt, rs);
+ return rel_set_type_param(sql, lt, rs, 0);
if (rt && lt) {
sql_subtype *i = lt;
@@ -2653,7 +2659,7 @@ rel_logical_value_exp(mvc *sql, sql_rel
if (!re)
return NULL;
if (!exp_subtype(re)) {
- if (rel_set_type_param(sql, st, re) == -1)
+ if (rel_set_type_param(sql, st, re, 0) == -1)
return sql_error(sql, 02, "LIKE: wrong type,
should be string");
} else if ((re = rel_check_type(sql, st, re, type_equal)) ==
NULL) {
return sql_error(sql, 02, "LIKE: wrong type, should be
string");
@@ -3195,7 +3201,7 @@ rel_logical_exp(mvc *sql, sql_rel *rel,
if (!re)
return NULL;
if (!exp_subtype(re)) {
- if (rel_set_type_param(sql, st, re) == -1)
+ if (rel_set_type_param(sql, st, re, 0) == -1)
return sql_error(sql, 02, "LIKE: wrong type,
should be string");
} else if ((re = rel_check_type(sql, st, re, type_equal)) ==
NULL) {
return sql_error(sql, 02, "LIKE: wrong type, should be
string");
@@ -3434,10 +3440,15 @@ rel_binop_(mvc *sql, sql_exp *l, sql_exp
s = sql->session->schema;
/* handle param's early */
- if ((!t1 || !t2) && rel_convert_types(sql, &l, &r, 1/*fix scale*/,
type_equal) >= 0) {
+ if (!t1 || !t2) {
+ if (t2 && !t1 && rel_set_type_param(sql, t2, l, 1) < 0)
+ return NULL;
+ if (t1 && !t2 && rel_set_type_param(sql, t1, r, 1) < 0)
+ return NULL;
t1 = exp_subtype(l);
t2 = exp_subtype(r);
}
+
if (!t1 || !t2)
return sql_error(sql, 01, "Cannot have a parameter (?) on both
sides of an expression");
diff --git
a/sql/test/BugTracker-2010/Tests/prepare_statements_crash_server.Bug-2599.stable.out
b/sql/test/BugTracker-2010/Tests/prepare_statements_crash_server.Bug-2599.stable.out
---
a/sql/test/BugTracker-2010/Tests/prepare_statements_crash_server.Bug-2599.stable.out
+++
b/sql/test/BugTracker-2010/Tests/prepare_statements_crash_server.Bug-2599.stable.out
@@ -27,37 +27,37 @@ Ready.
% .prepare, .prepare, .prepare, .prepare, .prepare,
.prepare # table_name
% type, digits, scale, schema, table, column # name
% varchar, int, int, str, str, str # type
-% 7, 2, 1, 0, 6, 1 # length
+% 6, 3, 1, 0, 6, 1 # length
[ "int", 32, 0, "", "t_2599", "a" ]
[ "int", 32, 0, "", "t_2599", "b" ]
-[ "tinyint", 8, 0, NULL, NULL, NULL ]
+[ "bigint", 64, 0, NULL, NULL, NULL ]
#prepare select * from t_2599 where a>2*?+1;
#prepare select * from t_2599 where a>2*?+1;
% .prepare, .prepare, .prepare, .prepare, .prepare,
.prepare # table_name
% type, digits, scale, schema, table, column # name
% varchar, int, int, str, str, str # type
-% 7, 2, 1, 0, 6, 1 # length
+% 6, 3, 1, 0, 6, 1 # length
[ "int", 32, 0, "", "t_2599", "a" ]
[ "int", 32, 0, "", "t_2599", "b" ]
-[ "tinyint", 8, 0, NULL, NULL, NULL ]
+[ "bigint", 64, 0, NULL, NULL, NULL ]
#prepare select * from t_2599 where a>?+1;
#prepare select * from t_2599 where a>?+1;
% .prepare, .prepare, .prepare, .prepare, .prepare,
.prepare # table_name
% type, digits, scale, schema, table, column # name
% varchar, int, int, str, str, str # type
-% 7, 2, 1, 0, 6, 1 # length
+% 6, 3, 1, 0, 6, 1 # length
[ "int", 32, 0, "", "t_2599", "a" ]
[ "int", 32, 0, "", "t_2599", "b" ]
-[ "tinyint", 8, 0, NULL, NULL, NULL ]
+[ "bigint", 64, 0, NULL, NULL, NULL ]
#prepare select * from t_2599 where a>1+?*2;
#prepare select * from t_2599 where a>1+?*2;
% .prepare, .prepare, .prepare, .prepare, .prepare,
.prepare # table_name
% type, digits, scale, schema, table, column # name
% varchar, int, int, str, str, str # type
-% 7, 2, 1, 0, 6, 1 # length
+% 6, 3, 1, 0, 6, 1 # length
[ "int", 32, 0, "", "t_2599", "a" ]
[ "int", 32, 0, "", "t_2599", "b" ]
-[ "tinyint", 8, 0, NULL, NULL, NULL ]
+[ "bigint", 64, 0, NULL, NULL, NULL ]
#drop table t_2599;
# 12:42:06 >
diff --git a/sql/test/BugTracker-2013/Tests/All
b/sql/test/BugTracker-2013/Tests/All
--- a/sql/test/BugTracker-2013/Tests/All
+++ b/sql/test/BugTracker-2013/Tests/All
@@ -19,3 +19,4 @@ corrupt-after-restart.Bug-3282
db_users.Bug-3287
create_table_with_func.Bug-3286
add_boolean.Bug-3289
+prepare-smallint.Bug-3297
diff --git a/sql/test/BugTracker-2013/Tests/prepare-smallint.Bug-3297.sql
b/sql/test/BugTracker-2013/Tests/prepare-smallint.Bug-3297.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2013/Tests/prepare-smallint.Bug-3297.sql
@@ -0,0 +1,5 @@
+CREATE TABLE ints ( val int );
+prepare INSERT INTO ints VALUES ( ? - 20 );
+exec **(1000);
+select * from ints;
+drop table ints;
diff --git
a/sql/test/BugTracker-2013/Tests/prepare-smallint.Bug-3297.stable.err
b/sql/test/BugTracker-2013/Tests/prepare-smallint.Bug-3297.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2013/Tests/prepare-smallint.Bug-3297.stable.err
@@ -0,0 +1,35 @@
+stderr of test 'prepare-smallint.Bug-3297` in directory
'sql/test/BugTracker-2013` itself:
+
+
+# 20:19:33 >
+# 20:19:33 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"mapi_open=true" "--set" "mapi_port=35817" "--set"
"mapi_usock=/var/tmp/mtest-25917/.s.monetdb.35817" "--set" "monet_prompt="
"--forcemito" "--set" "mal_listing=2"
"--dbpath=/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2013"
"--set" "mal_listing=0"
+# 20:19:33 >
+
+# builtin opt gdk_dbpath =
/home/niels/scratch/rc-clean/Linux-x86_64/var/monetdb5/dbfarm/demo
+# builtin opt gdk_debug = 0
+# builtin opt gdk_vmtrim = yes
+# builtin opt monet_prompt = >
+# builtin opt monet_daemon = no
+# builtin opt mapi_port = 50000
+# builtin opt mapi_open = false
+# builtin opt mapi_autosense = false
+# builtin opt sql_optimizer = default_pipe
+# builtin opt sql_debug = 0
+# cmdline opt gdk_nr_threads = 0
+# cmdline opt mapi_open = true
+# cmdline opt mapi_port = 35817
+# cmdline opt mapi_usock = /var/tmp/mtest-25917/.s.monetdb.35817
+# cmdline opt monet_prompt =
+# cmdline opt mal_listing = 2
+# cmdline opt gdk_dbpath =
/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2013
+# cmdline opt mal_listing = 0
+
+# 20:19:34 >
+# 20:19:34 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e"
"--host=/var/tmp/mtest-25917" "--port=35817"
+# 20:19:34 >
+
+
+# 20:19:34 >
+# 20:19:34 > "Done."
+# 20:19:34 >
+
diff --git
a/sql/test/BugTracker-2013/Tests/prepare-smallint.Bug-3297.stable.out
b/sql/test/BugTracker-2013/Tests/prepare-smallint.Bug-3297.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2013/Tests/prepare-smallint.Bug-3297.stable.out
@@ -0,0 +1,72 @@
+stdout of test 'prepare-smallint.Bug-3297` in directory
'sql/test/BugTracker-2013` itself:
+
+
+# 20:19:33 >
+# 20:19:33 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"mapi_open=true" "--set" "mapi_port=35817" "--set"
"mapi_usock=/var/tmp/mtest-25917/.s.monetdb.35817" "--set" "monet_prompt="
"--forcemito" "--set" "mal_listing=2"
"--dbpath=/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2013"
"--set" "mal_listing=0"
+# 20:19:33 >
+
+# MonetDB 5 server v11.15.4
+# This is an unreleased version
+# Serving database 'mTests_sql_test_BugTracker-2013', using 4 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically
linked
+# Found 3.777 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2013 MonetDB B.V., all rights reserved
+# Visit http://www.monetdb.org/ for further information
+# Listening for connection requests on
mapi:monetdb://niels.nesco.mine.nu:35817/
+# Listening for UNIX domain connection requests on
mapi:monetdb:///var/tmp/mtest-25917/.s.monetdb.35817
+# MonetDB/GIS module loaded
+# MonetDB/JAQL module loaded
+# MonetDB/SQL module loaded
+
+Ready.
+# SQL catalog created, loading sql scripts once
+# loading sql script: 09_like.sql
+# loading sql script: 10_math.sql
+# loading sql script: 11_times.sql
+# loading sql script: 12_url.sql
+# loading sql script: 13_date.sql
+# loading sql script: 14_inet.sql
+# loading sql script: 15_history.sql
+# loading sql script: 16_tracelog.sql
+# loading sql script: 17_compress.sql
+# loading sql script: 18_dictionary.sql
+# loading sql script: 19_cluster.sql
+# loading sql script: 20_vacuum.sql
+# loading sql script: 21_dependency_functions.sql
+# loading sql script: 22_clients.sql
+# loading sql script: 23_skyserver.sql
+# loading sql script: 24_zorder.sql
+# loading sql script: 25_debug.sql
+# loading sql script: 39_analytics.sql
+# loading sql script: 40_geom.sql
+# loading sql script: 75_storagemodel.sql
+# loading sql script: 80_udf.sql
+# loading sql script: 99_system.sql
+
+# 20:19:34 >
+# 20:19:34 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e"
"--host=/var/tmp/mtest-25917" "--port=35817"
+# 20:19:34 >
+
+#CREATE TABLE ints ( val int );
+#prepare INSERT INTO ints VALUES ( ? - 20 );
+#prepare INSERT INTO ints VALUES ( ? - 20 );
+% .prepare, .prepare, .prepare, .prepare, .prepare,
.prepare # table_name
+% type, digits, scale, schema, table, column # name
+% varchar, int, int, str, str, str # type
+% 6, 2, 1, 0, 0, 0 # length
+[ "bigint", 64, 0, NULL, NULL, NULL ]
+#exec 0(1000);
+[ 1 ]
+#select * from ints;
+% sys.ints # table_name
+% val # name
+% int # type
+% 3 # length
+[ 980 ]
+#drop table ints;
+
+# 20:19:34 >
+# 20:19:34 > "Done."
+# 20:19:34 >
+
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list