summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/CMakeLists.txt64
-rw-r--r--client/client_metadata.h57
-rw-r--r--client/client_priv.h2
-rw-r--r--client/completion_hash.cc6
-rw-r--r--client/mariadb-conv.cc481
-rw-r--r--client/mysql.cc90
-rw-r--r--client/mysql_plugin.c49
-rw-r--r--client/mysql_upgrade.c21
-rw-r--r--client/mysqladmin.cc13
-rw-r--r--client/mysqlbinlog.cc40
-rw-r--r--client/mysqlcheck.c35
-rw-r--r--client/mysqldump.c125
-rw-r--r--client/mysqlimport.c13
-rw-r--r--client/mysqlshow.c8
-rw-r--r--client/mysqlslap.c80
-rw-r--r--client/mysqltest.cc273
-rw-r--r--client/readline.cc18
-rw-r--r--client/sql_string.cc.dontuse836
-rw-r--r--client/sql_string.h.dontuse366
19 files changed, 1024 insertions, 1553 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
index 63e4cf36b00..36288900b8f 100644
--- a/client/CMakeLists.txt
+++ b/client/CMakeLists.txt
@@ -36,49 +36,53 @@ COPY_OPENSSL_DLLS(copy_openssl_client)
SET(CLIENT_LIB mariadbclient mysys)
ADD_DEFINITIONS(${SSL_DEFINES})
-MYSQL_ADD_EXECUTABLE(mysql completion_hash.cc mysql.cc readline.cc
+MYSQL_ADD_EXECUTABLE(mariadb completion_hash.cc mysql.cc readline.cc
${CMAKE_SOURCE_DIR}/sql/sql_string.cc)
-TARGET_LINK_LIBRARIES(mysql ${CLIENT_LIB})
+TARGET_LINK_LIBRARIES(mariadb ${CLIENT_LIB})
IF(UNIX)
- TARGET_LINK_LIBRARIES(mysql ${MY_READLINE_LIBRARY})
- SET_TARGET_PROPERTIES(mysql PROPERTIES ENABLE_EXPORTS TRUE)
+ TARGET_LINK_LIBRARIES(mariadb ${MY_READLINE_LIBRARY})
+ SET_TARGET_PROPERTIES(mariadb PROPERTIES ENABLE_EXPORTS TRUE)
ENDIF(UNIX)
-MYSQL_ADD_EXECUTABLE(mysqltest mysqltest.cc COMPONENT Test)
-SET_SOURCE_FILES_PROPERTIES(mysqltest.cc PROPERTIES COMPILE_FLAGS "-DTHREADS")
-TARGET_LINK_LIBRARIES(mysqltest ${CLIENT_LIB} pcreposix pcre)
-SET_TARGET_PROPERTIES(mysqltest PROPERTIES ENABLE_EXPORTS TRUE)
+MYSQL_ADD_EXECUTABLE(mariadb-test mysqltest.cc ${CMAKE_SOURCE_DIR}/sql/sql_string.cc COMPONENT Test)
+SET_SOURCE_FILES_PROPERTIES(mysqltest.cc PROPERTIES COMPILE_FLAGS "-DTHREADS ${PCRE2_DEBIAN_HACK}")
+TARGET_LINK_LIBRARIES(mariadb-test ${CLIENT_LIB} pcre2-posix pcre2-8)
+SET_TARGET_PROPERTIES(mariadb-test PROPERTIES ENABLE_EXPORTS TRUE)
-MYSQL_ADD_EXECUTABLE(mysqlcheck mysqlcheck.c)
-TARGET_LINK_LIBRARIES(mysqlcheck ${CLIENT_LIB})
+MYSQL_ADD_EXECUTABLE(mariadb-check mysqlcheck.c)
+TARGET_LINK_LIBRARIES(mariadb-check ${CLIENT_LIB})
-MYSQL_ADD_EXECUTABLE(mysqldump mysqldump.c ../sql-common/my_user.c)
-TARGET_LINK_LIBRARIES(mysqldump ${CLIENT_LIB})
+MYSQL_ADD_EXECUTABLE(mariadb-dump mysqldump.c ../sql-common/my_user.c)
+TARGET_LINK_LIBRARIES(mariadb-dump ${CLIENT_LIB})
-MYSQL_ADD_EXECUTABLE(mysqlimport mysqlimport.c)
+MYSQL_ADD_EXECUTABLE(mariadb-import mysqlimport.c)
SET_SOURCE_FILES_PROPERTIES(mysqlimport.c PROPERTIES COMPILE_FLAGS "-DTHREADS")
-TARGET_LINK_LIBRARIES(mysqlimport ${CLIENT_LIB})
+TARGET_LINK_LIBRARIES(mariadb-import ${CLIENT_LIB})
-MYSQL_ADD_EXECUTABLE(mysql_upgrade mysql_upgrade.c COMPONENT Server)
-TARGET_LINK_LIBRARIES(mysql_upgrade ${CLIENT_LIB})
-ADD_DEPENDENCIES(mysql_upgrade GenFixPrivs)
+MYSQL_ADD_EXECUTABLE(mariadb-upgrade mysql_upgrade.c COMPONENT Server)
+TARGET_LINK_LIBRARIES(mariadb-upgrade ${CLIENT_LIB})
+ADD_DEPENDENCIES(mariadb-upgrade GenFixPrivs)
-MYSQL_ADD_EXECUTABLE(mysqlshow mysqlshow.c)
-TARGET_LINK_LIBRARIES(mysqlshow ${CLIENT_LIB})
+MYSQL_ADD_EXECUTABLE(mariadb-show mysqlshow.c)
+TARGET_LINK_LIBRARIES(mariadb-show ${CLIENT_LIB})
-MYSQL_ADD_EXECUTABLE(mysql_plugin mysql_plugin.c)
-TARGET_LINK_LIBRARIES(mysql_plugin ${CLIENT_LIB})
+MYSQL_ADD_EXECUTABLE(mariadb-plugin mysql_plugin.c)
+TARGET_LINK_LIBRARIES(mariadb-plugin ${CLIENT_LIB})
-MYSQL_ADD_EXECUTABLE(mysqlbinlog mysqlbinlog.cc)
-TARGET_LINK_LIBRARIES(mysqlbinlog ${CLIENT_LIB} mysys_ssl)
+MYSQL_ADD_EXECUTABLE(mariadb-binlog mysqlbinlog.cc)
+TARGET_LINK_LIBRARIES(mariadb-binlog ${CLIENT_LIB} mysys_ssl)
-MYSQL_ADD_EXECUTABLE(mysqladmin mysqladmin.cc ../sql/password.c)
-TARGET_LINK_LIBRARIES(mysqladmin ${CLIENT_LIB} mysys_ssl)
+MYSQL_ADD_EXECUTABLE(mariadb-admin mysqladmin.cc ../sql/password.c)
+TARGET_LINK_LIBRARIES(mariadb-admin ${CLIENT_LIB} mysys_ssl)
-MYSQL_ADD_EXECUTABLE(mysqlslap mysqlslap.c)
+MYSQL_ADD_EXECUTABLE(mariadb-slap mysqlslap.c)
SET_SOURCE_FILES_PROPERTIES(mysqlslap.c PROPERTIES COMPILE_FLAGS "-DTHREADS")
-TARGET_LINK_LIBRARIES(mysqlslap ${CLIENT_LIB})
+TARGET_LINK_LIBRARIES(mariadb-slap ${CLIENT_LIB})
+
+MYSQL_ADD_EXECUTABLE(mariadb-conv mariadb-conv.cc
+ ${CMAKE_SOURCE_DIR}/sql/sql_string.cc)
+TARGET_LINK_LIBRARIES(mariadb-conv mysys strings)
# "WIN32" also covers 64 bit. "echo" is used in some files below "mysql-test/".
IF(WIN32)
@@ -89,11 +93,11 @@ ENDIF(WIN32)
ADD_EXECUTABLE(async_example async_example.c)
TARGET_LINK_LIBRARIES(async_example ${CLIENT_LIB})
-SET_TARGET_PROPERTIES (mysqlcheck mysqldump mysqlimport mysql_upgrade mysqlshow mysqlslap mysql_plugin async_example
+SET_TARGET_PROPERTIES (mariadb-check mariadb-dump mariadb-import mariadb-upgrade mariadb-show mariadb-slap mariadb-plugin async_example
PROPERTIES HAS_CXX TRUE)
-FOREACH(t mysql mysqltest mysqlcheck mysqldump mysqlimport mysql_upgrade mysqlshow mysql_plugin mysqlbinlog
- mysqladmin mysqlslap async_example)
+FOREACH(t mariadb mariadb-test mariadb-check mariadb-dump mariadb-import mariadb-upgrade mariadb-show mariadb-plugin mariadb-binlog
+ mariadb-admin mariadb-slap async_example)
ADD_DEPENDENCIES(${t} GenError ${CLIENT_LIB})
ENDFOREACH()
diff --git a/client/client_metadata.h b/client/client_metadata.h
new file mode 100644
index 00000000000..49921f01885
--- /dev/null
+++ b/client/client_metadata.h
@@ -0,0 +1,57 @@
+#ifndef SQL_CLIENT_METADATA_INCLUDED
+#define SQL_CLIENT_METADATA_INCLUDED
+/*
+ Copyright (c) 2020, MariaDB Corporation.
+
+ 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 St, Fifth Floor, Boston, MA 02110-1335 USA */
+
+#include "sql_string.h"
+
+
+/*
+ Print MYSQL_FIELD metadata in human readable format
+*/
+class Client_field_metadata
+{
+ const MYSQL_FIELD *m_field;
+public:
+ Client_field_metadata(MYSQL_FIELD *field)
+ :m_field(field)
+ { }
+ void print_attr(Binary_string *to,
+ const LEX_CSTRING &name,
+ mariadb_field_attr_t attr,
+ uint orig_to_length) const
+ {
+ MARIADB_CONST_STRING tmp;
+ if (!mariadb_field_attr(&tmp, m_field, attr) && tmp.length)
+ {
+ if (to->length() != orig_to_length)
+ to->append(" ", 1);
+ to->append(name);
+ to->append(tmp.str, tmp.length);
+ }
+ }
+ void print_data_type_related_attributes(Binary_string *to) const
+ {
+ static const LEX_CSTRING type= {C_STRING_WITH_LEN("type=")};
+ static const LEX_CSTRING format= {C_STRING_WITH_LEN("format=")};
+ uint to_length_orig= to->length();
+ print_attr(to, type, MARIADB_FIELD_ATTR_DATA_TYPE_NAME, to_length_orig);
+ print_attr(to, format, MARIADB_FIELD_ATTR_FORMAT_NAME, to_length_orig);
+ }
+};
+
+
+#endif // SQL_CLIENT_METADATA_INCLUDED
diff --git a/client/client_priv.h b/client/client_priv.h
index 7a6fa8f3bc8..0f2cec47a08 100644
--- a/client/client_priv.h
+++ b/client/client_priv.h
@@ -102,6 +102,8 @@ enum options_client
OPT_IGNORE_DATA,
OPT_PRINT_ROW_COUNT, OPT_PRINT_ROW_EVENT_POSITIONS,
OPT_SHUTDOWN_WAIT_FOR_SLAVES,
+ OPT_COPY_S3_TABLES,
+ OPT_PRINT_TABLE_METADATA,
OPT_MAX_CLIENT_OPTION /* should be always the last */
};
diff --git a/client/completion_hash.cc b/client/completion_hash.cc
index 0d88aa9b15e..0bfb4e879e4 100644
--- a/client/completion_hash.cc
+++ b/client/completion_hash.cc
@@ -41,15 +41,15 @@ uint hashpjw(const char *arKey, uint nKeyLength)
int completion_hash_init(HashTable *ht, uint nSize)
{
- ht->arBuckets = (Bucket **) my_malloc(nSize* sizeof(Bucket *),
- MYF(MY_ZEROFILL | MY_WME));
+ ht->arBuckets = (Bucket **) my_malloc(PSI_NOT_INSTRUMENTED,
+ nSize* sizeof(Bucket *), MYF(MY_ZEROFILL | MY_WME));
if (!ht->arBuckets)
{
ht->initialized = 0;
return FAILURE;
}
- init_alloc_root(&ht->mem_root, "completion_hash", 8192, 0, MYF(0));
+ init_alloc_root(PSI_NOT_INSTRUMENTED, &ht->mem_root, 8192, 0, MYF(0));
ht->pHashFunction = hashpjw;
ht->nTableSize = nSize;
ht->initialized = 1;
diff --git a/client/mariadb-conv.cc b/client/mariadb-conv.cc
new file mode 100644
index 00000000000..03018a93dbc
--- /dev/null
+++ b/client/mariadb-conv.cc
@@ -0,0 +1,481 @@
+/*
+ Copyright (c) 2001, 2013, Oracle and/or its affiliates.
+ Copyright (c) 2010, 2019, MariaDB
+
+ 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+/*
+ Character set conversion utility
+*/
+
+#include "mariadb.h"
+#include "client_priv.h"
+#include "sql_string.h"
+#include "my_dir.h"
+
+#define CONV_VERSION "1.0"
+
+
+class CmdOpt
+{
+public:
+ const char *m_charset_from;
+ const char *m_charset_to;
+ const char *m_delimiter;
+ my_bool m_continue;
+ CmdOpt()
+ :m_charset_from("latin1"),
+ m_charset_to("latin1"),
+ m_delimiter(NULL),
+ m_continue(FALSE)
+ { }
+ static CHARSET_INFO *csinfo_by_name(const char *csname)
+ {
+ return get_charset_by_csname(csname, MY_CS_PRIMARY, MYF(0));
+ }
+ CHARSET_INFO *csinfo_from() const
+ {
+ return m_charset_from ? csinfo_by_name(m_charset_from) : NULL;
+ }
+ CHARSET_INFO *csinfo_to() const
+ {
+ return m_charset_to ? csinfo_by_name(m_charset_to) : NULL;
+ }
+};
+
+
+static CmdOpt opt;
+
+
+static struct my_option long_options[] =
+{
+ {"from", 'f', "Specifies the encoding of the input.", &opt.m_charset_from,
+ &opt.m_charset_from, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"to", 't', "Specifies the encoding of the output.", &opt.m_charset_to,
+ &opt.m_charset_to, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"continue", 'c', "Silently ignore conversion errors.",
+ &opt.m_continue, &opt.m_continue, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"delimiter", 0, "Treat the specified characters as delimiters.",
+ &opt.m_delimiter, &opt.m_delimiter, 0, GET_STR, REQUIRED_ARG,
+ 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
+};
+
+
+my_bool
+get_one_option(const struct my_option *opt,
+ char *value, const char *filename)
+{
+ return 0;
+}
+
+
+class File_buffer: public Binary_string
+{
+public:
+ bool load_binary_stream(FILE *file);
+ bool load_binary_file_by_name(const char *file);
+};
+
+
+/*
+ Load data from a binary stream whose length is not known in advance,
+ e.g. from stdin.
+*/
+bool File_buffer::load_binary_stream(FILE *file)
+{
+ for ( ; ; )
+ {
+ char buf[1024];
+ if (length() + sizeof(buf) > UINT_MAX32 || reserve(sizeof(buf)))
+ {
+ fprintf(stderr, "Input data is too large\n");
+ return true;
+ }
+ size_t nbytes= my_fread(file, (uchar *) end(), sizeof(buf), MYF(0));
+ if (!nbytes || nbytes == (size_t) -1)
+ return false;
+ str_length+= (uint32) nbytes;
+ }
+ return false;
+}
+
+
+/*
+ Load data from a file by name.
+ The file size is know.
+*/
+bool File_buffer::load_binary_file_by_name(const char *filename)
+{
+ MY_STAT sbuf;
+ File fd;
+
+ if (!my_stat(filename, &sbuf, MYF(0)))
+ {
+ fprintf(stderr, "my_stat failed for '%s'\n", filename);
+ return true;
+ }
+
+ if (!MY_S_ISREG(sbuf.st_mode))
+ {
+ fprintf(stderr, "'%s' is not a regular file\n", filename);
+ return true;
+ }
+
+ if ((size_t) sbuf.st_size > UINT_MAX32)
+ {
+ fprintf(stderr, "File '%s' is too large\n", filename);
+ return true;
+ }
+
+ if (alloc((uint32) sbuf.st_size))
+ {
+ fprintf(stderr, "Failed to allocate read buffer\n");
+ return true;
+ }
+
+ if ((fd= my_open(filename, O_RDONLY, MYF(0))) == -1)
+ {
+ fprintf(stderr, "Could not open '%s'\n", filename);
+ return true;
+ }
+
+ size_t nbytes= my_read(fd, (uchar*) Ptr, (size_t)sbuf.st_size, MYF(0));
+ my_close(fd, MYF(0));
+ length((uint32) nbytes);
+
+ return false;
+}
+
+
+class Delimiter
+{
+protected:
+ bool m_delimiter[127];
+ bool m_has_delimiter_cached;
+ bool has_delimiter_slow() const
+ {
+ for (size_t i= 0; i < sizeof(m_delimiter); i++)
+ {
+ if (m_delimiter[i])
+ return true;
+ }
+ return false;
+ }
+ bool unescape(char *to, char from) const
+ {
+ switch (from) {
+ case '\\': *to= '\\'; return false;
+ case 'r': *to= '\r'; return false;
+ case 'n': *to= '\n'; return false;
+ case 't': *to= '\t'; return false;
+ case '0': *to= '\0'; return false;
+ }
+ *to= '\0';
+ return true;
+ }
+ bool is_delimiter(char ch) const
+ {
+ return (signed char) ch < 0 ? false : m_delimiter[(uint32) ch];
+ }
+public:
+ Delimiter()
+ :m_has_delimiter_cached(false)
+ {
+ bzero(&m_delimiter, sizeof(m_delimiter));
+ }
+ bool has_delimiter() const
+ {
+ return m_has_delimiter_cached;
+ }
+ bool set_delimiter_unescape(const char *str)
+ {
+ m_has_delimiter_cached= false;
+ for ( ; *str; str++)
+ {
+ if ((signed char) *str < 0)
+ return true;
+ if (*str == '\\')
+ {
+ char unescaped;
+ str++;
+ if (!*str || unescape(&unescaped, *str))
+ return true;
+ m_delimiter[(uint) unescaped]= true;
+ }
+ else
+ m_delimiter[(uint) *str]= true;
+ }
+ m_has_delimiter_cached= has_delimiter_slow();
+ return false;
+ }
+ size_t get_delimiter_length(const char *str, const char *end) const
+ {
+ const char *str0= str;
+ for ( ; str < end; str++)
+ {
+ if (!is_delimiter(*str))
+ break;
+ }
+ return str - str0;
+ }
+ size_t get_data_length(const char *str, const char *end) const
+ {
+ const char *str0= str;
+ for ( ; str < end; str++)
+ {
+ if (is_delimiter(*str))
+ break;
+ }
+ return str - str0;
+ }
+};
+
+
+class Conv_inbuf
+{
+ const char *m_ptr;
+ const char *m_end;
+public:
+ Conv_inbuf(const char *from, size_t length)
+ :m_ptr(from), m_end(from + length)
+ { }
+ const char *ptr() const { return m_ptr; }
+ const char *end() const { return m_end; }
+ size_t length() const
+ {
+ return m_end - m_ptr;
+ }
+private:
+ LEX_CSTRING get_prefix(size_t len)
+ {
+ LEX_CSTRING res;
+ res.str= ptr();
+ res.length= len;
+ m_ptr+= len;
+ return res;
+ }
+ LEX_CSTRING get_empty_string() const
+ {
+ static LEX_CSTRING str= {NULL, 0};
+ return str;
+ }
+public:
+ LEX_CSTRING get_delimiter_chunk(const Delimiter &delimiter)
+ {
+ if (!delimiter.has_delimiter())
+ return get_empty_string();
+ size_t len= delimiter.get_delimiter_length(ptr(), end());
+ return get_prefix(len);
+ }
+ LEX_CSTRING get_data_chunk(const Delimiter &delimiter)
+ {
+ if (!delimiter.has_delimiter())
+ return get_prefix(length());
+ size_t len= delimiter.get_data_length(ptr(), end());
+ return get_prefix(len);
+ }
+};
+
+
+class Conv_outbuf: public Binary_string
+{
+public:
+ bool alloc(size_t out_max_length)
+ {
+ if (out_max_length >= UINT_MAX32)
+ {
+ fprintf(stderr, "The data needs a too large output buffer\n");
+ return true;
+ }
+ if (Binary_string::alloc((uint32) out_max_length))
+ {
+ fprintf(stderr, "Failed to allocate the output buffer\n");
+ return true;
+ }
+ return false;
+ }
+};
+
+
+class Conv: public String_copier, public Delimiter
+{
+ CHARSET_INFO *m_tocs;
+ CHARSET_INFO *m_fromcs;
+ bool m_continue;
+public:
+ Conv(CHARSET_INFO *tocs, CHARSET_INFO *fromcs, bool opt_continue)
+ :m_tocs(tocs), m_fromcs(fromcs), m_continue(opt_continue)
+ { }
+ size_t out_buffer_max_length(size_t from_length) const
+ {
+ return from_length / m_fromcs->mbminlen * m_tocs->mbmaxlen;
+ }
+ bool convert_data(const char *from, size_t length);
+ bool convert_binary_stream(FILE *file)
+ {
+ File_buffer buf;
+ return buf.load_binary_stream(file) ||
+ convert_data(buf.ptr(), buf.length());
+ }
+ bool convert_binary_file_by_name(const char *filename)
+ {
+ File_buffer buf;
+ return buf.load_binary_file_by_name(filename)||
+ convert_data(buf.ptr(), buf.length());
+ }
+private:
+ void report_error(const char *from) const
+ {
+ if (well_formed_error_pos())
+ {
+ fflush(stdout);
+ fprintf(stderr,
+ "Illegal %s byte sequence at position %d\n",
+ m_fromcs->csname,
+ (uint) (well_formed_error_pos() - from));
+ }
+ else if (cannot_convert_error_pos())
+ {
+ fflush(stdout);
+ fprintf(stderr,
+ "Conversion from %s to %s failed at position %d\n",
+ m_fromcs->csname, m_tocs->csname,
+ (uint) (cannot_convert_error_pos() - from));
+ }
+ }
+ size_t write(const char *str, size_t length) const
+ {
+ return my_fwrite(stdout, (uchar *) str, length, MY_WME);
+ }
+};
+
+
+bool Conv::convert_data(const char *from, size_t from_length)
+{
+ Conv_inbuf inbuf(from, from_length);
+ Conv_outbuf outbuf;
+
+ if (outbuf.alloc(out_buffer_max_length(from_length)))
+ return true;
+
+ for ( ; ; )
+ {
+ LEX_CSTRING delim, data;
+
+ delim= inbuf.get_delimiter_chunk(*this);
+ if (delim.length)
+ write(delim.str, delim.length);
+
+ data= inbuf.get_data_chunk(*this);
+ if (!data.length)
+ break;
+ size_t length= well_formed_copy(m_tocs,
+ (char *) outbuf.ptr(),
+ outbuf.alloced_length(),
+ m_fromcs, data.str, data.length);
+ outbuf.length((uint32) length);
+
+ if (most_important_error_pos() && !m_continue)
+ {
+ report_error(from);
+ return true;
+ }
+ write(outbuf.ptr(), outbuf.length());
+ }
+ return false;
+}
+
+
+class Session
+{
+public:
+ Session(const char *prog)
+ {
+ MY_INIT(prog);
+ }
+ ~Session()
+ {
+ my_end(0);
+ }
+ void usage(void)
+ {
+ printf("%s Ver %s Distrib %s for %s on %s\n", my_progname, CONV_VERSION,
+ MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
+ puts("Character set conversion utility for MariaDB");
+ puts("Usage:");
+ printf("%s [OPTION...] [FILE...]\n", my_progname);
+ my_print_help(long_options);
+ }
+};
+
+
+int main(int argc, char *argv[])
+{
+ Session session(argv[0]);
+ CHARSET_INFO *charset_info_from= NULL;
+ CHARSET_INFO *charset_info_to= NULL;
+
+ if (handle_options(&argc, &argv, long_options, get_one_option))
+ {
+ session.usage();
+ return 1;
+ }
+
+ if (!(charset_info_from= opt.csinfo_from()))
+ {
+ fprintf(stderr, "Character set %s is not supported\n", opt.m_charset_from);
+ return 1;
+ }
+
+ if (!(charset_info_to= opt.csinfo_to()))
+ {
+ fprintf(stderr, "Character set %s is not supported\n", opt.m_charset_to);
+ return 1;
+ }
+
+ Conv conv(charset_info_to, charset_info_from, opt.m_continue);
+ if (opt.m_delimiter)
+ {
+ if (charset_info_from->mbminlen > 1 ||
+ charset_info_to->mbminlen > 1)
+ {
+ fprintf(stderr, "--delimiter cannot be used with %s to %s conversion\n",
+ charset_info_from->csname, charset_info_to->csname);
+ return 1;
+ }
+ if (conv.set_delimiter_unescape(opt.m_delimiter))
+ {
+ fprintf(stderr, "Bad --delimiter value\n");
+ return 1;
+ }
+ }
+
+ if (argc == 0)
+ {
+ if (conv.convert_binary_stream(stdin))
+ return 1;
+ }
+ else
+ {
+ for (int i= 0; i < argc; i++)
+ {
+ if (conv.convert_binary_file_by_name(argv[i]))
+ return 1;
+ }
+ }
+
+ return 0;
+} /* main */
diff --git a/client/mysql.cc b/client/mysql.cc
index 3cae7241969..dcd9dfecef9 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2000, 2018, Oracle and/or its affiliates.
- Copyright (c) 2009, 2019, MariaDB Corporation.
+ Copyright (c) 2009, 2020, MariaDB Corporation.
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
@@ -58,6 +58,7 @@ static char *server_version= NULL;
#define MAX_SERVER_ARGS 64
#include "sql_string.h"
+#include "client_metadata.h"
extern "C" {
#if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
@@ -207,7 +208,7 @@ static CHARSET_INFO *charset_info= &my_charset_latin1;
#include "sslopt-vars.h"
-const char *default_dbug_option="d:t:o,/tmp/mysql.trace";
+const char *default_dbug_option="d:t:o,/tmp/mariadb.trace";
void tee_fprintf(FILE *file, const char *fmt, ...);
void tee_fputs(const char *s, FILE *file);
@@ -1079,8 +1080,8 @@ inline bool is_delimiter_command(char *name, ulong len)
only name(first DELIMITER_NAME_LEN bytes) is checked.
*/
return (len >= DELIMITER_NAME_LEN &&
- !my_strnncoll(&my_charset_latin1, (uchar*) name, DELIMITER_NAME_LEN,
- (uchar *) DELIMITER_NAME, DELIMITER_NAME_LEN));
+ !my_charset_latin1.strnncoll(name, DELIMITER_NAME_LEN,
+ DELIMITER_NAME, DELIMITER_NAME_LEN));
}
/**
@@ -1119,10 +1120,10 @@ int main(int argc,char *argv[])
charset_index= get_command_index('C');
delimiter_index= get_command_index('d');
delimiter_str= delimiter;
- default_prompt = my_strdup(getenv("MYSQL_PS1") ?
+ default_prompt = my_strdup(PSI_NOT_INSTRUMENTED, getenv("MYSQL_PS1") ?
getenv("MYSQL_PS1") :
"\\N [\\d]> ",MYF(MY_WME));
- current_prompt = my_strdup(default_prompt,MYF(MY_WME));
+ current_prompt = my_strdup(PSI_NOT_INSTRUMENTED, default_prompt,MYF(MY_WME));
prompt_counter=0;
aborted= 0;
sf_leaking_memory= 1; /* no memory leak reports yet */
@@ -1190,7 +1191,7 @@ int main(int argc,char *argv[])
sf_leaking_memory= 0;
glob_buffer.realloc(512);
completion_hash_init(&ht, 128);
- init_alloc_root(&hash_mem_root, "hash", 16384, 0, MYF(0));
+ init_alloc_root(PSI_NOT_INSTRUMENTED, &hash_mem_root, 16384, 0, MYF(0));
if (sql_connect(current_host,current_db,current_user,opt_password,
opt_silent))
{
@@ -1232,12 +1233,11 @@ int main(int argc,char *argv[])
{
/* read-history from file, default ~/.mysql_history*/
if (getenv("MYSQL_HISTFILE"))
- histfile=my_strdup(getenv("MYSQL_HISTFILE"),MYF(MY_WME));
+ histfile=my_strdup(PSI_NOT_INSTRUMENTED, getenv("MYSQL_HISTFILE"),MYF(MY_WME));
else if (getenv("HOME"))
{
- histfile=(char*) my_malloc((uint) strlen(getenv("HOME"))
- + (uint) strlen("/.mysql_history")+2,
- MYF(MY_WME));
+ histfile=(char*) my_malloc(PSI_NOT_INSTRUMENTED,
+ strlen(getenv("HOME")) + strlen("/.mysql_history")+2, MYF(MY_WME));
if (histfile)
sprintf(histfile,"%s/.mysql_history",getenv("HOME"));
char link_name[FN_REFLEN];
@@ -1259,8 +1259,8 @@ int main(int argc,char *argv[])
if (verbose)
tee_fprintf(stdout, "Reading history-file %s\n",histfile);
read_history(histfile);
- if (!(histfile_tmp= (char*) my_malloc((uint) strlen(histfile) + 5,
- MYF(MY_WME))))
+ if (!(histfile_tmp= (char*) my_malloc(PSI_NOT_INSTRUMENTED,
+ strlen(histfile) + 5, MYF(MY_WME))))
{
fprintf(stderr, "Couldn't allocate memory for temp histfile!\n");
exit(1);
@@ -1715,10 +1715,9 @@ static void usage(int version)
my_bool
-get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
- char *argument)
+get_one_option(const struct my_option *opt, char *argument, const char *)
{
- switch(optid) {
+ switch(opt->id) {
case OPT_CHARSETS_DIR:
strmake_buf(mysql_charsets_dir, argument);
charsets_dir = mysql_charsets_dir;
@@ -1797,7 +1796,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
}
if (embedded_server_arg_count == MAX_SERVER_ARGS-1 ||
!(embedded_server_args[embedded_server_arg_count++]=
- my_strdup(argument, MYF(MY_FAE))))
+ my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE))))
{
put_info("Can't use server argument", INFO_ERROR);
return 0;
@@ -1833,7 +1832,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
{
char *start= argument;
my_free(opt_password);
- opt_password= my_strdup(argument, MYF(MY_FAE));
+ opt_password= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
while (*argument) *argument++= 'x'; // Destroy argument
if (*start)
start[1]=0 ;
@@ -1896,7 +1895,7 @@ static int get_options(int argc, char **argv)
tmp= (char *) getenv("MYSQL_HOST");
if (tmp)
- current_host= my_strdup(tmp, MYF(MY_WME));
+ current_host= my_strdup(PSI_NOT_INSTRUMENTED, tmp, MYF(MY_WME));
pagpoint= getenv("PAGER");
if (!((char*) (pagpoint)))
@@ -1938,7 +1937,7 @@ static int get_options(int argc, char **argv)
{
skip_updates= 0;
my_free(current_db);
- current_db= my_strdup(*argv, MYF(MY_WME));
+ current_db= my_strdup(PSI_NOT_INSTRUMENTED, *argv, MYF(MY_WME));
}
if (tty_password)
opt_password= get_tty_password(NullS);
@@ -2242,8 +2241,8 @@ static COMMANDS *find_command(char *name)
*/
for (uint i= 0; commands[i].func; i++)
{
- if (!my_strnncoll(&my_charset_latin1, (uchar*) name, len,
- (uchar*) commands[i].name, len) &&
+ if (!my_charset_latin1.strnncoll((uchar*) name, len,
+ (uchar*) commands[i].name, len) &&
(commands[i].name[len] == '\0') &&
(!end || (commands[i].takes_params && get_arg(name, CHECK))))
{
@@ -2294,7 +2293,7 @@ static bool add_line(String &buffer, char *line, size_t line_length,
#ifdef USE_MB
// Accept multi-byte characters as-is
int length;
- if (use_mb(charset_info) &&
+ if (charset_info->use_mb() &&
(length= my_ismbchar(charset_info, pos, end_of_line)))
{
if (!*ml_comment || preserve_comments)
@@ -2962,7 +2961,7 @@ static void get_current_db()
{
MYSQL_ROW row= mysql_fetch_row(res);
if (row && row[0])
- current_db= my_strdup(row[0], MYF(MY_WME));
+ current_db= my_strdup(PSI_NOT_INSTRUMENTED, row[0], MYF(MY_WME));
mysql_free_result(res);
}
}
@@ -3229,9 +3228,8 @@ com_go(String *buffer,char *line __attribute__((unused)))
(void) com_print(buffer,0);
if (skip_updates &&
- (buffer->length() < 4 || my_strnncoll(charset_info,
- (const uchar*)buffer->ptr(),4,
- (const uchar*)"SET ",4)))
+ (buffer->length() < 4 || charset_info->strnncoll((const uchar*)buffer->ptr(),4,
+ (const uchar*)"SET ",4)))
{
(void) put_info("Ignoring query to other database",INFO_INFO);
return 0;
@@ -3502,12 +3500,15 @@ print_field_types(MYSQL_RES *result)
while ((field = mysql_fetch_field(result)))
{
+ Client_field_metadata metadata(field);
+ BinaryStringBuffer<128> data_type_metadata_str;
+ metadata.print_data_type_related_attributes(&data_type_metadata_str);
tee_fprintf(PAGER, "Field %3u: `%s`\n"
"Catalog: `%s`\n"
"Database: `%s`\n"
"Table: `%s`\n"
"Org_table: `%s`\n"
- "Type: %s\n"
+ "Type: %s%s%.*s%s\n"
"Collation: %s (%u)\n"
"Length: %lu\n"
"Max_length: %lu\n"
@@ -3516,6 +3517,9 @@ print_field_types(MYSQL_RES *result)
++i,
field->name, field->catalog, field->db, field->table,
field->org_table, fieldtype2str(field->type),
+ data_type_metadata_str.length() ? " (" : "",
+ data_type_metadata_str.length(), data_type_metadata_str.ptr(),
+ data_type_metadata_str.length() ? ")" : "",
get_charset_name(field->charsetnr), field->charsetnr,
field->length, field->max_length, field->decimals,
fieldflags2str(field->flags));
@@ -3601,9 +3605,8 @@ print_table_data(MYSQL_RES *result)
for (uint off=0; (field = mysql_fetch_field(result)) ; off++)
{
size_t name_length= (uint) strlen(field->name);
- size_t numcells= charset_info->cset->numcells(charset_info,
- field->name,
- field->name + name_length);
+ size_t numcells= charset_info->numcells(field->name,
+ field->name + name_length);
size_t display_length= field->max_length + name_length - numcells;
tee_fprintf(PAGER, " %-*s |",(int) MY_MIN(display_length,
MAX_COLUMN_LENGTH),
@@ -3652,7 +3655,7 @@ print_table_data(MYSQL_RES *result)
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.
*/
- size_t visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length);
+ size_t visible_length= charset_info->numcells(buffer, buffer + data_length);
extra_padding= (uint) (data_length - visible_length);
if (opt_binhex && is_binary_field(field))
@@ -3999,7 +4002,7 @@ safe_put_field(const char *pos,ulong length)
{
#ifdef USE_MB
int l;
- if (use_mb(charset_info) &&
+ if (charset_info->use_mb() &&
(l = my_ismbchar(charset_info, pos, end)))
{
while (l--)
@@ -4314,12 +4317,12 @@ com_connect(String *buffer, char *line)
if (tmp && *tmp)
{
my_free(current_db);
- current_db= my_strdup(tmp, MYF(MY_WME));
+ current_db= my_strdup(PSI_NOT_INSTRUMENTED, tmp, MYF(MY_WME));
tmp= get_arg(buff, GET_NEXT);
if (tmp)
{
my_free(current_host);
- current_host=my_strdup(tmp,MYF(MY_WME));
+ current_host=my_strdup(PSI_NOT_INSTRUMENTED, tmp,MYF(MY_WME));
}
}
else
@@ -4504,7 +4507,7 @@ com_use(String *buffer __attribute__((unused)), char *line)
return put_error(&mysql);
}
my_free(current_db);
- current_db=my_strdup(tmp,MYF(MY_WME));
+ current_db=my_strdup(PSI_NOT_INSTRUMENTED, tmp,MYF(MY_WME));
#ifdef HAVE_READLINE
if (select_db > 1)
build_completion_hash(opt_rehash, 1);
@@ -4624,7 +4627,10 @@ static char *get_arg(char *line, get_arg_mode mode)
string, and the "dialog" plugin will free() it.
*/
-MYSQL_PLUGIN_EXPORT
+extern "C"
+#ifdef _MSC_VER
+__declspec(dllexport)
+#endif
char *mysql_authentication_dialog_ask(MYSQL *mysql, int type,
const char *prompt,
char *buf, int buf_len)
@@ -4909,7 +4915,7 @@ server_version_string(MYSQL *con)
/* version, space, comment, \0 */
size_t len= strlen(mysql_get_server_info(con)) + strlen(cur[0]) + 2;
- if ((server_version= (char *) my_malloc(len, MYF(MY_WME))))
+ if ((server_version= (char *) my_malloc(PSI_NOT_INSTRUMENTED, len, MYF(MY_WME))))
{
char *bufp;
bufp = strmov(server_version, mysql_get_server_info(con));
@@ -4926,7 +4932,7 @@ server_version_string(MYSQL *con)
*/
if (server_version == NULL)
- server_version= my_strdup(mysql_get_server_info(con), MYF(MY_WME));
+ server_version= my_strdup(PSI_NOT_INSTRUMENTED, mysql_get_server_info(con), MYF(MY_WME));
}
return server_version ? server_version : "";
@@ -5328,8 +5334,8 @@ static void init_username()
(result=mysql_use_result(&mysql)))
{
MYSQL_ROW cur=mysql_fetch_row(result);
- full_username=my_strdup(cur[0],MYF(MY_WME));
- part_username=my_strdup(strtok(cur[0],"@"),MYF(MY_WME));
+ full_username=my_strdup(PSI_NOT_INSTRUMENTED, cur[0],MYF(MY_WME));
+ part_username=my_strdup(PSI_NOT_INSTRUMENTED, strtok(cur[0],"@"),MYF(MY_WME));
(void) mysql_fetch_row(result); // Read eof
}
}
@@ -5340,7 +5346,7 @@ static int com_prompt(String *buffer __attribute__((unused)),
char *ptr=strchr(line, ' ');
prompt_counter = 0;
my_free(current_prompt);
- current_prompt=my_strdup(ptr ? ptr+1 : default_prompt,MYF(MY_WME));
+ current_prompt=my_strdup(PSI_NOT_INSTRUMENTED, ptr ? ptr+1 : default_prompt,MYF(MY_WME));
if (!ptr)
tee_fprintf(stdout, "Returning to default PROMPT of %s\n", default_prompt);
else
diff --git a/client/mysql_plugin.c b/client/mysql_plugin.c
index 7f2d806413c..eddae6114e6 100644
--- a/client/mysql_plugin.c
+++ b/client/mysql_plugin.c
@@ -191,7 +191,7 @@ static char *get_value(char *line, const char *item)
char *s= 0;
s = line + item_len + 1;
- destination= my_strndup(s, line_len - start, MYF(MY_FAE));
+ destination= my_strndup(PSI_NOT_INSTRUMENTED, s, line_len - start, MYF(MY_FAE));
destination[line_len - item_len - 2]= 0;
}
return destination;
@@ -259,7 +259,7 @@ static int has_spaces(const char *path)
static char *convert_path(const char *argument)
{
/* Convert / to \\ to make Windows paths */
- char *winfilename= my_strdup(argument, MYF(MY_FAE));
+ char *winfilename= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
char *pos, *end;
size_t length= strlen(argument);
@@ -291,7 +291,7 @@ static char *add_quotes(const char *path)
else
snprintf(windows_cmd_friendly, sizeof(windows_cmd_friendly),
"%s", path);
- return my_strdup(windows_cmd_friendly, MYF(MY_FAE));
+ return my_strdup(PSI_NOT_INSTRUMENTED, windows_cmd_friendly, MYF(MY_FAE));
}
#endif
@@ -376,19 +376,19 @@ static int get_default_values()
if ((opt_datadir == 0) && ((value= get_value(line, "--datadir"))))
{
- opt_datadir= my_strdup(value, MYF(MY_FAE));
+ opt_datadir= my_strdup(PSI_NOT_INSTRUMENTED, value, MYF(MY_FAE));
}
if ((opt_basedir == 0) && ((value= get_value(line, "--basedir"))))
{
- opt_basedir= my_strdup(value, MYF(MY_FAE));
+ opt_basedir= my_strdup(PSI_NOT_INSTRUMENTED, value, MYF(MY_FAE));
}
if ((opt_plugin_dir == 0) && ((value= get_value(line, "--plugin_dir"))))
{
- opt_plugin_dir= my_strdup(value, MYF(MY_FAE));
+ opt_plugin_dir= my_strdup(PSI_NOT_INSTRUMENTED, value, MYF(MY_FAE));
}
if ((opt_plugin_ini == 0) && ((value= get_value(line, "--plugin_ini"))))
{
- opt_plugin_ini= my_strdup(value, MYF(MY_FAE));
+ opt_plugin_ini= my_strdup(PSI_NOT_INSTRUMENTED, value, MYF(MY_FAE));
}
}
}
@@ -474,11 +474,10 @@ static void print_default_values(void)
*/
static my_bool
-get_one_option(int optid,
- const struct my_option *opt __attribute__((unused)),
- char *argument)
+get_one_option(const struct my_option *opt,
+ char *argument, const char *filename __attribute__((unused)))
{
- switch(optid) {
+ switch(opt->id) {
case 'n':
opt_no_defaults++;
break;
@@ -498,22 +497,22 @@ get_one_option(int optid,
usage();
exit(0);
case 'd':
- opt_datadir= my_strdup(argument, MYF(MY_FAE));
+ opt_datadir= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
break;
case 'b':
- opt_basedir= my_strdup(argument, MYF(MY_FAE));
+ opt_basedir= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
break;
case 'p':
- opt_plugin_dir= my_strdup(argument, MYF(MY_FAE));
+ opt_plugin_dir= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
break;
case 'i':
- opt_plugin_ini= my_strdup(argument, MYF(MY_FAE));
+ opt_plugin_ini= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
break;
case 'm':
- opt_mysqld= my_strdup(argument, MYF(MY_FAE));
+ opt_mysqld= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
break;
case 'f':
- opt_my_print_defaults= my_strdup(argument, MYF(MY_FAE));
+ opt_my_print_defaults= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
break;
}
return 0;
@@ -621,7 +620,7 @@ static int load_plugin_data(char *plugin_name, char *config_file)
if (opt_plugin_ini == 0)
{
fn_format(path, config_file, opt_plugin_dir, "", MYF(0));
- opt_plugin_ini= my_strdup(path, MYF(MY_FAE));
+ opt_plugin_ini= my_strdup(PSI_NOT_INSTRUMENTED, path, MYF(MY_FAE));
}
if (!file_exists(opt_plugin_ini))
{
@@ -637,7 +636,7 @@ static int load_plugin_data(char *plugin_name, char *config_file)
}
/* save name */
- plugin_data.name= my_strdup(plugin_name, MYF(MY_WME));
+ plugin_data.name= my_strdup(PSI_NOT_INSTRUMENTED, plugin_name, MYF(MY_WME));
/* Read plugin components */
while (i < 16)
@@ -667,14 +666,14 @@ static int load_plugin_data(char *plugin_name, char *config_file)
/* Add proper file extension for soname */
strcat(line, FN_SOEXT);
/* save so_name */
- plugin_data.so_name= my_strdup(line, MYF(MY_WME|MY_ZEROFILL));
+ plugin_data.so_name= my_strdup(PSI_NOT_INSTRUMENTED, line, MYF(MY_WME|MY_ZEROFILL));
i++;
}
else
{
if (strlen(line) > 0)
{
- plugin_data.components[i]= my_strdup(line, MYF(MY_WME));
+ plugin_data.components[i]= my_strdup(PSI_NOT_INSTRUMENTED, line, MYF(MY_WME));
i++;
}
else
@@ -740,21 +739,21 @@ static int check_options(int argc, char **argv, char *operation)
else if ((strncasecmp(argv[i], basedir_prefix, basedir_len) == 0) &&
!opt_basedir)
{
- opt_basedir= my_strndup(argv[i]+basedir_len,
+ opt_basedir= my_strndup(PSI_NOT_INSTRUMENTED, argv[i]+basedir_len,
strlen(argv[i])-basedir_len, MYF(MY_FAE));
num_found++;
}
else if ((strncasecmp(argv[i], datadir_prefix, datadir_len) == 0) &&
!opt_datadir)
{
- opt_datadir= my_strndup(argv[i]+datadir_len,
+ opt_datadir= my_strndup(PSI_NOT_INSTRUMENTED, argv[i]+datadir_len,
strlen(argv[i])-datadir_len, MYF(MY_FAE));
num_found++;
}
else if ((strncasecmp(argv[i], plugin_dir_prefix, plugin_dir_len) == 0) &&
!opt_plugin_dir)
{
- opt_plugin_dir= my_strndup(argv[i]+plugin_dir_len,
+ opt_plugin_dir= my_strndup(PSI_NOT_INSTRUMENTED, argv[i]+plugin_dir_len,
strlen(argv[i])-plugin_dir_len, MYF(MY_FAE));
num_found++;
}
@@ -867,7 +866,7 @@ static int process_options(int argc, char *argv[], char *operation)
#endif
buff[sizeof(buff) - 1]= 0;
my_free(opt_basedir);
- opt_basedir= my_strdup(buff, MYF(MY_FAE));
+ opt_basedir= my_strdup(PSI_NOT_INSTRUMENTED, buff, MYF(MY_FAE));
}
}
diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c
index aa73680a3df..a6af46e6d7b 100644
--- a/client/mysql_upgrade.c
+++ b/client/mysql_upgrade.c
@@ -62,7 +62,7 @@ static my_bool tty_password= 0;
static char opt_tmpdir[FN_REFLEN] = "";
#ifndef DBUG_OFF
-static char *default_dbug_option= (char*) "d:t:O,/tmp/mysql_upgrade.trace";
+static char *default_dbug_option= (char*) "d:t:O,/tmp/mariadb-upgrade.trace";
#endif
static char **defaults_argv;
@@ -268,12 +268,12 @@ static void add_one_option_cnf_file(DYNAMIC_STRING *ds,
}
static my_bool
-get_one_option(int optid, const struct my_option *opt,
- char *argument)
+get_one_option(const struct my_option *opt, char *argument,
+ const char *filename __attribute__((unused)))
{
my_bool add_option= TRUE;
- switch (optid) {
+ switch (opt->id) {
case '?':
printf("%s Ver %s Distrib %s, for %s (%s)\n",
@@ -317,7 +317,7 @@ get_one_option(int optid, const struct my_option *opt,
case 'b': /* --basedir */
case 'd': /* --datadir */
fprintf(stderr, "%s: the '--%s' option is always ignored\n",
- my_progname, optid == 'b' ? "basedir" : "datadir");
+ my_progname, opt->id == 'b' ? "basedir" : "datadir");
/* FALLTHROUGH */
case 'k': /* --version-check */
@@ -383,11 +383,20 @@ static int run_command(char* cmd,
if (opt_verbose >= 4)
puts(cmd);
- if (!(res_file= my_popen(cmd, IF_WIN("rt","r"))))
+ if (!(res_file= my_popen(cmd, "r")))
die("popen(\"%s\", \"r\") failed", cmd);
while (fgets(buf, sizeof(buf), res_file))
{
+#ifdef _WIN32
+ /* Strip '\r' off newlines. */
+ size_t len = strlen(buf);
+ if (len > 1 && buf[len - 2] == '\r' && buf[len - 1] == '\n')
+ {
+ buf[len - 2] = '\n';
+ buf[len - 1] = 0;
+ }
+#endif
DBUG_PRINT("info", ("buf: %s", buf));
if(ds_res)
{
diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc
index 32096fef996..1a128e61533 100644
--- a/client/mysqladmin.cc
+++ b/client/mysqladmin.cc
@@ -241,10 +241,9 @@ static const char *load_default_groups[]=
0 };
my_bool
-get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
- char *argument)
+get_one_option(const struct my_option *opt, char *argument, const char *)
{
- switch(optid) {
+ switch(opt->id) {
case 'c':
opt_count_iterations= 1;
break;
@@ -255,7 +254,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
{
char *start=argument;
my_free(opt_password);
- opt_password=my_strdup(argument,MYF(MY_FAE));
+ opt_password=my_strdup(PSI_NOT_INSTRUMENTED, argument,MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
if (*start)
start[1]=0; /* Cut length of argument */
@@ -1358,11 +1357,11 @@ static char **mask_password(int argc, char ***argv)
if (!argc)
return NULL;
- temp_argv= (char **)(my_malloc(sizeof(char *) * argc, MYF(MY_WME)));
+ temp_argv= (char **)(my_malloc(PSI_NOT_INSTRUMENTED, sizeof(char *) * argc, MYF(MY_WME)));
argc--;
while (argc > 0)
{
- temp_argv[argc]= my_strdup((*argv)[argc], MYF(MY_FAE));
+ temp_argv[argc]= my_strdup(PSI_NOT_INSTRUMENTED, (*argv)[argc], MYF(MY_FAE));
if (find_type((*argv)[argc - 1],&command_typelib, FIND_TYPE_BASIC) == ADMIN_PASSWORD ||
find_type((*argv)[argc - 1],&command_typelib, FIND_TYPE_BASIC) == ADMIN_OLD_PASSWORD)
{
@@ -1375,7 +1374,7 @@ static char **mask_password(int argc, char ***argv)
}
argc--;
}
- temp_argv[argc]= my_strdup((*argv)[argc], MYF(MY_FAE));
+ temp_argv[argc]= my_strdup(PSI_NOT_INSTRUMENTED, (*argv)[argc], MYF(MY_FAE));
return(temp_argv);
}
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index f8c27e3be5b..a93d925db58 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -62,20 +62,26 @@
extern "C" unsigned char *mysql_net_store_length(unsigned char *packet, size_t length);
#define net_store_length mysql_net_store_length
+#define key_memory_TABLE_RULE_ENT 0
+#define key_memory_rpl_filter 0
+
Rpl_filter *binlog_filter= 0;
#define BIN_LOG_HEADER_SIZE 4
#define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4)
/* Needed for Rpl_filter */
-CHARSET_INFO* system_charset_info= &my_charset_utf8_general_ci;
+CHARSET_INFO* system_charset_info= &my_charset_utf8mb3_general_ci;
/* Needed for Flashback */
DYNAMIC_ARRAY binlog_events; // Storing the events output string
DYNAMIC_ARRAY events_in_stmt; // Storing the events that in one statement
String stop_event_string; // Storing the STOP_EVENT output string
+extern "C" {
char server_version[SERVER_VERSION_LENGTH];
+}
+
ulong server_id = 0;
// needed by net_serv.c
@@ -91,7 +97,7 @@ static char *result_file_name= 0;
static const char *output_prefix= "";
#ifndef DBUG_OFF
-static const char *default_dbug_option = "d:t:o,/tmp/mysqlbinlog.trace";
+static const char *default_dbug_option = "d:t:o,/tmp/mariadb-binlog.trace";
const char *current_dbug_option= default_dbug_option;
#endif
static const char *load_groups[]=
@@ -145,6 +151,7 @@ static const char* dirname_for_local_load= 0;
static bool opt_skip_annotate_row_events= 0;
static my_bool opt_flashback;
+static bool opt_print_table_metadata;
#ifdef WHEN_FLASHBACK_REVIEW_READY
static my_bool opt_flashback_review;
static char *flashback_review_dbname, *flashback_review_tablename;
@@ -196,7 +203,7 @@ Log_event* read_remote_annotate_event(uchar* net_buf, ulong event_len,
uchar *event_buf;
Log_event* event;
- if (!(event_buf= (uchar*) my_malloc(event_len + 1, MYF(MY_WME))))
+ if (!(event_buf= (uchar*) my_malloc(PSI_NOT_INSTRUMENTED, event_len + 1, MYF(MY_WME))))
{
error("Out of memory");
return 0;
@@ -308,7 +315,7 @@ public:
int init()
{
- return my_init_dynamic_array(&file_names, sizeof(File_name_record),
+ return my_init_dynamic_array(PSI_NOT_INSTRUMENTED, &file_names, sizeof(File_name_record),
100, 100, MYF(0));
}
@@ -543,7 +550,7 @@ Exit_status Load_log_processor::process_first_event(const char *bname,
File_name_record rec;
DBUG_ENTER("Load_log_processor::process_first_event");
- if (!(fname= (char*) my_malloc(full_len,MYF(MY_WME))))
+ if (!(fname= (char*) my_malloc(PSI_NOT_INSTRUMENTED, full_len,MYF(MY_WME))))
{
error("Out of memory.");
delete ce;
@@ -1096,6 +1103,7 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
print_event_info->hexdump_from= pos;
print_event_info->base64_output_mode= opt_base64_output_mode;
+ print_event_info->print_table_metadata= opt_print_table_metadata;
DBUG_PRINT("debug", ("event_type: %s", ev->get_type_str()));
@@ -1789,6 +1797,10 @@ Example: rewrite-db='from->to'.",
(uchar**) &opt_skip_annotate_row_events,
(uchar**) &opt_skip_annotate_row_events,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"print-table-metadata", OPT_PRINT_TABLE_METADATA,
+ "Print metadata stored in Table_map_log_event",
+ &opt_print_table_metadata, &opt_print_table_metadata, 0,
+ GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
@@ -1927,11 +1939,10 @@ static my_time_t convert_str_to_timestamp(const char* str)
extern "C" my_bool
-get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
- char *argument)
+get_one_option(const struct my_option *opt, char *argument, const char *)
{
bool tty_password=0;
- switch (optid) {
+ switch (opt->id) {
#ifndef DBUG_OFF
case '#':
if (!argument)
@@ -1954,7 +1965,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
{
my_free(pass);
char *start=argument;
- pass= my_strdup(argument,MYF(MY_FAE));
+ pass= my_strdup(PSI_NOT_INSTRUMENTED, argument,MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
if (*start)
start[1]=0; /* Cut length of argument */
@@ -3040,10 +3051,10 @@ int main(int argc, char** argv)
if (opt_flashback)
{
- my_init_dynamic_array(&binlog_events, sizeof(LEX_STRING), 1024, 1024,
- MYF(0));
- my_init_dynamic_array(&events_in_stmt, sizeof(Rows_log_event*), 1024, 1024,
- MYF(0));
+ my_init_dynamic_array(PSI_NOT_INSTRUMENTED, &binlog_events,
+ sizeof(LEX_STRING), 1024, 1024, MYF(0));
+ my_init_dynamic_array(PSI_NOT_INSTRUMENTED, &events_in_stmt,
+ sizeof(Rows_log_event*), 1024, 1024, MYF(0));
}
if (opt_stop_never)
to_last_remote_log= TRUE;
@@ -3091,7 +3102,7 @@ int main(int argc, char** argv)
retval= ERROR_STOP;
goto err;
}
- dirname_for_local_load= my_strdup(my_tmpdir(&tmpdir), MY_WME);
+ dirname_for_local_load= my_strdup(PSI_NOT_INSTRUMENTED, my_tmpdir(&tmpdir), MY_WME);
}
if (load_processor.init())
@@ -3249,6 +3260,7 @@ struct encryption_service_st encryption_handler=
#include "../sql-common/my_time.c"
#include "password.c"
#include "log_event.cc"
+#include "log_event_client.cc"
#include "log_event_old.cc"
#include "rpl_utility.cc"
#include "sql_string.cc"
diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c
index c1859440446..d7eeec6198b 100644
--- a/client/mysqlcheck.c
+++ b/client/mysqlcheck.c
@@ -284,13 +284,13 @@ static void usage(void)
static my_bool
-get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
- char *argument)
+get_one_option(const struct my_option *opt,
+ char *argument, const char *filename __attribute__((unused)))
{
int orig_what_to_do= what_to_do;
DBUG_ENTER("get_one_option");
- switch(optid) {
+ switch(opt->id) {
case 'a':
what_to_do = DO_ANALYZE;
break;
@@ -326,7 +326,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
{
char *start = argument;
my_free(opt_password);
- opt_password = my_strdup(argument, MYF(MY_FAE));
+ opt_password = my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
if (*start)
start[1] = 0; /* Cut length of argument */
@@ -567,7 +567,7 @@ static int process_selected_tables(char *db, char **table_names, int tables)
tot_length+= fixed_name_length(*(table_names + i)) + 2;
if (!(table_names_comma_sep = (char *)
- my_malloc((sizeof(char) * tot_length) + 4, MYF(MY_WME))))
+ my_malloc(PSI_NOT_INSTRUMENTED, tot_length + 4, MYF(MY_WME))))
DBUG_RETURN(1);
for (end = table_names_comma_sep + 1; tables > 0;
@@ -678,12 +678,12 @@ static int process_all_tables_in_db(char *database)
}
mysql_data_seek(res, 0);
- if (!(tables=(char *) my_malloc(sizeof(char)*tot_length+4, MYF(MY_WME))))
+ if (!(tables=(char *) my_malloc(PSI_NOT_INSTRUMENTED, tot_length+4, MYF(MY_WME))))
{
mysql_free_result(res);
DBUG_RETURN(1);
}
- if (!(views=(char *) my_malloc(sizeof(char)*tot_views_length+4, MYF(MY_WME))))
+ if (!(views=(char *) my_malloc(PSI_NOT_INSTRUMENTED, tot_views_length+4, MYF(MY_WME))))
{
my_free(tables);
mysql_free_result(res);
@@ -799,8 +799,7 @@ static int rebuild_table(char *name)
int rc= 0;
DBUG_ENTER("rebuild_table");
- query= (char*)my_malloc(sizeof(char) * (12 + strlen(name) + 6 + 1),
- MYF(MY_WME));
+ query= (char*)my_malloc(PSI_NOT_INSTRUMENTED, 12+strlen(name)+6+1, MYF(MY_WME));
if (!query)
DBUG_RETURN(1);
ptr= strxmov(query, "ALTER TABLE ", name, " FORCE", NullS);
@@ -938,7 +937,7 @@ static int handle_request_for_tables(char *tables, size_t length,
DBUG_RETURN(fix_table_storage_name(tables));
}
- if (!(query =(char *) my_malloc(query_size, MYF(MY_WME))))
+ if (!(query =(char *) my_malloc(PSI_NOT_INSTRUMENTED, query_size, MYF(MY_WME))))
DBUG_RETURN(1);
if (dont_quote)
{
@@ -1195,14 +1194,14 @@ int main(int argc, char **argv)
}
if (opt_auto_repair &&
- (my_init_dynamic_array(&tables4repair, sizeof(char)*(NAME_LEN*2+2),16,
- 64, MYF(0)) ||
- my_init_dynamic_array(&views4repair, sizeof(char)*(NAME_LEN*2+2),16,
- 64, MYF(0)) ||
- my_init_dynamic_array(&tables4rebuild, sizeof(char)*(NAME_LEN*2+2),16,
- 64, MYF(0)) ||
- my_init_dynamic_array(&alter_table_cmds, MAX_ALTER_STR_SIZE, 0, 1,
- MYF(0))))
+ (my_init_dynamic_array(PSI_NOT_INSTRUMENTED, &tables4repair,
+ NAME_LEN*2+2, 16, 64, MYF(0)) ||
+ my_init_dynamic_array(PSI_NOT_INSTRUMENTED, &views4repair,
+ NAME_LEN*2+2, 16, 64, MYF(0)) ||
+ my_init_dynamic_array(PSI_NOT_INSTRUMENTED, &tables4rebuild,
+ NAME_LEN*2+2, 16, 64, MYF(0)) ||
+ my_init_dynamic_array(PSI_NOT_INSTRUMENTED, &alter_table_cmds,
+ MAX_ALTER_STR_SIZE, 0, 1, MYF(0))))
goto end;
if (opt_alldbs)
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 0a45b444023..4830a6c782b 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -83,6 +83,7 @@
#define IGNORE_NONE 0x00 /* no ignore */
#define IGNORE_DATA 0x01 /* don't dump data for this table */
#define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */
+#define IGNORE_S3_TABLE 0x04
/* Chars needed to store LONGLONG, excluding trailing '\0'. */
#define LONGLONG_LEN 20
@@ -101,6 +102,7 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0, opt_no_data_m
quick= 1, extended_insert= 1,
lock_tables=1,ignore_errors=0,flush_logs=0,flush_privileges=0,
opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0,
+ opt_copy_s3_tables=0,
opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0,
opt_alldbs=0,opt_create_db=0,opt_lock_all_tables=0,
opt_set_charset=0, opt_dump_date=1,
@@ -186,7 +188,7 @@ static const char *mysql_universal_client_charset=
MYSQL_UNIVERSAL_CLIENT_CHARSET;
static char *default_charset;
static CHARSET_INFO *charset_info= &my_charset_latin1;
-const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace";
+const char *default_dbug_option="d:t:o,/tmp/mariadb-dump.trace";
/* have we seen any VIEWs during table scanning? */
my_bool seen_views= 0;
const char *compatible_mode_names[]=
@@ -274,6 +276,11 @@ static struct my_option my_long_options[] =
{"compress", 'C', "Use compression in server/client protocol.",
&opt_compress, &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0},
+ {"copy_s3_tables", OPT_COPY_S3_TABLES,
+ "If 'no' S3 tables will be ignored, otherwise S3 tables will be copied as "
+ " Aria tables and then altered to S3",
+ &opt_copy_s3_tables, &opt_copy_s3_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0,
+ 0, 0, 0},
{"create-options", 'a',
"Include all MariaDB specific create options.",
&create_options, &create_options, 0, GET_BOOL, NO_ARG, 1,
@@ -815,10 +822,10 @@ uchar* get_table_key(const char *entry, size_t *length,
static my_bool
-get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
- char *argument)
+get_one_option(const struct my_option *opt,
+ char *argument, const char *filename __attribute__((unused)))
{
- switch (optid) {
+ switch (opt->id) {
case 'p':
if (argument == disabled_my_option)
argument= (char*) ""; /* Don't require password */
@@ -826,7 +833,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
{
char *start=argument;
my_free(opt_password);
- opt_password=my_strdup(argument,MYF(MY_FAE));
+ opt_password= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
if (*start)
start[1]=0; /* Cut length of argument */
@@ -908,7 +915,8 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
opt_databases=0;
break;
case (int) OPT_IGNORE_DATABASE:
- if (my_hash_insert(&ignore_database, (uchar*) my_strdup(argument, MYF(0))))
+ if (my_hash_insert(&ignore_database,
+ (uchar*) my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(0))))
exit(EX_EOM);
break;
case (int) OPT_IGNORE_DATA:
@@ -919,7 +927,8 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
"Illegal use of option --ignore-table-data=<database>.<table>\n");
exit(1);
}
- if (my_hash_insert(&ignore_data, (uchar*)my_strdup(argument, MYF(0))))
+ if (my_hash_insert(&ignore_data, (uchar*)my_strdup(PSI_NOT_INSTRUMENTED,
+ argument, MYF(0))))
exit(EX_EOM);
break;
}
@@ -930,7 +939,8 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
fprintf(stderr, "Illegal use of option --ignore-table=<database>.<table>\n");
exit(1);
}
- if (my_hash_insert(&ignore_table, (uchar*)my_strdup(argument, MYF(0))))
+ if (my_hash_insert(&ignore_table,
+ (uchar*)my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(0))))
exit(EX_EOM);
break;
}
@@ -1011,26 +1021,26 @@ static int get_options(int *argc, char ***argv)
load_defaults_or_exit("my", load_default_groups, argc, argv);
defaults_argv= *argv;
- if (my_hash_init(&ignore_database, charset_info, 16, 0, 0,
- (my_hash_get_key) get_table_key, my_free, 0))
+ if (my_hash_init(PSI_NOT_INSTRUMENTED, &ignore_database, charset_info, 16, 0, 0,
+ (my_hash_get_key) get_table_key, my_free, 0))
return(EX_EOM);
- if (my_hash_init(&ignore_table, charset_info, 16, 0, 0,
- (my_hash_get_key) get_table_key, my_free, 0))
+ if (my_hash_init(PSI_NOT_INSTRUMENTED, &ignore_table, charset_info, 16, 0, 0,
+ (my_hash_get_key) get_table_key, my_free, 0))
return(EX_EOM);
/* Don't copy internal log tables */
- if (my_hash_insert(&ignore_table,
- (uchar*) my_strdup("mysql.apply_status", MYF(MY_WME))) ||
- my_hash_insert(&ignore_table,
- (uchar*) my_strdup("mysql.schema", MYF(MY_WME))) ||
- my_hash_insert(&ignore_table,
- (uchar*) my_strdup("mysql.general_log", MYF(MY_WME))) ||
- my_hash_insert(&ignore_table,
- (uchar*) my_strdup("mysql.slow_log", MYF(MY_WME))) ||
- my_hash_insert(&ignore_table,
- (uchar*) my_strdup("mysql.transaction_registry", MYF(MY_WME))))
+ if (my_hash_insert(&ignore_table, (uchar*) my_strdup(PSI_NOT_INSTRUMENTED,
+ "mysql.apply_status", MYF(MY_WME))) ||
+ my_hash_insert(&ignore_table, (uchar*) my_strdup(PSI_NOT_INSTRUMENTED,
+ "mysql.schema", MYF(MY_WME))) ||
+ my_hash_insert(&ignore_table, (uchar*) my_strdup(PSI_NOT_INSTRUMENTED,
+ "mysql.general_log", MYF(MY_WME))) ||
+ my_hash_insert(&ignore_table, (uchar*) my_strdup(PSI_NOT_INSTRUMENTED,
+ "mysql.slow_log", MYF(MY_WME))) ||
+ my_hash_insert(&ignore_table, (uchar*) my_strdup(PSI_NOT_INSTRUMENTED,
+ "mysql.transaction_registry", MYF(MY_WME))))
return(EX_EOM);
- if (my_hash_init(&ignore_data, charset_info, 16, 0, 0,
+ if (my_hash_init(PSI_NOT_INSTRUMENTED, &ignore_data, charset_info, 16, 0, 0,
(my_hash_get_key) get_table_key, my_free, 0))
return(EX_EOM);
@@ -1390,10 +1400,10 @@ static char *my_case_str(const char *str,
{
my_match_t match;
- uint status= my_charset_latin1.coll->instr(&my_charset_latin1,
- str, str_len,
- token, token_len,
- &match, 1);
+ uint status= my_ci_instr(&my_charset_latin1,
+ str, str_len,
+ token, token_len,
+ &match, 1);
return status ? (char *) str + match.end : NULL;
}
@@ -1811,7 +1821,7 @@ static void unescape(FILE *file,char *pos, size_t length)
{
char *tmp;
DBUG_ENTER("unescape");
- if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
+ if (!(tmp=(char*) my_malloc(PSI_NOT_INSTRUMENTED, length*2+1, MYF(MY_WME))))
die(EX_MYSQLERR, "Couldn't allocate memory");
mysql_real_escape_string(&mysql_connection, tmp, pos, (ulong)length);
@@ -2172,7 +2182,12 @@ static void print_xml_row(FILE *xml_file, const char *row_name,
fputc(' ', xml_file);
print_quoted_xml(xml_file, field->name, field->name_length, 1);
fputs("=\"", xml_file);
- print_quoted_xml(xml_file, (*row)[i], lengths[i], 0);
+ if (opt_copy_s3_tables &&
+ !strcmp(field->name, "Engine") &&
+ !strcmp((*row)[i], "S3"))
+ print_quoted_xml(xml_file, "Aria", sizeof("Aria") - 1, 0);
+ else
+ print_quoted_xml(xml_file, (*row)[i], lengths[i], 0);
fputc('"', xml_file);
check_io(xml_file);
}
@@ -2768,11 +2783,18 @@ static uint get_table_structure(char *table, char *db, char *table_type,
my_bool is_log_table;
MYSQL_RES *result;
MYSQL_ROW row;
+ const char *s3_engine_ptr;
+ DYNAMIC_STRING create_table_str;
+ static const char s3_engine_token[]= " ENGINE=S3 ";
+ static const char aria_engine_token[]= " ENGINE=Aria ";
DBUG_ENTER("get_table_structure");
DBUG_PRINT("enter", ("db: %s table: %s", db, table));
*ignore_flag= check_if_ignore_table(table, table_type);
+ if (!opt_copy_s3_tables && *ignore_flag == IGNORE_S3_TABLE)
+ DBUG_RETURN(0);
+
delayed= opt_delayed;
if (delayed && (*ignore_flag & IGNORE_INSERT_DELAYED))
{
@@ -2882,7 +2904,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
/* save "show create" statement for later */
if ((row= mysql_fetch_row(result)) && (scv_buff=row[1]))
- scv_buff= my_strdup(scv_buff, MYF(0));
+ scv_buff= my_strdup(PSI_NOT_INSTRUMENTED, scv_buff, MYF(0));
mysql_free_result(result);
@@ -3006,11 +3028,22 @@ static uint get_table_structure(char *table, char *db, char *table_type,
is_log_table= general_log_or_slow_log_tables(db, table);
if (is_log_table)
row[1]+= 13; /* strlen("CREATE TABLE ")= 13 */
+ create_table_str.str= row[1];
+ if (opt_copy_s3_tables && (*ignore_flag & IGNORE_S3_TABLE) &&
+ (s3_engine_ptr= strstr(row[1], s3_engine_token)))
+ {
+ init_dynamic_string_checked(&create_table_str, "", 1024, 1024);
+ dynstr_append_mem_checked(&create_table_str, row[1],
+ (uint)(s3_engine_ptr - row[1]));
+ dynstr_append_checked(&create_table_str, aria_engine_token);
+ dynstr_append_checked(&create_table_str,
+ s3_engine_ptr + sizeof(s3_engine_token) - 1);
+ }
if (opt_compatible_mode & 3)
{
fprintf(sql_file,
is_log_table ? "CREATE TABLE IF NOT EXISTS %s;\n" : "%s;\n",
- row[1]);
+ create_table_str.str);
}
else
{
@@ -3020,10 +3053,12 @@ static uint get_table_structure(char *table, char *db, char *table_type,
"%s%s;\n"
"/*!40101 SET character_set_client = @saved_cs_client */;\n",
is_log_table ? "CREATE TABLE IF NOT EXISTS " : "",
- row[1]);
+ create_table_str.str);
}
check_io(sql_file);
+ if (create_table_str.str != row[1])
+ dynstr_free(&create_table_str);
mysql_free_result(result);
}
my_snprintf(query_buff, sizeof(query_buff), "show fields from %s",
@@ -3670,7 +3705,7 @@ static char *alloc_query_str(size_t size)
{
char *query;
- if (!(query= (char*) my_malloc(size, MYF(MY_WME))))
+ if (!(query= (char*) my_malloc(PSI_NOT_INSTRUMENTED, size, MYF(MY_WME))))
die(EX_MYSQLERR, "Couldn't allocate a query string.");
return query;
@@ -3722,6 +3757,14 @@ static void dump_table(char *table, char *db, const uchar *hash_key, size_t len)
if (strcmp(table_type, "VIEW") == 0)
DBUG_VOID_RETURN;
+ if (!opt_copy_s3_tables && (ignore_flag & IGNORE_S3_TABLE))
+ {
+ verbose_msg("-- Skipping dump data for table '%s', "
+ " this is S3 table and --copy-s3-tables=0\n",
+ table);
+ DBUG_VOID_RETURN;
+ }
+
/* Check --no-data flag */
if (opt_no_data || (hash_key && ignore_table_data(hash_key, len)))
{
@@ -4149,6 +4192,15 @@ static void dump_table(char *table, char *db, const uchar *hash_key, size_t len)
fputs("\t</table_data>\n", md_result_file);
else if (extended_insert && row_break)
fputs(";\n", md_result_file); /* If not empty table */
+ if (!opt_xml && opt_copy_s3_tables && (ignore_flag & IGNORE_S3_TABLE))
+ {
+ DYNAMIC_STRING alter_string;
+ init_dynamic_string_checked(&alter_string, "ATER TABLE ", 1024, 1024);
+ dynstr_append_checked(&alter_string, opt_quoted_table);
+ dynstr_append_checked(&alter_string, " ENGINE=S3;\n");
+ fputs(alter_string.str, md_result_file);
+ dynstr_free(&alter_string);
+ }
fflush(md_result_file);
check_io(md_result_file);
if (mysql_errno(mysql))
@@ -5047,7 +5099,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
if (init_dumping(db, init_dumping_tables))
DBUG_RETURN(1);
- init_alloc_root(&glob_root, "glob_root", 8192, 0, MYF(0));
+ init_alloc_root(PSI_NOT_INSTRUMENTED, &glob_root, 8192, 0, MYF(0));
if (!(dump_tables= pos= (char**) alloc_root(&glob_root,
tables * sizeof(char *))))
die(EX_EOM, "alloc_root failure.");
@@ -5719,6 +5771,9 @@ char check_if_ignore_table(const char *table_name, char *table_type)
result= IGNORE_INSERT_DELAYED;
}
+ if (!strcmp(table_type, "S3"))
+ result|= IGNORE_S3_TABLE;
+
/*
If these two types, we do want to skip dumping the table
*/
@@ -5796,7 +5851,7 @@ static char *primary_key_fields(const char *table_name)
{
char *end;
/* result (terminating \0 is already in result_length) */
- result= my_malloc(result_length + 10, MYF(MY_WME));
+ result= my_malloc(PSI_NOT_INSTRUMENTED, result_length + 10, MYF(MY_WME));
if (!result)
{
fprintf(stderr, "Error: Not enough memory to store ORDER BY clause\n");
diff --git a/client/mysqlimport.c b/client/mysqlimport.c
index e72eb12cb99..6cb32da2239 100644
--- a/client/mysqlimport.c
+++ b/client/mysqlimport.c
@@ -221,10 +221,10 @@ file. The SQL command 'LOAD DATA INFILE' is used to import the rows.\n");
static my_bool
-get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
- char *argument)
+get_one_option(const struct my_option *opt, char *argument,
+ const char *filename __attribute__((unused)))
{
- switch(optid) {
+ switch(opt->id) {
case 'p':
if (argument == disabled_my_option)
argument= (char*) ""; /* Don't require password */
@@ -232,7 +232,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
{
char *start=argument;
my_free(opt_password);
- opt_password=my_strdup(argument,MYF(MY_FAE));
+ opt_password=my_strdup(PSI_NOT_INSTRUMENTED, argument,MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
if (*start)
start[1]=0; /* Cut length of argument */
@@ -672,9 +672,8 @@ int main(int argc, char **argv)
table_count++;
argv= save_argv;
- if (!(worker_threads= (pthread_t*) my_malloc(table_count *
- sizeof(*worker_threads),
- MYF(0))))
+ if (!(worker_threads= (pthread_t*) my_malloc(PSI_NOT_INSTRUMENTED,
+ table_count * sizeof(*worker_threads), MYF(0))))
return -2;
for (; *argv != NULL; argv++) /* Loop through tables */
diff --git a/client/mysqlshow.c b/client/mysqlshow.c
index db5c2bbbbe6..2b0cae6dc98 100644
--- a/client/mysqlshow.c
+++ b/client/mysqlshow.c
@@ -289,10 +289,10 @@ are shown.");
static my_bool
-get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
- char *argument)
+get_one_option(const struct my_option *opt, char *argument,
+ const char *filename __attribute__((unused)))
{
- switch(optid) {
+ switch(opt->id) {
case 'v':
opt_verbose++;
break;
@@ -303,7 +303,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
{
char *start=argument;
my_free(opt_password);
- opt_password=my_strdup(argument,MYF(MY_FAE));
+ opt_password=my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
if (*start)
start[1]=0; /* Cut length of argument */
diff --git a/client/mysqlslap.c b/client/mysqlslap.c
index ed5e20ca18c..75cd7f14846 100644
--- a/client/mysqlslap.c
+++ b/client/mysqlslap.c
@@ -167,7 +167,7 @@ static char *create_string;
uint *concurrency;
static char mysql_charsets_dir[FN_REFLEN+1];
-const char *default_dbug_option="d:t:o,/tmp/mysqlslap.trace";
+const char *default_dbug_option="d:t:o,/tmp/mariadb-slap.trace";
const char *opt_csv_str;
File csv_file;
@@ -433,8 +433,8 @@ void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr)
unsigned long long client_limit;
int sysret;
- head_sptr= (stats *)my_malloc(sizeof(stats) * iterations,
- MYF(MY_ZEROFILL|MY_FAE|MY_WME));
+ head_sptr= (stats *)my_malloc(PSI_NOT_INSTRUMENTED,
+ sizeof(stats) * iterations, MYF(MY_ZEROFILL|MY_FAE|MY_WME));
bzero(&conclusion, sizeof(conclusions));
@@ -726,11 +726,11 @@ static void usage(void)
static my_bool
-get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
- char *argument)
+get_one_option(const struct my_option *opt, char *argument,
+ const char *filename __attribute__((unused)))
{
DBUG_ENTER("get_one_option");
- switch(optid) {
+ switch(opt->id) {
case 'v':
verbose++;
break;
@@ -741,7 +741,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
{
char *start= argument;
my_free(opt_password);
- opt_password= my_strdup(argument,MYF(MY_FAE));
+ opt_password= my_strdup(PSI_NOT_INSTRUMENTED, argument,MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
if (*start)
start[1]= 0; /* Cut length of argument */
@@ -918,9 +918,9 @@ build_table_string(void)
}
dynstr_append(&table_string, ")");
- ptr= (statement *)my_malloc(sizeof(statement),
+ ptr= (statement *)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(statement),
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
- ptr->string = (char *)my_malloc(table_string.length+1,
+ ptr->string = (char *)my_malloc(PSI_NOT_INSTRUMENTED, table_string.length+1,
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
ptr->length= table_string.length+1;
ptr->type= CREATE_TABLE_TYPE;
@@ -986,10 +986,10 @@ build_update_string(void)
dynstr_append(&update_string, " WHERE id = ");
- ptr= (statement *)my_malloc(sizeof(statement),
+ ptr= (statement *)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(statement),
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
- ptr->string= (char *)my_malloc(update_string.length + 1,
+ ptr->string= (char *)my_malloc(PSI_NOT_INSTRUMENTED, update_string.length + 1,
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
ptr->length= update_string.length+1;
if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
@@ -1082,9 +1082,9 @@ build_insert_string(void)
dynstr_append_mem(&insert_string, ")", 1);
- ptr= (statement *)my_malloc(sizeof(statement),
+ ptr= (statement *)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(statement),
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
- ptr->string= (char *)my_malloc(insert_string.length + 1,
+ ptr->string= (char *)my_malloc(PSI_NOT_INSTRUMENTED, insert_string.length + 1,
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
ptr->length= insert_string.length+1;
ptr->type= INSERT_TYPE;
@@ -1146,9 +1146,9 @@ build_select_string(my_bool key)
(auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
dynstr_append(&query_string, " WHERE id = ");
- ptr= (statement *)my_malloc(sizeof(statement),
+ ptr= (statement *)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(statement),
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
- ptr->string= (char *)my_malloc(query_string.length + 1,
+ ptr->string= (char *)my_malloc(PSI_NOT_INSTRUMENTED, query_string.length + 1,
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
ptr->length= query_string.length+1;
if ((key) &&
@@ -1405,7 +1405,7 @@ get_options(int *argc,char ***argv)
fprintf(stderr,"%s: Could not open create file\n", my_progname);
exit(1);
}
- tmp_string= (char *)my_malloc((size_t)sbuf.st_size + 1,
+ tmp_string= (char *)my_malloc(PSI_NOT_INSTRUMENTED, (size_t)sbuf.st_size + 1,
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
my_read(data_file, (uchar*) tmp_string, (size_t)sbuf.st_size, MYF(0));
tmp_string[sbuf.st_size]= '\0';
@@ -1432,7 +1432,7 @@ get_options(int *argc,char ***argv)
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
exit(1);
}
- tmp_string= (char *)my_malloc((size_t)sbuf.st_size + 1,
+ tmp_string= (char *)my_malloc(PSI_NOT_INSTRUMENTED, (size_t)sbuf.st_size + 1,
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
my_read(data_file, (uchar*) tmp_string, (size_t)sbuf.st_size, MYF(0));
tmp_string[sbuf.st_size]= '\0';
@@ -1463,7 +1463,7 @@ get_options(int *argc,char ***argv)
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
exit(1);
}
- tmp_string= (char *)my_malloc((size_t)sbuf.st_size + 1,
+ tmp_string= (char *)my_malloc(PSI_NOT_INSTRUMENTED, (size_t)sbuf.st_size + 1,
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
my_read(data_file, (uchar*) tmp_string, (size_t)sbuf.st_size, MYF(0));
tmp_string[sbuf.st_size]= '\0';
@@ -1494,7 +1494,7 @@ get_options(int *argc,char ***argv)
fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
exit(1);
}
- tmp_string= (char *)my_malloc((size_t)sbuf.st_size + 1,
+ tmp_string= (char *)my_malloc(PSI_NOT_INSTRUMENTED, (size_t)sbuf.st_size + 1,
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
my_read(data_file, (uchar*) tmp_string, (size_t)sbuf.st_size, MYF(0));
tmp_string[sbuf.st_size]= '\0';
@@ -1560,11 +1560,11 @@ generate_primary_key_list(MYSQL *mysql, option_string *engine_stmt)
strstr(engine_stmt->string, "blackhole")))
{
primary_keys_number_of= 1;
- primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
- primary_keys_number_of),
- MYF(MY_ZEROFILL|MY_FAE|MY_WME));
+ primary_keys= (char **)my_malloc(PSI_NOT_INSTRUMENTED,
+ (size_t)(sizeof(char *) * primary_keys_number_of),
+ MYF(MY_ZEROFILL|MY_FAE|MY_WME));
/* Yes, we strdup a const string to simplify the interface */
- primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
+ primary_keys[0]= my_strdup(PSI_NOT_INSTRUMENTED, "796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
}
else
{
@@ -1589,13 +1589,13 @@ generate_primary_key_list(MYSQL *mysql, option_string *engine_stmt)
/*
We create the structure and loop and create the items.
*/
- primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
- primary_keys_number_of),
- MYF(MY_ZEROFILL|MY_FAE|MY_WME));
+ primary_keys= (char **)my_malloc(PSI_NOT_INSTRUMENTED,
+ (size_t)(sizeof(char *) * primary_keys_number_of),
+ MYF(MY_ZEROFILL|MY_FAE|MY_WME));
row= mysql_fetch_row(result);
for (counter= 0; counter < primary_keys_number_of;
counter++, row= mysql_fetch_row(result))
- primary_keys[counter]= my_strdup(row[0], MYF(0));
+ primary_keys[counter]= my_strdup(PSI_NOT_INSTRUMENTED, row[0], MYF(0));
}
mysql_free_result(result);
@@ -2006,10 +2006,10 @@ parse_option(const char *origin, option_string **stmt, char delm)
size_t length= strlen(origin);
uint count= 0; /* We know that there is always one */
- for (tmp= *sptr= (option_string *)my_malloc(sizeof(option_string),
+ for (tmp= *sptr= (option_string *)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(option_string),
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
(retstr= strchr(ptr, delm));
- tmp->next= (option_string *)my_malloc(sizeof(option_string),
+ tmp->next= (option_string *)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(option_string),
MYF(MY_ZEROFILL|MY_FAE|MY_WME)),
tmp= tmp->next)
{
@@ -2040,18 +2040,18 @@ parse_option(const char *origin, option_string **stmt, char delm)
char *option_ptr;
tmp->length= (size_t)(buffer_ptr - buffer);
- tmp->string= my_strndup(ptr, (uint)tmp->length, MYF(MY_FAE));
+ tmp->string= my_strndup(PSI_NOT_INSTRUMENTED, ptr, (uint)tmp->length, MYF(MY_FAE));
option_ptr= ptr + 1 + tmp->length;
/* Move past the : and the first string */
tmp->option_length= (size_t)(retstr - option_ptr);
- tmp->option= my_strndup(option_ptr, (uint)tmp->option_length,
+ tmp->option= my_strndup(PSI_NOT_INSTRUMENTED, option_ptr, (uint)tmp->option_length,
MYF(MY_FAE));
}
else
{
- tmp->string= my_strndup(ptr, (size_t)(retstr - ptr), MYF(MY_FAE));
+ tmp->string= my_strndup(PSI_NOT_INSTRUMENTED, ptr, (size_t)(retstr - ptr), MYF(MY_FAE));
tmp->length= (size_t)(retstr - ptr);
}
@@ -2079,19 +2079,19 @@ parse_option(const char *origin, option_string **stmt, char delm)
char *option_ptr;
tmp->length= (size_t)(origin_ptr - ptr);
- tmp->string= my_strndup(ptr, tmp->length, MYF(MY_FAE));
+ tmp->string= my_strndup(PSI_NOT_INSTRUMENTED, ptr, tmp->length, MYF(MY_FAE));
option_ptr= (char *)ptr + 1 + tmp->length;
/* Move past the : and the first string */
tmp->option_length= strlen(option_ptr);
- tmp->option= my_strndup(option_ptr, tmp->option_length,
+ tmp->option= my_strndup(PSI_NOT_INSTRUMENTED, option_ptr, tmp->option_length,
MYF(MY_FAE));
}
else
{
tmp->length= strlen(ptr);
- tmp->string= my_strndup(ptr, tmp->length, MYF(MY_FAE));
+ tmp->string= my_strndup(PSI_NOT_INSTRUMENTED, ptr, tmp->length, MYF(MY_FAE));
}
count++;
@@ -2111,15 +2111,15 @@ parse_delimiter(const char *script, statement **stmt, char delm)
size_t length= strlen(script);
uint count= 0; /* We know that there is always one */
- for (tmp= *sptr= (statement *)my_malloc(sizeof(statement),
+ for (tmp= *sptr= (statement *)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(statement),
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
(retstr= strchr(ptr, delm));
- tmp->next= (statement *)my_malloc(sizeof(statement),
+ tmp->next= (statement *)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(statement),
MYF(MY_ZEROFILL|MY_FAE|MY_WME)),
tmp= tmp->next)
{
count++;
- tmp->string= my_strndup(ptr, (uint)(retstr - ptr), MYF(MY_FAE));
+ tmp->string= my_strndup(PSI_NOT_INSTRUMENTED, ptr, (uint)(retstr - ptr), MYF(MY_FAE));
tmp->length= (size_t)(retstr - ptr);
ptr+= retstr - ptr + 1;
if (isspace(*ptr))
@@ -2128,7 +2128,7 @@ parse_delimiter(const char *script, statement **stmt, char delm)
if (ptr != script+length)
{
- tmp->string= my_strndup(ptr, (uint)((script + length) - ptr),
+ tmp->string= my_strndup(PSI_NOT_INSTRUMENTED, ptr, (uint)((script + length) - ptr),
MYF(MY_FAE));
tmp->length= (size_t)((script + length) - ptr);
count++;
@@ -2150,7 +2150,7 @@ parse_comma(const char *string, uint **range)
if (*ptr == ',') count++;
/* One extra spot for the NULL */
- nptr= *range= (uint *)my_malloc(sizeof(uint) * (count + 1),
+ nptr= *range= (uint *)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(uint) * (count + 1),
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
ptr= (char *)string;
diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index 84a3875f308..79ca4ed60e7 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates.
- Copyright (c) 2009, 2019, MariaDB
+ Copyright (c) 2009, 2020, MariaDB
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
@@ -40,12 +40,13 @@
#include <mysqld_error.h>
#include <sql_common.h>
#include <m_ctype.h>
+#include "client_metadata.h"
#include <my_dir.h>
#include <hash.h>
#include <stdarg.h>
#include <violite.h>
-#define PCRE_STATIC 1 /* Important on Windows */
-#include "pcreposix.h" /* pcreposix regex library */
+#define PCRE2_STATIC 1 /* Important on Windows */
+#include "pcre2posix.h" /* pcreposix regex library */
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
@@ -96,8 +97,7 @@ static int setenv(const char *name, const char *value, int overwrite);
C_MODE_START
static sig_handler signal_handler(int sig);
-static my_bool get_one_option(int optid, const struct my_option *,
- char *argument);
+static my_bool get_one_option(const struct my_option *, char *, const char *);
C_MODE_END
enum {
@@ -1462,7 +1462,7 @@ void free_used_memory()
}
-static void cleanup_and_exit(int exit_code)
+ATTRIBUTE_NORETURN static void cleanup_and_exit(int exit_code)
{
free_used_memory();
@@ -1705,7 +1705,7 @@ int cat_file(DYNAMIC_STRING* ds, const char* filename)
len= (size_t) my_seek(fd, 0, SEEK_END, MYF(0));
my_seek(fd, 0, SEEK_SET, MYF(0));
if (len == (size_t)MY_FILEPOS_ERROR ||
- !(buff= (char*)my_malloc(len + 1, MYF(0))))
+ !(buff= (char*)my_malloc(PSI_NOT_INSTRUMENTED, len + 1, MYF(0))))
{
my_close(fd, MYF(0));
return 1;
@@ -2363,7 +2363,7 @@ VAR *var_init(VAR *v, const char *name, size_t name_len, const char *val, size_t
if (!val)
val_len= 0;
val_alloc_len = val_len + 16; /* room to grow */
- if (!(tmp_var=v) && !(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var)
+ if (!(tmp_var=v) && !(tmp_var = (VAR*)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(*tmp_var)
+ name_len+2, MYF(MY_WME))))
die("Out of memory");
@@ -2378,7 +2378,7 @@ VAR *var_init(VAR *v, const char *name, size_t name_len, const char *val, size_t
tmp_var->alloced = (v == 0);
- if (!(tmp_var->str_val = (char*)my_malloc(val_alloc_len+1, MYF(MY_WME))))
+ if (!(tmp_var->str_val = (char*)my_malloc(PSI_NOT_INSTRUMENTED, val_alloc_len+1, MYF(MY_WME))))
die("Out of memory");
if (val)
@@ -2926,8 +2926,8 @@ void var_copy(VAR *dest, VAR *src)
/* Alloc/realloc data for str_val in dest */
if (dest->alloced_len < src->alloced_len &&
!(dest->str_val= dest->str_val
- ? (char*)my_realloc(dest->str_val, src->alloced_len, MYF(MY_WME))
- : (char*)my_malloc(src->alloced_len, MYF(MY_WME))))
+ ? (char*)my_realloc(PSI_NOT_INSTRUMENTED, dest->str_val, src->alloced_len, MYF(MY_WME))
+ : (char*)my_malloc(PSI_NOT_INSTRUMENTED, src->alloced_len, MYF(MY_WME))))
die("Out of memory");
else
dest->alloced_len= src->alloced_len;
@@ -3004,8 +3004,8 @@ void eval_expr(VAR *v, const char *p, const char **p_end,
MIN_VAR_ALLOC : new_val_len + 1;
if (!(v->str_val =
v->str_val ?
- (char*)my_realloc(v->str_val, v->alloced_len+1, MYF(MY_WME)) :
- (char*)my_malloc(v->alloced_len+1, MYF(MY_WME))))
+ (char*)my_realloc(PSI_NOT_INSTRUMENTED, v->str_val, v->alloced_len+1, MYF(MY_WME)) :
+ (char*)my_malloc(PSI_NOT_INSTRUMENTED, v->alloced_len+1, MYF(MY_WME))))
die("Out of memory");
}
v->str_val_len = new_val_len;
@@ -3026,7 +3026,7 @@ bool open_and_set_current(const char *name)
cur_file++;
cur_file->file= opened;
- cur_file->file_name= my_strdup(name, MYF(MY_FAE));
+ cur_file->file_name= my_strdup(PSI_NOT_INSTRUMENTED, name, MYF(MY_FAE));
cur_file->lineno=1;
return true;
}
@@ -4778,7 +4778,7 @@ void do_sync_with_master(struct st_command *command)
p++;
while (*p && my_isspace(charset_info, *p))
p++;
- start= buff= (char*)my_malloc(strlen(p)+1,MYF(MY_WME | MY_FAE));
+ start= buff= (char*)my_malloc(PSI_NOT_INSTRUMENTED, strlen(p)+1,MYF(MY_WME | MY_FAE));
get_string(&buff, &p, command);
}
command->last_argument= p;
@@ -5583,7 +5583,7 @@ void do_close_connection(struct st_command *command)
When the connection is closed set name to "-closed_connection-"
to make it possible to reuse the connection name.
*/
- if (!(con->name = my_strdup("-closed_connection-", MYF(MY_WME))))
+ if (!(con->name = my_strdup(PSI_NOT_INSTRUMENTED, "-closed_connection-", MYF(MY_WME))))
die("Out of memory");
if (con == cur_con)
@@ -5825,13 +5825,21 @@ do_handle_error:
*/
+enum use_ssl
+{
+ USE_SSL_FORBIDDEN = -1,
+ USE_SSL_IF_POSSIBLE,
+ USE_SSL_REQUIRED
+};
+
void do_connect(struct st_command *command)
{
+ uint protocol= opt_protocol;
int con_port= opt_port;
char *con_options;
char *ssl_cipher __attribute__((unused))= 0;
- my_bool con_ssl= 0, con_compress= 0;
- my_bool con_pipe= 0;
+ enum use_ssl con_ssl __attribute__((unused))= USE_SSL_IF_POSSIBLE;
+ my_bool con_compress= 0;
int read_timeout= 0;
int write_timeout= 0;
int connect_timeout= 0;
@@ -5913,16 +5921,38 @@ void do_connect(struct st_command *command)
end++;
length= (size_t) (end - con_options);
if (length == 3 && !strncmp(con_options, "SSL", 3))
- con_ssl= 1;
+ con_ssl= USE_SSL_REQUIRED;
+ else if (length == 5 && !strncmp(con_options, "NOSSL", 5))
+ con_ssl= USE_SSL_FORBIDDEN;
else if (!strncmp(con_options, "SSL-CIPHER=", 11))
{
- con_ssl= 1;
+ con_ssl= USE_SSL_REQUIRED;
ssl_cipher=con_options + 11;
}
else if (length == 8 && !strncmp(con_options, "COMPRESS", 8))
con_compress= 1;
+ else if (length == 3 && !strncmp(con_options, "TCP", 3))
+ protocol= MYSQL_PROTOCOL_TCP;
+ else if (length == 7 && !strncmp(con_options, "DEFAULT", 7))
+ protocol= MYSQL_PROTOCOL_DEFAULT;
else if (length == 4 && !strncmp(con_options, "PIPE", 4))
- con_pipe= 1;
+ {
+#ifdef _WIN32
+ protocol= MYSQL_PROTOCOL_PIPE;
+#endif
+ }
+ else if (length == 6 && !strncmp(con_options, "SOCKET", 6))
+ {
+#ifndef _WIN32
+ protocol= MYSQL_PROTOCOL_SOCKET;
+#endif
+ }
+ else if (length == 6 && !strncmp(con_options, "MEMORY", 6))
+ {
+#ifdef _WIN32
+ protocol= MYSQL_PROTOCOL_MEMORY;
+#endif
+ }
else if (strncasecmp(con_options, "read_timeout=",
sizeof("read_timeout=")-1) == 0)
{
@@ -5983,14 +6013,13 @@ void do_connect(struct st_command *command)
if (opt_charsets_dir)
mysql_options(con_slot->mysql, MYSQL_SET_CHARSET_DIR,
opt_charsets_dir);
+
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
- if (opt_use_ssl)
- con_ssl= 1;
-#endif
+ if (con_ssl == USE_SSL_IF_POSSIBLE && opt_use_ssl)
+ con_ssl= USE_SSL_REQUIRED;
- if (con_ssl)
+ if (con_ssl == USE_SSL_REQUIRED)
{
-#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
mysql_ssl_set(con_slot->mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
opt_ssl_capath, ssl_cipher ? ssl_cipher : opt_ssl_cipher);
mysql_options(con_slot->mysql, MYSQL_OPT_SSL_CRL, opt_ssl_crl);
@@ -6002,18 +6031,11 @@ void do_connect(struct st_command *command)
mysql_options(con_slot->mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
&opt_ssl_verify_server_cert);
#endif
-#endif
}
-
- if (con_pipe)
- {
-#ifdef _WIN32
- opt_protocol= MYSQL_PROTOCOL_PIPE;
#endif
- }
- if (opt_protocol)
- mysql_options(con_slot->mysql, MYSQL_OPT_PROTOCOL, (char*) &opt_protocol);
+ if (protocol)
+ mysql_options(con_slot->mysql, MYSQL_OPT_PROTOCOL, (char*) &protocol);
if (read_timeout)
{
@@ -6054,7 +6076,7 @@ void do_connect(struct st_command *command)
{
DBUG_PRINT("info", ("Inserting connection %s in connection pool",
ds_connection_name.str));
- if (!(con_slot->name= my_strdup(ds_connection_name.str, MYF(MY_WME))))
+ if (!(con_slot->name= my_strdup(PSI_NOT_INSTRUMENTED, ds_connection_name.str, MYF(MY_WME))))
die("Out of memory");
con_slot->name_len= strlen(con_slot->name);
set_current_connection(con_slot);
@@ -6505,7 +6527,7 @@ int read_line()
if (p >= buf_end)
{
my_ptrdiff_t off= p - read_command_buf;
- read_command_buf= (char*)my_realloc(read_command_buf,
+ read_command_buf= (char*)my_realloc(PSI_NOT_INSTRUMENTED, read_command_buf,
read_command_buflen*2, MYF(MY_FAE));
p= read_command_buf + off;
read_command_buflen*= 2;
@@ -6666,14 +6688,14 @@ int read_line()
if (!skip_char)
{
*p++= c;
- if (use_mb(charset_info))
+ if (charset_info->use_mb())
{
const char *mb_start= p - 1;
/* Could be a multibyte character */
/* See a similar code in "sql_load.cc" */
for ( ; p < buf_end; )
{
- int charlen= my_charlen(charset_info, mb_start, p);
+ int charlen= charset_info->charlen(mb_start, p);
if (charlen > 0)
break; /* Full character */
if (MY_CS_IS_TOOSMALL(charlen))
@@ -6852,7 +6874,7 @@ int read_command(struct st_command** command_ptr)
DBUG_RETURN(0);
}
if (!(*command_ptr= command=
- (struct st_command*) my_malloc(sizeof(*command),
+ (struct st_command*) my_malloc(PSI_NOT_INSTRUMENTED, sizeof(*command),
MYF(MY_WME|MY_ZEROFILL))) ||
insert_dynamic(&q_lines, &command))
die("Out of memory");
@@ -6887,7 +6909,7 @@ int read_command(struct st_command** command_ptr)
while (*p && my_isspace(charset_info, *p))
p++;
- if (!(command->query_buf= command->query= my_strdup(p, MYF(MY_WME))))
+ if (!(command->query_buf= command->query= my_strdup(PSI_NOT_INSTRUMENTED, p, MYF(MY_WME))))
die("Out of memory");
/*
@@ -7100,7 +7122,7 @@ void read_embedded_server_arguments(const char *name)
{
*(strend(str)-1)=0; /* Remove end newline */
if (!(embedded_server_args[embedded_server_arg_count]=
- my_strdup(str, MYF(MY_WME))))
+ my_strdup(PSI_NOT_INSTRUMENTED, str, MYF(MY_WME))))
{
my_fclose(file,MYF(0));
die("Out of memory");
@@ -7117,9 +7139,9 @@ void read_embedded_server_arguments(const char *name)
static my_bool
-get_one_option(int optid, const struct my_option *opt, char *argument)
+get_one_option(const struct my_option *opt, char *argument, const char *)
{
- switch(optid) {
+ switch(opt->id) {
case '#':
#ifndef DBUG_OFF
DBUG_PUSH(argument ? argument : "d:t:S:i:O,/tmp/mysqltest.trace");
@@ -7143,7 +7165,7 @@ get_one_option(int optid, const struct my_option *opt, char *argument)
if (!(cur_file->file=
fopen(buff, "rb")))
die("Could not open '%s' for reading, errno: %d", buff, errno);
- cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
+ cur_file->file_name= my_strdup(PSI_NOT_INSTRUMENTED, buff, MYF(MY_FAE));
cur_file->lineno= 1;
break;
}
@@ -7166,7 +7188,7 @@ get_one_option(int optid, const struct my_option *opt, char *argument)
if (argument)
{
my_free(opt_pass);
- opt_pass= my_strdup(argument, MYF(MY_FAE));
+ opt_pass= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
tty_password= 0;
}
@@ -7185,7 +7207,7 @@ get_one_option(int optid, const struct my_option *opt, char *argument)
}
if (embedded_server_arg_count == MAX_EMBEDDED_SERVER_ARGS-1 ||
!(embedded_server_args[embedded_server_arg_count++]=
- my_strdup(argument, MYF(MY_FAE))))
+ my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE))))
{
die("Can't use server argument");
}
@@ -7359,7 +7381,7 @@ void init_win_path_patterns()
DBUG_ENTER("init_win_path_patterns");
- my_init_dynamic_array(&patterns, sizeof(const char*), 16, 16, MYF(0));
+ my_init_dynamic_array(PSI_NOT_INSTRUMENTED, &patterns, sizeof(const char*), 16, 16, MYF(0));
/* Loop through all paths in the array */
for (i= 0; i < num_paths; i++)
@@ -7368,10 +7390,10 @@ void init_win_path_patterns()
if (*(paths[i]) == '$')
{
v= var_get(paths[i], 0, 0, 0);
- p= my_strdup(v->str_val, MYF(MY_FAE));
+ p= my_strdup(PSI_NOT_INSTRUMENTED, v->str_val, MYF(MY_FAE));
}
else
- p= my_strdup(paths[i], MYF(MY_FAE));
+ p= my_strdup(PSI_NOT_INSTRUMENTED, paths[i], MYF(MY_FAE));
/* Don't insert zero length strings in patterns array */
if (strlen(p) == 0)
@@ -7555,11 +7577,11 @@ void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt,
int error;
/* Allocate array with bind structs, lengths and NULL flags */
- my_bind= (MYSQL_BIND*) my_malloc(num_fields * sizeof(MYSQL_BIND),
+ my_bind= (MYSQL_BIND*) my_malloc(PSI_NOT_INSTRUMENTED, num_fields * sizeof(MYSQL_BIND),
MYF(MY_WME | MY_FAE | MY_ZEROFILL));
- length= (ulong*) my_malloc(num_fields * sizeof(ulong),
+ length= (ulong*) my_malloc(PSI_NOT_INSTRUMENTED, num_fields * sizeof(ulong),
MYF(MY_WME | MY_FAE));
- is_null= (my_bool*) my_malloc(num_fields * sizeof(my_bool),
+ is_null= (my_bool*) my_malloc(PSI_NOT_INSTRUMENTED, num_fields * sizeof(my_bool),
MYF(MY_WME | MY_FAE));
/* Allocate data for the result of each field */
@@ -7567,7 +7589,7 @@ void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt,
{
uint max_length= fields[i].max_length + 1;
my_bind[i].buffer_type= MYSQL_TYPE_STRING;
- my_bind[i].buffer= my_malloc(max_length, MYF(MY_WME | MY_FAE));
+ my_bind[i].buffer= my_malloc(PSI_NOT_INSTRUMENTED, max_length, MYF(MY_WME | MY_FAE));
my_bind[i].buffer_length= max_length;
my_bind[i].is_null= &is_null[i];
my_bind[i].length= &length[i];
@@ -7642,6 +7664,17 @@ void append_metadata(DYNAMIC_STRING *ds,
dynstr_append_mem(ds, field->name, field->name_length);
dynstr_append_mem(ds, "\t", 1);
replace_dynstr_append_uint(ds, field->type);
+
+ Client_field_metadata metadata(field);
+ BinaryStringBuffer<128> data_type_metadata_str;
+ metadata.print_data_type_related_attributes(&data_type_metadata_str);
+ if (data_type_metadata_str.length())
+ {
+ dynstr_append_mem(ds, " (", 2);
+ dynstr_append_mem(ds, data_type_metadata_str.ptr(),
+ data_type_metadata_str.length());
+ dynstr_append_mem(ds, ")", 1);
+ }
dynstr_append_mem(ds, "\t", 1);
replace_dynstr_append_uint(ds, field->length);
dynstr_append_mem(ds, "\t", 1);
@@ -7678,6 +7711,28 @@ void append_info(DYNAMIC_STRING *ds, ulonglong affected_rows,
}
+#ifndef EMBEDDED_LIBRARY
+static const char *trking_info_desc[SESSION_TRACK_END + 1]=
+{
+ "Tracker : SESSION_TRACK_SYSTEM_VARIABLES\n",
+ "Tracker : SESSION_TRACK_SCHEMA\n",
+ "Tracker : SESSION_TRACK_STATE_CHANGE\n",
+ "Tracker : SESSION_TRACK_GTIDS\n",
+ "Tracker : SESSION_TRACK_TRANSACTION_CHARACTERISTICS\n",
+ "Tracker : SESSION_TRACK_TRANSACTION_TYPE\n"
+#ifdef USER_VAR_TRACKING
+ ,
+ "Tracker : SESSION_TRACK_MYSQL_RESERVED1\n",
+ "Tracker : SESSION_TRACK_MYSQL_RESERVED2\n",
+ "Tracker : SESSION_TRACK_MYSQL_RESERVED3\n",
+ "Tracker : SESSION_TRACK_MYSQL_RESERVED4\n",
+ "Tracker : SESSION_TRACK_MYSQL_RESERVED5\n",
+ "Tracker : SESSION_TRACK_MYSQL_RESERVED6\n",
+ "Tracker : SESSION_TRACK_USER_VARIABLES\n"
+#endif // USER_VAR_TRACKING
+};
+#endif // EMBEDDED_LIBRARY
+
/**
@brief Append state change information (received through Ok packet) to the output.
@@ -7698,31 +7753,15 @@ static void append_session_track_info(DYNAMIC_STRING *ds, MYSQL *mysql)
&data, &data_length))
{
dynstr_append(ds, "-- ");
- switch (type)
+ if (type <= SESSION_TRACK_END)
{
- case SESSION_TRACK_SYSTEM_VARIABLES:
- dynstr_append(ds, "Tracker : SESSION_TRACK_SYSTEM_VARIABLES\n");
- break;
- case SESSION_TRACK_SCHEMA:
- dynstr_append(ds, "Tracker : SESSION_TRACK_SCHEMA\n");
- break;
- case SESSION_TRACK_STATE_CHANGE:
- dynstr_append(ds, "Tracker : SESSION_TRACK_STATE_CHANGE\n");
- break;
- case SESSION_TRACK_GTIDS:
- dynstr_append(ds, "Tracker : SESSION_TRACK_GTIDS\n");
- break;
- case SESSION_TRACK_TRANSACTION_CHARACTERISTICS:
- dynstr_append(ds, "Tracker : SESSION_TRACK_TRANSACTION_CHARACTERISTICS\n");
- break;
- case SESSION_TRACK_TRANSACTION_TYPE:
- dynstr_append(ds, "Tracker : SESSION_TRACK_TRANSACTION_TYPE\n");
- break;
- default:
- DBUG_ASSERT(0);
- dynstr_append(ds, "\n");
+ dynstr_append(ds, trking_info_desc[type]);
+ }
+ else
+ {
+ DBUG_ASSERT(0);
+ dynstr_append(ds, "Tracker???\n");
}
-
dynstr_append(ds, "-- ");
dynstr_append_mem(ds, data, data_length);
@@ -7734,7 +7773,13 @@ static void append_session_track_info(DYNAMIC_STRING *ds, MYSQL *mysql)
&data, &data_length))
{
dynstr_append(ds, "\n-- ");
- dynstr_append_mem(ds, data, data_length);
+ if (data == NULL)
+ {
+ DBUG_ASSERT(data_length == 0);
+ dynstr_append_mem(ds, "<NULL>", sizeof("<NULL>") - 1);
+ }
+ else
+ dynstr_append_mem(ds, data, data_length);
}
dynstr_append(ds, "\n\n");
}
@@ -9044,7 +9089,7 @@ static void init_signal_handling(void)
DBUG_ENTER("init_signal_handling");
#ifdef HAVE_STACKTRACE
- my_init_stacktrace();
+ my_init_stacktrace(0);
#endif
sa.sa_flags = SA_RESETHAND | SA_NODEFER;
@@ -9106,10 +9151,10 @@ int main(int argc, char **argv)
cur_block->ok= TRUE; /* Outer block should always be executed */
cur_block->cmd= cmd_none;
- my_init_dynamic_array(&q_lines, sizeof(struct st_command*), 1024, 1024, MYF(0));
+ my_init_dynamic_array(PSI_NOT_INSTRUMENTED, &q_lines, sizeof(struct st_command*), 1024, 1024, MYF(0));
- if (my_hash_init2(&var_hash, 64, charset_info,
- 128, 0, 0, get_var_key, 0, var_free, MYF(0)))
+ if (my_hash_init2(PSI_NOT_INSTRUMENTED, &var_hash, 64, charset_info, 128, 0,
+ 0, get_var_key, 0, var_free, MYF(0)))
die("Variable hash initialization failed");
{
@@ -9139,10 +9184,10 @@ int main(int argc, char **argv)
init_win_path_patterns();
#endif
- read_command_buf= (char*)my_malloc(read_command_buflen= 65536, MYF(MY_FAE));
+ read_command_buf= (char*)my_malloc(PSI_NOT_INSTRUMENTED, read_command_buflen= 65536, MYF(MY_FAE));
init_dynamic_string(&ds_res, "", 2048, 2048);
- init_alloc_root(&require_file_root, "require_file", 1024, 1024, MYF(0));
+ init_alloc_root(PSI_NOT_INSTRUMENTED, &require_file_root, 1024, 1024, MYF(0));
parse_args(argc, argv);
@@ -9156,7 +9201,7 @@ int main(int argc, char **argv)
/* Init connections, allocate 1 extra as buffer + 1 for default */
connections= (struct st_connection*)
- my_malloc((opt_max_connections+2) * sizeof(struct st_connection),
+ my_malloc(PSI_NOT_INSTRUMENTED, (opt_max_connections+2) * sizeof(struct st_connection),
MYF(MY_WME | MY_ZEROFILL));
connections_end= connections + opt_max_connections +1;
next_con= connections + 1;
@@ -9187,7 +9232,7 @@ int main(int argc, char **argv)
if (cur_file == file_stack && cur_file->file == 0)
{
cur_file->file= stdin;
- cur_file->file_name= my_strdup("<stdin>", MYF(MY_WME));
+ cur_file->file_name= my_strdup(PSI_NOT_INSTRUMENTED, "<stdin>", MYF(MY_WME));
cur_file->lineno= 1;
}
var_set_string("MYSQLTEST_FILE", cur_file->file_name);
@@ -9240,7 +9285,7 @@ int main(int argc, char **argv)
}
#endif
- if (!(con->name = my_strdup("default", MYF(MY_WME))))
+ if (!(con->name = my_strdup(PSI_NOT_INSTRUMENTED, "default", MYF(MY_WME))))
die("Out of memory");
mysql_options(con->mysql, MYSQL_OPT_NONBLOCK, 0);
@@ -9648,7 +9693,8 @@ int main(int argc, char **argv)
break;
case Q_DIE:
/* Abort test with error code and error message */
- die("%s", command->first_argument);
+ die("%s", command->first_argument[0] ? command->first_argument :
+ "Explicit --die command executed");
break;
case Q_EXIT:
/* Stop processing any more commands */
@@ -9837,7 +9883,7 @@ void do_get_replace_column(struct st_command *command)
die("Missing argument in %s", command->query);
/* Allocate a buffer for results */
- start= buff= (char*)my_malloc(strlen(from)+1,MYF(MY_WME | MY_FAE));
+ start= buff= (char*)my_malloc(PSI_NOT_INSTRUMENTED, strlen(from)+1,MYF(MY_WME | MY_FAE));
while (*from)
{
char *to;
@@ -9850,7 +9896,7 @@ void do_get_replace_column(struct st_command *command)
command->query);
to= get_string(&buff, &from, command);
my_free(replace_column[column_number-1]);
- replace_column[column_number-1]= my_strdup(to, MYF(MY_WME | MY_FAE));
+ replace_column[column_number-1]= my_strdup(PSI_NOT_INSTRUMENTED, to, MYF(MY_WME | MY_FAE));
set_if_bigger(max_replace_column, column_number);
}
my_free(start);
@@ -9917,7 +9963,7 @@ void do_get_replace(struct st_command *command)
bzero(&from_array,sizeof(from_array));
if (!*from)
die("Missing argument in %s", command->query);
- start= buff= (char*)my_malloc(strlen(from)+1,MYF(MY_WME | MY_FAE));
+ start= buff= (char*)my_malloc(PSI_NOT_INSTRUMENTED, strlen(from)+1,MYF(MY_WME | MY_FAE));
while (*from)
{
char *to= buff;
@@ -10079,17 +10125,17 @@ struct st_replace_regex* init_replace_regex(char* expr)
size_t expr_len= strlen(expr);
/* my_malloc() will die on fail with MY_FAE */
- res=(struct st_replace_regex*)my_malloc(
+ res=(struct st_replace_regex*)my_malloc(PSI_NOT_INSTRUMENTED,
sizeof(*res)+8192 ,MYF(MY_FAE+MY_WME));
- my_init_dynamic_array(&res->regex_arr,sizeof(struct st_regex), 128, 128, MYF(0));
+ my_init_dynamic_array(PSI_NOT_INSTRUMENTED, &res->regex_arr, sizeof(struct st_regex), 128, 128, MYF(0));
expr_end= expr + expr_len;
buf_p= (char*)res + sizeof(*res);
append_replace_regex(expr, expr_end, res, &buf_p);
res->odd_buf_len= res->even_buf_len= 8192;
- res->even_buf= (char*)my_malloc(res->even_buf_len,MYF(MY_WME+MY_FAE));
- res->odd_buf= (char*)my_malloc(res->odd_buf_len,MYF(MY_WME+MY_FAE));
+ res->even_buf= (char*)my_malloc(PSI_NOT_INSTRUMENTED, res->even_buf_len,MYF(MY_WME+MY_FAE));
+ res->odd_buf= (char*)my_malloc(PSI_NOT_INSTRUMENTED, res->odd_buf_len,MYF(MY_WME+MY_FAE));
res->buf= res->even_buf;
return res;
@@ -10126,7 +10172,7 @@ void append_replace_regex(char* expr, char *expr_end, struct st_replace_regex* r
/* Allow variable for the *entire* list of replacements */
if (*p == '$')
{
- const char *v_end;
+ const char *v_end= 0;
VAR *val= var_get(p, &v_end, 0, 1);
if (val)
@@ -10273,7 +10319,7 @@ void free_replace_regex()
#define SECURE_REG_BUF if (buf_len < need_buf_len) \
{ \
ssize_t off= res_p - buf; \
- buf= (char*)my_realloc(buf,need_buf_len,MYF(MY_WME+MY_FAE)); \
+ buf= (char*)my_realloc(PSI_NOT_INSTRUMENTED, buf,need_buf_len,MYF(MY_WME+MY_FAE)); \
res_p= buf + off; \
buf_len= need_buf_len; \
} \
@@ -10326,7 +10372,7 @@ int reg_replace(char** buf_p, int* buf_len_p, char *pattern,
return 1;
}
- subs= (regmatch_t*)my_malloc(sizeof(regmatch_t) * (r.re_nsub+1),
+ subs= (regmatch_t*)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(regmatch_t) * (r.re_nsub+1),
MYF(MY_WME+MY_FAE));
*res_p= 0;
@@ -10574,7 +10620,7 @@ REPLACE *init_replace(char * *from, char * *to,uint count,
if (init_sets(&sets,states))
DBUG_RETURN(0);
found_sets=0;
- if (!(found_set= (FOUND_SET*) my_malloc(sizeof(FOUND_SET)*max_length*count,
+ if (!(found_set= (FOUND_SET*) my_malloc(PSI_NOT_INSTRUMENTED, sizeof(FOUND_SET)*max_length*count,
MYF(MY_WME))))
{
free_sets(&sets);
@@ -10585,7 +10631,7 @@ REPLACE *init_replace(char * *from, char * *to,uint count,
used_sets=-1;
word_states=make_new_set(&sets); /* Start of new word */
start_states=make_new_set(&sets); /* This is first state */
- if (!(follow=(FOLLOWS*) my_malloc((states+2)*sizeof(FOLLOWS),MYF(MY_WME))))
+ if (!(follow=(FOLLOWS*) my_malloc(PSI_NOT_INSTRUMENTED, (states+2)*sizeof(FOLLOWS),MYF(MY_WME))))
{
free_sets(&sets);
my_free(found_set);
@@ -10749,7 +10795,7 @@ REPLACE *init_replace(char * *from, char * *to,uint count,
/* Alloc replace structure for the replace-state-machine */
- if ((replace=(REPLACE*) my_malloc(sizeof(REPLACE)*(sets.count)+
+ if ((replace=(REPLACE*) my_malloc(PSI_NOT_INSTRUMENTED, sizeof(REPLACE)*(sets.count)+
sizeof(REPLACE_STRING)*(found_sets+1)+
sizeof(char *)*count+result_len,
MYF(MY_WME | MY_ZEROFILL))))
@@ -10767,7 +10813,7 @@ REPLACE *init_replace(char * *from, char * *to,uint count,
for (i=1 ; i <= found_sets ; i++)
{
pos=from[found_set[i-1].table_offset];
- rep_str[i].found= !memcmp(pos, "\\^", 3) ? 2 : 1;
+ rep_str[i].found= !strncmp(pos, "\\^", 3) ? 2 : 1;
rep_str[i].replace_string=to_array[found_set[i-1].table_offset];
rep_str[i].to_offset=found_set[i-1].found_offset-start_at_word(pos);
rep_str[i].from_offset=found_set[i-1].found_offset-replace_len(pos)+
@@ -10794,10 +10840,10 @@ int init_sets(REP_SETS *sets,uint states)
{
bzero(sets, sizeof(*sets));
sets->size_of_bits=((states+7)/8);
- if (!(sets->set_buffer=(REP_SET*) my_malloc(sizeof(REP_SET)*SET_MALLOC_HUNC,
+ if (!(sets->set_buffer=(REP_SET*) my_malloc(PSI_NOT_INSTRUMENTED, sizeof(REP_SET)*SET_MALLOC_HUNC,
MYF(MY_WME))))
return 1;
- if (!(sets->bit_buffer=(uint*) my_malloc(sizeof(uint)*sets->size_of_bits*
+ if (!(sets->bit_buffer=(uint*) my_malloc(PSI_NOT_INSTRUMENTED, sizeof(uint)*sets->size_of_bits*
SET_MALLOC_HUNC,MYF(MY_WME))))
{
my_free(sets->set);
@@ -10832,12 +10878,12 @@ REP_SET *make_new_set(REP_SETS *sets)
return set;
}
count=sets->count+sets->invisible+SET_MALLOC_HUNC;
- if (!(set=(REP_SET*) my_realloc(sets->set_buffer, sizeof(REP_SET)*count,
+ if (!(set=(REP_SET*) my_realloc(PSI_NOT_INSTRUMENTED, sets->set_buffer, sizeof(REP_SET)*count,
MYF(MY_WME))))
return 0;
sets->set_buffer=set;
sets->set=set+sets->invisible;
- if (!(bit_buffer=(uint*) my_realloc(sets->bit_buffer,
+ if (!(bit_buffer=(uint*) my_realloc(PSI_NOT_INSTRUMENTED, sets->bit_buffer,
(sizeof(uint)*sets->size_of_bits)*count,
MYF(MY_WME))))
return 0;
@@ -10992,11 +11038,11 @@ int insert_pointer_name(POINTER_ARRAY *pa,char * name)
if (! pa->typelib.count)
{
if (!(pa->typelib.type_names=(const char **)
- my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
+ my_malloc(PSI_NOT_INSTRUMENTED, ((PC_MALLOC-MALLOC_OVERHEAD)/
(sizeof(char *)+sizeof(*pa->flag))*
(sizeof(char *)+sizeof(*pa->flag))),MYF(MY_WME))))
DBUG_RETURN(-1);
- if (!(pa->str= (uchar*) my_malloc(PS_MALLOC - MALLOC_OVERHEAD,
+ if (!(pa->str= (uchar*) my_malloc(PSI_NOT_INSTRUMENTED, PS_MALLOC - MALLOC_OVERHEAD,
MYF(MY_WME))))
{
my_free(pa->typelib.type_names);
@@ -11012,7 +11058,7 @@ int insert_pointer_name(POINTER_ARRAY *pa,char * name)
length=(uint) strlen(name)+1;
if (pa->length+length >= pa->max_length)
{
- if (!(new_pos= (uchar*) my_realloc(pa->str, pa->length + length + PS_MALLOC,
+ if (!(new_pos= (uchar*) my_realloc(PSI_NOT_INSTRUMENTED, pa->str, pa->length + length + PS_MALLOC,
MYF(MY_WME))))
DBUG_RETURN(1);
if (new_pos != pa->str)
@@ -11030,7 +11076,7 @@ int insert_pointer_name(POINTER_ARRAY *pa,char * name)
int len;
pa->array_allocs++;
len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD);
- if (!(new_array=(const char **) my_realloc(pa->typelib.type_names,
+ if (!(new_array=(const char **) my_realloc(PSI_NOT_INSTRUMENTED, pa->typelib.type_names,
len/
(sizeof(uchar*)+sizeof(*pa->flag))*
(sizeof(uchar*)+sizeof(*pa->flag)),
@@ -11156,7 +11202,7 @@ void dynstr_append_sorted(DYNAMIC_STRING* ds, DYNAMIC_STRING *ds_input,
if (!*start)
DBUG_VOID_RETURN; /* No input */
- my_init_dynamic_array(&lines, sizeof(const char*), 32, 32, MYF(0));
+ my_init_dynamic_array(PSI_NOT_INSTRUMENTED, &lines, sizeof(const char*), 32, 32, MYF(0));
if (keep_header)
{
@@ -11221,7 +11267,10 @@ static int setenv(const char *name, const char *value, int overwrite)
that always reads from stdin with explicit echo.
*/
-MYSQL_PLUGIN_EXPORT
+extern "C"
+#ifdef _MSC_VER
+__declspec(dllexport)
+#endif
char *mysql_authentication_dialog_ask(MYSQL *mysql, int type,
const char *prompt,
char *buf, int buf_len)
diff --git a/client/readline.cc b/client/readline.cc
index 12df8b312ad..8d3d97b8585 100644
--- a/client/readline.cc
+++ b/client/readline.cc
@@ -43,7 +43,8 @@ LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file)
#endif
if (!(line_buff=(LINE_BUFFER*)
- my_malloc(sizeof(*line_buff),MYF(MY_WME | MY_ZEROFILL))))
+ my_malloc(PSI_NOT_INSTRUMENTED, sizeof(*line_buff),
+ MYF(MY_WME | MY_ZEROFILL))))
return 0;
if (init_line_buffer(line_buff,my_fileno(file),IO_SIZE,max_size))
{
@@ -93,7 +94,8 @@ LINE_BUFFER *batch_readline_command(LINE_BUFFER *line_buff, char * str)
{
if (!line_buff)
if (!(line_buff=(LINE_BUFFER*)
- my_malloc(sizeof(*line_buff),MYF(MY_WME | MY_ZEROFILL))))
+ my_malloc(PSI_NOT_INSTRUMENTED, sizeof(*line_buff),
+ MYF(MY_WME | MY_ZEROFILL))))
return 0;
if (init_line_buffer_from_string(line_buff,str))
{
@@ -114,8 +116,8 @@ init_line_buffer(LINE_BUFFER *buffer,File file,ulong size,ulong max_buffer)
buffer->file=file;
buffer->bufread=size;
buffer->max_size=max_buffer;
- if (!(buffer->buffer = (char*) my_malloc(buffer->bufread+1,
- MYF(MY_WME | MY_FAE))))
+ if (!(buffer->buffer = (char*) my_malloc(PSI_NOT_INSTRUMENTED,
+ buffer->bufread+1, MYF(MY_WME | MY_FAE))))
return 1;
buffer->end_of_line=buffer->end=buffer->buffer;
buffer->buffer[0]=0; /* For easy start test */
@@ -132,8 +134,8 @@ static bool init_line_buffer_from_string(LINE_BUFFER *buffer,char * str)
uint old_length=(uint)(buffer->end - buffer->buffer);
uint length= (uint) strlen(str);
if (!(buffer->buffer= buffer->start_of_line= buffer->end_of_line=
- (char*) my_realloc((uchar*) buffer->buffer, old_length+length+2,
- MYF(MY_FAE|MY_ALLOW_ZERO_PTR))))
+ (char*) my_realloc(PSI_NOT_INSTRUMENTED, buffer->buffer,
+ old_length+length+2, MYF(MY_FAE|MY_ALLOW_ZERO_PTR))))
return 1;
buffer->end= buffer->buffer + old_length;
if (old_length)
@@ -179,8 +181,8 @@ static size_t fill_buffer(LINE_BUFFER *buffer)
return 0;
}
buffer->bufread *= 2;
- if (!(buffer->buffer = (char*) my_realloc(buffer->buffer,
- buffer->bufread+1,
+ if (!(buffer->buffer = (char*) my_realloc(PSI_NOT_INSTRUMENTED,
+ buffer->buffer, buffer->bufread+1,
MYF(MY_WME | MY_FAE))))
{
buffer->error= my_errno;
diff --git a/client/sql_string.cc.dontuse b/client/sql_string.cc.dontuse
deleted file mode 100644
index 72736ef5511..00000000000
--- a/client/sql_string.cc.dontuse
+++ /dev/null
@@ -1,836 +0,0 @@
-/*
- Copyright (c) 2000, 2013, Oracle and/or its affiliates.
-
- 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 St, Fifth Floor, Boston, MA 02110-1335 USA
-*/
-
-/* This file is originally from the mysql distribution. Coded by monty */
-
-#ifdef USE_PRAGMA_IMPLEMENTATION
-#pragma implementation // gcc: Class implementation
-#endif
-
-#include <my_global.h>
-#include <my_sys.h>
-#include <m_string.h>
-#include <m_ctype.h>
-#include <mysql_com.h>
-
-#include "sql_string.h"
-
-/*****************************************************************************
-** String functions
-*****************************************************************************/
-
-bool String::real_alloc(uint32 length)
-{
- uint32 arg_length= ALIGN_SIZE(length + 1);
- DBUG_ASSERT(arg_length > length);
- if (arg_length <= length)
- return TRUE; /* Overflow */
- str_length=0;
- if (Alloced_length < arg_length)
- {
- free();
- if (!(Ptr=(char*) my_malloc(arg_length,MYF(MY_WME))))
- return TRUE;
- Alloced_length=arg_length;
- alloced=1;
- }
- Ptr[0]=0;
- return FALSE;
-}
-
-
-/*
-** Check that string is big enough. Set string[alloc_length] to 0
-** (for C functions)
-*/
-
-bool String::realloc(uint32 alloc_length)
-{
- uint32 len=ALIGN_SIZE(alloc_length+1);
- DBUG_ASSERT(len > alloc_length);
- if (len <= alloc_length)
- return TRUE; /* Overflow */
- if (Alloced_length < len)
- {
- char *new_ptr;
- if (alloced)
- {
- if (!(new_ptr= (char*) my_realloc(Ptr,len,MYF(MY_WME))))
- return TRUE; // Signal error
- }
- else if ((new_ptr= (char*) my_malloc(len,MYF(MY_WME))))
- {
- if (str_length > len - 1)
- str_length= 0;
- if (str_length) // Avoid bugs in memcpy on AIX
- memcpy(new_ptr,Ptr,str_length);
- new_ptr[str_length]=0;
- alloced=1;
- }
- else
- return TRUE; // Signal error
- Ptr= new_ptr;
- Alloced_length= len;
- }
- Ptr[alloc_length]=0; // This make other funcs shorter
- return FALSE;
-}
-
-bool String::set(longlong num, CHARSET_INFO *cs)
-{
- uint l=20*cs->mbmaxlen+1;
-
- if (alloc(l))
- return TRUE;
- str_length=(uint32) (cs->cset->longlong10_to_str)(cs,Ptr,l,-10,num);
- str_charset=cs;
- return FALSE;
-}
-
-bool String::set(ulonglong num, CHARSET_INFO *cs)
-{
- uint l=20*cs->mbmaxlen+1;
-
- if (alloc(l))
- return TRUE;
- str_length=(uint32) (cs->cset->longlong10_to_str)(cs,Ptr,l,10,num);
- str_charset=cs;
- return FALSE;
-}
-
-bool String::set(double num,uint decimals, CHARSET_INFO *cs)
-{
- char buff[FLOATING_POINT_BUFFER];
- uint dummy_errors;
- size_t len;
-
- str_charset=cs;
- if (decimals >= NOT_FIXED_DEC)
- {
- len= my_gcvt(num, MY_GCVT_ARG_DOUBLE, sizeof(buff) - 1, buff, NULL);
- return copy(buff, len, &my_charset_latin1, cs, &dummy_errors);
- }
- len= my_fcvt(num, decimals, buff, NULL);
- return copy(buff, (uint32) len, &my_charset_latin1, cs,
- &dummy_errors);
-}
-
-
-bool String::copy()
-{
- if (!alloced)
- {
- Alloced_length=0; // Force realloc
- return realloc(str_length);
- }
- return FALSE;
-}
-
-bool String::copy(const String &str)
-{
- if (alloc(str.str_length))
- return TRUE;
- str_length=str.str_length;
- bmove(Ptr,str.Ptr,str_length); // May be overlapping
- Ptr[str_length]=0;
- str_charset=str.str_charset;
- return FALSE;
-}
-
-bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *cs)
-{
- if (alloc(arg_length))
- return TRUE;
- if ((str_length=arg_length))
- memcpy(Ptr,str,arg_length);
- Ptr[arg_length]=0;
- str_charset=cs;
- return FALSE;
-}
-
-
-/*
- Checks that the source string can be just copied to the destination string
- without conversion.
-
- SYNPOSIS
-
- needs_conversion()
- arg_length Length of string to copy.
- from_cs Character set to copy from
- to_cs Character set to copy to
- uint32 *offset Returns number of unaligned characters.
-
- RETURN
- 0 No conversion needed
- 1 Either character set conversion or adding leading zeros
- (e.g. for UCS-2) must be done
-
- NOTE
- to_cs may be NULL for "no conversion" if the system variable
- character_set_results is NULL.
-*/
-
-bool String::needs_conversion(uint32 arg_length,
- CHARSET_INFO *from_cs,
- CHARSET_INFO *to_cs,
- uint32 *offset)
-{
- *offset= 0;
- if (!to_cs ||
- (to_cs == &my_charset_bin) ||
- (to_cs == from_cs) ||
- my_charset_same(from_cs, to_cs) ||
- ((from_cs == &my_charset_bin) &&
- (!(*offset=(arg_length % to_cs->mbminlen)))))
- return FALSE;
- return TRUE;
-}
-
-
-/*
- Copy a multi-byte character sets with adding leading zeros.
-
- SYNOPSIS
-
- copy_aligned()
- str String to copy
- arg_length Length of string. This should NOT be dividable with
- cs->mbminlen.
- offset arg_length % cs->mb_minlength
- cs Character set for 'str'
-
- NOTES
- For real multi-byte, ascii incompatible charactser sets,
- like UCS-2, add leading zeros if we have an incomplete character.
- Thus,
- SELECT _ucs2 0xAA
- will automatically be converted into
- SELECT _ucs2 0x00AA
-
- RETURN
- 0 ok
- 1 error
-*/
-
-bool String::copy_aligned(const char *str,uint32 arg_length, uint32 offset,
- CHARSET_INFO *cs)
-{
- /* How many bytes are in incomplete character */
- offset= cs->mbmaxlen - offset; /* How many zeros we should prepend */
- DBUG_ASSERT(offset && offset != cs->mbmaxlen);
-
- uint32 aligned_length= arg_length + offset;
- if (alloc(aligned_length))
- return TRUE;
-
- /*
- Note, this is only safe for little-endian UCS-2.
- If we add big-endian UCS-2 sometimes, this code
- will be more complicated. But it's OK for now.
- */
- bzero((char*) Ptr, offset);
- memcpy(Ptr + offset, str, arg_length);
- Ptr[aligned_length]=0;
- /* str_length is always >= 0 as arg_length is != 0 */
- str_length= aligned_length;
- str_charset= cs;
- return FALSE;
-}
-
-
-bool String::set_or_copy_aligned(const char *str,uint32 arg_length,
- CHARSET_INFO *cs)
-{
- /* How many bytes are in incomplete character */
- uint32 offset= (arg_length % cs->mbminlen);
-
- if (!offset) /* All characters are complete, just copy */
- {
- set(str, arg_length, cs);
- return FALSE;
- }
- return copy_aligned(str, arg_length, offset, cs);
-}
-
- /* Copy with charset conversion */
-
-bool String::copy(const char *str, uint32 arg_length,
- CHARSET_INFO *from_cs, CHARSET_INFO *to_cs, uint *errors)
-{
- uint32 offset;
- if (!needs_conversion(arg_length, from_cs, to_cs, &offset))
- {
- *errors= 0;
- return copy(str, arg_length, to_cs);
- }
- if ((from_cs == &my_charset_bin) && offset)
- {
- *errors= 0;
- return copy_aligned(str, arg_length, offset, to_cs);
- }
- uint32 new_length= to_cs->mbmaxlen*arg_length;
- if (alloc(new_length))
- return TRUE;
- str_length=copy_and_convert((char*) Ptr, new_length, to_cs,
- str, arg_length, from_cs, errors);
- str_charset=to_cs;
- return FALSE;
-}
-
-
-/*
- Set a string to the value of a latin1-string, keeping the original charset
-
- SYNOPSIS
- copy_or_set()
- str String of a simple charset (latin1)
- arg_length Length of string
-
- IMPLEMENTATION
- If string object is of a simple character set, set it to point to the
- given string.
- If not, make a copy and convert it to the new character set.
-
- RETURN
- 0 ok
- 1 Could not allocate result buffer
-
-*/
-
-bool String::set_ascii(const char *str, uint32 arg_length)
-{
- if (str_charset->mbminlen == 1)
- {
- set(str, arg_length, str_charset);
- return 0;
- }
- uint dummy_errors;
- return copy(str, arg_length, &my_charset_latin1, str_charset, &dummy_errors);
-}
-
-
-/* This is used by mysql.cc */
-
-bool String::fill(uint32 max_length,char fill_char)
-{
- if (str_length > max_length)
- Ptr[str_length=max_length]=0;
- else
- {
- if (realloc(max_length))
- return TRUE;
- bfill(Ptr+str_length,max_length-str_length,fill_char);
- str_length=max_length;
- }
- return FALSE;
-}
-
-void String::strip_sp()
-{
- while (str_length && my_isspace(str_charset,Ptr[str_length-1]))
- str_length--;
-}
-
-bool String::append(const String &s)
-{
- if (s.length())
- {
- if (realloc(str_length+s.length()))
- return TRUE;
- memcpy(Ptr+str_length,s.ptr(),s.length());
- str_length+=s.length();
- }
- return FALSE;
-}
-
-
-/*
- Append an ASCII string to the a string of the current character set
-*/
-
-bool String::append(const char *s,uint32 arg_length)
-{
- if (!arg_length)
- return FALSE;
-
- /*
- For an ASCII incompatible string, e.g. UCS-2, we need to convert
- */
- if (str_charset->mbminlen > 1)
- {
- uint32 add_length=arg_length * str_charset->mbmaxlen;
- uint dummy_errors;
- if (realloc(str_length+ add_length))
- return TRUE;
- str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset,
- s, arg_length, &my_charset_latin1,
- &dummy_errors);
- return FALSE;
- }
-
- /*
- For an ASCII compatinble string we can just append.
- */
- if (realloc(str_length+arg_length))
- return TRUE;
- memcpy(Ptr+str_length,s,arg_length);
- str_length+=arg_length;
- return FALSE;
-}
-
-
-/*
- Append a 0-terminated ASCII string
-*/
-
-bool String::append(const char *s)
-{
- return append(s, (uint) strlen(s));
-}
-
-
-/*
- Append a string in the given charset to the string
- with character set recoding
-*/
-
-bool String::append(const char *s,uint32 arg_length, CHARSET_INFO *cs)
-{
- uint32 dummy_offset;
-
- if (needs_conversion(arg_length, cs, str_charset, &dummy_offset))
- {
- uint32 add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen;
- uint dummy_errors;
- if (realloc(str_length + add_length))
- return TRUE;
- str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset,
- s, arg_length, cs, &dummy_errors);
- }
- else
- {
- if (realloc(str_length + arg_length))
- return TRUE;
- memcpy(Ptr + str_length, s, arg_length);
- str_length+= arg_length;
- }
- return FALSE;
-}
-
-
-#ifdef TO_BE_REMOVED
-bool String::append(FILE* file, uint32 arg_length, myf my_flags)
-{
- if (realloc(str_length+arg_length))
- return TRUE;
- if (my_fread(file, (uchar*) Ptr + str_length, arg_length, my_flags))
- {
- shrink(str_length);
- return TRUE;
- }
- str_length+=arg_length;
- return FALSE;
-}
-#endif
-
-bool String::append(IO_CACHE* file, uint32 arg_length)
-{
- if (realloc(str_length+arg_length))
- return TRUE;
- if (my_b_read(file, (uchar*) Ptr + str_length, arg_length))
- {
- shrink(str_length);
- return TRUE;
- }
- str_length+=arg_length;
- return FALSE;
-}
-
-bool String::append_with_prefill(const char *s,uint32 arg_length,
- uint32 full_length, char fill_char)
-{
- int t_length= arg_length > full_length ? arg_length : full_length;
-
- if (realloc(str_length + t_length))
- return TRUE;
- t_length= full_length - arg_length;
- if (t_length > 0)
- {
- bfill(Ptr+str_length, t_length, fill_char);
- str_length=str_length + t_length;
- }
- append(s, arg_length);
- return FALSE;
-}
-
-uint32 String::numchars()
-{
- return str_charset->cset->numchars(str_charset, Ptr, Ptr+str_length);
-}
-
-int String::charpos(longlong i,uint32 offset)
-{
- if (i <= 0)
- return (int)i;
- return (int)str_charset->cset->charpos(str_charset,Ptr+offset,Ptr+str_length,(size_t)i);
-}
-
-int String::strstr(const String &s,uint32 offset)
-{
- if (s.length()+offset <= str_length)
- {
- if (!s.length())
- return ((int) offset); // Empty string is always found
-
- register const char *str = Ptr+offset;
- register const char *search=s.ptr();
- const char *end=Ptr+str_length-s.length()+1;
- const char *search_end=s.ptr()+s.length();
-skip:
- while (str != end)
- {
- if (*str++ == *search)
- {
- register char *i,*j;
- i=(char*) str; j=(char*) search+1;
- while (j != search_end)
- if (*i++ != *j++) goto skip;
- return (int) (str-Ptr) -1;
- }
- }
- }
- return -1;
-}
-
-/*
-** Search string from end. Offset is offset to the end of string
-*/
-
-int String::strrstr(const String &s,uint32 offset)
-{
- if (s.length() <= offset && offset <= str_length)
- {
- if (!s.length())
- return offset; // Empty string is always found
- register const char *str = Ptr+offset-1;
- register const char *search=s.ptr()+s.length()-1;
-
- const char *end=Ptr+s.length()-2;
- const char *search_end=s.ptr()-1;
-skip:
- while (str != end)
- {
- if (*str-- == *search)
- {
- register char *i,*j;
- i=(char*) str; j=(char*) search-1;
- while (j != search_end)
- if (*i-- != *j--) goto skip;
- return (int) (i-Ptr) +1;
- }
- }
- }
- return -1;
-}
-
-/*
- Replace substring with string
- If wrong parameter or not enough memory, do nothing
-*/
-
-bool String::replace(uint32 offset,uint32 arg_length,const String &to)
-{
- return replace(offset,arg_length,to.ptr(),to.length());
-}
-
-bool String::replace(uint32 offset,uint32 arg_length,
- const char *to, uint32 to_length)
-{
- long diff = (long) to_length-(long) arg_length;
- if (offset+arg_length <= str_length)
- {
- if (diff < 0)
- {
- if (to_length)
- memcpy(Ptr+offset,to,to_length);
- bmove(Ptr+offset+to_length,Ptr+offset+arg_length,
- str_length-offset-arg_length);
- }
- else
- {
- if (diff)
- {
- if (realloc(str_length+(uint32) diff))
- return TRUE;
- bmove_upp((uchar*) Ptr+str_length+diff, (uchar*) Ptr+str_length,
- str_length-offset-arg_length);
- }
- if (to_length)
- memcpy(Ptr+offset,to,to_length);
- }
- str_length+=(uint32) diff;
- }
- return FALSE;
-}
-
-
-// added by Holyfoot for "geometry" needs
-int String::reserve(uint32 space_needed, uint32 grow_by)
-{
- if (Alloced_length < str_length + space_needed)
- {
- if (realloc(Alloced_length + max(space_needed, grow_by) - 1))
- return TRUE;
- }
- return FALSE;
-}
-
-void String::qs_append(const char *str, uint32 len)
-{
- memcpy(Ptr + str_length, str, len + 1);
- str_length += len;
-}
-
-void String::qs_append(double d)
-{
- char *buff = Ptr + str_length;
- str_length+= my_gcvt(d, MY_GCVT_ARG_DOUBLE, FLOATING_POINT_BUFFER - 1, buff,
- NULL);
-}
-
-void String::qs_append(double *d)
-{
- double ld;
- float8get(ld, (char*) d);
- qs_append(ld);
-}
-
-void String::qs_append(int i)
-{
- char *buff= Ptr + str_length;
- char *end= int10_to_str(i, buff, -10);
- str_length+= (int) (end-buff);
-}
-
-void String::qs_append(uint i)
-{
- char *buff= Ptr + str_length;
- char *end= int10_to_str(i, buff, 10);
- str_length+= (int) (end-buff);
-}
-
-/*
- Compare strings according to collation, without end space.
-
- SYNOPSIS
- sortcmp()
- s First string
- t Second string
- cs Collation
-
- NOTE:
- Normally this is case sensitive comparison
-
- RETURN
- < 0 s < t
- 0 s == t
- > 0 s > t
-*/
-
-
-int sortcmp(const String *s,const String *t, CHARSET_INFO *cs)
-{
- return cs->coll->strnncollsp(cs,
- (unsigned char *) s->ptr(),s->length(),
- (unsigned char *) t->ptr(),t->length(), 0);
-}
-
-
-/*
- Compare strings byte by byte. End spaces are also compared.
-
- SYNOPSIS
- stringcmp()
- s First string
- t Second string
-
- NOTE:
- Strings are compared as a stream of unsigned chars
-
- RETURN
- < 0 s < t
- 0 s == t
- > 0 s > t
-*/
-
-
-int stringcmp(const String *s,const String *t)
-{
- uint32 s_len=s->length(),t_len=t->length(),len=min(s_len,t_len);
- int cmp= memcmp(s->ptr(), t->ptr(), len);
- return (cmp) ? cmp : (int) (s_len - t_len);
-}
-
-
-String *copy_if_not_alloced(String *to,String *from,uint32 from_length)
-{
- if (from->Alloced_length >= from_length)
- return from;
- if ((from->alloced && (from->Alloced_length != 0)) || !to || from == to)
- {
- (void) from->realloc(from_length);
- return from;
- }
- if (to->realloc(from_length))
- return from; // Actually an error
- if ((to->str_length=min(from->str_length,from_length)))
- memcpy(to->Ptr,from->Ptr,to->str_length);
- to->str_charset=from->str_charset;
- return to;
-}
-
-
-/****************************************************************************
- Help functions
-****************************************************************************/
-
-/*
- copy a string from one character set to another
-
- SYNOPSIS
- copy_and_convert()
- to Store result here
- to_cs Character set of result string
- from Copy from here
- from_length Length of from string
- from_cs From character set
-
- NOTES
- 'to' must be big enough as form_length * to_cs->mbmaxlen
-
- RETURN
- length of bytes copied to 'to'
-*/
-
-
-uint32
-copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs,
- const char *from, uint32 from_length, CHARSET_INFO *from_cs,
- uint *errors)
-{
- int cnvres;
- my_wc_t wc;
- const uchar *from_end= (const uchar*) from+from_length;
- char *to_start= to;
- uchar *to_end= (uchar*) to+to_length;
- my_charset_conv_mb_wc mb_wc= from_cs->cset->mb_wc;
- my_charset_conv_wc_mb wc_mb= to_cs->cset->wc_mb;
- uint error_count= 0;
-
- while (1)
- {
- if ((cnvres= (*mb_wc)(from_cs, &wc, (uchar*) from,
- from_end)) > 0)
- from+= cnvres;
- else if (cnvres == MY_CS_ILSEQ)
- {
- error_count++;
- from++;
- wc= '?';
- }
- else if (cnvres > MY_CS_TOOSMALL)
- {
- /*
- A correct multibyte sequence detected
- But it doesn't have Unicode mapping.
- */
- error_count++;
- from+= (-cnvres);
- wc= '?';
- }
- else
- break; // Not enough characters
-
-outp:
- if ((cnvres= (*wc_mb)(to_cs, wc, (uchar*) to, to_end)) > 0)
- to+= cnvres;
- else if (cnvres == MY_CS_ILUNI && wc != '?')
- {
- error_count++;
- wc= '?';
- goto outp;
- }
- else
- break;
- }
- *errors= error_count;
- return (uint32) (to - to_start);
-}
-
-
-void String::print(String *str)
-{
- char *st= (char*)Ptr, *end= st+str_length;
- for (; st < end; st++)
- {
- uchar c= *st;
- switch (c)
- {
- case '\\':
- str->append(STRING_WITH_LEN("\\\\"));
- break;
- case '\0':
- str->append(STRING_WITH_LEN("\\0"));
- break;
- case '\'':
- str->append(STRING_WITH_LEN("\\'"));
- break;
- case '\n':
- str->append(STRING_WITH_LEN("\\n"));
- break;
- case '\r':
- str->append(STRING_WITH_LEN("\\r"));
- break;
- case 26: //Ctrl-Z
- str->append(STRING_WITH_LEN("\\z"));
- break;
- default:
- str->append(c);
- }
- }
-}
-
-
-/*
- Exchange state of this object and argument.
-
- SYNOPSIS
- String::swap()
-
- RETURN
- Target string will contain state of this object and vice versa.
-*/
-
-void String::swap(String &s)
-{
- swap_variables(char *, Ptr, s.Ptr);
- swap_variables(uint32, str_length, s.str_length);
- swap_variables(uint32, Alloced_length, s.Alloced_length);
- swap_variables(bool, alloced, s.alloced);
- swap_variables(CHARSET_INFO*, str_charset, s.str_charset);
-}
diff --git a/client/sql_string.h.dontuse b/client/sql_string.h.dontuse
deleted file mode 100644
index e5bf8e0b67c..00000000000
--- a/client/sql_string.h.dontuse
+++ /dev/null
@@ -1,366 +0,0 @@
-#ifndef SQL_STRING_INCLUDED
-#define SQL_STRING_INCLUDED
-
-/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
-
- 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 St, Fifth Floor, Boston, MA 02110-1335 USA */
-
-/* This file is originally from the mysql distribution. Coded by monty */
-
-#ifdef USE_PRAGMA_INTERFACE
-#pragma interface /* gcc class implementation */
-#endif
-
-class String;
-int sortcmp(const String *a,const String *b, CHARSET_INFO *cs);
-String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);
-uint32 copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs,
- const char *from, uint32 from_length,
- CHARSET_INFO *from_cs, uint *errors);
-
-class String
-{
- char *Ptr;
- uint32 str_length,Alloced_length, extra_alloc;
- bool alloced;
- CHARSET_INFO *str_charset;
-public:
- String()
- {
- Ptr=0; str_length=Alloced_length=extra_alloc=0; alloced=0;
- str_charset= &my_charset_bin;
- }
- String(uint32 length_arg)
- {
- alloced=0; Alloced_length=0; (void) real_alloc(length_arg);
- str_charset= &my_charset_bin;
- }
- String(const char *str, CHARSET_INFO *cs)
- {
- Ptr=(char*) str; str_length= (uint32) strlen(str);
- Alloced_length= extra_alloc= 0; alloced=0;
- str_charset=cs;
- }
- String(const char *str,uint32 len, CHARSET_INFO *cs)
- {
- Ptr=(char*) str; str_length=len; Alloced_length= extra_alloc=0; alloced=0;
- str_charset=cs;
- }
- String(char *str,uint32 len, CHARSET_INFO *cs)
- {
- Ptr=(char*) str; Alloced_length=str_length=len; extra_alloc= 0; alloced=0;
- str_charset=cs;
- }
- String(const String &str)
- {
- Ptr=str.Ptr ; str_length=str.str_length ;
- Alloced_length=str.Alloced_length; extra_alloc= 0; alloced=0;
- str_charset=str.str_charset;
- }
- static void *operator new(size_t size, MEM_ROOT *mem_root)
- { return (void*) alloc_root(mem_root, (uint) size); }
- static void operator delete(void *ptr_arg, size_t size)
- {
- (void) ptr_arg;
- (void) size;
- TRASH(ptr_arg, size);
- }
- static void operator delete(void *, MEM_ROOT *)
- { /* never called */ }
- ~String() { free(); }
-
- inline void set_charset(CHARSET_INFO *charset_arg)
- { str_charset= charset_arg; }
- inline CHARSET_INFO *charset() const { return str_charset; }
- inline uint32 length() const { return str_length;}
- inline uint32 alloced_length() const { return Alloced_length;}
- inline char& operator [] (uint32 i) const { return Ptr[i]; }
- inline void length(uint32 len) { str_length=len ; }
- inline bool is_empty() { return (str_length == 0); }
- inline void mark_as_const() { Alloced_length= 0;}
- inline const char *ptr() const { return Ptr; }
- inline char *c_ptr()
- {
- if (!Ptr || Ptr[str_length]) /* Should be safe */
- (void) realloc(str_length);
- return Ptr;
- }
- inline char *c_ptr_quick()
- {
- if (Ptr && str_length < Alloced_length)
- 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)
- {
- DBUG_ASSERT(&str != this);
- free();
- Ptr=(char*) str.ptr()+offset; str_length=arg_length; alloced=0;
- if (str.Alloced_length)
- Alloced_length=str.Alloced_length-offset;
- else
- Alloced_length=0;
- str_charset=str.str_charset;
- }
- inline void set(char *str,uint32 arg_length, CHARSET_INFO *cs)
- {
- free();
- Ptr=(char*) str; str_length=Alloced_length=arg_length ; alloced=0;
- str_charset=cs;
- }
- inline void set(const char *str,uint32 arg_length, CHARSET_INFO *cs)
- {
- free();
- Ptr=(char*) str; str_length=arg_length; Alloced_length=0 ; alloced=0;
- str_charset=cs;
- }
- bool set_ascii(const char *str, uint32 arg_length);
- inline void set_quick(char *str,uint32 arg_length, CHARSET_INFO *cs)
- {
- if (!alloced)
- {
- Ptr=(char*) str; str_length=Alloced_length=arg_length;
- }
- str_charset=cs;
- }
- bool set(longlong num, CHARSET_INFO *cs);
- bool set(ulonglong num, CHARSET_INFO *cs);
- bool set(double num,uint decimals, CHARSET_INFO *cs);
-
- /*
- PMG 2004.11.12
- This is a method that works the same as perl's "chop". It simply
- drops the last character of a string. This is useful in the case
- of the federated storage handler where I'm building a unknown
- number, list of values and fields to be used in a sql insert
- statement to be run on the remote server, and have a comma after each.
- When the list is complete, I "chop" off the trailing comma
-
- ex.
- String stringobj;
- stringobj.append("VALUES ('foo', 'fi', 'fo',");
- stringobj.chop();
- stringobj.append(")");
-
- In this case, the value of string was:
-
- VALUES ('foo', 'fi', 'fo',
- VALUES ('foo', 'fi', 'fo'
- VALUES ('foo', 'fi', 'fo')
-
- */
- inline void chop()
- {
- Ptr[str_length--]= '\0';
- }
-
- inline void free()
- {
- if (alloced)
- {
- alloced=0;
- Alloced_length=0;
- my_free(Ptr);
- Ptr=0;
- str_length=0; /* Safety */
- }
- }
- inline bool alloc(uint32 arg_length)
- {
- if (arg_length < Alloced_length)
- return 0;
- return real_alloc(arg_length);
- }
- bool real_alloc(uint32 arg_length); // Empties old string
- bool realloc(uint32 arg_length);
-
- // Shrink the buffer, but only if it is allocated on the heap.
- inline void shrink(uint32 arg_length)
- {
- if (!is_alloced())
- return;
- if (arg_length < Alloced_length)
- {
- char *new_ptr;
- if (!(new_ptr=(char*) my_realloc(Ptr,arg_length,MYF(0))))
- {
- Alloced_length = 0;
- real_alloc(arg_length);
- }
- else
- {
- Ptr=new_ptr;
- Alloced_length=arg_length;
- }
- }
- }
- bool is_alloced() const { return alloced; }
- inline String& operator = (const String &s)
- {
- if (&s != this)
- {
- /*
- It is forbidden to do assignments like
- some_string = substring_of_that_string
- */
- DBUG_ASSERT(!s.uses_buffer_owned_by(this));
- free();
- Ptr=s.Ptr ; str_length=s.str_length ; Alloced_length=s.Alloced_length;
- str_charset=s.str_charset;
- alloced=0;
- }
- return *this;
- }
-
- bool copy(); // Alloc string if not alloced
- bool copy(const String &s); // Allocate new string
- bool copy(const char *s,uint32 arg_length, CHARSET_INFO *cs); // Allocate new string
- static bool needs_conversion(uint32 arg_length,
- CHARSET_INFO *cs_from, CHARSET_INFO *cs_to,
- uint32 *offset);
- bool copy_aligned(const char *s, uint32 arg_length, uint32 offset,
- CHARSET_INFO *cs);
- bool set_or_copy_aligned(const char *s, uint32 arg_length, CHARSET_INFO *cs);
- bool copy(const char*s,uint32 arg_length, CHARSET_INFO *csfrom,
- CHARSET_INFO *csto, uint *errors);
- bool append(const String &s);
- bool append(const char *s);
- bool append(const char *s,uint32 arg_length);
- bool append(const char *s,uint32 arg_length, CHARSET_INFO *cs);
- bool append(IO_CACHE* file, uint32 arg_length);
- bool append_with_prefill(const char *s, uint32 arg_length,
- uint32 full_length, char fill_char);
- int strstr(const String &search,uint32 offset=0); // Returns offset to substring or -1
- int strrstr(const String &search,uint32 offset=0); // Returns offset to substring or -1
- bool replace(uint32 offset,uint32 arg_length,const char *to,uint32 length);
- bool replace(uint32 offset,uint32 arg_length,const String &to);
- inline bool append(char chr)
- {
- if (str_length < Alloced_length)
- {
- Ptr[str_length++]=chr;
- }
- else
- {
- if (realloc(str_length+1))
- return 1;
- Ptr[str_length++]=chr;
- }
- return 0;
- }
- bool fill(uint32 max_length,char fill);
- void strip_sp();
- friend int sortcmp(const String *a,const String *b, CHARSET_INFO *cs);
- friend int stringcmp(const String *a,const String *b);
- friend String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);
- uint32 numchars();
- int charpos(longlong i,uint32 offset=0);
-
- int reserve(uint32 space_needed)
- {
- return realloc(str_length + space_needed);
- }
- int reserve(uint32 space_needed, uint32 grow_by);
-
- /*
- The following append operations do NOT check alloced memory
- q_*** methods writes values of parameters itself
- qs_*** methods writes string representation of value
- */
- void q_append(const char c)
- {
- Ptr[str_length++] = c;
- }
- void q_append(const uint32 n)
- {
- int4store(Ptr + str_length, n);
- str_length += 4;
- }
- void q_append(double d)
- {
- float8store(Ptr + str_length, d);
- str_length += 8;
- }
- void q_append(double *d)
- {
- float8store(Ptr + str_length, *d);
- str_length += 8;
- }
- void q_append(const char *data, uint32 data_len)
- {
- memcpy(Ptr + str_length, data, data_len);
- str_length += data_len;
- }
-
- void write_at_position(int position, uint32 value)
- {
- int4store(Ptr + position,value);
- }
-
- void qs_append(const char *str, uint32 len);
- void qs_append(double d);
- void qs_append(double *d);
- inline void qs_append(const char c)
- {
- Ptr[str_length]= c;
- str_length++;
- }
- void qs_append(int i);
- void qs_append(uint i);
-
- /* Inline (general) functions used by the protocol functions */
-
- inline char *prep_append(uint32 arg_length, uint32 step_alloc)
- {
- uint32 new_length= arg_length + str_length;
- if (new_length > Alloced_length)
- {
- if (realloc(new_length + step_alloc))
- return 0;
- }
- uint32 old_length= str_length;
- str_length+= arg_length;
- return Ptr+ old_length; /* Area to use */
- }
-
- inline bool append(const char *s, uint32 arg_length, uint32 step_alloc)
- {
- uint32 new_length= arg_length + str_length;
- if (new_length > Alloced_length && realloc(new_length + step_alloc))
- return TRUE;
- memcpy(Ptr+str_length, s, arg_length);
- str_length+= arg_length;
- return FALSE;
- }
- void print(String *print);
-
- /* Swap two string objects. Efficient way to exchange data without memcpy. */
- void swap(String &s);
-
- inline bool uses_buffer_owned_by(const String *s) const
- {
- return (s->alloced && Ptr >= s->Ptr && Ptr < s->Ptr + s->str_length);
- }
-};
-
-#endif /* SQL_STRING_INCLUDED */