package init

This commit is contained in:
hht8 2020-10-23 16:05:26 +08:00
parent 02ed89f089
commit fb6c1bf648
27308 changed files with 3059 additions and 10352652 deletions

9
README.mysql-license Normal file
View File

@ -0,0 +1,9 @@
MySQL is distributed under GPL v2, but there are some licensing exceptions
that allow the client libraries to be linked with a non-GPL application,
so long as the application is under a license approved by Oracle.
For details see
http://www.mysql.com/about/legal/licensing/foss-exception/
Some innobase code from Percona and Google is under BSD license.
Some code related to test-suite is under LGPLv2.

View File

@ -0,0 +1,11 @@
diff -urp boost_1_54_0-orig/boost/locale/boundary/segment.hpp boost_1_54_0/boost/locale/boundary/segment.hpp
--- boost_1_54_0-orig/boost/locale/boundary/segment.hpp 2013-07-23 00:47:27.020787174 +0200
+++ boost_1_54_0/boost/locale/boundary/segment.hpp 2013-07-23 00:50:40.382959016 +0200
@@ -27,7 +27,6 @@ namespace boundary {
int compare_text(LeftIterator l_begin,LeftIterator l_end,RightIterator r_begin,RightIterator r_end)
{
typedef LeftIterator left_iterator;
- typedef RightIterator right_iterator;
typedef typename std::iterator_traits<left_iterator>::value_type char_type;
typedef std::char_traits<char_type> traits;
while(l_begin!=l_end && r_begin!=r_end) {

View File

@ -0,0 +1,31 @@
diff -up boost_1_57_0/boost/mpl/print.hpp\~ boost_1_57_0/boost/mpl/print.hpp
--- boost_1_57_0/boost/mpl/print.hpp~ 2014-07-09 23:12:31.000000000 +0200
+++ boost_1_57_0/boost/mpl/print.hpp 2015-01-20 12:44:59.621400948 +0100
@@ -52,16 +52,15 @@ struct print
enum { n = sizeof(T) + -1 };
#elif defined(__MWERKS__)
void f(int);
-#else
- enum {
- n =
-# if defined(__EDG_VERSION__)
- aux::dependent_unsigned<T>::value > -1
-# else
- sizeof(T) > -1
-# endif
- };
-#endif
+#elif defined(__EDG_VERSION__)
+ enum { n = aux::dependent_unsigned<T>::value > -1 };
+#elif defined(BOOST_GCC)
+ enum { n1 };
+ enum { n2 };
+ enum { n = n1 != n2 };
+#else
+ enum { n = sizeof(T) > -1 };
+#endif
};
#if defined(BOOST_MSVC)
Diff finished. Tue Jan 20 12:45:03 2015

View File

@ -0,0 +1,19 @@
diff -up boost_1_57_0/boost/spirit/home/classic/core/non_terminal/impl/grammar.ipp\~ boost_1_57_0/boost/spirit/home/classic/core/non_terminal/impl/grammar.ipp
--- boost_1_57_0/boost/spirit/home/classic/core/non_terminal/impl/grammar.ipp~ 2014-10-13 12:21:40.000000000 +0200
+++ boost_1_57_0/boost/spirit/home/classic/core/non_terminal/impl/grammar.ipp 2015-01-20 13:25:50.069710766 +0100
@@ -282,12 +282,12 @@ struct grammar_definition
#if !defined(BOOST_SPIRIT_SINGLE_GRAMMAR_INSTANCE)
typedef impl::grammar_helper_base<GrammarT> helper_base_t;
typedef grammar_helper_list<GrammarT> helper_list_t;
- typedef typename helper_list_t::vector_t::reverse_iterator iterator_t;
helper_list_t& helpers =
grammartract_helper_list::do_(self);
# if defined(BOOST_INTEL_CXX_VERSION)
+ typedef typename helper_list_t::vector_t::reverse_iterator iterator_t;
for (iterator_t i = helpers.rbegin(); i != helpers.rend(); ++i)
(*i)->undefine(self);
# else
Diff finished. Tue Jan 20 13:25:53 2015

120
boost-1.58.0-pool.patch Normal file
View File

@ -0,0 +1,120 @@
Index: boost/pool/pool.hpp
===================================================================
--- boost/pool/pool.hpp (revision 78317)
+++ boost/pool/pool.hpp (revision 78326)
@@ -27,4 +27,6 @@
#include <boost/pool/poolfwd.hpp>
+// std::numeric_limits
+#include <boost/limits.hpp>
// boost::integer::static_lcm
#include <boost/integer/common_factor_ct.hpp>
@@ -358,4 +360,11 @@
}
+ size_type max_chunks() const
+ { //! Calculated maximum number of memory chunks that can be allocated in a single call by this Pool.
+ size_type partition_size = alloc_size();
+ size_type POD_size = integer::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type);
+ return (std::numeric_limits<size_type>::max() - POD_size) / alloc_size();
+ }
+
static void * & nextof(void * const ptr)
{ //! \returns Pointer dereferenced.
@@ -377,5 +388,7 @@
//! the first time that object needs to allocate system memory.
//! The default is 32. This parameter may not be 0.
- //! \param nmax_size is the maximum number of chunks to allocate in one block.
+ //! \param nmax_size is the maximum number of chunks to allocate in one block.
+ set_next_size(nnext_size);
+ set_max_size(nmax_size);
}
@@ -400,7 +413,7 @@
}
void set_next_size(const size_type nnext_size)
- { //! Set number of chunks to request from the system the next time that object needs to allocate system memory. This value should never be set to 0.
- //! \returns nnext_size.
- next_size = start_size = nnext_size;
+ { //! Set number of chunks to request from the system the next time that object needs to allocate system memory. This value should never be set to 0.
+ BOOST_USING_STD_MIN();
+ next_size = start_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nnext_size, max_chunks());
}
size_type get_max_size() const
@@ -410,5 +423,6 @@
void set_max_size(const size_type nmax_size)
{ //! Set max_size.
- max_size = nmax_size;
+ BOOST_USING_STD_MIN();
+ max_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nmax_size, max_chunks());
}
size_type get_requested_size() const
@@ -713,7 +727,7 @@
BOOST_USING_STD_MIN();
if(!max_size)
- next_size <<= 1;
+ set_next_size(next_size << 1);
else if( next_size*partition_size/requested_size < max_size)
- next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
+ set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
// initialize it,
@@ -753,7 +767,7 @@
BOOST_USING_STD_MIN();
if(!max_size)
- next_size <<= 1;
+ set_next_size(next_size << 1);
else if( next_size*partition_size/requested_size < max_size)
- next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
+ set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
// initialize it,
@@ -797,4 +811,6 @@
//! \returns Address of chunk n if allocated ok.
//! \returns 0 if not enough memory for n chunks.
+ if (n > max_chunks())
+ return 0;
const size_type partition_size = alloc_size();
@@ -845,7 +861,7 @@
BOOST_USING_STD_MIN();
if(!max_size)
- next_size <<= 1;
+ set_next_size(next_size << 1);
else if( next_size*partition_size/requested_size < max_size)
- next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
+ set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
// insert it into the list,
Index: libs/pool/test/test_bug_6701.cpp
===================================================================
--- libs/pool/test/test_bug_6701.cpp (revision 78326)
+++ libs/pool/test/test_bug_6701.cpp (revision 78326)
@@ -0,0 +1,27 @@
+/* Copyright (C) 2012 Étienne Dupuis
+*
+* Use, modification and distribution is subject to the
+* Boost Software License, Version 1.0. (See accompanying
+* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+*/
+
+// Test of bug #6701 (https://svn.boost.org/trac/boost/ticket/6701)
+
+#include <boost/pool/object_pool.hpp>
+#include <boost/limits.hpp>
+
+int main()
+{
+ boost::pool<> p(1024, std::numeric_limits<size_t>::max() / 768);
+
+ void *x = p.malloc();
+ BOOST_ASSERT(!x);
+
+ BOOST_ASSERT(std::numeric_limits<size_t>::max() / 1024 >= p.get_next_size());
+ BOOST_ASSERT(std::numeric_limits<size_t>::max() / 1024 >= p.get_max_size());
+
+ void *y = p.ordered_malloc(std::numeric_limits<size_t>::max() / 768);
+ BOOST_ASSERT(!y);
+
+ return 0;
+}

View File

