Commit 4093d083 authored by Otto Kekäläinen's avatar Otto Kekäläinen
Browse files

New upstream version 10.3.11

parent cdc3e0d9
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
- Statements: - Statements:
The Lex in THD is replaced by a new Lex structure and the statement, The Lex in THD is replaced by a new Lex structure and the statement,
is parsed as usual. A sp_instr_stmt is created, containing the new is parsed as usual. A sp_instr_stmt is created, containing the new
Lex, and added to added to the instructions in sphead. Lex, and added to the instructions in sphead.
Afterwards, the procedure's Lex is restored in THD. Afterwards, the procedure's Lex is restored in THD.
- SET var: - SET var:
Setting a local variable generates a sp_instr_set instruction, Setting a local variable generates a sp_instr_set instruction,
...@@ -169,7 +169,7 @@ ...@@ -169,7 +169,7 @@
- Parsing CREATE FUNCTION ... - Parsing CREATE FUNCTION ...
Creating a functions is essensially the same thing as for a PROCEDURE, Creating a functions is essentially the same thing as for a PROCEDURE,
with the addition that a FUNCTION has a return type and a RETURN with the addition that a FUNCTION has a return type and a RETURN
statement, but no OUT or INOUT parameters. statement, but no OUT or INOUT parameters.
...@@ -189,7 +189,7 @@ ...@@ -189,7 +189,7 @@
additional requirement. They will be called in expressions with the same additional requirement. They will be called in expressions with the same
syntax as UDFs, so UDFs and stored FUNCTIONs share the namespace. Thus, syntax as UDFs, so UDFs and stored FUNCTIONs share the namespace. Thus,
we must make sure that we do not have UDFs and FUNCTIONs with the same we must make sure that we do not have UDFs and FUNCTIONs with the same
name (even if they are storded in different places). name (even if they are stored in different places).
This means that we can reparse the procedure as many time as we want. This means that we can reparse the procedure as many time as we want.
The first time, the resulting Lex is used to store the procedure in The first time, the resulting Lex is used to store the procedure in
...@@ -225,7 +225,7 @@ ...@@ -225,7 +225,7 @@
sql_parse.cc:mysql_execute_command() then uses sp.cc:sp_find() to sql_parse.cc:mysql_execute_command() then uses sp.cc:sp_find() to
get the sp_head for the procedure (which may have been read from the get the sp_head for the procedure (which may have been read from the
database or feetched from the in-memory cache) and calls the sp_head's database or fetched from the in-memory cache) and calls the sp_head's
method execute(). method execute().
Note: It's important that substatements called by the procedure do not Note: It's important that substatements called by the procedure do not
do send_ok(). Fortunately, there is a flag in THD->net to disable do send_ok(). Fortunately, there is a flag in THD->net to disable
...@@ -294,15 +294,15 @@ ...@@ -294,15 +294,15 @@
- Detecting and parsing a FUNCTION invocation - Detecting and parsing a FUNCTION invocation
The existance of UDFs are checked during the lexical analysis (in The existence of UDFs are checked during the lexical analysis (in
sql_lex.cc:find_keyword()). This has the drawback that they must sql_lex.cc:find_keyword()). This has the drawback that they must
exist before they are refered to, which was ok before SPs existed, exist before they are referred to, which was ok before SPs existed,
but then it becomes a problem. The first implementation of SP FUNCTIONs but then it becomes a problem. The first implementation of SP FUNCTIONs
will work the same way, but this should be fixed a.s.a.p. (This will will work the same way, but this should be fixed a.s.a.p. (This will
required some reworking of the way UDFs are handled, which is why it's required some reworking of the way UDFs are handled, which is why it's
not done from the start.) not done from the start.)
For the time being, a FUNCTION is detected the same way, and returns For the time being, a FUNCTION is detected the same way, and returns
the token SP_FUNC. During the parsing we only check for the *existance* the token SP_FUNC. During the parsing we only check for the *existence*
of the function, we don't parse it, since wa can't call the parser of the function, we don't parse it, since wa can't call the parser
recursively. recursively.
...@@ -323,13 +323,13 @@ ...@@ -323,13 +323,13 @@
One "obvious" solution would be to simply push "mysql.proc" to the list One "obvious" solution would be to simply push "mysql.proc" to the list
of tables used by the query, but this implies a "join" with this table of tables used by the query, but this implies a "join" with this table
if the query is a select, so it doesn't work (and we can't exclude this if the query is a select, so it doesn't work (and we can't exclude this
table easily; since a priviledged used might in fact want to search table easily; since a privileged used might in fact want to search
the proc table). the proc table).
Another solution would of course be to allow the opening and closing Another solution would of course be to allow the opening and closing
of the mysql.proc table during a query execution, but this it not of the mysql.proc table during a query execution, but this it not
possible at the present. possible at the present.
So, the solution is to collect the names of the refered FUNCTIONs during So, the solution is to collect the names of the referred FUNCTIONs during
parsing in the lex. parsing in the lex.
Then, before doing anything else in mysql_execute_command(), read all Then, before doing anything else in mysql_execute_command(), read all
functions from the database an keep them in the THD, where the function functions from the database an keep them in the THD, where the function
...@@ -390,7 +390,7 @@ ...@@ -390,7 +390,7 @@
a method in the THD's sp_rcontext (if there is one). If a handler is a method in the THD's sp_rcontext (if there is one). If a handler is
found, this is recorded in the context and the routine returns without found, this is recorded in the context and the routine returns without
sending the error message. sending the error message.
The exectution loop (sp_head::execute()) checks for this after each The execution loop (sp_head::execute()) checks for this after each
statement and invokes the handler that has been found. If several statement and invokes the handler that has been found. If several
errors or warnings occurs during one statement, only the first is errors or warnings occurs during one statement, only the first is
caught, the rest are ignored. caught, the rest are ignored.
...@@ -400,9 +400,9 @@ ...@@ -400,9 +400,9 @@
instruction. instruction.
Calling and returning from a CONTINUE handler poses some special Calling and returning from a CONTINUE handler poses some special
problems. Since we need to return to the point after its invokation, problems. Since we need to return to the point after its invocation,
we push the return location on a stack in the sp_rcontext (this is we push the return location on a stack in the sp_rcontext (this is
done by the exectution loop). The handler then ends with a special done by the execution loop). The handler then ends with a special
instruction, sp_instr_hreturn, which returns to this location. instruction, sp_instr_hreturn, which returns to this location.
CONTINUE handlers have one additional problem: They are parsed at CONTINUE handlers have one additional problem: They are parsed at
...@@ -545,8 +545,8 @@ ...@@ -545,8 +545,8 @@
Cons: Uses more memory, each SP read from table once per thread. Cons: Uses more memory, each SP read from table once per thread.
Unfortunately, we cannot use alternative 1 for the time being, as most Unfortunately, we cannot use alternative 1 for the time being, as most
of the datastructures to be cached (lex and items) are not reentrant of the data structures to be cached (lex and items) are not reentrant
and thread-safe. (Things are modifed at execution, we have THD pointers and thread-safe. (Things are modified at execution, we have THD pointers
stored everywhere, etc.) stored everywhere, etc.)
This leaves us with alternative 2, one cache per thread; or actually This leaves us with alternative 2, one cache per thread; or actually
two, since we keep FUNCTIONs and PROCEDUREs in separate caches. two, since we keep FUNCTIONs and PROCEDUREs in separate caches.
......
MariaDB is designed as a drop-in replacement of MySQL(R) with more
features, new storage engines, fewer bugs, and better performance.
MariaDB is brought to you by the MariaDB Foundation.
Please read the CREDITS file for details about the MariaDB Foundation,
and who is developing MariaDB.
MariaDB is developed by many of the original developers of MySQL who
now work for the MariadB Foundation and the MariaDB Corporation, and by many people in
the community.
MySQL, which is the base of MariaDB, is a product and trademark of Oracle
Corporation, Inc. For a list of developers and other contributors,
see the Credits appendix. You can also run 'SHOW authors' to get a
list of active contributors.
A description of the MariaDB project and a manual can be found at:
http://mariadb.org/
https://mariadb.com/kb/en/
https://mariadb.com/kb/en/mariadb-vs-mysql-features/
https://mariadb.com/kb/en/mariadb-versus-mysql-features/
https://mariadb.com/kb/en/mariadb-versus-mysql-compatibility/
As MariaDB is a full replacement of MySQL, the MySQL manual at
http://dev.mysql.com/doc is generally applicable.
More help is available from the Maria Discuss mailing list
https://launchpad.net/~maria-discuss
and the #maria IRC channel on Freenode.
***************************************************************************
NOTE:
MariaDB is specifically available only under version 2 of the GNU
General Public License (GPLv2). (I.e. Without the "any later version"
clause.) This is inherited from MySQL. Please see the README file in
the MySQL distribution for more information.
License information can be found in the COPYING, COPYING.LESSER,
and COPYING.thirdparty files.
***************************************************************************
IMPORTANT:
Bug and/or error reports regarding MariaDB should be submitted at:
https://jira.mariadb.org
For reporting security vulnerabilities see:
https://mariadb.org/about/security-policy/
Bugs in the MySQL code can also be submitted at:
http://bugs.mysql.com
The code for MariaDB, including all revision history, can be found at:
https://github.com/MariaDB/server
***************************************************************************
Code status:
------------
* [![tests status](https://secure.travis-ci.org/MariaDB/server.png?branch=10.3)](https://travis-ci.org/MariaDB/server) travis-ci.org (10.3 branch)
## MariaDB: drop-in replacement for MySQL
MariaDB is designed as a drop-in replacement of MySQL(R) with more
features, new storage engines, fewer bugs, and better performance.
MariaDB is brought to you by the MariaDB Foundation.
Please read the CREDITS file for details about the MariaDB Foundation,
and who is developing MariaDB.
MariaDB is developed by many of the original developers of MySQL who
now work for the MariaDB Foundation and the MariaDB Corporation, and by many people in
the community.
MySQL, which is the base of MariaDB, is a product and trademark of Oracle
Corporation, Inc. For a list of developers and other contributors,
see the Credits appendix. You can also run 'SHOW authors' to get a
list of active contributors.
A description of the MariaDB project and a manual can be found at:
https://mariadb.org/
https://mariadb.com/kb/en/
https://mariadb.com/kb/en/mariadb-vs-mysql-features/
https://mariadb.com/kb/en/mariadb-versus-mysql-features/
https://mariadb.com/kb/en/mariadb-versus-mysql-compatibility/
As MariaDB is a full replacement of MySQL, the MySQL manual at
http://dev.mysql.com/doc is generally applicable.
Help:
-----
More help is available from the Maria Discuss mailing list
https://launchpad.net/~maria-discuss
and the #maria IRC channel on Freenode.
License:
--------
***************************************************************************
NOTE:
MariaDB is specifically available only under version 2 of the GNU
General Public License (GPLv2). (I.e. Without the "any later version"
clause.) This is inherited from MySQL. Please see the README file in
the MySQL distribution for more information.
License information can be found in the COPYING, COPYING.LESSER,
and COPYING.thirdparty files.
***************************************************************************
Bug Reports:
------------
Bug and/or error reports regarding MariaDB should be submitted at:
https://jira.mariadb.org
For reporting security vulnerabilities see:
https://mariadb.org/about/security-policy/
Bugs in the MySQL code can also be submitted at:
https://bugs.mysql.com
The code for MariaDB, including all revision history, can be found at:
https://github.com/MariaDB/server
***************************************************************************
MYSQL_VERSION_MAJOR=10 MYSQL_VERSION_MAJOR=10
MYSQL_VERSION_MINOR=1 MYSQL_VERSION_MINOR=3
MYSQL_VERSION_PATCH=37 MYSQL_VERSION_PATCH=11
SERVER_MATURITY=stable
version: build-{build}~branch-{branch}
before_build:
- md %APPVEYOR_BUILD_FOLDER%\win_build
- cd %APPVEYOR_BUILD_FOLDER%\win_build
- cmake .. -G "Visual Studio 15 2017 Win64" -DWITH_UNIT_TESTS=0
build:
project: win_build\MySQL.sln
parallel: true
verbosity: minimal
configuration: RelWithDebInfo
platform: x64
test_script:
- set PATH=%PATH%;C:\Program Files (x86)\Windows Kits\10\Debuggers\x64
- cd %APPVEYOR_BUILD_FOLDER%\win_build\mysql-test
- perl mysql-test-run.pl --force --max-test-fail=10 --parallel=auto --testcase-timeout=10 --skip-test-list=unstable-tests --suite=main,innodb,plugins,mariabackup
image: Visual Studio 2017
...@@ -20,20 +20,25 @@ INCLUDE_DIRECTORIES( ...@@ -20,20 +20,25 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/mysys_ssl ${CMAKE_SOURCE_DIR}/mysys_ssl
${ZLIB_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR}
${SSL_INCLUDE_DIRS} ${SSL_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/libmysql
${CMAKE_SOURCE_DIR}/sql ${CMAKE_SOURCE_DIR}/sql
${CMAKE_SOURCE_DIR}/strings ${CMAKE_SOURCE_DIR}/strings
${MY_READLINE_INCLUDE_DIR} ${MY_READLINE_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
) )
INCLUDE_DIRECTORIES(BEFORE
${CMAKE_BINARY_DIR}/libmariadb/include
${CMAKE_SOURCE_DIR}/libmariadb/include)
## We will need libeay32.dll and ssleay32.dll when running client executables. ## We will need libeay32.dll and ssleay32.dll when running client executables.
COPY_OPENSSL_DLLS(copy_openssl_client) COPY_OPENSSL_DLLS(copy_openssl_client)
SET(CLIENT_LIB mariadbclient mysys)
ADD_DEFINITIONS(${SSL_DEFINES}) ADD_DEFINITIONS(${SSL_DEFINES})
MYSQL_ADD_EXECUTABLE(mysql completion_hash.cc mysql.cc readline.cc MYSQL_ADD_EXECUTABLE(mysql completion_hash.cc mysql.cc readline.cc
${CMAKE_SOURCE_DIR}/sql/sql_string.cc) ${CMAKE_SOURCE_DIR}/sql/sql_string.cc)
TARGET_LINK_LIBRARIES(mysql mysqlclient) TARGET_LINK_LIBRARIES(mysql ${CLIENT_LIB})
IF(UNIX) IF(UNIX)
TARGET_LINK_LIBRARIES(mysql ${MY_READLINE_LIBRARY}) TARGET_LINK_LIBRARIES(mysql ${MY_READLINE_LIBRARY})
SET_TARGET_PROPERTIES(mysql PROPERTIES ENABLE_EXPORTS TRUE) SET_TARGET_PROPERTIES(mysql PROPERTIES ENABLE_EXPORTS TRUE)
...@@ -41,39 +46,40 @@ ENDIF(UNIX) ...@@ -41,39 +46,40 @@ ENDIF(UNIX)
MYSQL_ADD_EXECUTABLE(mysqltest mysqltest.cc COMPONENT Test) MYSQL_ADD_EXECUTABLE(mysqltest mysqltest.cc COMPONENT Test)
SET_SOURCE_FILES_PROPERTIES(mysqltest.cc PROPERTIES COMPILE_FLAGS "-DTHREADS") SET_SOURCE_FILES_PROPERTIES(mysqltest.cc PROPERTIES COMPILE_FLAGS "-DTHREADS")
TARGET_LINK_LIBRARIES(mysqltest mysqlclient pcre pcreposix) TARGET_LINK_LIBRARIES(mysqltest ${CLIENT_LIB} pcre pcreposix)
SET_TARGET_PROPERTIES(mysqltest PROPERTIES ENABLE_EXPORTS TRUE) SET_TARGET_PROPERTIES(mysqltest PROPERTIES ENABLE_EXPORTS TRUE)
MYSQL_ADD_EXECUTABLE(mysqlcheck mysqlcheck.c) MYSQL_ADD_EXECUTABLE(mysqlcheck mysqlcheck.c)
TARGET_LINK_LIBRARIES(mysqlcheck mysqlclient) TARGET_LINK_LIBRARIES(mysqlcheck ${CLIENT_LIB})
MYSQL_ADD_EXECUTABLE(mysqldump mysqldump.c ../sql-common/my_user.c) MYSQL_ADD_EXECUTABLE(mysqldump mysqldump.c ../sql-common/my_user.c)
TARGET_LINK_LIBRARIES(mysqldump mysqlclient) TARGET_LINK_LIBRARIES(mysqldump ${CLIENT_LIB})
MYSQL_ADD_EXECUTABLE(mysqlimport mysqlimport.c) MYSQL_ADD_EXECUTABLE(mysqlimport mysqlimport.c)
SET_SOURCE_FILES_PROPERTIES(mysqlimport.c PROPERTIES COMPILE_FLAGS "-DTHREADS") SET_SOURCE_FILES_PROPERTIES(mysqlimport.c PROPERTIES COMPILE_FLAGS "-DTHREADS")
TARGET_LINK_LIBRARIES(mysqlimport mysqlclient) TARGET_LINK_LIBRARIES(mysqlimport ${CLIENT_LIB})
MYSQL_ADD_EXECUTABLE(mysql_upgrade mysql_upgrade.c COMPONENT Server) MYSQL_ADD_EXECUTABLE(mysql_upgrade mysql_upgrade.c COMPONENT Server)
TARGET_LINK_LIBRARIES(mysql_upgrade mysqlclient) TARGET_LINK_LIBRARIES(mysql_upgrade ${CLIENT_LIB})
ADD_DEPENDENCIES(mysql_upgrade GenFixPrivs) ADD_DEPENDENCIES(mysql_upgrade GenFixPrivs)
MYSQL_ADD_EXECUTABLE(mysqlshow mysqlshow.c) MYSQL_ADD_EXECUTABLE(mysqlshow mysqlshow.c)
TARGET_LINK_LIBRARIES(mysqlshow mysqlclient) TARGET_LINK_LIBRARIES(mysqlshow ${CLIENT_LIB})
MYSQL_ADD_EXECUTABLE(mysql_plugin mysql_plugin.c) MYSQL_ADD_EXECUTABLE(mysql_plugin mysql_plugin.c)
TARGET_LINK_LIBRARIES(mysql_plugin mysqlclient) TARGET_LINK_LIBRARIES(mysql_plugin ${CLIENT_LIB})
MYSQL_ADD_EXECUTABLE(mysqlbinlog mysqlbinlog.cc) MYSQL_ADD_EXECUTABLE(mysqlbinlog mysqlbinlog.cc)
TARGET_LINK_LIBRARIES(mysqlbinlog mysqlclient) TARGET_LINK_LIBRARIES(mysqlbinlog ${CLIENT_LIB})
MYSQL_ADD_EXECUTABLE(mysqladmin mysqladmin.cc) MYSQL_ADD_EXECUTABLE(mysqladmin mysqladmin.cc ../sql/password.c)
TARGET_LINK_LIBRARIES(mysqladmin mysqlclient) TARGET_LINK_LIBRARIES(mysqladmin ${CLIENT_LIB})
MYSQL_ADD_EXECUTABLE(mysqlslap mysqlslap.c) MYSQL_ADD_EXECUTABLE(mysqlslap mysqlslap.c)
SET_SOURCE_FILES_PROPERTIES(mysqlslap.c PROPERTIES COMPILE_FLAGS "-DTHREADS") SET_SOURCE_FILES_PROPERTIES(mysqlslap.c PROPERTIES COMPILE_FLAGS "-DTHREADS")
TARGET_LINK_LIBRARIES(mysqlslap mysqlclient) TARGET_LINK_LIBRARIES(mysqlslap ${CLIENT_LIB})
# "WIN32" also covers 64 bit. "echo" is used in some files below "mysql-test/". # "WIN32" also covers 64 bit. "echo" is used in some files below "mysql-test/".
IF(WIN32) IF(WIN32)
...@@ -82,10 +88,16 @@ ENDIF(WIN32) ...@@ -82,10 +88,16 @@ ENDIF(WIN32)
# async_example is just a code example, do not install it. # async_example is just a code example, do not install it.
ADD_EXECUTABLE(async_example async_example.c) ADD_EXECUTABLE(async_example async_example.c)
TARGET_LINK_LIBRARIES(async_example mysqlclient) TARGET_LINK_LIBRARIES(async_example ${CLIENT_LIB})
SET_TARGET_PROPERTIES (mysqlcheck mysqldump mysqlimport mysql_upgrade mysqlshow mysqlslap mysql_plugin async_example SET_TARGET_PROPERTIES (mysqlcheck mysqldump mysqlimport mysql_upgrade mysqlshow mysqlslap mysql_plugin async_example
PROPERTIES HAS_CXX TRUE) PROPERTIES HAS_CXX TRUE)
FOREACH(t mysql mysqltest mysqltest mysqlcheck mysqldump mysqlimport mysql_upgrade mysqlshow mysql_plugin mysqlbinlog
mysqladmin mysqlslap async_example)
ADD_DEPENDENCIES(${t} GenError ${CLIENT_LIB})
ENDFOREACH()
ADD_DEFINITIONS(-DHAVE_DLOPEN) ADD_DEFINITIONS(-DHAVE_DLOPEN)
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <mysql.h> #include <mysql.h>
#include <errmsg.h> #include <errmsg.h>
#include <my_getopt.h> #include <my_getopt.h>
#include <mysql_version.h>
#ifndef WEXITSTATUS #ifndef WEXITSTATUS
# ifdef __WIN__ # ifdef __WIN__
...@@ -60,11 +61,16 @@ enum options_client ...@@ -60,11 +61,16 @@ enum options_client
OPT_USE_THREADS, OPT_USE_THREADS,
OPT_IMPORT_USE_THREADS, OPT_IMPORT_USE_THREADS,
OPT_MYSQL_NUMBER_OF_QUERY, OPT_MYSQL_NUMBER_OF_QUERY,
OPT_IGNORE_DATABASE,
OPT_IGNORE_TABLE,OPT_INSERT_IGNORE,OPT_SHOW_WARNINGS,OPT_DROP_DATABASE, OPT_IGNORE_TABLE,OPT_INSERT_IGNORE,OPT_SHOW_WARNINGS,OPT_DROP_DATABASE,
OPT_TZ_UTC, OPT_CREATE_SLAP_SCHEMA, OPT_TZ_UTC, OPT_CREATE_SLAP_SCHEMA,
OPT_MYSQLDUMP_SLAVE_APPLY, OPT_MYSQLDUMP_SLAVE_APPLY,
OPT_MYSQLDUMP_SLAVE_DATA, OPT_MYSQLDUMP_SLAVE_DATA,
OPT_MYSQLDUMP_INCLUDE_MASTER_HOST_PORT, OPT_MYSQLDUMP_INCLUDE_MASTER_HOST_PORT,
#ifdef WHEN_FLASHBACK_REVIEW_READY
OPT_REVIEW,
OPT_REVIEW_DBNAME, OPT_REVIEW_TABLENAME,
#endif
OPT_SLAP_CSV, OPT_SLAP_CREATE_STRING, OPT_SLAP_CSV, OPT_SLAP_CREATE_STRING,
OPT_SLAP_AUTO_GENERATE_SQL_LOAD_TYPE, OPT_SLAP_AUTO_GENERATE_WRITE_NUM, OPT_SLAP_AUTO_GENERATE_SQL_LOAD_TYPE, OPT_SLAP_AUTO_GENERATE_WRITE_NUM,
OPT_SLAP_AUTO_GENERATE_ADD_AUTO, OPT_SLAP_AUTO_GENERATE_ADD_AUTO,
...@@ -93,6 +99,7 @@ enum options_client ...@@ -93,6 +99,7 @@ enum options_client
OPT_REPORT_PROGRESS, OPT_REPORT_PROGRESS,
OPT_SKIP_ANNOTATE_ROWS_EVENTS, OPT_SKIP_ANNOTATE_ROWS_EVENTS,
OPT_SSL_CRL, OPT_SSL_CRLPATH, OPT_SSL_CRL, OPT_SSL_CRLPATH,
OPT_PRINT_ROW_COUNT, OPT_PRINT_ROW_EVENT_POSITIONS,
OPT_MAX_CLIENT_OPTION /* should be always the last */ OPT_MAX_CLIENT_OPTION /* should be always the last */
}; };
......
...@@ -49,7 +49,7 @@ int completion_hash_init(HashTable *ht, uint nSize) ...@@ -49,7 +49,7 @@ int completion_hash_init(HashTable *ht, uint nSize)
ht->initialized = 0; ht->initialized = 0;
return FAILURE; return FAILURE;
} }
init_alloc_root(&ht->mem_root, 8192, 0, MYF(0)); init_alloc_root(&ht->mem_root, "completion_hash", 8192, 0, MYF(0));
ht->pHashFunction = hashpjw; ht->pHashFunction = hashpjw;
ht->nTableSize = nSize; ht->nTableSize = nSize;
ht->initialized = 1; ht->initialized = 1;
......
/* Copyright (c) 2000, 2001, 2003, 2006, 2008 MySQL AB
Use is subject to license terms
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; version 2 of the License.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
/*
** Ask for a password from tty
** This is an own file to avoid conflicts with curses
*/
#include <my_global.h>
#include <my_sys.h>
#include "mysql.h"
#include <m_string.h>
#include <m_ctype.h>
#ifdef HAVE_GETPASS
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif /* HAVE_PWD_H */
#else /* ! HAVE_GETPASS */
#ifndef __WIN__
#include <sys/ioctl.h>
#ifdef HAVE_TERMIOS_H /* For tty-password */
#include <termios.h>
#define TERMIO struct termios
#else
#ifdef HAVE_TERMIO_H /* For tty-password */
#include <termio.h>
#define TERMIO struct termio
#else
#include <sgtty.h>
#define TERMIO struct sgttyb
#endif
#endif
#ifdef alpha_linux_port
#include <asm/ioctls.h> /* QQ; Fix this in configure */
#include <asm/termiobits.h>
#endif
#else
#include <conio.h>
#endif /* __WIN__ */
#endif /* HAVE_GETPASS */
#ifdef HAVE_GETPASSPHRASE /* For Solaris */
#define getpass(A) getpassphrase(A)
#endif
#ifdef __WIN__
/* were just going to fake it here and get input from
the keyboard */
char *get_tty_password(const char *opt_message)
{
char to[80];
char *pos=to,*end=to+sizeof(to)-1;
int i=0;
DBUG_ENTER("get_tty_password");
_cputs(opt_message ? opt_message : "Enter password: ");
for (;;)
{
char tmp;
tmp=_getch();
if (tmp == '\b' || (int) tmp == 127)
{
if (pos != to)
{
_cputs("\b \b");
pos--;
continue;
}
}
if (tmp == '\n' || tmp == '\r' || tmp == 3)
break;
if (iscntrl(tmp) || pos == end)
continue;
_cputs("*");
*(pos++) = tmp;
}
while (pos != to && isspace(pos[-1]) == ' ')
pos--; /* Allow dummy space at end */
*pos=0;
_cputs("\n");
DBUG_RETURN(my_strdup(to,MYF(MY_FAE)));
}
#else
#ifndef HAVE_GETPASS
/*
** Can't use fgets, because readline will get confused
** length is max number of chars in to, not counting \0
* to will not include the eol characters.
*/
static void get_password(char *to,uint length,int fd, my_bool echo)
{
char *pos=to,*end=to+length;
for (;;)
{
uchar tmp;
if (my_read(fd,&tmp,1,MYF(0)) != 1)
break;
if (tmp == '\b' || (int) tmp == 127)
{
if (pos != to)
{
if (echo)
{
fputs("\b \b",stderr);
fflush(stderr);
}
pos--;
continue;
}
}
if (tmp == '\n' || tmp == '\r' || tmp == 3)
break;
if (iscntrl(tmp) || pos == end)
continue;
if (echo)
{
fputc('*',stderr);
fflush(stderr);
}
*(pos++)= (char) tmp;
}
while (pos != to && isspace(pos[-1]) == ' ')
pos--; /* Allow dummy space at end */
*pos=0;
return;
}
#endif /* ! HAVE_GETPASS */
char *get_tty_password(const char *opt_message)
{
#ifdef HAVE_GETPASS
char *passbuff;
#else /* ! HAVE_GETPASS */
TERMIO org,tmp;
#endif /* HAVE_GETPASS */
char buff[80];
DBUG_ENTER("get_tty_password");
#ifdef HAVE_GETPASS
passbuff = getpass(opt_message ? opt_message : "Enter password: ");
/* copy the password to buff and clear original (static) buffer */
strnmov(buff, passbuff, sizeof(buff) - 1);
#ifdef _PASSWORD_LEN
memset(passbuff, 0, _PASSWORD_LEN);
#endif
#else
if (isatty(fileno(stderr)))
{
fputs(opt_message ? opt_message : "Enter password: ",stderr);
fflush(stderr);
}
#if defined(HAVE_TERMIOS_H)
tcgetattr(fileno(stdin), &org);
tmp = org;
tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
tmp.c_cc[VMIN] = 1;
tmp.c_cc[VTIME] = 0;
tcsetattr(fileno(stdin), TCSADRAIN, &tmp);
get_password(buff, sizeof(buff)-1, fileno(stdin), isatty(fileno(stderr)));
tcsetattr(fileno(stdin), TCSADRAIN, &org);
#elif defined(HAVE_TERMIO_H)
ioctl(fileno(stdin), (int) TCGETA, &org);
tmp=org;
tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
tmp.c_cc[VMIN] = 1;
tmp.c_cc[VTIME]= 0;
ioctl(fileno(stdin),(int) TCSETA, &tmp);
get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stderr)));
ioctl(fileno(stdin),(int) TCSETA, &org);
#else
gtty(fileno(stdin), &org);
tmp=org;
tmp.sg_flags &= ~ECHO;
tmp.sg_flags |= RAW;
stty(fileno(stdin), &tmp);
get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stderr)));
stty(fileno(stdin), &org);
#endif
if (isatty(fileno(stderr)))
fputc('\n',stderr);
#endif /* HAVE_GETPASS */
DBUG_RETURN(my_strdup(buff,MYF(MY_FAE)));
}
#endif /*__WIN__*/
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#include "my_readline.h" #include "my_readline.h"
#include <signal.h> #include <signal.h>
#include <violite.h> #include <violite.h>
#include <source_revision.h>
#if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H) #if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
#include <locale.h> #include <locale.h>
#endif #endif
...@@ -1065,7 +1065,7 @@ static void fix_history(String *final_command); ...@@ -1065,7 +1065,7 @@ static void fix_history(String *final_command);
static COMMANDS *find_command(char *name); static COMMANDS *find_command(char *name);
static COMMANDS *find_command(char cmd_name); static COMMANDS *find_command(char cmd_name);
static bool add_line(String &, char *, ulong, char *, bool *, bool); static bool add_line(String &, char *, size_t line_length, char *, bool *, bool);
static void remove_cntrl(String &buffer); static void remove_cntrl(String &buffer);
static void print_table_data(MYSQL_RES *result); static void print_table_data(MYSQL_RES *result);
static void print_table_data_html(MYSQL_RES *result); static void print_table_data_html(MYSQL_RES *result);
...@@ -1073,9 +1073,7 @@ static void print_table_data_xml(MYSQL_RES *result); ...@@ -1073,9 +1073,7 @@ static void print_table_data_xml(MYSQL_RES *result);
static void print_tab_data(MYSQL_RES *result); static void print_tab_data(MYSQL_RES *result);
static void print_table_data_vertically(MYSQL_RES *result); static void print_table_data_vertically(MYSQL_RES *result);
static void print_warnings(void); static void print_warnings(void);
static ulong start_timer(void); static void end_timer(ulonglong start_time, char *buff);
static void end_timer(ulong start_time,char *buff);
static void mysql_end_timer(ulong start_time,char *buff);
static void nice_time(double sec,char *buff,bool part_second); static void nice_time(double sec,char *buff,bool part_second);
extern "C" sig_handler mysql_end(int sig) __attribute__ ((noreturn)); extern "C" sig_handler mysql_end(int sig) __attribute__ ((noreturn));
extern "C" sig_handler handle_sigint(int sig); extern "C" sig_handler handle_sigint(int sig);
...@@ -1144,6 +1142,7 @@ int main(int argc,char *argv[]) ...@@ -1144,6 +1142,7 @@ int main(int argc,char *argv[])
outfile[0]=0; // no (default) outfile outfile[0]=0; // no (default) outfile
strmov(pager, "stdout"); // the default, if --pager wasn't given strmov(pager, "stdout"); // the default, if --pager wasn't given
{ {
char *tmp=getenv("PAGER"); char *tmp=getenv("PAGER");
if (tmp && strlen(tmp)) if (tmp && strlen(tmp))
...@@ -1178,7 +1177,11 @@ int main(int argc,char *argv[]) ...@@ -1178,7 +1177,11 @@ int main(int argc,char *argv[])
load_defaults_or_exit("my", load_default_groups, &argc, &argv); load_defaults_or_exit("my", load_default_groups, &argc, &argv);
defaults_argv=argv; defaults_argv=argv;
if ((status.exit_status= get_options(argc, (char **) argv))) if ((status.exit_status= get_options(argc, (char **) argv)))
mysql_end(-1); {
free_defaults(defaults_argv);
my_end(0);
exit(status.exit_status);
}
if (status.batch && !status.line_buff && if (status.batch && !status.line_buff &&
!(status.line_buff= batch_readline_init(MAX_BATCH_BUFFER_SIZE, stdin))) !(status.line_buff= batch_readline_init(MAX_BATCH_BUFFER_SIZE, stdin)))
...@@ -1200,8 +1203,7 @@ int main(int argc,char *argv[]) ...@@ -1200,8 +1203,7 @@ int main(int argc,char *argv[])
sf_leaking_memory= 0; sf_leaking_memory= 0;
glob_buffer.realloc(512); glob_buffer.realloc(512);
completion_hash_init(&ht, 128); completion_hash_init(&ht, 128);
init_alloc_root(&hash_mem_root, 16384, 0, MYF(0)); init_alloc_root(&hash_mem_root, "hash", 16384, 0, MYF(0));
bzero((char*) &mysql, sizeof(mysql));
if (sql_connect(current_host,current_db,current_user,opt_password, if (sql_connect(current_host,current_db,current_user,opt_password,
opt_silent)) opt_silent))
{ {
...@@ -1705,19 +1707,18 @@ static struct my_option my_long_options[] = ...@@ -1705,19 +1707,18 @@ static struct my_option my_long_options[] =
static void usage(int version) static void usage(int version)
{ {
#ifdef HAVE_READLINE
#if defined(USE_LIBEDIT_INTERFACE) #if defined(USE_LIBEDIT_INTERFACE)
const char* readline= ""; const char* readline= "";
#else #else
const char* readline= "readline"; const char* readline= "readline";
#endif #endif
#ifdef HAVE_READLINE
printf("%s Ver %s Distrib %s, for %s (%s) using %s %s\n", printf("%s Ver %s Distrib %s, for %s (%s) using %s %s\n",
my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE, my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE,
readline, rl_library_version); readline, rl_library_version);
#else #else
printf("%s Ver %s Distrib %s, for %s (%s)\n", my_progname, VER, printf("%s Ver %s Distrib %s, for %s (%s), source revision %s\n", my_progname, VER,
MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE); MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE,SOURCE_REVISION);
#endif #endif
if (version) if (version)
...@@ -1891,6 +1892,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), ...@@ -1891,6 +1892,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
usage(1); usage(1);
status.exit_status= 0; status.exit_status= 0;
mysql_end(-1); mysql_end(-1);
break;
case 'I': case 'I':
case '?': case '?':
usage(0); usage(0);
...@@ -1964,7 +1966,7 @@ static int get_options(int argc, char **argv) ...@@ -1964,7 +1966,7 @@ static int get_options(int argc, char **argv)
connect_flag|= CLIENT_IGNORE_SPACE; connect_flag|= CLIENT_IGNORE_SPACE;
if (opt_progress_reports) if (opt_progress_reports)
connect_flag|= CLIENT_PROGRESS; connect_flag|= CLIENT_PROGRESS_OBSOLETE;
return(0); return(0);
} }
...@@ -1981,7 +1983,7 @@ static int read_and_execute(bool interactive) ...@@ -1981,7 +1983,7 @@ static int read_and_execute(bool interactive)
ulong line_number=0; ulong line_number=0;
bool ml_comment= 0; bool ml_comment= 0;
COMMANDS *com; COMMANDS *com;
ulong line_length= 0; size_t line_length= 0;
status.exit_status=1; status.exit_status=1;
real_binary_mode= !interactive && opt_binary_mode; real_binary_mode= !interactive && opt_binary_mode;
...@@ -2275,7 +2277,7 @@ static COMMANDS *find_command(char *name) ...@@ -2275,7 +2277,7 @@ static COMMANDS *find_command(char *name)
} }
static bool add_line(String &buffer, char *line, ulong line_length, static bool add_line(String &buffer, char *line, size_t line_length,
char *in_string, bool *ml_comment, bool truncated) char *in_string, bool *ml_comment, bool truncated)
{ {
uchar inchar; uchar inchar;
...@@ -2983,12 +2985,12 @@ static void get_current_db() ...@@ -2983,12 +2985,12 @@ static void get_current_db()
The different commands The different commands
***************************************************************************/ ***************************************************************************/
int mysql_real_query_for_lazy(const char *buf, int length) int mysql_real_query_for_lazy(const char *buf, size_t length)
{ {
for (uint retry=0;; retry++) for (uint retry=0;; retry++)
{ {
int error; int error;
if (!mysql_real_query(&mysql,buf,length)) if (!mysql_real_query(&mysql,buf,(ulong)length))
return 0; return 0;
error= put_error(&mysql); error= put_error(&mysql);
if (mysql_errno(&mysql) != CR_SERVER_GONE_ERROR || retry > 1 || if (mysql_errno(&mysql) != CR_SERVER_GONE_ERROR || retry > 1 ||
...@@ -3128,7 +3130,7 @@ static int ...@@ -3128,7 +3130,7 @@ static int
com_help(String *buffer __attribute__((unused)), com_help(String *buffer __attribute__((unused)),
char *line __attribute__((unused))) char *line __attribute__((unused)))
{ {
reg1 int i, j; int i, j;
char * help_arg= strchr(line,' '), buff[32], *end; char * help_arg= strchr(line,' '), buff[32], *end;
if (help_arg) if (help_arg)
{ {
...@@ -3207,9 +3209,10 @@ static int ...@@ -3207,9 +3209,10 @@ static int
com_go(String *buffer,char *line __attribute__((unused))) com_go(String *buffer,char *line __attribute__((unused)))
{ {
char buff[200]; /* about 110 chars used so far */ char buff[200]; /* about 110 chars used so far */
char time_buff[52+3+1]; /* time max + space&parens + NUL */ char time_buff[53+3+1]; /* time max + space&parens + NUL */
MYSQL_RES *result; MYSQL_RES *result;
ulong timer, warnings= 0; ulonglong timer;
ulong warnings= 0;
uint error= 0; uint error= 0;
int err= 0; int err= 0;
...@@ -3248,7 +3251,7 @@ com_go(String *buffer,char *line __attribute__((unused))) ...@@ -3248,7 +3251,7 @@ com_go(String *buffer,char *line __attribute__((unused)))
return 0; return 0;
} }
timer=start_timer(); timer= microsecond_interval_timer();
executing_query= 1; executing_query= 1;
error= mysql_real_query_for_lazy(buffer->ptr(),buffer->length()); error= mysql_real_query_for_lazy(buffer->ptr(),buffer->length());
report_progress_end(); report_progress_end();
...@@ -3287,7 +3290,7 @@ com_go(String *buffer,char *line __attribute__((unused))) ...@@ -3287,7 +3290,7 @@ com_go(String *buffer,char *line __attribute__((unused)))
} }
if (verbose >= 3 || !opt_silent) if (verbose >= 3 || !opt_silent)
mysql_end_timer(timer,time_buff); end_timer(timer, time_buff);
else else
time_buff[0]= '\0'; time_buff[0]= '\0';
...@@ -3497,7 +3500,6 @@ static char *fieldflags2str(uint f) { ...@@ -3497,7 +3500,6 @@ static char *fieldflags2str(uint f) {
ff2s_check_flag(NUM); ff2s_check_flag(NUM);
ff2s_check_flag(PART_KEY); ff2s_check_flag(PART_KEY);
ff2s_check_flag(GROUP); ff2s_check_flag(GROUP);
ff2s_check_flag(UNIQUE);
ff2s_check_flag(BINCMP); ff2s_check_flag(BINCMP);
ff2s_check_flag(ON_UPDATE_NOW); ff2s_check_flag(ON_UPDATE_NOW);
#undef ff2s_check_flag #undef ff2s_check_flag
...@@ -3559,10 +3561,10 @@ is_binary_field(MYSQL_FIELD *field) ...@@ -3559,10 +3561,10 @@ is_binary_field(MYSQL_FIELD *field)
/* Print binary value as hex literal (0x ...) */ /* Print binary value as hex literal (0x ...) */
static void static void
print_as_hex(FILE *output_file, const char *str, ulong len, ulong total_bytes_to_send) print_as_hex(FILE *output_file, const char *str, size_t len, size_t total_bytes_to_send)
{ {
const char *ptr= str, *end= ptr+len; const char *ptr= str, *end= ptr+len;
ulong i; size_t i;
fprintf(output_file, "0x"); fprintf(output_file, "0x");
for(; ptr < end; ptr++) for(; ptr < end; ptr++)
fprintf(output_file, "%02X", *((uchar*)ptr)); fprintf(output_file, "%02X", *((uchar*)ptr));
...@@ -3612,11 +3614,11 @@ print_table_data(MYSQL_RES *result) ...@@ -3612,11 +3614,11 @@ print_table_data(MYSQL_RES *result)
(void) tee_fputs("|", PAGER); (void) tee_fputs("|", PAGER);
for (uint off=0; (field = mysql_fetch_field(result)) ; off++) for (uint off=0; (field = mysql_fetch_field(result)) ; off++)
{ {
uint name_length= (uint) strlen(field->name); size_t name_length= (uint) strlen(field->name);
uint numcells= charset_info->cset->numcells(charset_info, size_t numcells= charset_info->cset->numcells(charset_info,
field->name, field->name,
field->name + name_length); field->name + name_length);
uint display_length= field->max_length + name_length - numcells; size_t display_length= field->max_length + name_length - numcells;
tee_fprintf(PAGER, " %-*s |",(int) MY_MIN(display_length, tee_fprintf(PAGER, " %-*s |",(int) MY_MIN(display_length,
MAX_COLUMN_LENGTH), MAX_COLUMN_LENGTH),
field->name); field->name);
...@@ -3637,7 +3639,6 @@ print_table_data(MYSQL_RES *result) ...@@ -3637,7 +3639,6 @@ print_table_data(MYSQL_RES *result)
const char *buffer; const char *buffer;
uint data_length; uint data_length;
uint field_max_length; uint field_max_length;
uint visible_length;
uint extra_padding; uint extra_padding;
if (off) if (off)
...@@ -3665,7 +3666,7 @@ print_table_data(MYSQL_RES *result) ...@@ -3665,7 +3666,7 @@ print_table_data(MYSQL_RES *result)
We need to find how much screen real-estate we will occupy to know how We need to find how much screen real-estate we will occupy to know how
many extra padding-characters we should send with the printing function. many extra padding-characters we should send with the printing function.
*/ */
visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length); size_t visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length);
extra_padding= (uint) (data_length - visible_length); extra_padding= (uint) (data_length - visible_length);
if (opt_binhex && is_binary_field(field)) if (opt_binhex && is_binary_field(field))
...@@ -3914,7 +3915,7 @@ print_table_data_vertically(MYSQL_RES *result) ...@@ -3914,7 +3915,7 @@ print_table_data_vertically(MYSQL_RES *result)
} }
tee_putc('\n', PAGER); tee_putc('\n', PAGER);
} }
else else
tee_fprintf(PAGER, "NULL\n"); tee_fprintf(PAGER, "NULL\n");
} }
} }
...@@ -4204,8 +4205,7 @@ com_edit(String *buffer,char *line __attribute__((unused))) ...@@ -4204,8 +4205,7 @@ com_edit(String *buffer,char *line __attribute__((unused)))
const char *editor; const char *editor;
MY_STAT stat_arg; MY_STAT stat_arg;
if ((fd=create_temp_file(filename,NullS,"sql", O_CREAT | O_WRONLY, if ((fd= create_temp_file(filename,NullS,"sql", 0, MYF(MY_WME))) < 0)
MYF(MY_WME))) < 0)
goto err; goto err;
if (buffer->is_empty() && !old_buffer.is_empty()) if (buffer->is_empty() && !old_buffer.is_empty())
(void) my_write(fd,(uchar*) old_buffer.ptr(),old_buffer.length(), (void) my_write(fd,(uchar*) old_buffer.ptr(),old_buffer.length(),
...@@ -4712,21 +4712,25 @@ sql_real_connect(char *host,char *database,char *user,char *password, ...@@ -4712,21 +4712,25 @@ sql_real_connect(char *host,char *database,char *user,char *password,
} }
return -1; // Retryable return -1; // Retryable
} }
charset_info= mysql.charset; charset_info= get_charset_by_name(mysql.charset->name, MYF(0));
connected=1; connected=1;
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
mysql.reconnect= debug_info_flag; // We want to know if this happens mysql_options(&mysql, MYSQL_OPT_RECONNECT, &debug_info_flag);
/* /*
CLIENT_PROGRESS is set only if we requsted it in mysql_real_connect() CLIENT_PROGRESS_OBSOLETE is set only if we requested it in
and the server also supports it mysql_real_connect() and the server also supports it
*/ */
if (mysql.client_flag & CLIENT_PROGRESS) if (mysql.client_flag & CLIENT_PROGRESS_OBSOLETE)
mysql_options(&mysql, MYSQL_PROGRESS_CALLBACK, (void*) report_progress); mysql_options(&mysql, MYSQL_PROGRESS_CALLBACK, (void*) report_progress);
#else #else
mysql.reconnect= 1; {
my_bool reconnect= 1;
mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect);
}
#endif #endif
#ifdef HAVE_READLINE #ifdef HAVE_READLINE
build_completion_hash(opt_rehash, 1); build_completion_hash(opt_rehash, 1);
...@@ -5083,31 +5087,11 @@ void tee_putc(int c, FILE *file) ...@@ -5083,31 +5087,11 @@ void tee_putc(int c, FILE *file)
putc(c, OUTFILE); putc(c, OUTFILE);
} }
#if defined(__WIN__)
#include <time.h>
#else
#include <sys/times.h>
#ifdef _SC_CLK_TCK // For mit-pthreads
#undef CLOCKS_PER_SEC
#define CLOCKS_PER_SEC (sysconf(_SC_CLK_TCK))
#endif
#endif
static ulong start_timer(void)
{
#if defined(__WIN__)
return clock();
#else
struct tms tms_tmp;
return times(&tms_tmp);
#endif
}
/** /**
Write as many as 52+1 bytes to buff, in the form of a legible duration of time. Write as many as 52+1 bytes to buff, in the form of a legible duration of time.
len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds") -> 52 len("4294967296 days, 23 hours, 59 minutes, 60.000 seconds") -> 53
*/ */
static void nice_time(double sec,char *buff,bool part_second) static void nice_time(double sec,char *buff,bool part_second)
{ {
...@@ -5134,24 +5118,20 @@ static void nice_time(double sec,char *buff,bool part_second) ...@@ -5134,24 +5118,20 @@ static void nice_time(double sec,char *buff,bool part_second)
buff=strmov(buff," min "); buff=strmov(buff," min ");
} }
if (part_second) if (part_second)
sprintf(buff,"%.2f sec",sec); sprintf(buff,"%.3f sec",sec);
else else
sprintf(buff,"%d sec",(int) sec); sprintf(buff,"%d sec",(int) sec);
} }
static void end_timer(ulong start_time,char *buff) static void end_timer(ulonglong start_time, char *buff)
{ {
nice_time((double) (start_timer() - start_time) / double sec;
CLOCKS_PER_SEC,buff,1);
}
static void mysql_end_timer(ulong start_time,char *buff)
{
buff[0]=' '; buff[0]=' ';
buff[1]='('; buff[1]='(';
end_timer(start_time,buff+2); sec= (microsecond_interval_timer() - start_time) / (double) (1000 * 1000);
nice_time(sec, buff + 2, 1);
strmov(strend(buff),")"); strmov(strend(buff),")");
} }
...@@ -5191,17 +5171,31 @@ static const char *construct_prompt() ...@@ -5191,17 +5171,31 @@ static const char *construct_prompt()
processed_prompt.append("unknown"); processed_prompt.append("unknown");
break; break;
case 'h': case 'h':
case 'H':
{ {
const char *prompt; const char *prompt;
prompt= connected ? mysql_get_host_info(&mysql) : "not_connected"; prompt= connected ? mysql_get_host_info(&mysql) : "not_connected";
if (strstr(prompt, "Localhost")) if (strstr(prompt, "Localhost") || strstr(prompt, "localhost "))
processed_prompt.append("localhost"); {
else if (*c == 'h')
{ processed_prompt.append("localhost");
const char *end=strcend(prompt,' '); else
processed_prompt.append(prompt, (uint) (end-prompt)); {
} static char hostname[FN_REFLEN];
break; if (hostname[0])
processed_prompt.append(hostname);
else if (gethostname(hostname, sizeof(hostname)) == 0)
processed_prompt.append(hostname);
else
processed_prompt.append("gethostname(2) failed");
}
}
else
{
const char *end=strcend(prompt,' ');
processed_prompt.append(prompt, (uint) (end-prompt));
}
break;
} }
case 'p': case 'p':
{ {
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <mysql.h> #include <mysql.h>
#include <my_getopt.h> #include <my_getopt.h>
#include <my_dir.h> #include <my_dir.h>
#include <mysql_version.h>
#define SHOW_VERSION "1.0.0" #define SHOW_VERSION "1.0.0"
#define PRINT_VERSION do { printf("%s Ver %s Distrib %s\n", \ #define PRINT_VERSION do { printf("%s Ver %s Distrib %s\n", \
...@@ -158,8 +159,7 @@ static int make_tempfile(char *filename, const char *ext) ...@@ -158,8 +159,7 @@ static int make_tempfile(char *filename, const char *ext)
{ {
int fd= 0; int fd= 0;
if ((fd=create_temp_file(filename, NullS, ext, O_CREAT | O_WRONLY, if ((fd= create_temp_file(filename, NullS, ext, 0, MYF(MY_WME))) < 0)
MYF(MY_WME))) < 0)
{ {
fprintf(stderr, "ERROR: Cannot generate temporary file. Error code: %d.\n", fprintf(stderr, "ERROR: Cannot generate temporary file. Error code: %d.\n",
fd); fd);
...@@ -261,7 +261,7 @@ static char *convert_path(const char *argument) ...@@ -261,7 +261,7 @@ static char *convert_path(const char *argument)
/* Convert / to \\ to make Windows paths */ /* Convert / to \\ to make Windows paths */
char *winfilename= my_strdup(argument, MYF(MY_FAE)); char *winfilename= my_strdup(argument, MYF(MY_FAE));
char *pos, *end; char *pos, *end;
int length= strlen(argument); size_t length= strlen(argument);
for (pos= winfilename, end= pos+length ; pos < end ; pos++) for (pos= winfilename, end= pos+length ; pos < end ; pos++)
{ {
...@@ -364,6 +364,12 @@ static int get_default_values() ...@@ -364,6 +364,12 @@ static int get_default_values()
} }
/* Now open the file and read the defaults we want. */ /* Now open the file and read the defaults we want. */
file= fopen(defaults_file, "r"); file= fopen(defaults_file, "r");
if (file == NULL)
{
fprintf(stderr, "ERROR: failed to open file %s: %s.\n", defaults_file,
strerror(errno));
goto exit;
}
while (fgets(line, FN_REFLEN, file) != NULL) while (fgets(line, FN_REFLEN, file) != NULL)
{ {
char *value= 0; char *value= 0;
...@@ -711,11 +717,11 @@ static int check_options(int argc, char **argv, char *operation) ...@@ -711,11 +717,11 @@ static int check_options(int argc, char **argv, char *operation)
/* Form prefix strings for the options. */ /* Form prefix strings for the options. */
const char *basedir_prefix = "--basedir="; const char *basedir_prefix = "--basedir=";
int basedir_len= strlen(basedir_prefix); size_t basedir_len= strlen(basedir_prefix);
const char *datadir_prefix = "--datadir="; const char *datadir_prefix = "--datadir=";
int datadir_len= strlen(datadir_prefix); size_t datadir_len= strlen(datadir_prefix);
const char *plugin_dir_prefix = "--plugin_dir="; const char *plugin_dir_prefix = "--plugin_dir=";
int plugin_dir_len= strlen(plugin_dir_prefix); size_t plugin_dir_len= strlen(plugin_dir_prefix);
strcpy(plugin_name, ""); strcpy(plugin_name, "");
for (i = 0; i < argc && num_found < 5; i++) for (i = 0; i < argc && num_found < 5; i++)
......
...@@ -501,7 +501,7 @@ static void find_tool(char *tool_executable_name, const char *tool_name, ...@@ -501,7 +501,7 @@ static void find_tool(char *tool_executable_name, const char *tool_name,
last_fn_libchar -= 6; last_fn_libchar -= 6;
} }
len= last_fn_libchar - self_name; len= (int)(last_fn_libchar - self_name);
my_snprintf(tool_executable_name, FN_REFLEN, "%.*s%c%s", my_snprintf(tool_executable_name, FN_REFLEN, "%.*s%c%s",
len, self_name, FN_LIBCHAR, tool_name); len, self_name, FN_LIBCHAR, tool_name);
...@@ -558,8 +558,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res, ...@@ -558,8 +558,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res,
DBUG_PRINT("enter", ("query: %s", query)); DBUG_PRINT("enter", ("query: %s", query));
if ((fd= create_temp_file(query_file_path, if ((fd= create_temp_file(query_file_path,
opt_tmpdir[0] ? opt_tmpdir : NULL, opt_tmpdir[0] ? opt_tmpdir : NULL,
"sql", O_CREAT | O_SHARE | O_RDWR, "sql", O_SHARE, MYF(MY_WME))) < 0)
MYF(MY_WME))) < 0)
die("Failed to create temporary file for defaults"); die("Failed to create temporary file for defaults");
/* /*
...@@ -673,7 +672,7 @@ static int get_upgrade_info_file_name(char* name) ...@@ -673,7 +672,7 @@ static int get_upgrade_info_file_name(char* name)
*/ */
static int upgrade_already_done(void) static int upgrade_already_done(myf flags)
{ {
FILE *in; FILE *in;
char upgrade_info_file[FN_REFLEN]= {0}; char upgrade_info_file[FN_REFLEN]= {0};
...@@ -681,17 +680,23 @@ static int upgrade_already_done(void) ...@@ -681,17 +680,23 @@ static int upgrade_already_done(void)
if (get_upgrade_info_file_name(upgrade_info_file)) if (get_upgrade_info_file_name(upgrade_info_file))
return 0; /* Could not get filename => not sure */ return 0; /* Could not get filename => not sure */
if (!(in= my_fopen(upgrade_info_file, O_RDONLY, MYF(0)))) if (!(in= my_fopen(upgrade_info_file, O_RDONLY, flags)))
return 0; /* Could not open file => not sure */ return 0; /* Could not open file => not sure */
bzero(upgrade_from_version, sizeof(upgrade_from_version)); bzero(upgrade_from_version, sizeof(upgrade_from_version));
if (!fgets(upgrade_from_version, sizeof(upgrade_from_version), in)) if (!fgets(upgrade_from_version, sizeof(upgrade_from_version), in))
{ {
/* Ignore, will be detected by strncmp() below */ /* Preserve errno for caller */
int save_errno= errno;
(void) my_fclose(in, flags);
errno= save_errno;
return 0;
} }
my_fclose(in, MYF(0)); if (my_fclose(in, flags))
return 0;
errno= 0;
return (strncmp(upgrade_from_version, MYSQL_SERVER_VERSION, return (strncmp(upgrade_from_version, MYSQL_SERVER_VERSION,
sizeof(MYSQL_SERVER_VERSION)-1)==0); sizeof(MYSQL_SERVER_VERSION)-1)==0);
} }
...@@ -720,23 +725,24 @@ static void create_mysql_upgrade_info_file(void) ...@@ -720,23 +725,24 @@ static void create_mysql_upgrade_info_file(void)
{ {
fprintf(stderr, fprintf(stderr,
"Could not create the upgrade info file '%s' in " "Could not create the upgrade info file '%s' in "
"the MySQL Servers datadir, errno: %d\n", "the MariaDB Servers datadir, errno: %d\n",
upgrade_info_file, errno); upgrade_info_file, errno);
return; return;
} }
/* Write new version to file */ /* Write new version to file */
fputs(MYSQL_SERVER_VERSION, out); my_fwrite(out, (uchar*) MYSQL_SERVER_VERSION,
my_fclose(out, MYF(0)); sizeof(MYSQL_SERVER_VERSION), MY_WME);
my_fclose(out, MYF(MY_WME));
/* /*
Check if the upgrad_info_file was properly created/updated Check if the upgrad_info_file was properly created/updated
It's not a fatal error -> just print a message if it fails It's not a fatal error -> just print a message if it fails
*/ */
if (!upgrade_already_done()) if (!upgrade_already_done(MY_WME))
fprintf(stderr, fprintf(stderr,
"Could not write to the upgrade info file '%s' in " "Upgrade file '%s' was not properly created. "
"the MySQL Servers datadir, errno: %d\n", "Got error errno while checking file content: %d\n",
upgrade_info_file, errno); upgrade_info_file, errno);
return; return;
} }
...@@ -958,8 +964,9 @@ static int install_used_engines(void) ...@@ -958,8 +964,9 @@ static int install_used_engines(void)
{ {
char buf[512]; char buf[512];
DYNAMIC_STRING ds_result; DYNAMIC_STRING ds_result;
const char *query = "SELECT DISTINCT LOWER(engine) FROM information_schema.tables" const char *query = "SELECT DISTINCT LOWER(engine) AS c1 FROM information_schema.tables"
" WHERE table_comment LIKE 'Unknown storage engine%'"; " WHERE table_comment LIKE 'Unknown storage engine%'"
" ORDER BY c1";
if (opt_systables_only || !from_before_10_1()) if (opt_systables_only || !from_before_10_1())
{ {
...@@ -1136,7 +1143,7 @@ int main(int argc, char **argv) ...@@ -1136,7 +1143,7 @@ int main(int argc, char **argv)
load_defaults_or_exit("my", load_default_groups, &argc, &argv); load_defaults_or_exit("my", load_default_groups, &argc, &argv);
defaults_argv= argv; /* Must be freed by 'free_defaults' */ defaults_argv= argv; /* Must be freed by 'free_defaults' */
#if __WIN__ #if defined(__WIN__)
if (GetModuleFileName(NULL, self_name, FN_REFLEN) == 0) if (GetModuleFileName(NULL, self_name, FN_REFLEN) == 0)
#endif #endif
{ {
...@@ -1168,7 +1175,7 @@ int main(int argc, char **argv) ...@@ -1168,7 +1175,7 @@ int main(int argc, char **argv)
cnf_file_path= strmov(defaults_file, "--defaults-file="); cnf_file_path= strmov(defaults_file, "--defaults-file=");
{ {
int fd= create_temp_file(cnf_file_path, opt_tmpdir[0] ? opt_tmpdir : NULL, int fd= create_temp_file(cnf_file_path, opt_tmpdir[0] ? opt_tmpdir : NULL,
"mysql_upgrade-", O_CREAT | O_WRONLY, MYF(MY_FAE)); "mysql_upgrade-", 0, MYF(MY_FAE));
if (fd < 0) if (fd < 0)
die(NULL); die(NULL);
my_write(fd, USTRING_WITH_LEN( "[client]\n"), MYF(MY_FAE)); my_write(fd, USTRING_WITH_LEN( "[client]\n"), MYF(MY_FAE));
...@@ -1189,7 +1196,7 @@ int main(int argc, char **argv) ...@@ -1189,7 +1196,7 @@ int main(int argc, char **argv)
Read the mysql_upgrade_info file to check if mysql_upgrade Read the mysql_upgrade_info file to check if mysql_upgrade
already has been run for this installation of MySQL already has been run for this installation of MySQL
*/ */
if (!opt_force && upgrade_already_done()) if (!opt_force && upgrade_already_done(0))
{ {
printf("This installation of MySQL is already upgraded to %s, " printf("This installation of MySQL is already upgraded to %s, "
"use --force if you still need to run mysql_upgrade\n", "use --force if you still need to run mysql_upgrade\n",
......
...@@ -22,9 +22,10 @@ ...@@ -22,9 +22,10 @@
#include <my_pthread.h> /* because of signal() */ #include <my_pthread.h> /* because of signal() */
#include <sys/stat.h> #include <sys/stat.h>
#include <mysql.h> #include <mysql.h>
#include <sql_common.h> #include <mysql_version.h>
#include <welcome_copyright_notice.h> #include <welcome_copyright_notice.h>
#include <my_rnd.h> #include <my_rnd.h>
#include <password.h>
#define ADMIN_VERSION "9.1" #define ADMIN_VERSION "9.1"
#define MAX_MYSQL_VAR 512 #define MAX_MYSQL_VAR 512
...@@ -33,9 +34,9 @@ ...@@ -33,9 +34,9 @@
char *host= NULL, *user= 0, *opt_password= 0, char *host= NULL, *user= 0, *opt_password= 0,
*default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME; *default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME;
char truncated_var_names[MAX_MYSQL_VAR][MAX_TRUNC_LENGTH]; char truncated_var_names[MAX_MYSQL_VAR+100][MAX_TRUNC_LENGTH];
char ex_var_names[MAX_MYSQL_VAR][FN_REFLEN]; char ex_var_names[MAX_MYSQL_VAR+100][FN_REFLEN];
ulonglong last_values[MAX_MYSQL_VAR]; ulonglong last_values[MAX_MYSQL_VAR+100];
static int interval=0; static int interval=0;
static my_bool option_force=0,interrupted=0,new_line=0, static my_bool option_force=0,interrupted=0,new_line=0,
opt_compress= 0, opt_local= 0, opt_relative= 0, opt_verbose= 0, opt_compress= 0, opt_local= 0, opt_relative= 0, opt_verbose= 0,
...@@ -451,7 +452,7 @@ int main(int argc,char *argv[]) ...@@ -451,7 +452,7 @@ int main(int argc,char *argv[])
didn't signal for us to die. Otherwise, signal failure. didn't signal for us to die. Otherwise, signal failure.
*/ */
if (mysql.net.vio == 0) if (mysql.net.pvio == 0)
{ {
if (option_wait && !interrupted) if (option_wait && !interrupted)
{ {
...@@ -530,7 +531,8 @@ static my_bool sql_connect(MYSQL *mysql, uint wait) ...@@ -530,7 +531,8 @@ static my_bool sql_connect(MYSQL *mysql, uint wait)
if (mysql_real_connect(mysql,host,user,opt_password,NullS,tcp_port, if (mysql_real_connect(mysql,host,user,opt_password,NullS,tcp_port,
unix_port, CLIENT_REMEMBER_OPTIONS)) unix_port, CLIENT_REMEMBER_OPTIONS))
{ {
mysql->reconnect= 1; my_bool reconnect= 1;
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
if (info) if (info)
{ {
fputs("\n",stderr); fputs("\n",stderr);
...@@ -884,7 +886,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv) ...@@ -884,7 +886,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
return -1; return -1;
} }
DBUG_ASSERT(mysql_num_rows(res) < MAX_MYSQL_VAR); DBUG_ASSERT(mysql_num_rows(res) < MAX_MYSQL_VAR+100);
if (!opt_vertical) if (!opt_vertical)
print_header(res); print_header(res);
...@@ -1179,9 +1181,9 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv) ...@@ -1179,9 +1181,9 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
} }
} }
if (old) if (old)
make_scrambled_password_323(crypted_pw, typed_password); my_make_scrambled_password_323(crypted_pw, typed_password, strlen(typed_password));
else else
make_scrambled_password(crypted_pw, typed_password); my_make_scrambled_password(crypted_pw, typed_password, strlen(typed_password));
} }
else else
crypted_pw[0]=0; /* No password */ crypted_pw[0]=0; /* No password */
...@@ -1290,7 +1292,9 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv) ...@@ -1290,7 +1292,9 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
break; break;
} }
case ADMIN_PING: case ADMIN_PING:
mysql->reconnect=0; /* We want to know of reconnects */ {
my_bool reconnect= 0;
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
if (!mysql_ping(mysql)) if (!mysql_ping(mysql))
{ {
if (option_silent < 2) if (option_silent < 2)
...@@ -1300,7 +1304,8 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv) ...@@ -1300,7 +1304,8 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
{ {
if (mysql_errno(mysql) == CR_SERVER_GONE_ERROR) if (mysql_errno(mysql) == CR_SERVER_GONE_ERROR)
{ {
mysql->reconnect=1; reconnect= 1;
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
if (!mysql_ping(mysql)) if (!mysql_ping(mysql))
puts("connection was down, but mysqld is now alive"); puts("connection was down, but mysqld is now alive");
} }
...@@ -1311,8 +1316,10 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv) ...@@ -1311,8 +1316,10 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
return -1; return -1;
} }
} }
mysql->reconnect=1; /* Automatic reconnect is default */ reconnect=1; /* Automatic reconnect is default */
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
break; break;
}
default: default:
my_printf_error(0, "Unknown command: '%-.60s'", error_flags, argv[0]); my_printf_error(0, "Unknown command: '%-.60s'", error_flags, argv[0]);
return 1; return 1;
......
This diff is collapsed.
...@@ -541,7 +541,7 @@ static int process_selected_tables(char *db, char **table_names, int tables) ...@@ -541,7 +541,7 @@ static int process_selected_tables(char *db, char **table_names, int tables)
{ {
int view; int view;
char *table; char *table;
uint table_len; size_t table_len;
DBUG_ENTER("process_selected_tables"); DBUG_ENTER("process_selected_tables");
if (use_db(db)) if (use_db(db))
...@@ -585,6 +585,7 @@ static int process_selected_tables(char *db, char **table_names, int tables) ...@@ -585,6 +585,7 @@ static int process_selected_tables(char *db, char **table_names, int tables)
my_free(table_names_comma_sep); my_free(table_names_comma_sep);
} }
else else
{
for (; tables > 0; tables--, table_names++) for (; tables > 0; tables--, table_names++)
{ {
table= *table_names; table= *table_names;
...@@ -594,6 +595,7 @@ static int process_selected_tables(char *db, char **table_names, int tables) ...@@ -594,6 +595,7 @@ static int process_selected_tables(char *db, char **table_names, int tables)
continue; continue;
handle_request_for_tables(table, table_len, view == 1, opt_all_in_1); handle_request_for_tables(table, table_len, view == 1, opt_all_in_1);
} }
}
DBUG_RETURN(0); DBUG_RETURN(0);
} /* process_selected_tables */ } /* process_selected_tables */
...@@ -667,7 +669,7 @@ static int process_all_tables_in_db(char *database) ...@@ -667,7 +669,7 @@ static int process_all_tables_in_db(char *database)
size_t tot_length = 0; size_t tot_length = 0;
char *views, *views_end; char *views, *views_end;
uint tot_views_length = 0; size_t tot_views_length = 0;
while ((row = mysql_fetch_row(res))) while ((row = mysql_fetch_row(res)))
{ {
...@@ -913,16 +915,29 @@ static int handle_request_for_tables(char *tables, size_t length, ...@@ -913,16 +915,29 @@ static int handle_request_for_tables(char *tables, size_t length,
} }
break; break;
case DO_ANALYZE: case DO_ANALYZE:
if (view)
{
printf("%-50s %s\n", tables, "Can't run anaylyze on a view");
DBUG_RETURN(1);
}
DBUG_ASSERT(!view); DBUG_ASSERT(!view);
op= (opt_write_binlog) ? "ANALYZE" : "ANALYZE NO_WRITE_TO_BINLOG"; op= (opt_write_binlog) ? "ANALYZE" : "ANALYZE NO_WRITE_TO_BINLOG";
if (opt_persistent_all) end = strmov(end, " PERSISTENT FOR ALL"); if (opt_persistent_all) end = strmov(end, " PERSISTENT FOR ALL");
break; break;
case DO_OPTIMIZE: case DO_OPTIMIZE:
DBUG_ASSERT(!view); if (view)
{
printf("%-50s %s\n", tables, "Can't run optimize on a view");
DBUG_RETURN(1);
}
op= (opt_write_binlog) ? "OPTIMIZE" : "OPTIMIZE NO_WRITE_TO_BINLOG"; op= (opt_write_binlog) ? "OPTIMIZE" : "OPTIMIZE NO_WRITE_TO_BINLOG";
break; break;
case DO_FIX_NAMES: case DO_FIX_NAMES:
DBUG_ASSERT(!view); if (view)
{
printf("%-50s %s\n", tables, "Can't run fix names on a view");
DBUG_RETURN(1);
}
DBUG_RETURN(fix_table_storage_name(tables)); DBUG_RETURN(fix_table_storage_name(tables));
} }
...@@ -951,7 +966,7 @@ static int handle_request_for_tables(char *tables, size_t length, ...@@ -951,7 +966,7 @@ static int handle_request_for_tables(char *tables, size_t length,
} }
if (verbose >= 3) if (verbose >= 3)
puts(query); puts(query);
if (mysql_real_query(sock, query, query_length)) if (mysql_real_query(sock, query, (ulong)query_length))
{ {
sprintf(message, "when executing '%s%s... %s'", op, tab_view, options); sprintf(message, "when executing '%s%s... %s'", op, tab_view, options);
DBerror(sock, message); DBerror(sock, message);
...@@ -962,7 +977,7 @@ static int handle_request_for_tables(char *tables, size_t length, ...@@ -962,7 +977,7 @@ static int handle_request_for_tables(char *tables, size_t length,
if (opt_flush_tables) if (opt_flush_tables)
{ {
query_length= sprintf(query, "FLUSH TABLES %s", table_name); query_length= sprintf(query, "FLUSH TABLES %s", table_name);
if (mysql_real_query(sock, query, query_length)) if (mysql_real_query(sock, query, (ulong)query_length))
{ {
DBerror(sock, query); DBerror(sock, query);
my_free(query); my_free(query);
...@@ -1077,6 +1092,7 @@ static void print_result() ...@@ -1077,6 +1092,7 @@ static void print_result()
static int dbConnect(char *host, char *user, char *passwd) static int dbConnect(char *host, char *user, char *passwd)
{ {
my_bool reconnect= 1;
DBUG_ENTER("dbConnect"); DBUG_ENTER("dbConnect");
if (verbose > 1) if (verbose > 1)
{ {
...@@ -1115,7 +1131,7 @@ static int dbConnect(char *host, char *user, char *passwd) ...@@ -1115,7 +1131,7 @@ static int dbConnect(char *host, char *user, char *passwd)
DBerror(&mysql_connection, "when trying to connect"); DBerror(&mysql_connection, "when trying to connect");
DBUG_RETURN(1); DBUG_RETURN(1);
} }
mysql_connection.reconnect= 1; mysql_options(&mysql_connection, MYSQL_OPT_RECONNECT, &reconnect);
DBUG_RETURN(0); DBUG_RETURN(0);
} /* dbConnect */ } /* dbConnect */
......
This diff is collapsed.
...@@ -413,7 +413,7 @@ static void lock_table(MYSQL *mysql, int tablecount, char **raw_tablename) ...@@ -413,7 +413,7 @@ static void lock_table(MYSQL *mysql, int tablecount, char **raw_tablename)
dynstr_append(&query, tablename); dynstr_append(&query, tablename);
dynstr_append(&query, " WRITE,"); dynstr_append(&query, " WRITE,");
} }
if (mysql_real_query(mysql, query.str, query.length-1)) if (mysql_real_query(mysql, query.str, (ulong)query.length-1))
db_error(mysql); /* We shall countinue here, if --force was given */ db_error(mysql); /* We shall countinue here, if --force was given */
} }
...@@ -424,6 +424,7 @@ static MYSQL *db_connect(char *host, char *database, ...@@ -424,6 +424,7 @@ static MYSQL *db_connect(char *host, char *database,
char *user, char *passwd) char *user, char *passwd)
{ {
MYSQL *mysql; MYSQL *mysql;
my_bool reconnect;
if (verbose) if (verbose)
fprintf(stdout, "Connecting to %s\n", host ? host : "localhost"); fprintf(stdout, "Connecting to %s\n", host ? host : "localhost");
if (opt_use_threads && !lock_tables) if (opt_use_threads && !lock_tables)
...@@ -479,7 +480,8 @@ static MYSQL *db_connect(char *host, char *database, ...@@ -479,7 +480,8 @@ static MYSQL *db_connect(char *host, char *database,
ignore_errors=0; /* NO RETURN FROM db_error */ ignore_errors=0; /* NO RETURN FROM db_error */
db_error(mysql); db_error(mysql);
} }
mysql->reconnect= 0; reconnect= 0;
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
if (verbose) if (verbose)
fprintf(stdout, "Selecting database %s\n", database); fprintf(stdout, "Selecting database %s\n", database);
if (mysql_select_db(mysql, database)) if (mysql_select_db(mysql, database))
......
...@@ -68,6 +68,7 @@ int main(int argc, char **argv) ...@@ -68,6 +68,7 @@ int main(int argc, char **argv)
my_bool first_argument_uses_wildcards=0; my_bool first_argument_uses_wildcards=0;
char *wild; char *wild;
MYSQL mysql; MYSQL mysql;
my_bool reconnect;
static char **defaults_argv; static char **defaults_argv;
MY_INIT(argv[0]); MY_INIT(argv[0]);
sf_leaking_memory=1; /* don't report memory leaks on early exits */ sf_leaking_memory=1; /* don't report memory leaks on early exits */
...@@ -154,7 +155,8 @@ int main(int argc, char **argv) ...@@ -154,7 +155,8 @@ int main(int argc, char **argv)
error= 1; error= 1;
goto error; goto error;
} }
mysql.reconnect= 1; reconnect= 1;
mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect);
switch (argc) { switch (argc) {
case 0: error=list_dbs(&mysql,wild); break; case 0: error=list_dbs(&mysql,wild); break;
...@@ -658,7 +660,7 @@ static int ...@@ -658,7 +660,7 @@ static int
list_table_status(MYSQL *mysql,const char *db,const char *wild) list_table_status(MYSQL *mysql,const char *db,const char *wild)
{ {
char query[NAME_LEN + 100]; char query[NAME_LEN + 100];
int len; size_t len;
MYSQL_RES *result; MYSQL_RES *result;
MYSQL_ROW row; MYSQL_ROW row;
...@@ -905,7 +907,7 @@ static void print_res_header(MYSQL_RES *result) ...@@ -905,7 +907,7 @@ static void print_res_header(MYSQL_RES *result)
static void print_res_top(MYSQL_RES *result) static void print_res_top(MYSQL_RES *result)
{ {
uint i,length; size_t i,length;
MYSQL_FIELD *field; MYSQL_FIELD *field;
putchar('+'); putchar('+');
...@@ -913,7 +915,7 @@ static void print_res_top(MYSQL_RES *result) ...@@ -913,7 +915,7 @@ static void print_res_top(MYSQL_RES *result)
while((field = mysql_fetch_field(result))) while((field = mysql_fetch_field(result)))
{ {
if ((length= strlen(field->name)) > field->max_length) if ((length= strlen(field->name)) > field->max_length)
field->max_length=length; field->max_length=(ulong)length;
else else
length=field->max_length; length=field->max_length;
for (i=length+2 ; i--> 0 ; ) for (i=length+2 ; i--> 0 ; )
......
...@@ -144,7 +144,7 @@ static unsigned long connect_flags= CLIENT_MULTI_RESULTS | ...@@ -144,7 +144,7 @@ static unsigned long connect_flags= CLIENT_MULTI_RESULTS |
CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_STATEMENTS |
CLIENT_REMEMBER_OPTIONS; CLIENT_REMEMBER_OPTIONS;
static int verbose, delimiter_length; static int verbose;
static uint commit_rate; static uint commit_rate;
static uint detach_rate; static uint detach_rate;
const char *num_int_cols_opt; const char *num_int_cols_opt;
...@@ -263,7 +263,7 @@ void option_cleanup(option_string *stmt); ...@@ -263,7 +263,7 @@ void option_cleanup(option_string *stmt);
void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr); void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr);
static int run_statements(MYSQL *mysql, statement *stmt); static int run_statements(MYSQL *mysql, statement *stmt);
int slap_connect(MYSQL *mysql); int slap_connect(MYSQL *mysql);
static int run_query(MYSQL *mysql, const char *query, int len); static int run_query(MYSQL *mysql, const char *query, size_t len);
static const char ALPHANUMERICS[]= static const char ALPHANUMERICS[]=
"0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz"; "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
...@@ -339,9 +339,6 @@ int main(int argc, char **argv) ...@@ -339,9 +339,6 @@ int main(int argc, char **argv)
if (auto_generate_sql) if (auto_generate_sql)
srandom((uint)time(NULL)); srandom((uint)time(NULL));
/* globals? Yes, so we only have to run strlen once */
delimiter_length= strlen(delimiter);
if (argc > 2) if (argc > 2)
{ {
fprintf(stderr,"%s: Too many arguments\n",my_progname); fprintf(stderr,"%s: Too many arguments\n",my_progname);
...@@ -583,8 +580,8 @@ static struct my_option my_long_options[] = ...@@ -583,8 +580,8 @@ static struct my_option my_long_options[] =
&auto_generate_sql_number, &auto_generate_sql_number, &auto_generate_sql_number, &auto_generate_sql_number,
0, GET_ULL, REQUIRED_ARG, 100, 0, 0, 0, 0, 0}, 0, GET_ULL, REQUIRED_ARG, 100, 0, 0, 0, 0, 0},
{"character-sets-dir", OPT_CHARSETS_DIR, {"character-sets-dir", OPT_CHARSETS_DIR,
"Directory for character set files.", &charsets_dir, "Directory for character set files.", (char **)&charsets_dir,
&charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, (char **)&charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"commit", OPT_SLAP_COMMIT, "Commit records every X number of statements.", {"commit", OPT_SLAP_COMMIT, "Commit records every X number of statements.",
&commit_rate, &commit_rate, 0, GET_UINT, REQUIRED_ARG, &commit_rate, &commit_rate, 0, GET_UINT, REQUIRED_ARG,
0, 0, 0, 0, 0, 0}, 0, 0, 0, 0, 0, 0},
...@@ -817,7 +814,7 @@ get_random_string(char *buf) ...@@ -817,7 +814,7 @@ get_random_string(char *buf)
DBUG_ENTER("get_random_string"); DBUG_ENTER("get_random_string");
for (x= RAND_STRING_SIZE; x > 0; x--) for (x= RAND_STRING_SIZE; x > 0; x--)
*buf_ptr++= ALPHANUMERICS[random() % ALPHANUMERICS_SIZE]; *buf_ptr++= ALPHANUMERICS[random() % ALPHANUMERICS_SIZE];
DBUG_RETURN(buf_ptr - buf); DBUG_RETURN((uint)(buf_ptr - buf));
} }
...@@ -1548,18 +1545,18 @@ get_options(int *argc,char ***argv) ...@@ -1548,18 +1545,18 @@ get_options(int *argc,char ***argv)
} }
static int run_query(MYSQL *mysql, const char *query, int len) static int run_query(MYSQL *mysql, const char *query, size_t len)
{ {
if (opt_only_print) if (opt_only_print)
{ {
printf("%.*s;\n", len, query); printf("%.*s;\n", (int)len, query);
return 0; return 0;
} }
if (verbose >= 3) if (verbose >= 3)
printf("%.*s;\n", len, query); printf("%.*s;\n", (int)len, query);
return mysql_real_query(mysql, query, len); return mysql_real_query(mysql, query, (ulong)len);
} }
...@@ -2127,7 +2124,7 @@ parse_delimiter(const char *script, statement **stmt, char delm) ...@@ -2127,7 +2124,7 @@ parse_delimiter(const char *script, statement **stmt, char delm)
char *ptr= (char *)script; char *ptr= (char *)script;
statement **sptr= stmt; statement **sptr= stmt;
statement *tmp; statement *tmp;
uint length= strlen(script); size_t length= strlen(script);
uint count= 0; /* We know that there is always one */ uint count= 0; /* We know that there is always one */
for (tmp= *sptr= (statement *)my_malloc(sizeof(statement), for (tmp= *sptr= (statement *)my_malloc(sizeof(statement),
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment