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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
bb67600d
Commit
bb67600d
authored
Dec 17, 2002
by
hf@deer.mysql.r18.ru
Browse files
Options
Browse Files
Download
Plain Diff
Merging
parents
d8c70089
e56fb196
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
258 additions
and
100 deletions
+258
-100
include/mysql.h
include/mysql.h
+2
-1
libmysql/libmysql.c
libmysql/libmysql.c
+48
-12
libmysqld/libmysqld.c
libmysqld/libmysqld.c
+28
-8
sql/field.cc
sql/field.cc
+128
-71
sql/field.h
sql/field.h
+2
-1
sql/sql_show.cc
sql/sql_show.cc
+1
-1
sql/udf_example.cc
sql/udf_example.cc
+49
-6
No files found.
include/mysql.h
View file @
bb67600d
...
...
@@ -122,7 +122,8 @@ typedef struct st_mysql_data {
struct
st_mysql_options
{
unsigned
int
connect_timeout
,
client_flag
;
unsigned
int
port
;
char
*
host
,
*
init_command
,
*
user
,
*
password
,
*
unix_socket
,
*
db
;
char
*
host
,
*
user
,
*
password
,
*
unix_socket
,
*
db
;
struct
st_dynamic_array
*
init_commands
;
char
*
my_cnf_file
,
*
my_cnf_group
,
*
charset_dir
,
*
charset_name
;
char
*
ssl_key
;
/* PEM key file */
char
*
ssl_cert
;
/* PEM cert file */
...
...
libmysql/libmysql.c
View file @
bb67600d
...
...
@@ -935,6 +935,27 @@ static const char *default_options[]=
static
TYPELIB
option_types
=
{
array_elements
(
default_options
)
-
1
,
"options"
,
default_options
};
static
int
add_init_command
(
struct
st_mysql_options
*
options
,
const
char
*
cmd
)
{
char
**
ptr
,
*
tmp
;
if
(
!
options
->
init_commands
)
{
options
->
init_commands
=
(
DYNAMIC_ARRAY
*
)
my_malloc
(
sizeof
(
DYNAMIC_ARRAY
),
MYF
(
MY_WME
));
init_dynamic_array
(
options
->
init_commands
,
sizeof
(
char
*
),
0
,
5
CALLER_INFO
);
}
if
(
!
(
tmp
=
my_strdup
(
cmd
,
MYF
(
MY_WME
)))
||
insert_dynamic
(
options
->
init_commands
,
&
tmp
))
{
my_free
(
tmp
,
MYF
(
MY_ALLOW_ZERO_PTR
));
return
1
;
}
return
0
;
}
static
void
mysql_read_default_options
(
struct
st_mysql_options
*
options
,
const
char
*
filename
,
const
char
*
group
)
{
...
...
@@ -1003,11 +1024,7 @@ static void mysql_read_default_options(struct st_mysql_options *options,
}
break
;
case
8
:
/* init-command */
if
(
opt_arg
)
{
my_free
(
options
->
init_command
,
MYF
(
MY_ALLOW_ZERO_PTR
));
options
->
init_command
=
my_strdup
(
opt_arg
,
MYF
(
MY_WME
));
}
add_init_command
(
options
,
opt_arg
);
break
;
case
9
:
/* host */
if
(
opt_arg
)
...
...
@@ -2328,13 +2345,29 @@ Try also with PIPE or TCP/IP
net
->
compress
=
1
;
if
(
db
&&
mysql_select_db
(
mysql
,
db
))
goto
error
;
if
(
mysql
->
options
.
init_command
)
if
(
mysql
->
options
.
init_commands
)
{
DYNAMIC_ARRAY
*
init_commands
=
mysql
->
options
.
init_commands
;
char
**
ptr
=
(
char
**
)
init_commands
->
buffer
;
char
**
end
=
ptr
+
init_commands
->
elements
;
my_bool
reconnect
=
mysql
->
reconnect
;
mysql
->
reconnect
=
0
;
if
(
mysql_query
(
mysql
,
mysql
->
options
.
init_command
))
goto
error
;
mysql_free_result
(
mysql_use_result
(
mysql
));
for
(;
ptr
<
end
;
ptr
++
)
{
MYSQL_RES
*
res
;
if
(
mysql_query
(
mysql
,
*
ptr
))
goto
error
;
if
(
mysql
->
fields
)
{
if
(
!
(
res
=
mysql_use_result
(
mysql
)))
goto
error
;
mysql_free_result
(
res
);
}
}
mysql
->
reconnect
=
reconnect
;
}
...
...
@@ -2579,7 +2612,6 @@ mysql_close(MYSQL *mysql)
my_free
(
mysql
->
user
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
passwd
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
db
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
init_command
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
user
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
host
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
password
,
MYF
(
MY_ALLOW_ZERO_PTR
));
...
...
@@ -2589,6 +2621,11 @@ mysql_close(MYSQL *mysql)
my_free
(
mysql
->
options
.
my_cnf_group
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
charset_dir
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
charset_name
,
MYF
(
MY_ALLOW_ZERO_PTR
));
if
(
mysql
->
options
.
init_commands
)
{
delete_dynamic
(
mysql
->
options
.
init_commands
);
my_free
((
char
*
)
mysql
->
options
.
init_commands
,
MYF
(
MY_WME
));
}
#ifdef HAVE_OPENSSL
mysql_ssl_free
(
mysql
);
#endif
/* HAVE_OPENSSL */
...
...
@@ -3334,8 +3371,7 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg)
mysql
->
options
.
client_flag
&=
~
CLIENT_LOCAL_FILES
;
break
;
case
MYSQL_INIT_COMMAND
:
my_free
(
mysql
->
options
.
init_command
,
MYF
(
MY_ALLOW_ZERO_PTR
));
mysql
->
options
.
init_command
=
my_strdup
(
arg
,
MYF
(
MY_WME
));
add_init_command
(
&
mysql
->
options
,
arg
);
break
;
case
MYSQL_READ_DEFAULT_FILE
:
my_free
(
mysql
->
options
.
my_cnf_file
,
MYF
(
MY_ALLOW_ZERO_PTR
));
...
...
libmysqld/libmysqld.c
View file @
bb67600d
...
...
@@ -219,6 +219,27 @@ static const char *default_options[]=
static
TYPELIB
option_types
=
{
array_elements
(
default_options
)
-
1
,
"options"
,
default_options
};
static
int
add_init_command
(
struct
st_mysql_options
*
options
,
const
char
*
cmd
)
{
char
**
ptr
,
*
tmp
;
if
(
!
options
->
init_commands
)
{
options
->
init_commands
=
(
DYNAMIC_ARRAY
*
)
my_malloc
(
sizeof
(
DYNAMIC_ARRAY
),
MYF
(
MY_WME
));
init_dynamic_array
(
options
->
init_commands
,
sizeof
(
char
*
),
0
,
5
CALLER_INFO
);
}
if
(
!
(
tmp
=
my_strdup
(
cmd
,
MYF
(
MY_WME
)))
||
insert_dynamic
(
options
->
init_commands
,
&
tmp
))
{
my_free
(
tmp
,
MYF
(
MY_ALLOW_ZERO_PTR
));
return
1
;
}
return
0
;
}
static
void
mysql_read_default_options
(
struct
st_mysql_options
*
options
,
const
char
*
filename
,
const
char
*
group
)
{
...
...
@@ -288,11 +309,7 @@ static void mysql_read_default_options(struct st_mysql_options *options,
}
break
;
case
8
:
/* init-command */
if
(
opt_arg
)
{
my_free
(
options
->
init_command
,
MYF
(
MY_ALLOW_ZERO_PTR
));
options
->
init_command
=
my_strdup
(
opt_arg
,
MYF
(
MY_WME
));
}
add_init_command
(
options
,
opt_arg
);
break
;
case
9
:
/* host */
if
(
opt_arg
)
...
...
@@ -589,7 +606,6 @@ mysql_close(MYSQL *mysql)
DBUG_ENTER
(
"mysql_close"
);
if
(
mysql
)
/* Some simple safety */
{
my_free
(
mysql
->
options
.
init_command
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
user
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
host
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
password
,
MYF
(
MY_ALLOW_ZERO_PTR
));
...
...
@@ -599,6 +615,11 @@ mysql_close(MYSQL *mysql)
my_free
(
mysql
->
options
.
my_cnf_group
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
charset_dir
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
charset_name
,
MYF
(
MY_ALLOW_ZERO_PTR
));
if
(
mysql
->
options
.
init_commands
)
{
delete_dynamic
(
mysql
->
options
.
init_commands
);
my_free
((
char
*
)
mysql
->
options
.
init_commands
,
MYF
(
MY_WME
));
}
/* Clear pointers for better safety */
bzero
((
char
*
)
&
mysql
->
options
,
sizeof
(
mysql
->
options
));
#ifdef HAVE_OPENSSL
...
...
@@ -1161,8 +1182,7 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg)
mysql
->
options
.
client_flag
&=
~
CLIENT_LOCAL_FILES
;
break
;
case
MYSQL_INIT_COMMAND
:
my_free
(
mysql
->
options
.
init_command
,
MYF
(
MY_ALLOW_ZERO_PTR
));
mysql
->
options
.
init_command
=
my_strdup
(
arg
,
MYF
(
MY_WME
));
add_init_command
(
&
mysql
->
options
,
arg
);
break
;
case
MYSQL_READ_DEFAULT_FILE
:
my_free
(
mysql
->
options
.
my_cnf_file
,
MYF
(
MY_ALLOW_ZERO_PTR
));
...
...
sql/field.cc
View file @
bb67600d
This diff is collapsed.
Click to expand it.
sql/field.h
View file @
bb67600d
...
...
@@ -262,6 +262,7 @@ class Field_str :public Field {
unireg_check_arg
,
field_name_arg
,
table_arg
)
{
field_charset
=
charset
;
}
Item_result
result_type
()
const
{
return
STRING_RESULT
;
}
void
add_binary_or_charset
(
String
&
res
)
const
;
uint
decimals
()
const
{
return
NOT_FIXED_DEC
;
}
void
make_field
(
Send_field
*
);
uint
size_of
()
const
{
return
sizeof
(
*
this
);
}
...
...
@@ -556,7 +557,7 @@ class Field_null :public Field_str {
int
cmp
(
const
char
*
a
,
const
char
*
b
)
{
return
0
;}
void
sort_string
(
char
*
buff
,
uint
length
)
{}
uint32
pack_length
()
const
{
return
0
;
}
void
sql_type
(
String
&
str
)
const
{
str
.
set
(
"null"
,
4
,
my_thd_charset
);
}
void
sql_type
(
String
&
str
)
const
;
uint
size_of
()
const
{
return
sizeof
(
*
this
);
}
};
...
...
sql/sql_show.cc
View file @
bb67600d
...
...
@@ -711,7 +711,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
{
byte
*
pos
;
uint
flags
=
field
->
flags
;
String
type
(
tmp
,
sizeof
(
tmp
),
default_charset_info
);
String
type
(
tmp
,
sizeof
(
tmp
),
current_thd
->
thd_charset
);
uint
col_access
;
bool
null_default_value
=
0
;
...
...
sql/udf_example.cc
View file @
bb67600d
...
...
@@ -126,6 +126,8 @@ typedef long long longlong;
#include <m_ctype.h>
#include <m_string.h> // To get strmov()
static
pthread_mutex_t
LOCK_hostname
;
#ifdef HAVE_DLOPEN
/* These must be right or mysqld will not find the symbol! */
...
...
@@ -282,8 +284,8 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result,
for
(
n
=
ntrans
+
1
,
n_end
=
ntrans
+
sizeof
(
ntrans
)
-
2
;
word
!=
w_end
&&
n
<
n_end
;
word
++
)
if
(
isalpha
(
*
word
))
*
n
++
=
toupper
(
*
word
);
if
(
my_isalpha
(
my_charset_latin1
,
*
word
))
*
n
++
=
my_toupper
(
my_charset_latin1
,
*
word
);
if
(
n
==
ntrans
+
1
)
/* return empty string if 0 bytes */
{
...
...
@@ -583,6 +585,8 @@ longlong myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
case
REAL_RESULT
:
// Add numers as longlong
val
+=
(
longlong
)
*
((
double
*
)
args
->
args
[
i
]);
break
;
default:
break
;
}
}
return
val
;
...
...
@@ -642,8 +646,6 @@ longlong sequence(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
**
****************************************************************************/
#if defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST)
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
...
...
@@ -651,9 +653,11 @@ longlong sequence(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
extern
"C"
{
my_bool
lookup_init
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
message
);
void
lookup_deinit
(
UDF_INIT
*
initid
);
char
*
lookup
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
result
,
unsigned
long
*
length
,
char
*
null_value
,
char
*
error
);
my_bool
reverse_lookup_init
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
message
);
void
reverse_lookup_deinit
(
UDF_INIT
*
initid
);
char
*
reverse_lookup
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
result
,
unsigned
long
*
length
,
char
*
null_value
,
char
*
error
);
}
...
...
@@ -676,9 +680,19 @@ my_bool lookup_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
}
initid
->
max_length
=
11
;
initid
->
maybe_null
=
1
;
#if !defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST)
(
void
)
pthread_mutex_init
(
&
LOCK_hostname
,
MY_MUTEX_INIT_SLOW
);
#endif
return
0
;
}
void
lookup_deinit
(
UDF_INIT
*
initid
)
{
#if !defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST)
(
void
)
pthread_mutex_destroy
(
&
LOCK_hostname
);
#endif
}
char
*
lookup
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
result
,
unsigned
long
*
res_length
,
char
*
null_value
,
char
*
error
)
{
...
...
@@ -696,13 +710,23 @@ char *lookup(UDF_INIT *initid, UDF_ARGS *args, char *result,
length
=
sizeof
(
name_buff
)
-
1
;
memcpy
(
name_buff
,
args
->
args
[
0
],
length
);
name_buff
[
length
]
=
0
;
#if defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST)
if
(
!
(
hostent
=
gethostbyname_r
(
name_buff
,
&
tmp_hostent
,
hostname_buff
,
sizeof
(
hostname_buff
),
&
tmp_errno
)))
{
*
null_value
=
1
;
return
0
;
}
#else
VOID
(
pthread_mutex_lock
(
&
LOCK_hostname
));
if
(
!
(
hostent
=
gethostbyname
((
char
*
)
name_buff
)))
{
VOID
(
pthread_mutex_unlock
(
&
LOCK_hostname
));
*
null_value
=
1
;
return
0
;
}
VOID
(
pthread_mutex_unlock
(
&
LOCK_hostname
));
#endif
struct
in_addr
in
;
memcpy_fixed
((
char
*
)
&
in
,(
char
*
)
*
hostent
->
h_addr_list
,
sizeof
(
in
.
s_addr
));
*
res_length
=
(
ulong
)
(
strmov
(
result
,
inet_ntoa
(
in
))
-
result
);
...
...
@@ -731,9 +755,18 @@ my_bool reverse_lookup_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
}
initid
->
max_length
=
32
;
initid
->
maybe_null
=
1
;
#if !defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST)
(
void
)
pthread_mutex_init
(
&
LOCK_hostname
,
MY_MUTEX_INIT_SLOW
);
#endif
return
0
;
}
void
reverse_lookup_deinit
(
UDF_INIT
*
initid
)
{
#if !defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST)
(
void
)
pthread_mutex_destroy
(
&
LOCK_hostname
);
#endif
}
char
*
reverse_lookup
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
result
,
unsigned
long
*
res_length
,
char
*
null_value
,
char
*
error
)
...
...
@@ -776,6 +809,7 @@ char *reverse_lookup(UDF_INIT *initid, UDF_ARGS *args, char *result,
return
0
;
}
struct
hostent
*
hp
;
#if defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST)
int
tmp_errno
;
if
(
!
(
hp
=
gethostbyaddr_r
((
char
*
)
&
taddr
,
sizeof
(
taddr
),
AF_INET
,
&
tmp_hostent
,
name_buff
,
sizeof
(
name_buff
),
...
...
@@ -784,10 +818,19 @@ char *reverse_lookup(UDF_INIT *initid, UDF_ARGS *args, char *result,
*
null_value
=
1
;
return
0
;
}
#else
VOID
(
pthread_mutex_lock
(
&
LOCK_hostname
));
if
(
!
(
hp
=
gethostbyaddr
((
char
*
)
&
taddr
,
sizeof
(
taddr
),
AF_INET
)))
{
VOID
(
pthread_mutex_unlock
(
&
LOCK_hostname
));
*
null_value
=
1
;
return
0
;
}
VOID
(
pthread_mutex_unlock
(
&
LOCK_hostname
));
#endif
*
res_length
=
(
ulong
)
(
strmov
(
result
,
hp
->
h_name
)
-
result
);
return
result
;
}
#endif // defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST)
/*
** Syntax for the new aggregate commands are:
...
...
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