@ -0,0 +1,25 @@
From f410fbd64d887e2a8824f968b0533588489b5430 Mon Sep 17 00:00:00 2001
From: Jonathan Wakely <jwakely@redhat.com>
Date: Wed, 2 Sep 2015 13:02:12 +0100
Subject: [PATCH] Python: Fix condition for make_setter overload.
This fixes the regression caused by 42e7d7b.
Fixes #39
---
include/boost/python/data_members.hpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/boost/python/data_members.hpp b/include/boost/python/data_members.hpp
index 139bde3..5d3309c 100644
--- a/include/boost/python/data_members.hpp
+++ b/include/boost/python/data_members.hpp
@@ -305,7 +305,7 @@ inline object make_setter(D& x)
return detail::make_setter(x, default_call_policies(), is_member_pointer<D>(), 0);
}
-# if BOOST_WORKAROUND(__EDG_VERSION__, <= 238)
+# if !BOOST_WORKAROUND(__EDG_VERSION__, <= 238)
template <class D>
inline object make_setter(D const& x)
{

View File

@ -0,0 +1,32 @@
commit 2f3b98e640c25fe45ae691a5aa950745380b983e
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Sep 14 15:05:24 2015 +0100
Do not qualify <fenv.h> names that might be macros.
diff --git a/include/boost/test/impl/execution_monitor.ipp b/include/boost/test/impl/execution_monitor.ipp
index 3a9e779..8b319df 100644
--- a/include/boost/test/impl/execution_monitor.ipp
+++ b/include/boost/test/impl/execution_monitor.ipp
@@ -1380,8 +1380,8 @@ enable( unsigned mask )
return ~old_cw & BOOST_FPE_ALL;
#elif defined(__GLIBC__) && defined(__USE_GNU) && !defined(BOOST_CLANG) && !defined(BOOST_NO_FENV_H)
- ::feclearexcept(BOOST_FPE_ALL);
- int res = ::feenableexcept( mask );
+ feclearexcept(BOOST_FPE_ALL);
+ int res = feenableexcept( mask );
return res == -1 ? (unsigned)BOOST_FPE_INV : (unsigned)res;
#else
/* Not Implemented */
@@ -1417,8 +1417,8 @@ disable( unsigned mask )
return ~old_cw & BOOST_FPE_ALL;
#elif defined(__GLIBC__) && defined(__USE_GNU) && !defined(BOOST_CLANG) && !defined(BOOST_NO_FENV_H)
- ::feclearexcept(BOOST_FPE_ALL);
- int res = ::fedisableexcept( mask );
+ feclearexcept(BOOST_FPE_ALL);
+ int res = fedisableexcept( mask );
return res == -1 ? (unsigned)BOOST_FPE_INV : (unsigned)res;
#else
/* Not Implemented */

106
boost-1.59.0-log.patch Normal file
View File

@ -0,0 +1,106 @@
From 7da193fde1a9c1bc925ee980339f4df2e1a66fa7 Mon Sep 17 00:00:00 2001
From: Andrey Semashev <andrey.semashev@gmail.com>
Date: Sun, 23 Aug 2015 17:27:20 +0300
Subject: [PATCH] Fixed compilation of operator<< into a record ostream, when
the operator right hand argument is not directly supported by
formatting_ostream. Fixed #11549.
---
diff --git a/include/boost/log/sources/record_ostream.hpp b/include/boost/log/sources/record_ostream.hpp
index b3c58e2..c1e8059 100644
--- a/include/boost/log/sources/record_ostream.hpp
+++ b/include/boost/log/sources/record_ostream.hpp
@@ -39,6 +39,18 @@ namespace boost {
BOOST_LOG_OPEN_NAMESPACE
+template< typename CharT >
+class basic_record_ostream;
+
+namespace aux {
+
+template< typename StreamT, typename R >
+struct enable_if_record_ostream {};
+template< typename CharT, typename R >
+struct enable_if_record_ostream< basic_record_ostream< CharT >, R > { typedef R type; };
+
+} // namespace aux
+
/*!
* \brief Logging record adapter with a streaming capability
*
@@ -174,6 +186,55 @@ typedef basic_record_ostream< char > record_ostream; //!< Convenience typ
typedef basic_record_ostream< wchar_t > wrecord_ostream; //!< Convenience typedef for wide-character logging
#endif
+// Implementation note: these operators below should be the least attractive for the compiler
+// so that user's overloads are chosen, when present. We use function template partial ordering for this purpose.
+// We also don't use perfect forwarding for the right hand argument because in ths case the generic overload
+// would be more preferred than the typical one written by users:
+//
+// record_ostream& operator<< (record_ostream& strm, my_type const& arg);
+//
+// This is because my_type rvalues require adding const to the type, which counts as a conversion that is not required
+// if there is a perfect forwarding overload.
+template< typename StreamT, typename T >
+inline typename boost::log::aux::enable_if_record_ostream< StreamT, StreamT& >::type
+operator<< (StreamT& strm, T const& value)
+{
+ typedef basic_formatting_ostream< typename StreamT::char_type > formatting_ostream_type;
+ static_cast< formatting_ostream_type& >(strm) << value;
+ return strm;
+}
+
+template< typename StreamT, typename T >
+inline typename boost::log::aux::enable_if_record_ostream< StreamT, StreamT& >::type
+operator<< (StreamT& strm, T& value)
+{
+ typedef basic_formatting_ostream< typename StreamT::char_type > formatting_ostream_type;
+ static_cast< formatting_ostream_type& >(strm) << value;
+ return strm;
+}
+
+#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
+
+template< typename StreamT, typename T >
+inline typename boost::log::aux::enable_if_record_ostream< StreamT, StreamT& >::type
+operator<< (StreamT&& strm, T const& value)
+{
+ typedef basic_formatting_ostream< typename StreamT::char_type > formatting_ostream_type;
+ static_cast< formatting_ostream_type& >(strm) << value;
+ return strm;
+}
+
+template< typename StreamT, typename T >
+inline typename boost::log::aux::enable_if_record_ostream< StreamT, StreamT& >::type
+operator<< (StreamT&& strm, T& value)
+{
+ typedef basic_formatting_ostream< typename StreamT::char_type > formatting_ostream_type;
+ static_cast< formatting_ostream_type& >(strm) << value;
+ return strm;
+}
+
+#endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
+
namespace aux {
//! Internal class that provides formatting streams for record pumps
diff --git a/include/boost/log/utility/formatting_ostream.hpp b/include/boost/log/utility/formatting_ostream.hpp
index 4345206..744acc0 100644
--- a/include/boost/log/utility/formatting_ostream.hpp
+++ b/include/boost/log/utility/formatting_ostream.hpp
@@ -779,6 +779,13 @@ void basic_formatting_ostream< CharT, TraitsT, AllocatorT >::aligned_write(const
// Implementation note: these operators below should be the least attractive for the compiler
// so that user's overloads are chosen, when present. We use function template partial ordering for this purpose.
+// We also don't use perfect forwarding for the right hand argument because in ths case the generic overload
+// would be more preferred than the typical one written by users:
+//
+// formatting_ostream& operator<< (formatting_ostream& strm, my_type const& arg);
+//
+// This is because my_type rvalues require adding const to the type, which counts as a conversion that is not required
+// if there is a perfect forwarding overload.
template< typename StreamT, typename T >
inline typename boost::log::aux::enable_if_formatting_ostream< StreamT, StreamT& >::type
operator<< (StreamT& strm, T const& value)

18
my.cnf.in Normal file
View File

@ -0,0 +1,18 @@
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# This group is read by the server
#
[mysqld]
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#
# include all files from the config directory
#
!includedir @SYSCONF2DIR@

48
mysql-5.6.10-rpmlintrc Normal file
View File

@ -0,0 +1,48 @@
# Filtered out until upstream fixes them
# Upstream bug: http://bugs.mysql.com/68518
addFilter("incorrect-fsf-address")
# Done to avoid _prefix/lib64/tmpfiles.d
addFilter("E: hardcoded-library-path in %\{_prefix\}/lib/tmpfiles.d")
# Keeping the old summary for now
addFilter("W: name-repeated-in-summary C MySQL")
# Spellchecked
addFilter("W: spelling-error %description -l en_US multi -> mulch, mufti")
addFilter("W: spelling-error %description -l en_US benchmarking -> bench marking, bench-marking, benchmark")
addFilter("W: spelling-error Summary(en_US) embeddable -> embedded")
addFilter("W: spelling-error.*embeddable -> embedded")
# As long as the manual is part of the original tarball, we have do to
# this
addFilter("mysql.src: W: invalid-url Source0: mysql-5.6.[0-9]+-nodocs.tar.gz")
# Leave the logfile where it is for now
addFilter("E: non-root-user-log-file /var/log/mysqld.log mysql")
addFilter("E: non-root-group-log-file /var/log/mysqld.log mysql")
addFilter("E: non-ghost-file /var/log/mysqld.log")
addFilter("E: zero-length /var/log/mysqld.log")
addFilter("E: incoherent-logrotate-file /etc/logrotate.d/mysqld")
# Hidden files and zero lenght files is normal for some tests
addFilter("W: hidden-file-or-dir /usr/share/mysql-test/std_data/.mylogin.cnf")
addFilter("E: zero-length /usr/share/mysql-test/suite/parts/t/disabled.def")
addFilter("E: zero-length /usr/share/mysql-test/std_data/bug37631.MYD")
addFilter("E: zero-length /usr/share/mysql-test/std_data/cluster_7022_table.MYD")
addFilter("E: zero-length /usr/share/mysql-test/collections/disabled-weekly.list")
addFilter("E: zero-length /usr/share/mysql-test/collections/disabled-daily.list")
# debuginfo bug?
addFilter("E: non-standard-dir-perm /usr/src/debug/tmp 01777")
# mysql-config *script* in lib
addFilter("W: only-non-binary-in-usr-lib")
# missing
addFilter("W: no-manual-page-for-binary my_safe_process")
# cluster is gone
addFilter("W: obsolete-not-provided mysql-cluster")

View File

@ -1,45 +0,0 @@
This directory used to contain lots of build scripts for building
MySQL on various platforms. They are mostly gone, use cmake instead.
Some scripts have been kept for backward compatibility (other scripts
depend on them). Others have been kept to illustrate how to enable
gcov or gprof, or explicitly selecting 64bit architecture. If you
want to use these scripts for building, you may want to speed things
up a bit by setting environment variable MAKEFLAGS="-j8"
(or some other number/flag depending on your environment)
The recommended way to build MySQL for developers:
cd <some build directory>
cmake <path to source directory>
make
This will give you a release build, with compiler options taken from
../cmake/build_configurations/compiler_options.cmake
and "feature set" taken from
../cmake/build_configurations/feature_set.cmake
Adding -DWITH_DEBUG=1 to the cmake command line gives you a debug build.
Building on Windows is slightly different:
cd <some build directory>
cmake <path to source directory>
cmake --build . --config Debug
or
cmake --build . --config RelWithDebInfo
If you have special needs, you can disable the defaults by setting
these cmake variables off:
WITH_DEFAULT_COMPILER_OPTIONS
WITH_DEFAULT_FEATURE_SET
Note: For building with unit tests, you need to tell cmake where to find
the sources, see ../unittest/gunit/CMakeLists.txt
You should *not* 'make install' googletest/googlemock on your system,
the libraries must be built from source, with the unit tests.
Note: You need to tell cmake where to find boost, see ../cmake/boost.cmake

View File

@ -1,254 +0,0 @@
#!/bin/sh
# Copyright (c) 2000, 2014, 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 Library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA
########################################################################
get_key_value()
{
echo "$1" | sed 's/^--[a-zA-Z_-]*=//'
}
usage()
{
cat <<EOF
Usage: $0 [-h|-n] [configure-options]
-h, --help Show this help message.
-n, --just-print Don't actually run any commands; just print them.
-c, --just-configure Stop after running configure.
--with-debug=full Build with full debug(no optimizations, keep call stack).
--warning-mode=[old|pedantic|maintainer]
Influences the debug flags. Old is default.
--prefix=path Build with prefix 'path'.
Note: this script is intended for internal use by MySQL developers.
EOF
}
parse_options()
{
while test $# -gt 0
do
case "$1" in
--prefix=*)
prefix=`get_key_value "$1"`;;
--with-debug=full)
full_debug="=full";;
--warning-mode=*)
warning_mode=`get_key_value "$1"`;;
-c | --just-configure)
just_configure=1;;
-n | --just-print | --print)
just_print=1;;
-h | --help)
usage
exit 0;;
*)
echo "Unknown option '$1'"
exit 1;;
esac
shift
done
}
########################################################################
if test ! -f sql/mysqld.cc
then
echo "You must run this script from the MySQL top-level directory"
exit 1
fi
prefix="/usr/local/mysql"
just_print=
just_configure=
warning_mode=
maintainer_mode=
full_debug=
parse_options "$@"
if test -n "$MYSQL_BUILD_PREFIX"
then
prefix="$MYSQL_BUILD_PREFIX"
fi
set -e
#
# Check for the CPU and set up CPU specific flags. We may reset them
# later.
#
path=`dirname $0`
. "$path/check-cpu"
export AM_MAKEFLAGS
AM_MAKEFLAGS="-j 6"
# SSL library to use.--with-ssl will select our bundled yaSSL
# implementation of SSL. To use openSSl you will nee too point out
# the location of openSSL headers and lbs on your system.
# Ex --with-ssl=/usr
SSL_LIBRARY=--with-ssl
if [ "x$warning_mode" = "xpedantic" ]; then
warnings="-W -Wall -ansi -pedantic -Wno-long-long -Wno-unused -D_POSIX_SOURCE"
c_warnings="$warnings"
cxx_warnings="$warnings -std=c++98"
# NOTE: warning mode should not influence optimize/debug mode.
# Please feel free to add a separate option if you don't feel it's an overkill.
debug_extra_cflags="-O0"
# Reset CPU flags (-mtune), they don't work in -pedantic mode
check_cpu_cflags=""
elif [ "x$warning_mode" = "xmaintainer" ]; then
c_warnings="-Wall -Wextra"
cxx_warnings="$c_warnings -Wno-unused-parameter"
maintainer_mode="--enable-mysql-maintainer-mode"
debug_extra_cflags="-g3"
else
# Both C and C++ warnings
warnings="-Wall -Wextra -Wunused -Wwrite-strings"
# For more warnings, uncomment the following line
# warnings="$warnings -Wshadow"
# C warnings
c_warnings="$warnings"
# C++ warnings
cxx_warnings="$warnings -Wno-unused-parameter"
# cxx_warnings="$cxx_warnings -Woverloaded-virtual -Wsign-promo"
cxx_warnings="$cxx_warnings -Wnon-virtual-dtor"
debug_extra_cflags="-O0 -g3 -gdwarf-2"
fi
# Set flags for various build configurations.
# Used in -valgrind builds
valgrind_flags="-DMYSQL_SERVER_SUFFIX=-valgrind-max"
valgrind_configs="--with-valgrind"
#
# Used in -debug builds
debug_cflags="-DEXTRA_DEBUG "
debug_cflags="$debug_cflags -DSAFE_MUTEX"
error_inject="--with-error-inject "
#
# Base C++ flags for all builds
base_cxxflags="-felide-constructors"
#
# Flags for optimizing builds.
# Be as fast as we can be without losing our ability to backtrace.
fast_cflags="-O3 -fno-omit-frame-pointer"
debug_configs="--with-debug"
if [ -z "$full_debug" ]
then
debug_cflags="$debug_cflags $debug_extra_cflags"
fi
#
# Configuration options.
#
base_configs="--prefix=$prefix --enable-assembler "
base_configs="$base_configs --with-extra-charsets=complex "
base_configs="$base_configs --enable-thread-safe-client "
base_configs="$base_configs --with-big-tables $maintainer_mode"
if test -d "$path/../cmd-line-utils/libedit"
then
base_configs="$base_configs --with-libedit"
fi
static_link="--with-mysqld-ldflags=-all-static "
static_link="$static_link --with-client-ldflags=-all-static"
# we need local-infile in all binaries for rpl000001
# if you need to disable local-infile in the client, write a build script
# and unset local_infile_configs
local_infile_configs="--enable-local-infile"
max_no_embedded_configs="$SSL_LIBRARY --with-plugins=max"
max_no_ndb_configs="$SSL_LIBRARY --with-plugins=max-no-ndb --with-embedded-server"
max_configs="$SSL_LIBRARY --with-plugins=max --with-embedded-server"
#
# CPU and platform specific compilation flags.
#
alpha_cflags="$check_cpu_cflags -Wa,-m$cpu_flag"
amd64_cflags="$check_cpu_cflags"
amd64_cxxflags="" # If dropping '--with-big-tables', add here "-DBIG_TABLES"
pentium_cflags="$check_cpu_cflags"
pentium64_cflags="$check_cpu_cflags -m64"
ppc_cflags="$check_cpu_cflags"
sparc_cflags=""
if gmake --version > /dev/null 2>&1
then
make=gmake
else
make=make
fi
if test -z "$CC" ; then
CC=gcc
fi
if test -z "$CXX" ; then
CXX=g++
fi
# If ccache (a compiler cache which reduces build time)
# (http://samba.org/ccache) is installed, use it.
# We use 'grep' and hope 'grep' will work as expected
# (returns 0 if finds lines)
if test "$USING_GCOV" != "1"
then
# Not using gcov; Safe to use ccache
CCACHE_GCOV_VERSION_ENABLED=1
fi
if ccache -V > /dev/null 2>&1 && test "$CCACHE_GCOV_VERSION_ENABLED" = "1"
then
echo "$CC" | grep "ccache" > /dev/null || CC="ccache $CC"
echo "$CXX" | grep "ccache" > /dev/null || CXX="ccache $CXX"
fi
# gcov
# The -fprofile-arcs and -ftest-coverage options cause GCC to instrument the
# code with profiling information used by gcov.
# The -DDISABLE_TAO_ASM is needed to avoid build failures in Yassl.
# The -DHAVE_gcov enables code to write out coverage info even when crashing.
gcov_compile_flags="-fprofile-arcs -ftest-coverage"
gcov_compile_flags="$gcov_compile_flags -DDISABLE_TAO_ASM"
gcov_compile_flags="$gcov_compile_flags -DMYSQL_SERVER_SUFFIX=-gcov -DHAVE_gcov"
# GCC4 needs -fprofile-arcs -ftest-coverage on the linker command line (as well
# as on the compiler command line), and this requires setting LDFLAGS for BDB.
gcov_link_flags="-fprofile-arcs -ftest-coverage"
gcov_configs="--with-gcov"
# gprof
gprof_compile_flags="-O2 -pg -g"
gprof_link_flags="--disable-shared $static_link"

View File

@ -1,27 +0,0 @@
#!/bin/sh
# Copyright (c) 2005, 2010, 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 Library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA
# Create MySQL cmake configure wrapper
die() { echo "$@"; exit 1; }
# Use a configure script that will call CMake.
path=`dirname $0`
cp $path/cmake_configure.sh $path/../configure
chmod +x $path/../configure

View File

@ -1,35 +0,0 @@
#!/bin/sh
# Copyright (c) 2009, 2010, 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 Library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA
# Ensure cmake and perl are there
cmake -P cmake/check_minimal_version.cmake >/dev/null 2>&1 || HAVE_CMAKE=no
perl --version >/dev/null 2>&1 || HAVE_PERL=no
scriptdir=`dirname $0`
if test "$HAVE_CMAKE" = "no"
then
echo "CMake is required to build MySQL."
exit 1
elif test "$HAVE_PERL" = "no"
then
echo "Perl is required to build MySQL using the configure to CMake translator."
exit 1
else
perl $scriptdir/cmake/configure.pl "$@"
fi

View File

@ -1,31 +0,0 @@
#!/bin/sh
# Copyright (c) 2004, 2012, 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-1301 USA
#
# This script's purpose is to prepare for a subsequent 'make dist';
# We don't actually have to compile anything,
# as the 'dist' target in our .cmake files is self-contained
# i.e. it generates source dependencies.
#
path=`dirname $0`
. $path/autorun.sh
# By default we get the "community" feature set from
# cmake/build_configurations/feature_set.cmake
#
./configure

View File

@ -1,20 +0,0 @@
#! /bin/sh
# Copyright (c) 2000, 2012, 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 Street, Fifth Floor, Boston, MA 02110-1301, USA
path=`dirname $0`
cmake $path/.. -DWITH_DEBUG=0
make

View File

@ -1,20 +0,0 @@
#! /bin/sh
# Copyright (c) 2000, 2012, 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-1301 USA
path=`dirname $0`
cmake $path/.. -DWITH_DEBUG=1
make

View File

@ -1,20 +0,0 @@
#! /bin/sh
# Copyright (c) 2001, 2012, 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-1301 USA
path=`dirname $0`
cmake $path/.. -DWITH_DEBUG=1
make

View File

@ -1,20 +0,0 @@
#! /bin/sh
# Copyright (c) 2001, 2012, 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 Street, Fifth Floor, Boston, MA 02110-1301, USA
path=`dirname $0`
cmake $path/.. -DWITH_DEBUG=1 -DWITH_NDBCLUSTER=0 $@
make

View File

@ -1,20 +0,0 @@
#! /bin/sh
# Copyright (c) 2000, 2012, 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 Street, Fifth Floor, Boston, MA 02110-1301, USA
path=`dirname $0`
cmake $path/.. -DWITH_DEBUG=1 -DENABLE_GCOV=ON
make

View File

@ -1,20 +0,0 @@
#! /bin/sh
# Copyright (c) 2000, 2012, 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 Street, Fifth Floor, Boston, MA 02110-1301, USA
path=`dirname $0`
cmake $path/.. -DWITH_DEBUG=0 -DENABLE_GPROF=ON
make

View File

@ -1,22 +0,0 @@
#! /bin/sh
# Copyright (c) 2002, 2014, 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-1301 USA
# WITH_VALGRIND : include valgrind/memcheck.h;valgrind/valgrind.h
path=`dirname $0`
cmake $path/.. -DWITH_DEBUG=1 -DWITH_VALGRIND=1
make

View File

@ -1,23 +0,0 @@
#! /bin/sh
# Copyright (c) 2008, 2014, 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 Library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA
path=`dirname $0`
cmake $path/.. -DWITH_DEBUG=1 -DWITH_VALGRIND=1 \
-DWITH_NDBCLUSTER=0
make

View File

@ -1,22 +0,0 @@
#! /bin/sh
# Copyright (c) 2002, 2012, 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 Library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA
path=`dirname $0`
cmake $path/.. -DCMAKE_CXX_FLAGS=-m64 -DCMAKE_C_FLAGS=-m64
make

View File

@ -1,836 +0,0 @@
# Copyright (c) 2006, 2019, 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-1301 USA
IF(WIN32)
# CMake 2.8.12 is needed for Visual Studio 2013
# CMake 3.1.0 is needed for $<TARGET_PDB_FILE:${target}>
CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)
ELSE()
# There's a bug in unzipping prior to 2.8.2
# Debian 7 has the oldest cmake we need to support
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)
ENDIF()
# We use CMAKE_SHARED_LIBRARY_<Lang>_FLAGS. See cmake --help-policy CMP0018
IF(CMAKE_VERSION VERSION_GREATER "2.8.8")
CMAKE_POLICY(SET CMP0018 OLD)
ENDIF()
# We use PROPERTIES LINK_INTERFACE_LIBRARIES. See cmake --help-policy CMP0022
IF(CMAKE_VERSION VERSION_EQUAL "2.8.12" OR
CMAKE_VERSION VERSION_GREATER "2.8.12")
CMAKE_POLICY(SET CMP0022 OLD)
ENDIF()
# We use get_target_property() for non-existent targets (CMP0045)
# and INSTALL_NAME_DIR (CMP0042)
IF(CMAKE_VERSION VERSION_EQUAL "3.0.0" OR
CMAKE_VERSION VERSION_GREATER "3.0.0")
CMAKE_POLICY(SET CMP0045 OLD)
CMAKE_POLICY(SET CMP0042 OLD)
ENDIF()
MESSAGE(STATUS "Running cmake version ${CMAKE_VERSION}")
# Will set GIT_EXECUTABLE and GIT_FOUND
FIND_PACKAGE(Git)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
# First, decide about build type (debug or release)
# If cmake is invoked with -DCMAKE_BUILD_TYPE,
# respect user wishes and do not (re)define CMAKE_BUILD_TYPE. If WITH_DEBUG
# is given, set CMAKE_BUILD_TYPE = Debug. Otherwise, use Relwithdebinfo.
IF(DEFINED CMAKE_BUILD_TYPE)
SET(HAVE_CMAKE_BUILD_TYPE TRUE)
ENDIF()
OPTION(WITH_DEBUG "Use dbug/safemutex" OFF)
# Distinguish between community and non-community builds, with the
# default being a community build. This does not impact the feature
# set that will be compiled in; it's merely provided as a hint to
# custom packaging steps.
OPTION(COMMUNITY_BUILD "Set to true if this is a community build" ON)
# Use a default manufacturer if no manufacturer was identified.
SET(MANUFACTURER_DOCSTRING
"Set the entity that appears as the manufacturer of packages that support a manufacturer field.")
IF(NOT DEFINED MANUFACTURER)
SET(MANUFACTURER "Built from Source" CACHE STRING ${MANUFACTURER_DOCSTRING})
MARK_AS_ADVANCED(MANUFACTURER)
ENDIF()
# MAX_INDEXES - Set the maximum number of indexes per table, default 64U
IF (NOT MAX_INDEXES)
SET(MAX_INDEXES 64U)
ENDIF(NOT MAX_INDEXES)
IF (${MAX_INDEXES} GREATER 255)
MESSAGE(FATAL_ERROR "MAX_INDEXES values greater than 255 is not supported!")
ENDIF()
MESSAGE(STATUS "Configuring with MAX_INDEXES = ${MAX_INDEXES}")
# We choose to provide WITH_DEBUG as alias to standard CMAKE_BUILD_TYPE=Debug
# which turns out to be not trivial, as this involves synchronization
# between CMAKE_BUILD_TYPE and WITH_DEBUG. Besides, we have to deal with cases
# where WITH_DEBUG is reset from ON to OFF and here we need to reset
# CMAKE_BUILD_TYPE to either none or default RelWithDebInfo
SET(BUILDTYPE_DOCSTRING
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or
CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel")
IF(WITH_DEBUG)
SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING ${BUILDTYPE_DOCSTRING} FORCE)
IF(UNIX AND NOT APPLE)
# Compiling with PIC speeds up embedded build, on PIC sensitive systems
# Predefine it to ON, in case user chooses to build embedded.
SET(WITH_PIC ON CACHE BOOL "Compile with PIC")
ENDIF()
SET(OLD_WITH_DEBUG 1 CACHE INTERNAL "" FORCE)
ELSEIF(NOT HAVE_CMAKE_BUILD_TYPE OR OLD_WITH_DEBUG)
IF(CMAKE_BUILD_TYPE MATCHES "Debug" OR NOT HAVE_CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
${BUILDTYPE_DOCSTRING} FORCE)
ENDIF()
SET(OLD_WITH_DEBUG 0 CACHE INTERNAL "" FORCE)
ENDIF()
# Optionally set project name, e.g.
# foo.xcodeproj (mac) or foo.sln (windows)
SET(MYSQL_PROJECT_NAME_DOCSTRING "MySQL project name")
IF(DEFINED MYSQL_PROJECT_NAME)
SET(MYSQL_PROJECT_NAME ${MYSQL_PROJECT_NAME} CACHE STRING
${MYSQL_PROJECT_NAME_DOCSTRING} FORCE)
ELSE()
SET(MYSQL_PROJECT_NAME "MySQL" CACHE STRING
${MYSQL_PROJECT_NAME_DOCSTRING} FORCE)
MARK_AS_ADVANCED(MYSQL_PROJECT_NAME)
ENDIF()
PROJECT(${MYSQL_PROJECT_NAME})
# STRING(APPEND ...) from cmake VERSION 3.4
MACRO(STRING_APPEND STRING_VAR INPUT)
SET(${STRING_VAR} "${${STRING_VAR}}${INPUT}")
ENDMACRO()
MACRO(STRING_PREPEND STRING_VAR INPUT)
SET(${STRING_VAR} "${INPUT}${${STRING_VAR}}")
ENDMACRO()
SET(BUILD_IS_SINGLE_CONFIG TRUE)
MESSAGE(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
IF(CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR STREQUAL "Xcode")
SET(BUILD_IS_SINGLE_CONFIG FALSE)
ENDIF()
# Maintainer mode is default on only for debug builds using GCC/G++
IF(CMAKE_BUILD_TYPE MATCHES "Debug" OR WITH_DEBUG)
IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX)
SET(MYSQL_MAINTAINER_MODE ON CACHE BOOL
"MySQL maintainer-specific development environment")
ENDIF()
ENDIF()
OPTION(WITH_DEFAULT_COMPILER_OPTIONS
"Use flags from cmake/build_configurations/compiler_options.cmake"
ON)
OPTION(WITH_DEFAULT_FEATURE_SET
"Use feature set in cmake/build_configurations/feature_set.cmake"
ON)
IF(BUILD_CONFIG)
INCLUDE(
${CMAKE_SOURCE_DIR}/cmake/build_configurations/${BUILD_CONFIG}.cmake)
ENDIF()
#cmake on 64bit windows/mac/solaris doesn't set CMAKE_SYSTEM_PROCESSOR correctly
SET(MYSQL_MACHINE_TYPE ${CMAKE_SYSTEM_PROCESSOR})
# Include the platform-specific file. To allow exceptions, this code
# looks for files in order of how specific they are. If there is, for
# example, a generic Linux.cmake and a version-specific
# Linux-2.6.28-11-generic, it will pick Linux-2.6.28-11-generic and
# include it. It is then up to the file writer to include the generic
# version if necessary.
FOREACH(_base
${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_VERSION}-${CMAKE_SYSTEM_PROCESSOR}
${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_VERSION}
${CMAKE_SYSTEM_NAME})
SET(_file ${CMAKE_SOURCE_DIR}/cmake/os/${_base}.cmake)
IF(EXISTS ${_file})
INCLUDE(${_file})
BREAK()
ENDIF()
ENDFOREACH()
IF(UNIX)
OPTION(WITH_INNODB_MEMCACHED "" OFF)
OPTION(ENABLE_MEMCACHED_SASL "Enable SASL on InnoDB Memcached" OFF)
OPTION(ENABLE_MEMCACHED_SASL_PWDB "Enable SASL on InnoDB Memcached" OFF)
ELSE()
OPTION(WITH_INNODB_MEMCACHED "" OFF)
ENDIF()
# Following autotools tradition, add preprocessor definitions
# specified in environment variable CPPFLAGS
IF(DEFINED ENV{CPPFLAGS})
ADD_DEFINITIONS($ENV{CPPFLAGS})
ENDIF()
INCLUDE(CheckTypeSize)
CHECK_TYPE_SIZE("void *" SIZEOF_VOIDP)
MESSAGE(STATUS "SIZEOF_VOIDP ${SIZEOF_VOIDP}")
# On some platforms, cmake may think that CMAKE_SIZEOF_VOID_P == 4
# even if we have configured for 64bit build....
SET(CMAKE_SIZEOF_VOID_P ${SIZEOF_VOIDP})
IF(WITH_DEFAULT_COMPILER_OPTIONS)
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/build_configurations/compiler_options.cmake)
ENDIF()
IF(WITH_DEFAULT_FEATURE_SET)
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/build_configurations/feature_set.cmake)
ENDIF()
# Add macros
INCLUDE(character_sets)
INCLUDE(cpu_info)
INCLUDE(zlib)
INCLUDE(lz4)
INCLUDE(libevent)
INCLUDE(ssl)
INCLUDE(sasl)
INCLUDE(rpc)
INCLUDE(readline)
INCLUDE(protobuf)
INCLUDE(mysql_version)
INCLUDE(libutils)
INCLUDE(dtrace)
INCLUDE(plugin)
INCLUDE(install_macros)
INCLUDE(install_layout)
INCLUDE(mysql_add_executable)
INCLUDE(curl)
# Handle options
IF(EXISTS ${CMAKE_SOURCE_DIR}/rapid)
OPTION(WITH_RAPID
"Build additonal code(plugins) that is located in rapid directory" ON)
ELSE()
OPTION(WITH_RAPID
"Build additonal code(plugins) that is located in rapid directory" OFF)
ENDIF()
OPTION(DISABLE_SHARED
"Don't build shared libraries, compile code as position-dependent" OFF)
IF(DISABLE_SHARED)
SET(WITHOUT_DYNAMIC_PLUGINS 1)
ENDIF()
OPTION(ENABLED_PROFILING "Enable profiling" ON)
OPTION(WITHOUT_SERVER OFF)
IF(UNIX)
OPTION(WITH_VALGRIND "Valgrind instrumentation" OFF)
ENDIF()
IF(WIN32)
OPTION(WITH_MSCRT_DEBUG "MS Visual Studio Debug CRT instrumentation" OFF)
ENDIF()
IF(NOT WITHOUT_SERVER)
OPTION (WITH_UNIT_TESTS "Compile MySQL with unit tests" ON)
ENDIF()
OPTION(FORCE_UNSUPPORTED_COMPILER "Disable compiler version checks" OFF)
MARK_AS_ADVANCED(WITHOUT_SERVER DISABLE_SHARED FORCE_UNSUPPORTED_COMPILER)
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
# We need some extra FAIL_REGEX patterns
# Note that CHECK_C_SOURCE_COMPILES is a misnomer, it will also link.
MACRO (MY_CHECK_C_COMPILER_FLAG FLAG RESULT)
SET(SAVE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${FLAG}")
CHECK_C_SOURCE_COMPILES("int main(void) { return 0; }" ${RESULT}
FAIL_REGEX "argument unused during compilation"
FAIL_REGEX "unsupported .*option"
FAIL_REGEX "unknown .*option"
FAIL_REGEX "unrecognized .*option"
FAIL_REGEX "ignoring unknown option"
FAIL_REGEX "[Ww]arning: [Oo]ption"
FAIL_REGEX "error: visibility"
FAIL_REGEX "warning: visibility"
)
SET(CMAKE_REQUIRED_FLAGS "${SAVE_CMAKE_REQUIRED_FLAGS}")
ENDMACRO()
MACRO (MY_CHECK_CXX_COMPILER_FLAG FLAG RESULT)
SET(SAVE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${FLAG}")
CHECK_CXX_SOURCE_COMPILES("int main(void) { return 0; }" ${RESULT}
FAIL_REGEX "argument unused during compilation"
FAIL_REGEX "unsupported .*option"
FAIL_REGEX "unknown .*option"
FAIL_REGEX "unrecognized .*option"
FAIL_REGEX "ignoring unknown option"
FAIL_REGEX "[Ww]arning: [Oo]ption"
FAIL_REGEX "error: visibility"
FAIL_REGEX "warning: visibility"
)
SET(CMAKE_REQUIRED_FLAGS "${SAVE_CMAKE_REQUIRED_FLAGS}")
ENDMACRO()
MACRO(MY_SANITIZER_CHECK SAN_OPT RESULT)
MY_CHECK_C_COMPILER_FLAG("${SAN_OPT}" C_RESULT)
MY_CHECK_CXX_COMPILER_FLAG("${SAN_OPT}" CXX_RESULT)
IF(C_RESULT AND CXX_RESULT)
# We switch on basic optimization also for debug builds.
# With optimization we may get some warnings, so we switch off -Werror
SET(CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} ${SAN_OPT} -O1 -Wno-error -fPIC")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO
"${CMAKE_C_FLAGS_RELWITHDEBINFO} ${SAN_OPT} -fPIC")
SET(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} ${SAN_OPT} -O1 -Wno-error -fPIC")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SAN_OPT} -fPIC")
SET(${RESULT} 1)
ELSE()
SET(${RESULT} 0)
ENDIF()
ENDMACRO()
OPTION(WITH_ASAN "Enable address sanitizer" OFF)
OPTION(WITH_ASAN_SCOPE "Enable -fsanitize-address-use-after-scope" OFF)
IF(WITH_ASAN)
MY_SANITIZER_CHECK("-fsanitize=address" WITH_ASAN_OK)
IF(WITH_ASAN_OK)
SET(HAVE_ASAN 1)
# This works with clang, but not gcc it seems.
MY_CHECK_CXX_COMPILER_FLAG(
"-fsanitize=address -fsanitize-address-use-after-scope"
HAVE_SANITIZE_SCOPE)
IF(WITH_ASAN_SCOPE AND HAVE_SANITIZE_SCOPE)
SET(CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} -fsanitize-address-use-after-scope")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO
"${CMAKE_C_FLAGS_RELWITHDEBINFO} -fsanitize-address-use-after-scope")
SET(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize-address-use-after-scope")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fsanitize-address-use-after-scope")
ENDIF()
ELSE()
MESSAGE(FATAL_ERROR "Do not know how to enable address sanitizer")
ENDIF()
ENDIF()
OPTION(WITH_MSAN "Enable memory sanitizer" OFF)
IF(WITH_MSAN)
MY_SANITIZER_CHECK("-fsanitize=memory -fsanitize-memory-track-origins"
WITH_MSAN_OK)
IF(NOT WITH_MSAN_OK)
MESSAGE(FATAL_ERROR "Do not know how to enable memory sanitizer")
ENDIF()
ENDIF()
OPTION(WITH_UBSAN "Enable undefined behavior sanitizer" OFF)
IF(WITH_UBSAN)
MY_SANITIZER_CHECK("-fsanitize=undefined" WITH_UBSAN_OK)
IF(NOT WITH_UBSAN_OK)
MESSAGE(FATAL_ERROR
"Do not know how to enable undefined behavior sanitizer")
ELSE()
MESSAGE(WARNING
"Note that Undefined Behavior support is currently experimental.")
ENDIF()
ENDIF()
IF(WITH_ASAN AND WITH_MSAN)
MESSAGE(FATAL_ERROR
"Cannot use AddressSanitizer and MemorySanitizer together")
ENDIF()
# Always enable debug sync for debug builds.
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DENABLED_DEBUG_SYNC")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DENABLED_DEBUG_SYNC")
# Older versions of ccache must be disabled: export CCACHE_DISABLE=1
# See http://www.cmake.org/Wiki/CTest/Coverage
OPTION(ENABLE_GCOV "Enable gcov (debug, Linux builds only)" OFF)
IF (ENABLE_GCOV AND NOT WIN32 AND NOT APPLE)
SET(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -DHAVE_GCOV")
SET(CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -DHAVE_GCOV")
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -lgcov")
ENDIF()
OPTION(ENABLE_GPROF "Enable gprof (optimized, Linux builds only)" OFF)
IF (ENABLE_GPROF AND NOT WIN32 AND NOT APPLE)
SET(CMAKE_C_FLAGS_RELWITHDEBINFO
"${CMAKE_C_FLAGS_RELWITHDEBINFO} -pg")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -pg")
SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
"${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} -pg")
ENDIF()
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
OPTION(REPRODUCIBLE_BUILD "Take extra pains to make build result independent of build location and time" OFF)
ENDIF()
IF(REPRODUCIBLE_BUILD)
SET(DEBUG_PREFIX_FLAGS
"-fdebug-prefix-map=${CMAKE_SOURCE_DIR}/=./ -fdebug-prefix-map=${CMAKE_CURRENT_BINARY_DIR}=./obj")
# See if -fdebug-prefix= commands are included in the debug output,
# making the build unreproducible with switches recorded.
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69821.
EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -g3 -x c -S -fdebug-prefix-map=foo=bar -o - -
INPUT_FILE /dev/null OUTPUT_VARIABLE DEBUG_PREFIX_MAP_RESULT)
IF(DEBUG_PREFIX_MAP_RESULT MATCHES "foo=bar")
SET(DEBUG_PREFIX_FLAGS "${DEBUG_PREFIX_FLAGS} -gno-record-gcc-switches")
ENDIF()
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_PREFIX_FLAGS}")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO
"${CMAKE_C_FLAGS_RELWITHDEBINFO} ${DEBUG_PREFIX_FLAGS}")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_PREFIX_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${DEBUG_PREFIX_FLAGS}")
SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--build-id=none")
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--build-id=none")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE
"${CMAKE_SOURCE_DIR}/scripts/invoke-with-relative-paths.pl")
ENDIF()
OPTION(ENABLED_LOCAL_INFILE
"If we should enable LOAD DATA LOCAL by default" ${IF_WIN})
MARK_AS_ADVANCED(ENABLED_LOCAL_INFILE)
OPTION(OPTIMIZER_TRACE "Support tracing of Optimizer" ON)
#
# Options related to client-side protocol tracing
#
OPTION(WITH_CLIENT_PROTOCOL_TRACING
"Support for client-side protocol tracing plugins" ON)
OPTION(WITH_TEST_TRACE_PLUGIN
"Have a built-in test protocol trace plugin in libmysql (requires WITH_CLIENT_PROTOCOL_TRACING option)" OFF)
# Sanity checks for protocol tracing options
IF(WITH_TEST_TRACE_PLUGIN AND NOT WITH_CLIENT_PROTOCOL_TRACING)
MESSAGE("WARNING: Test trace plugin was selected but client protocol tracing infrastructure is not enabled - ignoring")
SET(WITH_TEST_TRACE_PLUGIN 0)
ENDIF()
IF(WITH_TEST_TRACE_PLUGIN AND NOT CMAKE_BUILD_TYPE MATCHES "Debug")
MESSAGE(SEND_ERROR
"Test trace plugin was selected but it can be included only in debug binaries.
Set WITH_TEST_TRACE_PLUGIN to OFF or WITH_DEBUG to ON.")
ENDIF()
# Set DBUG_OFF and other optional release-only flags for non-debug project types
FOREACH(BUILD_TYPE RELEASE RELWITHDEBINFO MINSIZEREL)
FOREACH(LANG C CXX)
SET(CMAKE_${LANG}_FLAGS_${BUILD_TYPE}
"${CMAKE_${LANG}_FLAGS_${BUILD_TYPE}} -DDBUG_OFF")
ENDFOREACH()
ENDFOREACH()
IF(NOT CMAKE_BUILD_TYPE
AND NOT CMAKE_GENERATOR MATCHES "Visual Studio"
AND NOT CMAKE_GENERATOR MATCHES "Xcode")
# This is the case of no CMAKE_BUILD_TYPE choosen, typical for VS and Xcode
# or if custom C flags are set. In VS and Xcode for non-Debug configurations
# DBUG_OFF is already correctly set.
ADD_DEFINITIONS(-DDBUG_OFF)
ENDIF()
# Add safemutex for debug configurations
IF(NOT WITH_INNODB_MEMCACHED)
FOREACH(LANG C CXX)
SET(CMAKE_${LANG}_FLAGS_DEBUG
"${CMAKE_${LANG}_FLAGS_DEBUG} -DSAFE_MUTEX")
ENDFOREACH()
ENDIF()
# Set commonly used variables
IF(WIN32)
SET(DEFAULT_MYSQL_HOME "C:/Program Files/MySQL/MySQL Server ${MYSQL_BASE_VERSION}" )
SET(SHAREDIR share)
ELSE()
SET(DEFAULT_MYSQL_HOME ${CMAKE_INSTALL_PREFIX})
SET(SHAREDIR ${DEFAULT_MYSQL_HOME}/${INSTALL_MYSQLSHAREDIR})
ENDIF()
SET(DEFAULT_BASEDIR "${DEFAULT_MYSQL_HOME}")
IF(INSTALL_MYSQLDATADIR MATCHES "^/.*")
SET(MYSQL_DATADIR ${INSTALL_MYSQLDATADIR} CACHE PATH "default MySQL data directory")
ELSE()
SET(MYSQL_DATADIR "${DEFAULT_MYSQL_HOME}/${INSTALL_MYSQLDATADIR}" CACHE PATH "default MySQL data directory")
ENDIF()
IF(INSTALL_MYSQLKEYRINGDIR MATCHES "^/.*")
SET(MYSQL_KEYRINGDIR ${INSTALL_MYSQLKEYRINGDIR} CACHE PATH "default MySQL keyring directory")
ELSE()
SET(MYSQL_KEYRINGDIR "${DEFAULT_MYSQL_HOME}/${INSTALL_MYSQLKEYRINGDIR}" CACHE PATH "default MySQL keyring directory")
ENDIF()
SET(DEFAULT_CHARSET_HOME "${DEFAULT_MYSQL_HOME}")
SET(PLUGINDIR "${DEFAULT_MYSQL_HOME}/${INSTALL_PLUGINDIR}")
IF(SYSCONFDIR)
SET(DEFAULT_SYSCONFDIR "${SYSCONFDIR}")
ENDIF()
IF(WIN32) # P_tmpdir is not defined on Windows as of VS2015.
SET(TMPDIR "" # So we use empty path as default. In practice TMP/TEMP is used
CACHE PATH
"PATH to MySQL TMP dir")
ELSE()
SET(TMPDIR "P_tmpdir"
CACHE PATH
"PATH to MySQL TMP dir. Defaults to the P_tmpdir macro in <stdio.h>")
ENDIF()
IF(TMPDIR STREQUAL "P_tmpdir")
# Do not quote it, to refer to the P_tmpdir macro.
SET(DEFAULT_TMPDIR "P_tmpdir")
ELSE()
# Quote it, to make it a const char string.
SET(DEFAULT_TMPDIR "\"${TMPDIR}\"")
ENDIF()
INCLUDE(cmake/boost.cmake)
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
OPTION(WITH_SYSTEMD "Enable installation of systemd support files" OFF)
IF (WITH_SYSTEMD)
INCLUDE(cmake/systemd.cmake)
ENDIF()
ELSE()
IF (WITH_SYSTEMD)
MESSAGE(FATAL_ERROR "Installation of systemd support files not supported")
ENDIF()
ENDIF()
# Run platform tests
INCLUDE(configure.cmake)
# Common defines and includes
ADD_DEFINITIONS(-DHAVE_CONFIG_H)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_SOURCE_DIR}/extra/rapidjson/include
${CMAKE_CURRENT_BINARY_DIR}/libbinlogevents/include
${CMAKE_SOURCE_DIR}/libbinlogevents/export)
# Add bundled or system zlib.
MYSQL_CHECK_ZLIB_WITH_COMPRESS()
IF(BUILD_BUNDLED_ZLIB)
INCLUDE_DIRECTORIES(SYSTEM
${CMAKE_CURRENT_SOURCE_DIR}/zlib
${CMAKE_CURRENT_BINARY_DIR}/zlib
)
ENDIF()
# Add bundled yassl/taocrypt or system openssl.
MYSQL_CHECK_SSL()
# Add system/bundled editline.
MYSQL_CHECK_EDITLINE()
# Add libevent
MYSQL_CHECK_LIBEVENT()
# Add lz4 library
MYSQL_CHECK_LZ4()
# Add SASL library
MYSQL_CHECK_SASL()
# Add protoc and libprotobuf
IF(NOT WITHOUT_SERVER)
MYSQL_CHECK_PROTOBUF()
ENDIF()
# Try and set CURL_LIBRARY
MYSQL_CHECK_CURL()
# Check for SYS_thread_selfid system call
CHECK_C_SOURCE_COMPILES("
#include <sys/types.h>
#include <sys/syscall.h>
#include <unistd.h>
int main(int ac, char **av)
{
unsigned long long tid = syscall(SYS_thread_selfid);
return (tid != 0 ? 0 : 1);
}"
HAVE_SYS_THREAD_SELFID)
# Check for gettid() system call
CHECK_C_SOURCE_COMPILES("
#include <sys/types.h>
#include <sys/syscall.h>
#include <unistd.h>
int main(int ac, char **av)
{
unsigned long long tid = syscall(SYS_gettid);
return (tid != 0 ? 0 : 1);
}"
HAVE_SYS_GETTID)
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
# Check for pthread_setname_np
CHECK_C_SOURCE_COMPILES("
#include <pthread.h>
int main(int ac, char **av)
{
const char *thread_name= 0;
int ret = pthread_setname_np(pthread_self(), thread_name);
return ret;
}"
HAVE_PTHREAD_SETNAME_NP)
ENDIF()
# Check for pthread_getthreadid_np()
CHECK_C_SOURCE_COMPILES("
#include <pthread_np.h>
int main(int ac, char **av)
{
unsigned long long tid = pthread_getthreadid_np();
return (tid != 0 ? 0 : 1);
}"
HAVE_PTHREAD_GETTHREADID_NP)
# Check for pthread_self() returning an integer type
CHECK_C_SOURCE_COMPILES("
#include <sys/types.h>
#include <pthread.h>
int main(int ac, char **av)
{
unsigned long long tid = pthread_self();
return (tid != 0 ? 0 : 1);
}"
HAVE_INTEGER_PTHREAD_SELF
FAIL_REGEX "warning: incompatible pointer to integer conversion"
)
#
# Setup maintainer mode options by the end. Platform checks are
# not run with the warning options as to not perturb fragile checks
# (i.e. do not make warnings into errors).
#
# Why don't these flags affect the entire build?
# Because things may already have been included with ADD_SUBDIRECTORY
#
OPTION(MYSQL_MAINTAINER_MODE
"MySQL maintainer-specific development environment" OFF)
INCLUDE(maintainer)
IF(WITH_UNIT_TESTS)
ENABLE_TESTING()
ENDIF()
ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(dbug)
ADD_SUBDIRECTORY(strings)
ADD_SUBDIRECTORY(vio)
ADD_SUBDIRECTORY(regex)
ADD_SUBDIRECTORY(mysys)
ADD_SUBDIRECTORY(mysys_ssl)
ADD_SUBDIRECTORY(libmysql)
ADD_SUBDIRECTORY(libbinlogevents)
ADD_SUBDIRECTORY(libbinlogstandalone)
# gcc9 will not allow CTORs to do memset(this, 0, sizeof(*this));
IF(CMAKE_COMPILER_IS_GNUCXX AND NOT GXX_VERSION VERSION_LESS 9)
STRING_APPEND(CMAKE_CXX_FLAGS_DEBUG " -Wno-class-memaccess")
STRING_APPEND(CMAKE_CXX_FLAGS_RELWITHDEBINFO " -Wno-class-memaccess")
ENDIF()
IF(NOT WITHOUT_SERVER)
SET (MYSQLD_STATIC_PLUGIN_LIBS "" CACHE INTERNAL "")
SET (MYSQLD_STATIC_EMBEDDED_PLUGIN_LIBS "" CACHE INTERNAL "")
# Add storage engines and plugins.
CONFIGURE_PLUGINS()
ELSE()
# We may still want Cluster client libraries, use -DWITH_NDBCLUSTER=1
ADD_SUBDIRECTORY(storage/ndb)
ENDIF()
IF(WITH_UNIT_TESTS)
# Visual Studio 11 needs this extra flag in order to compile gmock.
IF(WIN32)
ADD_DEFINITIONS( /D _VARIADIC_MAX=10 )
ENDIF()
# libc++ doesn't have tuple in tr1
IF(HAVE_LLVM_LIBCPP)
ADD_DEFINITIONS(-DGTEST_USE_OWN_TR1_TUPLE=1)
ENDIF()
ADD_SUBDIRECTORY(unittest)
ADD_SUBDIRECTORY(unittest/examples)
ADD_SUBDIRECTORY(unittest/mytap)
ADD_SUBDIRECTORY(unittest/mytap/t)
IF(WITH_RAPID AND EXISTS ${CMAKE_SOURCE_DIR}/rapid/unittest/gunit)
ADD_SUBDIRECTORY(rapid/unittest/gunit)
ENDIF()
ENDIF()
ADD_SUBDIRECTORY(extra)
ADD_SUBDIRECTORY(client)
ADD_SUBDIRECTORY(sql/share)
ADD_SUBDIRECTORY(libservices)
IF(UNIX)
ADD_SUBDIRECTORY(man)
ENDIF()
IF(NOT WITHOUT_SERVER)
ADD_SUBDIRECTORY(testclients)
ADD_SUBDIRECTORY(sql)
OPTION (WITH_EMBEDDED_SERVER "Compile MySQL with embedded server" OFF)
IF(WITH_EMBEDDED_SERVER)
ADD_SUBDIRECTORY(libmysqld)
ADD_SUBDIRECTORY(libmysqld/examples)
ENDIF(WITH_EMBEDDED_SERVER)
ENDIF()
# scripts/mysql_config depends on client and server targets loaded above.
# It is referenced by some of the directories below, so we insert it here.
ADD_SUBDIRECTORY(scripts)
IF(NOT WITHOUT_SERVER)
ADD_SUBDIRECTORY(mysql-test)
ADD_SUBDIRECTORY(mysql-test/lib/My/SafeProcess)
ADD_SUBDIRECTORY(support-files)
IF(EXISTS ${CMAKE_SOURCE_DIR}/internal/CMakeLists.txt)
ADD_SUBDIRECTORY(internal)
ENDIF()
ADD_SUBDIRECTORY(packaging/rpm-common)
ADD_SUBDIRECTORY(packaging/rpm-oel)
ADD_SUBDIRECTORY(packaging/rpm-fedora)
ADD_SUBDIRECTORY(packaging/rpm-sles)
ADD_SUBDIRECTORY(packaging/rpm-docker)
ADD_SUBDIRECTORY(packaging/deb-in)
ENDIF()
INCLUDE(cmake/abi_check.cmake)
INCLUDE(cmake/tags.cmake)
CONFIGURE_FILE(config.h.cmake ${CMAKE_BINARY_DIR}/include/my_config.h)
CONFIGURE_FILE(config.h.cmake ${CMAKE_BINARY_DIR}/include/config.h)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/include/mysql_version.h.in
${CMAKE_BINARY_DIR}/include/mysql_version.h )
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc.in
${CMAKE_BINARY_DIR}/sql/sql_builtin.cc)
CONFIGURE_FILE(
${CMAKE_SOURCE_DIR}/cmake/info_macros.cmake.in
${CMAKE_BINARY_DIR}/info_macros.cmake @ONLY)
SET(KNOWN_CONVENIENCE_LIBRARIES "" CACHE INTERNAL "")
# Handle the "INFO_*" files.
INCLUDE(${CMAKE_BINARY_DIR}/info_macros.cmake)
# Source: This can be done during the cmake phase, all information is
# available, but should be repeated on each "make" just in case someone
# does "cmake ; make ; git pull ; make".
CREATE_INFO_SRC(${CMAKE_BINARY_DIR}/Docs)
ADD_CUSTOM_TARGET(INFO_SRC ALL
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/info_src.cmake
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Build flags: This must be postponed to the make phase.
ADD_CUSTOM_TARGET(INFO_BIN ALL
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/info_bin.cmake
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Packaging
IF(WIN32)
SET(CPACK_GENERATOR "ZIP")
ELSE()
SET(CPACK_GENERATOR "TGZ")
ENDIF()
ADD_SUBDIRECTORY(packaging/WiX)
ADD_SUBDIRECTORY(packaging/solaris)
IF(UNIX)
INSTALL(FILES Docs/mysql.info DESTINATION ${INSTALL_INFODIR} OPTIONAL COMPONENT Info)
ENDIF()
#
# RPM installs documentation directly from the source tree
#
IF(NOT INSTALL_LAYOUT MATCHES "RPM")
INSTALL(FILES COPYING LICENSE.mysql
DESTINATION ${INSTALL_DOCREADMEDIR}
COMPONENT Readme
OPTIONAL
)
INSTALL(FILES README DESTINATION ${INSTALL_DOCREADMEDIR} COMPONENT Readme)
INSTALL(FILES ${CMAKE_BINARY_DIR}/Docs/INFO_SRC ${CMAKE_BINARY_DIR}/Docs/INFO_BIN DESTINATION ${INSTALL_DOCDIR})
# MYSQL_DOCS_LOCATON is used in "make dist", points to the documentation directory
SET(MYSQL_DOCS_LOCATION "" CACHE PATH "Location from where documentation is copied")
MARK_AS_ADVANCED(MYSQL_DOCS_LOCATION)
INSTALL(DIRECTORY Docs/ DESTINATION ${INSTALL_DOCDIR}
COMPONENT Documentation
PATTERN "Makefile.*" EXCLUDE
PATTERN "glibc*" EXCLUDE
PATTERN "linuxthreads.txt" EXCLUDE
PATTERN "myisam.txt" EXCLUDE
PATTERN "mysql.info" EXCLUDE
PATTERN "sp-imp-spec.txt" EXCLUDE
)
ENDIF()
INCLUDE(CPack)
# C compiler flags consist of:
# CPPFLAGS Taken from environment, see above.
# ADD_DEFINITIONS In each individual CMakeLists.txt
# CMAKE_C_FLAGS From command line.
# We extend these in maintainer.cmake
# ENV{CFLAGS} From environment, but environment is ignored if
# CMAKE_C_FLAGS is also given on command line
# CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}
# We extend these in compiler_options.cmake
#
# Note that CMakeCache.txt contains cmake builtins for these variables,
# *not* the values that will actually be used:
IF(BUILD_IS_SINGLE_CONFIG)
MESSAGE(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
ENDIF()
GET_PROPERTY(cwd_definitions DIRECTORY PROPERTY COMPILE_DEFINITIONS)
MESSAGE(STATUS "COMPILE_DEFINITIONS: ${cwd_definitions}")
MESSAGE(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
MESSAGE(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
MESSAGE(STATUS "CMAKE_C_LINK_FLAGS: ${CMAKE_C_LINK_FLAGS}")
MESSAGE(STATUS "CMAKE_CXX_LINK_FLAGS: ${CMAKE_CXX_LINK_FLAGS}")
IF(CMAKE_BUILD_TYPE AND BUILD_IS_SINGLE_CONFIG)
STRING(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKEBT)
MESSAGE(STATUS "CMAKE_C_FLAGS_${CMAKEBT}: ${CMAKE_C_FLAGS_${CMAKEBT}}")
MESSAGE(STATUS "CMAKE_CXX_FLAGS_${CMAKEBT}: ${CMAKE_CXX_FLAGS_${CMAKEBT}}")
ENDIF()
IF(NOT BUILD_IS_SINGLE_CONFIG)
MESSAGE(STATUS "CMAKE_C_FLAGS_DEBUG: ${CMAKE_C_FLAGS_DEBUG}")
MESSAGE(STATUS "CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
MESSAGE(STATUS
"CMAKE_C_FLAGS_RELWITHDEBINFO: ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
MESSAGE(STATUS
"CMAKE_CXX_FLAGS_RELWITHDEBINFO: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
ENDIF()

View File

@ -1,339 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

View File

@ -1,2 +0,0 @@
You can find a detailed list of changes at
to https://github.com/mysql/mysql-server/commits/5.7

View File

@ -1,7 +0,0 @@
commit: 8ccfc51ab8d361be94168fe04b6818d0b234c9c0
date: 2019-06-10 20:06:14 +0530
build-date: 2019-06-10 16:43:41 +0200
short: 8ccfc51
branch: mysql-5.7.27-release
MySQL source 5.7.27

View File

@ -1,901 +0,0 @@
#.# mi_changed()
int mi_is_changed(MI_INFO *mip)
#.#.1 Description
Reports whether any changes have occurred to the MyISAM table associated with mip.
For information only, I notice that mi_changed() is a wrapper around this: (_mi_readinfo(info,F_RDLCK,1)).
#.#.2 Return values
Zero if the table has not changed. Non-zero (-1) if the table has changed.
#.#.3 Errors
Nothing specific yet identified.
#.#.4 Examples
if( mi_changed( mip )) printf( "file has changed" );
====================
#.# mi_close()
int mi_close( MI_INFO *mip )
#.#.1 Description
Closes the MyISAM table associated with mip, a structure created by mi_open().
Any locks on that file pointer are released.
The MI_INFO structure mip is released.
See also mi_panic() which can be used to close all open MyISAM files.
mip is a pointer to the MI_INFO returned by mi_open().
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
Nothing specific yet identified.
#.#.4 Examples
result = mi_close(mip);
====================
#.# mi_create()
int mi_create( const char *name, uint keys, MI_KEYDEF *keydefs,
uint columns, MI_COLUMNDEF *recinfo,
uint uniques, MI_UNIQUEDEF *uniquedefs,
MI_CREATE_INFO *ci, uint flags )
#.#.1 Description
Creates a new MyISAM table.
Documentation for this function is not complete because I am not using mi_create directly.
Because all our tables are used with MySQL, I create new tables using SQL "CREATE TABLE" via the C API.
See MySQL Appendix B "Choosing a table type".
MyISAM allows about 32 indexes. However the official MySQL limit is 16 until MySQL 4.0.
The parameters are specified as follows:
name The file pathname, excluding the suffixes.
keys Number of indexes.
keydefs A MI_KEYDEF structure containing key definitions.
HA_KEYTYPE_END=0
HA_KEYTYPE_TEXT=1, /* Key is sorted as letters */
HA_KEYTYPE_BINARY=2, /* Key is sorted as unsigned chars
HA_KEYTYPE_SHORT_INT=3,
HA_KEYTYPE_LONG_INT=4,
HA_KEYTYPE_FLOAT=5,
HA_KEYTYPE_DOUBLE=6,
HA_KEYTYPE_NUM=7, /* Not packed num with pre-space *
HA_KEYTYPE_USHORT_INT=8,
HA_KEYTYPE_ULONG_INT=9,
HA_KEYTYPE_LONGLONG=10,
HA_KEYTYPE_ULONGLONG=11,
HA_KEYTYPE_INT24=12,
HA_KEYTYPE_UINT24=13,
HA_KEYTYPE_INT8=14,
HA_KEYTYPE_VARTEXT=15, /* Key is sorted as letters */
HA_KEYTYPE_VARBINARY=16 /* Key is sorted as unsigned chars
columns The number of columns.
recinfo A MI_COLUMNDEF structure containing column definitions.
uniques The number of unique indexes.
uniquedefs A MI_UNIQUEDEF structure containing unique index definitions.
ci A MI_CREATE_INFO structure containing column definitions.
flags a pointer to the record buffer that will contain the row.
#.#.2 Return values
Zero if the create is successful. Non-zero if an error occurs.
#.#.3 Errors
HA_WRONG_CREATE_OPTION
means that some of the arguments was wrong.
appart from the above one can get any unix error that one can get from open(), write() or close().
#.#.4 Examples
if (mi_create(fn_format(name,filename,"",MI_NAME_IEXT, 4+ (opt_follow_links ? 16 : 0)),
share.base.keys - share.state.header.uniques, keyinfo, share.base.fields, recdef,
share.state.header.uniques, uniquedef, &create_info, HA_DONT_TOUCH_DATA))
====================
#.# mi_delete()
int mi_delete(MI_INFO *mip, const byte *buf)
#.#.1 Description
Removes a row from a MyISAM table.
mip is an MI_INFO pointer to the open handle.
buf is the buffer containing the row that is to be deleted.
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
EACCES
File was opened read-only.
HA_ERR_KEY_NOT_FOUND
No database read
HA_ERR_RECORD_CHANGED
The buffer contents were different to the actual row contents.
HA_ERR_CRASHED
The indexing has crashed.
#.#.4 Examples
if (mi_delete(file,read_record))
====================
#.# mi_delete_all()
int mi_delete_all_rows(MI_INFO *mip)
#.#.1 Description
Removes ALL rows from a MyISAM table.
This only clears the status information. The files are not truncated.
mip is an MI_INFO pointer to the open handle.
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
EACCES
File was opened read-only.
#.#.4 Examples
error = mi_delete_all( mip );
====================
#.# mi_extra()
int mi_extra(MI_INFO *info, enum ha_extra_function function)
#.#.1 Description
Controls some special MyISAM modes.
The function parameter can be:
HA_EXTRA_NORMAL=0 Optimize for space (def)
HA_EXTRA_QUICK=1 Optimize for speed
HA_EXTRA_RESET=2 Reset database to after open
HA_EXTRA_CACHE=3 Cash record in HA_rrnd()
HA_EXTRA_NO_CACHE=4 End cacheing of records (def)
HA_EXTRA_NO_READCHECK=5 No readcheck on update
HA_EXTRA_READCHECK=6 Use readcheck (def)
HA_EXTRA_KEYREAD=7 Read only key to database
HA_EXTRA_NO_KEYREAD=8 Normal read of records (def)
HA_EXTRA_NO_USER_CHANGE=9 No user is allowed to write
HA_EXTRA_KEY_CACHE=10
HA_EXTRA_NO_KEY_CACHE=11
HA_EXTRA_WAIT_LOCK=12 Wait until file is avalably (def)
HA_EXTRA_NO_WAIT_LOCK=13 If file is locked, return quickly
HA_EXTRA_WRITE_CACHE=14 Use write cache in ha_write()
HA_EXTRA_FLUSH_CACHE=15 flush write_record_cache
HA_EXTRA_NO_KEYS=16 Remove all update of keys
HA_EXTRA_KEYREAD_CHANGE_POS=17 Keyread, but change pos
xxxxchk -r must be used
HA_EXTRA_REMEMBER_POS=18 Remember pos for next/prev
HA_EXTRA_RESTORE_POS=19
HA_EXTRA_REINIT_CACHE=20 init cache from current record
HA_EXTRA_FORCE_REOPEN=21 Datafile have changed on disk
HA_EXTRA_FLUSH Flush tables to disk
HA_EXTRA_NO_ROWS Don't write rows
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
Nothing specific yet identified.
#.#.4 Examples
====================
#.# mi_make_application_key()
void mi_make_application_key(register MI_INFO *mip, uint keynr, uchar *key, const byte *record)
#.#.1 Description
Construct a key string for the given index, from the provided record buffer.
Monty wrote this function to: "to create an external key for an application from your record. It should work for all keys except BLOB and true VARCHAR (not supported by MySQL yet), but I don't think you have either of these!" He just wrote it, so I expect it to included in releases from about 3.23.15. ??
The parameters are:
A MI_INFO pointer mip.
The index number keynr.
The buffer to contain the formatted key string key.
The record buffer record.
#.#.2 Return values
The byte length of the created key string.
#.#.3 Errors
Nothing specific yet identified.
#.#.4 Examples
uint new_length=_mi_make_application_key(info,i,new_key,newrec);
====================
#.# mi_open()
MI_INFO *mi_open( const char *name, int mode, uint handle_locking )
#.#.1 Description
Opens a MyISAM file for processing.
mi_open() returns a MI_INFO structure pointer that you must use in subsequent operations on the MyISAM file. MI_INFO structures are defined in "myisam/myisamdef.h", which is included in your program via your include myisam.h - used by both MyISAM and MySQL.
The name parameter must contain a null-terminated string without an extension, which is the filename of the MyISAM file to be processed.
There is no automatic positioning nor key selection.
Caution! It is extremely important to close MyISAM files after processing has finished, especially on operating systems without file-locking system calls. Failure to close MyISAM files using mi_close() or mi_panic() leaves the files locked on systems without these system calls.
name Is the name of the file.
mode Is the access mode parameter. Use one of the following access mode parameters:
O_RDONLY to open for input only.
O_RDWR opens the file for output.
O_SHARE opens the file for both input and output. When used, O_SHARE should be added to O_RDONLY and O_RDWR.
handle_locking is the locking mode parameter. Select from the following:
HA_OPEN_ABORT_IF_LOCKED (0) exit with error if database is locked
HA_OPEN_WAIT_IF_LOCKED (1) wait if database is locked
HA_OPEN_IGNORE_IF_LOCKED (2) continue, but count-vars in st_i_info may be wrong. count-vars are automatically fixed after next isam request.
#.#.2 Return values
A pointer to MI_INFO for successfully open file. NULL if unsuccessful, when my_errno will contain the error code.
#.#.3 Errors
HA_ERR_OLD_FILE
wrong options
HA_ERR_CRASHED
wrong header
HA_ERR_UNSUPPORTED
too many keys or keys too long
HA_ERR_END_OF_FILE
empty file?
MY_FILE_ERROR
?
EACCES
cannot open in write mode
ENOMEM
not enough memory
Otherwise one has probably got a fatal error like HA_ERR_CRASHED or some I-O related error from the Operating System.
#.#.4 Examples
pfm = mi_open("/D1/adir/perform",O_SHARE | O_RDONLY, HA_OPEN_ABORT_IF_LOCKED);
====================
#.# mi_panic()
int mi_panic( enum ha_panic_function flag )
#.#.1 Description
mi_panic() is used to close any MyISAM files before exiting, or to safeguard file updates when using a shell.
The flag parameter specifies the function and can be:
HA_PANIC_CLOSE Close all databases (MyISAM files).
HA_PANIC_WRITE Unlock and write status, flushing all buffers to disk.
HA_PANIC_READ Lock and read key info per HA_PANIC_WRITE.
The CLOSE function also writes buffers before it closes and turns logging off by closing the log file..
See also my_end(), a debugging function.
One use is to do a WRITE, use a shell to run myisamchk, then do a READ.
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
Nothing specific yet identified.
#.#.4 Examples
result = mi_panic(HA_PANIC_CLOSE);
====================
#.# mi_position()
my_off_t mi_position(MI_INFO *mip)
#.#.1 Description
Gets the byte position in the file of the last record read.
mip is an MI_INFO pointer to the open handle.
#.#.2 Return values
Byte position if successful. Zero if an error occurred. ??
#.#.3 Errors
HA_OFFSET_ERROR
if there wasn't any active row.
#.#.4 Examples
currentpos = mi_position( mip );
====================
#.# mi_rfirst()
int mi_rfirst(MI_INFO *mip , byte *buf, int inx)
#.#.1 Description
Reads the first row in the MyISAM file according to the specified index.
If one want's to read rows in physical sequences, then one should instead use mi_scan() or mi_rrnd().
mip is an MI_INFO pointer to the open handle.
buf is the record buffer that will contain the row.
Inx is the index (key) number, which must be the same as currently selected.
mi_rfirst() works by setting the current position mip->lastpos to HA_OFFSET_ERROR (undefined) then calling mi_rnext().
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
HA_ERR_END_OF_FILE
End of file
Otherwise one has probably got a fatal error like HA_ERR_CRASHED or some I-O related error from the Operating System.
#.#.4 Examples
error = mi_rfirst( mip, buffer, keynum);
====================
#.# mi_rkey()
int mi_rkey(MI_INFO *mip, byte *buf, int inx, const byte *key, uint key_len, enum ha_rkey_function search_flag)
#.#.1 Description
Reads the next row after the last row read, using the current index.
If one want's to read rows in physical sequences, then one should instead use mi_scan() or mi_rrnd().
mip is an MI_INFO pointer to the open handle.
buf is the record buffer that will contain the row.
Inx is the index (key) number, which must be the same as currently selected.
If (mip->lastpos) is HA_OFFSET_ERROR (undefined) then mi_rnext() gives the first row.
If you specify a different index number than the last read used, you will get an error.
If the last (current) row has been changed since we read it, mi_rnext() will reposition from the position where that row WAS, not where it is now. (This behaviour is similar to CISAM and better than used in Codebase.)
mi_extra(HA_EXTRA_KEYREAD) can be called first, to cause mi_rkey to read the key but not the record. Then call mi_extra(HA_EXTRA_NO_KEYREAD) to resume normal behaviour.
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
HA_ERR_END_OF_FILE
End of file
Otherwise one has probably got a fatal error like HA_ERR_CRASHED or some I-O related error from the Operating System.
#.#.4 Examples
error = mi_rnext( mip, buffer, keynum );
====================
#.# mi_rlast()
int mi_rlast(MI_INFO *mip , byte *buf, int inx)
#.#.1 Description
Reads the last row in the MyISAM file according to the specified index.
If one want's to read rows in physical sequences, then one should instead use mi_scan() or mi_rrnd().
mip is an MI_INFO pointer to the open handle.
buf is a pointer to the record buffer that will contain the row.
Inx is the index (key) number, which must be the same as currently selected.
mi_rlast() works by setting the current position (mip->lastpos) to HA_OFFSET_ERROR (undefined) then calling mi_rprev().
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
HA_ERR_END_OF_FILE
End of file
Otherwise one has probably got a fatal error like HA_ERR_CRASHED or some I-O related error from the Operating System.
#.#.4 Examples
error = mi_rlast( mip, buffer, keynum);
====================
#.# mi_rnext()
int mi_rnext(MI_INFO *mip , byte *buf, int inx )
#.#.1 Description
Reads the next row after the last row read, using the current index.
If one want's to read rows in physical sequences, then one should instead use mi_scan() or mi_rrnd().
mip is an MI_INFO pointer to the open handle.
buf is the record buffer that will contain the row.
Inx is the index (key) number, which must be the same as currently selected.
If (mip->lastpos) is HA_OFFSET_ERROR (undefined) then mi_rnext() gives the first row.
If you specify a different index number than the last read used, you will get an error.
If the last (current) row has been changed since we read it, mi_rnext() will reposition from the position where that row WAS, not where it is now. (This behaviour is similar to CISAM and better than used in Codebase.)
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
HA_ERR_END_OF_FILE
End of file
Otherwise one has probably got a fatal error like HA_ERR_CRASHED or some I-O related error from the Operating System.
#.#.4 Examples
error = mi_rnext( mip, buffer, keynum );
====================
#.# mi_rrnd()
int mi_rrnd( MI_INFO *mip , byte *buf, my_off_t filepos )
#.#.1 Description
Reads a row based on physical position.
Position can be calculated from record number only when fixed record lengths are used:
position = mip->s.pack.header_length + recnum * mip->s->base.reclength.
If filepos= HA_OFFSET_ERROR then it reads the next row.
And if (mip->lastpos == HA_OFFSET_ERROR) it reads the first row.
mip is an MI_INFO pointer to the open handle.
buf is the record buffer that will contain the row.
filepos is the byte position in the file of the required record.
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
HA_ERR_RECORD_DELETED
A deleted record was read.
HA_ERR_END_OF_FILE
End of file.
#.#.4 Examples
error = mi_rrnd( mip, buffer, mip->nextpos );
====================
#.# mi_rprev()
int mi_rprev(MI_INFO *mip , byte *buf, int inx)
#.#.1 Description
Reads the row previous to the last row read, using the current index.
If one wants to read rows in physical sequences, then one should instead use mi_scan() or mi_rrnd().
If (mip->lastpos) is HA_OFFSET_ERROR (undefined) then mi_rnext() gives the last row in the index.
If you specify a different index number than the last read used, you will get an error.
If the last (current) row has been changed since we read it, mi_rprev() will reposition from the position where that row WAS, not where it is now. This behaviour is similar to CISAM and better than used in Codebase.
mip is an MI_INFO pointer to the open handle.
buf is the record buffer that will contain the row.
Inx is the index (key) number, which must be the same as currently selected.
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
HA_ERR_END_OF_FILE
End of file
Otherwise one has probably got a fatal error like HA_ERR_CRASHED or some I-O related error from the Operating System.
#.#.4 Examples
error = mi_rprev( mip, buffer, keynum );
====================
#.# mi_rsame()
int mi_rsame(MI_INFO *mip, byte *buf, int inx)
#.#.1 Description
Reads the current row to get its latest contents. This is useful to refresh the record buffer in case someone else has changed it.
If inx is negative it reads by position. If inx is >= 0 it reads by key.
With mi_rsame() one can switch to use any other index for the current row. This is good if you have a user application that lets the user do 'read-next' on a row. In this case, if the user want's to start scanning on another index, one simply has to do a mi_rsame() on the new index to activate this.
mip is an MI_INFO pointer to the open handle.
buf is the record buffer that will contain the row.
inx is the index (key) number, or a negative number to select read by position not index. Maybe the negative number has to be (-1) to achieve this behaviour.
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
HA_ERR_WRONG_INDEX
an incorrect index number was supplied
HA_ERR_KEY_NOT_FOUND
info->lastpos was not defined, or the record was already deleted.
#.#.4 Examples
error = mi_rsame( m5mip, rec_ptr, keynum );
====================
#.# mi_scan()
int mi_scan(MI_INFO *mip, byte *buf)
#.#.1 Description
Reads the next row by physical position.
Deleted rows are bypassed.
mi_scan() uses a function pointer "read_rnd" that uses either lower level static or dynamic read functions, positioning from mip->nextpos. Read_rnd is defined in mi_open() depending if the table is Static (read*static - see mi_statrec.c), Compressed (read*pack - see mi_packrec.c), or Space packed or Blobs (read*dynamic - see mi_dynrec.c).
See also mi_scan_init() which initialises ready to mi_scan() through the whole table.
mip is an MI_INFO pointer to the open handle.
buf is the record buffer that will contain the row.
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
HA_ERR_END_OF_FILE
End of file
Otherwise one has probably got a fatal error like HA_ERR_CRASHED or some I-O related error from the Operating System.
#.#.4 Examples
error = mi_scan( mip, recbuff );
====================
#.# mi_scan_init()
int mi_scan_init(MI_INFO *mip[SB1])
#.#.1 Description
Initialises ready to mi_scan() through all rows.
mip is an MI_INFO pointer to the open handle.
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
Nothing specific yet identified.
#.#.4 Examples
====================
#.# mi_status()
int mi_status(MI_INFO *mip, MI_ISAMINFO *x, uint flag)
#.#.1 Description
Gets information about the table.
It is used to get/fill the MI_ISAMINFO struct with statistics data about the MySQL server. One can get information of the number of active rows, delete rows, file lengths...
mip is an MI_INFO pointer to the open handle.
flag is one of the following:
HA_STATUS_POS Return position
HA_STATUS_NO_LOCK Don't use external lock
HA_STATUS_TIME Return update time
HA_STATUS_CONST Return constants value
HA_STATUS_VARIABLE
HA_STATUS_ERRKEY
HA_STATUS_AUTO
#.#.2 Return values
Zero.
#.#.3 Errors
Nothing specific yet identified.
#.#.4 Examples
====================
#.# mi_update()
int mi_update( MI_INFO *mip, const byte *oldbuf, byte *newbuf)
#.#.1 Description
Updates the contents of the current record.
By default you must supply an oldbuf record buffer with the current record contents. This is compared with the file as a guard in case someone else has changed the record in the meantime. *
mip is an MI_INFO pointer to the open handle.
oldbuf is the record buffer that contains the current record contents.
newbuf is the record buffer that contains the new record contents.
*Sometimes you might want to force an update without checking whether another user has changed the record since you last read it. This is somewhat dangerous, so it should ideally not be used. That can be accomplished by wrapping the mi_update() call in two calls to mi_extra(), using these functions:
HA_EXTRA_NO_READCHECK=5 No readcheck on update
HA_EXTRA_READCHECK=6 Use readcheck (def)
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
EACCES
The file was opened for read-only access.
HA_ERR_RECORD_CHANGED
When mi_update() read the current record contents before updating, it differed from oldbuf.
HA_ERR_CRASHED
Key could not be found ??
HA_ERR_FOUND_DUPP_KEY
HA_ERR_RECORD_FILE_FULL
#.#.4 Examples
error = mi_update( mip, oldbuf, newbuf );
====================
#.# mi_write()
int mi_write( MI_INFO *mip, byte *record)
#.#.1 Description
Writes a row to a MyISAM table.
mip is an MI_INFO pointer to the open handle.
The record contents are supplied in buf record buffer.
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
HA_ERR_FOUND_DUPP_KEY
A record already existed with a unique key same as this new record.
HA_ERR_RECORD_FILE_FULL
The error is given if you hit a system limit or if you try to create more rows in a table that you reserverd room for with mi_create().
ENOSPC
The disk is full.
EACCES
The file was opened for read-only access.
#.#.4 Examples
error = mi_write( m5mip, recbuf );
====================
#.# my_end()
void my_end(int infoflag)
#.#.1 Description
Shows debugging information about open MyISAM handles.
my_end() exists primarily for MyISAM debugging.
It would not normally be used in a production environment.
It can give a nice summary of how you have used my_xxx() functions.
It can be used to check that you have closed all files that you have opened.
infoflag is the list function and can be:
MY_CHECK_ERROR List which MyISAM handles are open.
MY_GIVE_INFO Show runtime information.
#.#.2 Return values
Void
#.#.3 Errors
Nothing specific yet identified.
#.#.4 Examples
my_end(MY_CHECK_ERROR | MY_GIVE_INFO);
====================
#.# my_init()
void my_init( void )
#.#.1 Description
Performs MyISAM initialisation for program startup, particularly if using threads.
If using threads, be sure to call my_init() at start of program. (CFS does this in XPOPEN.) It is also safe to call my_init() when not using threads.
#.#.2 Return values
void
Sometimes my_errno might be meaningful if a warning is generated during debugging.
#.#.3 Errors
Nothing specific yet identified.
#.#.4 Examples
my_init();
====================
#.# init_key_cache()
int init_key_cache( long int use_mem, (uint) reserve_mem;
#.#.1 Description
Starts and controls caching of keys. Call init_key_cache() to reserve memory for key caching and to start the caching. (CFS does this in XPOPEN if MYCACHE is defined (regular size), or MYCACHELARGE or MYCACHESMALL.)
Provide use_mem the number of bytes of memory to use for key caching by this process.
reserve_mem should be 0. This is just for very old systems with very little memory.
#.#.2 Return values
The number of 1kb memory blocks now allocated to key caching. Zero if key caching cannot be started (check my_errno), or key caching was already active.
#.#.3 Errors
Nothing specific yet identified.
#.#.4 Examples
Blocks = init_key_cache( 65536L, IO_SIZE*4*10 );
====================
#.# _mi_make_key()
uint _mi_make_key( MI_INFO *mip, uint keynr, uchar *key, const char *record, my_off_t filepos)
#.#.1 Description
Construct a key string for the given index, from the provided record buffer.
??? When packed records are used ...
This is an internal function, not for use by applications. Monty says: "This can't be used to create an external key for an application from your record."
See mi_make_application_key() for a similar function that is useable by applications.
The parameters are:
A MI_INFO pointer mip.
The index number keynr.
The buffer to contain the formatted key string key.
The record buffer record.
??? A file position filepos or zero.
#.#.2 Return values
The byte length of the created key string.
#.#.3 Errors
Nothing specific yet identified.
#.#.4 Examples
uint new_length=_mi_make_key(info,i,new_key,newrec,pos);
====================
#.# _mi_print_key()
void _mi_print_key(FILE *stream, MI_KEYSEG *keyseg, const uchar *key, uint length)
#.#.1 Description
Prints a key in a user understandable format.
This is an internal function for debugging, not for use by applications.
??? Not yet fully documented. I just include it here so that I know it exists.
#.#.2 Return values
A readable print of the key contents goes to the specified output.
#.#.3 Errors
Nothing specific yet identified.
#.#.4 Examples
_mi_print_key(stdout,share->keyinfo[info->errkey].seg,info->lastkey, USE_WHOLE_KEY);
====================
APPENDIX B Choosing a table type
(excerpt from manual.txt in MySQL 3.23.8-alpha)
With MySQL you can currently (version 3.23.5) choose between four usable table formats from a speed point of view.
Static (Fixed-length) table characteristics
* This is the default format. It's used when the table contains no `VARCHAR', `BLOB' or `TEXT' columns.
* All `CHAR', `NUMERIC' and `DECIMAL' columns are space-padded to the column width.
* Very quick.
* Easy to cache.
* Easy to reconstruct after a crash, because records are located in fixed positions.
* Doesn't have to be reorganized (with `myisamchk') unless a huge number of records are deleted and you want to return free disk space to the operating system.
* Usually requires more disk space than dynamic tables.
Dynamic table characteristics
* This format is used if the table contains any `VARCHAR', `BLOB' or `TEXT' columns.
* All string columns are dynamic (except those with a length less than 4).
* Each record is preceded by a bitmap indicating which columns are empty (`''') for string columns, or zero for numeric columns (this isn't the same as columns containing `NULL' values). If a string column has a length of zero after removal of trailing spaces, or a numeric column has a value of zero, it is marked in the bit map and not saved to disk. Non-empty strings are saved as a length byte plus the string contents.
* Usually takes much less disk space than fixed-length tables.
* Each record uses only as much space as is required. If a record becomes larger, it is split into as many pieces as required. This results in record fragmentation.
* If you update a row with information that extends the row length, the row will be fragmented. In this case, you may have to run `myisamchk -r' from time to time to get better performance. Use `myisamchk -ei tbl_name' for some statistics.
* Not as easy to reconstruct after a crash, because a record may be fragmented into many pieces and a link (fragment) may be missing.
* The expected row length for dynamic sized records is:
3
+ (number of columns + 7) / 8
+ (number of char columns)
+ packed size of numeric columns
+ length of strings
+ (number of NULL columns + 7) / 8
There is a penalty of 6 bytes for each link. A dynamic record is linked whenever an update causes an enlargement of the record.
Each new link will be at least 20 bytes, so the next enlargement will probably go in the same link. If not, there will be another link. You may check how many links there are with `myisamchk -ed'. All links may be removed with `myisamchk -r'.
Compressed table characteristics
* A read-only table made with the `myisampack' utility. All customers with extended *MySQL* email support are entitled to a copy of `myisampack' for their internal usage.
* The uncompress code exists in all *MySQL* distributions so that even customers who don't have `myisampack' can read tables that were compressed with `myisampack'
* Takes very little disk space. Minimises disk usage.
* Each record is compressed separately (very little access overhead). The header for a record is fixed (1-3 bytes) depending on the biggest record in the table. Each column is compressed differently. Some of the compression types are:
- There is usually a different Huffman table for each column.
- Suffix space compression.
- Prefix space compression.
- Numbers with value `0' are stored using 1 bit.
- If values in an integer column have a small range, the column is stored using the smallest possible type. For example, a `BIGINT' column (8 bytes) may be stored as a `TINYINT' column (1 byte) if all values are in the range `0' to `255'.
- If a column has only a small set of possible values, the column type is converted to `ENUM'.
- A column may use a combination of the above compressions.
* Can handle fixed or dynamic length records, but not `BLOB' or `TEXT' columns.
* Can be uncompressed with `myisamchk'.
*MySQL* can support different index types, but the normal type is ISAM.
This is a B-tree index and you can roughly calculate the size for the index file as `(key_length+4)*0.67', summed over all keys. (This is for the worst case when all keys are inserted in sorted order.)
String indexes are space compressed. If the first index part is a string, it will also be prefix compressed.
Space compression makes the index file smaller if the string column has a lot of trailing space or is a `VARCHAR' column that is not always used to the full length.
Prefix compression helps if there are many strings with an identical prefix.
In memory table characteristics
HEAP tables only exists in memory so they are lost if `mysqld' is taken down or crashes. But since they are *very* fast they are usefull as anyway.
The *MySQL* internal HEAP tables uses 100% dynamic hashing without overflow areas and don't have problems with delete.
You can only access things by equality using a index (usually by the `=' operator) whith a heap table.
The downside with HEAPS are:
1. You need enough extra memory for all HEAP tables that you want to use at the same time.
2. You can't search on a part of a index.
3. You can't search for the next entry in order (that is to use the index to do a `ORDER BY').
1. *MySQL* also cannot find out how approximately many rows there are between two values. This is used by the optimizer to chose which index to use. But on the other hand no disk seeks are even needed.
====================
#.# mi_()
#.#.1 Description
#.#.2 Return values
Zero if successful. Non-zero if an error occurred.
#.#.3 Errors
Nothing specific yet identified.
#.#.4 Examples
[SB1]int _mi_read_rnd_static_record(MI_INFO *info, byte *buf, my_off_t filepos,
my_bool skipp_deleted_blocks)
int _mi_read_dynamic_record(MI_INFO *info, my_off_t filepos, byte *buf)
Printed on 17/03/00
C-7

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +0,0 @@
Pre-built binaries in different package formats can be found on
http://www.mysql.com/downloads
You can find information about how to install from a source distribution at
http://dev.mysql.com/doc/refman/5.7/en/source-installation.html
The MySQL 5.7 Reference Manual is available on
http://dev.mysql.com/doc/refman/5.7/en/

View File

@ -1,56 +0,0 @@
MySQL Server 5.7
This is a release of MySQL, a dual-license SQL database server.
For the avoidance of doubt, this particular copy of the software
is released under the version 2 of the GNU General Public License.
MySQL is brought to you by Oracle.
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
License information can be found in the COPYING file.
MySQL FOSS License Exception
We want free and open source software applications under certain
licenses to be able to use specified GPL-licensed MySQL client
libraries despite the fact that not all such FOSS licenses are
compatible with version 2 of the GNU General Public License.
Therefore there are special exceptions to the terms and conditions
of the GPLv2 as applied to these client libraries, which are
identified and described in more detail in the FOSS License
Exception at
<http://www.mysql.com/about/legal/licensing/foss-exception.html>.
This distribution may include materials developed by third
parties. For license and attribution notices for these
materials, please refer to the documentation that accompanies
this distribution (see the "Licenses for Third-Party Components"
appendix) or view the online documentation at
<http://dev.mysql.com/doc/>.
GPLv2 Disclaimer
For the avoidance of doubt, except that if any license choice
other than GPL or LGPL is available it will apply instead,
Oracle elects to use only the General Public License version 2
(GPLv2) at this time for any software where a choice of GPL
license versions is made available with the language indicating
that GPLv2 or any later version may be used, or where a choice
of which version of the GPL is applied is otherwise unspecified.
For further information about MySQL or additional documentation,
see:
- The latest information about MySQL: http://www.mysql.com
- The current MySQL documentation: http://dev.mysql.com/doc
Some Reference Manual sections of special interest:
- If you are migrating from an older version of MySQL, please
read the "Upgrading from..." section.
- To see what MySQL can do, take a look at the features section.
- For installation instructions, see the Installing and Upgrading
chapter.
- For the new features/bugfix history, see the MySQL Change History
appendix.
You can browse the MySQL Reference Manual online or download it
in any of several formats at the URL given earlier in this file.
Source distributions include a local copy of the manual in the
Docs directory.

View File

@ -1,4 +0,0 @@
MYSQL_VERSION_MAJOR=5
MYSQL_VERSION_MINOR=7
MYSQL_VERSION_PATCH=27
MYSQL_VERSION_EXTRA=

View File

@ -1,134 +0,0 @@
# Copyright (c) 2006, 2018, 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-1301 USA
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/client
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/mysys_ssl
${LZ4_INCLUDE_DIR}
${SSL_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/libmysql
${CMAKE_SOURCE_DIR}/libbinlogevents/include
${CMAKE_SOURCE_DIR}/regex
${CMAKE_SOURCE_DIR}/strings
${EDITLINE_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake)
## Subdirectory with common client code.
ADD_SUBDIRECTORY(base)
## Subdirectory for mysqlpump code.
ADD_SUBDIRECTORY(dump)
## We will need libeay32.dll and ssleay32.dll when running client executables.
COPY_OPENSSL_DLLS(copy_openssl_client)
INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake)
ADD_DEFINITIONS(${SSL_DEFINES})
MYSQL_ADD_EXECUTABLE(mysql completion_hash.cc mysql.cc readline.cc ../sql-common/sql_string.cc)
TARGET_LINK_LIBRARIES(mysql mysqlclient)
IF(UNIX)
TARGET_LINK_LIBRARIES(mysql ${EDITLINE_LIBRARY})
ENDIF(UNIX)
IF(NOT WITHOUT_SERVER)
MYSQL_ADD_EXECUTABLE(mysql_upgrade
upgrade/program.cc
)
ADD_COMPILE_FLAGS(
upgrade/program.cc COMPILE_FLAGS -I${BOOST_PATCHES_DIR} -I${BOOST_INCLUDE_DIR}
)
TARGET_LINK_LIBRARIES(mysql_upgrade mysqlclient client_base mysqlcheck_core)
ADD_DEPENDENCIES(mysql_upgrade GenFixPrivs GenSysSchema)
ENDIF()
MYSQL_ADD_EXECUTABLE(mysqltest mysqltest.cc COMPONENT Test)
SET_SOURCE_FILES_PROPERTIES(mysqltest.cc PROPERTIES COMPILE_FLAGS "-DTHREADS")
TARGET_LINK_LIBRARIES(mysqltest mysqlclient regex)
ADD_DEPENDENCIES(mysqltest GenError)
ADD_CONVENIENCE_LIBRARY(mysqlcheck_core check/mysqlcheck_core.cc)
TARGET_LINK_LIBRARIES(mysqlcheck_core mysqlclient)
MYSQL_ADD_EXECUTABLE(mysqlcheck check/mysqlcheck.cc)
TARGET_LINK_LIBRARIES(mysqlcheck mysqlcheck_core)
MYSQL_ADD_EXECUTABLE(mysqldump mysqldump.c ../sql-common/my_user.c)
TARGET_LINK_LIBRARIES(mysqldump mysqlclient)
MYSQL_ADD_EXECUTABLE(mysqlimport mysqlimport.c)
SET_SOURCE_FILES_PROPERTIES(mysqlimport.c PROPERTIES COMPILE_FLAGS "-DTHREADS")
TARGET_LINK_LIBRARIES(mysqlimport mysqlclient)
MYSQL_ADD_EXECUTABLE(mysqlshow mysqlshow.c)
TARGET_LINK_LIBRARIES(mysqlshow mysqlclient)
MYSQL_ADD_EXECUTABLE(mysql_plugin mysql_plugin.c)
TARGET_LINK_LIBRARIES(mysql_plugin mysqlclient)
MYSQL_ADD_EXECUTABLE(mysqlbinlog mysqlbinlog.cc)
ADD_COMPILE_FLAGS(
mysqlbinlog.cc
COMPILE_FLAGS "-I${CMAKE_SOURCE_DIR}/sql" "-DHAVE_REPLICATION" "-DDISABLE_PSI_MUTEX"
)
TARGET_LINK_LIBRARIES(mysqlbinlog mysqlclient binlogevents_static)
MYSQL_ADD_EXECUTABLE(mysqladmin mysqladmin.cc)
TARGET_LINK_LIBRARIES(mysqladmin mysqlclient)
MYSQL_ADD_EXECUTABLE(mysqlslap mysqlslap.cc)
SET_SOURCE_FILES_PROPERTIES(mysqlslap.cc PROPERTIES COMPILE_FLAGS "-DTHREADS")
TARGET_LINK_LIBRARIES(mysqlslap mysqlclient)
MYSQL_ADD_EXECUTABLE(mysql_config_editor mysql_config_editor.cc)
TARGET_LINK_LIBRARIES(mysql_config_editor mysqlclient)
MYSQL_ADD_EXECUTABLE(mysql_secure_installation mysql_secure_installation.cc)
TARGET_LINK_LIBRARIES(mysql_secure_installation mysqlclient)
IF(UNIX AND NOT WITHOUT_SERVER)
MYSQL_ADD_EXECUTABLE(mysql_install_db
mysql_install_db.cc auth_utils.cc path.cc logger.cc)
TARGET_LINK_LIBRARIES(mysql_install_db mysqlclient)
ADD_COMPILE_FLAGS(
auth_utils.cc mysql_install_db.cc
COMPILE_FLAGS "-I${CMAKE_SOURCE_DIR}/sql/auth"
)
ADD_DEPENDENCIES(mysql_install_db GenBootstrapPriv GenSysSchema)
ENDIF()
MYSQL_ADD_EXECUTABLE(mysql_ssl_rsa_setup mysql_ssl_rsa_setup.cc path.cc logger.cc)
TARGET_LINK_LIBRARIES(mysql_ssl_rsa_setup mysys mysys_ssl)
SET_TARGET_PROPERTIES(mysql_ssl_rsa_setup PROPERTIES LINKER_LANGUAGE CXX)
# "WIN32" also covers 64 bit. "echo" is used in some files below "mysql-test/".
IF(WIN32)
MYSQL_ADD_EXECUTABLE(echo echo.c)
ENDIF(WIN32)
SET_TARGET_PROPERTIES (
mysql_plugin
mysqlcheck
mysqldump
mysqlimport
mysqlshow
mysqlslap
PROPERTIES HAS_CXX TRUE)
ADD_DEFINITIONS(-DHAVE_DLOPEN)

View File

@ -1,129 +0,0 @@
/*
Copyright (c) 2012, 2016, 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-1301 USA
*/
#include "client_priv.h"
#include "my_rnd.h"
#include "my_aes.h"
#include <sstream>
#include <fstream>
#include <stdint.h>
#include "auth_utils.h"
using namespace std;
/**
Lazy whitespace trimmer
*/
void trim(string *s)
{
stringstream trimmer;
trimmer << *s;
s->clear();
trimmer >> *s;
}
int parse_cnf_file(istream &sin, map<string, string > *options,
const string &header)
{
string option_name;
string option_value;
string token_header;
token_header.append("[").append(header).append("]");
try{
while(true)
{
string row;
getline(sin, row);
trim(&row);
if (row == token_header)
break;
else if (sin.eof())
return ERR_NO_SUCH_CATEGORY;
}
while (!getline(sin, option_name, '=').eof())
{
trim(&option_name);
if (option_name[0] == '[')
break;
getline(sin, option_value);
trim(&option_value);
if (option_name.length() > 0)
options->insert(make_pair(option_name, option_value));
}
return ALL_OK;
} catch(...)
{
return ERR_SYNTAX;
}
}
#define MAX_CIPHER_LEN 4096
#define MAX_CIPHER_STORE_LEN 4U
#define LOGIN_KEY_LEN 20U
int decrypt_login_cnf_file(istream &fin, ostream &sout)
{
try {
fin.seekg(MAX_CIPHER_STORE_LEN, fin.beg);
char rkey[LOGIN_KEY_LEN];
fin.read(rkey, LOGIN_KEY_LEN);
while(true)
{
int len;
char len_buf[MAX_CIPHER_STORE_LEN];
char cipher[MAX_CIPHER_LEN];
fin.read(len_buf, MAX_CIPHER_STORE_LEN);
len= sint4korr(len_buf);
if (len == 0 || fin.eof())
break;
if (len > MAX_CIPHER_LEN)
return ERR_ENCRYPTION;
fin.read(cipher, len);
char plain[MAX_CIPHER_LEN+1];
int aes_length;
aes_length= my_aes_decrypt((const unsigned char *) cipher, len,
(unsigned char *) plain,
(const unsigned char *) rkey,
LOGIN_KEY_LEN, my_aes_128_ecb, NULL);
if ((aes_length > MAX_CIPHER_LEN) || (aes_length <= 0))
return ERR_ENCRYPTION;
plain[aes_length]= 0;
sout << plain;
}
return ALL_OK;
} catch(...)
{
return ERR_ENCRYPTION;
}
}
const string g_allowed_pwd_chars("qwertyuiopasdfghjklzxcvbnm,.-1234567890+*"
"QWERTYUIOPASDFGHJKLZXCVBNM;:_!#%&/()=?><");
const string get_allowed_pwd_chars() { return g_allowed_pwd_chars; }
void generate_password(string *password, int size)
{
stringstream ss;
rand_struct srnd;
while(size > 0)
{
int ch= ((int)(my_rnd_ssl(&srnd)*100))%get_allowed_pwd_chars().size();
ss << get_allowed_pwd_chars()[ch];
--size;
}
password->assign(ss.str());
}

View File

@ -1,132 +0,0 @@
/*
Copyright (c) 2012, 2014, 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-1301 USA
*/
#ifndef AUTH_UTILS_INCLUDED
#define AUTH_UTILS_INCLUDED
#include <string>
#include <iostream>
#include <map>
#include <auth_acls.h>
#define ERR_FILE 1 // File related error
#define ERR_ENCRYPTION 2 // Encryption related error
#define ERR_SYNTAX 3 // Syntax and parsing related error
#define ERR_OTHER 4 // Unspecified error
#define ERR_NO_SUCH_CATEGORY 5 // The specified category isn't present
#define ALL_OK 0 // Reporting success and good fortune
/**
Trivial parser for the login.cnf file which assumes that first entry
is a [client] header followed by some attribute/value -pairs
@param sin Input stream
@param[out] options Output map
@return success rate
@retval ALL_OK Reporting success and good fortune
@retval ERR_SYNTAX Failed to parse the stream
*/
int parse_cnf_file(std::istream &sin,
std::map<std::string, std::string > *options,
const std::string &header);
/**
Decrypts a file and produces a stringstream.
@param fin Input stream
@param[out] sout Output stream
@return success rate
@retval ALL_OK Reporting success and good fortune
@retval ERR_ENCRYPTION Failed to decrypt the input stream
*/
int decrypt_login_cnf_file(std::istream &fin, std::ostream &sout);
void generate_password(std::string *password, int size);
void trim(std::string *s);
const std::string get_allowed_pwd_chars();
/**
An experimental uniform representation of access privileges in MySQL
*/
class Access_privilege
{
public:
Access_privilege() : m_priv(0) {}
Access_privilege(uint64_t privileges) : m_priv(privileges) {}
Access_privilege(const Access_privilege &priv) : m_priv(priv.m_priv) {}
bool has_select_ac() { return (m_priv & SELECT_ACL) > 0; }
bool has_insert_ac() { return (m_priv & INSERT_ACL) > 0; }
bool has_update_ac() { return (m_priv & UPDATE_ACL) > 0; }
bool has_delete_ac() { return (m_priv & DELETE_ACL) > 0; }
bool has_create_ac() { return (m_priv & CREATE_ACL) > 0; }
bool has_drop_ac() { return (m_priv & DROP_ACL) > 0; }
bool has_relead_ac() { return (m_priv & RELOAD_ACL) > 0; }
bool has_shutdown_ac() { return (m_priv & SHUTDOWN_ACL) > 0; }
bool has_process_ac() { return (m_priv & PROCESS_ACL) > 0; }
bool has_file_ac() { return (m_priv & FILE_ACL) > 0; }
bool has_grant_ac() { return (m_priv & GRANT_ACL) > 0; }
bool has_references_ac() { return (m_priv & REFERENCES_ACL) > 0; }
bool has_index_ac() { return (m_priv & INDEX_ACL) > 0; }
bool has_alter_ac() { return (m_priv & ALTER_ACL) > 0; }
bool has_show_db_ac() { return (m_priv & SHOW_DB_ACL) > 0; }
bool has_super_ac() { return (m_priv & SUPER_ACL) > 0; }
bool has_create_tmp_ac() { return (m_priv & CREATE_TMP_ACL) > 0; }
bool has_lock_tables_ac() { return (m_priv & LOCK_TABLES_ACL) > 0; }
bool has_execute_ac() { return (m_priv & EXECUTE_ACL) > 0; }
bool has_repl_slave_ac() { return (m_priv & REPL_SLAVE_ACL) > 0; }
bool has_repl_client_ac() { return (m_priv & REPL_CLIENT_ACL) > 0; }
bool has_create_view_ac() { return (m_priv & CREATE_VIEW_ACL) > 0; }
bool has_show_view_ac() { return (m_priv & SHOW_VIEW_ACL) > 0; }
bool has_create_proc_ac() { return (m_priv & CREATE_PROC_ACL) > 0; }
bool has_alter_proc_ac() { return (m_priv & ALTER_PROC_ACL) > 0; }
bool has_create_user_ac() { return (m_priv & CREATE_USER_ACL) > 0; }
bool has_event_ac() { return (m_priv & EVENT_ACL) > 0; }
bool has_trigger_ac() { return (m_priv & TRIGGER_ACL) > 0; }
bool has_create_tablespace_ac() { return (m_priv & CREATE_TABLESPACE_ACL) > 0; }
inline static uint64_t select_ac() { return SELECT_ACL; }
inline uint64_t insert_ac() { return INSERT_ACL; }
inline uint64_t update_ac() { return UPDATE_ACL; }
inline uint64_t delete_ac() { return DELETE_ACL; }
inline static uint64_t create_ac() { return CREATE_ACL; }
inline static uint64_t drop_ac() { return DROP_ACL; }
inline static uint64_t relead_ac() { return RELOAD_ACL; }
inline static uint64_t shutdown_ac() { return SHUTDOWN_ACL; }
inline static uint64_t process_ac() { return PROCESS_ACL; }
inline static uint64_t file_ac() { return FILE_ACL; }
inline static uint64_t grant_ac() { return GRANT_ACL; }
inline static uint64_t references_ac() { return REFERENCES_ACL; }
inline static uint64_t index_ac() { return INDEX_ACL; }
inline static uint64_t alter_ac() { return ALTER_ACL; }
inline static uint64_t show_db_ac() { return SHOW_DB_ACL; }
inline static uint64_t super_ac() { return SUPER_ACL; }
inline static uint64_t create_tmp_ac() { return CREATE_TMP_ACL; }
inline static uint64_t lock_tables_ac() { return LOCK_TABLES_ACL; }
inline static uint64_t execute_ac() { return EXECUTE_ACL; }
inline static uint64_t repl_slave_ac() { return REPL_SLAVE_ACL; }
inline static uint64_t repl_client_ac() { return REPL_CLIENT_ACL; }
inline static uint64_t create_view_ac() { return CREATE_VIEW_ACL; }
inline static uint64_t show_view_ac() { return SHOW_VIEW_ACL; }
inline static uint64_t create_proc_ac() { return CREATE_PROC_ACL; }
inline static uint64_t alter_proc_ac() { return ALTER_PROC_ACL; }
inline static uint64_t create_user_ac() { return CREATE_USER_ACL; }
inline static uint64_t event_ac() { return EVENT_ACL; }
inline static uint64_t trigger_ac() { return TRIGGER_ACL; }
inline static uint64_t create_tablespace_ac() { return CREATE_TABLESPACE_ACL; }
inline static uint64_t acl_all() { return ~NO_ACCESS; }
uint64_t to_int() const { return m_priv; };
private:
uint64_t m_priv;
};
#endif

View File

@ -1,60 +0,0 @@
# Copyright (c) 2014, 2018, 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-1301 USA
ADD_DEFINITIONS(${SSL_DEFINES})
INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake)
ADD_CONVENIENCE_LIBRARY(client_base
i_option.cc
bool_option.cc
char_array_option.cc
disabled_option.cc
password_option.cc
simple_option.cc
string_option.cc
abstract_options_provider.cc
composite_options_provider.cc
debug_options.cc
help_options.cc
mysql_connection_options.cc
ssl_options.cc
abstract_program.cc
abstract_connection_program.cc
message_data.cc
mysql_query_runner.cc
show_variable_query_extractor.cc
mutex.cc
../get_password.c
../../sql-common/sql_string.cc
)
ADD_COMPILE_FLAGS(
mutex.cc
mysql_query_runner.cc
show_variable_query_extractor.cc
COMPILE_FLAGS -I${BOOST_PATCHES_DIR} -I${BOOST_INCLUDE_DIR}
)
TARGET_LINK_LIBRARIES(client_base mysqlclient)
# Do not build library unless it is needed by some other target.
SET_PROPERTY(TARGET client_base PROPERTY EXCLUDE_FROM_ALL TRUE)

View File

@ -1,42 +0,0 @@
/*
Copyright (c) 2014, 2015, 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-1301 USA
*/
#include "abstract_connection_program.h"
using namespace Mysql::Tools::Base;
Abstract_connection_program::Abstract_connection_program()
: m_connection_options(this)
{
this->add_provider(&this->m_connection_options);
}
MYSQL* Abstract_connection_program::create_connection()
{
return this->m_connection_options.create_connection();
}
CHARSET_INFO* Abstract_connection_program::get_current_charset() const
{
return m_connection_options.get_current_charset();
}
void Abstract_connection_program::set_current_charset(CHARSET_INFO* charset)
{
m_connection_options.set_current_charset(charset);
}

View File

@ -1,69 +0,0 @@
/*
Copyright (c) 2014, 2015, 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-1301 USA
*/
#ifndef ABSTRACT_CONNECTION_PROGRAM_INCLUDED
#define ABSTRACT_CONNECTION_PROGRAM_INCLUDED
#include "client_priv.h"
#include <string>
#include "i_options_provider.h"
#include "composite_options_provider.h"
#include "mysql_connection_options.h"
#include "i_connection_factory.h"
#include "abstract_program.h"
namespace Mysql{
namespace Tools{
namespace Base{
/**
Base class for all programs that use connection to MySQL database server.
*/
class Abstract_connection_program
: public Abstract_program, public I_connection_factory
{
public:
/**
Provides new connection to MySQL database server based on option values.
Implementation of I_connection_factory interface.
*/
virtual MYSQL* create_connection();
/**
Retrieves charset that will be used in new MySQL connections. Can be NULL
if none was set explicitly.
*/
CHARSET_INFO* get_current_charset() const;
/**
Sets charset that will be used in new MySQL connections.
*/
void set_current_charset(CHARSET_INFO* charset);
protected:
Abstract_connection_program();
private:
Options::Mysql_connection_options m_connection_options;
};
}
}
}
#endif

View File

@ -1,67 +0,0 @@
/*
Copyright (c) 2016 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-1301 USA
*/
#ifndef ABSTRACT_ENUM_OPTION_INCLUDED
#define ABSTRACT_ENUM_OPTION_INCLUDED
#include <string>
#include "abstract_option.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Abstract option to handle enum option values.
*/
template<typename T_type, typename T_typelib> class Abstract_enum_option
: public Abstract_option<T_type>
{
protected:
/**
Constructs new enum option.
@param value Pointer to object to receive option value.
@param value Pointer to enum tylelib.
@param var_type my_getopt internal option type.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
@param default_value default value to be supplied to internal option
data structure.
*/
Abstract_enum_option(T_type* value, const T_typelib* type, ulong var_type,
std::string name, std::string description, uint64 default_value);
};
template<typename T_type, typename T_typelib>Abstract_enum_option<T_type, T_typelib>
::Abstract_enum_option(
T_type* value, const T_typelib* type, ulong var_type, std::string name,
std::string description, uint64 default_value)
: Abstract_option<T_type>(
value, var_type, name, description, default_value)
{
this->m_option_structure.typelib= const_cast<T_typelib*>(type);
}
}
}
}
}
#endif

