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
1e62d607
Commit
1e62d607
authored
Jun 14, 2003
by
monty@narttu.mysql.fi
Browse files
Options
Browse Files
Download
Plain Diff
Merge bk-internal.mysql.com:/home/bk/mysql-4.1
into narttu.mysql.fi:/my/mysql-4.1
parents
002d8420
a1034db4
Changes
21
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
636 additions
and
691 deletions
+636
-691
client/mysql.cc
client/mysql.cc
+4
-1
client/sql_string.h
client/sql_string.h
+8
-0
include/mysql.h
include/mysql.h
+10
-12
include/mysql_com.h
include/mysql_com.h
+2
-1
include/sql_common.h
include/sql_common.h
+0
-4
include/sql_state.h
include/sql_state.h
+0
-3
libmysql/client_settings.h
libmysql/client_settings.h
+4
-21
libmysql/libmysql.c
libmysql/libmysql.c
+89
-94
mysys/charset.c
mysys/charset.c
+8
-4
mysys/errors.c
mysys/errors.c
+1
-1
sql-common/client.c
sql-common/client.c
+380
-441
sql/Makefile.am
sql/Makefile.am
+1
-1
sql/client_settings.h
sql/client_settings.h
+7
-10
sql/log.cc
sql/log.cc
+2
-2
sql/mysql_priv.h
sql/mysql_priv.h
+2
-2
sql/mysqld.cc
sql/mysqld.cc
+35
-33
sql/protocol.cc
sql/protocol.cc
+1
-24
sql/repl_failsafe.cc
sql/repl_failsafe.cc
+11
-10
sql/set_var.cc
sql/set_var.cc
+2
-2
sql/slave.cc
sql/slave.cc
+24
-25
sql/sql_client.cc
sql/sql_client.cc
+45
-0
No files found.
client/mysql.cc
View file @
1e62d607
...
...
@@ -1525,6 +1525,9 @@ static int com_server_help(String *buffer __attribute__((unused)),
char
last_char
;
int
num_name
,
num_cat
;
LINT_INIT
(
num_name
);
LINT_INIT
(
num_cat
);
if
(
num_fields
==
2
)
{
put_info
(
"Many help items for your request exist"
,
INFO_INFO
);
...
...
@@ -1841,7 +1844,7 @@ print_table_data(MYSQL_RES *result)
separator
.
fill
(
separator
.
length
()
+
length
+
2
,
'-'
);
separator
.
append
(
'+'
);
}
tee_puts
(
separator
.
c_ptr
(),
PAGER
);
tee_puts
(
separator
.
c_ptr
_safe
(),
PAGER
);
if
(
column_names
)
{
mysql_field_seek
(
result
,
0
);
...
...
client/sql_string.h
View file @
1e62d607
...
...
@@ -92,6 +92,14 @@ public:
Ptr
[
str_length
]
=
0
;
return
Ptr
;
}
inline
char
*
c_ptr_safe
()
{
if
(
Ptr
&&
str_length
<
Alloced_length
)
Ptr
[
str_length
]
=
0
;
else
(
void
)
realloc
(
str_length
);
return
Ptr
;
}
void
set
(
String
&
str
,
uint32
offset
,
uint32
arg_length
)
{
...
...
include/mysql.h
View file @
1e62d607
...
...
@@ -135,9 +135,9 @@ typedef struct st_mysql_data {
}
MYSQL_DATA
;
struct
st_mysql_options
{
unsigned
int
connect_timeout
;
unsigned
int
connect_timeout
,
read_timeout
,
write_timeout
;
unsigned
int
port
,
protocol
;
unsigned
long
client_flag
;
unsigned
int
port
;
char
*
host
,
*
user
,
*
password
,
*
unix_socket
,
*
db
;
struct
st_dynamic_array
*
init_commands
;
char
*
my_cnf_file
,
*
my_cnf_group
,
*
charset_dir
,
*
charset_name
;
...
...
@@ -146,6 +146,7 @@ struct st_mysql_options {
char
*
ssl_ca
;
/* PEM CA file */
char
*
ssl_capath
;
/* PEM directory of CA-s? */
char
*
ssl_cipher
;
/* cipher to use */
char
*
shared_memory_base_name
;
unsigned
long
max_allowed_packet
;
my_bool
use_ssl
;
/* if to use SSL or not */
my_bool
compress
,
named_pipe
;
...
...
@@ -167,18 +168,15 @@ struct st_mysql_options {
#ifdef EMBEDDED_LIBRARY
my_bool
separate_thread
;
#endif
char
*
shared_memory_base_name
;
unsigned
int
protocol
;
};
enum
mysql_option
{
MYSQL_OPT_CONNECT_TIMEOUT
,
MYSQL_OPT_COMPRESS
,
MYSQL_OPT_NAMED_PIPE
,
MYSQL_INIT_COMMAND
,
MYSQL_READ_DEFAULT_FILE
,
MYSQL_READ_DEFAULT_GROUP
,
MYSQL_SET_CHARSET_DIR
,
MYSQL_SET_CHARSET_NAME
,
MYSQL_OPT_LOCAL_INFILE
,
MYSQL_OPT_PROTOCOL
,
MYSQL_SHARED_MEMORY_BASE_NAME
#ifdef EMBEDDED_LIBRARY
,
MYSQL_OPT_USE_RESULT
#endif
MYSQL_OPT_CONNECT_TIMEOUT
,
MYSQL_OPT_COMPRESS
,
MYSQL_OPT_NAMED_PIPE
,
MYSQL_INIT_COMMAND
,
MYSQL_READ_DEFAULT_FILE
,
MYSQL_READ_DEFAULT_GROUP
,
MYSQL_SET_CHARSET_DIR
,
MYSQL_SET_CHARSET_NAME
,
MYSQL_OPT_LOCAL_INFILE
,
MYSQL_OPT_PROTOCOL
,
MYSQL_SHARED_MEMORY_BASE_NAME
,
MYSQL_OPT_READ_TIMEOUT
,
MYSQL_OPT_WRITE_TIMEOUT
,
MYSQL_OPT_USE_RESULT
};
enum
mysql_status
...
...
@@ -188,8 +186,8 @@ enum mysql_status
enum
mysql_protocol_type
{
MYSQL_PROTOCOL_DEFAULT
,
MYSQL_PROTOCOL_TCP
,
MYSQL_PROTOCOL_SOCKET
,
MYSQL_PROTOCOL_PIPE
,
MYSQL_PROTOCOL_MEMORY
MYSQL_PROTOCOL_DEFAULT
,
MYSQL_PROTOCOL_TCP
,
MYSQL_PROTOCOL_SOCKET
,
MYSQL_PROTOCOL_
PIPE
,
MYSQL_PROTOCOL_
MEMORY
};
/*
There are three types of queries - the ones that have to go to
...
...
include/mysql_com.h
View file @
1e62d607
...
...
@@ -25,7 +25,7 @@
#define HOSTNAME_LENGTH 60
#define USERNAME_LENGTH 16
#define SERVER_VERSION_LENGTH 60
#define SQLSTATE_LENGTH
6
#define SQLSTATE_LENGTH
5
#define LOCAL_HOST "localhost"
#define LOCAL_HOST_NAMEDPIPE "."
...
...
@@ -110,6 +110,7 @@ enum enum_server_command
#define CLIENT_SECURE_CONNECTION 32768
/* New 4.1 authentication */
#define CLIENT_MULTI_QUERIES 65536
/* Enable/disable multiquery support */
#define CLIENT_MULTI_RESULTS 131072
/* Enable/disable multi-results */
#define CLIENT_REMEMBER_OPTIONS (1L << 31)
#define SERVER_STATUS_IN_TRANS 1
/* Transaction has started */
#define SERVER_STATUS_AUTOCOMMIT 2
/* Server in auto_commit mode */
...
...
include/sql_common.h
View file @
1e62d607
...
...
@@ -42,9 +42,5 @@ my_bool mysql_reconnect(MYSQL *mysql);
}
#endif
#ifdef MYSQL_SERVER
#define protocol_41(A) FALSE
#else
#define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
#endif
include/sql_state.h
View file @
1e62d607
...
...
@@ -86,7 +86,6 @@ ER_UNSUPPORTED_EXTENSION, "42000", "",
ER_TABLE_MUST_HAVE_COLUMNS
,
"42000"
,
""
,
ER_UNKNOWN_CHARACTER_SET
,
"42000"
,
""
,
ER_TOO_BIG_ROWSIZE
,
"42000"
,
""
,
ER_STACK_OVERRUN
,
"HY000"
,
""
,
ER_WRONG_OUTER_JOIN
,
"42000"
,
""
,
ER_NULL_COLUMN_IN_INDEX
,
"42000"
,
""
,
ER_PASSWORD_ANONYMOUS_USER
,
"42000"
,
""
,
...
...
@@ -128,8 +127,6 @@ ER_REQUIRES_PRIMARY_KEY, "42000", "",
ER_CHECK_NO_SUCH_TABLE
,
"42000"
,
""
,
ER_CHECK_NOT_IMPLEMENTED
,
"42000"
,
""
,
ER_CANT_DO_THIS_DURING_AN_TRANSACTION
,
"25000"
,
""
,
ER_ERROR_DURING_COMMIT
,
"HY000"
,
""
,
ER_ERROR_DURING_ROLLBACK
,
"HY000"
,
""
,
ER_NEW_ABORTING_CONNECTION
,
"08S01"
,
""
,
ER_MASTER_NET_READ
,
"08S01"
,
""
,
ER_MASTER_NET_WRITE
,
"08S01"
,
""
,
...
...
libmysql/client_settings.h
View file @
1e62d607
...
...
@@ -15,27 +15,10 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
static
my_bool
mysql_client_init
=
0
;
extern
uint
mysql_port
;
extern
my_string
mysql_unix_port
;
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | \
CLIENT_LOCAL_FILES | CLIENT_TRANSACTIONS | \
CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION)
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG \
| CLIENT_LOCAL_FILES | CLIENT_TRANSACTIONS \
| CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION)
#ifdef __WIN__
#define CONNECT_TIMEOUT 20
#else
#define CONNECT_TIMEOUT 0
#endif
#ifdef HAVE_SMEM
char
*
shared_memory_base_name
=
0
;
const
char
*
def_shared_memory_base_name
=
default_shared_memory_base_name
;
#endif
static
my_bool
org_my_init_done
=
0
;
sig_handler
pipe_sig_handler
(
int
sig
__attribute__
((
unused
)));
my_bool
stmt_close
(
MYSQL_STMT
*
stmt
,
my_bool
skip_list
);
...
...
@@ -48,7 +31,7 @@ my_bool send_file_to_server(MYSQL *mysql, const char *filename);
*/
#if !defined(__WIN__) && defined(SIGPIPE) && !defined(THREAD)
#define init_sigpipe_variables sig_return old_signal_handler=(sig_return) 0
;
#define init_sigpipe_variables sig_return old_signal_handler=(sig_return) 0
#define set_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) old_signal_handler=signal(SIGPIPE,pipe_sig_handler)
#define reset_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) signal(SIGPIPE,old_signal_handler);
#else
...
...
libmysql/libmysql.c
View file @
1e62d607
...
...
@@ -59,24 +59,11 @@
#include <sql_common.h>
uint
mysql_port
=
0
;
my_string
mysql_unix_port
=
0
;
ulong
net_buffer_length
=
8192
;
ulong
max_allowed_packet
=
1024L
*
1024L
*
1024L
;
ulong
net_read_timeout
=
NET_READ_TIMEOUT
;
ulong
net_write_timeout
=
NET_WRITE_TIMEOUT
;
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG \
| CLIENT_LOCAL_FILES | CLIENT_TRANSACTIONS \
| CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION)
#ifdef __WIN__
#define CONNECT_TIMEOUT 20
#else
#define CONNECT_TIMEOUT 0
#endif
#if defined(MSDOS) || defined(__WIN__)
/* socket_errno is defined in my_global.h for all platforms */
#define perror(A)
...
...
@@ -85,10 +72,6 @@ ulong net_write_timeout= NET_WRITE_TIMEOUT;
#define SOCKET_ERROR -1
#endif
/* __WIN__ */
const
char
*
sql_protocol_names_lib
[]
=
{
"TCP"
,
"SOCKET"
,
"PIPE"
,
"MEMORY"
,
NullS
};
TYPELIB
sql_protocol_typelib
=
{
array_elements
(
sql_protocol_names_lib
)
-
1
,
""
,
sql_protocol_names_lib
};
/*
If allowed through some configuration, then this needs to
be changed
...
...
@@ -101,7 +84,67 @@ sig_handler pipe_sig_handler(int sig);
static
ulong
mysql_sub_escape_string
(
CHARSET_INFO
*
charset_info
,
char
*
to
,
const
char
*
from
,
ulong
length
);
my_bool
stmt_close
(
MYSQL_STMT
*
stmt
,
my_bool
skip_list
);
static
my_bool
org_my_init_done
=
0
;
/*
Initialize the MySQL library
SYNOPSIS
mysql_once_init()
NOTES
Can't be static on NetWare
This function is called by mysql_init() and indirectly called
by mysql_real_query(), so one should never have to call this from an
outside program.
*/
static
my_bool
mysql_client_init
=
0
;
static
my_bool
org_my_init_done
=
0
;
void
mysql_once_init
(
void
)
{
if
(
!
mysql_client_init
)
{
mysql_client_init
=
1
;
org_my_init_done
=
my_init_done
;
my_init
();
/* Will init threads */
init_client_errs
();
if
(
!
mysql_port
)
{
mysql_port
=
MYSQL_PORT
;
#ifndef MSDOS
{
struct
servent
*
serv_ptr
;
char
*
env
;
if
((
serv_ptr
=
getservbyname
(
"mysql"
,
"tcp"
)))
mysql_port
=
(
uint
)
ntohs
((
ushort
)
serv_ptr
->
s_port
);
if
((
env
=
getenv
(
"MYSQL_TCP_PORT"
)))
mysql_port
=
(
uint
)
atoi
(
env
);
}
#endif
}
if
(
!
mysql_unix_port
)
{
char
*
env
;
#ifdef __WIN__
mysql_unix_port
=
(
char
*
)
MYSQL_NAMEDPIPE
;
#else
mysql_unix_port
=
(
char
*
)
MYSQL_UNIX_ADDR
;
#endif
if
((
env
=
getenv
(
"MYSQL_UNIX_PORT"
)))
mysql_unix_port
=
env
;
}
mysql_debug
(
NullS
);
#if defined(SIGPIPE) && !defined(THREAD) && !defined(__WIN__)
(
void
)
signal
(
SIGPIPE
,
SIG_IGN
);
#endif
}
#ifdef THREAD
else
my_thread_init
();
/* Init if new thread */
#endif
}
int
STDCALL
mysql_server_init
(
int
argc
__attribute__
((
unused
)),
char
**
argv
__attribute__
((
unused
)),
...
...
@@ -529,30 +572,6 @@ STDCALL mysql_rpl_query_type(const char* q, int len)
return
MYSQL_RPL_MASTER
;
/* By default, send to master */
}
/*
Fill in SSL part of MYSQL structure and set 'use_ssl' flag.
NB! Errors are not reported until you do mysql_real_connect.
*/
#define strdup_if_not_null(A) (A) == 0 ? 0 : my_strdup((A),MYF(MY_WME))
my_bool
STDCALL
mysql_ssl_set
(
MYSQL
*
mysql
__attribute__
((
unused
))
,
const
char
*
key
__attribute__
((
unused
)),
const
char
*
cert
__attribute__
((
unused
)),
const
char
*
ca
__attribute__
((
unused
)),
const
char
*
capath
__attribute__
((
unused
)),
const
char
*
cipher
__attribute__
((
unused
)))
{
#ifdef HAVE_OPENSSL
mysql
->
options
.
ssl_key
=
strdup_if_not_null
(
key
);
mysql
->
options
.
ssl_cert
=
strdup_if_not_null
(
cert
);
mysql
->
options
.
ssl_ca
=
strdup_if_not_null
(
ca
);
mysql
->
options
.
ssl_capath
=
strdup_if_not_null
(
capath
);
mysql
->
options
.
ssl_cipher
=
strdup_if_not_null
(
cipher
);
#endif
/* HAVE_OPENSSL */
return
0
;
}
/**************************************************************************
Connect to sql server
...
...
@@ -578,6 +597,7 @@ mysql_connect(MYSQL *mysql,const char *host,
}
#endif
/**************************************************************************
Change user and database
**************************************************************************/
...
...
@@ -836,56 +856,6 @@ STDCALL mysql_add_slave(MYSQL* mysql, const char* host,
return
0
;
}
/**************************************************************************
Alloc struct for use with unbuffered reads. Data is fetched by domand
when calling to mysql_fetch_row.
mysql_data_seek is a noop.
No other queries may be specified with the same MYSQL handle.
There shouldn't be much processing per row because mysql server shouldn't
have to wait for the client (and will not wait more than 30 sec/packet).
**************************************************************************/
MYSQL_RES
*
STDCALL
mysql_use_result
(
MYSQL
*
mysql
)
{
MYSQL_RES
*
result
;
DBUG_ENTER
(
"mysql_use_result"
);
mysql
=
mysql
->
last_used_con
;
if
(
!
mysql
->
fields
)
DBUG_RETURN
(
0
);
if
(
mysql
->
status
!=
MYSQL_STATUS_GET_RESULT
)
{
strmov
(
mysql
->
net
.
sqlstate
,
unknown_sqlstate
);
strmov
(
mysql
->
net
.
last_error
,
ER
(
mysql
->
net
.
last_errno
=
CR_COMMANDS_OUT_OF_SYNC
));
DBUG_RETURN
(
0
);
}
if
(
!
(
result
=
(
MYSQL_RES
*
)
my_malloc
(
sizeof
(
*
result
)
+
sizeof
(
ulong
)
*
mysql
->
field_count
,
MYF
(
MY_WME
|
MY_ZEROFILL
))))
DBUG_RETURN
(
0
);
result
->
lengths
=
(
ulong
*
)
(
result
+
1
);
if
(
!
(
result
->
row
=
(
MYSQL_ROW
)
my_malloc
(
sizeof
(
result
->
row
[
0
])
*
(
mysql
->
field_count
+
1
),
MYF
(
MY_WME
))))
{
/* Ptrs: to one row */
my_free
((
gptr
)
result
,
MYF
(
0
));
DBUG_RETURN
(
0
);
}
result
->
fields
=
mysql
->
fields
;
result
->
field_alloc
=
mysql
->
field_alloc
;
result
->
field_count
=
mysql
->
field_count
;
result
->
current_field
=
0
;
result
->
handle
=
mysql
;
result
->
current_row
=
0
;
mysql
->
fields
=
0
;
/* fields is now in result */
mysql
->
status
=
MYSQL_STATUS_USE_RESULT
;
DBUG_RETURN
(
result
);
/* Data is read to be fetched */
}
/**************************************************************************
Return next field of the query results
...
...
@@ -899,6 +869,13 @@ mysql_fetch_field(MYSQL_RES *result)
return
&
result
->
fields
[
result
->
current_field
++
];
}
/**************************************************************************
Get column lengths of the current row
If one uses mysql_use_result, res->lengths contains the length information,
else the lengths are calculated from the offset between pointers.
**************************************************************************/
ulong
*
STDCALL
mysql_fetch_lengths
(
MYSQL_RES
*
res
)
{
...
...
@@ -911,6 +888,23 @@ mysql_fetch_lengths(MYSQL_RES *res)
return
res
->
lengths
;
}
/**************************************************************************
Move to a specific row and column
**************************************************************************/
void
STDCALL
mysql_data_seek
(
MYSQL_RES
*
result
,
my_ulonglong
row
)
{
MYSQL_ROWS
*
tmp
=
0
;
DBUG_PRINT
(
"info"
,(
"mysql_data_seek(%ld)"
,(
long
)
row
));
if
(
result
->
data
)
for
(
tmp
=
result
->
data
->
data
;
row
--
&&
tmp
;
tmp
=
tmp
->
next
)
;
result
->
current_row
=
0
;
result
->
data_cursor
=
tmp
;
}
/*************************************************************************
put the row or field cursor one a position one got from mysql_row_tell()
This doesn't restore any data. The next mysql_fetch_row or
...
...
@@ -935,6 +929,7 @@ mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET field_offset)
return
return_value
;
}
/*****************************************************************************
List all databases
*****************************************************************************/
...
...
@@ -2444,7 +2439,7 @@ static void send_data_long(MYSQL_BIND *param, longlong value)
}
default:
{
char
tmp
[
12
];
char
tmp
[
22
];
/* Enough for longlong */
uint
length
=
(
uint
)(
longlong10_to_str
(
value
,(
char
*
)
tmp
,
10
)
-
tmp
);
ulong
copy_length
=
min
((
ulong
)
length
-
param
->
offset
,
param
->
buffer_length
);
memcpy
(
buffer
,
(
char
*
)
tmp
+
param
->
offset
,
copy_length
);
...
...
@@ -2492,7 +2487,7 @@ static void send_data_double(MYSQL_BIND *param, double value)
}
default:
{
char
tmp
[
12
];
char
tmp
[
12
8
];
uint
length
=
my_sprintf
(
tmp
,(
tmp
,
"%g"
,
value
));
ulong
copy_length
=
min
((
ulong
)
length
-
param
->
offset
,
param
->
buffer_length
);
memcpy
(
buffer
,
(
char
*
)
tmp
+
param
->
offset
,
copy_length
);
...
...
mysys/charset.c
View file @
1e62d607
...
...
@@ -368,6 +368,7 @@ static my_bool my_read_charset_file(const char *filename, myf myflags)
char
*
get_charsets_dir
(
char
*
buf
)
{
const
char
*
sharedir
=
SHAREDIR
;
char
*
res
;
DBUG_ENTER
(
"get_charsets_dir"
);
if
(
charsets_dir
!=
NULL
)
...
...
@@ -381,9 +382,9 @@ char *get_charsets_dir(char *buf)
strxmov
(
buf
,
DEFAULT_CHARSET_HOME
,
"/"
,
sharedir
,
"/"
,
CHARSET_DIR
,
NullS
);
}
convert_dirname
(
buf
,
buf
,
NullS
);
res
=
convert_dirname
(
buf
,
buf
,
NullS
);
DBUG_PRINT
(
"info"
,(
"charsets dir: '%s'"
,
buf
));
DBUG_RETURN
(
strend
(
buf
)
);
DBUG_RETURN
(
res
);
}
CHARSET_INFO
*
all_charsets
[
256
];
...
...
@@ -613,6 +614,9 @@ CHARSET_INFO *get_charset_by_csname(const char *cs_name,
{
CHARSET_INFO
*
cs
=
NULL
;
CHARSET_INFO
**
css
;
DBUG_ENTER
(
"get_charset_by_csname"
);
DBUG_PRINT
(
"enter"
,(
"name: '%s'"
,
cs_name
));
(
void
)
init_available_charsets
(
MYF
(
0
));
/* If it isn't initialized */
for
(
css
=
all_charsets
;
css
<
all_charsets
+
255
;
++
css
)
...
...
@@ -633,5 +637,5 @@ CHARSET_INFO *get_charset_by_csname(const char *cs_name,
my_error
(
EE_UNKNOWN_CHARSET
,
MYF
(
ME_BELL
),
cs_name
,
index_file
);
}
return
cs
;
DBUG_RETURN
(
cs
)
;
}
mysys/errors.c
View file @
1e62d607
...
...
@@ -82,7 +82,7 @@ void init_glob_errs()
EE
(
EE_OPEN_WARNING
)
=
"%d files and %d streams is left open
\n
"
;
EE
(
EE_DISK_FULL
)
=
"Disk is full writing '%s'. Waiting for someone to free space..."
;
EE
(
EE_CANT_MKDIR
)
=
"Can't create directory '%s' (Errcode: %d)"
;
EE
(
EE_UNKNOWN_CHARSET
)
=
"Character set is not a compiled character set and is not specified in the %s file"
;
EE
(
EE_UNKNOWN_CHARSET
)
=
"Character set
'%s'
is not a compiled character set and is not specified in the %s file"
;
EE
(
EE_OUT_OF_FILERESOURCES
)
=
"Out of resources when opening file '%s' (Errcode: %d)"
;
EE
(
EE_CANT_READLINK
)
=
"Can't read value for symlink '%s' (Error %d)"
;
EE
(
EE_CANT_SYMLINK
)
=
"Can't create symlink '%s' pointing at '%s' (Error %d)"
;
...
...
sql-common/client.c
View file @
1e62d607
/* Copyright (C) 2000
MySQL AB & MySQL Finland AB & TCX DataKonsult
AB
/* Copyright (C) 2000
-2003 MySQL
AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
...
...
@@ -37,13 +37,11 @@
#include <my_global.h>
#if defined(MYSQL_SERVER) || defined(HAVE_EXTERNAL_CLIENT)
#include "mysql.h"
#if !defined(MYSQL_SERVER) &&
defined(__WIN__) || defined(_WIN32) || defined(_WIN64
)
#if !defined(MYSQL_SERVER) &&
(defined(__WIN__) || defined(_WIN32) || defined(_WIN64)
)
#include <winsock.h>
#include <odbcinst.h>
#endif
#endif
/* !defined(MYSQL_SERVER) && (defined(__WIN__) ... */
#include <my_sys.h>
#include <mysys_err.h>
#include <m_string.h>
...
...
@@ -55,21 +53,19 @@
#include <assert.h>
#if defined(THREAD) && !defined(__WIN__)
#include <my_pthread.h>
/* because of signal() */
#endif
#endif
/* defined(THREAD) && !defined(__WIN__) */
#if defined(
OS2) && defined(MYSQL_SERVER)
#if defined(OS2) && defined(MYSQL_SERVER)
#undef ER
#define ER CER
#endif
#endif
/* defined( OS2) && defined(MYSQL_SERVER) */
#include <sys/stat.h>
#include <signal.h>
#include <time.h>
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#if !defined(MSDOS) && !defined(__WIN__)
#include <sys/socket.h>
#include <netinet/in.h>
...
...
@@ -96,16 +92,27 @@
#define SOCKET_ERROR -1
#endif
#ifdef __WIN__
#define CONNECT_TIMEOUT 20
#else
#define CONNECT_TIMEOUT 0
#endif
#include "client_settings.h"
#include <sql_common.h>
const
char
*
unknown_sqlstate
=
"HY0000"
;
uint
mysql_port
=
0
;
char
*
mysql_unix_port
=
0
;
const
char
*
unknown_sqlstate
=
"HY000"
;
const
char
*
not_error_sqlstate
=
"00000"
;
#ifdef MYSQL_CLIENT
extern
my_bool
stmt_close
(
MYSQL_STMT
*
stmt
,
my_bool
skip_list
)
;
#ifdef HAVE_SMEM
char
*
shared_memory_base_name
=
0
;
const
char
def_shared_memory_base_name
=
default_shared_memory_base_name
;
#endif
static
void
mysql_close_free_options
(
MYSQL
*
mysql
);
static
void
mysql_close_free
(
MYSQL
*
mysql
);
/****************************************************************************
A modified version of connect(). my_connect() allows you to specify
a timeout value, in seconds, that we should wait until we
...
...
@@ -293,6 +300,7 @@ HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host,
}
#endif
/*
Create new shared memory connection, return handler of connection
...
...
@@ -310,7 +318,8 @@ HANDLE create_shared_memory(MYSQL *mysql,NET *net, uint connect_timeout)
/*
event_connect_request is event object for start connection actions
event_connect_answer is event object for confirm, that server put data
handle_connect_file_map is file-mapping object, use for create shared memory
handle_connect_file_map is file-mapping object, use for create shared
memory
handle_connect_map is pointer on shared memory
handle_map is pointer on shared memory for client
event_server_wrote,
...
...
@@ -594,8 +603,6 @@ advanced_command(MYSQL *mysql, enum enum_server_command command,
mysql
->
info
=
0
;
mysql
->
affected_rows
=
~
(
my_ulonglong
)
0
;
net_clear
(
&
mysql
->
net
);
/* Clear receive buffer */
if
(
!
arg
)
arg
=
""
;
if
(
net_write_command
(
net
,(
uchar
)
command
,
header
,
header_length
,
arg
,
arg_length
))
...
...
@@ -640,7 +647,6 @@ void free_old_query(MYSQL *mysql)
DBUG_ENTER
(
"free_old_query"
);
if
(
mysql
->
fields
)
free_root
(
&
mysql
->
field_alloc
,
MYF
(
0
));
else
init_alloc_root
(
&
mysql
->
field_alloc
,
8192
,
0
);
/* Assume rowlength < 8192 */
mysql
->
fields
=
0
;
mysql
->
field_count
=
0
;
/* For API */
...
...
@@ -676,6 +682,7 @@ void end_server(MYSQL *mysql)
DBUG_VOID_RETURN
;
}
void
STDCALL
mysql_free_result
(
MYSQL_RES
*
result
)
{
...
...
@@ -726,6 +733,11 @@ static const char *default_options[]=
static
TYPELIB
option_types
=
{
array_elements
(
default_options
)
-
1
,
"options"
,
default_options
};
const
char
*
sql_protocol_names_lib
[]
=
{
"TCP"
,
"SOCKET"
,
"PIPE"
,
"MEMORY"
,
NullS
};
TYPELIB
sql_protocol_typelib
=
{
array_elements
(
sql_protocol_names_lib
)
-
1
,
""
,
sql_protocol_names_lib
};
static
int
add_init_command
(
struct
st_mysql_options
*
options
,
const
char
*
cmd
)
{
char
*
tmp
;
...
...
@@ -832,8 +844,8 @@ static void mysql_read_default_options(struct st_mysql_options *options,
options
->
db
=
my_strdup
(
opt_arg
,
MYF
(
MY_WME
));
}
break
;
#ifdef MYSQL_CLIENT
case
11
:
/* debug */
#ifdef MYSQL_CLIENT
mysql_debug
(
opt_arg
?
opt_arg
:
"d:t:o,/tmp/client.trace"
);
break
;
#endif
...
...
@@ -885,26 +897,30 @@ static void mysql_read_default_options(struct st_mysql_options *options,
options
->
client_flag
&=
CLIENT_LOCAL_FILES
;
break
;
case
23
:
/* replication probe */
#ifndef TO_BE_DELETED
options
->
rpl_probe
=
1
;
#endif
break
;
case
24
:
/* enable-reads-from-master */
options
->
no_master_reads
=
0
;
break
;
case
25
:
/* repl-parse-query */
#ifndef TO_BE_DELETED
options
->
rpl_parse
=
1
;
#endif
break
;
case
27
:
options
->
max_allowed_packet
=
atoi
(
opt_arg
);
break
;
#ifdef MYSQL_CLIENT
case
28
:
/* protocol */
if
((
options
->
protocol
=
find_type
(
opt_arg
,
&
sql_protocol_typelib
,
0
))
==
~
(
ulong
)
0
)
if
((
options
->
protocol
=
find_type
(
opt_arg
,
&
sql_protocol_typelib
,
0
))
==
~
(
ulong
)
0
)
{
fprintf
(
stderr
,
"Unknown option to protocol: %s
\n
"
,
opt_arg
);
exit
(
1
);
}
break
;
#endif
case
29
:
/* shared_memory_base_name */
#ifdef HAVE_SMEM
if
(
options
->
shared_memory_base_name
!=
def_shared_memory_base_name
)
...
...
@@ -928,6 +944,7 @@ static void mysql_read_default_options(struct st_mysql_options *options,
DBUG_VOID_RETURN
;
}
/**************************************************************************
Get column lengths of the current row
If one uses mysql_use_result, res->lengths contains the length information,
...
...
@@ -956,51 +973,6 @@ void fetch_lengths(ulong *to, MYSQL_ROW column, uint field_count)
}
static
inline
void
unpack_fields_40
(
MYSQL_ROWS
*
row
,
MYSQL_FIELD
*
field
,
MEM_ROOT
*
alloc
,
ulong
*
lengths
,
uint
n_lengths
,
my_bool
default_value
,
my_bool
long_flag_protocol
)
{
DBUG_ENTER
(
"unpack_fields_40"
);
for
(;
row
;
row
=
row
->
next
,
field
++
)
{
fetch_lengths
(
lengths
,
row
->
data
,
n_lengths
);
field
->
org_table
=
field
->
table
=
strdup_root
(
alloc
,(
char
*
)
row
->
data
[
0
]);
field
->
name
=
strdup_root
(
alloc
,(
char
*
)
row
->
data
[
1
]);
field
->
length
=
(
uint
)
uint3korr
(
row
->
data
[
2
]);
field
->
type
=
(
enum
enum_field_types
)
(
uchar
)
row
->
data
[
3
][
0
];
field
->
catalog
=
(
char
*
)
""
;
field
->
db
=
(
char
*
)
""
;
field
->
catalog_length
=
0
;
field
->
db_length
=
0
;
field
->
org_table_length
=
field
->
table_length
=
lengths
[
0
];
field
->
name_length
=
lengths
[
1
];
if
(
long_flag_protocol
)
{
field
->
flags
=
uint2korr
(
row
->
data
[
4
]);
field
->
decimals
=
(
uint
)
(
uchar
)
row
->
data
[
4
][
2
];
}
else
{
field
->
flags
=
(
uint
)
(
uchar
)
row
->
data
[
4
][
0
];
field
->
decimals
=
(
uint
)
(
uchar
)
row
->
data
[
4
][
1
];
}
if
(
INTERNAL_NUM_FIELD
(
field
))
field
->
flags
|=
NUM_FLAG
;
if
(
default_value
&&
row
->
data
[
5
])
{
field
->
def
=
strdup_root
(
alloc
,(
char
*
)
row
->
data
[
5
]);
field
->
def_length
=
lengths
[
5
];
}
else
field
->
def
=
0
;
field
->
max_length
=
0
;
}
}
/***************************************************************************
Change field rows to field structs
***************************************************************************/
...
...
@@ -1009,25 +981,19 @@ MYSQL_FIELD *
unpack_fields
(
MYSQL_DATA
*
data
,
MEM_ROOT
*
alloc
,
uint
fields
,
my_bool
default_value
,
uint
server_capabilities
)
{
#ifdef MYSQL_CLIENT
MYSQL_ROWS
*
row
;
#endif
MYSQL_FIELD
*
field
,
*
result
;
ulong
lengths
[
9
];
/* Max of fields */
DBUG_ENTER
(
"unpack_fields"
);
field
=
result
=
(
MYSQL_FIELD
*
)
alloc_root
(
alloc
,
(
uint
)
sizeof
(
MYSQL_FIELD
)
*
fields
);
field
=
result
=
(
MYSQL_FIELD
*
)
alloc_root
(
alloc
,
(
uint
)
sizeof
(
*
field
)
*
fields
);
if
(
!
result
)
{
free_rows
(
data
);
/* Free old data */
DBUG_RETURN
(
0
);
}
bzero
((
char
*
)
field
,
(
uint
)
sizeof
(
MYSQL_FIELD
)
*
fields
);
#ifdef MYSQL_SERVER
unpack_fields_40
(
data
->
data
,
field
,
alloc
,
lengths
,
default_value
?
6
:
5
,
default_value
,
(
my_bool
)(
server_capabilities
&
CLIENT_LONG_FLAG
));
#else
if
(
server_capabilities
&
CLIENT_PROTOCOL_41
)
{
/* server is 4.1, and returns the new field result format */
...
...
@@ -1071,10 +1037,46 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
}
#ifndef DELETE_SUPPORT_OF_4_0_PROTOCOL
else
unpack_fields_40
(
data
->
data
,
field
,
alloc
,
lengths
,
default_value
?
6
:
5
,
default_value
,
(
my_bool
)(
server_capabilities
&
CLIENT_LONG_FLAG
));
{
/* old protocol, for backward compatibility */
for
(
row
=
data
->
data
;
row
;
row
=
row
->
next
,
field
++
)
{
fetch_lengths
(
&
lengths
[
0
],
row
->
data
,
default_value
?
6
:
5
);
field
->
org_table
=
field
->
table
=
strdup_root
(
alloc
,(
char
*
)
row
->
data
[
0
]);
field
->
name
=
strdup_root
(
alloc
,(
char
*
)
row
->
data
[
1
]);
field
->
length
=
(
uint
)
uint3korr
(
row
->
data
[
2
]);
field
->
type
=
(
enum
enum_field_types
)
(
uchar
)
row
->
data
[
3
][
0
];
field
->
catalog
=
(
char
*
)
""
;
field
->
db
=
(
char
*
)
""
;
field
->
catalog_length
=
0
;
field
->
db_length
=
0
;
field
->
org_table_length
=
field
->
table_length
=
lengths
[
0
];
field
->
name_length
=
lengths
[
1
];
if
(
server_capabilities
&
CLIENT_LONG_FLAG
)
{
field
->
flags
=
uint2korr
(
row
->
data
[
4
]);
field
->
decimals
=
(
uint
)
(
uchar
)
row
->
data
[
4
][
2
];
}
else
{
field
->
flags
=
(
uint
)
(
uchar
)
row
->
data
[
4
][
0
];
field
->
decimals
=
(
uint
)
(
uchar
)
row
->
data
[
4
][
1
];
}
if
(
INTERNAL_NUM_FIELD
(
field
))
field
->
flags
|=
NUM_FLAG
;
if
(
default_value
&&
row
->
data
[
5
])
{
field
->
def
=
strdup_root
(
alloc
,(
char
*
)
row
->
data
[
5
]);
field
->
def_length
=
lengths
[
5
];
}
else
field
->
def
=
0
;
field
->
max_length
=
0
;
}
}
#endif
/* DELETE_SUPPORT_OF_4_0_PROTOCOL */
#endif
/*MYSQL_SERVER*/
free_rows
(
data
);
/* Free old data */
DBUG_RETURN
(
result
);
}
...
...
@@ -1172,13 +1174,11 @@ MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
}
}
*
prev_ptr
=
0
;
/* last pointer is null */
#ifndef MYSQL_SERVER
if
(
pkt_len
>
1
)
/* MySQL 4.1 protocol */
{
mysql
->
warning_count
=
uint2korr
(
cp
+
1
);
DBUG_PRINT
(
"info"
,(
"warning_count: %ld"
,
mysql
->
warning_count
));
}
#endif
DBUG_PRINT
(
"exit"
,(
"Got %d rows"
,
result
->
rows
));
DBUG_RETURN
(
result
);
}
...
...
@@ -1201,10 +1201,8 @@ read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths)
return
-
1
;
if
(
pkt_len
<=
8
&&
net
->
read_pos
[
0
]
==
254
)
{
#ifndef MYSQL_SERVER
if
(
pkt_len
>
1
)
/* MySQL 4.1 protocol */
mysql
->
warning_count
=
uint2korr
(
net
->
read_pos
+
1
);
#endif
return
1
;
/* End of data */
}
prev_pos
=
0
;
/* allowed to write at packet[-1] */
...
...
@@ -1256,102 +1254,84 @@ mysql_init(MYSQL *mysql)
}
else
bzero
((
char
*
)
(
mysql
),
sizeof
(
*
(
mysql
)));
#ifndef MYSQL_SERVER
mysql
->
options
.
connect_timeout
=
CONNECT_TIMEOUT
;
mysql
->
last_used_con
=
mysql
->
next_slave
=
mysql
->
master
=
mysql
;
mysql
->
options
.
connect_timeout
=
CONNECT_TIMEOUT
;
mysql
->
last_used_con
=
mysql
->
next_slave
=
mysql
->
master
=
mysql
;
/*
By default, we are a replication pivot. The caller must reset it
after we return if this is not the case.
*/
#ifndef TO_BE_DELETED
mysql
->
rpl_pivot
=
1
;
#if defined(SIGPIPE) && defined(THREAD) && !defined(__WIN__)
#endif
#if defined(SIGPIPE) && defined(THREAD) && !defined(__WIN__) && !defined(MYSQL_SERVER)
if
(
!
((
mysql
)
->
client_flag
&
CLIENT_IGNORE_SIGPIPE
))
(
void
)
signal
(
SIGPIPE
,
pipe_sig_handler
);
#endif
/*
/*
Only enable LOAD DATA INFILE by default if configured with
--enable-local-infile
*/
#if
def ENABLED_LOCAL_INFILE
*/
#if
defined(ENABLED_LOCAL_INFILE) && !defined(MYSQL_SERVER)
mysql
->
options
.
client_flag
|=
CLIENT_LOCAL_FILES
;
#endif
#ifdef HAVE_SMEM
mysql
->
options
.
shared_memory_base_name
=
(
char
*
)
def_shared_memory_base_name
;
#endif
#else
/*MYSQL_SERVER*/
#ifdef __WIN__
mysql
->
options
.
connect_timeout
=
20
;
mysql
->
options
.
shared_memory_base_name
=
(
char
*
)
def_shared_memory_base_name
;
#endif
#endif
/*MYSQL_SERVER*/
return
mysql
;
}
/*
Initialize the MySQL library
SYNOPSIS
mysql_once_init()
NOTES
Can't be static on NetWare
This function is called by mysql_init() and indirectly called
by mysql_query(), so one should never have to call this from an
outside program.
Fill in SSL part of MYSQL structure and set 'use_ssl' flag.
NB! Errors are not reported until you do mysql_real_connect.
*/
void
mysql_once_init
(
void
)
#define strdup_if_not_null(A) (A) == 0 ? 0 : my_strdup((A),MYF(MY_WME))
my_bool
STDCALL
mysql_ssl_set
(
MYSQL
*
mysql
__attribute__
((
unused
))
,
const
char
*
key
__attribute__
((
unused
)),
const
char
*
cert
__attribute__
((
unused
)),
const
char
*
ca
__attribute__
((
unused
)),
const
char
*
capath
__attribute__
((
unused
)),
const
char
*
cipher
__attribute__
((
unused
)))
{
#ifndef MYSQL_SERVER
#ifdef HAVE_OPENSSL
mysql
->
options
.
ssl_key
=
strdup_if_not_null
(
key
);
mysql
->
options
.
ssl_cert
=
strdup_if_not_null
(
cert
);
mysql
->
options
.
ssl_ca
=
strdup_if_not_null
(
ca
);
mysql
->
options
.
ssl_capath
=
strdup_if_not_null
(
capath
);
mysql
->
options
.
ssl_cipher
=
strdup_if_not_null
(
cipher
);
#endif
/* HAVE_OPENSSL */
return
0
;
}
if
(
!
mysql_client_init
)
{
mysql_client_init
=
1
;
org_my_init_done
=
my_init_done
;
my_init
();
/* Will init threads */
init_client_errs
();
if
(
!
mysql_port
)
{
mysql_port
=
MYSQL_PORT
;
#ifndef MSDOS
{
struct
servent
*
serv_ptr
;
char
*
env
;
if
((
serv_ptr
=
getservbyname
(
"mysql"
,
"tcp"
)))
mysql_port
=
(
uint
)
ntohs
((
ushort
)
serv_ptr
->
s_port
);
if
((
env
=
getenv
(
"MYSQL_TCP_PORT"
)))
mysql_port
=
(
uint
)
atoi
(
env
);
}
#endif
}
if
(
!
mysql_unix_port
)
{
char
*
env
;
#ifdef __WIN__
mysql_unix_port
=
(
char
*
)
MYSQL_NAMEDPIPE
;
#else
mysql_unix_port
=
(
char
*
)
MYSQL_UNIX_ADDR
;
#endif
if
((
env
=
getenv
(
"MYSQL_UNIX_PORT"
)))
mysql_unix_port
=
env
;
}
mysql_debug
(
NullS
);
#if defined(SIGPIPE) && !defined(THREAD) && !defined(__WIN__)
(
void
)
signal
(
SIGPIPE
,
SIG_IGN
);
#endif
}
#ifdef THREAD
else
my_thread_init
();
/* Init if new thread */
#endif
#else
/*MYSQL_SERVER*/
init_client_errs
();
#endif
/*MYSQL_SERVER*/
/*
Free strings in the SSL structure and clear 'use_ssl' flag.
NB! Errors are not reported until you do mysql_real_connect.
*/
#ifdef HAVE_OPENSSL
static
void
mysql_ssl_free
(
MYSQL
*
mysql
__attribute__
((
unused
)))
{
my_free
(
mysql
->
options
.
ssl_key
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
ssl_cert
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
ssl_ca
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
ssl_capath
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
ssl_cipher
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
connector_fd
,
MYF
(
MY_ALLOW_ZERO_PTR
));
mysql
->
options
.
ssl_key
=
0
;
mysql
->
options
.
ssl_cert
=
0
;
mysql
->
options
.
ssl_ca
=
0
;
mysql
->
options
.
ssl_capath
=
0
;
mysql
->
options
.
ssl_cipher
=
0
;
mysql
->
options
.
use_ssl
=
FALSE
;
mysql
->
connector_fd
=
0
;
}
#endif
/* HAVE_OPENSSL */
/*
...
...
@@ -1423,6 +1403,7 @@ error:
return
1
;
}
/*
Note that the mysql argument must be initialized with mysql_init()
before calling mysql_real_connect !
...
...
@@ -1433,12 +1414,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
const
char
*
passwd
,
const
char
*
db
,
uint
port
,
const
char
*
unix_socket
,
ulong
client_flag
)
{
#ifdef MYSQL_CLIENT
char
*
charset_name
;
char
charset_name_buff
[
16
];
#endif
char
buff
[
NAME_LEN
+
USERNAME_LENGTH
+
100
];
char
*
end
,
*
host_info
;
char
buff
[
NAME_LEN
+
USERNAME_LENGTH
+
100
],
charset_name_buff
[
16
];
char
*
end
,
*
host_info
,
*
charset_name
;
my_socket
sock
;
uint32
ip_addr
;
struct
sockaddr_in
sock_addr
;
...
...
@@ -1447,16 +1424,14 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
#ifdef MYSQL_SERVER
thr_alarm_t
alarmed
;
ALARM
alarm_buff
;
ulong
max_allowed_packet
;
#endif
#ifdef __WIN__
HANDLE
hPipe
=
INVALID_HANDLE_VALUE
;
#endif
#ifdef HAVE_SYS_UN_H
struct
sockaddr_un
UNIXaddr
;
#endif
init_sigpipe_variables
init_sigpipe_variables
;
DBUG_ENTER
(
"mysql_real_connect"
);
LINT_INIT
(
host_info
);
...
...
@@ -1469,9 +1444,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
set_sigpipe
(
mysql
);
net
->
vio
=
0
;
/* If something goes wrong */
mysql
->
client_flag
=
0
;
/* For handshake */
#ifdef MYSQL_SERVER
mysql
->
charset
=
default_charset_info
;
/* Set character set */
#endif
/* use default options */
if
(
mysql
->
options
.
my_cnf_file
||
mysql
->
options
.
my_cnf_group
)
...
...
@@ -1493,7 +1465,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if
(
!
passwd
)
{
passwd
=
mysql
->
options
.
password
;
#if
ndef DONT_USE_MYSQL_PWD
#if
!defined(DONT_USE_MYSQL_PWD) && !defined(MYSQL_SERVER)
if
(
!
passwd
)
passwd
=
getenv
(
"MYSQL_PWD"
);
/* get it from environment */
#endif
...
...
@@ -1511,7 +1483,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
/*
Grab a socket and connect it to the server
*/
#if
def HAVE_SMEM
#if
defined(HAVE_SMEM)
if
((
!
mysql
->
options
.
protocol
||
mysql
->
options
.
protocol
==
MYSQL_PROTOCOL_MEMORY
)
&&
(
!
host
||
!
strcmp
(
host
,
LOCAL_HOST
)))
...
...
@@ -1537,11 +1509,12 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
host
=
mysql
->
options
.
shared_memory_base_name
;
host_info
=
(
char
*
)
ER
(
CR_SHARED_MEMORY_CONNECTION
);
}
}
else
}
#endif
/* HAVE_SMEM */
#if defined(HAVE_SYS_UN_H)
if
((
!
mysql
->
options
.
protocol
||
mysql
->
options
.
protocol
==
MYSQL_PROTOCOL_SOCKET
)
&&
if
(
!
net
->
vio
&&
(
!
mysql
->
options
.
protocol
||
mysql
->
options
.
protocol
==
MYSQL_PROTOCOL_SOCKET
)
&&
(
unix_socket
||
mysql_unix_port
)
&&
(
!
host
||
!
strcmp
(
host
,
LOCAL_HOST
)))
{
...
...
@@ -1571,19 +1544,13 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
sprintf
(
net
->
last_error
,
ER
(
net
->
last_errno
),
unix_socket
,
socket_errno
);
goto
error
;
}
#ifdef MYSQL_CLIENT
else
mysql
->
options
.
protocol
=
MYSQL_PROTOCOL_SOCKET
;
#endif
}
else
#elif defined(__WIN__)
{
if
((
!
mysql
->
options
.
protocol
||
mysql
->
options
.
protocol
==
MYSQL_PROTOCOL_PIPE
)
&&
((
unix_socket
||
!
host
&&
is_NT
()
||
host
&&
!
strcmp
(
host
,
LOCAL_HOST_NAMEDPIPE
)
||!
have_tcpip
))
&&
(
!
net
->
vio
))
if
(
!
net
->
vio
&&
(
mysql
->
options
.
protocol
==
MYSQL_PROTOCOL_PIPE
||
(
host
&&
!
strcmp
(
host
,
LOCAL_HOST_NAMEDPIPE
))
||
(
!
have_tcpip
&&
(
unix_socket
||
!
host
&&
is_NT
()))))
{
sock
=
0
;
if
((
hPipe
=
create_named_pipe
(
net
,
mysql
->
options
.
connect_timeout
,
...
...
@@ -1608,15 +1575,10 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
unix_socket
);
}
}
}
#ifdef MYSQL_SERVER
if
(
hPipe
==
INVALID_HANDLE_VALUE
)
#endif
#endif
#ifdef MYSQL_CLIENT
if
((
!
mysql
->
options
.
protocol
||
mysql
->
options
.
protocol
==
MYSQL_PROTOCOL_TCP
)
&&
(
!
net
->
vio
))
#endif
if
(
!
net
->
vio
&&
(
!
mysql
->
options
.
protocol
||
mysql
->
options
.
protocol
==
MYSQL_PROTOCOL_TCP
))
{
unix_socket
=
0
;
/* This is not used */
if
(
!
port
)
...
...
@@ -1629,11 +1591,11 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
thr_alarm_init
(
&
alarmed
);
thr_alarm
(
&
alarmed
,
mysql
->
options
.
connect_timeout
,
&
alarm_buff
);
#endif
/* _WIN64 ; Assume that the (int) range is enough for socket() */
sock
=
(
my_socket
)
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
#ifdef MYSQL_SERVER
thr_end_alarm
(
&
alarmed
);
#endif
/* _WIN64 ; Assume that the (int) range is enough for socket() */
if
(
sock
==
SOCKET_ERROR
)
{
net
->
last_errno
=
CR_IPSOCK_ERROR
;
...
...
@@ -1683,17 +1645,16 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
goto
error
;
}
}
#ifdef MYSQL_CLIENT
else
if
(
!
net
->
vio
)
if
(
!
net
->
vio
)
{
DBUG_PRINT
(
"error"
,(
"Unknow protocol %d "
,
mysql
->
options
.
protocol
));
net
->
last_errno
=
CR_CONN_UNKNOW_PROTOCOL
;
strmov
(
net
->
sqlstate
,
unknown_sqlstate
);
sprintf
(
net
->
last_error
,
ER
(
CR_CONN_UNKNOW_PROTOCOL
));
net
->
last_errno
=
CR_CONN_UNKNOW_PROTOCOL
;
strmov
(
net
->
last_error
,
ER
(
CR_CONN_UNKNOW_PROTOCOL
));
goto
error
;
}
#endif
/*MYSQL_CLIENT*/
if
(
!
net
->
vio
||
my_net_init
(
net
,
net
->
vio
))
if
(
my_net_init
(
net
,
net
->
vio
))
{
vio_delete
(
net
->
vio
);
net
->
vio
=
0
;
...
...
@@ -1703,9 +1664,14 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
goto
error
;
}
vio_keepalive
(
net
->
vio
,
TRUE
);
#ifdef MYSQL_SERVER
net
->
read_timeout
=
slave_net_timeout
;
#endif
/* Override local client variables */
if
(
mysql
->
options
.
read_timeout
)
net
->
read_timeout
=
mysql
->
options
.
read_timeout
;
if
(
mysql
->
options
.
write_timeout
)
net
->
write_timeout
=
mysql
->
options
.
write_timeout
;
if
(
mysql
->
options
.
max_allowed_packet
)
net
->
max_packet_size
=
mysql
->
options
.
max_allowed_packet
;
/* Get version info */
mysql
->
protocol_version
=
PROTOCOL_VERSION
;
/* Assume this */
if
(
mysql
->
options
.
connect_timeout
&&
...
...
@@ -1725,9 +1691,9 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
DBUG_DUMP
(
"packet"
,(
char
*
)
net
->
read_pos
,
10
);
DBUG_PRINT
(
"info"
,(
"mysql protocol version %d, server=%d"
,
PROTOCOL_VERSION
,
mysql
->
protocol_version
));
if
(
mysql
->
protocol_version
!=
PROTOCOL_VERSION
&&
mysql
->
protocol_version
!=
PROTOCOL_VERSION
-
1
)
if
(
mysql
->
protocol_version
!=
PROTOCOL_VERSION
)
{
strmov
(
net
->
sqlstate
,
unknown_sqlstate
);
net
->
last_errno
=
CR_VERSION_ERROR
;
sprintf
(
net
->
last_error
,
ER
(
CR_VERSION_ERROR
),
mysql
->
protocol_version
,
PROTOCOL_VERSION
);
...
...
@@ -1747,7 +1713,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
mysql
->
server_status
=
uint2korr
(
end
+
3
);
}
#ifdef MYSQL_CLIENT
/* Set character set */
if
((
charset_name
=
mysql
->
options
.
charset_name
))
{
...
...
@@ -1762,7 +1727,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
else
if
(
mysql
->
server_language
)
{
charset_name
=
charset_name_buff
;
sprintf
(
charset_name
,
"%d"
,
mysql
->
server_language
);
/* In case of errors */
/* Save name in case of errors */
int10_to_str
(
mysql
->
server_language
,
charset_name
,
10
);
if
(
!
(
mysql
->
charset
=
get_charset
((
uint8
)
mysql
->
server_language
,
MYF
(
0
))))
mysql
->
charset
=
default_charset_info
;
/* shouldn't be fatal */
...
...
@@ -1775,20 +1741,21 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
net
->
last_errno
=
CR_CANT_READ_CHARSET
;
strmov
(
net
->
sqlstate
,
unknown_sqlstate
);
if
(
mysql
->
options
.
charset_dir
)
sprintf
(
net
->
last_error
,
ER
(
net
->
last_errno
),
my_snprintf
(
net
->
last_error
,
sizeof
(
net
->
last_error
)
-
1
,
ER
(
net
->
last_errno
),
charset_name
?
charset_name
:
"unknown"
,
mysql
->
options
.
charset_dir
);
else
{
char
cs_dir_name
[
FN_REFLEN
];
get_charsets_dir
(
cs_dir_name
);
sprintf
(
net
->
last_error
,
ER
(
net
->
last_errno
),
my_snprintf
(
net
->
last_error
,
sizeof
(
net
->
last_error
)
-
1
,
ER
(
net
->
last_errno
),
charset_name
?
charset_name
:
"unknown"
,
cs_dir_name
);
}
goto
error
;
}
#endif
/*MYSQL_CLIENT*/
/* Save connection information */
if
(
!
user
)
user
=
""
;
...
...
@@ -1834,7 +1801,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if
(
db
)
client_flag
|=
CLIENT_CONNECT_WITH_DB
;
#ifdef MYSQL_CLIENT
/* Remove options that server doesn't support */
client_flag
=
((
client_flag
&
~
(
CLIENT_COMPRESS
|
CLIENT_SSL
|
CLIENT_PROTOCOL_41
))
|
...
...
@@ -1842,11 +1808,12 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
#ifndef HAVE_COMPRESS
client_flag
&=
~
CLIENT_COMPRESS
;
#endif
if
(
client_flag
&
CLIENT_PROTOCOL_41
)
{
/* 4.1 server and 4.1 client has a 32 byte option flag */
int4store
(
buff
,
client_flag
);
int4store
(
buff
+
4
,
max_allowed_packet
);
int4store
(
buff
+
4
,
net
->
max_packet_size
);
buff
[
8
]
=
mysql
->
charset
->
number
;
bzero
(
buff
+
9
,
32
-
9
);
end
=
buff
+
32
;
...
...
@@ -1854,46 +1821,10 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
else
{
int2store
(
buff
,
client_flag
);
int3store
(
buff
+
2
,
max_allowed_packet
);
int3store
(
buff
+
2
,
net
->
max_packet_size
);
end
=
buff
+
5
;
}
mysql
->
client_flag
=
client_flag
;
#endif
/*MYSQL_CLIENT*/
#ifdef MYSQL_SERVER
#ifdef HAVE_COMPRESS
if
((
mysql
->
server_capabilities
&
CLIENT_COMPRESS
)
&&
(
mysql
->
options
.
compress
||
(
client_flag
&
CLIENT_COMPRESS
)))
client_flag
|=
CLIENT_COMPRESS
;
/* We will use compression */
else
#endif
client_flag
&=
~
CLIENT_COMPRESS
;
#endif
/*MYSQL_SERVER*/
#ifdef MYSQL_SERVER
#ifdef HAVE_OPENSSL
if
((
mysql
->
server_capabilities
&
CLIENT_SSL
)
&&
(
mysql
->
options
.
use_ssl
||
(
client_flag
&
CLIENT_SSL
)))
{
DBUG_PRINT
(
"info"
,
(
"Changing IO layer to SSL"
));
client_flag
|=
CLIENT_SSL
;
}
else
{
if
(
client_flag
&
CLIENT_SSL
)
{
DBUG_PRINT
(
"info"
,
(
"Leaving IO layer intact because server doesn't support SSL"
));
}
client_flag
&=
~
CLIENT_SSL
;
}
#endif
/* HAVE_OPENSSL */
max_allowed_packet
=
mysql
->
net
.
max_packet_size
;
int2store
(
buff
,
client_flag
);
int3store
(
buff
+
2
,
max_allowed_packet
);
end
=
buff
+
5
;
mysql
->
client_flag
=
client_flag
;
#endif
/*MYSQL_SERVER*/
#ifdef HAVE_OPENSSL
/*
...
...
@@ -1902,9 +1833,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
*/
if
(
client_flag
&
CLIENT_SSL
)
{
#ifdef MYSQL_CLIENT
struct
st_mysql_options
*
options
=
&
mysql
->
options
;
#endif
if
(
my_net_write
(
net
,
buff
,(
uint
)
(
end
-
buff
))
||
net_flush
(
net
))
{
strmov
(
net
->
sqlstate
,
unknown_sqlstate
);
...
...
@@ -1913,7 +1842,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
goto
error
;
}
/* Do the SSL layering. */
#ifdef MYSQL_CLIENT
if
(
!
(
mysql
->
connector_fd
=
(
gptr
)
new_VioSSLConnectorFd
(
options
->
ssl_key
,
options
->
ssl_cert
,
...
...
@@ -1926,7 +1854,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
strmov
(
net
->
last_error
,
ER
(
net
->
last_errno
));
goto
error
;
}
#endif
/*MYSQL_CLIENT*/
DBUG_PRINT
(
"info"
,
(
"IO layer change in progress..."
));
if
(
sslconnect
((
struct
st_VioSSLConnectorFd
*
)(
mysql
->
connector_fd
),
mysql
->
net
.
vio
,
(
long
)
(
mysql
->
options
.
connect_timeout
)))
...
...
@@ -1947,18 +1874,11 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if
(
user
&&
user
[
0
])
strmake
(
end
,
user
,
32
);
/* Max user name */
else
#ifdef MYSQL_SERVER
{
user
=
getenv
(
"USER"
);
if
(
!
user
)
user
=
"mysql"
;
strmov
((
char
*
)
end
,
user
);
}
#else
read_user_name
((
char
*
)
end
);
#endif
/*MYSQL_SERVER*/
/* We have to handle different version of handshake here */
#if
defined(_CUSTOMCONFIG_) && defined(MYSQL_CLIENT)
#include "_cust_libmysql.h"
;
#if
def _CUSTOMCONFIG_
#include "_cust_libmysql.h"
#endif
DBUG_PRINT
(
"info"
,(
"user: %s"
,
end
));
/*
...
...
@@ -2012,9 +1932,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if
(
client_flag
&
CLIENT_COMPRESS
)
/* We will use compression */
net
->
compress
=
1
;
#ifdef MYSQL_CLIENT
if
(
mysql
->
options
.
max_allowed_packet
)
net
->
max_packet_size
=
mysql
->
options
.
max_allowed_packet
;
if
(
db
&&
mysql_select_db
(
mysql
,
db
))
goto
error
;
...
...
@@ -2030,7 +1947,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
for
(;
ptr
<
end
;
ptr
++
)
{
MYSQL_RES
*
res
;
if
(
mysql_
query
(
mysql
,
*
ptr
))
if
(
mysql_
real_query
(
mysql
,
*
ptr
,
strlen
(
*
ptr
)
))
goto
error
;
if
(
mysql
->
fields
)
{
...
...
@@ -2039,13 +1956,13 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
mysql_free_result
(
res
);
}
}
mysql
->
reconnect
=
reconnect
;
}
#ifndef TO_BE_DELETED
if
(
mysql
->
options
.
rpl_probe
&&
mysql_rpl_probe
(
mysql
))
goto
error
;
#endif
/*MYSQL_CLIENT*/
#endif
DBUG_PRINT
(
"exit"
,(
"Mysql handler: %lx"
,
mysql
));
reset_sigpipe
(
mysql
);
...
...
@@ -2057,37 +1974,35 @@ error:
net
->
last_errno
,
net
->
sqlstate
,
net
->
last_error
));
{
/* Free alloced memory */
my_bool
free_me
=
mysql
->
free_me
;
end_server
(
mysql
);
mysql
->
free_me
=
0
;
mysql_close
(
mysql
);
mysql
->
free_me
=
free_me
;
mysql
_close_free
(
mysql
)
;
if
(
!
(
client_flag
&
CLIENT_REMEMBER_OPTIONS
))
mysql_close_free_options
(
mysql
)
;
}
DBUG_RETURN
(
0
);
}
/* needed when we move MYSQL structure to a different address */
#ifndef TO_BE_DELETED
static
void
mysql_fix_pointers
(
MYSQL
*
mysql
,
MYSQL
*
old_mysql
)
{
MYSQL
*
tmp
,
*
tmp_prev
;
if
(
mysql
->
master
==
old_mysql
)
mysql
->
master
=
mysql
;
mysql
->
master
=
mysql
;
if
(
mysql
->
last_used_con
==
old_mysql
)
mysql
->
last_used_con
=
mysql
;
mysql
->
last_used_con
=
mysql
;
if
(
mysql
->
last_used_slave
==
old_mysql
)
mysql
->
last_used_slave
=
mysql
;
#ifdef MYSQL_CLIENT
/*should work in MYSQL_SERVER also, but doesn't */
{
MYSQL
*
tmp
,
*
tmp_prev
;
mysql
->
last_used_slave
=
mysql
;
for
(
tmp_prev
=
mysql
,
tmp
=
mysql
->
next_slave
;
tmp
!=
old_mysql
;
tmp
=
tmp
->
next_slave
)
{
tmp_prev
=
tmp
;
}
tmp_prev
->
next_slave
=
mysql
;
tmp_prev
=
tmp
;
}
#endif
/*MYSQL_CLIENT*/
tmp_prev
->
next_slave
=
mysql
;
}
#endif
my_bool
mysql_reconnect
(
MYSQL
*
mysql
)
...
...
@@ -2111,11 +2026,11 @@ my_bool mysql_reconnect(MYSQL *mysql)
tmp_mysql
.
rpl_pivot
=
mysql
->
rpl_pivot
;
if
(
!
mysql_real_connect
(
&
tmp_mysql
,
mysql
->
host
,
mysql
->
user
,
mysql
->
passwd
,
mysql
->
db
,
mysql
->
port
,
mysql
->
unix_socket
,
mysql
->
client_flag
))
mysql
->
client_flag
|
CLIENT_REMEMBER_OPTIONS
))
{
mysql
->
net
.
last_errno
=
tmp_mysql
.
net
.
last_errno
;
strmov
(
mysql
->
net
.
last_error
,
tmp_mysql
.
net
.
last_error
);
strmov
(
mysql
->
net
.
sqlstate
,
unknown_
sqlstate
);
strmov
(
mysql
->
net
.
sqlstate
,
tmp_mysql
.
net
.
sqlstate
);
DBUG_RETURN
(
1
);
}
tmp_mysql
.
free_me
=
mysql
->
free_me
;
...
...
@@ -2128,6 +2043,7 @@ my_bool mysql_reconnect(MYSQL *mysql)
DBUG_RETURN
(
0
);
}
/**************************************************************************
Set current database
**************************************************************************/
...
...
@@ -2146,51 +2062,14 @@ mysql_select_db(MYSQL *mysql, const char *db)
DBUG_RETURN
(
0
);
}
/*
Free strings in the SSL structure and clear 'use_ssl' flag.
NB! Errors are not reported until you do mysql_real_connect.
*/
#ifdef HAVE_OPENSSL
static
void
mysql_ssl_free
(
MYSQL
*
mysql
__attribute__
((
unused
)))
{
my_free
(
mysql
->
options
.
ssl_key
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
ssl_cert
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
ssl_ca
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
ssl_capath
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
options
.
ssl_cipher
,
MYF
(
MY_ALLOW_ZERO_PTR
));
my_free
(
mysql
->
connector_fd
,
MYF
(
MY_ALLOW_ZERO_PTR
));
mysql
->
options
.
ssl_key
=
0
;
mysql
->
options
.
ssl_cert
=
0
;
mysql
->
options
.
ssl_ca
=
0
;
mysql
->
options
.
ssl_capath
=
0
;
mysql
->
options
.
ssl_cipher
=
0
;
mysql
->
options
.
use_ssl
=
FALSE
;
mysql
->
connector_fd
=
0
;
}
#endif
/* HAVE_OPENSSL */
/*************************************************************************
Send a QUIT to the server and close the connection
If handle is alloced by mysql connect free it.
*************************************************************************/
void
STDCALL
mysql_close
(
MYSQL
*
mysql
)
static
void
mysql_close_free_options
(
MYSQL
*
mysql
)
{
DBUG_ENTER
(
"mysql_close"
);
if
(
mysql
)
/* Some simple safety */
{
if
(
mysql
->
net
.
vio
!=
0
)
{
free_old_query
(
mysql
);
mysql
->
status
=
MYSQL_STATUS_READY
;
/* Force command */
mysql
->
reconnect
=
0
;
simple_command
(
mysql
,
COM_QUIT
,
NullS
,
0
,
1
);
end_server
(
mysql
);
/* Sets mysql->net.vio= 0 */
}
my_free
((
gptr
)
mysql
->
host_info
,
MYF
(
MY_ALLOW_ZERO_PTR
));
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
));
...
...
@@ -2213,24 +2092,42 @@ mysql_close(MYSQL *mysql)
delete_dynamic
(
init_commands
);
my_free
((
char
*
)
init_commands
,
MYF
(
MY_WME
));
}
#ifdef HAVE_OPENSSL
mysql_ssl_free
(
mysql
);
#endif
/* HAVE_OPENSSL */
#ifdef HAVE_SMEM
if
(
mysql
->
options
.
shared_memory_base_name
!=
def_shared_memory_base_name
)
my_free
(
mysql
->
options
.
shared_memory_base_name
,
MYF
(
MY_ALLOW_ZERO_PTR
));
#endif
/* HAVE_SMEM */
bzero
((
char
*
)
&
mysql
->
options
,
sizeof
(
mysql
->
options
));
}
/* free/close slave list */
if
(
mysql
->
rpl_pivot
)
static
void
mysql_close_free
(
MYSQL
*
mysql
)
{
/* Clear pointers for better safety */
my_free
((
gptr
)
mysql
->
host_info
,
MYF
(
MY_ALLOW_ZERO_PTR
));
mysql
->
host_info
=
mysql
->
user
=
mysql
->
passwd
=
mysql
->
db
=
0
;
}
void
STDCALL
mysql_close
(
MYSQL
*
mysql
)
{
DBUG_ENTER
(
"mysql_close"
);
if
(
mysql
)
/* Some simple safety */
{
MYSQL
*
tmp
;
for
(
tmp
=
mysql
->
next_slave
;
tmp
!=
mysql
;
)
/* If connection is still up, send a QUIT message */
if
(
mysql
->
net
.
vio
!=
0
)
{
/* trick to avoid following freed pointer */
MYSQL
*
tmp1
=
tmp
->
next_slave
;
mysql_close
(
tmp
);
tmp
=
tmp1
;
}
mysql
->
rpl_pivot
=
0
;
free_old_query
(
mysql
);
mysql
->
status
=
MYSQL_STATUS_READY
;
/* Force command */
mysql
->
reconnect
=
0
;
simple_command
(
mysql
,
COM_QUIT
,
NullS
,
0
,
1
);
end_server
(
mysql
);
/* Sets mysql->net.vio= 0 */
}
mysql_close_free_options
(
mysql
);
mysql_close_free
(
mysql
);
#ifdef MYSQL_CLIENT
if
(
mysql
->
stmts
)
{
...
...
@@ -2241,24 +2138,33 @@ mysql_close(MYSQL *mysql)
next_element
=
element
->
next
;
stmt_close
((
MYSQL_STMT
*
)
element
->
data
,
0
);
}
mysql
->
stmts
=
0
;
}
#endif
/*MYSQL_CLIENT*/
#ifndef TO_BE_DELETED
/* free/close slave list */
if
(
mysql
->
rpl_pivot
)
{
MYSQL
*
tmp
;
for
(
tmp
=
mysql
->
next_slave
;
tmp
!=
mysql
;
)
{
/* trick to avoid following freed pointer */
MYSQL
*
tmp1
=
tmp
->
next_slave
;
mysql_close
(
tmp
);
tmp
=
tmp1
;
}
mysql
->
rpl_pivot
=
0
;
}
#endif
if
(
mysql
!=
mysql
->
master
)
mysql_close
(
mysql
->
master
);
#endif
/*MYSQL_CLIENT*/
#ifdef HAVE_OPENSSL
mysql_ssl_free
(
mysql
);
#endif
/* HAVE_OPENSSL */
/* Clear pointers for better safety */
mysql
->
host_info
=
mysql
->
user
=
mysql
->
passwd
=
mysql
->
db
=
0
;
bzero
((
char
*
)
&
mysql
->
options
,
sizeof
(
mysql
->
options
));
if
(
mysql
->
free_me
)
my_free
((
gptr
)
mysql
,
MYF
(
0
));
}
DBUG_VOID_RETURN
;
}
my_bool
STDCALL
mysql_read_query_result
(
MYSQL
*
mysql
)
{
uchar
*
pos
;
...
...
@@ -2267,18 +2173,16 @@ my_bool STDCALL mysql_read_query_result(MYSQL *mysql)
ulong
length
;
DBUG_ENTER
(
"mysql_read_query_result"
);
#ifdef MYSQL_CLIENT
/*
Read from the connection which we actually used, which
could differ from the original connection if we have slaves
*/
mysql
=
mysql
->
last_used_con
;
#endif
if
((
length
=
net_safe_read
(
mysql
))
==
packet_error
)
DBUG_RETURN
(
1
);
free_old_query
(
mysql
);
/* Free old result */
#ifdef MYSQL_CLIENT
/*or else gcc will
warn of unused labels*/
#ifdef MYSQL_CLIENT
/* Avoid
warn of unused labels*/
get_info:
#endif
pos
=
(
uchar
*
)
mysql
->
net
.
read_pos
;
...
...
@@ -2341,7 +2245,7 @@ mysql_send_query(MYSQL* mysql, const char* query, ulong length)
DBUG_ENTER
(
"mysql_send_query"
);
DBUG_PRINT
(
"enter"
,(
"rpl_parse: %d rpl_pivot: %d"
,
mysql
->
options
.
rpl_parse
,
mysql
->
rpl_pivot
));
#if
def MYSQL_CLIENT
#if
ndef TO_BE_DELETED
if
(
mysql
->
options
.
rpl_parse
&&
mysql
->
rpl_pivot
)
{
switch
(
mysql_rpl_query_type
(
query
,
length
))
{
...
...
@@ -2353,9 +2257,8 @@ mysql_send_query(MYSQL* mysql, const char* query, ulong length)
break
;
/* fall through */
}
}
mysql
->
last_used_con
=
mysql
;
#endif
/*MYSQL_CLIENT*/
#endif
DBUG_RETURN
(
simple_command
(
mysql
,
COM_QUERY
,
query
,
length
,
1
));
}
...
...
@@ -2373,6 +2276,7 @@ mysql_real_query(MYSQL *mysql, const char *query, ulong length)
DBUG_RETURN
((
int
)
mysql_read_query_result
(
mysql
));
}
/**************************************************************************
Alloc result struct for buffered results. All rows are read to buffer.
mysql_data_seek may be used.
...
...
@@ -2383,11 +2287,8 @@ mysql_store_result(MYSQL *mysql)
{
MYSQL_RES
*
result
;
DBUG_ENTER
(
"mysql_store_result"
);
#ifdef MYSQL_CLIENT
/* read from the actually used connection */
mysql
=
mysql
->
last_used_con
;
#endif
if
(
!
mysql
->
fields
)
DBUG_RETURN
(
0
);
if
(
mysql
->
status
!=
MYSQL_STATUS_GET_RESULT
)
...
...
@@ -2426,6 +2327,57 @@ mysql_store_result(MYSQL *mysql)
DBUG_RETURN
(
result
);
/* Data fetched */
}
/**************************************************************************
Alloc struct for use with unbuffered reads. Data is fetched by domand
when calling to mysql_fetch_row.
mysql_data_seek is a noop.
No other queries may be specified with the same MYSQL handle.
There shouldn't be much processing per row because mysql server shouldn't
have to wait for the client (and will not wait more than 30 sec/packet).
**************************************************************************/
MYSQL_RES
*
STDCALL
mysql_use_result
(
MYSQL
*
mysql
)
{
MYSQL_RES
*
result
;
DBUG_ENTER
(
"mysql_use_result"
);
mysql
=
mysql
->
last_used_con
;
if
(
!
mysql
->
fields
)
DBUG_RETURN
(
0
);
if
(
mysql
->
status
!=
MYSQL_STATUS_GET_RESULT
)
{
strmov
(
mysql
->
net
.
sqlstate
,
unknown_sqlstate
);
strmov
(
mysql
->
net
.
last_error
,
ER
(
mysql
->
net
.
last_errno
=
CR_COMMANDS_OUT_OF_SYNC
));
DBUG_RETURN
(
0
);
}
if
(
!
(
result
=
(
MYSQL_RES
*
)
my_malloc
(
sizeof
(
*
result
)
+
sizeof
(
ulong
)
*
mysql
->
field_count
,
MYF
(
MY_WME
|
MY_ZEROFILL
))))
DBUG_RETURN
(
0
);
result
->
lengths
=
(
ulong
*
)
(
result
+
1
);
if
(
!
(
result
->
row
=
(
MYSQL_ROW
)
my_malloc
(
sizeof
(
result
->
row
[
0
])
*
(
mysql
->
field_count
+
1
),
MYF
(
MY_WME
))))
{
/* Ptrs: to one row */
my_free
((
gptr
)
result
,
MYF
(
0
));
DBUG_RETURN
(
0
);
}
result
->
fields
=
mysql
->
fields
;
result
->
field_alloc
=
mysql
->
field_alloc
;
result
->
field_count
=
mysql
->
field_count
;
result
->
current_field
=
0
;
result
->
handle
=
mysql
;
result
->
current_row
=
0
;
mysql
->
fields
=
0
;
/* fields is now in result */
mysql
->
status
=
MYSQL_STATUS_USE_RESULT
;
DBUG_RETURN
(
result
);
/* Data is read to be fetched */
}
/**************************************************************************
Return next row of the query results
**************************************************************************/
...
...
@@ -2467,20 +2419,6 @@ mysql_fetch_row(MYSQL_RES *res)
}
}
/**************************************************************************
Move to a specific row and column
**************************************************************************/
void
STDCALL
mysql_data_seek
(
MYSQL_RES
*
result
,
my_ulonglong
row
)
{
MYSQL_ROWS
*
tmp
=
0
;
DBUG_PRINT
(
"info"
,(
"mysql_data_seek(%ld)"
,(
long
)
row
));
if
(
result
->
data
)
for
(
tmp
=
result
->
data
->
data
;
row
--
&&
tmp
;
tmp
=
tmp
->
next
)
;
result
->
current_row
=
0
;
result
->
data_cursor
=
tmp
;
}
int
STDCALL
mysql_options
(
MYSQL
*
mysql
,
enum
mysql_option
option
,
const
char
*
arg
)
...
...
@@ -2491,11 +2429,17 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg)
case
MYSQL_OPT_CONNECT_TIMEOUT
:
mysql
->
options
.
connect_timeout
=
*
(
uint
*
)
arg
;
break
;
case
MYSQL_OPT_READ_TIMEOUT
:
mysql
->
options
.
read_timeout
=
*
(
uint
*
)
arg
;
break
;
case
MYSQL_OPT_WRITE_TIMEOUT
:
mysql
->
options
.
write_timeout
=
*
(
uint
*
)
arg
;
break
;
case
MYSQL_OPT_COMPRESS
:
mysql
->
options
.
compress
=
1
;
/* Remember for connect */
mysql
->
options
.
client_flag
|=
CLIENT_COMPRESS
;
break
;
case
MYSQL_OPT_NAMED_PIPE
:
case
MYSQL_OPT_NAMED_PIPE
:
/* This option is depricated */
mysql
->
options
.
protocol
=
MYSQL_PROTOCOL_PIPE
;
/* Force named pipe */
break
;
case
MYSQL_OPT_LOCAL_INFILE
:
/* Allow LOAD DATA LOCAL ?*/
...
...
@@ -2504,11 +2448,9 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg)
else
mysql
->
options
.
client_flag
&=
~
CLIENT_LOCAL_FILES
;
break
;
#ifdef MYSQL_CLIENT
case
MYSQL_INIT_COMMAND
:
add_init_command
(
&
mysql
->
options
,
arg
);
break
;
#endif
case
MYSQL_READ_DEFAULT_FILE
:
my_free
(
mysql
->
options
.
my_cnf_file
,
MYF
(
MY_ALLOW_ZERO_PTR
));
mysql
->
options
.
my_cnf_file
=
my_strdup
(
arg
,
MYF
(
MY_WME
));
...
...
@@ -2567,6 +2509,3 @@ const char * STDCALL mysql_error(MYSQL *mysql)
{
return
mysql
->
net
.
last_error
;
}
#endif
/* defined(MYSQL_SERVER) || defined(HAVE_EXTERNAL_CLIENT) */
sql/Makefile.am
View file @
1e62d607
...
...
@@ -84,7 +84,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \
sql_load.cc mf_iocache.cc field_conv.cc sql_show.cc
\
sql_udf.cc sql_analyse.cc sql_analyse.h sql_cache.cc
\
slave.cc sql_repl.cc sql_union.cc sql_derived.cc
\
client.c mini_client_errors.c pack.c
\
client.c
sql_client.cc
mini_client_errors.c pack.c
\
stacktrace.c repl_failsafe.h repl_failsafe.cc sql_olap.cc
\
gstream.cc spatial.cc sql_help.cc protocol_cursor.cc
gen_lex_hash_SOURCES
=
gen_lex_hash.cc
...
...
sql/client_settings.h
View file @
1e62d607
...
...
@@ -17,18 +17,15 @@
#include <thr_alarm.h>
extern
char
*
mysql_unix_port
;
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG \
| CLIENT_LOCAL_FILES | CLIENT_SECURE_CONNECTION)
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | \
CLIENT_SECURE_CONNECTION | CLIENT_TRANSACTIONS | \
CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION)
#define init_sigpipe_variables
#define set_sigpipe(mysql)
#define reset_sigpipe(mysql)
extern
ulong
slave_net_timeout
;
#ifdef HAVE_SMEM
#define read_user_name(A) {}
#define mysql_rpl_query_type(A,B) MYSQL_RPL_ADMIN
#define mysql_rpl_probe(mysql) 0
#undef HAVE_SMEM
#
endif
#
undef _CUSTOMCONFIG_
sql/log.cc
View file @
1e62d607
...
...
@@ -209,9 +209,9 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg,
#ifdef EMBEDDED_LIBRARY
sprintf
(
buff
,
"%s, Version: %s, embedded library
\n
"
,
my_progname
,
server_version
);
#elif __NT__
sprintf
(
buff
,
"%s, Version: %s, started with:
\n
TCP Port: %d, Named Pipe: %s
\n
"
,
my_progname
,
server_version
,
mysql
_port
,
mysql
_unix_port
);
sprintf
(
buff
,
"%s, Version: %s, started with:
\n
TCP Port: %d, Named Pipe: %s
\n
"
,
my_progname
,
server_version
,
mysql
d_port
,
mysqld
_unix_port
);
#else
sprintf
(
buff
,
"%s, Version: %s, started with:
\n
Tcp port: %d Unix socket: %s
\n
"
,
my_progname
,
server_version
,
mysql
_port
,
mysql
_unix_port
);
sprintf
(
buff
,
"%s, Version: %s, started with:
\n
Tcp port: %d Unix socket: %s
\n
"
,
my_progname
,
server_version
,
mysql
d_port
,
mysqld
_unix_port
);
#endif
end
=
strmov
(
strend
(
buff
),
"Time Id Command Argument
\n
"
);
if
(
my_b_write
(
&
log_file
,
(
byte
*
)
buff
,(
uint
)
(
end
-
buff
))
||
...
...
sql/mysql_priv.h
View file @
1e62d607
...
...
@@ -732,7 +732,7 @@ extern ulong specialflag, current_pid;
extern
ulong
expire_logs_days
;
extern
my_bool
relay_log_purge
;
extern
uint
test_flags
,
select_errors
,
ha_open_options
;
extern
uint
protocol_version
,
dropping_tables
;
extern
uint
protocol_version
,
mysqld_port
,
dropping_tables
;
extern
uint
delay_key_write_options
;
extern
bool
opt_endinfo
,
using_udf_functions
,
locked_in_memory
;
extern
bool
opt_using_transactions
,
mysql_embedded
;
...
...
@@ -747,7 +747,7 @@ extern my_bool opt_slave_compressed_protocol, use_temp_pool;
extern
my_bool
opt_readonly
;
extern
my_bool
opt_enable_named_pipe
;
extern
my_bool
opt_old_passwords
,
use_old_passwords
;
extern
char
*
shared_memory_base_name
;
extern
char
*
shared_memory_base_name
,
*
mysqld_unix_port
;
extern
bool
opt_enable_shared_memory
;
extern
MYSQL_LOG
mysql_log
,
mysql_update_log
,
mysql_slow_log
,
mysql_bin_log
;
...
...
sql/mysqld.cc
View file @
1e62d607
...
...
@@ -35,6 +35,7 @@
#include <nisam.h>
#include <thr_alarm.h>
#include <ft_global.h>
#include <errmsg.h>
#define mysqld_charset &my_charset_latin1
...
...
@@ -254,7 +255,7 @@ my_bool opt_console= 0, opt_bdb, opt_innodb, opt_isam;
my_bool
opt_readonly
,
use_temp_pool
,
relay_log_purge
;
volatile
bool
mqh_used
=
0
;
uint
mysql_port
,
test_flags
,
select_errors
,
dropping_tables
,
ha_open_options
;
uint
mysql
d
_port
,
test_flags
,
select_errors
,
dropping_tables
,
ha_open_options
;
uint
delay_key_write_options
,
protocol_version
;
uint
volatile
thread_count
,
thread_running
,
kill_cached_threads
,
wake_thread
;
...
...
@@ -303,7 +304,7 @@ char mysql_real_data_home[FN_REFLEN],
char
*
language_ptr
,
*
default_collation_name
,
*
default_character_set_name
;
char
mysql_data_home_buff
[
2
],
*
mysql_data_home
=
mysql_real_data_home
;
char
server_version
[
SERVER_VERSION_LENGTH
]
=
MYSQL_SERVER_VERSION
;
char
*
mysql_unix_port
,
*
opt_mysql_tmpdir
;
char
*
mysql
d
_unix_port
,
*
opt_mysql_tmpdir
;
char
*
my_bind_addr_str
;
const
char
**
errmesg
;
/* Error messages */
const
char
*
myisam_recover_options_str
=
"OFF"
;
...
...
@@ -561,7 +562,7 @@ static void close_connections(void)
{
(
void
)
shutdown
(
unix_sock
,
2
);
(
void
)
closesocket
(
unix_sock
);
(
void
)
unlink
(
mysql_unix_port
);
(
void
)
unlink
(
mysql
d
_unix_port
);
unix_sock
=
INVALID_SOCKET
;
}
#endif
...
...
@@ -670,7 +671,7 @@ static void close_server_sock()
DBUG_PRINT
(
"info"
,(
"calling closesocket on unix/IP socket"
));
VOID
(
closesocket
(
tmp_sock
));
#endif
VOID
(
unlink
(
mysql_unix_port
));
VOID
(
unlink
(
mysql
d
_unix_port
));
}
DBUG_VOID_RETURN
;
#endif
...
...
@@ -961,24 +962,24 @@ static void clean_up_mutexes()
static
void
set_ports
()
{
char
*
env
;
if
(
!
mysql_port
&&
!
opt_disable_networking
)
if
(
!
mysql
d
_port
&&
!
opt_disable_networking
)
{
// Get port if not from commandline
struct
servent
*
serv_ptr
;
mysql
_port
=
MYSQL_PORT
;
if
((
serv_ptr
=
getservbyname
(
"mysql"
,
"tcp"
)))
mysql
_port
=
ntohs
((
u_short
)
serv_ptr
->
s_port
);
/* purecov: inspected */
mysql
d_port
=
MYSQL_PORT
;
if
((
serv_ptr
=
getservbyname
(
"mysql"
,
"tcp"
)))
mysql
d_port
=
ntohs
((
u_short
)
serv_ptr
->
s_port
);
/* purecov: inspected */
if
((
env
=
getenv
(
"MYSQL_TCP_PORT"
)))
mysql
_port
=
(
uint
)
atoi
(
env
);
/* purecov: inspected */
mysql
d_port
=
(
uint
)
atoi
(
env
);
/* purecov: inspected */
}
if
(
!
mysql_unix_port
)
if
(
!
mysql
d
_unix_port
)
{
#ifdef __WIN__
mysql
_unix_port
=
(
char
*
)
MYSQL_NAMEDPIPE
;
mysql
d_unix_port
=
(
char
*
)
MYSQL_NAMEDPIPE
;
#else
mysql
_unix_port
=
(
char
*
)
MYSQL_UNIX_ADDR
;
mysql
d_unix_port
=
(
char
*
)
MYSQL_UNIX_ADDR
;
#endif
if
((
env
=
getenv
(
"MYSQL_UNIX_PORT"
)))
mysql
_unix_port
=
env
;
/* purecov: inspected */
mysql
d_unix_port
=
env
;
/* purecov: inspected */
}
}
...
...
@@ -1088,9 +1089,9 @@ static void server_init(void)
set_ports
();
if
(
mysql_port
!=
0
&&
!
opt_disable_networking
&&
!
opt_bootstrap
)
if
(
mysql
d
_port
!=
0
&&
!
opt_disable_networking
&&
!
opt_bootstrap
)
{
DBUG_PRINT
(
"general"
,(
"IP Socket is %d"
,
mysql_port
));
DBUG_PRINT
(
"general"
,(
"IP Socket is %d"
,
mysql
d
_port
));
ip_sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
if
(
ip_sock
==
INVALID_SOCKET
)
{
...
...
@@ -1101,14 +1102,14 @@ static void server_init(void)
bzero
((
char
*
)
&
IPaddr
,
sizeof
(
IPaddr
));
IPaddr
.
sin_family
=
AF_INET
;
IPaddr
.
sin_addr
.
s_addr
=
my_bind_addr
;
IPaddr
.
sin_port
=
(
unsigned
short
)
htons
((
unsigned
short
)
mysql_port
);
IPaddr
.
sin_port
=
(
unsigned
short
)
htons
((
unsigned
short
)
mysql
d
_port
);
(
void
)
setsockopt
(
ip_sock
,
SOL_SOCKET
,
SO_REUSEADDR
,(
char
*
)
&
arg
,
sizeof
(
arg
));
if
(
bind
(
ip_sock
,
my_reinterpret_cast
(
struct
sockaddr
*
)
(
&
IPaddr
),
sizeof
(
IPaddr
))
<
0
)
{
DBUG_PRINT
(
"error"
,(
"Got error: %d from bind"
,
socket_errno
));
sql_perror
(
"Can't start server: Bind on TCP/IP port"
);
sql_print_error
(
"Do you already have another mysqld server running on port: %d ?"
,
mysql_port
);
sql_print_error
(
"Do you already have another mysqld server running on port: %d ?"
,
mysql
d
_port
);
unireg_abort
(
1
);
}
if
(
listen
(
ip_sock
,(
int
)
back_log
)
<
0
)
...
...
@@ -1123,10 +1124,10 @@ static void server_init(void)
#ifdef __NT__
/* create named pipe */
if
(
Service
.
IsNT
()
&&
mysql_unix_port
[
0
]
&&
!
opt_bootstrap
&&
if
(
Service
.
IsNT
()
&&
mysql
d
_unix_port
[
0
]
&&
!
opt_bootstrap
&&
opt_enable_named_pipe
)
{
sprintf
(
szPipeName
,
"
\\\\
.
\\
pipe
\\
%s"
,
mysql_unix_port
);
sprintf
(
szPipeName
,
"
\\\\
.
\\
pipe
\\
%s"
,
mysql
d
_unix_port
);
ZeroMemory
(
&
saPipeSecurity
,
sizeof
(
saPipeSecurity
)
);
ZeroMemory
(
&
sdPipeDescriptor
,
sizeof
(
sdPipeDescriptor
)
);
if
(
!
InitializeSecurityDescriptor
(
&
sdPipeDescriptor
,
...
...
@@ -1172,9 +1173,9 @@ static void server_init(void)
/*
** Create the UNIX socket
*/
if
(
mysql_unix_port
[
0
]
&&
!
opt_bootstrap
)
if
(
mysql
d
_unix_port
[
0
]
&&
!
opt_bootstrap
)
{
DBUG_PRINT
(
"general"
,(
"UNIX Socket is %s"
,
mysql_unix_port
));
DBUG_PRINT
(
"general"
,(
"UNIX Socket is %s"
,
mysql
d
_unix_port
));
if
((
unix_sock
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
0
))
<
0
)
{
...
...
@@ -1183,8 +1184,8 @@ static void server_init(void)
}
bzero
((
char
*
)
&
UNIXaddr
,
sizeof
(
UNIXaddr
));
UNIXaddr
.
sun_family
=
AF_UNIX
;
strmov
(
UNIXaddr
.
sun_path
,
mysql_unix_port
);
(
void
)
unlink
(
mysql_unix_port
);
strmov
(
UNIXaddr
.
sun_path
,
mysql
d
_unix_port
);
(
void
)
unlink
(
mysql
d
_unix_port
);
(
void
)
setsockopt
(
unix_sock
,
SOL_SOCKET
,
SO_REUSEADDR
,(
char
*
)
&
arg
,
sizeof
(
arg
));
umask
(
0
);
...
...
@@ -1192,12 +1193,12 @@ static void server_init(void)
sizeof
(
UNIXaddr
))
<
0
)
{
sql_perror
(
"Can't start server : Bind on unix socket"
);
/* purecov: tested */
sql_print_error
(
"Do you already have another mysqld server running on socket: %s ?"
,
mysql_unix_port
);
sql_print_error
(
"Do you already have another mysqld server running on socket: %s ?"
,
mysql
d
_unix_port
);
unireg_abort
(
1
);
/* purecov: tested */
}
umask
(((
~
my_umask
)
&
0666
));
#if defined(S_IFSOCK) && defined(SECURE_SOCKETS)
(
void
)
chmod
(
mysql_unix_port
,
S_IFSOCK
);
/* Fix solaris 2.6 bug */
(
void
)
chmod
(
mysql
d
_unix_port
,
S_IFSOCK
);
/* Fix solaris 2.6 bug */
#endif
if
(
listen
(
unix_sock
,(
int
)
back_log
)
<
0
)
sql_print_error
(
"Warning: listen() on Unix socket failed with error %d"
,
...
...
@@ -2024,6 +2025,7 @@ static int init_common_variables(const char *conf_file_name, int argc,
#endif
unireg_init
(
opt_specialflag
);
/* Set up extern variabels */
init_errmessage
();
/* Read error messages from file */
init_client_errs
();
lex_init
();
item_init
();
set_var_init
();
...
...
@@ -2426,7 +2428,7 @@ The server will not act as a slave.");
(
void
)
my_delete
(
pidfile_name
,
MYF
(
MY_WME
));
// Not needed anymore
#endif
if
(
unix_sock
!=
INVALID_SOCKET
)
unlink
(
mysql_unix_port
);
unlink
(
mysql
d
_unix_port
);
exit
(
1
);
}
if
(
!
opt_noacl
)
...
...
@@ -2458,8 +2460,8 @@ The server will not act as a slave.");
create_maintenance_thread
();
printf
(
ER
(
ER_READY
),
my_progname
,
server_version
,
((
unix_sock
==
INVALID_SOCKET
)
?
(
char
*
)
""
:
mysql_unix_port
),
mysql_port
);
((
unix_sock
==
INVALID_SOCKET
)
?
(
char
*
)
""
:
mysql
d
_unix_port
),
mysql
d
_port
);
fflush
(
stdout
);
#if defined(__NT__) || defined(HAVE_SMEM)
...
...
@@ -3774,8 +3776,8 @@ Does nothing yet.",
{
"log-error"
,
OPT_ERROR_LOG_FILE
,
"Log error file."
,
(
gptr
*
)
&
log_error_file_ptr
,
(
gptr
*
)
&
log_error_file_ptr
,
0
,
GET_STR
,
OPT_ARG
,
0
,
0
,
0
,
0
,
0
,
0
},
{
"port"
,
'P'
,
"Port number to use for connection."
,
(
gptr
*
)
&
mysql_port
,
(
gptr
*
)
&
mysql_port
,
0
,
GET_UINT
,
REQUIRED_ARG
,
0
,
0
,
0
,
0
,
0
,
0
},
{
"port"
,
'P'
,
"Port number to use for connection."
,
(
gptr
*
)
&
mysql
d
_port
,
(
gptr
*
)
&
mysql
d
_port
,
0
,
GET_UINT
,
REQUIRED_ARG
,
0
,
0
,
0
,
0
,
0
,
0
},
{
"reckless-slave"
,
OPT_RECKLESS_SLAVE
,
"Used for debugging."
,
0
,
0
,
0
,
GET_NO_ARG
,
NO_ARG
,
0
,
0
,
0
,
0
,
0
,
0
},
{
"replicate-do-db"
,
OPT_REPLICATE_DO_DB
,
...
...
@@ -3913,7 +3915,7 @@ replicating a LOAD DATA INFILE command.",
0
,
0
,
0
,
GET_STR
,
REQUIRED_ARG
,
0
,
0
,
0
,
0
,
0
,
0
},
#endif
{
"socket"
,
OPT_SOCKET
,
"Socket file to use for connection."
,
(
gptr
*
)
&
mysql
_unix_port
,
(
gptr
*
)
&
mysql
_unix_port
,
0
,
GET_STR
,
(
gptr
*
)
&
mysql
d_unix_port
,
(
gptr
*
)
&
mysqld
_unix_port
,
0
,
GET_STR
,
REQUIRED_ARG
,
0
,
0
,
0
,
0
,
0
,
0
},
{
"sql-bin-update-same"
,
OPT_SQL_BIN_UPDATE_SAME
,
"If set, setting SQL_LOG_BIN to a value will automatically set SQL_LOG_UPDATE to the same value and vice versa."
,
...
...
@@ -4628,7 +4630,7 @@ static void mysql_init_variables(void)
max_sort_char
=
0
;
mysqld_user
=
mysqld_chroot
=
opt_init_file
=
opt_bin_logname
=
0
;
errmesg
=
0
;
mysql_unix_port
=
opt_mysql_tmpdir
=
my_bind_addr_str
=
NullS
;
mysql
d
_unix_port
=
opt_mysql_tmpdir
=
my_bind_addr_str
=
NullS
;
bzero
((
gptr
)
&
mysql_tmpdir_list
,
sizeof
(
mysql_tmpdir_list
));
bzero
((
gptr
)
&
com_stat
,
sizeof
(
com_stat
));
...
...
@@ -5035,7 +5037,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break
;
case
(
int
)
OPT_SKIP_NETWORKING
:
opt_disable_networking
=
1
;
mysql_port
=
0
;
mysql
d
_port
=
0
;
break
;
case
(
int
)
OPT_SKIP_SHOW_DB
:
opt_skip_show_db
=
1
;
...
...
sql/protocol.cc
View file @
1e62d607
...
...
@@ -103,8 +103,7 @@ void send_error(THD *thd, uint sql_errno, const char *err)
{
/* The first # is to make the protocol backward compatible */
buff
[
2
]
=
'#'
;
strmov
(
buff
+
3
,
mysql_errno_to_sqlstate
(
sql_errno
));
pos
=
buff
+
2
+
SQLSTATE_LENGTH
+
1
;
pos
=
strmov
(
buff
+
3
,
mysql_errno_to_sqlstate
(
sql_errno
));
}
length
=
(
uint
)
(
strmake
(
pos
,
err
,
MYSQL_ERRMSG_SIZE
-
1
)
-
buff
);
err
=
buff
;
...
...
@@ -236,28 +235,6 @@ net_printf(THD *thd, uint errcode, ...)
DBUG_VOID_RETURN
;
}
/*
Function called by my_net_init() to set some check variables
*/
#ifndef EMBEDDED_LIBRARY
extern
"C"
{
void
my_net_local_init
(
NET
*
net
)
{
net
->
max_packet
=
(
uint
)
global_system_variables
.
net_buffer_length
;
net
->
read_timeout
=
(
uint
)
global_system_variables
.
net_read_timeout
;
net
->
write_timeout
=
(
uint
)
global_system_variables
.
net_write_timeout
;
net
->
retry_count
=
(
uint
)
global_system_variables
.
net_retry_count
;
net
->
max_packet_size
=
max
(
global_system_variables
.
net_buffer_length
,
global_system_variables
.
max_allowed_packet
);
}
}
#else
/* EMBEDDED_LIBRARY */
void
my_net_local_init
(
NET
*
net
__attribute__
(
unused
))
{
}
#endif
/* EMBEDDED_LIBRARY */
/*
Return ok to the client.
...
...
sql/repl_failsafe.cc
View file @
1e62d607
...
...
@@ -450,11 +450,11 @@ int show_new_master(THD* thd)
/*
Asks the master for the list of its other connected slaves.
This is for failsafe replication
:
in order for failsafe replication to work, the servers involved in
replication
must know of each other. We accomplish this by having each slave report to the
master how to reach it, and on connection, each slave receives information
about where the other slaves are.
This is for failsafe replication:
in order for failsafe replication to work, the servers involved in
replication must know of each other. We accomplish this by having each
slave report to the master how to reach it, and on connection, each
slave receives information
about where the other slaves are.
SYNOPSIS
update_slave_list()
...
...
@@ -466,8 +466,8 @@ int show_new_master(THD* thd)
hostname/port of the master, the username used by the slave to connect to
the master.
If the user used by the slave to connect to the master does not have the
REPLICATION SLAVE privilege, it will pop in this function because
SHOW SLAVE
HOSTS will fail on the master.
REPLICATION SLAVE privilege, it will pop in this function because
SHOW SLAVE
HOSTS will fail on the master.
RETURN VALUES
1 error
...
...
@@ -483,7 +483,6 @@ int update_slave_list(MYSQL* mysql, MASTER_INFO* mi)
int
port_ind
;
DBUG_ENTER
(
"update_slave_list"
);
if
(
mysql_real_query
(
mysql
,
"SHOW SLAVE HOSTS"
,
16
)
||
!
(
res
=
mysql_store_result
(
mysql
)))
{
...
...
@@ -668,8 +667,10 @@ int connect_to_master(THD *thd, MYSQL* mysql, MASTER_INFO* mi)
strmov
(
mysql
->
net
.
last_error
,
"Master is not configured"
);
DBUG_RETURN
(
1
);
}
mysql_options
(
mysql
,
MYSQL_OPT_CONNECT_TIMEOUT
,
(
char
*
)
&
slave_net_timeout
);
mysql_options
(
mysql
,
MYSQL_SET_CHARSET_NAME
,
(
char
*
)
default_charset_info
);
mysql_options
(
mysql
,
MYSQL_OPT_CONNECT_TIMEOUT
,
(
char
*
)
&
slave_net_timeout
);
mysql_options
(
mysql
,
MYSQL_OPT_READ_TIMEOUT
,
(
char
*
)
&
slave_net_timeout
);
mysql_options
(
mysql
,
MYSQL_SET_CHARSET_NAME
,
default_charset_info
->
csname
);
mysql_options
(
mysql
,
MYSQL_SET_CHARSET_DIR
,
(
char
*
)
charsets_dir
);
if
(
!
mysql_real_connect
(
mysql
,
mi
->
host
,
mi
->
user
,
mi
->
password
,
0
,
mi
->
port
,
0
,
0
))
DBUG_RETURN
(
1
);
...
...
sql/set_var.cc
View file @
1e62d607
...
...
@@ -600,7 +600,7 @@ struct show_var_st init_vars[]= {
{
"open_files_limit"
,
(
char
*
)
&
open_files_limit
,
SHOW_LONG
},
{
"pid_file"
,
(
char
*
)
pidfile_name
,
SHOW_CHAR
},
{
"log_error"
,
(
char
*
)
log_error_file
,
SHOW_CHAR
},
{
"port"
,
(
char
*
)
&
mysql_port
,
SHOW_INT
},
{
"port"
,
(
char
*
)
&
mysql
d
_port
,
SHOW_INT
},
{
"protocol_version"
,
(
char
*
)
&
protocol_version
,
SHOW_INT
},
{
sys_pseudo_thread_id
.
name
,
(
char
*
)
&
sys_pseudo_thread_id
,
SHOW_SYS
},
{
sys_read_buff_size
.
name
,
(
char
*
)
&
sys_read_buff_size
,
SHOW_SYS
},
...
...
@@ -631,7 +631,7 @@ struct show_var_st init_vars[]= {
{
"skip_show_database"
,
(
char
*
)
&
opt_skip_show_db
,
SHOW_BOOL
},
{
sys_slow_launch_time
.
name
,
(
char
*
)
&
sys_slow_launch_time
,
SHOW_SYS
},
#ifdef HAVE_SYS_UN_H
{
"socket"
,
(
char
*
)
&
mysql_unix_port
,
SHOW_CHAR_PTR
},
{
"socket"
,
(
char
*
)
&
mysql
d
_unix_port
,
SHOW_CHAR_PTR
},
#endif
{
sys_sort_buffer
.
name
,
(
char
*
)
&
sys_sort_buffer
,
SHOW_SYS
},
{
sys_sql_mode
.
name
,
(
char
*
)
&
sys_sql_mode
,
SHOW_SYS
},
...
...
sql/slave.cc
View file @
1e62d607
...
...
@@ -71,7 +71,7 @@ static int connect_to_master(THD* thd, MYSQL* mysql, MASTER_INFO* mi,
static
int
safe_sleep
(
THD
*
thd
,
int
sec
,
CHECK_KILLED_FUNC
thread_killed
,
void
*
thread_killed_arg
);
static
int
request_table_dump
(
MYSQL
*
mysql
,
const
char
*
db
,
const
char
*
table
);
static
int
create_table_from_dump
(
THD
*
thd
,
NET
*
net
,
const
char
*
db
,
static
int
create_table_from_dump
(
THD
*
thd
,
MYSQL
*
mysql
,
const
char
*
db
,
const
char
*
table_name
);
static
int
check_master_version
(
MYSQL
*
mysql
,
MASTER_INFO
*
mi
);
char
*
rewrite_db
(
char
*
db
);
...
...
@@ -1049,10 +1049,10 @@ static int check_master_version(MYSQL* mysql, MASTER_INFO* mi)
}
static
int
create_table_from_dump
(
THD
*
thd
,
NET
*
net
,
const
char
*
db
,
static
int
create_table_from_dump
(
THD
*
thd
,
MYSQL
*
mysql
,
const
char
*
db
,
const
char
*
table_name
)
{
ulong
packet_len
=
my_net_read
(
net
);
// read create table statement
ulong
packet_len
;
char
*
query
;
Vio
*
save_vio
;
HA_CHECK_OPT
check_opt
;
...
...
@@ -1060,7 +1060,9 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db,
int
error
=
1
;
handler
*
file
;
ulong
save_options
;
NET
*
net
=
&
mysql
->
net
;
packet_len
=
my_net_read
(
net
);
// read create table statement
if
(
packet_len
==
packet_error
)
{
send_error
(
thd
,
ER_MASTER_NET_READ
);
...
...
@@ -1068,28 +1070,23 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db,
}
if
(
net
->
read_pos
[
0
]
==
255
)
// error from master
{
net
->
read_pos
[
packet_len
]
=
0
;
net_printf
(
thd
,
ER_MASTER
,
net
->
read_pos
+
3
);
char
*
err_msg
;
err_msg
=
(
char
*
)
net
->
read_pos
+
((
mysql
->
server_capabilities
&
CLIENT_PROTOCOL_41
)
?
3
+
SQLSTATE_LENGTH
+
1
:
3
);
net_printf
(
thd
,
ER_MASTER
,
err_msg
);
return
1
;
}
thd
->
command
=
COM_TABLE_DUMP
;
thd
->
query_length
=
packet_len
;
/* Note that we should not set thd->query until the area is initalized */
if
(
!
(
query
=
sql_alloc
(
packet_len
+
1
)))
if
(
!
(
query
=
thd
->
strmake
((
char
*
)
net
->
read_pos
,
packet_len
)))
{
sql_print_error
(
"create_table_from_dump: out of memory"
);
net_printf
(
thd
,
ER_GET_ERRNO
,
"Out of memory"
);
return
1
;
}
memcpy
(
query
,
net
->
read_pos
,
packet_len
);
query
[
packet_len
]
=
0
;
thd
->
query_length
=
packet_len
;
/*
We make the following lock in an attempt to ensure that the compiler will
not rearrange the code so that thd->query is set too soon
*/
VOID
(
pthread_mutex_lock
(
&
LOCK_thread_count
));
thd
->
query
=
query
;
VOID
(
pthread_mutex_unlock
(
&
LOCK_thread_count
));
thd
->
current_tablenr
=
0
;
thd
->
query_error
=
0
;
thd
->
net
.
no_send_ok
=
1
;
...
...
@@ -1185,8 +1182,7 @@ int fetch_master_table(THD *thd, const char *db_name, const char *table_name,
errmsg
=
"Failed on table dump request"
;
goto
err
;
}
if
(
create_table_from_dump
(
thd
,
&
mysql
->
net
,
db_name
,
table_name
))
if
(
create_table_from_dump
(
thd
,
mysql
,
db_name
,
table_name
))
goto
err
;
// create_table_from_dump will have sent the error already
error
=
0
;
...
...
@@ -2996,17 +2992,20 @@ static int connect_to_master(THD* thd, MYSQL* mysql, MASTER_INFO* mi,
#ifndef DBUG_OFF
events_till_disconnect
=
disconnect_slave_event_count
;
#endif
u
int
client_flag
=
0
;
u
long
client_flag
=
CLIENT_REMEMBER_OPTIONS
;
if
(
opt_slave_compressed_protocol
)
client_flag
=
CLIENT_COMPRESS
;
/* We will use compression */
mysql_options
(
mysql
,
MYSQL_OPT_CONNECT_TIMEOUT
,
(
char
*
)
&
slave_net_timeout
);
mysql_options
(
mysql
,
MYSQL_OPT_READ_TIMEOUT
,
(
char
*
)
&
slave_net_timeout
);
mysql_options
(
mysql
,
MYSQL_SET_CHARSET_NAME
,
default_charset_info
->
csname
);
/* This one is not strictly needed but we have it here for completeness */
mysql_options
(
mysql
,
MYSQL_SET_CHARSET_DIR
,
(
char
*
)
charsets_dir
);
while
(
!
(
slave_was_killed
=
io_slave_killed
(
thd
,
mi
))
&&
(
reconnect
?
mysql_reconnect
(
mysql
)
!=
0
:
!
(
mysql_options
(
mysql
,
MYSQL_OPT_CONNECT_TIMEOUT
,
(
char
*
)
&
thd
->
variables
.
net_read_timeout
),
mysql_options
(
mysql
,
MYSQL_SET_CHARSET_NAME
,
(
char
*
)
default_charset_info
),
(
reconnect
?
mysql_reconnect
(
mysql
)
!=
0
:
mysql_real_connect
(
mysql
,
mi
->
host
,
mi
->
user
,
mi
->
password
,
0
,
mi
->
port
,
0
,
client_flag
))
))
mi
->
port
,
0
,
client_flag
)
==
0
))
{
/* Don't repeat last error */
if
((
int
)
mysql_errno
(
mysql
)
!=
last_errno
)
...
...
sql/sql_client.cc
0 → 100644
View file @
1e62d607
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
This files defines some MySQL C API functions that are server specific
*/
#include <mysql_priv.h>
/*
Function called by my_net_init() to set some check variables
*/
extern
"C"
{
void
my_net_local_init
(
NET
*
net
)
{
#ifndef EMBEDDED_LIBRARY
net
->
max_packet
=
(
uint
)
global_system_variables
.
net_buffer_length
;
net
->
read_timeout
=
(
uint
)
global_system_variables
.
net_read_timeout
;
net
->
write_timeout
=
(
uint
)
global_system_variables
.
net_write_timeout
;
net
->
retry_count
=
(
uint
)
global_system_variables
.
net_retry_count
;
net
->
max_packet_size
=
max
(
global_system_variables
.
net_buffer_length
,
global_system_variables
.
max_allowed_packet
);
#endif
}
}
extern
"C"
{
void
mysql_once_init
(
void
)
{
}
}
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