diff options
Diffstat (limited to 'libmysqld')
-rw-r--r-- | libmysqld/CMakeLists.txt | 213 | ||||
-rw-r--r-- | libmysqld/Makefile.am | 237 | ||||
-rw-r--r-- | libmysqld/emb_qcache.cc | 12 | ||||
-rw-r--r-- | libmysqld/emb_qcache.h | 9 | ||||
-rw-r--r-- | libmysqld/embedded_priv.h | 6 | ||||
-rw-r--r-- | libmysqld/examples/CMakeLists.txt | 62 | ||||
-rw-r--r-- | libmysqld/examples/Makefile.am | 57 | ||||
-rw-r--r-- | libmysqld/lib_sql.cc | 220 | ||||
-rw-r--r-- | libmysqld/libmysqld.c | 47 | ||||
-rw-r--r-- | libmysqld/libmysqld.def | 5 |
10 files changed, 314 insertions, 554 deletions
diff --git a/libmysqld/CMakeLists.txt b/libmysqld/CMakeLists.txt index 431f54abd22..eaf14b8a65a 100644 --- a/libmysqld/CMakeLists.txt +++ b/libmysqld/CMakeLists.txt @@ -11,103 +11,40 @@ # # 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 - -SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") -SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") - -# Need to set USE_TLS, since __declspec(thread) approach to thread local -# storage does not work properly in DLLs. -IF(WIN32) - ADD_DEFINITIONS(-DUSE_TLS) -ENDIF(WIN32) - -ADD_DEFINITIONS(-DMYSQL_SERVER -DEMBEDDED_LIBRARY -DHAVE_DLOPEN) - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include - ${CMAKE_SOURCE_DIR}/libmysqld - ${CMAKE_SOURCE_DIR}/libmysql - ${CMAKE_SOURCE_DIR}/sql - ${CMAKE_SOURCE_DIR}/regex - ${CMAKE_SOURCE_DIR}/extra/yassl/include - ${CMAKE_SOURCE_DIR}/zlib) - -SET(GEN_SOURCES ${CMAKE_SOURCE_DIR}/sql/sql_yacc.cc - ${CMAKE_SOURCE_DIR}/sql/sql_yacc.h - ${CMAKE_SOURCE_DIR}/sql/message.h - ${CMAKE_SOURCE_DIR}/sql/message.rc - ${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc - ${CMAKE_SOURCE_DIR}/sql/lex_hash.h) - -SET_SOURCE_FILES_PROPERTIES(${GEN_SOURCES} PROPERTIES GENERATED 1) - -# Include and add the directory path -SET(SOURCE_SUBLIBS TRUE) -SET(LIB_SOURCES "") - -INCLUDE(${CMAKE_SOURCE_DIR}/zlib/CMakeLists.txt) -FOREACH(rpath ${ZLIB_SOURCES}) - SET(LIB_SOURCES ${LIB_SOURCES} ../zlib/${rpath}) -ENDFOREACH(rpath) - -# FIXME only needed if build type is "Debug", but CMAKE_BUILD_TYPE is -# not set during configure time. -INCLUDE(${CMAKE_SOURCE_DIR}/dbug/CMakeLists.txt) -FOREACH(rpath ${DBUG_SOURCES}) - SET(LIB_SOURCES ${LIB_SOURCES} ../dbug/${rpath}) -ENDFOREACH(rpath) - -INCLUDE(${CMAKE_SOURCE_DIR}/extra/yassl/taocrypt/CMakeLists.txt) -FOREACH(rpath ${TAOCRYPT_SOURCES}) - SET(LIB_SOURCES ${LIB_SOURCES} ../extra/yassl/taocrypt/${rpath}) -ENDFOREACH(rpath) - -INCLUDE(${CMAKE_SOURCE_DIR}/extra/yassl/CMakeLists.txt) -FOREACH(rpath ${YASSL_SOURCES}) - SET(LIB_SOURCES ${LIB_SOURCES} ../extra/yassl/${rpath}) -ENDFOREACH(rpath) - -INCLUDE(${CMAKE_SOURCE_DIR}/strings/CMakeLists.txt) -FOREACH(rpath ${STRINGS_SOURCES}) - SET(LIB_SOURCES ${LIB_SOURCES} ../strings/${rpath}) -ENDFOREACH(rpath) - -INCLUDE(${CMAKE_SOURCE_DIR}/regex/CMakeLists.txt) -FOREACH(rpath ${REGEX_SOURCES}) - SET(LIB_SOURCES ${LIB_SOURCES} ../regex/${rpath}) -ENDFOREACH(rpath) - -INCLUDE(${CMAKE_SOURCE_DIR}/mysys/CMakeLists.txt) -FOREACH(rpath ${MYSYS_SOURCES}) - SET(LIB_SOURCES ${LIB_SOURCES} ../mysys/${rpath}) -ENDFOREACH(rpath) - -INCLUDE(${CMAKE_SOURCE_DIR}/vio/CMakeLists.txt) -FOREACH(rpath ${VIO_SOURCES}) - SET(LIB_SOURCES ${LIB_SOURCES} ../vio/${rpath}) -ENDFOREACH(rpath) - - - -FOREACH (ENGINE_LIB ${MYSQLD_STATIC_ENGINE_LIBS}) - STRING(TOUPPER ${ENGINE_LIB} ENGINE_LIB_UPPER) - SET(ENGINE_DIR ${${ENGINE_LIB_UPPER}_DIR}) - INCLUDE(${CMAKE_SOURCE_DIR}/storage/${ENGINE_DIR}/CMakeLists.txt) - FOREACH(rpath ${${ENGINE_LIB_UPPER}_SOURCES}) - SET(LIB_SOURCES ${LIB_SOURCES} ${CMAKE_SOURCE_DIR}/storage/${ENGINE_DIR}/${rpath}) - ENDFOREACH(rpath) -ENDFOREACH(ENGINE_LIB) - - -SET(SOURCE_SUBLIBS FALSE) - -SET(LIBMYSQLD_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +ADD_DEFINITIONS(-DMYSQL_SERVER -DEMBEDDED_LIBRARY + ${SSL_DEFINES}) + +INCLUDE_DIRECTORIES( +${CMAKE_SOURCE_DIR}/include +${CMAKE_SOURCE_DIR}/libmysql +${CMAKE_SOURCE_DIR}/libmysqld +${CMAKE_SOURCE_DIR}/sql +${CMAKE_BINARY_DIR}/sql +${CMAKE_SOURCE_DIR}/regex +${ZLIB_INCLUDE_DIR} +${SSL_INCLUDE_DIRS} +${SSL_INTERNAL_INCLUDE_DIRS} +${CMAKE_SOURCE_DIR}/sql/backup +) + +SET(GEN_SOURCES +${CMAKE_BINARY_DIR}/sql/sql_yacc.h +${CMAKE_BINARY_DIR}/sql/sql_yacc.cc +${CMAKE_BINARY_DIR}/sql/lex_hash.h +) + +SET_SOURCE_FILES_PROPERTIES(${GEN_SOURCES} PROPERTIES GENERATED TRUE) + +SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc ../libmysql/libmysql.c ../libmysql/errmsg.c ../client/get_password.c ../sql-common/client.c ../sql-common/my_time.c ../sql-common/my_user.c ../sql-common/pack.c + ../sql-common/client_plugin.c ../sql/password.c ../sql/discover.cc ../sql/derror.cc ../sql/field.cc ../sql/field_conv.cc - ../sql/filesort.cc ../sql/gstream.cc ../sql/ha_partition.cc + ../sql/filesort.cc ../sql/gstream.cc ../sql/signal_handler.cc ../sql/handler.cc ../sql/hash_filo.cc ../sql/hostname.cc ../sql/init.cc ../sql/item_buff.cc ../sql/item_cmpfunc.cc @@ -119,7 +56,7 @@ SET(LIBMYSQLD_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc ../sql/net_serv.cc ../sql/opt_range.cc ../sql/opt_sum.cc ../sql/parse_file.cc ../sql/procedure.cc ../sql/protocol.cc ../sql/records.cc ../sql/repl_failsafe.cc ../sql/rpl_filter.cc - ../sql/rpl_record.cc + ../sql/rpl_record.cc ../sql/sha2.cc ../sql/des_key_file.cc ../sql/rpl_injector.cc ../sql/set_var.cc ../sql/spatial.cc ../sql/sp_cache.cc ../sql/sp.cc ../sql/sp_head.cc ../sql/sp_pcontext.cc ../sql/sp_rcontext.cc ../sql/sql_acl.cc @@ -127,9 +64,11 @@ SET(LIBMYSQLD_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc ../sql/sql_class.cc ../sql/sql_crypt.cc ../sql/sql_cursor.cc ../sql/sql_db.cc ../sql/sql_delete.cc ../sql/sql_derived.cc ../sql/sql_do.cc ../sql/sql_error.cc ../sql/sql_handler.cc - ../sql/sql_help.cc ../sql/sql_insert.cc ../sql/sql_lex.cc + ../sql/sql_help.cc ../sql/sql_insert.cc ../sql/datadict.cc + ../sql/sql_admin.cc ../sql/sql_truncate.cc ../sql/sql_reload.cc + ../sql/sql_lex.cc ../sql/keycaches.cc ../sql/sql_list.cc ../sql/sql_load.cc ../sql/sql_locale.cc - ../sql/sql_binlog.cc ../sql/sql_manager.cc ../sql/sql_map.cc + ../sql/sql_binlog.cc ../sql/sql_manager.cc ../sql/sql_parse.cc ../sql/sql_partition.cc ../sql/sql_plugin.cc ../sql/debug_sync.cc ../sql/sql_prepare.cc ../sql/sql_rename.cc ../sql/sql_repl.cc @@ -139,32 +78,68 @@ SET(LIBMYSQLD_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc ../sql/sql_trigger.cc ../sql/sql_udf.cc ../sql/sql_union.cc ../sql/sql_update.cc ../sql/sql_view.cc ../sql/sql_profile.cc ../sql/strfunc.cc ../sql/table.cc ../sql/thr_malloc.cc - ../sql/time.cc ../sql/tztime.cc ../sql/uniques.cc ../sql/unireg.cc + ../sql/sql_time.cc ../sql/tztime.cc ../sql/uniques.cc ../sql/unireg.cc ../sql/partition_info.cc ../sql/sql_connect.cc - ../sql/scheduler.cc ../sql/event_parse_data.cc + ../sql/scheduler.cc ../sql/sql_audit.cc + ../sql/sql_alter.cc ../sql/sql_partition_admin.cc + ../sql/event_parse_data.cc + ../sql/sql_signal.cc ../sql/rpl_handler.cc + ../sql/rpl_utility.cc + ../sql/sys_vars.cc + ${CMAKE_BINARY_DIR}/sql/sql_builtin.cc + ../sql/mdl.cc ../sql/transaction.cc ${GEN_SOURCES} - ${LIB_SOURCES}) + ${MYSYS_LIBWRAP_SOURCE} +) -# Seems we cannot make a library without at least one source file. So use a -# dummy empty file -FILE(WRITE cmake_dummy.c " ") -# Tried use the correct ${GEN_SOURCES} as dependency, worked on Unix -# but not on Windows and Visual Studio generators. Likely because they -# are no real targets from the Visual Studio project files view. Added -# custom targets to "sql/CMakeLists.txt" and reference them here. -ADD_LIBRARY(mysqlserver STATIC ${LIBMYSQLD_SOURCES}) -ADD_DEPENDENCIES(mysqlserver GenServerSource GenError) -TARGET_LINK_LIBRARIES(mysqlserver) +ADD_CONVENIENCE_LIBRARY(sql_embedded ${SQL_EMBEDDED_SOURCES}) +DTRACE_INSTRUMENT(sql_embedded) +ADD_DEPENDENCIES(sql_embedded GenError GenServerSource) -# Add any additional libraries requested by engine(s) -FOREACH (ENGINE_LIB ${MYSQLD_STATIC_ENGINE_LIBS}) - STRING(TOUPPER ${ENGINE_LIB} ENGINE_LIB_UPPER) - IF(${ENGINE_LIB_UPPER}_LIBS) - TARGET_LINK_LIBRARIES(mysqlserver ${${ENGINE_LIB_UPPER}_LIBS}) - ENDIF(${ENGINE_LIB_UPPER}_LIBS) -ENDFOREACH(ENGINE_LIB) - -ADD_LIBRARY(libmysqld SHARED cmake_dummy.c libmysqld.def) -ADD_DEPENDENCIES(libmysqld mysqlserver) -TARGET_LINK_LIBRARIES(libmysqld mysqlserver wsock32) +# On Windows, static embedded server library is called mysqlserver.lib +# On Unix, it is libmysqld.a +IF(WIN32) + SET(MYSQLSERVER_OUTPUT_NAME mysqlserver) +ELSE() + SET(MYSQLSERVER_OUTPUT_NAME mysqld) +ENDIF() + + +SET(LIBS + dbug strings regex mysys vio + ${ZLIB_LIBRARY} ${SSL_LIBRARIES} + ${LIBWRAP} ${LIBCRYPT} ${LIBDL} + ${MYSQLD_STATIC_PLUGIN_LIBS} + sql_embedded +) + +# Some storage engine were compiled for embedded specifically +# (with corresponding target ${engine}_embedded) +SET(EMBEDDED_LIBS) +FOREACH(LIB ${LIBS}) + GET_TARGET_PROPERTY(EMBEDDED_LOCATION ${LIB}_embedded LOCATION) + IF(EMBEDDED_LOCATION) + LIST(APPEND EMBEDDED_LIBS ${LIB}_embedded) + ELSE() + LIST(APPEND EMBEDDED_LIBS ${LIB}) + ENDIF() +ENDFOREACH() + +MERGE_LIBRARIES(mysqlserver STATIC ${EMBEDDED_LIBS} + OUTPUT_NAME ${MYSQLSERVER_OUTPUT_NAME} COMPONENT Embedded) + +# Visual Studio users need debug static library +IF(MSVC) + INSTALL_DEBUG_TARGET(mysqlserver DESTINATION ${INSTALL_LIBDIR}/debug) +ENDIF() + +IF(UNIX) + INSTALL_DEBUG_TARGET(mysqlserver DESTINATION ${INSTALL_LIBDIR} RENAME + ${CMAKE_STATIC_LIBRARY_PREFIX}mysqld-debug) +ENDIF() + +IF(MSVC AND NOT DISABLE_SHARED) + MERGE_LIBRARIES(libmysqld SHARED ${LIBS} EXPORTS ${CLIENT_API_FUNCTIONS} + COMPONENT Embedded) +ENDIF() diff --git a/libmysqld/Makefile.am b/libmysqld/Makefile.am deleted file mode 100644 index 5b8255031ff..00000000000 --- a/libmysqld/Makefile.am +++ /dev/null @@ -1,237 +0,0 @@ -# Copyright (c) 2001-2008 MySQL AB, 2009 Sun Microsystems, Inc. -# Use is subject to license terms. -# -# This library 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 library 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 -# -# This file is public domain and comes with NO WARRANTY of any kind - -MYSQLDATAdir = $(localstatedir) -MYSQLSHAREdir = $(pkgdatadir) -MYSQLBASEdir= $(prefix) -MYSQLLIBdir= $(libdir) -pkgplugindir = $(pkglibdir)/plugin - -EXTRA_DIST = libmysqld.def CMakeLists.txt -DEFS = -DEMBEDDED_LIBRARY -DMYSQL_SERVER \ - -DDEFAULT_MYSQL_HOME="\"$(MYSQLBASEdir)\"" \ - -DMYSQL_DATADIR="\"$(MYSQLDATAdir)\"" \ - -DSHAREDIR="\"$(MYSQLSHAREdir)\"" \ - -DPLUGINDIR="\"$(pkgplugindir)\"" -INCLUDES= -I$(top_builddir)/include -I$(top_srcdir)/include \ - -I$(top_builddir)/sql -I$(top_srcdir)/sql \ - -I$(top_srcdir)/sql/examples \ - -I$(top_srcdir)/regex \ - $(openssl_includes) @ZLIB_INCLUDES@ \ - @condition_dependent_plugin_includes@ - -noinst_LIBRARIES = libmysqld_int.a -pkglib_LIBRARIES = libmysqld.a -SUBDIRS = . examples -libmysqld_sources= libmysqld.c lib_sql.cc emb_qcache.cc -libmysqlsources = errmsg.c get_password.c libmysql.c client.c pack.c \ - my_time.c - -noinst_HEADERS = embedded_priv.h emb_qcache.h - -sqlsources = derror.cc field.cc field_conv.cc strfunc.cc filesort.cc \ - ha_ndbcluster.cc ha_ndbcluster_cond.cc \ - ha_ndbcluster_binlog.cc ha_partition.cc \ - handler.cc sql_handler.cc \ - hostname.cc init.cc password.c \ - item.cc item_buff.cc item_cmpfunc.cc item_create.cc \ - item_func.cc item_strfunc.cc item_sum.cc item_timefunc.cc \ - item_geofunc.cc item_subselect.cc item_row.cc\ - item_xmlfunc.cc \ - key.cc lock.cc log.cc sql_state.c \ - log_event.cc rpl_record.cc \ - log_event_old.cc rpl_record_old.cc \ - protocol.cc net_serv.cc opt_range.cc \ - opt_sum.cc procedure.cc records.cc sql_acl.cc \ - sql_load.cc discover.cc sql_locale.cc \ - sql_profile.cc \ - sql_analyse.cc sql_base.cc sql_cache.cc sql_class.cc \ - sql_crypt.cc sql_db.cc sql_delete.cc sql_error.cc sql_insert.cc \ - sql_lex.cc sql_list.cc sql_manager.cc sql_map.cc \ - scheduler.cc sql_connect.cc sql_parse.cc \ - sql_prepare.cc sql_derived.cc sql_rename.cc \ - sql_select.cc sql_do.cc sql_show.cc set_var.cc \ - sql_string.cc sql_table.cc sql_test.cc sql_udf.cc \ - sql_update.cc sql_yacc.cc table.cc thr_malloc.cc time.cc \ - unireg.cc uniques.cc sql_union.cc hash_filo.cc \ - spatial.cc gstream.cc sql_help.cc tztime.cc sql_cursor.cc \ - sp_head.cc sp_pcontext.cc sp.cc sp_cache.cc sp_rcontext.cc \ - parse_file.cc sql_view.cc sql_trigger.cc my_decimal.cc \ - rpl_filter.cc sql_partition.cc sql_builtin.cc sql_plugin.cc \ - debug_sync.cc \ - sql_tablespace.cc \ - rpl_injector.cc my_user.c partition_info.cc \ - sql_servers.cc event_parse_data.cc - -libmysqld_int_a_SOURCES= $(libmysqld_sources) -nodist_libmysqld_int_a_SOURCES= $(libmysqlsources) $(sqlsources) -libmysqld_a_SOURCES= - -sqlstoragesources = $(EXTRA_libmysqld_a_SOURCES) -storagesources = @condition_dependent_plugin_modules@ -storageobjects = @condition_dependent_plugin_objects@ -storagesourceslinks = @condition_dependent_plugin_links@ - -# automake misses these -sql_yacc.cc sql_yacc.h: $(top_srcdir)/sql/sql_yacc.yy - -# The following libraries should be included in libmysqld.a -INC_LIB= $(top_builddir)/regex/libregex.a \ - $(top_builddir)/mysys/libmysys.a \ - $(top_builddir)/strings/libmystrings.a \ - $(top_builddir)/dbug/libdbug.a \ - $(top_builddir)/vio/libvio.a \ - @NDB_SCI_LIBS@ \ - @mysql_plugin_libs@ \ - $(yassl_inc_libs) - -if HAVE_YASSL -yassl_inc_libs= $(top_builddir)/extra/yassl/src/.libs/libyassl.a \ - $(top_builddir)/extra/yassl/taocrypt/src/.libs/libtaocrypt.a -endif - -# Storage engine specific compilation options -ha_ndbcluster.o:ha_ndbcluster.cc - $(CXXCOMPILE) @ndbcluster_includes@ $(LM_CFLAGS) -c $< - -ha_ndbcluster_cond.o:ha_ndbcluster_cond.cc - $(CXXCOMPILE) @ndbcluster_includes@ $(LM_CFLAGS) -c $< - -ha_ndbcluster_binlog.o: ha_ndbcluster_binlog.cc - $(CXXCOMPILE) @ndbcluster_includes@ $(LM_CFLAGS) -c $< - -# Until we can remove dependency on ha_ndbcluster.h -handler.o: handler.cc - $(CXXCOMPILE) @ndbcluster_includes@ $(LM_CFLAGS) -c $< - -# We need rules to compile these as no good way -# found to append fileslists that collected by configure -# to the sources list - -ha_federated.o:ha_federated.cc - $(CXXCOMPILE) $(LM_CFLAGS) -c $< - -ha_heap.o:ha_heap.cc - $(CXXCOMPILE) $(LM_CFLAGS) -c $< - -ha_innodb.o:ha_innodb.cc - $(CXXCOMPILE) $(LM_CFLAGS) -c $< - -ha_myisam.o:ha_myisam.cc - $(CXXCOMPILE) $(LM_CFLAGS) -c $< - -ha_myisammrg.o:ha_myisammrg.cc - $(CXXCOMPILE) $(LM_CFLAGS) -c $< - -# -# To make it easy for the end user to use the embedded library we -# generate a total libmysqld.a from all library files, - -# note - InnoDB libraries have circular dependencies, so in INC_LIB -# few libraries are present two times. Metrowerks linker doesn't like -# it at all. Traditional ar has no problems with it, but still there's no -# need to add the same file twice to the library, so 'sort -u' save us -# some time and spares unnecessary work. - -libmysqld.a: libmysqld_int.a $(INC_LIB) $(libmysqld_a_DEPENDENCIES) $(storageobjects) -if DARWIN_MWCC - mwld -lib -o $@ libmysqld_int.a `echo $(INC_LIB) | sort -u` $(storageobjects) -else - -rm -f libmysqld.a - if test "$(host_os)" = "netware" ; \ - then \ - $(libmysqld_a_AR) libmysqld.a $(INC_LIB) libmysqld_int.a $(storageobjects); \ - else \ - current_dir=`pwd`; \ - rm -rf tmp; mkdir tmp; \ - (for arc in $(INC_LIB) ./libmysqld_int.a; do \ - arpath=`echo $$arc|sed 's|[^/]*$$||'|sed 's|\.libs/$$||'`; \ - artmp=`echo $$arc|sed 's|^.*/|tmp/lib-|'`; \ - for F in `$(AR) t $$arc | grep -v SYMDEF`; do \ - if test -e "$$arpath/$$F" ; then echo "$$arpath/$$F"; else \ - mkdir $$artmp; cd $$artmp > /dev/null; \ - $(AR) x ../../$$arc; \ - cd $$current_dir > /dev/null; \ - ls $$artmp/* | grep -v SYMDEF; \ - continue 2; fi; done; \ - done; echo $(libmysqld_a_DEPENDENCIES) ) | sort -u | xargs $(AR) cq libmysqld.a ; \ - $(AR) r libmysqld.a $(storageobjects); \ - $(RANLIB) libmysqld.a ; \ - rm -rf tmp; \ - fi -endif - -## XXX: any time the client interface changes, we'll need to bump -## the version info for libmysqld; however, it's possible for the -## libmysqld interface to change without affecting the standard -## libmysqlclient interface. Should we make a separate version -## string for the two? -#libmysqld_la_LDFLAGS = -version-info @SHARED_LIB_VERSION@ -#CLEANFILES = $(libmysqld_la_LIBADD) libmysqld.la - -BUILT_SOURCES = link_sources - -CLEANFILES = $(BUILT_SOURCES) - -link_sources: - for f in $(sqlsources); do \ - rm -f $$f; \ - if test -e $(top_srcdir)/sql/$$f ; \ - then \ - @LN_CP_F@ $(top_srcdir)/sql/$$f $$f; \ - else \ - @LN_CP_F@ $(top_builddir)/sql/$$f $$f; \ - fi ; \ - done; \ - for f in $(libmysqlsources); do \ - rm -f $$f; \ - if test -e $(top_srcdir)/libmysql/$$f ; \ - then \ - @LN_CP_F@ $(top_srcdir)/libmysql/$$f $$f; \ - else \ - @LN_CP_F@ $(top_builddir)/libmysql/$$f $$f; \ - fi ; \ - done; \ - if test -n "$(sqlstoragesources)" ; \ - then \ - for f in "$(sqlstoragesources)"; do \ - rm -f "$$f"; \ - @LN_CP_F@ `find $(srcdir)/../sql -name "$$f"` "$$f"; \ - done; \ - fi; \ - if test -n "$(storagesources)" ; \ - then \ - rm -f $(storagesources); \ - for f in $(storagesourceslinks); do \ - @LN_CP_F@ $(top_srcdir)/$$f . ; \ - done; \ - fi; \ - rm -f client_settings.h; \ - @LN_CP_F@ $(top_srcdir)/libmysql/client_settings.h \ - client_settings.h; \ - echo timestamp > link_sources - - -clean-local: - rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlstoragesources) $(storagesources) | sed "s;\.lo;.c;g"`; \ - rm -f client_settings.h - -# Don't update the files from bitkeeper -%::SCCS/s.% diff --git a/libmysqld/emb_qcache.cc b/libmysqld/emb_qcache.cc index b4eddf39c1f..d263e5d5fe8 100644 --- a/libmysqld/emb_qcache.cc +++ b/libmysqld/emb_qcache.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (c) 2000, 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 General Public License as published by @@ -11,13 +11,16 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "sql_priv.h" +#include "my_global.h" // HAVE_* -#include "mysql_priv.h" #ifdef HAVE_QUERY_CACHE #include <mysql.h> #include "emb_qcache.h" #include "embedded_priv.h" +#include "sql_class.h" // THD void Querycache_stream::store_uchar(uchar c) { @@ -483,7 +486,8 @@ int emb_load_querycache_result(THD *thd, Querycache_stream *src) *prev_row= NULL; data->embedded_info->prev_ptr= prev_row; return_ok: - net_send_eof(thd, thd->server_status, thd->total_warn_count); + net_send_eof(thd, thd->server_status, + thd->warning_info->statement_warn_count()); DBUG_RETURN(0); err: DBUG_RETURN(1); diff --git a/libmysqld/emb_qcache.h b/libmysqld/emb_qcache.h index f53d5eb82fb..8fd166df88d 100644 --- a/libmysqld/emb_qcache.h +++ b/libmysqld/emb_qcache.h @@ -1,6 +1,4 @@ -/* - Copyright (c) 2003, 2005-2007 MySQL AB, 2009 Sun Microsystems, Inc. - Use is subject to license terms. +/* Copyright (c) 2003, 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 General Public License as published by @@ -13,8 +11,9 @@ 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 -*/ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "sql_cache.h" /* Query_cache_block */ class Querycache_stream { diff --git a/libmysqld/embedded_priv.h b/libmysqld/embedded_priv.h index 369b344d4bd..c096954a460 100644 --- a/libmysqld/embedded_priv.h +++ b/libmysqld/embedded_priv.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2004, 2006 MySQL AB +/* Copyright (c) 2001, 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 General Public License as published by @@ -11,10 +11,12 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Prototypes for the embedded version of MySQL */ +#include <sql_common.h> + C_MODE_START void lib_connection_phase(NET *net, int phase); void init_embedded_mysql(MYSQL *mysql, int client_flag); diff --git a/libmysqld/examples/CMakeLists.txt b/libmysqld/examples/CMakeLists.txt index d7f994d9b9f..c4055a56303 100644 --- a/libmysqld/examples/CMakeLists.txt +++ b/libmysqld/examples/CMakeLists.txt @@ -1,5 +1,4 @@ -# Copyright (c) 2006-2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc. -# Use is subject to license terms. +# Copyright (c) 2006, 2011, 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 @@ -12,32 +11,51 @@ # # 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 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/libmysqld/include - ${CMAKE_SOURCE_DIR}/regex - ${CMAKE_SOURCE_DIR}/zlib + ${CMAKE_SOURCE_DIR}/regex ${CMAKE_SOURCE_DIR}/tests - ${CMAKE_SOURCE_DIR}/extra/yassl/include) + ${READLINE_INCLUDE_DIR} + ) -# Currently does not work with DBUG, there are missing symbols reported. -IF(WIN32) - ADD_DEFINITIONS(-DUSE_TLS) -ENDIF(WIN32) -ADD_DEFINITIONS(-DEMBEDDED_LIBRARY) +ADD_DEFINITIONS(-DEMBEDDED_LIBRARY -UMYSQL_CLIENT) -ADD_EXECUTABLE(mysql_embedded ../../client/completion_hash.cc - ../../client/mysql.cc ../../client/readline.cc - ../../client/sql_string.cc) -TARGET_LINK_LIBRARIES(mysql_embedded debug dbug strings mysys vio yassl taocrypt regex ws2_32) -TARGET_LINK_LIBRARIES(mysql_embedded libmysqld) -ADD_EXECUTABLE(mysqltest_embedded ../../client/mysqltest.cc) -TARGET_LINK_LIBRARIES(mysqltest_embedded debug dbug strings mysys vio yassl taocrypt regex ws2_32) -TARGET_LINK_LIBRARIES(mysqltest_embedded libmysqld) +MYSQL_ADD_EXECUTABLE(mysql_embedded ../../client/completion_hash.cc + ../../client/mysql.cc ../../client/readline.cc) +TARGET_LINK_LIBRARIES(mysql_embedded mysqlserver) +IF(UNIX) + ADD_DEFINITIONS(${READLINE_DEFINES}) + TARGET_LINK_LIBRARIES(mysql_embedded ${READLINE_LIBRARY}) +ENDIF(UNIX) -ADD_EXECUTABLE(mysql_client_test_embedded ../../tests/mysql_client_test.c) -TARGET_LINK_LIBRARIES(mysql_client_test_embedded debug dbug strings mysys vio yassl taocrypt regex ws2_32) -TARGET_LINK_LIBRARIES(mysql_client_test_embedded libmysqld) +MYSQL_ADD_EXECUTABLE(mysqltest_embedded ../../client/mysqltest.cc) +TARGET_LINK_LIBRARIES(mysqltest_embedded mysqlserver) + + +IF(CMAKE_GENERATOR MATCHES "Xcode") +# It does not seem possible to tell Xcode the resulting target might need +# to be linked with C++ runtime. The project needs to have at least one C++ +# file. Add a dummy one. + ADD_CUSTOM_COMMAND(OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/mysql_client_test_embedded_dummy.cc + COMMAND ${CMAKE_COMMAND} -E touch + ${CMAKE_CURRENT_BINARY_DIR}/mysql_client_test_embedded_dummy.cc + ) + MYSQL_ADD_EXECUTABLE(mysql_client_test_embedded + ${CMAKE_CURRENT_BINARY_DIR}/mysql_client_test_embedded_dummy.cc + ../../tests/mysql_client_test.c) +ELSE() + MYSQL_ADD_EXECUTABLE(mysql_client_test_embedded ../../tests/mysql_client_test.c) + SET_TARGET_PROPERTIES(mysql_client_test_embedded PROPERTIES HAS_CXX TRUE) +ENDIF() +TARGET_LINK_LIBRARIES(mysql_client_test_embedded mysqlserver) + +IF(UNIX) +SET_TARGET_PROPERTIES(mysql_embedded PROPERTIES ENABLE_EXPORTS TRUE) +SET_TARGET_PROPERTIES(mysqltest_embedded PROPERTIES ENABLE_EXPORTS TRUE) +SET_TARGET_PROPERTIES(mysql_client_test_embedded PROPERTIES ENABLE_EXPORTS TRUE) +ENDIF() diff --git a/libmysqld/examples/Makefile.am b/libmysqld/examples/Makefile.am deleted file mode 100644 index a0f1a64ffdc..00000000000 --- a/libmysqld/examples/Makefile.am +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (c) 2001, 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 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 - -noinst_PROGRAMS = mysql -bin_PROGRAMS = mysqltest_embedded mysql_client_test_embedded -client_sources = $(nodist_mysqltest_embedded_SOURCES) $(nodist_mysql_SOURCES) -tests_sources = $(nodist_mysql_client_test_embedded_SOURCES) -BUILT_SOURCES = link_sources -CLEANFILES = $(client_sources) $(tests_sources) $(BUILT_SOURCES) -EXTRA_DIST = CMakeLists.txt - -link_sources: - for f in $(client_sources); do \ - rm -f $$f; \ - @LN_CP_F@ $(top_srcdir)/client/$$f $$f; \ - done; \ - for f in $(tests_sources); do \ - rm -f $$f; \ - @LN_CP_F@ $(top_srcdir)/tests/$$f $$f; \ - done - echo timestamp > link_sources - -DEFS = -DEMBEDDED_LIBRARY -INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(srcdir) \ - -I$(top_srcdir) -I$(top_srcdir)/client -I$(top_srcdir)/regex \ - -I$(top_srcdir)/tests $(openssl_includes) -LIBS = @LIBS@ @WRAPLIBS@ @CLIENT_LIBS@ $(yassl_libs) -LDADD = @CLIENT_EXTRA_LDFLAGS@ ../libmysqld.a @LIBDL@ $(CXXLDFLAGS) \ - @NDB_SCI_LIBS@ - -mysqltest_embedded_LINK = $(CXXLINK) -nodist_mysqltest_embedded_SOURCES = mysqltest.cc -mysqltest_embedded_LDADD = $(LDADD) $(top_builddir)/regex/libregex.a \ - @MYSQLD_EXTRA_LDFLAGS@ - -nodist_mysql_SOURCES = mysql.cc readline.cc completion_hash.cc \ - my_readline.h sql_string.h completion_hash.h -mysql_LDADD = @readline_link@ @TERMCAP_LIB@ $(LDADD) - -mysql_client_test_embedded_LINK = $(CXXLINK) -nodist_mysql_client_test_embedded_SOURCES = mysql_client_test.c -mysql_client_test.o: $(top_srcdir)/tests/mysql_client_fw.c - -# Don't update the files from bitkeeper -%::SCCS/s.% diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index 4afe02efbdb..2de7217f10b 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -35,7 +35,6 @@ C_MODE_START #include <mysql.h> #undef ER #include "errmsg.h" -#include <sql_common.h> #include "embedded_priv.h" extern unsigned int mysql_server_last_errno; @@ -56,7 +55,7 @@ extern "C" void unireg_clear(int exit_code) handler based on whether thread is in client/server context */ -static int embedded_error_handler(uint error, const char *str, myf MyFlags) +static void embedded_error_handler(uint error, const char *str, myf MyFlags) { DBUG_ENTER("embedded_error_handler"); @@ -66,7 +65,7 @@ static int embedded_error_handler(uint error, const char *str, myf MyFlags) server error handler. */ DBUG_RETURN(current_thd ? my_message_sql(error, str, MyFlags): - my_message_no_curses(error, str, MyFlags)); + my_message_stderr(error, str, MyFlags)); } /* @@ -93,7 +92,7 @@ void embedded_get_error(MYSQL *mysql, MYSQL_DATA *data) strmake(net->last_error, ei->info, sizeof(net->last_error)-1); memcpy(net->sqlstate, ei->sqlstate, sizeof(net->sqlstate)); mysql->server_status= ei->server_status; - my_free(data, MYF(0)); + my_free(data); } static my_bool @@ -115,7 +114,7 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, thd= (THD *) mysql->thd; } -#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER) +#if defined(ENABLED_PROFILING) thd->profiling.start_new_query(); #endif @@ -130,14 +129,14 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, /* Clear result variables */ thd->clear_error(); - thd->main_da.reset_diagnostics_area(); + thd->stmt_da->reset_diagnostics_area(); mysql->affected_rows= ~(my_ulonglong) 0; mysql->field_count= 0; net_clear_error(net); thd->current_stmt= stmt; + thd->thread_stack= (char*) &thd; thd->store_globals(); // Fix if more than one connect - lex_start(thd); /* We have to call free_old_query before we start to fill mysql->fields for new query. In the case of embedded server we collect field data @@ -156,13 +155,14 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, result= dispatch_command(command, thd, (char *) arg, arg_length); thd->cur_data= 0; + thd->mysys_var= NULL; if (!skip_check) result= thd->is_error() ? -1 : 0; thd->mysys_var= 0; -#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER) +#if defined(ENABLED_PROFILING) thd->profiling.finish_current_query(); #endif @@ -171,7 +171,7 @@ end: return result; } -static void emb_flush_use_result(MYSQL *mysql) +static void emb_flush_use_result(MYSQL *mysql, my_bool) { THD *thd= (THD*) mysql->thd; if (thd->cur_data) @@ -227,7 +227,7 @@ static MYSQL_FIELD *emb_list_fields(MYSQL *mysql) res= ((THD*) mysql->thd)->cur_data; ((THD*) mysql->thd)->cur_data= 0; mysql->field_alloc= res->alloc; - my_free(res,MYF(0)); + my_free(res); mysql->status= MYSQL_STATUS_READY; return mysql->fields; } @@ -240,7 +240,7 @@ static my_bool emb_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt) stmt->stmt_id= thd->client_stmt_id; stmt->param_count= thd->client_param_count; stmt->field_count= 0; - mysql->warning_count= thd->total_warn_count; + mysql->warning_count= thd->warning_info->statement_warn_count(); if (thd->first_data) { @@ -256,7 +256,7 @@ static my_bool emb_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt) stmt->fields= mysql->fields; stmt->mem_root= res->alloc; mysql->fields= NULL; - my_free(res,MYF(0)); + my_free(res); } return 0; @@ -313,7 +313,7 @@ static my_bool emb_read_query_result(MYSQL *mysql) thd->cur_data= res; } else - my_free(res, MYF(0)); + my_free(res); return 0; } @@ -357,7 +357,7 @@ int emb_read_binary_rows(MYSQL_STMT *stmt) return 1; } stmt->result= *data; - my_free((char *) data, MYF(0)); + my_free(data); set_stmt_errmsg(stmt, &stmt->mysql->net); return 0; } @@ -427,7 +427,7 @@ static void emb_free_embedded_thd(MYSQL *mysql) static const char * emb_read_statistics(MYSQL *mysql) { THD *thd= (THD*)mysql->thd; - return thd->is_error() ? thd->main_da.message() : ""; + return thd->is_error() ? thd->stmt_da->message() : ""; } @@ -436,11 +436,10 @@ static MYSQL_RES * emb_store_result(MYSQL *mysql) return mysql_store_result(mysql); } -int emb_read_change_user_result(MYSQL *mysql, - char *buff __attribute__((unused)), - const char *passwd __attribute__((unused))) +int emb_read_change_user_result(MYSQL *mysql) { - return mysql_errno(mysql); + mysql->net.read_pos= (uchar*)""; // fake an OK packet + return mysql_errno(mysql) ? packet_error : 1 /* length of the OK packet */; } MYSQL_METHODS embedded_methods= @@ -451,6 +450,7 @@ MYSQL_METHODS embedded_methods= emb_store_result, emb_fetch_lengths, emb_flush_use_result, + emb_read_change_user_result, emb_list_fields, emb_read_prepare_result, emb_stmt_execute, @@ -459,7 +459,6 @@ MYSQL_METHODS embedded_methods= emb_free_embedded_thd, emb_read_statistics, emb_read_query_result, - emb_read_change_user_result, emb_read_rows_from_cursor }; @@ -503,6 +502,10 @@ int init_embedded_server(int argc, char **argv, char **groups) char *fake_argv[] = { (char *)"", 0 }; const char *fake_groups[] = { "server", "embedded", 0 }; my_bool acl_error; + + if (my_thread_init()) + return 1; + if (argc) { argcp= &argc; @@ -524,15 +527,31 @@ int init_embedded_server(int argc, char **argv, char **groups) */ logger.init_base(); - if (init_common_variables("my", *argcp, *argvp, (const char **)groups)) + orig_argc= *argcp; + orig_argv= *argvp; + if (load_defaults("my", (const char **)groups, argcp, argvp)) + return 1; + defaults_argc= *argcp; + defaults_argv= *argvp; + remaining_argc= *argcp; + remaining_argv= *argvp; + + /* Must be initialized early for comparison of options name */ + system_charset_info= &my_charset_utf8_general_ci; + sys_var_init(); + + if (init_common_variables()) { mysql_server_end(); return 1; } - + + mysql_data_home= mysql_real_data_home; + mysql_data_home_len= mysql_real_data_home_len; + /* Get default temporary directory */ opt_mysql_tmpdir=getenv("TMPDIR"); /* Use this if possible */ -#if defined( __WIN__) || defined(OS2) +#if defined(__WIN__) if (!opt_mysql_tmpdir) opt_mysql_tmpdir=getenv("TEMP"); if (!opt_mysql_tmpdir) @@ -541,6 +560,7 @@ int init_embedded_server(int argc, char **argv, char **groups) if (!opt_mysql_tmpdir || !opt_mysql_tmpdir[0]) opt_mysql_tmpdir=(char*) P_tmpdir; /* purecov: inspected */ + init_ssl(); umask(((~my_umask) & 0666)); if (init_server_components()) { @@ -599,7 +619,7 @@ int init_embedded_server(int argc, char **argv, char **groups) void end_embedded_server() { - my_free((char*) copy_arguments_ptr, MYF(MY_ALLOW_ZERO_PTR)); + my_free(copy_arguments_ptr); copy_arguments_ptr=0; clean_up(0); } @@ -610,6 +630,7 @@ void init_embedded_mysql(MYSQL *mysql, int client_flag) THD *thd = (THD *)mysql->thd; thd->mysql= mysql; mysql->server_version= server_version; + mysql->client_flag= client_flag; init_alloc_root(&mysql->field_alloc, 8192, 0); } @@ -640,10 +661,9 @@ void *create_embedded_thd(int client_flag) /* TODO - add init_connect command execution */ if (thd->variables.max_join_size == HA_POS_ERROR) - thd->options |= OPTION_BIG_SELECTS; + thd->variables.option_bits |= OPTION_BIG_SELECTS; thd->proc_info=0; // Remove 'login' thd->command=COM_SLEEP; - thd->version=refresh_version; thd->set_time(); thd->init_for_queries(); thd->client_capabilities= client_flag; @@ -674,15 +694,21 @@ err: int check_embedded_connection(MYSQL *mysql, const char *db) { int result; + LEX_STRING db_str = { (char*)db, db ? strlen(db) : 0 }; THD *thd= (THD*)mysql->thd; thd_init_client_charset(thd, mysql->charset->number); thd->update_charset(); Security_context *sctx= thd->security_ctx; sctx->host_or_ip= sctx->host= (char*) my_localhost; strmake(sctx->priv_host, (char*) my_localhost, MAX_HOSTNAME-1); - sctx->priv_user= sctx->user= my_strdup(mysql->user, MYF(0)); - result= check_user(thd, COM_CONNECT, NULL, 0, db, true); - net_end_statement(thd); + strmake(sctx->priv_user, mysql->user, USERNAME_LENGTH-1); + sctx->user= my_strdup(mysql->user, MYF(0)); + sctx->proxy_user[0]= 0; + sctx->master_access= GLOBAL_ACLS; // Full rights + /* Change database if necessary */ + if (!(result= (db && db[0] && mysql_change_db(thd, &db_str, FALSE)))) + my_ok(thd); + thd->protocol->end_statement(); emb_read_query_result(mysql); return result; } @@ -690,14 +716,15 @@ int check_embedded_connection(MYSQL *mysql, const char *db) #else int check_embedded_connection(MYSQL *mysql, const char *db) { + /* + we emulate a COM_CHANGE_USER user here, + it's easier than to emulate the complete 3-way handshake + */ + char buf[USERNAME_LENGTH + SCRAMBLE_LENGTH + 1 + 2*NAME_LEN + 2], *end; + NET *net= &mysql->net; THD *thd= (THD*)mysql->thd; Security_context *sctx= thd->security_ctx; - int result; - char scramble_buff[SCRAMBLE_LENGTH]; - int passwd_len; - thd_init_client_charset(thd, mysql->charset->number); - thd->update_charset(); if (mysql->options.client_ip) { sctx->host= my_strdup(mysql->options.client_ip, MYF(0)); @@ -708,36 +735,43 @@ int check_embedded_connection(MYSQL *mysql, const char *db) sctx->host_or_ip= sctx->host; if (acl_check_host(sctx->host, sctx->ip)) - { - result= ER_HOST_NOT_PRIVILEGED; goto err; - } - sctx->user= my_strdup(mysql->user, MYF(0)); + /* construct a COM_CHANGE_USER packet */ + end= strmake(buf, mysql->user, USERNAME_LENGTH) + 1; + + memset(thd->scramble, 55, SCRAMBLE_LENGTH); // dummy scramble + thd->scramble[SCRAMBLE_LENGTH]= 0; + if (mysql->passwd && mysql->passwd[0]) { - memset(thd->scramble, 55, SCRAMBLE_LENGTH); // dummy scramble - thd->scramble[SCRAMBLE_LENGTH]= 0; - scramble(scramble_buff, thd->scramble, mysql->passwd); - passwd_len= SCRAMBLE_LENGTH; + *end++= SCRAMBLE_LENGTH; + scramble(end, thd->scramble, mysql->passwd); + end+= SCRAMBLE_LENGTH; } else - passwd_len= 0; + *end++= 0; - if((result= check_user(thd, COM_CONNECT, - scramble_buff, passwd_len, db, true))) - goto err; + end= strmake(end, db ? db : "", NAME_LEN) + 1; - return 0; -err: + int2store(end, (ushort) mysql->charset->number); + end+= 2; + + /* acl_authenticate() takes the data from thd->net->read_pos */ + thd->net.read_pos= (uchar*)buf; + + if (acl_authenticate(thd, 0, end - buf)) { - NET *net= &mysql->net; - strmake(net->last_error, thd->main_da.message(), sizeof(net->last_error)-1); - memcpy(net->sqlstate, - mysql_errno_to_sqlstate(thd->main_da.sql_errno()), - sizeof(net->sqlstate)-1); + x_free(thd->security_ctx->user); + goto err; } - return result; + return 0; +err: + strmake(net->last_error, thd->main_da.message(), sizeof(net->last_error)-1); + memcpy(net->sqlstate, + mysql_errno_to_sqlstate(thd->main_da.sql_errno()), + sizeof(net->sqlstate)-1); + return 1; } #endif @@ -756,11 +790,6 @@ void THD::clear_data_list() cur_data= 0; } -void THD::clear_error() -{ - if (main_da.is_error()) - main_da.reset_diagnostics_area(); -} static char *dup_str_aux(MEM_ROOT *root, const char *from, uint length, CHARSET_INFO *fromcs, CHARSET_INFO *tocs) @@ -833,7 +862,7 @@ MYSQL_DATA *THD::alloc_new_dataset() static bool -write_eof_packet(THD *thd, uint server_status, uint total_warn_count) +write_eof_packet(THD *thd, uint server_status, uint statement_warn_count) { if (!thd->mysql) // bootstrap file handling return FALSE; @@ -850,7 +879,7 @@ write_eof_packet(THD *thd, uint server_status, uint total_warn_count) is cleared between substatements, and mysqltest gets confused */ thd->cur_data->embedded_info->warning_count= - (thd->spcont ? 0 : min(total_warn_count, 65535)); + (thd->spcont ? 0 : min(statement_warn_count, 65535)); return FALSE; } @@ -907,7 +936,7 @@ void Protocol_text::remove_last_row() } -bool Protocol::send_fields(List<Item> *list, uint flags) +bool Protocol::send_result_set_metadata(List<Item> *list, uint flags) { List_iterator_fast<Item> it(*list); Item *item; @@ -916,7 +945,7 @@ bool Protocol::send_fields(List<Item> *list, uint flags) CHARSET_INFO *thd_cs= thd->variables.character_set_results; CHARSET_INFO *cs= system_charset_info; MYSQL_DATA *data; - DBUG_ENTER("send_fields"); + DBUG_ENTER("send_result_set_metadata"); if (!thd->mysql) // bootstrap file handling DBUG_RETURN(0); @@ -951,10 +980,10 @@ bool Protocol::send_fields(List<Item> *list, uint flags) strlen(server_field.org_table_name), cs, thd_cs); client_field->org_name= dup_str_aux(field_alloc, server_field.org_col_name, strlen(server_field.org_col_name), cs, thd_cs); - if (item->collation.collation == &my_charset_bin || thd_cs == NULL) + if (item->charset_for_protocol() == &my_charset_bin || thd_cs == NULL) { /* No conversion */ - client_field->charsetnr= server_field.charsetnr; + client_field->charsetnr= item->charset_for_protocol()->number; client_field->length= server_field.length; } else @@ -966,7 +995,8 @@ bool Protocol::send_fields(List<Item> *list, uint flags) server_field.type <= (int) MYSQL_TYPE_BLOB) ? server_field.length / item->collation.collation->mbminlen : server_field.length / item->collation.collation->mbmaxlen; - client_field->length= max_char_len * thd_cs->mbmaxlen; + client_field->length= char_to_byte_length_safe(max_char_len, + thd_cs->mbmaxlen); } client_field->type= server_field.type; client_field->flags= server_field.flags; @@ -980,7 +1010,7 @@ bool Protocol::send_fields(List<Item> *list, uint flags) client_field->catalog= dup_str_aux(field_alloc, "def", 3, cs, thd_cs); client_field->catalog_length= 3; - if (INTERNAL_NUM_FIELD(client_field)) + if (IS_NUM(client_field->type)) client_field->flags|= NUM_FLAG; if (flags & (int) Protocol::SEND_DEFAULTS) @@ -1007,9 +1037,10 @@ bool Protocol::send_fields(List<Item> *list, uint flags) } if (flags & SEND_EOF) - write_eof_packet(thd, thd->server_status, thd->total_warn_count); + write_eof_packet(thd, thd->server_status, + thd->warning_info->statement_warn_count()); - DBUG_RETURN(prepare_for_send(list)); + DBUG_RETURN(prepare_for_send(list->elements)); err: my_error(ER_OUT_OF_RESOURCES, MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ @@ -1069,25 +1100,24 @@ bool Protocol_binary::write() bool net_send_ok(THD *thd, - uint server_status, uint total_warn_count, - ha_rows affected_rows, ulonglong id, const char *message) + uint server_status, uint statement_warn_count, + ulonglong affected_rows, ulonglong id, const char *message) { DBUG_ENTER("emb_net_send_ok"); MYSQL_DATA *data; - bool error; MYSQL *mysql= thd->mysql; if (!mysql) // bootstrap file handling DBUG_RETURN(FALSE); if (!(data= thd->alloc_new_dataset())) - return TRUE; + DBUG_RETURN(TRUE); data->embedded_info->affected_rows= affected_rows; data->embedded_info->insert_id= id; if (message) strmake(data->embedded_info->info, message, sizeof(data->embedded_info->info)-1); - error= write_eof_packet(thd, server_status, total_warn_count); + bool error= write_eof_packet(thd, server_status, statement_warn_count); thd->cur_data= 0; DBUG_RETURN(error); } @@ -1104,16 +1134,19 @@ net_send_ok(THD *thd, */ bool -net_send_eof(THD *thd, uint server_status, uint total_warn_count) +net_send_eof(THD *thd, uint server_status, uint statement_warn_count) { - bool error= write_eof_packet(thd, server_status, total_warn_count); + bool error= write_eof_packet(thd, server_status, statement_warn_count); thd->cur_data= 0; return error; } -bool net_send_error_packet(THD *thd, uint sql_errno, const char *err) +bool net_send_error_packet(THD *thd, uint sql_errno, const char *err, + const char *sqlstate) { + uint error; + char converted_err[MYSQL_ERRMSG_SIZE]; MYSQL_DATA *data= thd->cur_data; struct embedded_query_result *ei; @@ -1128,8 +1161,13 @@ bool net_send_error_packet(THD *thd, uint sql_errno, const char *err) ei= data->embedded_info; ei->last_errno= sql_errno; - strmake(ei->info, err, sizeof(ei->info)-1); - strmov(ei->sqlstate, mysql_errno_to_sqlstate(sql_errno)); + convert_error_message(converted_err, sizeof(converted_err), + thd->variables.character_set_results, + err, strlen(err), + system_charset_info, &error); + /* Converted error message is always null-terminated. */ + strmake(ei->info, converted_err, sizeof(ei->info)-1); + strmov(ei->sqlstate, sqlstate); ei->server_status= thd->server_status; thd->cur_data= 0; return FALSE; @@ -1202,3 +1240,27 @@ int vprint_msg_to_log(enum loglevel level __attribute__((unused)), mysql_server_last_errno= CR_UNKNOWN_ERROR; return 0; } + + +bool Protocol::net_store_data(const uchar *from, size_t length, + CHARSET_INFO *from_cs, CHARSET_INFO *to_cs) +{ + uint conv_length= to_cs->mbmaxlen * length / from_cs->mbminlen; + uint dummy_error; + char *field_buf; + if (!thd->mysql) // bootstrap file handling + return false; + + if (!(field_buf= (char*) alloc_root(alloc, conv_length + sizeof(uint) + 1))) + return true; + *next_field= field_buf + sizeof(uint); + length= copy_and_convert(*next_field, conv_length, to_cs, + (const char*) from, length, from_cs, &dummy_error); + *(uint *) field_buf= length; + (*next_field)[length]= 0; + if (next_mysql_field->max_length < length) + next_mysql_field->max_length= length; + ++next_field; + ++next_mysql_field; + return false; +} diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c index 508916e79ba..6de1e3383d2 100644 --- a/libmysqld/libmysqld.c +++ b/libmysqld/libmysqld.c @@ -1,6 +1,4 @@ -/* - Copyright (c) 2001-2008 MySQL AB, 2009 Sun Microsystems, Inc. - Use is subject to license terms. +/* Copyright (c) 2001, 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 General Public License as published by @@ -13,15 +11,12 @@ 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 -*/ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include <my_global.h> #include <mysql.h> -#include <mysql_embed.h> #include <mysqld_error.h> #include <my_pthread.h> -#include "embedded_priv.h" #include <my_sys.h> #include <mysys_err.h> #include <m_string.h> @@ -31,11 +26,13 @@ #include <sys/stat.h> #include <signal.h> #include <time.h> +#include <sql_common.h> +#include "embedded_priv.h" #include "client_settings.h" #ifdef HAVE_PWD_H #include <pwd.h> #endif -#if !defined(MSDOS) && !defined(__WIN__) +#if !defined(__WIN__) #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> @@ -57,7 +54,7 @@ extern ulong net_buffer_length; extern ulong max_allowed_packet; -#if defined(MSDOS) || defined(__WIN__) +#if defined(__WIN__) #define ERRNO WSAGetLastError() #define perror(A) #else @@ -80,17 +77,6 @@ static my_bool is_NT(void) } #endif -/************************************************************************** -** Shut down connection -**************************************************************************/ - -static void end_server(MYSQL *mysql) -{ - DBUG_ENTER("end_server"); - free_old_query(mysql); - DBUG_VOID_RETURN; -} - int mysql_init_character_set(MYSQL *mysql); @@ -102,11 +88,18 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, char name_buff[USERNAME_LENGTH]; DBUG_ENTER("mysql_real_connect"); - DBUG_PRINT("enter",("host: %s db: %s user: %s", + DBUG_PRINT("enter",("host: %s db: %s user: %s (libmysqld)", host ? host : "(Null)", db ? db : "(Null)", user ? user : "(Null)")); + /* Test whether we're already connected */ + if (mysql->server_version) + { + set_mysql_error(mysql, CR_ALREADY_CONNECTED, unknown_sqlstate); + DBUG_RETURN(0); + } + if (!host || !host[0]) host= mysql->options.host; @@ -126,8 +119,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, (mysql->options.my_cnf_file ? mysql->options.my_cnf_file : "my"), mysql->options.my_cnf_group); - my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->options.my_cnf_file); + my_free(mysql->options.my_cnf_group); mysql->options.my_cnf_file=mysql->options.my_cnf_group=0; } @@ -172,7 +165,11 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, client_flag|=CLIENT_CAPABILITIES; if (client_flag & CLIENT_MULTI_STATEMENTS) client_flag|= CLIENT_MULTI_RESULTS; - client_flag&= ~CLIENT_COMPRESS; + /* + no compression in embedded as we don't send any data, + and no pluggable auth, as we cannot do a client-server dialog + */ + client_flag&= ~(CLIENT_COMPRESS | CLIENT_PLUGIN_AUTH); if (db) client_flag|=CLIENT_CONNECT_WITH_DB; @@ -219,7 +216,7 @@ error: { /* Free alloced memory */ my_bool free_me=mysql->free_me; - end_server(mysql); + free_old_query(mysql); mysql->free_me=0; mysql_close(mysql); mysql->free_me=free_me; diff --git a/libmysqld/libmysqld.def b/libmysqld/libmysqld.def index 047cfe0fe57..ecfad75b12f 100644 --- a/libmysqld/libmysqld.def +++ b/libmysqld/libmysqld.def @@ -13,9 +13,7 @@ EXPORTS mysql_commit mysql_data_seek mysql_debug - mysql_disable_rpl_parse mysql_dump_debug_info - mysql_enable_rpl_parse mysql_eof mysql_errno mysql_error @@ -61,8 +59,6 @@ EXPORTS mysql_rollback mysql_row_seek mysql_row_tell - mysql_rpl_parse_enabled - mysql_rpl_probe mysql_select_db mysql_send_query mysql_shutdown @@ -108,3 +104,4 @@ EXPORTS mysql_stmt_attr_get mysql_stmt_attr_set mysql_stmt_field_count + mysql_stmt_next_result |