View File

@ -1,122 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef ABSTRACT_INTEGER_NUMBER_OPTION_INCLUDED
#define ABSTRACT_INTEGER_NUMBER_OPTION_INCLUDED
#include <string>
#include "abstract_number_option.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Abstract option to handle integer number option values.
*/
template<typename T_type, typename T_value> class Abstract_integer_number_option
: public Abstract_number_option<T_type, T_value>
{
public:
/**
Sets value for this option. If it is specified before handling commandline
options then supplied value is used as default value of this option.
*/
T_type* set_value(T_value value);
/**
Sets required divisor of input value.
*/
T_type* set_value_step(T_value step);
/**
Sets minimum value boundary for option value. Smaller values passed as
option value will be changed to this minimum value.
Part of implementation of Abstract_number_option virtual method.
*/
virtual T_type* set_minimum_value(T_value minimum);
/**
Sets maximum value boundary for option value. Greater values passed as
option value will be changed to this maximum value.
Part of implementation of Abstract_number_option virtual method.
*/
virtual T_type* set_maximum_value(T_value maximum);
protected:
/**
Constructs new number option.
@param value Pointer to object to receive option value.
@param var_type my_getopt internal option type.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Abstract_integer_number_option(
T_value* value, ulong var_type, std::string name, std::string description);
};
template<typename T_type, typename T_value>
Abstract_integer_number_option<T_type, T_value>::
Abstract_integer_number_option(
T_value* value, ulong var_type, std::string name,
std::string description)
: Abstract_number_option<T_type, T_value>(
value, var_type, name, description, 0)
{
*value= 0;
}
template<typename T_type, typename T_value>
T_type* Abstract_integer_number_option<T_type, T_value>::
set_value(T_value value)
{
*(T_value*)this->m_option_structure.value= value;
this->m_option_structure.def_value= (longlong)value;
return (T_type*)this;
}
template<typename T_type, typename T_value>
T_type* Abstract_integer_number_option<T_type, T_value>::
set_value_step(T_value step)
{
this->m_option_structure.block_size= (long)step;
return (T_type*)this;
}
template<typename T_type, typename T_value>
T_type* Abstract_integer_number_option<T_type, T_value>::
set_minimum_value(T_value minimum)
{
this->m_option_structure.min_value= (longlong)minimum;
return (T_type*)this;
}
template<typename T_type, typename T_value>
T_type* Abstract_integer_number_option<T_type, T_value>::
set_maximum_value(T_value maximum)
{
this->m_option_structure.max_value= (ulonglong)maximum;
return (T_type*)this;
}
}
}
}
}
#endif

View File

@ -1,76 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef ABSTRACT_NUMBER_OPTION_INCLUDED
#define ABSTRACT_NUMBER_OPTION_INCLUDED
#include <string>
#include "abstract_value_option.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Abstract option to handle numeric option values.
*/
template<typename T_type, typename T_value> class Abstract_number_option
: public Abstract_value_option<T_type>
{
public:
/**
Sets minimum value boundary for option value. Smaller values passed as
option value will be changed to this minimum value.
*/
virtual T_type* set_minimum_value(T_value minimum)= 0;
/**
Sets maximum value boundary for option value. Greater values passed as
option value will be changed to this maximum value.
*/
virtual T_type* set_maximum_value(T_value maximum)= 0;
protected:
/**
Constructs new number option.
@param value Pointer to object to receive option value.
@param var_type my_getopt internal option type.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
@param default_value default value to be supplied to internal option
data structure.
*/
Abstract_number_option(T_value* value, ulong var_type, std::string name,
std::string description, uint64 default_value);
};
template<typename T_type, typename T_value>Abstract_number_option<T_type, T_value>
::Abstract_number_option(
T_value* value, ulong var_type, std::string name, std::string description,
uint64 default_value)
: Abstract_value_option<T_type>(
value, var_type, name, description, default_value)
{}
}
}
}
}
#endif

