Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
61a5fac1
Commit
61a5fac1
authored
Sep 06, 2005
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug #6172 RAND(a) should only accept constant values as arguments(2nd version)
Argument of RAND function can be constant value only
parent
f53de1f2
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
26 deletions
+41
-26
mysql-test/r/func_math.result
mysql-test/r/func_math.result
+5
-0
mysql-test/r/ps.result
mysql-test/r/ps.result
+21
-23
mysql-test/t/func_math.test
mysql-test/t/func_math.test
+9
-0
mysql-test/t/ps.test
mysql-test/t/ps.test
+1
-3
sql/item_func.cc
sql/item_func.cc
+5
-0
No files found.
mysql-test/r/func_math.result
View file @
61a5fac1
...
@@ -140,3 +140,8 @@ drop table t1;
...
@@ -140,3 +140,8 @@ drop table t1;
select abs(-2) * -2;
select abs(-2) * -2;
abs(-2) * -2
abs(-2) * -2
-4
-4
create table t1 (i int);
insert into t1 values (1);
select rand(i) from t1;
ERROR HY000: Incorrect arguments to RAND
drop table t1;
mysql-test/r/ps.result
View file @
61a5fac1
...
@@ -334,39 +334,37 @@ create table t1 (a int);
...
@@ -334,39 +334,37 @@ create table t1 (a int);
insert into t1 (a) values (1), (2), (3), (4);
insert into t1 (a) values (1), (2), (3), (4);
set @precision=10000000000;
set @precision=10000000000;
select rand(),
select rand(),
cast(rand(10)*@precision as unsigned integer),
cast(rand(10)*@precision as unsigned integer) from t1;
cast(rand(a)*@precision as unsigned integer) from t1;
rand() cast(rand(10)*@precision as unsigned integer)
rand() cast(rand(10)*@precision as unsigned integer) cast(rand(a)*@precision as unsigned integer)
- 6570515219
- 6570515219 -
- 1282061302
- 1282061302 -
- 6698761160
- 6698761160 -
- 9647622201
- 9647622201 -
prepare stmt from
prepare stmt from
"select rand(),
"select rand(),
cast(rand(10)*@precision as unsigned integer),
cast(rand(10)*@precision as unsigned integer),
cast(rand(a)*@precision as unsigned integer),
cast(rand(?)*@precision as unsigned integer) from t1";
cast(rand(?)*@precision as unsigned integer) from t1";
set @var=1;
set @var=1;
execute stmt using @var;
execute stmt using @var;
rand() cast(rand(10)*@precision as unsigned integer) cast(rand(
a)*@precision as unsigned integer) cast(rand(
?)*@precision as unsigned integer)
rand() cast(rand(10)*@precision as unsigned integer) cast(rand(?)*@precision as unsigned integer)
- 6570515219 -
4054035371
- 6570515219 -
- 1282061302 -
8716141803
- 1282061302 -
- 6698761160 -
1418603212
- 6698761160 -
- 9647622201 -
944590960
- 9647622201 -
set @var=2;
set @var=2;
execute stmt using @var;
execute stmt using @var;
rand() cast(rand(10)*@precision as unsigned integer) cast(rand(
a)*@precision as unsigned integer) cast(rand(
?)*@precision as unsigned integer)
rand() cast(rand(10)*@precision as unsigned integer) cast(rand(?)*@precision as unsigned integer)
- 6570515219
1559528654
6555866465
- 6570515219 6555866465
- 1282061302
6238114970
1223466192
- 1282061302 1223466192
- 6698761160 6
511989195 6
449731873
- 6698761160 6449731873
- 9647622201
3845601374
8578261098
- 9647622201 8578261098
set @var=3;
set @var=3;
execute stmt using @var;
execute stmt using @var;
rand() cast(rand(10)*@precision as unsigned integer) cast(rand(
a)*@precision as unsigned integer) cast(rand(
?)*@precision as unsigned integer)
rand() cast(rand(10)*@precision as unsigned integer) cast(rand(?)*@precision as unsigned integer)
- 6570515219
1559528654
9057697559
- 6570515219 9057697559
- 1282061302
6238114970
3730790581
- 1282061302 3730790581
- 6698761160
6511989195
1480860534
- 6698761160 1480860534
- 9647622201
3845601374
6211931236
- 9647622201 6211931236
drop table t1;
drop table t1;
deallocate prepare stmt;
deallocate prepare stmt;
create database mysqltest1;
create database mysqltest1;
...
...
mysql-test/t/func_math.test
View file @
61a5fac1
...
@@ -77,4 +77,13 @@ drop table t1;
...
@@ -77,4 +77,13 @@ drop table t1;
#
#
select
abs
(
-
2
)
*
-
2
;
select
abs
(
-
2
)
*
-
2
;
#
# Bug #6172 RAND(a) should only accept constant values as arguments
#
create
table
t1
(
i
int
);
insert
into
t1
values
(
1
);
--
error
1210
select
rand
(
i
)
from
t1
;
drop
table
t1
;
# End of 4.1 tests
# End of 4.1 tests
mysql-test/t/ps.test
View file @
61a5fac1
...
@@ -368,12 +368,10 @@ insert into t1 (a) values (1), (2), (3), (4);
...
@@ -368,12 +368,10 @@ insert into t1 (a) values (1), (2), (3), (4);
set
@
precision
=
10000000000
;
set
@
precision
=
10000000000
;
--
replace_column
1
-
3
-
--
replace_column
1
-
3
-
select
rand
(),
select
rand
(),
cast
(
rand
(
10
)
*@
precision
as
unsigned
integer
),
cast
(
rand
(
10
)
*@
precision
as
unsigned
integer
)
from
t1
;
cast
(
rand
(
a
)
*@
precision
as
unsigned
integer
)
from
t1
;
prepare
stmt
from
prepare
stmt
from
"select rand(),
"select rand(),
cast(rand(10)*@precision as unsigned integer),
cast(rand(10)*@precision as unsigned integer),
cast(rand(a)*@precision as unsigned integer),
cast(rand(?)*@precision as unsigned integer) from t1"
;
cast(rand(?)*@precision as unsigned integer) from t1"
;
set
@
var
=
1
;
set
@
var
=
1
;
--
replace_column
1
-
3
-
--
replace_column
1
-
3
-
...
...
sql/item_func.cc
View file @
61a5fac1
...
@@ -1038,6 +1038,11 @@ bool Item_func_rand::fix_fields(THD *thd, struct st_table_list *tables,
...
@@ -1038,6 +1038,11 @@ bool Item_func_rand::fix_fields(THD *thd, struct st_table_list *tables,
used_tables_cache
|=
RAND_TABLE_BIT
;
used_tables_cache
|=
RAND_TABLE_BIT
;
if
(
arg_count
)
if
(
arg_count
)
{
// Only use argument once in query
{
// Only use argument once in query
if
(
!
args
[
0
]
->
const_during_execution
())
{
my_error
(
ER_WRONG_ARGUMENTS
,
MYF
(
0
),
"RAND"
);
return
TRUE
;
}
/*
/*
Allocate rand structure once: we must use thd->current_arena
Allocate rand structure once: we must use thd->current_arena
to create rand in proper mem_root if it's a prepared statement or
to create rand in proper mem_root if it's a prepared statement or
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment