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
b3e5cc6b
Commit
b3e5cc6b
authored
Nov 14, 2006
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merge bk-internal:/home/bk/mysql-5.0-maint
into neptunus.(none):/home/msvensson/mysql/mysql-5.0-maint
parents
2df738f3
1aad9901
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
146 additions
and
28 deletions
+146
-28
BitKeeper/etc/collapsed
BitKeeper/etc/collapsed
+8
-0
mysql-test/r/udf.result
mysql-test/r/udf.result
+35
-0
mysql-test/t/udf.test
mysql-test/t/udf.test
+38
-1
sql/item_func.cc
sql/item_func.cc
+35
-27
sql/udf_example.c
sql/udf_example.c
+30
-0
No files found.
BitKeeper/etc/collapsed
View file @
b3e5cc6b
...
...
@@ -16,6 +16,14 @@
45214a07hVsIGwvwa-WrO-jpeaSwVw
452a92d0-31-8wSzSfZi165fcGcXPA
454a7ef8gdvE_ddMlJyghvOAkKPNOQ
454bb488ijVLOUK_GFjcoISE0GxPUA
454bb9a8AwlGRC_wWLS2sNMoRBMRGw
454c946ciQoR4dfTBZ0RTBmGJKp6lw
454f6e7eAnfLD9OCbGr5X9KiKvfKcQ
454f704bJiJy0_Nx2drY9P5kK3uOzg
454f8960jsVT_kMKJtZ9OCgXoba0xQ
454fa71cxshxszXJQYa9jbo0-_hAHw
4550b0ceIcozdgQhWFUTAtWkN196lA
4554a95d7txO1DuO9G3nAizI3SkFAA
4554b3722d71SbPiI2Gx-RhbZjmuIQ
4558b3d73Cxjlb7Wv1oytdSTthxDfw
mysql-test/r/udf.result
View file @
b3e5cc6b
...
...
@@ -115,3 +115,38 @@ DROP FUNCTION sequence;
DROP FUNCTION lookup;
DROP FUNCTION reverse_lookup;
DROP FUNCTION avgcost;
CREATE FUNCTION is_const RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
select
is_const(3) as const,
is_const(3.14) as const,
is_const('fnord') as const,
is_const(2+3) as const,
is_const(rand()) as 'nc rand()',
is_const(sin(3.14)) as const,
is_const(upper('test')) as const;
const const const const nc rand() const const
const const const const not const const const
create table bug18761 (n int);
insert into bug18761 values (null),(2);
select
is_const(3) as const,
is_const(3.14) as const,
is_const('fnord') as const,
is_const(2+3) as const,
is_const(2+n) as 'nc 2+n ',
is_const(sin(n)) as 'nc sin(n)',
is_const(sin(3.14)) as const,
is_const(upper('test')) as const,
is_const(rand()) as 'nc rand()',
is_const(n) as 'nc n ',
is_const(is_const(n)) as 'nc ic?(n)',
is_const(is_const('c')) as const
from
bug18761;
const const const const nc 2+n nc sin(n) const const nc rand() nc n nc ic?(n) const
const const const const not const not const const const not const not const not const const
const const const const not const not const const const not const not const not const const
drop table bug18761;
select is_const((1,2,3));
ERROR 21000: Operand should contain 1 column(s)
drop function if exists is_const;
mysql-test/t/udf.test
View file @
b3e5cc6b
...
...
@@ -143,4 +143,41 @@ DROP FUNCTION lookup;
DROP
FUNCTION
reverse_lookup
;
DROP
FUNCTION
avgcost
;
#
# Bug#18761: constant expression as UDF parameters not passed in as constant
#
--
replace_result
$UDF_EXAMPLE_LIB
UDF_EXAMPLE_LIB
eval
CREATE
FUNCTION
is_const
RETURNS
STRING
SONAME
"
$UDF_EXAMPLE_LIB
"
;
select
is_const
(
3
)
as
const
,
is_const
(
3.14
)
as
const
,
is_const
(
'fnord'
)
as
const
,
is_const
(
2
+
3
)
as
const
,
is_const
(
rand
())
as
'nc rand()'
,
is_const
(
sin
(
3.14
))
as
const
,
is_const
(
upper
(
'test'
))
as
const
;
create
table
bug18761
(
n
int
);
insert
into
bug18761
values
(
null
),(
2
);
select
is_const
(
3
)
as
const
,
is_const
(
3.14
)
as
const
,
is_const
(
'fnord'
)
as
const
,
is_const
(
2
+
3
)
as
const
,
is_const
(
2
+
n
)
as
'nc 2+n '
,
is_const
(
sin
(
n
))
as
'nc sin(n)'
,
is_const
(
sin
(
3.14
))
as
const
,
is_const
(
upper
(
'test'
))
as
const
,
is_const
(
rand
())
as
'nc rand()'
,
is_const
(
n
)
as
'nc n '
,
is_const
(
is_const
(
n
))
as
'nc ic?(n)'
,
is_const
(
is_const
(
'c'
))
as
const
from
bug18761
;
drop
table
bug18761
;
--
error
1241
select
is_const
((
1
,
2
,
3
));
drop
function
if
exists
is_const
;
sql/item_func.cc
View file @
b3e5cc6b
...
...
@@ -2696,39 +2696,47 @@ udf_handler::fix_fields(THD *thd, Item_result_field *func,
char
*
to
=
num_buffer
;
for
(
uint
i
=
0
;
i
<
arg_count
;
i
++
)
{
f_args
.
args
[
i
]
=
0
;
/*
For a constant argument i, args->args[i] points to the argument value.
For non-constant, args->args[i] is NULL.
*/
f_args
.
args
[
i
]
=
NULL
;
/* Non-const unless updated below. */
f_args
.
lengths
[
i
]
=
arguments
[
i
]
->
max_length
;
f_args
.
maybe_null
[
i
]
=
(
char
)
arguments
[
i
]
->
maybe_null
;
f_args
.
attributes
[
i
]
=
arguments
[
i
]
->
name
;
f_args
.
attribute_lengths
[
i
]
=
arguments
[
i
]
->
name_length
;
switch
(
arguments
[
i
]
->
type
())
{
case
Item
:
:
STRING_ITEM
:
// Constant string !
if
(
arguments
[
i
]
->
const_item
())
{
String
*
res
=
arguments
[
i
]
->
val_str
(
&
buffers
[
i
]);
if
(
arguments
[
i
]
->
null_value
)
continue
;
f_args
.
args
[
i
]
=
(
char
*
)
res
->
ptr
();
break
;
}
case
Item
:
:
INT_ITEM
:
*
((
longlong
*
)
to
)
=
arguments
[
i
]
->
val_int
();
if
(
!
arguments
[
i
]
->
null_value
)
{
f_args
.
args
[
i
]
=
to
;
to
+=
ALIGN_SIZE
(
sizeof
(
longlong
));
}
break
;
case
Item
:
:
REAL_ITEM
:
*
((
double
*
)
to
)
=
arguments
[
i
]
->
val_real
();
if
(
!
arguments
[
i
]
->
null_value
)
{
f_args
.
args
[
i
]
=
to
;
to
+=
ALIGN_SIZE
(
sizeof
(
double
));
}
break
;
default:
// Skip these
break
;
if
(
arguments
[
i
]
->
null_value
)
continue
;
switch
(
arguments
[
i
]
->
result_type
())
{
case
STRING_RESULT
:
case
DECIMAL_RESULT
:
{
String
*
res
=
arguments
[
i
]
->
val_str
(
&
buffers
[
i
]);
f_args
.
args
[
i
]
=
(
char
*
)
res
->
ptr
();
break
;
}
case
INT_RESULT
:
*
((
longlong
*
)
to
)
=
arguments
[
i
]
->
val_int
();
f_args
.
args
[
i
]
=
to
;
to
+=
ALIGN_SIZE
(
sizeof
(
longlong
));
break
;
case
REAL_RESULT
:
*
((
double
*
)
to
)
=
arguments
[
i
]
->
val_real
();
f_args
.
args
[
i
]
=
to
;
to
+=
ALIGN_SIZE
(
sizeof
(
double
));
break
;
case
ROW_RESULT
:
default:
// This case should never be chosen
DBUG_ASSERT
(
0
);
break
;
}
}
}
thd
->
net
.
last_error
[
0
]
=
0
;
...
...
sql/udf_example.c
View file @
b3e5cc6b
...
...
@@ -165,6 +165,9 @@ void avgcost_reset( UDF_INIT* initid, UDF_ARGS* args, char* is_null, char *error
void
avgcost_clear
(
UDF_INIT
*
initid
,
char
*
is_null
,
char
*
error
);
void
avgcost_add
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
is_null
,
char
*
error
);
double
avgcost
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
is_null
,
char
*
error
);
my_bool
is_const_init
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
message
);
char
*
is_const
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
result
,
unsigned
long
*
length
,
char
*
is_null
,
char
*
error
);
/*************************************************************************
...
...
@@ -1075,4 +1078,31 @@ char *myfunc_argument_name(UDF_INIT *initid __attribute__((unused)),
return
result
;
}
my_bool
is_const_init
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
message
)
{
if
(
args
->
arg_count
!=
1
)
{
strmov
(
message
,
"IS_CONST accepts only one argument"
);
return
1
;
}
initid
->
ptr
=
(
args
->
args
[
0
]
!=
NULL
)
?
1
:
0
;
return
0
;
}
char
*
is_const
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
result
,
unsigned
long
*
length
,
char
*
is_null
,
char
*
error
)
{
if
(
initid
->
ptr
!=
0
)
{
sprintf
(
result
,
"const"
);
}
else
{
sprintf
(
result
,
"not const"
);
}
*
is_null
=
0
;
*
length
=
strlen
(
result
);
return
result
;
}
#endif
/* HAVE_DLOPEN */
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