View File

@ -1,197 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef ABSTRACT_OPTION_INCLUDED
#define ABSTRACT_OPTION_INCLUDED
#include <string>
#include <vector>
#include "my_getopt.h"
#include "i_option_changed_listener.h"
#include "i_callable.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
class Abstract_options_provider;
/**
Abstract base with common option functionalities.
*/
template<typename T_type> class Abstract_option : public I_option
{
public:
virtual ~Abstract_option();
/**
Adds new callback for this option for option_parsed() event to callback
chain.
I_Callable can be replaced with std::Function<void(char*)> once we get
one.
*/
T_type* add_callback(Mysql::I_callable<void, char*>* callback);
/**
Sets optid to given character to make possible usage of short option
alternative.
*/
T_type* set_short_character(char code);
protected:
/**
Constructs new option.
@param value Pointer to object to receive option value.
@param var_type my_getopt internal option type.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
@param default_value default value to be supplied to internal option
data structure.
*/
Abstract_option(void* value, ulong var_type, std::string name,
std::string description, uint64 default_value);
/**
Returns my_getopt internal option data structure representing this option.
To be used by Abstract_options_provider when preparing options array to
return.
*/
my_option get_my_option();
/**
Method to set listener on option changed events.
For use from Abstract_options_provider class only.
*/
void set_option_changed_listener(I_option_changed_listener* listener);
my_option m_option_structure;
private:
void call_callbacks(char* argument);
std::vector<Mysql::I_callable<void, char*>*> m_callbacks;
I_option_changed_listener* m_option_changed_listener;
friend class Abstract_options_provider;
};
template<typename T_type> Abstract_option<T_type>::~Abstract_option()
{
my_free((void*)this->m_option_structure.name);
my_free((void*)this->m_option_structure.comment);
for (std::vector<Mysql::I_callable<void, char*>*>::iterator
it= this->m_callbacks.begin();
it != this->m_callbacks.end();
it++)
{
delete *it;
}
}
template<typename T_type> T_type* Abstract_option<T_type>::add_callback(
Mysql::I_callable<void, char*>* callback)
{
this->m_callbacks.push_back(callback);
return (T_type*)this;
}
template<typename T_type> T_type* Abstract_option<T_type>::set_short_character(
char code)
{
// Change optid to new one
uint32 old_optid= this->m_option_structure.id;
this->m_option_structure.id= (int)code;
// Inform that it has changed
if (this->m_option_changed_listener != NULL)
{
this->m_option_changed_listener->notify_option_optid_changed(
this, old_optid);
}
return (T_type*)this;
}
template<typename T_type> Abstract_option<T_type>::Abstract_option(void* value,
ulong var_type, std::string name, std::string description,
uint64 default_value)
: m_option_changed_listener(NULL)
{
this->m_option_structure.block_size= 0;
this->m_option_structure.max_value= 0;
this->m_option_structure.min_value= 0;
this->m_option_structure.sub_size= 0;
this->m_option_structure.typelib= NULL;
this->m_option_structure.u_max_value= NULL;
this->m_option_structure.app_type= this;
this->m_option_structure.arg_type= REQUIRED_ARG;
this->m_option_structure.comment= my_strdup(
PSI_NOT_INSTRUMENTED, description.c_str(), MYF(MY_FAE));
// This in future can be changed to atomic operation (compare_and_exchange)
this->m_option_structure.id= Abstract_option::last_optid;
Abstract_option::last_optid++;
;
this->m_option_structure.def_value= default_value;
this->m_option_structure.name= my_strdup(
PSI_NOT_INSTRUMENTED, name.c_str(), MYF(MY_FAE));
/*
TODO mbabij 15-04-2014: this is based on previous usages of my_option.
Everyone sets this the same as my_option::value, explain why.
*/
this->m_option_structure.u_max_value= value;
this->m_option_structure.value= value;
this->m_option_structure.var_type= var_type;
}
template<typename T_type> my_option Abstract_option<T_type>::get_my_option()
{
return this->m_option_structure;
}
template<typename T_type> void
Abstract_option<T_type>::set_option_changed_listener(
I_option_changed_listener* listener)
{
DBUG_ASSERT(this->m_option_changed_listener == NULL);
this->m_option_changed_listener= listener;
}
template<typename T_type> void Abstract_option<T_type>::call_callbacks(
char* argument)
{
std::vector<Mysql::I_callable<void, char*>*>::iterator callback_it;
for (callback_it= this->m_callbacks.begin();
callback_it != this->m_callbacks.end(); callback_it++)
{
(**callback_it)(argument);
}
}
}
}
}
}
#endif

View File

@ -1,224 +0,0 @@
/*
Copyright (c) 2001, 2016, 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-1301 USA
*/
#include <vector>
#include <iostream>
#include "my_getopt.h"
#include "abstract_options_provider.h"
#include "i_options_provider.h"
using std::vector;
using std::string;
using std::map;
using namespace Mysql::Tools::Base::Options;
using Mysql::Nullable;
Simple_option* Abstract_options_provider::create_new_option(
string name, string description)
{
return this->attach_new_option<Simple_option>(
new Simple_option(name, description));
}
Disabled_option* Abstract_options_provider::create_new_disabled_option(
string name, string description)
{
return this->attach_new_option<Disabled_option>(
new Disabled_option(name, description));
}
Char_array_option* Abstract_options_provider::create_new_option(
char** value, string name, string description)
{
return this->attach_new_option<Char_array_option>(
new Char_array_option(value, false, name, description));
}
Password_option* Abstract_options_provider::create_new_password_option(
Nullable<string>* value, string name, string description)
{
return this->attach_new_option<Password_option>(
new Password_option(value, name, description));
}
String_option* Abstract_options_provider::create_new_option(
Nullable<string>* value, string name, string description)
{
return this->attach_new_option<String_option>(
new String_option(value, name, description));
}
Number_option<int32>* Abstract_options_provider::create_new_option(
int32* value, string name, string description)
{
return this->attach_new_option<Number_option<int32> >(
new Number_option<int32>(value, name, description));
}
Number_option<uint32>* Abstract_options_provider::create_new_option(
uint32* value, string name, string description)
{
return this->attach_new_option<Number_option<uint32> >(
new Number_option<uint32>(value, name, description));
}
Number_option<int64>* Abstract_options_provider::create_new_option(
int64* value, string name, string description)
{
return this->attach_new_option<Number_option<int64> >(
new Number_option<int64>(value, name, description));
}
Number_option<uint64>* Abstract_options_provider::create_new_option(
uint64* value, string name, string description)
{
return this->attach_new_option<Number_option<uint64> >(
new Number_option<uint64>(value, name, description));
}
Number_option<double>* Abstract_options_provider::create_new_option(
double* value, string name, string description)
{
return this->attach_new_option<Number_option<double> >(
new Number_option<double>(value, name, description));
}
Bool_option* Abstract_options_provider::create_new_option(
bool* value, string name, string description)
{
return this->attach_new_option<Bool_option>(
new Bool_option(value, name, description));
}
vector<my_option> Abstract_options_provider::generate_options()
{
if (this->m_are_options_created == false)
{
this->m_are_options_created= true;
this->create_options();
}
vector<my_option> res;
for (vector<I_option*>::iterator it= this->m_options_created.begin();
it != this->m_options_created.end();
it++)
{
res.push_back((*it)->get_my_option());
}
return res;
}
void Abstract_options_provider::options_parsed()
{}
Abstract_options_provider::Abstract_options_provider()
: m_are_options_created(false),
m_option_changed_listener(NULL)
{}
Abstract_options_provider::~Abstract_options_provider()
{
for (vector<I_option*>::iterator it= this->m_options_created.begin();
it != this->m_options_created.end();
it++)
{
delete *it;
}
}
void Abstract_options_provider::set_option_changed_listener(I_option_changed_listener* listener)
{
DBUG_ASSERT(this->m_option_changed_listener == NULL);
this->m_option_changed_listener= listener;
}
void Abstract_options_provider::notify_option_name_changed(I_option* source,
string old_name)
{
// Check if it is modification or new assignment
if (old_name != "")
{
this->m_name_usage.erase(this->m_name_usage.find(old_name));
}
string new_name= source->get_my_option().name;
// Try to find existing option with that name.
map<string, I_option*>::iterator name_item =
this->m_name_usage.find(new_name);
// Report error if already used.
if (name_item != this->m_name_usage.end())
{
std::cerr << "Cannot register new option \"" << new_name
<< "\" as it collides with existing one with following name \""
<< name_item->second->get_my_option().name << "\" and description: "
<< name_item->second->get_my_option().comment << std::endl;
exit(1);
}
// Add name usage.
this->m_name_usage.insert(std::make_pair(new_name, source));
// If we have listener we should inform it too.
if (this->m_option_changed_listener != NULL)
{
this->m_option_changed_listener->notify_option_name_changed(source, old_name);
}
}
void Abstract_options_provider::notify_option_optid_changed(I_option* source,
uint32 old_optid)
{
// Check if it is modification or new assignment
if (old_optid != 0)
{
this->m_optid_usage.erase(this->m_optid_usage.find(old_optid));
}
uint32 new_optid= source->get_my_option().id;
// Try to find existing option with that optid.
map<uint32, I_option*>::iterator optid_item =
this->m_optid_usage.find(new_optid);
// Report error if already used.
if (optid_item != this->m_optid_usage.end())
{
string name= source->get_my_option().name;
std::cerr << "Cannot register new option \"" << name
<< "\" as it collides with existing one with following name \""
<< optid_item->second->get_my_option().name << "\" and description: "
<< optid_item->second->get_my_option().comment << std::endl;
exit(1);
}
// Add optid usage.
this->m_optid_usage.insert(std::make_pair(new_optid, source));
// If we have listener we should inform it too.
if (this->m_option_changed_listener != NULL)
{
this->m_option_changed_listener->notify_option_optid_changed(source, old_optid);
}
}

View File

@ -1,233 +0,0 @@
/*
Copyright (c) 2014, 2016 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-1301 USA
*/
#ifndef ABSTRACT_OPTIONS_PROVIDER_INCLUDED
#define ABSTRACT_OPTIONS_PROVIDER_INCLUDED
#include <map>
#include <string>
#include "i_option.h"
#include "i_options_provider.h"
#include "i_option_changed_listener.h"
#include "simple_option.h"
#include "disabled_option.h"
#include "char_array_option.h"
#include "password_option.h"
#include "string_option.h"
#include "number_option.h"
#include "bool_option.h"
#include "enum_option.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Common abstract class for options providers.
Provides common functionalities.
*/
class Abstract_options_provider : public I_options_provider
{
public:
/**
Creates and attach new simple option.
@param name Name of option. It is used in command-line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Simple_option* create_new_option(std::string name, std::string description);
/**
Creates and attach new disabled option. This option is to mark existance
of options inavailable due to distribution configuration.
@param name Name of option. It is used in command-line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Disabled_option* create_new_disabled_option(
std::string name, std::string description);
/**
Creates and attach new string option stored in char* type object.
@param value Pointer to char* object to receive option value.
@param allocated Specifies if value set should be some static string or
dynamically allocated string with my_strdup.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Char_array_option* create_new_option(
char** value, std::string name, std::string description);
/**
Creates and attach new password option. It removes password from
command-line on UNIX systems to prevent password to be seen when listing
processes.
@param value Pointer to Nullable<string> object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Password_option* create_new_password_option(
Nullable<std::string>* value, std::string name, std::string description);
/**
Creates and attach new string option.
@param value Pointer to Nullable<string> object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
String_option* create_new_option(
Nullable<std::string>* value, std::string name, std::string description);
/**
Creates and attach new 32-bit signed number option.
@param value Pointer to int32 object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Number_option<int32>* create_new_option(
int32* value, std::string name, std::string description);
/**
Creates and attach new 32-bit unsigned number option.
@param value Pointer to uint32 object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Number_option<uint32>* create_new_option(
uint32* value, std::string name, std::string description);
/**
Creates and attach new 64-bit signed number option.
@param value Pointer to int64 object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Number_option<int64>* create_new_option(
int64* value, std::string name, std::string description);
/**
Creates and attach new 64-bit unsigned number option.
@param value Pointer to uint64 object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Number_option<uint64>* create_new_option(
uint64* value, std::string name, std::string description);
/**
Creates and attach new floating-point number option.
@param value Pointer to double object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Number_option<double>* create_new_option(
double* value, std::string name, std::string description);
/**
Creates and attach new boolean option with value received from argument.
@param value Pointer to double object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Bool_option* create_new_option(
bool* value, std::string name, std::string description);
template<typename T_type, typename T_typelib>
Enum_option<T_type, T_typelib>* create_new_enum_option(
T_type* value, const T_typelib* type, std::string name,
std::string description)
{
return this->attach_new_option<Enum_option<T_type, T_typelib> >(
new Enum_option<T_type, T_typelib>(value, type, name, description));
}
/**
Creates all options that will be provided.
*/
virtual void create_options()= 0;
/**
Creates list of options provided by this provider.
Part of I_options_provider interface implementation.
@returns list of my_getopt internal option data structures.
*/
virtual std::vector<my_option> generate_options();
/**
Callback to be called when command-line options parsing have finished.
Part of I_options_provider interface implementation.
*/
virtual void options_parsed();
protected:
Abstract_options_provider();
virtual ~Abstract_options_provider();
/**
Sets optional option changes listener to which all changes in all options
contained in this provider should be reported. This is used when this
provider is attached to another.
Part of I_options_provider interface implementation.
*/
virtual void set_option_changed_listener(I_option_changed_listener* listener);
private:
/**
Makes sure this provider will be able to watch name and optid usage.
*/
template<typename T_type> T_type* attach_new_option(T_type* option)
{
// Make this option reporting all name and optid changes to us.
option->set_option_changed_listener(this);
// Add to list of our own options.
this->m_options_created.push_back(option);
// Check for name and optid collision.
this->notify_option_name_changed(option, "");
this->notify_option_optid_changed(option, 0);
return option;
}
/**
Called after specified option has name changed.
It is also called when new option is added, old_name is empty string in
that case.
Part of I_option_changed_listener interface implementation.
*/
virtual void notify_option_name_changed(I_option* source, std::string old_name);
/**
Called after specified option has option ID changed.
It is also called when new option is added, old_optid is 0 in that case.
Part of I_option_changed_listener interface implementation.
*/
virtual void notify_option_optid_changed(I_option* source, uint32 old_optid);
bool m_are_options_created;
std::map<std::string, I_option*> m_name_usage;
std::map<uint32, I_option*> m_optid_usage;
I_option_changed_listener* m_option_changed_listener;
std::vector<I_option*> m_options_created;
};
}
}
}
}
#endif

View File

@ -1,163 +0,0 @@
/*
Copyright (c) 2014, 2016 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-1301 USA
*/
#include "client_priv.h"
#include "abstract_program.h"
#include "my_default.h"
#include <algorithm>
using namespace Mysql::Tools::Base;
using std::string;
using std::vector;
extern const char *load_default_groups[];
my_bool Abstract_program::callback_option_parsed(
int optid,
const struct my_option *opt MY_ATTRIBUTE((unused)),
char *argument)
{
// Check if option uses My::Tools::Base::Options, and it should.
Options::I_option* app_type = (Options::I_option*)opt->app_type;
Options::I_option* option = dynamic_cast<Options::I_option*>(app_type);
if (option != NULL)
{
option->call_callbacks(argument);
}
return 0;
}
const string Abstract_program::get_name()
{
return this->m_name;
}
my_option* Abstract_program::get_options_array()
{
return &this->m_options[0];
}
Abstract_program::Abstract_program()
: m_debug_options(this),
m_help_options(this),
m_defaults_argv(NULL)
{
this->add_providers(&this->m_help_options, &this->m_debug_options, NULL);
}
void Abstract_program::run(int argc, char **argv)
{
vector<Options::I_options_provider*>::iterator it;
this->init_name(argv[0]);
MY_INIT(this->m_name.c_str());
this->aggregate_options();
my_getopt_use_args_separator= TRUE;
if (load_defaults("my",load_default_groups,&argc,&argv))
this->error(Message_data(
1, "Error during loading default options", Message_type_error));
my_getopt_use_args_separator= FALSE;
this->m_defaults_argv= argv;
int ho_error= handle_options(&argc, &argv, this->get_options_array(),
Abstract_program::callback_option_parsed);
if (ho_error != 0)
{
this->error(Message_data(
ho_error, "Error during handling options", Message_type_error));
}
// Let providers handle their parsed options.
this->options_parsed();
vector<string> positional_options;
for (; argc > 0; argc--, argv++)
{
positional_options.push_back(*argv);
}
// Execute main body of program.
int result= this->execute(positional_options);
exit(result);
}
Abstract_program::~Abstract_program()
{
if (this->m_defaults_argv)
{
free_defaults(this->m_defaults_argv);
}
}
void Abstract_program::init_name(char *name_from_cmd_line)
{
#if _WIN32
char* name;
char name_buf[FN_REFLEN];
if (GetModuleFileName(NULL, name_buf, FN_REFLEN) != 0)
{
name= name_buf;
}
else
{
name= name_from_cmd_line;
}
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath_s( name, drive, dir, fname, ext);
this->m_name= fname;
#else
string name= name_from_cmd_line;
this->m_name= name.substr( name.find_last_of( '/' ) +1 );
#endif
}
void Abstract_program::aggregate_options()
{
// Concatenate all available command line options.
this->m_options.clear();
this->m_options= this->generate_options();
// Sort by lexical order of long names.
std::sort(this->m_options.begin(), this->m_options.end(),
&Abstract_program::options_by_name_comparer);
// Adding sentinel, handle_options assume input as array with sentinel.
my_option sentinel=
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0};
this->m_options.push_back(sentinel);
}
bool Abstract_program::options_by_name_comparer(const my_option& a, const my_option& b)
{
if (strcmp(a.name, "help") == 0)
return true;
if (strcmp(b.name, "help") == 0)
return false;
return strcmp(a.name, b.name) < 0;
}

View File

@ -1,131 +0,0 @@
/*
Copyright (c) 2014, 2016 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-1301 USA
*/
#ifndef ABSTRACT_PROGRAM_INCLUDED
#define ABSTRACT_PROGRAM_INCLUDED
#include <string>
#include "i_options_provider.h"
#include "composite_options_provider.h"
#include "debug_options.h"
#include "help_options.h"
#include "message_data.h"
namespace Mysql{
namespace Tools{
namespace Base{
/**
Base class for all MySQL client tools.
*/
class Abstract_program : public Options::Composite_options_provider
{
public:
virtual ~Abstract_program();
/**
Returns null-terminated string with name of current program.
*/
const std::string get_name();
/**
Returns pointer to array of options for usage in handle_options.
Array has empty sentinel at the end, as handle_options expects.
*/
my_option* get_options_array();
/**
Does all initialization and exit work, calls execute().
*/
void run(int argc, char **argv);
/**
Returns string describing current version of this program.
*/
virtual std::string get_version()= 0;
/**
Returns year of first release of this program.
*/
virtual int get_first_release_year()= 0;
/**
Returns string describing shortly current program
*/
virtual std::string get_description()= 0;
/**
Handles general errors.
*/
virtual void error(const Message_data& message)= 0;
/**
Runs main program code.
*/
virtual int execute(std::vector<std::string> positional_options)= 0;
/**
Prints program invocation message.
*/
virtual void short_usage()= 0;
/**
Return error code
*/
virtual int get_error_code()= 0;
protected:
Abstract_program();
private:
/**
Initializes program name.
*/
void init_name(char *name_from_cmd_line);
/**
Gathers all options from option providers and save in array to be used in
my_getopt functionality.
*/
void aggregate_options();
/**
Compares option structures by long name. Keeps --help first.
*/
static bool options_by_name_comparer(const my_option& a, const my_option& b);
/*
Redirects call to option_parsed of main Abstract_program instance.
If we have anonymous functions or binding this should be removed.
*/
static my_bool callback_option_parsed(int optid,
const struct my_option *opt MY_ATTRIBUTE((unused)),
char *argument);
Options::Debug_options m_debug_options;
Options::Help_options m_help_options;
std::vector<my_option> m_options;
char **m_defaults_argv;
std::string m_name;
friend class Abstract_connection_program;
};
}
}
}
#endif

View File

@ -1,110 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef ABSTRACT_STRING_OPTION_INCLUDED
#define ABSTRACT_STRING_OPTION_INCLUDED
#include <string>
#include "my_getopt.h"
#include "abstract_value_option.h"
#include "nullable.h"
#include "instance_callback.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Abstract option to handle options accepting string value argument.
*/
template<typename T_type> class Abstract_string_option
: public Abstract_value_option<T_type>
{
public:
/**
Sets value for this option. If it is specified before handling commandline
options then supplied value is used as default value of this option.
*/
T_type* set_value(std::string value);
protected:
/**
Constructs new string option.
@param value Pointer to string object to receive option value.
@param var_type my_getopt internal option type.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Abstract_string_option(
Nullable<std::string>* value, ulong var_type, std::string name,
std::string description);
Nullable<std::string>* m_destination_value;
private:
void string_callback(char* argument);
const char* m_original_value;
};
template<typename T_type> Abstract_string_option<T_type>::Abstract_string_option(
Nullable<std::string>* value, ulong var_type, std::string name, std::string description)
: Abstract_value_option<T_type>(
&this->m_original_value, var_type, name, description, (uint64)NULL),
m_destination_value(value)
{
*value= Nullable<std::string>();
this->m_original_value= NULL;
this->add_callback(new Instance_callback
<void, char*, Abstract_string_option<T_type> >(
this, &Abstract_string_option<T_type>::string_callback));
}
template<typename T_type> T_type* Abstract_string_option<T_type>::set_value(
std::string value)
{
*this->m_destination_value= Nullable<std::string>(value);
this->m_original_value= this->m_destination_value->value().c_str();
this->m_option_structure.def_value= (uint64)this->m_destination_value
->value().c_str();
return (T_type*)this;
}
template<typename T_type> void Abstract_string_option<T_type>::string_callback(
char* argument)
{
if (argument != NULL)
{
// Copy argument value from char* to destination string.
*this->m_destination_value= Nullable<std::string>(this->m_original_value);
}
else
{
// There is no argument supplied, we shouldn't change default value.
}
}
}
}
}
}
#endif

View File

@ -1,75 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef ABSTRACT_VALUE_OPTION_INCLUDED
#define ABSTRACT_VALUE_OPTION_INCLUDED
#include <string>
#include <my_getopt.h>
#include "abstract_option.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Abstract option to handle options accepting value argument.
*/
template<typename T_type> class Abstract_value_option
: public Abstract_option<T_type>
{
public:
/**
Sets arg_type to OPT_ARG - doesn't require argument to be specified when
using this option.
*/
T_type* value_optional();
protected:
/**
Constructs new option with value argument.
@param value Pointer to object to receive option value.
@param var_type my_getopt internal option type.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
@param default_value default value to be supplied to internal option
data structure.
*/
Abstract_value_option(void* value, ulong var_type, std::string name,
std::string description, uint64 default_value);
};
template<typename T_type> Abstract_value_option<T_type>::Abstract_value_option(
void* value, ulong var_type, std::string name, std::string description,
uint64 default_value)
: Abstract_option<T_type>(value, var_type, name, description, default_value)
{}
template<typename T_type> T_type* Abstract_value_option<T_type>::value_optional()
{
this->m_option_structure.arg_type= OPT_ARG;
return (T_type*)this;
}
}
}
}
}
#endif

View File

@ -1,104 +0,0 @@
/*
Copyright (c) 2015, 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-1301 USA
*/
#ifndef ATOMIC_INCLUDED
#define ATOMIC_INCLUDED
#include "my_global.h"
#include "my_atomic.h"
namespace my_boost{
template<typename TType> class atomic
{
public:
atomic()
{}
atomic(const TType& value)
{
this->store(value);
}
TType load() const
{
return (TType)my_atomic_load64((volatile int64*)&m_value);
}
void store(TType value)
{
my_atomic_store64(&m_value, value);
}
bool compare_exchange_strong(TType& expected, TType destination)
{
int64 u64_expected= expected;
bool res= my_atomic_cas64(&m_value, &u64_expected, destination);
expected= u64_expected;
return res;
}
TType operator ++()
{
return *this += 1;
}
TType operator ++(int)
{
return (TType)my_atomic_add64(&m_value, 1);
}
TType operator --()
{
return *this -= 1;
}
TType operator --(int)
{
return my_atomic_add64(&m_value, -1);
}
TType operator +=(TType value)
{
return my_atomic_add64(&m_value, value) + value;
}
TType operator -=(TType value)
{
return this->fetch_sub(value) - value;
}
TType fetch_sub(TType value)
{
return (TType)my_atomic_add64(&m_value, -(signed)value);
}
operator TType() const
{
return this->load();
}
void join();
private:
volatile int64 m_value;
};
typedef atomic<uint32> atomic_uint32_t;
typedef atomic<int64> atomic_int64_t;
typedef atomic<uint64> atomic_uint64_t;
typedef atomic<bool> atomic_bool;
}
#endif

View File

@ -1,35 +0,0 @@
/*
Copyright (c) 2014, 2015, 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-1301 USA
*/
#include "bool_option.h"
using namespace Mysql::Tools::Base::Options;
using std::string;
Bool_option::Bool_option(bool* value, string name, string description)
: Abstract_option<Bool_option>(value, GET_BOOL, name, description, false)
{
this->m_option_structure.arg_type= NO_ARG;
*value= false;
}
Bool_option* Bool_option::set_value(bool value)
{
*(bool*)this->m_option_structure.value= value;
this->m_option_structure.def_value= (longlong)value;
return this;
}

View File

@ -1,57 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef BOOL_OPTION_INCLUDED
#define BOOL_OPTION_INCLUDED
#include <string>
#include <my_getopt.h>
#include "abstract_option.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Boolean option with value specified as argument.
*/
class Bool_option : public Abstract_option<Bool_option>
{
public:
/**
Constructs new boolean option with value received from argument.
@param value Pointer to double object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Bool_option(bool* value, std::string name, std::string description);
/**
Sets value for this option. If it is specified before handling commandline
options then supplied value is used as default value of this option.
*/
Bool_option* set_value(bool value);
};
}
}
}
}
#endif

View File

@ -1,36 +0,0 @@
/*
Copyright (c) 2001, 2015, 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-1301 USA
*/
#include "char_array_option.h"
using namespace Mysql::Tools::Base::Options;
using std::string;
Char_array_option::Char_array_option(
char** value, bool allocated, string name, string description)
: Abstract_value_option<char*>(value, allocated ? GET_STR_ALLOC : GET_STR,
name, description, (uint64)NULL)
{
*value= NULL;
}
Char_array_option* Char_array_option::set_value(char* value)
{
*(char**)this->m_option_structure.value= value;
this->m_option_structure.def_value= (uint64)value;
return this;
}

View File

@ -1,58 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef CHAR_ARRAY_OPTION_INCLUDED
#define CHAR_ARRAY_OPTION_INCLUDED
#include "abstract_value_option.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Option class to get string parameter value and set to char* type object.
*/
class Char_array_option : public Abstract_value_option<char*>
{
public:
/**
Constructs new string option.
@param value Pointer to char* object to receive option value.
@param allocated Specifies if value set should be some static string or
dynamically allocated string with my_strdup.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Char_array_option(
char** value, bool allocated, std::string name, std::string description);
/**
Sets value for this option. If it is specified before handling commandline
options then supplied value is used as default value of this option.
*/
Char_array_option* set_value(char* value);
};
}
}
}
}
#endif

View File

@ -1,87 +0,0 @@
/*
Copyright (c) 2001, 2014, 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-1301 USA
*/
#include <vector>
#include "composite_options_provider.h"
#include "i_options_provider.h"
using std::vector;
using namespace Mysql::Tools::Base::Options;
void Composite_options_provider::add_providers(
I_options_provider* first, ...)
{
DBUG_ASSERT(this->m_options_providers.size() == 0);
va_list options_to_add;
va_start(options_to_add, first);
this->add_provider(first);
for (;;)
{
Options::I_options_provider* options_provider=
va_arg(options_to_add, I_options_provider*);
if (options_provider == NULL)
{
break;
}
this->add_provider(options_provider);
}
va_end(options_to_add);
}
void Composite_options_provider::add_provider(
I_options_provider* options_provider)
{
this->m_options_providers.push_back(options_provider);
options_provider->set_option_changed_listener(this);
}
void Composite_options_provider::options_parsed()
{
vector<I_options_provider*>::iterator it;
for (it= this->m_options_providers.begin();
it != this->m_options_providers.end();
it++)
{
(*it)->options_parsed();
}
}
vector<my_option> Composite_options_provider::generate_options()
{
vector<my_option> result;
// Add options for all children providers.
vector<I_options_provider*>::iterator it;
for (it= this->m_options_providers.begin();
it != this->m_options_providers.end();
it++)
{
vector<my_option> new_options= (*it)->generate_options();
result.insert(result.end(), new_options.begin(), new_options.end());
}
// Add options from this provider.
vector<my_option> new_options= Abstract_options_provider::generate_options();
result.insert(result.end(), new_options.begin(), new_options.end());
return result;
}

View File

@ -1,65 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef COMPOSITE_OPTIONS_PROVIDER_INCLUDED
#define COMPOSITE_OPTIONS_PROVIDER_INCLUDED
#include "i_option.h"
#include "abstract_options_provider.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Provider that aggregates options from other providers.
It is still a provider, so can have have own options added.
*/
class Composite_options_provider : public Abstract_options_provider
{
public:
/**
Adds new providers to list. Last parameter value must be NULL.
*/
void add_providers(I_options_provider* first, /*I_options_provider* */...);
/**
Adds new provider to list.
*/
void add_provider(I_options_provider* options_provider);
/**
This callback is to be called after all options were parsed.
*/
virtual void options_parsed();
/**
Aggregates all options from itsself and all contained providers.
*/
virtual std::vector<my_option> generate_options();
private:
std::vector<I_options_provider*> m_options_providers;
};
}
}
}
}
#endif

View File

@ -1,95 +0,0 @@
/*
Copyright (c) 2014, 2016, 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-1301 USA
*/
#include "client_priv.h"
#include "debug_options.h"
#include "abstract_program.h"
#include "instance_callback.h"
using namespace Mysql::Tools::Base::Options;
using Mysql::Tools::Base::Abstract_program;
static Debug_options* primary_debug_options= NULL;
static uint my_end_arg;
static void debug_do_exit()
{
my_end(::my_end_arg);
}
Debug_options::Debug_options(Abstract_program* program)
: m_program(program)
{
if (::primary_debug_options == NULL)
{
primary_debug_options= this;
/*
We don't want to call this routine in destructor, as we want it being
called only once, and second we want it to be called as late as possible.
Possibly when this object is already freed up.
*/
atexit(&::debug_do_exit);
}
}
void Debug_options::create_options()
{
#ifdef DBUG_OFF
this->create_new_disabled_option("debug",
"This is a non-debug version. Catch this and exit.")
->set_short_character('#');
this->create_new_disabled_option("debug-check",
"This is a non-debug version. Catch this and exit.");
this->create_new_disabled_option("debug-info",
"This is a non-debug version. Catch this and exit.");
#else
this->create_new_option(&this->m_dbug_option, "debug", "Output debug log.")
->set_short_character('#')
->value_optional()
->set_value("d:t:O,/tmp/" + this->m_program->get_name() + ".trace")
->add_callback(new Instance_callback<void, char*, Debug_options>(
this, &Debug_options::debug_option_callback));
this->create_new_option(&this->m_debug_check_flag, "debug-check",
"Check memory and open file usage at exit.");
this->create_new_option(&this->m_debug_info_flag, "debug-info",
"Print some debug info at exit.")
->set_short_character('T');
#endif
}
void Debug_options::debug_option_callback(char *argument MY_ATTRIBUTE((unused)))
{
if (this->m_dbug_option.has_value())
{
DBUG_PUSH(this->m_dbug_option.value().c_str());
}
this->m_debug_check_flag= 1;
}
void Debug_options::options_parsed()
{
if (this->m_debug_info_flag)
{
::my_end_arg|= MY_CHECK_ERROR | MY_GIVE_INFO;
}
else if (this->m_debug_check_flag)
{
::my_end_arg|= MY_CHECK_ERROR;
}
}

View File

@ -1,68 +0,0 @@
/*
Copyright (c) 2014, 2016, 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-1301 USA
*/
#ifndef DEBUG_OPTIONS_INCLUDED
#define DEBUG_OPTIONS_INCLUDED
#include "abstract_options_provider.h"
#include "nullable.h"
namespace Mysql{
namespace Tools{
namespace Base{
class Abstract_program;
namespace Options{
/**
Options provider providing debugging options.
*/
class Debug_options : public Abstract_options_provider
{
public:
/**
Constructs new debug options provider.
@param program Pointer to main program class.
*/
Debug_options(Abstract_program* program);
/**
Creates all options that will be provided.
Implementation of Abstract_options_provider virtual method.
*/
virtual void create_options();
/**
Callback to be called when command-line options parsing have finished.
*/
virtual void options_parsed();
private:
void debug_option_callback(char *argument MY_ATTRIBUTE((unused)));
Abstract_program* m_program;
bool m_debug_info_flag;
bool m_debug_check_flag;
Nullable<std::string> m_dbug_option;
};
}
}
}
}
#endif

View File

@ -1,27 +0,0 @@
/*
Copyright (c) 2001, 2015, 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-1301 USA
*/
#include "disabled_option.h"
using std::string;
using namespace Mysql::Tools::Base::Options;
Disabled_option::Disabled_option(string name, string description)
: Abstract_option<Disabled_option>(NULL, GET_DISABLED, name, description, 0)
{
this->m_option_structure.arg_type= OPT_ARG;
}

View File

@ -1,50 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef DISABLED_OPTION_INCLUDED
#define DISABLED_OPTION_INCLUDED
#include <my_getopt.h>
#include "abstract_option.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Disabled option. This option is used to mark existance of options
inavailable due to distribution configuration.
*/
class Disabled_option : public Abstract_option<Disabled_option>
{
public:
/**
Constructs new disabled option.
@param name Name of option. It is used in command-line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Disabled_option(std::string name, std::string description);
};
}
}
}
}
#endif

View File

@ -1,62 +0,0 @@
/*
Copyright (c) 2016 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-1301 USA
*/
#ifndef ENUM_OPTION_INCLUDED
#define ENUM_OPTION_INCLUDED
#include <string>
#include "abstract_enum_option.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Enum value option.
*/
template<typename T_type, typename T_typelib>
class Enum_option : public Abstract_enum_option<T_type, T_typelib>
{
public:
/**
Constructs new enum option.
@param value Pointer to enum object to receive option value.
@param value Pointer to enum tylelib.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Enum_option(T_type* value, const T_typelib* type, std::string name, std::string description)
: Abstract_enum_option<T_type, T_typelib>(value, type, GET_ENUM, name, description, 1),
m_value(value)
{}
void set_value(T_type value)
{
*m_value= value;
}
private:
T_type* m_value;
};
}
}
}
}
#endif

View File

@ -1,117 +0,0 @@
/*
Copyright (c) 2014, 2017, 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-1301 USA
*/
#include "client_priv.h"
#include "my_default.h"
#include <sstream>
#include "help_options.h"
#include "abstract_program.h"
#include <welcome_copyright_notice.h> /* ORACLE_WELCOME_COPYRIGHT_NOTICE */
using namespace Mysql::Tools::Base::Options;
using Mysql::Tools::Base::Abstract_program;
using std::string;
extern const char *load_default_groups[];
Help_options::Help_options(Abstract_program *program)
: m_program(program)
{}
void Help_options::create_options()
{
this->create_new_option("help", "Display this help message and exit.")
->set_short_character('?')
->add_callback(new Instance_callback<void, char*, Help_options>(
this, &Help_options::help_callback));
this->create_new_option("version", "Output version information and exit.")
->set_short_character('V')
->add_callback(new Instance_callback<void, char*, Help_options>(
this, &Help_options::version_callback));
}
void Help_options::help_callback(char* argument MY_ATTRIBUTE((unused)))
{
this->print_usage();
exit(0);
}
void Help_options::version_callback(char* argument MY_ATTRIBUTE((unused)))
{
this->print_version_line();
exit(0);
}
/** A helper function. Prints the program version line. */
void Help_options::print_version_line()
{
printf("%s Ver %s Distrib %s, for %s (%s)\n",
this->m_program->get_name().c_str(),
this->m_program->get_version().c_str(),
MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
}
void Mysql::Tools::Base::Options::Help_options::print_usage()
{
this->print_version_line();
std::ostringstream s;
s << m_program->get_first_release_year();
string first_year_str(s.str());
string copyright;
if (first_year_str == COPYRIGHT_NOTICE_CURRENT_YEAR)
{
copyright= ORACLE_WELCOME_COPYRIGHT_NOTICE(COPYRIGHT_NOTICE_CURRENT_YEAR);
}
else
{
#define FIRST_YEAR_CONSTANT "$first_year$"
string first_year_constant_str= FIRST_YEAR_CONSTANT;
copyright= ORACLE_WELCOME_COPYRIGHT_NOTICE(FIRST_YEAR_CONSTANT);
copyright= copyright.replace(copyright.find(first_year_constant_str),
first_year_constant_str.length(), first_year_str);
}
printf("%s\n%s\n",
copyright.c_str(),
this->m_program->get_description().c_str());
/*
Turn default for zombies off so that the help on how to
turn them off text won't show up.
This is safe to do since it's followed by a call to exit().
*/
for (struct my_option *optp= this->m_program->get_options_array();
optp->name; optp++)
{
if (!strcmp(optp->name, "secure-auth"))
{
optp->def_value= 0;
break;
}
}
this->m_program->short_usage();
print_defaults("my", load_default_groups);
my_print_help(this->m_program->get_options_array());
my_print_variables(this->m_program->get_options_array());
}

View File

@ -1,67 +0,0 @@
/*
Copyright (c) 2014, 2016, 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-1301 USA
*/
#ifndef HELP_OPTIONS_INCLUDED
#define HELP_OPTIONS_INCLUDED
#include "abstract_options_provider.h"
namespace Mysql{
namespace Tools{
namespace Base{
class Abtract_program;
namespace Options{
/**
Options provider providing --help option and handling usage printing.
*/
class Help_options : public Abstract_options_provider
{
public:
/**
Constructs new help options provider.
@param program Pointer to main program class, used to collect list of all
options available in program.
*/
Help_options(Base::Abstract_program *program);
/**
Creates all options that will be provided.
Implementation of Abstract_options_provider virtual method.
*/
virtual void create_options();
/**
Prints program usage message.
*/
virtual void print_usage();
private:
void help_callback(char* argument MY_ATTRIBUTE((unused)));
void version_callback(char* argument MY_ATTRIBUTE((unused)));
void print_version_line();
Abstract_program *m_program;
};
}
}
}
}
#endif

View File

@ -1,44 +0,0 @@
/*
Copyright (c) 2014, 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-1301 USA
*/
#ifndef I_CONNECTION_FACTORY_INCLUDED
#define I_CONNECTION_FACTORY_INCLUDED
#include "client_priv.h"
namespace Mysql{
namespace Tools{
namespace Base{
/**
Interface for classes that are capable of creating connection to
MySQL database server.
*/
class I_connection_factory
{
public:
/**
Provides new connection to MySQL database server.
*/
virtual MYSQL* create_connection()= 0;
};
}
}
}
#endif

View File

@ -1,25 +0,0 @@
/*
Copyright (c) 2014, 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-1301 USA
*/
#include "i_option.h"
using namespace Mysql::Tools::Base::Options;
uint32 I_option::last_optid = 256;
I_option::~I_option()
{}

View File

@ -1,70 +0,0 @@
/*
Copyright (c) 2014, 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-1301 USA
*/
#ifndef I_OPTION_INCLUDED
#define I_OPTION_INCLUDED
#include "my_getopt.h"
namespace Mysql{
namespace Tools{
namespace Base{
class Abstract_program;
namespace Options{
class I_option_changed_listener;
/**
Common interface for all program option objects.
*/
class I_option
{
public:
virtual ~I_option();
protected:
/**
Calls all option value callbacks.
To be used only from Abstract_program.
*/
virtual void call_callbacks(char* argument)= 0;
/**
Internal method to get my_getopt internal option data structure.
*/
virtual my_option get_my_option()= 0;
/**
Method to set listener on optid changed event.
For use from Abstract_options_provider class only.
*/
virtual void set_option_changed_listener(
I_option_changed_listener* listener)= 0;
static uint32 last_optid;
friend class Abstract_options_provider;
friend class Mysql::Tools::Base::Abstract_program;
};
}
}
}
}
#endif

View File

@ -1,55 +0,0 @@
/*
Copyright (c) 2014, 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-1301 USA
*/
#ifndef I_OPTION_CHANGED_LISTENER_INCLUDED
#define I_OPTION_CHANGED_LISTENER_INCLUDED
#include "i_option.h"
#include <string>
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Interface for listeners on some of option changes.
*/
class I_option_changed_listener
{
public:
/**
Called after specified option has name changed.
It is also called when new option is added, old_name is empty string in
that case.
*/
virtual void notify_option_name_changed(
I_option* source, std::string old_name)= 0;
/**
Called after specified option has option ID changed.
It is also called when new option is added, old_optid is 0 in that case.
*/
virtual void notify_option_optid_changed(
I_option* source, uint32 old_optid)= 0;
};
}
}
}
}
#endif

View File

@ -1,59 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef I_OPTIONS_PROVIDER_INCLUDED
#define I_OPTIONS_PROVIDER_INCLUDED
#include <vector>
#include <my_getopt.h>
#include "i_option_changed_listener.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Interface for basic options providers functionality.
*/
class I_options_provider : public I_option_changed_listener
{
public:
/**
Creates list of options provided by this provider.
@returns list of my_getopt internal option data structures.
*/
virtual std::vector<my_option> generate_options()= 0;
/**
Callback to be called when command-line options parsing have finished.
*/
virtual void options_parsed()= 0;
/**
Sets optional option changes listener to which all changes in all options
contained in this provider should be reported. This is used when this
provider is attached to another.
*/
virtual void set_option_changed_listener(
I_option_changed_listener* listener)= 0;
};
}
}
}
}
#endif

View File

@ -1,72 +0,0 @@
/*
Copyright (c) 2015, 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-1301 USA
*/
#include "message_data.h"
#include "sql_string.h"
#include "m_ctype.h"
using namespace Mysql::Tools::Base;
Message_data::Message_data(uint64 code, std::string message,
enum Message_type message_type)
: m_code(code),
m_message(message),
m_message_type(message_type)
{}
uint64 Message_data::get_code() const
{
return m_code;
}
std::string Message_data::get_message() const
{
return m_message;
}
Message_type Message_data::get_message_type() const
{
return m_message_type;
}
std::string Message_data::get_message_type_string() const
{
return message_type_strings[m_message_type];
}
void Message_data::print_error(std::string program_name) const
{
std::cerr << program_name << ": ["
<< get_message_type_string() << "] " << get_code()
<< ": " << get_message() << std::endl;
}
const char* Message_data::message_type_strings[]={
"INFORMATION",
"NOTE",
"WARNING",
"ERROR",
"Unknown message type"
};
const int Message_data::message_type_strings_count=
array_elements(Message_data::message_type_strings);
void Warning_data::print_error(std::string program_name) const
{
std::cerr << program_name << ": (non fatal) ["
<< get_message_type_string() << "] " << get_code()
<< ": " << get_message() << std::endl;
}

View File

@ -1,80 +0,0 @@
/*
Copyright (c) 2014,2015 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-1301 USA
*/
#ifndef MESSAGE_DATA_INCLUDED
#define MESSAGE_DATA_INCLUDED
#include <iostream>
#include <string>
#include "my_global.h"
namespace Mysql{
namespace Tools{
namespace Base{
enum Message_type
{
Message_type_info,
Message_type_note,
Message_type_warning,
Message_type_error,
Message_type_unknown
};
/**
Structure to represent message from server sent after executing query.
*/
class Message_data
{
public:
Message_data(uint64 code, std::string message, Message_type message_type);
virtual ~Message_data()
{ }
uint64 get_code() const;
std::string get_message() const;
Message_type get_message_type() const;
std::string get_message_type_string() const;
static const char* message_type_strings[];
static const int message_type_strings_count;
/**
Prints errors, warnings and notes to standard error.
*/
virtual void print_error(std::string program_name) const;
private:
uint64 m_code;
std::string m_message;
Message_type m_message_type;
};
class Warning_data: public Message_data
{
public:
Warning_data(uint64 code, std::string message, Message_type message_type):
Message_data(code, message, message_type)
{ }
void print_error(std::string program_name) const;
};
}
}
}
#endif

View File

@ -1,51 +0,0 @@
/*
Copyright (c) 2015, 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-1301 USA
*/
#include "mutex.h"
// We must use full boost::mutex name, because mutex is ambigious on Solaris.
my_boost::mutex::mutex()
{
native_mutex_init(&m_mutex, NULL);
}
my_boost::mutex::~mutex()
{
native_mutex_destroy(&m_mutex);
}
void my_boost::mutex::lock()
{
native_mutex_lock(&m_mutex);
}
bool my_boost::mutex::try_lock()
{
return native_mutex_trylock(&m_mutex) == 0;
}
void my_boost::mutex::unlock()
{
native_mutex_unlock(&m_mutex);
}
my_boost::mutex::scoped_lock::scoped_lock(my_boost::mutex& mutex_to_lock)
: m_mutex(mutex_to_lock)
{
m_mutex.lock();
}
my_boost::mutex::scoped_lock::~scoped_lock()
{
m_mutex.unlock();
}

View File

@ -1,53 +0,0 @@
/*
Copyright (c) 2015, 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-1301 USA
*/
#ifndef MUTEX_INCLUDED
#define MUTEX_INCLUDED
#include "my_global.h"
#include "my_thread.h"
#include "thr_mutex.h"
namespace my_boost{
class mutex
{
public:
mutex();
~mutex();
void lock();
bool try_lock();
void unlock();
class scoped_lock
{
public:
scoped_lock(my_boost::mutex& mutex_to_lock);
~scoped_lock();
private:
my_boost::mutex& m_mutex;
};
private:
native_mutex_t m_mutex;
};
}
#endif

View File

@ -1,257 +0,0 @@
/*
Copyright (c) 2014, 2018, 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-1301 USA
*/
#include <sstream>
#include <vector>
#include "abstract_options_provider.h"
#include "mysql_connection_options.h"
#include "abstract_program.h"
#include <mysys_err.h>
#include "caching_sha2_passwordopt-vars.h"
using Mysql::Tools::Base::Abstract_program;
using namespace Mysql::Tools::Base::Options;
using Mysql::Nullable;
using std::vector;
using std::string;
bool Mysql_connection_options::mysql_inited;
static void atexit_mysql_library_end()
{
mysql_library_end();
}
Mysql_connection_options::Mysql_connection_options(Abstract_program *program)
: m_ssl_options_provider(),
m_program(program),
m_protocol(0)
{
if (Mysql_connection_options::mysql_inited == false)
{
Mysql_connection_options::mysql_inited= true;
mysql_library_init(0, NULL, NULL);
atexit(atexit_mysql_library_end);
}
this->add_provider(&this->m_ssl_options_provider);
}
void Mysql_connection_options::create_options()
{
this->create_new_option(&this->m_bind_addr, "bind-address",
"IP address to bind to.");
this->create_new_option((char**)&charsets_dir, "character-sets-dir",
"Directory for character set files.");
this->create_new_option(&this->m_compress, "compress",
"Use compression in server/client protocol.")
->set_short_character('C');
this->create_new_option(&this->m_default_charset, "default-character-set",
"Set the default character set.")
->set_value("UTF8MB4");
this->create_new_option(&this->m_host, "host", "Connect to host.")
->set_short_character('h');
this->create_new_option(&this->m_max_allowed_packet, "max_allowed_packet",
"The maximum packet length to send to or receive from server.")
->set_minimum_value(4096)
->set_maximum_value(2U*1024*1024*1024)
->set_value_step(1024)
->set_value(24*1024*1024);
this->create_new_option(&this->m_net_buffer_length, "net_buffer_length",
"The buffer size for TCP/IP and socket communication.")
->set_minimum_value(4096)
->set_maximum_value(16*1024*1024)
->set_value_step(1024)
->set_value(1024*1024L-1024);
this->create_new_password_option(&this->m_password, "password",
"Password to use when connecting to server. If password is not given,"
" it's solicited on the tty.")
->set_short_character('p');
#ifdef _WIN32
this->create_new_option("pipe", "Use named pipes to connect to server.")
->set_short_character('W')
->add_callback(new Instance_callback<void, char*, Mysql_connection_options>
(this, &Mysql_connection_options::pipe_protocol_callback));
#endif
this->create_new_option(&this->m_mysql_port, "port",
"Port number to use for connection.")
->set_short_character('P');
this->create_new_option(&this->m_protocol_string, "protocol",
"The protocol to use for connection (tcp, socket, pipe, memory).")
->add_callback(new Instance_callback<void, char*, Mysql_connection_options>
(this, &Mysql_connection_options::protocol_callback));
#if defined (_WIN32) && !defined (EMBEDDED_LIBRARY)
this->create_new_option(&this->m_shared_memory_base_name,
"shared-memory-base-name", "Base name of shared memory.");
#endif
this->create_new_option(&this->m_mysql_unix_port, "socket",
"The socket file to use for connection.")
->set_short_character('S');
this->create_new_option(&this->m_secure_auth, "secure-auth",
"Refuse client connecting to server if it uses old (pre-4.1.1) "
"protocol. Deprecated. Always TRUE")
->add_callback(new Instance_callback<void, char*, Mysql_connection_options>
(this, &Mysql_connection_options::secure_auth_callback));
this->create_new_option(&this->m_user, "user",
"User for login if not current user.")
->set_short_character('u');
this->create_new_option(&this->m_plugin_dir, "plugin_dir",
"Directory for client-side plugins.");
this->create_new_option(&this->m_default_auth, "default_auth",
"Default authentication client-side plugin to use.");
this->create_new_option(&this->m_server_public_key, "server_public_key_path",
"Path to file containing server public key");
this->create_new_option(&this->m_get_server_public_key,
"get-server-public-key",
"Get public key from server");
}
MYSQL* Mysql_connection_options::create_connection()
{
MYSQL *connection= mysql_init(NULL);
if (this->m_compress)
mysql_options(connection, MYSQL_OPT_COMPRESS, NullS);
this->m_ssl_options_provider.apply_for_connection(connection);
if (this->m_protocol)
mysql_options(connection,MYSQL_OPT_PROTOCOL,
(char*)&this->m_protocol);
if (this->m_bind_addr.has_value())
mysql_options(connection,MYSQL_OPT_BIND,
this->m_bind_addr.value().c_str());
if (!this->m_secure_auth)
mysql_options(connection,MYSQL_SECURE_AUTH,
(char*)&this->m_secure_auth);
#if defined (_WIN32) && !defined (EMBEDDED_LIBRARY)
if (this->m_shared_memory_base_name.has_value())
mysql_options(connection,MYSQL_SHARED_MEMORY_BASE_NAME,
this->m_shared_memory_base_name.value().c_str());
#endif
if (this->m_default_charset.has_value())
{
mysql_options(connection, MYSQL_SET_CHARSET_NAME,
this->m_default_charset.value().c_str());
}
else
{
mysql_options(connection, MYSQL_SET_CHARSET_NAME, "utf8mb4");
}
if (this->m_plugin_dir.has_value())
mysql_options(connection, MYSQL_PLUGIN_DIR,
this->m_plugin_dir.value().c_str());
if (this->m_default_auth.has_value())
mysql_options(connection, MYSQL_DEFAULT_AUTH,
this->m_default_auth.value().c_str());
mysql_options(connection, MYSQL_OPT_CONNECT_ATTR_RESET, 0);
mysql_options4(connection, MYSQL_OPT_CONNECT_ATTR_ADD,
"program_name", this->m_program->get_name().c_str());
#if !defined(HAVE_YASSL)
if (this->m_server_public_key.has_value())
{
opt_server_public_key=
const_cast <char *> (this->m_server_public_key.value().c_str());
}
opt_get_server_public_key= this->m_get_server_public_key ? TRUE : FALSE;
#endif /* !HAVE_YASSL */
set_server_public_key(connection);
set_get_server_public_key_option(connection);
if (!mysql_real_connect(connection,
this->get_null_or_string(this->m_host),
this->get_null_or_string(this->m_user),
this->get_null_or_string(this->m_password), NULL,
this->m_mysql_port,
this->get_null_or_string(this->m_mysql_unix_port), 0))
{
this->db_error(connection, "while connecting to the MySQL server");
mysql_close(connection);
return NULL;
}
return connection;
}
CHARSET_INFO* Mysql_connection_options::get_current_charset() const
{
return m_default_charset.has_value()
? get_charset_by_csname(
m_default_charset.value().c_str(), MY_CS_PRIMARY, MYF(MY_WME))
: NULL;
}
void Mysql_connection_options::set_current_charset(CHARSET_INFO* charset)
{
m_default_charset= string(charset->csname);
}
const char* Mysql_connection_options::get_null_or_string(
Nullable<string>& maybe_string)
{
if (maybe_string.has_value())
{
return maybe_string.value().c_str();
}
else
{
return NULL;
}
}
#ifdef _WIN32
void Mysql_connection_options::pipe_protocol_callback(
char* not_used MY_ATTRIBUTE((unused)))
{
this->m_protocol= MYSQL_PROTOCOL_PIPE;
}
#endif
void Mysql_connection_options::protocol_callback(
char* not_used MY_ATTRIBUTE((unused)))
{
this->m_protocol=
find_type_or_exit(this->m_protocol_string.value().c_str(),
&sql_protocol_typelib, "protocol");
}
void Mysql_connection_options::secure_auth_callback(
char* not_used MY_ATTRIBUTE((unused)))
{
/* --secure-auth is a zombie option. */
if (!this->m_secure_auth)
{
my_printf_error(0, "--skip-secure-auth is not supported.\n", MYF(0));
exit(1);
}
else
CLIENT_WARN_DEPRECATED_NO_REPLACEMENT("--secure-auth");
}
void Mysql_connection_options::db_error(
MYSQL* connection, const char* when)
{
my_printf_error(0,"Got error: %d: %s %s", MYF(0),
mysql_errno(connection), mysql_error(connection), when);
this->m_program->error(Mysql::Tools::Base::Message_data(
EXIT_CANNOT_CONNECT_TO_SERVICE, "", Message_type_error));
}

View File

@ -1,149 +0,0 @@
/*
Copyright (c) 2014, 2018, 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-1301 USA
*/
#ifndef MYSQL_CONNECTION_OPTIONS_INCLUDED
#define MYSQL_CONNECTION_OPTIONS_INCLUDED
#include "client_priv.h"
#include <vector>
#include "composite_options_provider.h"
#include "abstract_program.h"
#include "i_connection_factory.h"
#include "nullable.h"
#include "base/mutex.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Options provider providing options to specify connection to MySQL server.
*/
class Mysql_connection_options
: public Composite_options_provider, I_connection_factory
{
private:
/**
Options provider enclosing options related to SSL settings of connection
to MySQL server.
*/
class Ssl_options : public Abstract_options_provider
{
public:
/**
Creates all options that will be provided.
Implementation of Abstract_options_provider virtual method.
*/
void create_options();
/**
Applies option values to MYSQL connection structure.
*/
void apply_for_connection(MYSQL* connection);
private:
Nullable<std::string> m_ssl_mode_string;
bool m_ssl;
bool m_ssl_verify_server_cert;
void ca_option_callback(char *argument);
void mode_option_callback(char *argument);
void use_ssl_option_callback(char *argument);
void ssl_verify_server_cert_callback(char *argument);
};
public:
/**
Constructs new MySQL server connection options provider. Calling this
function from multiple threads simultaneously is not thread safe.
@param program Pointer to main program class.
*/
Mysql_connection_options(Abstract_program *program);
/**
Creates all options that will be provided.
Implementation of Abstract_options_provider virtual method.
*/
void create_options();
/**
Provides new connection to MySQL database server based on option values.
Implementation of I_connection_factory interface.
*/
MYSQL* create_connection();
/**
Retrieves charset that will be used in new MySQL connections.. Can be NULL
if none was set explicitly.
*/
CHARSET_INFO* get_current_charset() const;
/**
Sets charset that will be used in new MySQL connections.
*/
void set_current_charset(CHARSET_INFO* charset);
private:
/**
Returns pointer to constant array containing specified string or NULL
value if string has length 0.
*/
const char* get_null_or_string(Nullable<std::string>& maybeString);
/**
Prints database connection error and exits program.
*/
void db_error(MYSQL* connection, const char* when);
#ifdef _WIN32
void pipe_protocol_callback(char* not_used MY_ATTRIBUTE((unused)));
#endif
void protocol_callback(char* not_used MY_ATTRIBUTE((unused)));
void secure_auth_callback(char* argument MY_ATTRIBUTE((unused)));
static bool mysql_inited;
Ssl_options m_ssl_options_provider;
Abstract_program *m_program;
Nullable<std::string> m_protocol_string;
uint32 m_protocol;
Nullable<std::string> m_bind_addr;
Nullable<std::string> m_host;
uint32 m_mysql_port;
Nullable<std::string> m_mysql_unix_port;
#if defined (_WIN32) && !defined (EMBEDDED_LIBRARY)
Nullable<std::string> m_shared_memory_base_name;
#endif
Nullable<std::string> m_default_auth;
bool m_secure_auth;
Nullable<std::string> m_plugin_dir;
uint32 m_net_buffer_length;
uint32 m_max_allowed_packet;
bool m_compress;
Nullable<std::string> m_user;
Nullable<std::string> m_password;
Nullable<std::string> m_default_charset;
Nullable<std::string> m_server_public_key;
bool m_get_server_public_key;
};
}
}
}
}
#endif

View File

@ -1,482 +0,0 @@
/*
Copyright (c) 2014, 2016, 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-1301 USA
*/
#include "mysql_query_runner.h"
#include "instance_callback.h"
#include "sql_string.h"
#include "m_ctype.h"
using namespace Mysql::Tools::Base;
using Mysql::I_callable;
using Mysql::Instance_callback;
using std::vector;
using std::string;
Mysql_query_runner::Mysql_query_runner(MYSQL* connection)
: m_is_processing(new my_boost::atomic<bool>(false)),
m_is_original_runner(true),
m_connection(connection)
{}
Mysql_query_runner::Mysql_query_runner(const Mysql_query_runner& source)
: m_result_callbacks(source.m_result_callbacks),
m_message_callbacks(source.m_message_callbacks),
m_is_processing(source.m_is_processing),
m_is_original_runner(false),
m_connection(source.m_connection)
{
}
Mysql_query_runner::~Mysql_query_runner()
{
if (m_is_original_runner)
{
for (std::vector<I_callable<int64, const Row&>*>::iterator
it= m_result_callbacks.begin(); it != m_result_callbacks.end(); ++it)
{
delete *it;
}
for (std::vector<I_callable<int64, const Message_data&>*>::iterator
it= m_message_callbacks.begin(); it != m_message_callbacks.end(); ++it)
{
delete *it;
}
delete m_is_processing;
mysql_close(this->m_connection);
}
}
Mysql_query_runner& Mysql_query_runner::add_result_callback(
I_callable<int64, const Row& >* result_callback)
{
m_result_callbacks.push_back(result_callback);
return *this;
}
Mysql_query_runner& Mysql_query_runner::add_message_callback(
I_callable<int64, const Message_data&>* message_callback)
{
m_message_callbacks.push_back(message_callback);
return *this;
}
MYSQL* Mysql_query_runner::get_low_level_connection() const
{
return m_connection;
}
int64 Mysql_query_runner::run_query_store(
std::string query, std::vector<const Row* >* result)
{
Store_result_helper helper(result);
return this->run_query(query, helper.get_result_callback());
}
int64 Mysql_query_runner::run_query(
std::string query,
I_callable<int64, const Row& >* result_callback)
{
Mysql_query_runner copy(*this);
copy.add_result_callback(result_callback);
int64 result= copy.run_query(query);
delete result_callback;
copy.m_result_callbacks.clear();
return result;
}
int64 Mysql_query_runner::run_query(string query)
{
bool expected_value= false;
/*
Try to change processing flag to true. If it's not false already, this
means that another query is in progress, which is not allowed.
*/
if (!m_is_processing->compare_exchange_strong(expected_value, true))
{
Message_data message(1, "Cannot execute more than one "
"MySQL query in parallel on single MySQL connection.",
Message_type_error);
return this->report_message(message);
}
uint64 result= this->run_query_unguarded(query);
*m_is_processing= false;
return result;
}
int64 Mysql_query_runner::run_query_unguarded(string query)
{
if (0 != mysql_query(m_connection, query.c_str()))
return this->report_mysql_error();
MYSQL_RES* results= mysql_use_result(m_connection);
if (results != NULL)
{
for (;;)
{
// Feed result callbacks with results.
MYSQL_ROW row= mysql_fetch_row(results);
if (row == NULL)
{
// NULL row indicates end of rows or error
if (mysql_errno(m_connection) == 0)
break;
else
{
mysql_free_result(results);
return this->report_mysql_error();
}
}
unsigned int columns= mysql_field_count(m_connection);
Row* processed_row= new Row(results, columns, row);
vector<I_callable<int64, const Row& >*>::reverse_iterator it;
for (it= m_result_callbacks.rbegin();
it != m_result_callbacks.rend();
it++)
{
int64 callback_result= (**it)(*processed_row);
if (callback_result != 0)
{
mysql_free_result(results);
return callback_result;
}
}
}
mysql_free_result(results);
}
else
{
if (mysql_errno(m_connection) != 0)
return this->report_mysql_error();
}
// Get all notes, warnings and errors of last query.
if (0 != mysql_query(m_connection, "SHOW WARNINGS") ||
NULL == (results= mysql_use_result(m_connection)))
{
this->report_mysql_error();
return 0;
}
// Process all errors and warnings.
for (;;)
{
// Feed message callbacks with results.
MYSQL_ROW row= mysql_fetch_row(results);
if (row == NULL)
{
// End of rows or an error.
if (mysql_errno(m_connection) != 0)
this->report_mysql_error();
break;
}
unsigned int columns = mysql_field_count(m_connection);
Row* processed_row= new Row(results, columns, row);
Warning_data warning(atoi((*processed_row)[1].c_str()),
(*processed_row)[2],
this->get_message_type_from_severity((*processed_row)[0]));
this->report_message(warning);
delete processed_row;
}
mysql_free_result(results);
return 0;
}
int64 Mysql_query_runner::report_mysql_error()
{
Message_data message(mysql_errno(m_connection), mysql_error(m_connection),
Message_type_error);
return this->report_message(message);
}
int64 Mysql_query_runner::report_message(Message_data &message)
{
vector<I_callable<int64, const Message_data&>*>::reverse_iterator it;
for (it= m_message_callbacks.rbegin();
it != m_message_callbacks.rend();
it++)
{
int64 callback_result= (**it)(message);
if (callback_result < 0)
{
return 0;
}
else if (callback_result != 0)
{
return callback_result;
}
}
return message.get_code();
}
enum Message_type Mysql_query_runner::get_message_type_from_severity(
string severity)
{
for (int i= 0; i+1 < Message_data::message_type_strings_count; i++)
{
String severity_string;
uint dummy_errors;
severity_string.copy(Message_data::message_type_strings[i],
strlen(Message_data::message_type_strings[i]),
&my_charset_latin1, m_connection->charset, &dummy_errors);
if (my_strcasecmp(m_connection->charset, severity.c_str(),
severity_string.c_ptr_safe()) == 0)
{
return (Message_type)i;
}
}
return Message_type_unknown;
}
Mysql_query_runner::Store_result_helper::Store_result_helper(
std::vector<const Row*>* result)
: m_result(result)
{}
I_callable<int64, const Mysql_query_runner::Row&>*
Mysql_query_runner::Store_result_helper::get_result_callback()
{
return new Instance_callback<
int64, const Row&, Store_result_helper>(
this, &Store_result_helper::result_callback);
}
int64 Mysql_query_runner::Store_result_helper::result_callback(const Row& row)
{
m_result->push_back(&row);
return 0;
}
void Mysql_query_runner::cleanup_result(const Mysql_query_runner::Row& result)
{
delete &result;
}
std::string Mysql_query_runner::escape_string(const std::string& original)
{
std::string res;
this->append_escape_string(&res, original);
return res;
}
void Mysql_query_runner::append_escape_string(
std::string* destination_string, const std::string& original)
{
this->append_escape_string(
destination_string, original.c_str(), original.size());
}
void Mysql_query_runner::append_escape_string(
std::string* destination_string, const char* original, size_t original_length)
{
size_t start_lenght= destination_string->size();
size_t required_capacity= start_lenght + original_length * 2 + 1;
destination_string->resize(required_capacity);
int length = mysql_real_escape_string_quote(
m_connection, &((*destination_string)[0]) + start_lenght, original,
(ulong)original_length, '"');
destination_string->resize(start_lenght + length);
}
void Mysql_query_runner::append_hex_string(
std::string* destination_string, const char* original, size_t original_length)
{
size_t start_lenght= destination_string->size();
size_t required_capacity= start_lenght + original_length * 2 + 1;
destination_string->resize(required_capacity);
int length = mysql_hex_string(
&((*destination_string)[0]) + start_lenght, original,
original_length);
destination_string->resize(start_lenght + length);
}
void Mysql_query_runner::cleanup_result(
std::vector<const Mysql_query_runner::Row*>* result)
{
for (vector<const Mysql_query_runner::Row*>::const_iterator
it= result->begin(); it != result->end(); it++)
{
delete *it;
}
result->clear();
}
Mysql_query_runner::Row::Row(MYSQL_RES* mysql_result_info, unsigned int column_count,
MYSQL_ROW row)
: m_buffer(NULL),
m_buffer_capacity(0),
m_buffer_size(0),
m_mysql_result_info(mysql_result_info)
{
size_t total_length= 0;
unsigned long* column_lengths= mysql_fetch_lengths(mysql_result_info);
for (unsigned int column = 0; column < column_count; column++)
total_length+= column_lengths[column] + 1;
this->reserve(column_count, total_length);
// first column always starts at 0 offset
m_buffer_starts.push_back(0);
for (unsigned int column = 0; column < column_count; column++)
{
this->push_back(row[column], column_lengths[column]);
}
}
Mysql_query_runner::Row::~Row()
{
if (m_buffer != NULL)
free(m_buffer);
}
std::string Mysql_query_runner::Row::operator[] (std::size_t index) const
{
std::size_t length;
const char* buffer= this->get_buffer(index, length);
return std::string(buffer, length);
}
void Mysql_query_runner::Row::push_back(char* buff, std::size_t length)
{
if (buff != NULL)
{
// Prepare buffer to be able to contain new data.
this->reserve(
m_buffer_starts.size(), m_buffer_size + length + 1);
// Copy data.
memcpy(&m_buffer[m_buffer_size], buff, length);
// Set new buffer length.
m_buffer_size += length + 1;
// Set sentinel NULL terminating character.
m_buffer[m_buffer_size - 1]= 0;
// Add new end marker.
m_buffer_starts.push_back(m_buffer_size);
}
else
{
// Prepare to be able to contain new data NULL value marker.
this->reserve(m_buffer_starts.size(), m_buffer_size);
// Add new end marker specifying NULL value.
m_buffer_starts.push_back(SIZE_T_MAX);
}
}
const char* Mysql_query_runner::Row::get_buffer(
std::size_t index, std::size_t& length) const
{
std::size_t start= SIZE_T_MAX;
for (std::size_t start_index= index; start == SIZE_T_MAX; start_index--)
{
start= m_buffer_starts[start_index];
}
std::size_t end= m_buffer_starts[index + 1];
length = (end - start - 1);
return &m_buffer[start];
}
std::size_t Mysql_query_runner::Row::size_of_element(std::size_t index) const
{
std::size_t res= 0;
if (!is_value_null(index))
this->get_buffer(index, res);
return res;
}
bool Mysql_query_runner::Row::is_value_null(std::size_t index) const
{
return m_buffer_starts[index + 1] == SIZE_T_MAX;
}
std::size_t Mysql_query_runner::Row::size() const
{
return m_buffer_starts.size() - 1;
}
void Mysql_query_runner::Row::reserve(
std::size_t strings, std::size_t buffer_size)
{
if (strings >= m_buffer_starts.capacity())
{
m_buffer_starts.reserve(strings + 1);
}
if (buffer_size > m_buffer_capacity)
{
m_buffer_capacity= buffer_size;
m_buffer= (char*)realloc(m_buffer, m_buffer_capacity);
}
}
Mysql_query_runner::Row::Iterator Mysql_query_runner::Row::begin() const
{
return Mysql_query_runner::Row::Iterator(*this, 0);
}
Mysql_query_runner::Row::Iterator Mysql_query_runner::Row::end() const
{
return Mysql_query_runner::Row::Iterator(*this, m_buffer_starts.size() - 1);
}
MYSQL_RES* Mysql_query_runner::Row::get_mysql_result_info() const
{
return m_mysql_result_info;
}
Mysql_query_runner::Row::Iterator::Iterator(const Row& row, std::size_t index)
: m_row(row),
m_index(index)
{}
bool Mysql_query_runner::Row::Iterator::is_value_null()
{
return m_row.is_value_null(m_index);
}
std::string Mysql_query_runner::Row::Iterator::operator *()
{
return m_row[m_index];
}
void Mysql_query_runner::Row::Iterator::operator ++()
{
m_index++;
}
bool Mysql_query_runner::Row::Iterator::operator ==(const Iterator& other)
{
return &m_row == &other.m_row && m_index == other.m_index;
}
bool Mysql_query_runner::Row::Iterator::operator !=(const Iterator& other)
{
return !(*this == other);
}

View File

@ -1,232 +0,0 @@
/*
Copyright (c) 2014, 2016, 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-1301 USA
*/
#ifndef MYSQL_QUERY_RUNNER_INCLUDED
#define MYSQL_QUERY_RUNNER_INCLUDED
#include "my_global.h"
#include "mysql.h"
#include "mutex.h"
#include "i_callable.h"
#include "message_data.h"
#include "atomic.h"
#include <algorithm>
#include <string>
#include <vector>
namespace Mysql{
namespace Tools{
namespace Base{
/**
Helper class to run SQL query on existing MySQL database server connection,
receive all data and all errors, warnings and notes returned during query
execution. All acquired information is passed to set of callbacks to make
data flows more customizable.
*/
class Mysql_query_runner
{
public:
class Row;
/**
Standard constructor based on MySQL connection.
*/
Mysql_query_runner(MYSQL* connection);
/**
Copy constructor.
*/
Mysql_query_runner(const Mysql_query_runner& source);
~Mysql_query_runner();
/**
Adds new callback to be called on every result row of query.
If callback return value other than 0 then query execution, passing
current row to other callbacks and error messages processing, and
Mysql_query_runner::run_query() will return value returned from this
callback.
Callbacks are called in reverse order of addition, i.e. newest are first.
*/
Mysql_query_runner& add_result_callback(
I_callable<int64, const Row&>* result_callback);
/**
Adds new callback to be called on every message after query execution,
this includes errors, warnings and other notes. Return value from callback
of 0 will lead to next handler being called, positive number return value
will cause Mysql_query_runner::run_query() will return immediately this
value and negative number will continue query execution and other messages
processing, but will not pass current message to rest of callbacks.
Callbacks are called in reverse order of addition, i.e. newest are first.
*/
Mysql_query_runner& add_message_callback(
I_callable<int64, const Message_data&>* message_callback);
/**
Runs specified query and processes result rows and messages to callbacks.
*/
int64 run_query(std::string query);
/**
Runs specified query, fills result vector with processed result rows
and processes messages to callbacks.
*/
int64 run_query_store(
std::string query, std::vector<const Row*>* result);
/**
Runs specified query with result callback specified. Does not add specified
callback to list of callbacks, next queries will not process rows to this
callback.
*/
int64 run_query(
std::string query,
I_callable<int64, const Row&>* result_callback);
/**
Returns escaped copy of string to use in queries.
*/
std::string escape_string(const std::string& original);
/**
Escapes specified input string and appends it escaped to destination
string.
*/
void append_escape_string(std::string* destination_string,
const std::string& original);
/**
Escapes specified input string specified as characters buffer and its size,
and appends it escaped to destination string.
*/
void append_escape_string(std::string* destination_string,
const char* original, size_t original_length);
/**
Converts to HEX specified input string specified as characters buffer and
its size, and appends it escaped to destination string.
*/
void append_hex_string(std::string* destination_string,
const char* original, size_t original_length);
/**
Empties memory used by result strings.
*/
static void cleanup_result(const Row& result);
/**
Empties memory used by result strings.
*/
static void cleanup_result(std::vector<const Row*>* result);
MYSQL* get_low_level_connection() const;
class Row
{
public:
class Iterator;
Row(MYSQL_RES* mysql_result_info, unsigned int column_count,
MYSQL_ROW row);
~Row();
std::string operator[] (std::size_t index) const;
void push_back(char* buff, std::size_t length);
const char* get_buffer(std::size_t index, std::size_t& length) const;
std::size_t size_of_element(std::size_t index) const;
bool is_value_null(std::size_t index) const;
std::size_t size() const;
Iterator begin() const;
Iterator end() const;
MYSQL_RES* get_mysql_result_info() const;
class Iterator
{
public:
Iterator(const Row& row, std::size_t index);
bool is_value_null();
std::string operator *();
void operator ++();
bool operator ==(const Iterator& other);
bool operator !=(const Iterator& other);
private:
const Row& m_row;
std::size_t m_index;
};
private:
void reserve(std::size_t strings, std::size_t buffer_size);
// Represents table row as a string
char* m_buffer;
// Represents offsets to each column in m_buffer
std::vector<std::size_t> m_buffer_starts;
// Total buffer size
std::size_t m_buffer_capacity;
// Actual buffer size
std::size_t m_buffer_size;
MYSQL_RES* m_mysql_result_info;
};
private:
/**
Runs specified query and process result rows and messages to callbacks.
Does not check for multiple queries being executed in parallel.
*/
int64 run_query_unguarded(std::string query);
/**
Creates error message from mysql_errno and mysql_error and passes it to
callbacks.
*/
int64 report_mysql_error();
/**
Creates error message from mysql_errno and mysql_error and passes it to
callbacks.
*/
int64 report_message(Message_data &message);
/**
Returns parsed Message_type from given MySQL severity string.
*/
Message_type get_message_type_from_severity(std::string severity);
class Store_result_helper
{
public:
Store_result_helper(std::vector<const Row*>* result);
I_callable<int64, const Row&>* get_result_callback();
private:
int64 result_callback(const Row& row);
std::vector<const Row*>* m_result;
};
std::vector<I_callable<int64, const Row&>*>
m_result_callbacks;
std::vector<I_callable<int64, const Message_data&>*> m_message_callbacks;
/**
Indicates if there is query currently executed. Only one query can be
executed in specified time moment.
*/
my_boost::atomic<bool>* m_is_processing;
/**
Indicates if this is original runner or a copy. In case of original the
cleanup is performed on destruction.
*/
bool m_is_original_runner;
MYSQL* m_connection;
};
}
}
}
#endif

View File

@ -1,174 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef NUMBER_OPTION_INCLUDED
#define NUMBER_OPTION_INCLUDED
#include <string>
#include "abstract_integer_number_option.h"
ulonglong getopt_double2ulonglong(double v);
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Template class for all number options.
*/
template<typename T_value> class Number_option
: public Abstract_integer_number_option<Number_option<T_value>, T_value>
{
private:
/**
This class cannot be instanced. It is only as template for specialized
implementations.
*/
Number_option();
};
template<typename T_value> Number_option<T_value>::Number_option()
{}
/**
32-bit signed number option.
*/
template<> class Number_option<int32>
: public Abstract_integer_number_option<Number_option<int32>, int32>
{
public:
/**
Constructs new 32-bit signed number option.
@param value Pointer to int32 object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Number_option(int32* value, std::string name, std::string description)
: Abstract_integer_number_option<Number_option<int32>, int32>(
value, GET_INT32, name, description)
{}
};
/**
32-bit unsigned number option.
*/
template<> class Number_option<uint32>
: public Abstract_integer_number_option<Number_option<uint32>, uint32>
{
public:
/**
Constructs new 32-bit unsigned number option.
@param value Pointer to uint32 object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Number_option(uint32* value, std::string name, std::string description)
: Abstract_integer_number_option<Number_option<uint32>, uint32>(
value, GET_UINT32, name, description)
{}
};
/**
64-bit signed number option.
*/
template<> class Number_option<int64>
: public Abstract_integer_number_option<Number_option<int64>, int64>
{
public:
/**
Constructs new 64-bit signed number option.
@param value Pointer to int64 object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Number_option(int64* value, std::string name, std::string description)
: Abstract_integer_number_option<Number_option<int64>, int64>(
value, GET_LL, name, description)
{}
};
/**
64-bit unsigned number option.
*/
template<> class Number_option<uint64>
: public Abstract_integer_number_option<Number_option<uint64>, uint64>
{
public:
/**
Constructs new 64-bit unsigned number option.
@param value Pointer to uint64 object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Number_option(uint64* value, std::string name, std::string description)
: Abstract_integer_number_option<Number_option<uint64>, uint64>(
value, GET_ULL, name, description)
{}
};
/**
Double precision floating-point number option.
*/
template<> class Number_option<double>
: public Abstract_number_option<Number_option<double>, double>
{
public:
/**
Constructs new floating-point number option.
@param value Pointer to double object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Number_option(double* value, std::string name, std::string description)
: Abstract_number_option<Number_option<double>, double>(
value, GET_DOUBLE, name, description,
getopt_double2ulonglong((double)*value))
{}
/**
Sets minimum value boundary for option value. Smaller values passed as
option value will be changed to this minimum value.
*/
virtual Number_option<double>* set_minimum_value(double minimum)
{
this->m_option_structure.min_value= getopt_double2ulonglong(minimum);
return this;
}
/**
Sets maximum value boundary for option value. Greater values passed as
option value will be changed to this maximum value.
*/
virtual Number_option<double>* set_maximum_value(double maximum)
{
this->m_option_structure.max_value= getopt_double2ulonglong(maximum);
return this;
}
};
}
}
}
}
#endif

View File

@ -1,69 +0,0 @@
/*
Copyright (c) 2001, 2016, 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-1301 USA
*/
#include "client_priv.h"
#include "password_option.h"
using namespace Mysql::Tools::Base::Options;
using Mysql::Nullable;
using std::string;
Password_option::Password_option(Nullable<string>* value, string name, string description)
: Abstract_string_option<Password_option>(value, GET_PASSWORD, name, description)
{
this->value_optional()
->add_callback(
new Instance_callback<void, char*, Password_option>(
this, &Password_option::password_callback));
}
void Password_option::password_callback(char* argument)
{
if (argument == ::disabled_my_option)
{
// This prevents ::disabled_my_option being overriden later in this function.
argument= (char*) "";
}
if (argument != NULL)
{
/*
Destroy argument value, this modifies part of argv passed to main
routine. This makes command line on linux changed, so no user can see
password shortly after program starts. This works for example for
/proc/<pid>/cmdline file and ps tool.
*/
for (char* pos= argument; *pos != 0; pos++)
{
*pos= '*';
}
/*
This cuts argument length to hide password length on linux commandline
showing tools.
*/
if (*argument)
argument[1]= 0;
}
else
{
char *password= ::get_tty_password(NULL);
*this->m_destination_value = Nullable<string>(password);
my_free(password);
}
}

View File

@ -1,57 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef PASSWORD_OPTION_INCLUDED
#define PASSWORD_OPTION_INCLUDED
#include <string>
#include <my_getopt.h>
#include "abstract_string_option.h"
#include "nullable.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
String value option to handle passwords. Removes password from command line
on UNIX systems to prevent password to be seen when listing processes.
*/
class Password_option : public Abstract_string_option<Password_option>
{
public:
/**
Constructs new password option.
@param value Pointer to string object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Password_option(
Nullable<std::string>* value, std::string name, std::string description);
private:
void password_callback(char*);
};
}
}
}
}
#endif

View File

@ -1,80 +0,0 @@
/*
Copyright (c) 2014, 2015, 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-1301 USA
*/
#include "show_variable_query_extractor.h"
#include "instance_callback.h"
using namespace Mysql::Tools::Base;
using std::string;
using std::vector;
Show_variable_query_extractor::Show_variable_query_extractor()
: m_exists(false)
{}
int64 Show_variable_query_extractor::extract_variable(
const Mysql_query_runner::Row& result_row)
{
this->m_extracted_variable= result_row[0];
this->m_exists= true;
Mysql_query_runner::cleanup_result(result_row);
return 0;
}
int64 Show_variable_query_extractor::get_variable_value(
Mysql_query_runner* query_runner_to_copy,
string variable, string& value, bool& exists)
{
Show_variable_query_extractor extractor;
Mysql_query_runner query_runner_to_use(*query_runner_to_copy);
Instance_callback<int64, const Mysql_query_runner::Row&,
Show_variable_query_extractor>
result_cb(&extractor, &Show_variable_query_extractor::extract_variable);
query_runner_to_use.add_result_callback(&result_cb);
/*
Note: Because MySQL uses the C escape syntax in strings (for example, '\n'
to represent newline), you must double any '\' that you use in your LIKE
strings. For example, to search for '\n', specify it as '\\n'.To search for
'\', specify it as '\\\\' (the backslashes are stripped once by the parser
and another time when the pattern match is done, leaving a single backslash
to be matched).
Example: "t\1" = > "t\\\\1"
*/
string quoted_variable;
for (size_t i= 0; i < variable.size(); i++)
{
if (variable[i] == '\\')
{
quoted_variable.append(3, '\\');
}
else if (variable[i] == '\'' || variable[i] == '_' || variable[i] == '%')
{
quoted_variable+= '\\';
}
quoted_variable+= variable[i];
}
query_runner_to_use.run_query("SELECT @@global." + quoted_variable);
value= extractor.m_extracted_variable;
exists= extractor.m_exists;
return 0;
}

View File

@ -1,72 +0,0 @@
/*
Copyright (c) 2014, 2015, 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-1301 USA
*/
#ifndef SHOW_VARIABLE_QUERY_EXTRACTOR_INCLUDED
#define SHOW_VARIABLE_QUERY_EXTRACTOR_INCLUDED
#include "i_callable.h"
#include "base/mysql_query_runner.h"
#include "mysql.h"
#include<string>
#include<vector>
namespace Mysql{
namespace Tools{
namespace Base{
/**
Extracts the value of server variable.
*/
class Show_variable_query_extractor
{
public:
/**
Extract the value of server variable.
@param[in] query_runner MySQL query runner to use.
@param[in] variable Name of variable to get value of.
@param[out] value reference to String to store variable value to.
@param[out] value reference to bool to store if variable was found.
@return nonzero if error was encountered.
*/
static int64 get_variable_value(
Mysql_query_runner* query_runner, std::string variable,
std::string& value, bool& exists);
private:
Show_variable_query_extractor();
/**
Result row callback to be used in query runner.
*/
int64 extract_variable(const Mysql_query_runner::Row& result_row);
/**
Temporary placeholder for extracted value.
*/
std::string m_extracted_variable;
/**
Temporary placeholder for value received flag.
*/
bool m_exists;
};
}
}
}
#endif

View File

@ -1,27 +0,0 @@
/*
Copyright (c) 2001, 2015, 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-1301 USA
*/
#include "simple_option.h"
using namespace Mysql::Tools::Base::Options;
using std::string;
Simple_option::Simple_option(string name, string description)
: Abstract_option<Simple_option>(NULL, GET_NO_ARG, name, description, 0)
{
this->m_option_structure.arg_type= NO_ARG;
}

View File

@ -1,50 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef SIMPLE_OPTION_INCLUDED
#define SIMPLE_OPTION_INCLUDED
#include <string>
#include <my_getopt.h>
#include "abstract_option.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
Simple boolean option. Does not accept value.
*/
class Simple_option : public Abstract_option<Simple_option>
{
public:
/**
Constructs new simple option.
@param name Name of option. It is used in command-line option name as
--name.
@param desription Description of option to be printed in --help.
*/
Simple_option(std::string name, std::string description);
};
}
}
}
}
#endif

View File

@ -1,126 +0,0 @@
/*
Copyright (c) 2015, 2016, 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-1301 USA
*/
#include "client_priv.h"
#include <vector>
#include "mysql_connection_options.h"
#include "sslopt-vars.h"
#include "instance_callback.h"
using namespace Mysql::Tools::Base::Options;
void Mysql_connection_options::Ssl_options::create_options()
{
Instance_callback<void, char*, Mysql_connection_options::Ssl_options>
callback(this, &Mysql_connection_options::Ssl_options::mode_option_callback);
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
this->create_new_option(&this->m_ssl_mode_string, "ssl-mode",
"SSL connection mode.")
#ifdef MYSQL_CLIENT
->add_callback(new Instance_callback<void, char*,
Mysql_connection_options::Ssl_options>(
this, &Mysql_connection_options::Ssl_options::mode_option_callback))
#endif
;
this->create_new_option(&::opt_ssl_ca, "ssl-ca", "CA file in PEM format.")
->add_callback(new Instance_callback<void, char*,
Mysql_connection_options::Ssl_options>(
this, &Mysql_connection_options::Ssl_options::ca_option_callback));
this->create_new_option(&::opt_ssl_capath, "ssl-capath", "CA directory.")
->add_callback(new Instance_callback<void, char*,
Mysql_connection_options::Ssl_options>(
this, &Mysql_connection_options::Ssl_options::ca_option_callback));
this->create_new_option(&::opt_ssl_cert, "ssl-cert",
"X509 cert in PEM format.");
this->create_new_option(&::opt_ssl_cipher, "ssl-cipher",
"SSL cipher to use.");
this->create_new_option(&::opt_ssl_key, "ssl-key",
"X509 key in PEM format.");
this->create_new_option(&::opt_ssl_crl, "ssl-crl",
"Certificate revocation list.");
this->create_new_option(&::opt_ssl_crlpath, "ssl-crlpath",
"Certificate revocation list path.");
this->create_new_option(&::opt_tls_version, "tls-version",
"TLS version to use.");
#ifdef MYSQL_CLIENT
this->create_new_option(&this->m_ssl, "ssl",
"Deprecated. Use ssl-mode instead.")
->add_callback(new Instance_callback<void, char*,
Mysql_connection_options::Ssl_options>(
this, &Mysql_connection_options::Ssl_options::use_ssl_option_callback));
this->create_new_option(&this->m_ssl_verify_server_cert, "ssl-verify-server-cert",
"Deprecated. Use ssl-mode=VERIFY_IDENTITY instead.")
->add_callback(new Instance_callback<void, char*,
Mysql_connection_options::Ssl_options>(
this,
&Mysql_connection_options::Ssl_options::ssl_verify_server_cert_callback));
#endif
#endif /* HAVE_OPENSSL */
}
void Mysql_connection_options::Ssl_options::ca_option_callback(
char *argument MY_ATTRIBUTE((unused)))
{
if (!ssl_mode_set_explicitly)
::opt_ssl_mode= SSL_MODE_VERIFY_CA;
}
void Mysql_connection_options::Ssl_options::mode_option_callback(
char *argument)
{
::opt_ssl_mode= find_type_or_exit(argument, &ssl_mode_typelib, "ssl-mode");
ssl_mode_set_explicitly= true;
}
void Mysql_connection_options::Ssl_options::apply_for_connection(
MYSQL* connection)
{
SSL_SET_OPTIONS(connection);
}
void Mysql_connection_options::Ssl_options::use_ssl_option_callback(
char *argument MY_ATTRIBUTE((unused)))
{
CLIENT_WARN_DEPRECATED("--ssl", "--ssl-mode");
if (!opt_use_ssl_arg)
opt_ssl_mode= SSL_MODE_DISABLED;
else if (opt_ssl_mode < SSL_MODE_REQUIRED)
opt_ssl_mode= SSL_MODE_REQUIRED;
}
void Mysql_connection_options::Ssl_options::ssl_verify_server_cert_callback(
char *argument MY_ATTRIBUTE((unused)))
{
CLIENT_WARN_DEPRECATED("--ssl-verify-server-cert",
"--ssl-mode=VERIFY_IDENTITY");
if (!opt_ssl_verify_server_cert_arg)
{
if (opt_ssl_mode >= SSL_MODE_VERIFY_IDENTITY)
opt_ssl_mode= SSL_MODE_VERIFY_CA;
}
else
opt_ssl_mode= SSL_MODE_VERIFY_IDENTITY;
}

View File

@ -1,26 +0,0 @@
/*
Copyright (c) 2001, 2015, 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-1301 USA
*/
#include "string_option.h"
using namespace Mysql::Tools::Base::Options;
using Mysql::Nullable;
using std::string;
String_option::String_option(Nullable<string>* value, string name, string description)
: Abstract_string_option<String_option>(value, GET_STR, name, description)
{}

View File

@ -1,53 +0,0 @@
/*
Copyright (c) 2014, 2015 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-1301 USA
*/
#ifndef STRING_OPTION_INCLUDED
#define STRING_OPTION_INCLUDED
#include <string>
#include <my_getopt.h>
#include "abstract_string_option.h"
#include "nullable.h"
namespace Mysql{
namespace Tools{
namespace Base{
namespace Options{
/**
String value option.
*/
class String_option : public Abstract_string_option<String_option>
{
public:
/**
Constructs new string option.
@param value Pointer to string object to receive option value.
@param name Name of option. It is used in command line option name as
--name.
@param desription Description of option to be printed in --help.
*/
String_option(
Nullable<std::string>* value, std::string name, std::string description);
};
}
}
}
}
#endif

View File

@ -1,578 +0,0 @@
/*
Copyright (c) 2001, 2018, 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-1301 USA
*/
#define CHECK_VERSION "2.5.1"
#include "client_priv.h"
#include "my_default.h"
#include "mysqlcheck.h"
#include <m_ctype.h>
#include <mysql_version.h>
#include <mysqld_error.h>
#include <sslopt-vars.h>
#include <caching_sha2_passwordopt-vars.h>
#include <welcome_copyright_notice.h> /* ORACLE_WELCOME_COPYRIGHT_NOTICE */
using namespace Mysql::Tools::Check;
using std::string;
using std::vector;
/* Exit codes */
#define EX_USAGE 1
#define EX_MYSQLERR 2
static MYSQL mysql_connection, *sock = 0;
static my_bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0,
opt_compress = 0, opt_databases = 0, opt_fast = 0,
opt_medium_check = 0, opt_quick = 0, opt_all_in_1 = 0,
opt_silent = 0, opt_auto_repair = 0, ignore_errors = 0,
tty_password= 0, opt_frm= 0, debug_info_flag= 0, debug_check_flag= 0,
opt_fix_table_names= 0, opt_fix_db_names= 0, opt_upgrade= 0,
opt_write_binlog= 1, opt_secure_auth=TRUE;
static uint verbose = 0, opt_mysql_port=0;
static uint opt_enable_cleartext_plugin= 0;
static my_bool using_opt_enable_cleartext_plugin= 0;
static int my_end_arg;
static char * opt_mysql_unix_port = 0;
static char *opt_password = 0, *current_user = 0,
*default_charset= 0, *current_host= 0;
static char *opt_plugin_dir= 0, *opt_default_auth= 0;
static int first_error = 0;
static const char *opt_skip_database= "";
#if defined (_WIN32) && !defined (EMBEDDED_LIBRARY)
static char *shared_memory_base_name=0;
#endif
static uint opt_protocol=0;
static char *opt_bind_addr = NULL;
static struct my_option my_long_options[] =
{
{"all-databases", 'A',
"Check all the databases. This is the same as --databases with all databases selected.",
&opt_alldbs, &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
0, 0},
{"analyze", 'a', "Analyze given tables.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
0, 0, 0, 0},
{"all-in-1", '1',
"Instead of issuing one query for each table, use one query per database, naming all tables in the database in a comma-separated list.",
&opt_all_in_1, &opt_all_in_1, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0},
{"auto-repair", OPT_AUTO_REPAIR,
"If a checked table is corrupted, automatically fix it. Repairing will be done after all tables have been checked, if corrupted ones were found.",
&opt_auto_repair, &opt_auto_repair, 0, GET_BOOL, NO_ARG, 0,
0, 0, 0, 0, 0},
{"bind-address", 0, "IP address to bind to.",
(uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"character-sets-dir", OPT_CHARSETS_DIR,
"Directory for character set files.", &charsets_dir,
&charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"check", 'c', "Check table for errors.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
0, 0, 0, 0},
{"check-only-changed", 'C',
"Check only tables that have changed since last check or haven't been closed properly.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"check-upgrade", 'g',
"Check tables for version-dependent changes. May be used with --auto-repair to correct tables requiring version-dependent updates.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"compress", OPT_COMPRESS, "Use compression in server/client protocol.",
&opt_compress, &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0},
{"databases", 'B',
"Check several databases. Note the difference in usage; in this case no tables are given. All name arguments are regarded as database names.",
&opt_databases, &opt_databases, 0, GET_BOOL, NO_ARG,
0, 0, 0, 0, 0, 0},
#ifdef DBUG_OFF
{"debug", '#', "This is a non-debug version. Catch this and exit.",
0, 0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"debug-check", OPT_DEBUG_CHECK, "This is a non-debug version. Catch this and exit.",
0, 0, 0, GET_DISABLED, NO_ARG, 0, 0, 0, 0, 0, 0},
{"debug-info", OPT_DEBUG_INFO, "This is a non-debug version. Catch this and exit.",
0, 0, 0, GET_DISABLED, NO_ARG, 0, 0, 0, 0, 0, 0},
#else
{"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.",
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
&debug_check_flag, &debug_check_flag, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
&debug_info_flag, &debug_info_flag,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"default-character-set", OPT_DEFAULT_CHARSET,
"Set the default character set.", &default_charset,
&default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"default_auth", OPT_DEFAULT_AUTH,
"Default authentication client-side plugin to use.",
&opt_default_auth, &opt_default_auth, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"enable_cleartext_plugin", OPT_ENABLE_CLEARTEXT_PLUGIN,
"Enable/disable the clear text authentication plugin.",
&opt_enable_cleartext_plugin, &opt_enable_cleartext_plugin,
0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"fast",'F', "Check only tables that haven't been closed properly.",
&opt_fast, &opt_fast, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
0},
{"fix-db-names", OPT_FIX_DB_NAMES, "Fix database names.",
&opt_fix_db_names, &opt_fix_db_names,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"fix-table-names", OPT_FIX_TABLE_NAMES, "Fix table names.",
&opt_fix_table_names, &opt_fix_table_names,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"force", 'f', "Continue even if we get an SQL error.",
&ignore_errors, &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
0, 0, 0, 0},
{"extended", 'e',
"If you are using this option with CHECK TABLE, it will ensure that the table is 100 percent consistent, but will take a long time. If you are using this option with REPAIR TABLE, it will force using old slow repair with keycache method, instead of much faster repair by sorting.",
&opt_extended, &opt_extended, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0},
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"host",'h', "Connect to host.", &current_host,
&current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"medium-check", 'm',
"Faster than extended-check, but only finds 99.99 percent of all errors. Should be good enough for most cases.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"write-binlog", OPT_WRITE_BINLOG,
"Log ANALYZE, OPTIMIZE and REPAIR TABLE commands. Use --skip-write-binlog "
"when commands should not be sent to replication slaves.",
&opt_write_binlog, &opt_write_binlog, 0, GET_BOOL, NO_ARG,
1, 0, 0, 0, 0, 0},
{"secure-auth", OPT_SECURE_AUTH, "Refuse client connecting to server if it"
" uses old (pre-4.1.1) protocol. Deprecated. Always TRUE",
&opt_secure_auth, &opt_secure_auth, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"optimize", 'o', "Optimize table.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
0, 0},
{"password", 'p',
"Password to use when connecting to server. If password is not given, it's solicited on the tty.",
0, 0, 0, GET_PASSWORD, OPT_ARG, 0, 0, 0, 0, 0, 0},
#ifdef _WIN32
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"plugin_dir", OPT_PLUGIN_DIR, "Directory for client-side plugins.",
&opt_plugin_dir, &opt_plugin_dir, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"port", 'P', "Port number to use for connection or 0 for default to, in "
"order of preference, my.cnf, $MYSQL_TCP_PORT, "
#if MYSQL_PORT_DEFAULT == 0
"/etc/services, "
#endif
"built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
&opt_mysql_port, &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
0},
{"protocol", OPT_MYSQL_PROTOCOL, "The protocol to use for connection (tcp, socket, pipe, memory).",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"quick", 'q',
"If you are using this option with CHECK TABLE, it prevents the check from scanning the rows to check for wrong links. This is the fastest check. If you are using this option with REPAIR TABLE, it will try to repair only the index tree. This is the fastest repair method for a table.",
&opt_quick, &opt_quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
0},
{"repair", 'r',
"Can fix almost anything except unique keys that aren't unique.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
#if defined (_WIN32) && !defined (EMBEDDED_LIBRARY)
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
"Base name of shared memory.", &shared_memory_base_name, &shared_memory_base_name,
0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"silent", 's', "Print only error messages.", &opt_silent,
&opt_silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"skip_database", 0, "Don't process the database specified as argument",
&opt_skip_database, &opt_skip_database, 0, GET_STR, REQUIRED_ARG,
0, 0, 0, 0, 0, 0},
{"socket", 'S', "The socket file to use for connection.",
&opt_mysql_unix_port, &opt_mysql_unix_port, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#include <sslopt-longopts.h>
#include <caching_sha2_passwordopt-longopts.h>
{"tables", OPT_TABLES, "Overrides option --databases (-B).", 0, 0, 0,
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"use-frm", OPT_FRM,
"When used with REPAIR, get table structure from .frm file, so the table can be repaired even if .MYI header is corrupted.",
&opt_frm, &opt_frm, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
0},
{"user", 'u', "User for login if not current user.", &current_user,
&current_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", 'v', "Print info about the various stages.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
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}
};
static const char *load_default_groups[] = { "mysqlcheck", "client", 0 };
static void print_version(void);
static void usage(void);
static int get_options(int *argc, char ***argv);
static int dbConnect(char *host, char *user,char *passwd);
static void dbDisconnect(char *host);
static void DBerror(MYSQL *mysql, string when);
static void safe_exit(int error);
static int what_to_do = 0;
static void print_version(void)
{
printf("%s Ver %s Distrib %s, for %s (%s)\n", my_progname, CHECK_VERSION,
MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
} /* print_version */
static void usage(void)
{
print_version();
puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000"));
puts("This program can be used to CHECK (-c, -m, -C), REPAIR (-r), ANALYZE (-a),");
puts("or OPTIMIZE (-o) tables. Some of the options (like -e or -q) can be");
puts("used at the same time. Not all options are supported by all storage engines.");
puts("Please consult the MySQL manual for latest information about the");
puts("above. The options -c, -r, -a, and -o are exclusive to each other, which");
puts("means that the last option will be used, if several was specified.\n");
puts("The option -c will be used by default, if none was specified. You");
puts("can change the default behavior by making a symbolic link, or");
puts("copying this file somewhere with another name, the alternatives are:");
puts("mysqlrepair: The default option will be -r");
puts("mysqlanalyze: The default option will be -a");
puts("mysqloptimize: The default option will be -o\n");
printf("Usage: %s [OPTIONS] database [tables]\n", my_progname);
printf("OR %s [OPTIONS] --databases DB1 [DB2 DB3...]\n",
my_progname);
printf("OR %s [OPTIONS] --all-databases\n", my_progname);
print_defaults("my", load_default_groups);
/*
Turn default for zombies off so that the help on how to
turn them off text won't show up.
This is safe to do since it's followed by a call to exit().
*/
for (struct my_option *optp= my_long_options; optp->name; optp++)
{
if (optp->id == OPT_SECURE_AUTH)
{
optp->def_value= 0;
break;
}
}
my_print_help(my_long_options);
my_print_variables(my_long_options);
} /* usage */
static my_bool
get_one_option(int optid, const struct my_option *opt MY_ATTRIBUTE((unused)),
char *argument)
{
int orig_what_to_do= what_to_do;
switch(optid) {
case 'a':
what_to_do = DO_ANALYZE;
break;
case 'c':
what_to_do = DO_CHECK;
break;
case 'C':
what_to_do = DO_CHECK;
opt_check_only_changed = 1;
break;
case 'I': /* Fall through */
case '?':
usage();
exit(0);
case 'm':
what_to_do = DO_CHECK;
opt_medium_check = 1;
break;
case 'o':
what_to_do = DO_OPTIMIZE;
break;
case OPT_FIX_DB_NAMES:
what_to_do= DO_UPGRADE;
opt_databases= 1;
CLIENT_WARN_DEPRECATED_NO_REPLACEMENT("--fix-db-names");
break;
case OPT_FIX_TABLE_NAMES:
what_to_do= DO_UPGRADE;
CLIENT_WARN_DEPRECATED_NO_REPLACEMENT("--fix-table-names");
break;
case 'p':
if (argument == disabled_my_option)
argument= (char*) ""; /* Don't require password */
if (argument)
{
char *start = argument;
my_free(opt_password);
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 */
tty_password= 0;
}
else
tty_password = 1;
break;
case 'r':
what_to_do = DO_REPAIR;
break;
case 'g':
what_to_do= DO_CHECK;
opt_upgrade= 1;
break;
case 'W':
#ifdef _WIN32
opt_protocol = MYSQL_PROTOCOL_PIPE;
#endif
break;
case '#':
DBUG_PUSH(argument ? argument : "d:t:o");
debug_check_flag= 1;
break;
#include <sslopt-case.h>
case OPT_TABLES:
opt_databases = 0;
break;
case 'v':
verbose++;
break;
case 'V': print_version(); exit(0);
case OPT_ENABLE_CLEARTEXT_PLUGIN:
using_opt_enable_cleartext_plugin= TRUE;
break;
case OPT_MYSQL_PROTOCOL:
opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
opt->name);
break;
case OPT_SECURE_AUTH:
/* --secure-auth is a zombie option. */
if (!opt_secure_auth)
{
fprintf(stderr, "mysql: [ERROR] --skip-secure-auth is not supported.\n");
exit(1);
}
else
CLIENT_WARN_DEPRECATED_NO_REPLACEMENT("--secure-auth");
break;
}
if (orig_what_to_do && (what_to_do != orig_what_to_do))
{
fprintf(stderr, "Error: %s doesn't support multiple contradicting commands.\n",
my_progname);
return 1;
}
return 0;
}
static int get_options(int *argc, char ***argv)
{
int ho_error;
if (*argc == 1)
{
usage();
exit(0);
}
my_getopt_use_args_separator= TRUE;
if ((ho_error= load_defaults("my", load_default_groups, argc, argv)) ||
(ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
my_getopt_use_args_separator= FALSE;
if (!what_to_do)
{
size_t pnlen= strlen(my_progname);
if (pnlen < 6) /* name too short */
what_to_do = DO_CHECK;
else if (!strcmp("repair", my_progname + pnlen - 6))
what_to_do = DO_REPAIR;
else if (!strcmp("analyze", my_progname + pnlen - 7))
what_to_do = DO_ANALYZE;
else if (!strcmp("optimize", my_progname + pnlen - 8))
what_to_do = DO_OPTIMIZE;
else
what_to_do = DO_CHECK;
}
/*
If there's no --default-character-set option given with
--fix-table-name or --fix-db-name set the default character set to "utf8".
*/
if (!default_charset)
{
if (opt_fix_db_names || opt_fix_table_names)
default_charset= (char*) "utf8";
else
default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME;
}
if (strcmp(default_charset, MYSQL_AUTODETECT_CHARSET_NAME) &&
!get_charset_by_csname(default_charset, MY_CS_PRIMARY, MYF(MY_WME)))
{
printf("Unsupported character set: %s\n", default_charset);
return 1;
}
if (*argc > 0 && opt_alldbs)
{
printf("You should give only options, no arguments at all, with option\n");
printf("--all-databases. Please see %s --help for more information.\n",
my_progname);
return 1;
}
if (*argc < 1 && !opt_alldbs)
{
printf("You forgot to give the arguments! Please see %s --help\n",
my_progname);
printf("for more information.\n");
return 1;
}
if (tty_password)
opt_password = get_tty_password(NullS);
if (debug_info_flag)
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
if (debug_check_flag)
my_end_arg= MY_CHECK_ERROR;
return(0);
} /* get_options */
static int dbConnect(char *host, char *user, char *passwd)
{
DBUG_ENTER("dbConnect");
if (verbose)
{
fprintf(stderr, "# Connecting to %s...\n", host ? host : "localhost");
}
mysql_init(&mysql_connection);
if (opt_compress)
mysql_options(&mysql_connection, MYSQL_OPT_COMPRESS, NullS);
SSL_SET_OPTIONS(&mysql_connection);
if (opt_protocol)
mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
if (opt_bind_addr)
mysql_options(&mysql_connection, MYSQL_OPT_BIND, opt_bind_addr);
#if defined (_WIN32) && !defined (EMBEDDED_LIBRARY)
if (shared_memory_base_name)
mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
#endif
if (opt_plugin_dir && *opt_plugin_dir)
mysql_options(&mysql_connection, MYSQL_PLUGIN_DIR, opt_plugin_dir);
if (opt_default_auth && *opt_default_auth)
mysql_options(&mysql_connection, MYSQL_DEFAULT_AUTH, opt_default_auth);
if (using_opt_enable_cleartext_plugin)
mysql_options(&mysql_connection, MYSQL_ENABLE_CLEARTEXT_PLUGIN,
(char *) &opt_enable_cleartext_plugin);
mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset);
mysql_options(&mysql_connection, MYSQL_OPT_CONNECT_ATTR_RESET, 0);
mysql_options4(&mysql_connection, MYSQL_OPT_CONNECT_ATTR_ADD,
"program_name", "mysqlcheck");
set_server_public_key(&mysql_connection);
set_get_server_public_key_option(&mysql_connection);
if (!(sock = mysql_real_connect(&mysql_connection, host, user, passwd,
NULL, opt_mysql_port, opt_mysql_unix_port, 0)))
{
DBerror(&mysql_connection, "when trying to connect");
DBUG_RETURN(1);
}
mysql_connection.reconnect= 1;
DBUG_RETURN(0);
} /* dbConnect */
static void dbDisconnect(char *host)
{
if (verbose)
fprintf(stderr, "# Disconnecting from %s...\n", host ? host : "localhost");
mysql_close(sock);
} /* dbDisconnect */
static void DBerror(MYSQL *mysql, string when)
{
DBUG_ENTER("DBerror");
my_printf_error(0,"Got error: %d: %s %s", MYF(0),
mysql_errno(mysql), mysql_error(mysql), when.c_str());
safe_exit(EX_MYSQLERR);
DBUG_VOID_RETURN;
} /* DBerror */
static void safe_exit(int error)
{
if (!first_error)
first_error= error;
if (ignore_errors)
return;
if (sock)
mysql_close(sock);
exit(error);
}
int main(int argc, char **argv)
{
MY_INIT(argv[0]);
/*
** Check out the args
*/
if (get_options(&argc, &argv))
{
my_end(my_end_arg);
exit(EX_USAGE);
}
if (dbConnect(current_host, current_user, opt_password))
exit(EX_MYSQLERR);
// Sun Studio does not work with range constructor from char** to string.
vector<string> conv;
conv.reserve(argc);
for (int i= 0; i < argc; i++)
conv.push_back(argv[i]);
mysql_check(sock, what_to_do, opt_alldbs,
opt_check_only_changed, opt_extended,
opt_databases, opt_fast,
opt_medium_check, opt_quick,
opt_all_in_1, opt_silent,
opt_auto_repair, ignore_errors,
opt_frm, opt_fix_table_names,
opt_fix_db_names, opt_upgrade,
opt_write_binlog, verbose,
opt_skip_database, conv,
DBerror);
dbDisconnect(current_host);
my_free(opt_password);
#if defined (_WIN32) && !defined (EMBEDDED_LIBRARY)
my_free(shared_memory_base_name);
#endif
free_defaults(argv);
my_end(my_end_arg);
return(first_error!=0);
} /* main */

View File

@ -1,139 +0,0 @@
/*
Copyright (c) 2014, 2015, 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-1301 USA
*/
#ifndef MYSQLCHECK_INCLUDED
#define MYSQLCHECK_INCLUDED
#include <string>
#include <vector>
namespace Mysql{
namespace Tools{
namespace Check{
enum operations { DO_CHECK=1, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE, DO_UPGRADE };
extern void mysql_check(MYSQL* connection, int what_to_do, my_bool opt_alldbs,
my_bool opt_check_only_changed, my_bool opt_extended,
my_bool opt_databases, my_bool opt_fast,
my_bool opt_medium_check, my_bool opt_quick,
my_bool opt_all_in_1, my_bool opt_silent,
my_bool opt_auto_repair, my_bool ignore_errors,
my_bool opt_frm, my_bool opt_fix_table_names,
my_bool opt_fix_db_names, my_bool opt_upgrade,
my_bool opt_write_binlog, uint verbose,
std::string opt_skip_database,
std::vector<std::string> arguments,
void (*dberror)(MYSQL *mysql, std::string when));
/**
This class is object wrapper to mysql_check function. It looks like
it is implementing Abstract_program, but it is not explicitly implementing
it now. This is to make future implementation of Abstract_program easier.
*/
class Program
{
public:
/**
Default constructor.
*/
Program();
/**
Checks specified databases on MySQL server.
*/
int check_databases(MYSQL* connection, std::vector<std::string> databases);
/**
Checks all databases on MySQL server.
*/
int check_all_databases(MYSQL* connection);
/**
Upgrades specified on MySQL server.
*/
int upgrade_databases(MYSQL* connection, std::vector<std::string> databases);
/**
Upgrades all databases on MySQL server.
*/
int upgrade_all_databases(MYSQL* connection);
/**
Automatically try to fix table when upgrade is needed.
*/
Program* enable_auto_repair(bool enable);
/**
Check and upgrade tables.
*/
Program* enable_upgrade(bool enable);
/**
Turns on verbose messages.
*/
Program* enable_verbosity(bool enable);
/**
Enables logging repairing queries to binlog.
*/
Program* enable_writing_binlog(bool enable);
/**
Enables table name fixing for all encountered tables.
*/
Program* enable_fixing_table_names(bool enable);
/**
Enables database name fixing for all encountered databases.
*/
Program* enable_fixing_db_names(bool enable);
/**
Ignores all errors and don't print error messages.
*/
Program* set_ignore_errors(bool ignore);
/**
Sets a name of database to ignore during process.
*/
Program* set_skip_database(std::string database);
/**
Sets error callback to be called when error is encountered.
*/
Program* set_error_callback(
void (*error_callback)(MYSQL *mysql, std::string when));
private:
/**
Sets mysqlcheck program operation type to perform.
*/
Program* set_what_to_do(int functionality);
/**
Starts mysqlcheck process.
*/
int execute(std::vector<std::string> positional_options);
int m_what_to_do;
bool m_auto_repair;
bool m_upgrade;
bool m_verbose;
bool m_ignore_errors;
bool m_write_binlog;
bool m_process_all_dbs;
bool m_fix_table_names;
bool m_fix_db_names;
MYSQL* m_connection;
std::string m_database_to_skip;
void (*m_error_callback)(MYSQL *mysql, std::string when);
};
}
}
}
#endif

View File

@ -1,699 +0,0 @@
/*
Copyright (c) 2001, 2017, 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-1301 USA
*/
#include "client_priv.h"
#include "my_default.h"
#include "mysqlcheck.h"
#include <m_ctype.h>
#include <mysql_version.h>
#include <mysqld_error.h>
#include <string>
#include <vector>
using namespace Mysql::Tools::Check;
using std::string;
using std::vector;
/* ALTER instead of repair. */
#define MAX_ALTER_STR_SIZE 128 * 1024
#define KEY_PARTITIONING_CHANGED_STR "KEY () partitioning changed"
static MYSQL *sock= 0;
static my_bool opt_alldbs= 0, opt_check_only_changed= 0, opt_extended= 0,
opt_databases= 0, opt_fast= 0,
opt_medium_check = 0, opt_quick= 0, opt_all_in_1= 0,
opt_silent= 0, opt_auto_repair= 0, ignore_errors= 0,
opt_frm= 0, opt_fix_table_names= 0, opt_fix_db_names= 0, opt_upgrade= 0,
opt_write_binlog= 1;
static uint verbose = 0;
static string opt_skip_database;
int what_to_do = 0;
void (*DBError)(MYSQL *mysql, string when);
static int first_error = 0;
vector<string> tables4repair, tables4rebuild, alter_table_cmds, failed_tables;
static int process_all_databases();
static int process_databases(vector<string> db_names);
static int process_selected_tables(string db, vector<string> table_names);
static int process_all_tables_in_db(string database);
static int process_one_db(string database);
static int use_db(string database);
static int handle_request_for_tables(string tables);
static void print_result();
static string escape_table_name(string src);
static int process_all_databases()
{
MYSQL_ROW row;
MYSQL_RES *tableres;
int result = 0;
if (mysql_query(sock, "SHOW DATABASES") ||
!(tableres = mysql_store_result(sock)))
{
my_printf_error(0, "Error: Couldn't execute 'SHOW DATABASES': %s",
MYF(0), mysql_error(sock));
return 1;
}
while ((row = mysql_fetch_row(tableres)))
{
if (process_one_db(row[0]))
result = 1;
}
mysql_free_result(tableres);
return result;
}
/* process_all_databases */
static int process_databases(vector<string> db_names)
{
int result = 0;
vector<string>::iterator it;
for (it= db_names.begin() ; it != db_names.end(); it++)
{
if (process_one_db(*it))
result = 1;
}
return result;
} /* process_databases */
static int process_selected_tables(string db, vector<string> table_names)
{
if (use_db(db))
return 1;
vector<string>::iterator it;
for (it= table_names.begin(); it != table_names.end(); it++)
{
if (what_to_do != DO_UPGRADE)
*it= escape_table_name(*it);
handle_request_for_tables(*it);
}
return 0;
} /* process_selected_tables */
static inline void escape_str(string src, size_t start, size_t end, string &res)
{
res+= '`';
for (size_t i= start; i < end; i++)
{
switch (src[i]) {
case '`': /* Escape backtick character. */
res+= '`';
/* Fall through. */
default:
res+= src[i];
}
}
res+= '`';
}
static string escape_table_name(string src)
{
string res= "";
escape_str(src, 0, src.length(), res);
return res;
}
static string escape_db_table_name(string src, size_t dot_pos)
{
string res= "";
/* Escape database name. */
escape_str(src, 0, dot_pos - 1, res);
/* Add a dot. */
res+= '.';
/* Escape table name. */
escape_str(src, dot_pos, src.length(), res);
return res;
}
static int process_all_tables_in_db(string database)
{
MYSQL_RES *res= NULL;
MYSQL_ROW row;
uint num_columns;
if (use_db(database))
return 1;
if ((mysql_query(sock, "SHOW /*!50002 FULL*/ TABLES") &&
mysql_query(sock, "SHOW TABLES")) ||
!(res= mysql_store_result(sock)))
{
my_printf_error(0, "Error: Couldn't get table list for database %s: %s",
MYF(0), database.c_str(), mysql_error(sock));
return 1;
}
num_columns= mysql_num_fields(res);
vector<string> table_names;
while ((row = mysql_fetch_row(res)))
{
/* Skip views if we don't perform renaming. */
if ((what_to_do != DO_UPGRADE) && (num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
continue;
table_names.push_back(row[0]);
}
mysql_free_result(res);
process_selected_tables(database, table_names);
return 0;
} /* process_all_tables_in_db */
static int run_query(string query)
{
if (mysql_query(sock, query.c_str()))
{
fprintf(stderr, "Failed to run query \"%s\"\n", query.c_str());
fprintf(stderr, "Error: %s\n", mysql_error(sock));
return 1;
}
return 0;
}
static int fix_table_storage_name(string name)
{
if (strncmp(name.c_str(), "#mysql50#", 9))
return 1;
int rc= run_query("RENAME TABLE `" + name + "` TO `" + name.substr(9) + "`");
if (verbose)
printf("%-50s %s\n", name.c_str(), rc ? "FAILED" : "OK");
return rc;
}
static int fix_database_storage_name(string name)
{
if (strncmp(name.c_str(), "#mysql50#", 9))
return 1;
int rc= run_query("ALTER DATABASE `" + name + "` UPGRADE DATA DIRECTORY NAME");
if (verbose)
printf("%-50s %s\n", name.c_str(), rc ? "FAILED" : "OK");
return rc;
}
static int rebuild_table(string name)
{
int rc= 0;
string query= "ALTER TABLE " + name + " FORCE";
if (mysql_real_query(sock, query.c_str(), (ulong)query.length()))
{
fprintf(stderr, "Failed to %s\n", query.c_str());
fprintf(stderr, "Error: %s\n", mysql_error(sock));
rc= 1;
}
else
printf("%s\nRunning : %s\nstatus : OK\n", name.c_str(), query.c_str());
return rc;
}
static int process_one_db(string database)
{
if (opt_skip_database.length() > 0 && opt_alldbs
&& database == opt_skip_database)
return 0;
if (what_to_do == DO_UPGRADE)
{
int rc= 0;
if (opt_fix_db_names && !strncmp(database.c_str(),"#mysql50#", 9))
{
rc= fix_database_storage_name(database);
database= database.substr(9);
}
if (rc || !opt_fix_table_names)
return rc;
}
return process_all_tables_in_db(database);
}
static int use_db(string database)
{
if (mysql_get_server_version(sock) >= FIRST_INFORMATION_SCHEMA_VERSION &&
!my_strcasecmp(
&my_charset_latin1, database.c_str(), INFORMATION_SCHEMA_DB_NAME))
return 1;
if (mysql_get_server_version(sock) >= FIRST_PERFORMANCE_SCHEMA_VERSION &&
!my_strcasecmp(
&my_charset_latin1, database.c_str(), PERFORMANCE_SCHEMA_DB_NAME))
return 1;
if (mysql_select_db(sock, database.c_str()))
{
DBError(sock, "when selecting the database");
return 1;
}
return 0;
} /* use_db */
static int disable_binlog()
{
return run_query("SET SQL_LOG_BIN=0");
}
static int handle_request_for_tables(string tables)
{
string operation, options;
switch (what_to_do) {
case DO_CHECK:
operation = "CHECK";
if (opt_quick) options+= " QUICK";
if (opt_fast) options+= " FAST";
if (opt_medium_check) options+= " MEDIUM"; /* Default */
if (opt_extended) options+= " EXTENDED";
if (opt_check_only_changed) options+= " CHANGED";
if (opt_upgrade) options+= " FOR UPGRADE";
break;
case DO_REPAIR:
operation= (opt_write_binlog) ? "REPAIR" : "REPAIR NO_WRITE_TO_BINLOG";
if (opt_quick) options+= " QUICK";
if (opt_extended) options+= " EXTENDED";
if (opt_frm) options+= " USE_FRM";
break;
case DO_ANALYZE:
operation= (opt_write_binlog) ? "ANALYZE" : "ANALYZE NO_WRITE_TO_BINLOG";
break;
case DO_OPTIMIZE:
operation= (opt_write_binlog) ? "OPTIMIZE" : "OPTIMIZE NO_WRITE_TO_BINLOG";
break;
case DO_UPGRADE:
return fix_table_storage_name(tables);
}
string query= operation + " TABLE " + tables + " " + options;
if (mysql_real_query(sock, query.c_str(), (ulong)query.length()))
{
DBError(sock,
"when executing '" + operation + " TABLE ... " + options + "'");
return 1;
}
print_result();
return 0;
}
static void print_result()
{
MYSQL_RES *res;
MYSQL_ROW row;
char prev[NAME_LEN*3+2];
char prev_alter[MAX_ALTER_STR_SIZE];
uint i;
size_t dot_pos;
my_bool found_error=0, table_rebuild=0;
res = mysql_use_result(sock);
dot_pos= strlen(sock->db) + 1;
prev[0] = '\0';
prev_alter[0]= 0;
for (i = 0; (row = mysql_fetch_row(res)); i++)
{
int changed = strcmp(prev, row[0]);
my_bool status = !strcmp(row[2], "status");
if (status)
{
/*
if there was an error with the table, we have --auto-repair set,
and this isn't a repair op, then add the table to the tables4repair
list
*/
if (found_error && opt_auto_repair && what_to_do != DO_REPAIR &&
strcmp(row[3],"OK"))
{
if (table_rebuild)
{
if (prev_alter[0])
alter_table_cmds.push_back(prev_alter);
else
tables4rebuild.push_back(escape_db_table_name(prev, dot_pos));
}
else
{
tables4repair.push_back(escape_db_table_name(prev, dot_pos));
}
}
found_error= 0;
table_rebuild= 0;
prev_alter[0]= '\0';
if (opt_silent)
continue;
}
if (status && changed)
printf("%-50s %s", row[0], row[3]);
else if (!status && changed)
{
printf("%s\n%-9s: %s", row[0], row[2], row[3]);
if (opt_auto_repair && strcmp(row[2],"note"))
{
const char *alter_txt= strstr(row[3], "ALTER TABLE");
found_error= 1;
if (alter_txt)
{
table_rebuild= 1;
const char *match_str;
if (!strncmp(row[3], KEY_PARTITIONING_CHANGED_STR,
strlen(KEY_PARTITIONING_CHANGED_STR)))
{
if (strstr(alter_txt, "PARTITION BY") &&
strlen(alter_txt) < MAX_ALTER_STR_SIZE)
{
strncpy(prev_alter, alter_txt, MAX_ALTER_STR_SIZE-1);
prev_alter[MAX_ALTER_STR_SIZE-1]= 0;
}
else
{
printf("\nError: Alter command unknown or too long (%d >= %d), "
"please investigate the above or dump/reload to fix it!"
"\n",
(int)strlen(alter_txt),
MAX_ALTER_STR_SIZE);
found_error= 0;
table_rebuild= 0;
prev_alter[0]= '\0';
failed_tables.push_back(row[0]);
}
}
else if ((match_str= strstr(alter_txt, "` UPGRADE PARTITIONING")) &&
strlen(match_str) == 22)
{
strcpy(prev_alter, alter_txt);
}
}
else
{
/*
Search the error message specific to pre 5.0 decimal type.
"REPAIR TABLE" should not be present in the error message and
"dump/reload" should be present in the error message. In this
case, do not add table to the repair list.
*/
const char *repair_txt= strstr(row[3], "REPAIR TABLE");
const char *dump_txt= strstr(row[3], "dump/reload table");
if (dump_txt && !repair_txt)
{
found_error= 0;
table_rebuild= 0;
prev_alter[0]= '\0';
failed_tables.push_back(row[0]);
}
}
}
}
else
printf("%-9s: %s", row[2], row[3]);
my_stpcpy(prev, row[0]);
putchar('\n');
}
/* add the last table to be repaired to the list */
if (found_error && opt_auto_repair && what_to_do != DO_REPAIR)
{
if (table_rebuild)
{
if (prev_alter[0])
alter_table_cmds.push_back(prev_alter);
else
tables4rebuild.push_back(escape_db_table_name(prev, dot_pos));
}
else
{
tables4repair.push_back(escape_db_table_name(prev, dot_pos));
}
}
mysql_free_result(res);
}
void Mysql::Tools::Check::mysql_check(MYSQL* connection, int what_to_do,
my_bool opt_alldbs,
my_bool opt_check_only_changed, my_bool opt_extended,
my_bool opt_databases, my_bool opt_fast,
my_bool opt_medium_check, my_bool opt_quick,
my_bool opt_all_in_1, my_bool opt_silent,
my_bool opt_auto_repair, my_bool ignore_errors,
my_bool opt_frm, my_bool opt_fix_table_names,
my_bool opt_fix_db_names, my_bool opt_upgrade,
my_bool opt_write_binlog, uint verbose,
string opt_skip_database, vector<string> arguments,
void (*dberror)(MYSQL *mysql, string when))
{
::sock= connection;
::what_to_do= what_to_do;
::opt_alldbs= opt_alldbs;
::opt_check_only_changed= opt_check_only_changed;
::opt_extended= opt_extended;
::opt_databases= opt_databases;
::opt_fast= opt_fast;
::opt_medium_check= opt_medium_check;
::opt_quick= opt_quick;
::opt_all_in_1= opt_all_in_1;
::opt_silent= opt_silent;
::opt_auto_repair= opt_auto_repair;
::ignore_errors= ignore_errors;
::opt_frm= opt_frm;
::opt_fix_table_names= opt_fix_table_names;
::opt_fix_db_names= opt_fix_db_names;
::opt_upgrade= opt_upgrade;
::opt_write_binlog= opt_write_binlog;
::verbose= verbose;
::opt_skip_database= opt_skip_database;
::DBError= dberror;
if (!::opt_write_binlog)
{
if (disable_binlog()) {
first_error= 1;
return;
}
}
if (::opt_alldbs)
process_all_databases();
/* Only one database and selected table(s) */
else if (arguments.size() > 1 && !::opt_databases)
{
string db_name= arguments[0];
arguments.erase(arguments.begin());
process_selected_tables(db_name, arguments);
}
/* One or more databases, all tables */
else
process_databases(arguments);
if (::opt_auto_repair)
{
if (!::opt_silent)
{
if (!(tables4repair.empty() && tables4rebuild.empty()))
puts("\nRepairing tables");
if (!(alter_table_cmds.empty()))
puts("\nUpgrading tables");
}
::what_to_do = DO_REPAIR;
vector<string>::iterator it;
for (it = tables4repair.begin(); it != tables4repair.end() ; it++)
{
handle_request_for_tables(*it);
}
for (it = tables4rebuild.begin(); it != tables4rebuild.end() ; it++)
{
rebuild_table(*it);
}
for (it = alter_table_cmds.begin(); it != alter_table_cmds.end() ; it++)
{
if (0 == run_query(*it))
printf("Running : %s\nstatus : OK\n", (*it).c_str());
else
{
fprintf(stderr, "Failed to %s\n", (*it).c_str());
fprintf(stderr, "Error: %s\n", mysql_error(sock));
}
}
if (!failed_tables.empty())
{
fprintf(stderr,
"These tables cannot be automatically upgraded,"
" see the log above:\n");
}
for (it = failed_tables.begin(); it != failed_tables.end() ; it++)
{
fprintf(stderr, "%s\n", it->c_str());
}
}
}
Program::Program()
: m_what_to_do(0),
m_auto_repair(false),
m_upgrade(false),
m_verbose(false),
m_ignore_errors(false),
m_write_binlog(false),
m_process_all_dbs(false),
m_fix_table_names(false),
m_fix_db_names(false),
m_connection(NULL),
m_error_callback(NULL)
{
}
int Program::check_databases(MYSQL* connection, vector<string> databases)
{
this->m_connection= connection;
this->m_process_all_dbs= false;
return this->set_what_to_do(DO_CHECK)
->execute(databases);
}
int Program::check_all_databases(MYSQL* connection)
{
this->m_connection= connection;
this->m_process_all_dbs= true;
return this->set_what_to_do(DO_CHECK)
->execute(vector<string>());
}
int Program::upgrade_databases(MYSQL* connection, vector<string> databases)
{
this->m_connection= connection;
this->m_process_all_dbs= false;
return this->set_what_to_do(DO_UPGRADE)
->execute(databases);
}
int Program::upgrade_all_databases(MYSQL* connection)
{
this->m_connection= connection;
this->m_process_all_dbs= true;
return this->set_what_to_do(DO_UPGRADE)
->execute(vector<string>());
}
Program* Program::enable_auto_repair(bool enable)
{
this->m_auto_repair= enable;
return this;
}
Program* Program::enable_upgrade(bool enable)
{
this->m_upgrade= enable;
return this;
}
Program* Program::enable_verbosity(bool enable)
{
this->m_verbose= enable;
return this;
}
Program* Program::enable_writing_binlog(bool enable)
{
this->m_write_binlog= enable;
return this;
}
Program* Program::enable_fixing_table_names(bool enable)
{
this->m_fix_table_names= enable;
return this;
}
Program* Program::enable_fixing_db_names(bool enable)
{
this->m_fix_db_names= enable;
return this;
}
Program* Program::set_ignore_errors(bool ignore)
{
this->m_ignore_errors= ignore;
return this;
}
Program* Program::set_skip_database(string database)
{
this->m_database_to_skip= database;
return this;
}
Program* Program::set_error_callback(void (
*error_callback)(MYSQL *mysql, string when))
{
this->m_error_callback= error_callback;
return this;
}
Program* Program::set_what_to_do(int functionality)
{
this->m_what_to_do= functionality;
return this;
}
int Program::execute(vector<string> positional_options)
{
Mysql::Tools::Check::mysql_check(
this->m_connection, // connection
this->m_what_to_do, // what_to_do
this->m_process_all_dbs, // opt_alldbs
false, // opt_check_only_changed
false, // opt_extended
!this->m_process_all_dbs, // opt_databases
false, // opt_fast
false, // opt_medium_check
false, // opt_quick
false, // opt_all_in_1
false, // opt_silent
this->m_auto_repair, // opt_auto_repair
this->m_ignore_errors, // ignore_errors
false, // opt_frm
this->m_fix_table_names, // opt_fix_table_names
this->m_fix_db_names, // opt_fix_db_names
this->m_upgrade, // opt_upgrade
this->m_write_binlog, // opt_write_binlog
this->m_verbose, // verbose
this->m_database_to_skip,
positional_options,
this->m_error_callback);
return 0;
}

View File

@ -1,156 +0,0 @@
/*
Copyright (c) 2001, 2017, 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-1301 USA
*/
#ifndef CLIENT_PRIV_INCLUDED
#define CLIENT_PRIV_INCLUDED
/* Common defines for all clients */
#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include <mysql.h>
#include <errmsg.h>
#include <my_getopt.h>
#ifndef WEXITSTATUS
# ifdef _WIN32
# define WEXITSTATUS(stat_val) (stat_val)
# else
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
# endif
#endif
enum options_client
{
OPT_CHARSETS_DIR=256, OPT_DEFAULT_CHARSET,
OPT_PAGER, OPT_TEE,
OPT_LOW_PRIORITY, OPT_AUTO_REPAIR, OPT_COMPRESS,
OPT_DROP, OPT_LOCKS, OPT_KEYWORDS, OPT_OPTIMIZE,
OPT_FTB, OPT_LTB, OPT_ENC, OPT_O_ENC, OPT_ESC, OPT_TABLES,
OPT_MASTER_DATA, OPT_AUTOCOMMIT, OPT_AUTO_REHASH,
OPT_LINE_NUMBERS, OPT_COLUMN_NAMES, OPT_CONNECT_TIMEOUT,
OPT_MAX_ALLOWED_PACKET, OPT_NET_BUFFER_LENGTH,
OPT_SELECT_LIMIT, OPT_MAX_JOIN_SIZE, OPT_SSL_SSL,
OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA, OPT_SSL_CAPATH,
OPT_SSL_CIPHER, OPT_SHUTDOWN_TIMEOUT, OPT_LOCAL_INFILE,
OPT_DELETE_MASTER_LOGS, OPT_COMPACT,
OPT_PROMPT, OPT_IGN_LINES, OPT_TRANSACTION, OPT_MYSQL_PROTOCOL,
OPT_SHARED_MEMORY_BASE_NAME, OPT_FRM, OPT_SKIP_OPTIMIZATION,
OPT_COMPATIBLE, OPT_RECONNECT, OPT_DELIMITER, OPT_SECURE_AUTH,
OPT_OPEN_FILES_LIMIT, OPT_SET_CHARSET, OPT_SET_GTID_PURGED, OPT_SERVER_ARG,
OPT_STOP_POSITION, OPT_START_DATETIME, OPT_STOP_DATETIME,
OPT_SIGINT_IGNORE, OPT_HEXBLOB, OPT_ORDER_BY_PRIMARY, OPT_COUNT,
OPT_TRIGGERS,
OPT_MYSQL_ONLY_PRINT,
OPT_MYSQL_LOCK_DIRECTORY,
OPT_USE_THREADS,
OPT_IMPORT_USE_THREADS,
OPT_MYSQL_NUMBER_OF_QUERY,
OPT_IGNORE_TABLE, OPT_INSERT_IGNORE, OPT_SHOW_WARNINGS, OPT_DROP_DATABASE,
OPT_TZ_UTC, OPT_CREATE_SLAP_SCHEMA,
OPT_MYSQLDUMP_SLAVE_APPLY,
OPT_MYSQLDUMP_SLAVE_DATA,
OPT_MYSQLDUMP_INCLUDE_MASTER_HOST_PORT,
OPT_MYSQLDUMP_IGNORE_ERROR,
OPT_SLAP_CSV, OPT_SLAP_CREATE_STRING,
OPT_SLAP_AUTO_GENERATE_SQL_LOAD_TYPE, OPT_SLAP_AUTO_GENERATE_WRITE_NUM,
OPT_SLAP_AUTO_GENERATE_ADD_AUTO,
OPT_SLAP_AUTO_GENERATE_GUID_PRIMARY,
OPT_SLAP_AUTO_GENERATE_EXECUTE_QUERIES,
OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES,
OPT_SLAP_AUTO_GENERATE_UNIQUE_WRITE_NUM,
OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM,
OPT_SLAP_PRE_QUERY,
OPT_SLAP_POST_QUERY,
OPT_SLAP_PRE_SYSTEM,
OPT_SLAP_POST_SYSTEM,
OPT_SLAP_COMMIT,
OPT_SLAP_DETACH,
OPT_SLAP_NO_DROP,
OPT_MYSQL_REPLACE_INTO, OPT_BASE64_OUTPUT_MODE, OPT_SERVER_ID,
OPT_FIX_TABLE_NAMES, OPT_FIX_DB_NAMES, OPT_SSL_VERIFY_SERVER_CERT,
OPT_AUTO_VERTICAL_OUTPUT,
OPT_DEBUG_INFO, OPT_DEBUG_CHECK, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE,
OPT_WRITE_BINLOG, OPT_DUMP_DATE,
OPT_INIT_COMMAND,
OPT_PLUGIN_DIR,
OPT_DEFAULT_AUTH,
OPT_DEFAULT_PLUGIN,
OPT_RAW_OUTPUT, OPT_WAIT_SERVER_ID, OPT_STOP_NEVER,
OPT_BINLOG_ROWS_EVENT_MAX_SIZE,
OPT_HISTIGNORE,
OPT_BINARY_MODE,
OPT_SSL_CRL, OPT_SSL_CRLPATH,
OPT_MYSQLBINLOG_SKIP_GTIDS,
OPT_MYSQLBINLOG_INCLUDE_GTIDS,
OPT_MYSQLBINLOG_EXCLUDE_GTIDS,
OPT_REMOTE_PROTO,
OPT_CONFIG_ALL,
OPT_REWRITE_DB,
OPT_SERVER_PUBLIC_KEY,
OPT_ENABLE_CLEARTEXT_PLUGIN,
OPT_CONNECTION_SERVER_ID,
OPT_TLS_VERSION,
OPT_SSL_MODE,
/* Add new option above this */
OPT_MAX_CLIENT_OPTION
};
/**
First mysql version supporting the information schema.
*/
#define FIRST_INFORMATION_SCHEMA_VERSION 50003
/**
Name of the information schema database.
*/
#define INFORMATION_SCHEMA_DB_NAME "information_schema"
/**
First mysql version supporting the performance schema.
*/
#define FIRST_PERFORMANCE_SCHEMA_VERSION 50503
/**
Name of the performance schema database.
*/
#define PERFORMANCE_SCHEMA_DB_NAME "performance_schema"
/**
First mysql version supporting the sys schema.
*/
#define FIRST_SYS_SCHEMA_VERSION 50707
/**
Name of the sys schema database.
*/
#define SYS_SCHEMA_DB_NAME "sys"
/**
Client deprecation warnings
*/
#define CLIENT_WARN_DEPRECATED_NO_REPLACEMENT(opt) \
fprintf(stderr, "WARNING: " opt \
" is deprecated and will be removed in a future version\n")
#define CLIENT_WARN_DEPRECATED(opt, new_opt) \
fprintf(stderr, "WARNING: " opt \
" is deprecated and will be removed in a future version. " \
"Use " new_opt " instead.\n")
#endif

View File

@ -1,226 +0,0 @@
/* 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-1301 USA */
/* Quick & light hash implementation for tab completion purposes
*
* by Andi Gutmans <andi@zend.com>
* and Zeev Suraski <zeev@zend.com>
* Small portability changes by Monty. Changed also to use my_malloc/my_free
*/
#include <my_global.h>
#include <m_string.h>
#include <my_sys.h>
#include "completion_hash.h"
uint hashpjw(const char *arKey, uint nKeyLength)
{
uint h = 0, g, i;
for (i = 0; i < nKeyLength; i++) {
h = (h << 4) + arKey[i];
if ((g = (h & 0xF0000000))) {
h = h ^ (g >> 24);
h = h ^ g;
}
}
return h;
}
int completion_hash_init(HashTable *ht, uint nSize)
{
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(PSI_NOT_INSTRUMENTED, &ht->mem_root, 8192, 0);
ht->pHashFunction = hashpjw;
ht->nTableSize = nSize;
ht->initialized = 1;
return SUCCESS;
}
int completion_hash_update(HashTable *ht, char *arKey, uint nKeyLength,
char *str)
{
uint h, nIndex;
Bucket *p;
h = ht->pHashFunction(arKey, nKeyLength);
nIndex = h % ht->nTableSize;
if (nKeyLength <= 0) {
return FAILURE;
}
p = ht->arBuckets[nIndex];
while (p)
{
if ((p->h == h) && (p->nKeyLength == nKeyLength)) {
if (!memcmp(p->arKey, arKey, nKeyLength)) {
entry *n;
if (!(n = (entry *) alloc_root(&ht->mem_root,sizeof(entry))))
return FAILURE;
n->pNext = p->pData;
n->str = str;
p->pData = n;
p->count++;
return SUCCESS;
}
}
p = p->pNext;
}
if (!(p = (Bucket *) alloc_root(&ht->mem_root, sizeof(Bucket))))
return FAILURE;
p->arKey = arKey;
p->nKeyLength = nKeyLength;
p->h = h;
if (!(p->pData = (entry*) alloc_root(&ht->mem_root, sizeof(entry))))
return FAILURE;
p->pData->str = str;
p->pData->pNext = 0;
p->count = 1;
p->pNext = ht->arBuckets[nIndex];
ht->arBuckets[nIndex] = p;
return SUCCESS;
}
static Bucket *completion_hash_find(HashTable *ht, const char *arKey,
uint nKeyLength)
{
uint h, nIndex;
Bucket *p;
h = ht->pHashFunction(arKey, nKeyLength);
nIndex = h % ht->nTableSize;
p = ht->arBuckets[nIndex];
while (p)
{
if ((p->h == h) && (p->nKeyLength == nKeyLength)) {
if (!memcmp(p->arKey, arKey, nKeyLength)) {
return p;
}
}
p = p->pNext;
}
return (Bucket*) 0;
}
int completion_hash_exists(HashTable *ht, char *arKey, uint nKeyLength)
{
uint h, nIndex;
Bucket *p;
h = ht->pHashFunction(arKey, nKeyLength);
nIndex = h % ht->nTableSize;
p = ht->arBuckets[nIndex];
while (p)
{
if ((p->h == h) && (p->nKeyLength == nKeyLength))
{
if (!strcmp(p->arKey, arKey)) {
return 1;
}
}
p = p->pNext;
}
return 0;
}
Bucket *find_all_matches(HashTable *ht, const char *str, uint length,
uint *res_length)
{
Bucket *b;
b = completion_hash_find(ht,str,length);
if (!b) {
*res_length = 0;
return (Bucket*) 0;
} else {
*res_length = length;
return b;
}
}
Bucket *find_longest_match(HashTable *ht, char *str, uint length,
uint *res_length)
{
Bucket *b,*return_b;
char *s;
uint count;
uint lm;
b = completion_hash_find(ht,str,length);
if (!b) {
*res_length = 0;
return (Bucket*) 0;
}
count = b->count;
lm = length;
s = b->pData->str;
return_b = b;
while (s[lm]!=0 && (b=completion_hash_find(ht,s,lm+1))) {
if (b->count<count) {
*res_length=lm;
return return_b;
}
return_b=b;
lm++;
}
*res_length=lm;
return return_b;
}
void completion_hash_clean(HashTable *ht)
{
free_root(&ht->mem_root,MYF(0));
memset(ht->arBuckets, 0, ht->nTableSize * sizeof(Bucket *));
}
void completion_hash_free(HashTable *ht)
{
completion_hash_clean(ht);
my_free(ht->arBuckets);
}
void add_word(HashTable *ht,char *str)
{
int i;
char *pos=str;
for (i=1; *pos; i++, pos++)
completion_hash_update(ht, str, i, str);
}

View File

@ -1,61 +0,0 @@
/* Copyright (c) 2000-2002, 2006 MySQL AB
Use is subject to license terms
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA */
#ifndef _HASH_
#define _HASH_
#define SUCCESS 0
#define FAILURE 1
#include <sys/types.h>
#include <my_sys.h>
typedef struct _entry {
char *str;
struct _entry *pNext;
} entry;
typedef struct bucket
{
uint h; /* Used for numeric indexing */
char *arKey;
uint nKeyLength;
uint count;
entry *pData;
struct bucket *pNext;
} Bucket;
typedef struct hashtable {
uint nTableSize;
uint initialized;
MEM_ROOT mem_root;
uint(*pHashFunction) (const char *arKey, uint nKeyLength);
Bucket **arBuckets;
} HashTable;
extern int completion_hash_init(HashTable *ht, uint nSize);
extern int completion_hash_update(HashTable *ht, char *arKey, uint nKeyLength, char *str);
extern int hash_exists(HashTable *ht, char *arKey);
extern Bucket *find_all_matches(HashTable *ht, const char *str, uint length, uint *res_length);
extern Bucket *find_longest_match(HashTable *ht, char *str, uint length, uint *res_length);
extern void add_word(HashTable *ht,char *str);
extern void completion_hash_clean(HashTable *ht);
extern int completion_hash_exists(HashTable *ht, char *arKey, uint nKeyLength);
extern void completion_hash_free(HashTable *ht);
#endif /* _HASH_ */

View File

@ -1,149 +0,0 @@
# Copyright (c) 2015, 2018, 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-1301 USA
INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake)
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/dump
)
# Prevent Boost from including external precompiled Boost libraries,
# and turn off unused functionality.
IF(USING_LOCAL_BOOST)
ADD_DEFINITIONS(
-DBOOST_ALL_NO_LIB
-DBOOST_SYSTEM_NO_DEPRECATED)
ENDIF()
SET(BOOST_LIB_SOURCES
${BOOST_SOURCES_DIR}/libs/chrono/src/chrono.cpp
${BOOST_SOURCES_DIR}/libs/system/src/error_code.cpp
)
INCLUDE_DIRECTORIES(SYSTEM
${BOOST_PATCHES_DIR}
${BOOST_INCLUDE_DIR}
)
IF(USING_LOCAL_BOOST)
ADD_CONVENIENCE_LIBRARY(boost_lib ${BOOST_LIB_SOURCES})
# Do not build library unless it is needed by some other target.
SET_PROPERTY(TARGET boost_lib PROPERTY EXCLUDE_FROM_ALL TRUE)
IF(HAVE_clock_gettime_IN_rt)
TARGET_LINK_LIBRARIES(boost_lib ${LIBRT})
ENDIF()
# Need explicit pthread for gcc -fsanitize=address
IF(CMAKE_USE_PTHREADS_INIT AND CMAKE_C_FLAGS MATCHES "-fsanitize=")
TARGET_LINK_LIBRARIES(boost_lib pthread)
ENDIF()
SET(LOCAL_BOOST_LIB boost_lib)
ENDIF()
SET(MYSQLPUMP_LIB_SOURCES
abstract_chain_element.cc
abstract_connection_provider.cc
abstract_crawler.cc
abstract_data_formatter_wrapper.cc
abstract_data_object.cc
abstract_database_dump_task.cc
abstract_dump_task.cc
abstract_mysql_chain_element_extension.cc
abstract_object_reader_wrapper.cc
abstract_output_writer_wrapper.cc
abstract_plain_sql_object.cc
abstract_plain_sql_object_dump_task.cc
abstract_progress_reporter.cc
abstract_progress_watcher.cc
abstract_simple_dump_task.cc
abstract_table_dump_task.cc
chain_data.cc
composite_message_handler.cc
compression_lz4_writer.cc
compression_zlib_writer.cc
database.cc
database_end_dump_task.cc
database_start_dump_task.cc
dump_end_dump_task.cc
dump_start_dump_task.cc
event_scheduler_event.cc
field.cc
file_writer.cc
i_chain_element.cc
i_connection_provider.cc
i_crawler.cc
i_data_formatter.cc
i_data_formatter_wrapper.cc
i_data_object.cc
i_dump_task.cc
i_object_reader.cc
i_object_reader_wrapper.cc
i_output_writer.cc
i_output_writer_wrapper.cc
i_progress_reporter.cc
i_progress_watcher.cc
item_processing_data.cc
mysql_chain_element_options.cc
mysql_crawler.cc
mysql_field.cc
mysql_function.cc
mysql_object_reader.cc
mysql_object_reader_options.cc
mysqldump_tool_chain_maker.cc
mysqldump_tool_chain_maker_options.cc
object_filter.cc
object_queue.cc
pattern_matcher.cc
privilege.cc
row.cc
row_group_dump_task.cc
simple_id_generator.cc
single_transaction_connection_provider.cc
sql_formatter.cc
sql_formatter_options.cc
standard_progress_watcher.cc
standard_writer.cc
stored_procedure.cc
table.cc
table_deferred_indexes_dump_task.cc
table_definition_dump_task.cc
table_rows_dump_task.cc
tables_definition_ready_dump_task.cc
thread.cc
thread_group.cc
thread_specific_connection_provider.cc
trigger.cc
view.cc
../../sql-common/my_user.c)
ADD_CONVENIENCE_LIBRARY(mysqlpump_lib ${MYSQLPUMP_LIB_SOURCES})
TARGET_LINK_LIBRARIES(mysqlpump_lib
client_base ${LZ4_LIBRARY})
ADD_COMPILE_FLAGS(
compression_writer.cc
mysqldump_tool_chain_maker.cc
COMPILE_FLAGS -I${LZ4_INCLUDE_DIR}
)
MYSQL_ADD_EXECUTABLE(mysqlpump program.cc)
TARGET_LINK_LIBRARIES(mysqlpump mysqlpump_lib ${LOCAL_BOOST_LIB})
IF(USING_SYSTEM_BOOST)
TARGET_LINK_LIBRARIES(mysqlpump "-lboost_system")
TARGET_LINK_LIBRARIES(mysqlpump "-lboost_chrono")
ENDIF()
SET_TARGET_PROPERTIES(mysqlpump PROPERTIES HAS_CXX TRUE)

View File

@ -1,169 +0,0 @@
/*
Copyright (c) 2015, 2017 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-1301 USA
*/
#include "abstract_chain_element.h"
using namespace Mysql::Tools::Dump;
my_boost::atomic_uint64_t Abstract_chain_element::next_id;
uint64 Abstract_chain_element::get_id() const
{
return m_id;
}
Abstract_chain_element::Abstract_chain_element(
Mysql::I_callable<bool, const Mysql::Tools::Base::Message_data&>*
message_handler, Simple_id_generator* object_id_generator)
: m_id(Abstract_chain_element::next_id++),
m_message_handler(message_handler),
m_item_processed_callback(this,
&Abstract_chain_element::item_completion_in_child_callback_wrapper),
m_item_processed_complete_callback(this,
&Abstract_chain_element::
item_completion_in_child_completes_task_callback),
m_object_id_generator(object_id_generator)
{}
void Abstract_chain_element::object_processing_starts(
Item_processing_data* item_to_process)
{
this->report_object_processing_started(item_to_process);
item_to_process->start_processing();
}
Item_processing_data* Abstract_chain_element::object_to_be_processed_in_child(
Item_processing_data* current_item_data,
I_chain_element* child_chain_element)
{
return this->task_to_be_processed_in_child(
current_item_data, child_chain_element,
current_item_data->get_process_task_object(),
(current_item_data->have_completion_callback()
|| this->need_callbacks_in_child())
? &m_item_processed_callback : NULL);
}
Item_processing_data* Abstract_chain_element::new_task_created(
I_dump_task* dump_task_created)
{
return new Item_processing_data(
NULL, dump_task_created, this,
this->need_callbacks_in_child()
? &m_item_processed_complete_callback : NULL,
NULL);
}
Item_processing_data* Abstract_chain_element::new_chain_created(
Chain_data* new_chain_data, Item_processing_data* parent_processing_data,
I_chain_element* child_chain_element)
{
Item_processing_data* new_item_to_process=
this->object_to_be_processed_in_child(
parent_processing_data, child_chain_element);
parent_processing_data->set_had_chain_created();
this->report_new_chain_created(new_item_to_process);
return new_item_to_process;
}
Item_processing_data* Abstract_chain_element::new_chain_created(
Item_processing_data* current_item_data, I_dump_task* dump_task_created)
{
Item_processing_data* new_item_to_process=
this->task_to_be_processed_in_child(
current_item_data, this, dump_task_created,
(current_item_data->have_completion_callback()
|| this->need_callbacks_in_child())
? &m_item_processed_complete_callback : NULL);
current_item_data->set_had_chain_created();
this->report_new_chain_created(new_item_to_process);
return new_item_to_process;
}
void Abstract_chain_element::object_processing_ends(
Item_processing_data* processed_item)
{
if (processed_item != NULL && processed_item->end_processing())
{
this->report_object_processing_ended(processed_item);
if (processed_item->call_completion_callback_at_end())
{
delete processed_item;
}
}
}
uint64 Abstract_chain_element::generate_new_object_id()
{
return m_object_id_generator->create_id();
}
Simple_id_generator* Abstract_chain_element::get_object_id_generator() const
{
return m_object_id_generator;
}
void Abstract_chain_element::pass_message(
const Mysql::Tools::Base::Message_data& message_data)
{
if (m_message_handler)
{
(*m_message_handler)(message_data);
}
}
Mysql::I_callable<bool, const Mysql::Tools::Base::Message_data&>*
Abstract_chain_element::get_message_handler() const
{
return m_message_handler;
}
bool Abstract_chain_element::need_callbacks_in_child()
{
return this->have_progress_watcher();
}
void Abstract_chain_element::item_completion_in_child_callback_wrapper(
Item_processing_data* item_processed)
{
this->item_completion_in_child_callback(item_processed);
}
void Abstract_chain_element::item_completion_in_child_completes_task_callback(
Item_processing_data* item_processed)
{
item_processed->get_process_task_object()->set_completed();
this->item_completion_in_child_callback_wrapper(item_processed);
}
void Abstract_chain_element::item_completion_in_child_callback(
Item_processing_data* item_processed)
{
this->object_processing_ends(item_processed->get_parent_item_data());
}
Item_processing_data* Abstract_chain_element::task_to_be_processed_in_child(
Item_processing_data* current_item_data,
I_chain_element* child_chain_element, I_dump_task* task_to_be_processed,
Mysql::Instance_callback<
void, Item_processing_data*, Abstract_chain_element>* callback)
{
current_item_data->start_processing();
return new Item_processing_data(current_item_data->get_chain(),
task_to_be_processed, child_chain_element,
callback, current_item_data);
}

View File

@ -1,156 +0,0 @@
/*
Copyright (c) 2015, 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-1301 USA
*/
#ifndef ABSTRACT_CHAIN_ELEMENT_INCLUDED
#define ABSTRACT_CHAIN_ELEMENT_INCLUDED
#include "i_chain_element.h"
#include "abstract_progress_reporter.h"
#include "base/message_data.h"
#include "i_callable.h"
#include "simple_id_generator.h"
#include "instance_callback.h"
#include "item_processing_data.h"
namespace Mysql{
namespace Tools{
namespace Dump{
class Abstract_chain_element : public virtual I_chain_element,
public virtual Abstract_progress_reporter
{
public:
/**
Returns an application unique ID of this chain element object. This helps
progress watching with multiple parts of chain during all objects
processing.
*/
uint64 get_id() const;
protected:
Abstract_chain_element(
Mysql::I_callable<bool, const Mysql::Tools::Base::Message_data&>*
message_handler, Simple_id_generator* object_id_generator);
/**
Process task object with specified function if that task object can be
casted to type TType. Returns true if object was processed.
*/
template<typename TType, typename TClass> bool try_process_task(
Item_processing_data* item_to_process,
void (TClass::* processing_func)(TType*, Item_processing_data*))
{
TType* casted_object= dynamic_cast<TType*>(
item_to_process->get_process_task_object());
if (casted_object != NULL)
(((TClass*)this)->*processing_func)(casted_object, item_to_process);
return casted_object != NULL;
}
/**
Process task object with specified function if that task object can be
casted to type TType. Returns true if object was processed.
*/
template<typename TType, typename TClass> bool try_process_task(
Item_processing_data* item_to_process,
void(TClass::* processing_func)(TType*))
{
TType* casted_object= dynamic_cast<TType*>(
item_to_process->get_process_task_object());
if (casted_object != NULL)
(((TClass*)this)->*processing_func)(casted_object);
return casted_object != NULL;
}
void object_processing_starts(Item_processing_data* item_to_process);
Item_processing_data* object_to_be_processed_in_child(
Item_processing_data* current_item_data,
I_chain_element* child_chain_element);
Item_processing_data* new_task_created(I_dump_task* dump_task_created);
Item_processing_data* new_chain_created(
Chain_data* new_chain_data, Item_processing_data* parent_processing_data,
I_chain_element* child_chain_element);
Item_processing_data* new_chain_created(
Item_processing_data* current_item_data,
I_dump_task* dump_task_created);
void object_processing_ends(Item_processing_data* processed_item);
uint64 generate_new_object_id();
Simple_id_generator* get_object_id_generator() const;
/**
Passes message to message callback.
*/
void pass_message(const Mysql::Tools::Base::Message_data& message_data);
Mysql::I_callable<bool, const Mysql::Tools::Base::Message_data&>*
get_message_handler() const;
protected:
virtual bool need_callbacks_in_child();
private:
/**
Wrapper on item_completion_in_child_callback which allows creation of
pointer to function which will then fetch correct virtual method pointer.
*/
void item_completion_in_child_callback_wrapper(
Item_processing_data* item_processed);
/**
Wrapper on item_completion_in_child_callback_wrapper which also sets
precessed task to be fully completed.
*/
void item_completion_in_child_completes_task_callback(
Item_processing_data* item_processed);
void item_completion_in_child_callback(Item_processing_data* item_processed);
Item_processing_data* task_to_be_processed_in_child(
Item_processing_data* current_item_data,
I_chain_element* child_chain_element,
I_dump_task* task_to_be_processed,
Mysql::Instance_callback<
void, Item_processing_data*, Abstract_chain_element>*
callback);
uint64 m_id;
Mysql::I_callable<bool, const Mysql::Tools::Base:: Message_data&>*
m_message_handler;
Mysql::Instance_callback<void, Item_processing_data*, Abstract_chain_element>
m_item_processed_callback;
Mysql::Instance_callback<void, Item_processing_data*, Abstract_chain_element>
m_item_processed_complete_callback;
Simple_id_generator* m_object_id_generator;
/**
Stores next chain element ID to be used. Used as ID generator.
*/
static my_boost::atomic_uint64_t next_id;
};
}
}
}
#endif

View File

@ -1,60 +0,0 @@
/*
Copyright (c) 2015, 2016 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-1301 USA
*/
#include "abstract_connection_provider.h"
#include "instance_callback.h"
using namespace Mysql::Tools::Dump;
int64 Abstract_connection_provider::Message_handler_wrapper::pass_message(
const Mysql::Tools::Base::Message_data& message)
{
if (m_message_handler != NULL)
{
return (*m_message_handler)(message) ? -1 : 0;
}
return 0;
}
Abstract_connection_provider::Message_handler_wrapper::Message_handler_wrapper(
Mysql::I_callable<bool, const Mysql::Tools::Base::Message_data&>*
message_handler)
: m_message_handler(message_handler)
{}
Mysql::Tools::Base::Mysql_query_runner*
Abstract_connection_provider::create_new_runner(
Mysql::I_callable<bool, const Mysql::Tools::Base::Message_data&>*
message_handler)
{
MYSQL* connection= m_connection_factory->create_connection();
Message_handler_wrapper* message_wrapper=
new Message_handler_wrapper(message_handler);
I_callable<int64, const Mysql::Tools::Base::Message_data&>* callback
= new Mysql::Instance_callback_own<
int64, const Mysql::Tools::Base::Message_data&,
Message_handler_wrapper>(
message_wrapper, &Message_handler_wrapper::pass_message);
return &((new Mysql::Tools::Base::Mysql_query_runner(connection))
->add_message_callback(callback));
}
Abstract_connection_provider::Abstract_connection_provider(
Mysql::Tools::Base::I_connection_factory* connection_factory)
: m_connection_factory(connection_factory)
{}

View File

@ -1,61 +0,0 @@
/*
Copyright (c) 2015, 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-1301 USA
*/
#ifndef ABSTRACT_CONNECTION_PROVIDER_INCLUDED
#define ABSTRACT_CONNECTION_PROVIDER_INCLUDED
#include "i_connection_provider.h"
#include "base/i_connection_factory.h"
#include "i_callable.h"
namespace Mysql{
namespace Tools{
namespace Dump{
class Abstract_connection_provider : public I_connection_provider
{
protected:
Abstract_connection_provider(
Mysql::Tools::Base::I_connection_factory* connection_factory);
virtual Mysql::Tools::Base::Mysql_query_runner* create_new_runner(
Mysql::I_callable<bool, const Mysql::Tools::Base::Message_data&>*
message_handler);
private:
Mysql::Tools::Base::I_connection_factory* m_connection_factory;
class Message_handler_wrapper
{
public:
Message_handler_wrapper(
Mysql::I_callable<bool, const Mysql::Tools::Base::Message_data&>*
message_handler);
int64 pass_message(const Mysql::Tools::Base::Message_data& message);
private:
Mysql::I_callable<bool, const Mysql::Tools::Base::Message_data&>*
m_message_handler;
};
};
}
}
}
#endif

View File

@ -1,118 +0,0 @@
/*
Copyright (c) 2015, 2018 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-1301 USA
*/
#include "abstract_crawler.h"
#include "dump_end_dump_task.h"
#include "this_thread.h"
#include <boost/date_time.hpp>
using namespace Mysql::Tools::Dump;
my_boost::atomic_uint64_t Abstract_crawler::next_chain_id;
Abstract_crawler::Abstract_crawler(
Mysql::I_callable<bool, const Mysql::Tools::Base::Message_data&>*
message_handler, Simple_id_generator* object_id_generator,
Mysql::Tools::Base::Abstract_program* program)
: Abstract_chain_element(message_handler, object_id_generator),
m_program(program)
{}
Abstract_crawler::~Abstract_crawler()
{
for (std::vector<I_dump_task*>::iterator it= m_dump_tasks_created.begin();
it != m_dump_tasks_created.end(); ++it)
{
delete *it;
}
}
void Abstract_crawler::register_chain_maker(I_chain_maker* new_chain_maker)
{
m_chain_makers.push_back(new_chain_maker);
}
Mysql::Tools::Base::Abstract_program* Abstract_crawler::get_program()
{
return m_program;
}
void Abstract_crawler::process_dump_task(I_dump_task* new_dump_task)
{
/*
Add the tasks to this list so that even if we error out,
cleanup is done properly.
*/
m_dump_tasks_created.push_back(new_dump_task);
/* in case of error stop all further processing */
if (get_program()->get_error_code())
return;
Item_processing_data* main_item_processing_data=
this->new_task_created(new_dump_task);
this->object_processing_starts(main_item_processing_data);
for (std::vector<I_chain_maker*>::iterator it= m_chain_makers.begin();
it != m_chain_makers.end(); ++it)
{
uint64 new_chain_id= next_chain_id++;
Chain_data* chain_data= new Chain_data(new_chain_id);
I_object_reader* chain= (*it)->create_chain(chain_data, new_dump_task);
if (chain != NULL)
{
main_item_processing_data->set_chain(chain_data);
chain->read_object(
this->new_chain_created(
chain_data, main_item_processing_data, chain));
}
else
{
delete chain_data;
}
}
this->object_processing_ends(main_item_processing_data);
}
void Abstract_crawler::wait_for_tasks_completion()
{
for (std::vector<I_dump_task*>::iterator it= m_dump_tasks_created.begin();
it != m_dump_tasks_created.end(); ++it)
{
while ((*it)->is_completed() == false)
{
/* in case of error stop all running queues */
if (get_program()->get_error_code())
{
for (std::vector<I_chain_maker*>::iterator it= m_chain_makers.begin();
it != m_chain_makers.end(); ++it)
{
(*it)->stop_queues();
}
return;
}
my_boost::this_thread::sleep(boost::posix_time::milliseconds(1));
}
}
}
bool Abstract_crawler::need_callbacks_in_child()
{
return true;
}

View File

@ -1,70 +0,0 @@
/*
Copyright (c) 2015, 2016, 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-1301 USA
*/
#ifndef ABSTRACT_CRAWLER_INCLUDED
#define ABSTRACT_CRAWLER_INCLUDED
#include "i_crawler.h"
#include "abstract_chain_element.h"
#include "i_chain_maker.h"
#include "i_dump_task.h"
#include "base/abstract_program.h"
namespace Mysql{
namespace Tools{
namespace Dump{
class Abstract_crawler : public Abstract_chain_element,
public virtual I_crawler
{
public:
/**
Adds new Chain Maker to ask for chains for found objects.
*/
virtual void register_chain_maker(I_chain_maker* new_chain_maker);
~Abstract_crawler();
protected:
Abstract_crawler(
Mysql::I_callable<bool, const Mysql::Tools::Base::Message_data&>*
message_handler, Simple_id_generator* object_id_generator,
Mysql::Tools::Base::Abstract_program* program);
/**
Routine for performing common work on each enumerated DB object.
*/
void process_dump_task(I_dump_task* new_dump_task);
void wait_for_tasks_completion();
bool need_callbacks_in_child();
Mysql::Tools::Base::Abstract_program* get_program();
private:
std::vector<I_chain_maker*> m_chain_makers;
std::vector<I_dump_task*> m_dump_tasks_created;
/**
Stores next chain ID to be used. Used as ID generator.
*/
static my_boost::atomic_uint64_t next_chain_id;
Mysql::Tools::Base::Abstract_program* m_program;
};
}
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More