diff options
Diffstat (limited to 'libmysql')
-rw-r--r-- | libmysql/.cvsignore | 10 | ||||
-rw-r--r--[-rwxr-xr-x] | libmysql/CMakeLists.txt | 331 | ||||
-rw-r--r-- | libmysql/Makefile.am | 17 | ||||
-rw-r--r-- | libmysql/Makefile.shared | 32 | ||||
-rw-r--r-- | libmysql/client_settings.h | 16 | ||||
-rw-r--r-- | libmysql/dll.c | 125 | ||||
-rw-r--r-- | libmysql/errmsg.c | 139 | ||||
-rw-r--r-- | libmysql/get_password.c | 14 | ||||
-rw-r--r-- | libmysql/libmysql.c | 655 | ||||
-rw-r--r-- | libmysql/libmysql.def | 47 | ||||
-rw-r--r-- | libmysql/manager.c | 269 |
11 files changed, 405 insertions, 1250 deletions
diff --git a/libmysql/.cvsignore b/libmysql/.cvsignore deleted file mode 100644 index a58235fee47..00000000000 --- a/libmysql/.cvsignore +++ /dev/null @@ -1,10 +0,0 @@ -*.lo -.deps -.libs -Makefile -Makefile.in -conf_to_src -config.status -configure -ctype_extra_sources.c -libmysqlclient.la diff --git a/libmysql/CMakeLists.txt b/libmysql/CMakeLists.txt index 55138e4aa06..0de582a0212 100755..100644 --- a/libmysql/CMakeLists.txt +++ b/libmysql/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2006 MySQL AB +# Copyright (c) 2006, 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,121 +11,214 @@ # # 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("${PROJECT_SOURCE_DIR}/win/mysql_manifest.cmake") - -SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") -SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") - -# Note that we don't link with the libraries "strings" or "mysys" -# here, instead we recompile the files needed and include them -# directly. This means we don't have to worry here about if these -# libraries are compiled defining USE_TLS or not. Not that it *should* -# have been a problem anyway, they don't use thread local storage. - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include - ${CMAKE_SOURCE_DIR}/libmysql - ${CMAKE_SOURCE_DIR}/regex - ${CMAKE_SOURCE_DIR}/sql - ${CMAKE_SOURCE_DIR}/strings) - -# We include the source file listing instead of referencing the -# libraries. At least with CMake 2.4 and Visual Studio 2005 a static -# library created from other static libraries would not be complete, -# i.e. the libraries listed in TARGET_LINK_LIBRARIES() were just -# ignored. - - -# 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) - -SET(CLIENT_SOURCES ../mysys/array.c ../strings/bchange.c ../strings/bmove.c - ../strings/bmove_upp.c ../mysys/charset-def.c ../mysys/charset.c - ../sql-common/client.c ../strings/ctype-big5.c ../strings/ctype-bin.c - ../strings/ctype-cp932.c ../strings/ctype-czech.c ../strings/ctype-euc_kr.c - ../strings/ctype-eucjpms.c ../strings/ctype-extra.c ../strings/ctype-gb2312.c - ../strings/ctype-gbk.c ../strings/ctype-latin1.c ../strings/ctype-mb.c - ../strings/ctype-simple.c ../strings/ctype-sjis.c ../strings/ctype-tis620.c - ../strings/ctype-uca.c ../strings/ctype-ucs2.c ../strings/ctype-ujis.c - ../strings/ctype-utf8.c ../strings/ctype-win1250ch.c ../strings/ctype.c - ../mysys/default.c errmsg.c ../mysys/errors.c - ../mysys/hash.c ../mysys/my_sleep.c ../mysys/default_modify.c - get_password.c ../strings/int2str.c ../strings/is_prefix.c - libmysql.c ../mysys/list.c ../strings/llstr.c - ../strings/longlong2str.c manager.c ../mysys/mf_arr_appstr.c ../mysys/mf_cache.c - ../mysys/mf_dirname.c ../mysys/mf_fn_ext.c ../mysys/mf_format.c - ../mysys/mf_iocache.c ../mysys/mf_iocache2.c ../mysys/mf_loadpath.c - ../mysys/mf_pack.c ../mysys/mf_path.c ../mysys/mf_tempfile.c ../mysys/mf_unixpath.c - ../mysys/mf_wcomp.c ../mysys/mulalloc.c ../mysys/my_access.c ../mysys/my_alloc.c - ../mysys/my_chsize.c ../mysys/my_compress.c ../mysys/my_create.c - ../mysys/my_delete.c ../mysys/my_div.c ../mysys/my_error.c ../mysys/my_file.c - ../mysys/my_fopen.c ../mysys/my_fstream.c ../mysys/my_gethostbyname.c - ../mysys/my_getopt.c ../mysys/my_getwd.c ../mysys/my_init.c ../mysys/my_lib.c - ../mysys/my_malloc.c ../mysys/my_messnc.c ../mysys/my_net.c ../mysys/my_once.c - ../mysys/my_open.c ../mysys/my_pread.c ../mysys/my_pthread.c ../mysys/my_read.c - ../mysys/my_realloc.c ../mysys/my_rename.c ../mysys/my_seek.c - ../mysys/my_static.c ../strings/my_strtoll10.c ../mysys/my_symlink.c - ../mysys/my_symlink2.c ../mysys/my_thr_init.c ../sql-common/my_time.c - ../strings/my_vsnprintf.c ../mysys/my_wincond.c ../mysys/my_winthread.c - ../mysys/my_write.c ../sql/net_serv.cc ../sql-common/pack.c ../sql/password.c - ../mysys/safemalloc.c ../mysys/sha1.c ../strings/str2int.c - ../strings/str_alloc.c ../strings/strcend.c ../strings/strcont.c ../strings/strend.c - ../strings/strfill.c ../mysys/string.c ../strings/strinstr.c ../strings/strmake.c - ../strings/strmov.c ../strings/strnlen.c ../strings/strnmov.c ../strings/strtod.c - ../strings/strtoll.c ../strings/strtoull.c ../strings/strxmov.c ../strings/strxnmov.c - ../mysys/thr_mutex.c ../mysys/typelib.c ../vio/vio.c ../vio/viosocket.c - ../vio/viossl.c ../vio/viosslfactories.c ../strings/xml.c ../mysys/mf_qsort.c - ../mysys/my_getsystime.c ../mysys/my_sync.c ${LIB_SOURCES}) - -# Need to set USE_TLS for building the DLL, since __declspec(thread) -# approach to thread local storage does not work properly in DLLs. -# -# The static library might be used to form another DLL, as is the case -# with the ODBC driver, so it has to be compiled with USE_TLS as well. -# -# We create a third library without USE_TLS for internal use. We can't -# be sure that some client application part of this build doesn't go -# beond the documented API, and try access the Thread Local Storage. -# The "_notls" means no Tls*() functions used, i.e. "static" TLS. - -ADD_LIBRARY(mysqlclient STATIC ${CLIENT_SOURCES}) -ADD_DEPENDENCIES(mysqlclient GenError) -TARGET_LINK_LIBRARIES(mysqlclient) - -ADD_LIBRARY(mysqlclient_notls STATIC ${CLIENT_SOURCES}) -ADD_DEPENDENCIES(mysqlclient_notls GenError) -TARGET_LINK_LIBRARIES(mysqlclient_notls) - -ADD_LIBRARY(libmysql SHARED ${CLIENT_SOURCES} dll.c libmysql.def) -IF(WIN32) - SET_TARGET_PROPERTIES(libmysql mysqlclient PROPERTIES COMPILE_FLAGS "-DUSE_TLS") -ENDIF(WIN32) -ADD_DEPENDENCIES(libmysql GenError) -TARGET_LINK_LIBRARIES(libmysql wsock32) - -IF(EMBED_MANIFESTS) - MYSQL_EMBED_MANIFEST("myTest" "asInvoker") -ENDIF(EMBED_MANIFESTS) +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/libmysql + ${CMAKE_SOURCE_DIR}/regex + ${CMAKE_SOURCE_DIR}/sql + ${CMAKE_SOURCE_DIR}/strings + ${SSL_INCLUDE_DIRS} + ${SSL_INTERNAL_INCLUDE_DIRS} + ${ZLIB_INCLUDE_DIR}) +ADD_DEFINITIONS(${SSL_DEFINES}) + +SET(CLIENT_API_FUNCTIONS +load_defaults +mysql_thread_end +mysql_thread_init +myodbc_remove_escape +mysql_affected_rows +mysql_autocommit +mysql_stmt_bind_param +mysql_stmt_bind_result +mysql_change_user +mysql_character_set_name +mysql_close +mysql_commit +mysql_data_seek +mysql_debug +mysql_dump_debug_info +mysql_eof +mysql_errno +mysql_error +mysql_escape_string +mysql_hex_string +mysql_stmt_execute +mysql_stmt_fetch +mysql_stmt_fetch_column +mysql_fetch_field +mysql_fetch_field_direct +mysql_fetch_fields +mysql_fetch_lengths +mysql_fetch_row +mysql_field_count +mysql_field_seek +mysql_field_tell +mysql_free_result +mysql_get_client_info +mysql_get_host_info +mysql_get_proto_info +mysql_get_server_info +mysql_get_client_version +mysql_get_ssl_cipher +mysql_info +mysql_init +mysql_insert_id +mysql_kill +mysql_set_server_option +mysql_list_dbs +mysql_list_fields +mysql_list_processes +mysql_list_tables +mysql_more_results +mysql_next_result +mysql_num_fields +mysql_num_rows +mysql_options +mysql_stmt_param_count +mysql_stmt_param_metadata +mysql_ping +mysql_stmt_result_metadata +mysql_query +mysql_read_query_result +mysql_real_connect +mysql_real_escape_string +mysql_real_query +mysql_refresh +mysql_rollback +mysql_row_seek +mysql_row_tell +mysql_select_db +mysql_stmt_send_long_data +mysql_send_query +mysql_shutdown +mysql_ssl_set +mysql_stat +mysql_stmt_affected_rows +mysql_stmt_close +mysql_stmt_reset +mysql_stmt_data_seek +mysql_stmt_errno +mysql_stmt_error +mysql_stmt_free_result +mysql_stmt_num_rows +mysql_stmt_row_seek +mysql_stmt_row_tell +mysql_stmt_store_result +mysql_store_result +mysql_thread_id +mysql_thread_safe +mysql_use_result +mysql_warning_count +mysql_stmt_sqlstate +mysql_sqlstate +mysql_get_server_version +mysql_stmt_prepare +mysql_stmt_init +mysql_stmt_insert_id +mysql_stmt_attr_get +mysql_stmt_attr_set +mysql_stmt_field_count +mysql_set_local_infile_default +mysql_set_local_infile_handler +mysql_embedded +mysql_server_init +mysql_server_end +mysql_set_character_set +mysql_get_character_set_info +mysql_stmt_next_result + +CACHE INTERNAL "Functions exported by client API" + +) + +SET(CLIENT_SOURCES + get_password.c + libmysql.c + errmsg.c + ../sql-common/client.c + ../sql-common/my_time.c + ../sql/net_serv.cc + ../sql-common/pack.c + ../sql/password.c +) +ADD_CONVENIENCE_LIBRARY(clientlib ${CLIENT_SOURCES}) +DTRACE_INSTRUMENT(clientlib) +ADD_DEPENDENCIES(clientlib GenError) + +SET(LIBS clientlib dbug strings vio mysys ${ZLIB_LIBRARY} ${SSL_LIBRARIES}) + +# Merge several convenience libraries into one big mysqlclient +# and link them together into shared library. +MERGE_LIBRARIES(mysqlclient STATIC ${LIBS} COMPONENT Development) + +# Visual Studio users need debug static library for debug projects +IF(MSVC) + INSTALL_DEBUG_TARGET(mysqlclient DESTINATION ${INSTALL_LIBDIR}/debug) +ENDIF() + +IF(UNIX) + MACRO(GET_VERSIONED_LIBNAME LIBNAME EXTENSION VERSION OUTNAME) + SET(DOT_VERSION ".${VERSION}") + IF(DOT_VERSION STREQUAL ".") + SET(DOT_VERSION "") + ENDIF() + IF(APPLE) + SET(${OUTNAME} ${LIBNAME}${DOT_VERSION}${EXTENSION}) + ELSE() + SET(${OUTNAME} ${LIBNAME}${EXTENSION}${DOT_VERSION}) + ENDIF() + ENDMACRO() + INSTALL_SYMLINK(${CMAKE_STATIC_LIBRARY_PREFIX}mysqlclient_r.a mysqlclient ${INSTALL_LIBDIR} COMPONENT SharedLibraries) +ENDIF() + +IF(NOT DISABLE_SHARED) + MERGE_LIBRARIES(libmysql SHARED ${LIBS} EXPORTS ${CLIENT_API_FUNCTIONS} COMPONENT SharedLibraries) + IF(UNIX) + # libtool compatability + IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR APPLE) + SET(OS_SHARED_LIB_VERSION "${SHARED_LIB_MAJOR_VERSION}") + ELSEIF(CMAKE_SYSTEM_NAME MATCHES "HP-UX") + SET(OS_SHARED_LIB_VERSION "${SHARED_LIB_MAJOR_VERSION}.0") + ELSE() + SET(OS_SHARED_LIB_VERSION "${SHARED_LIB_MAJOR_VERSION}.0.0") + ENDIF() + # Name of shared library is mysqlclient on Unix + SET_TARGET_PROPERTIES(libmysql PROPERTIES + OUTPUT_NAME mysqlclient + VERSION "${OS_SHARED_LIB_VERSION}" + SOVERSION "${SHARED_LIB_MAJOR_VERSION}") + IF(LINK_FLAG_NO_UNDEFINED) + GET_TARGET_PROPERTY(libmysql_link_flags libmysql LINK_FLAGS) + IF(NOT libmysql_link_flag) + SET(libmysql_link_flags) + ENDIF() + SET_TARGET_PROPERTIES(libmysql PROPERTIES LINK_FLAGS + "${libmysql_link_flags} ${LINK_FLAG_NO_UNDEFINED}") + ENDIF() + # clean direct output needs to be set several targets have the same name + #(mysqlclient in this case) + SET_TARGET_PROPERTIES(mysqlclient PROPERTIES CLEAN_DIRECT_OUTPUT 1) + SET_TARGET_PROPERTIES(libmysql PROPERTIES CLEAN_DIRECT_OUTPUT 1) + + # Install links to libmysqlclient.so (client_r) + GET_VERSIONED_LIBNAME( + "${CMAKE_SHARED_LIBRARY_PREFIX}mysqlclient_r" + "${CMAKE_SHARED_LIBRARY_SUFFIX}" + "" + linkname) + INSTALL_SYMLINK(${linkname} libmysql ${INSTALL_LIBDIR} COMPONENT SharedLibraries) + SET(OS_SHARED_LIB_SYMLINKS "${SHARED_LIB_MAJOR_VERSION}" "${OS_SHARED_LIB_VERSION}") + LIST(REMOVE_DUPLICATES OS_SHARED_LIB_SYMLINKS) + FOREACH(ver ${OS_SHARED_LIB_SYMLINKS}) + GET_VERSIONED_LIBNAME( + "${CMAKE_SHARED_LIBRARY_PREFIX}mysqlclient_r" + "${CMAKE_SHARED_LIBRARY_SUFFIX}" + "${ver}" + linkname) + INSTALL_SYMLINK(${linkname} libmysql ${INSTALL_LIBDIR} COMPONENT SharedLibraries) + ENDFOREACH() + ENDIF() +ENDIF() diff --git a/libmysql/Makefile.am b/libmysql/Makefile.am index f67abfd8ac6..07f66c28ddb 100644 --- a/libmysql/Makefile.am +++ b/libmysql/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (C) 2000-2004 MySQL AB +# Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 GNU General Public License as @@ -21,7 +21,9 @@ # This file is public domain and comes with NO WARRANTY of any kind target = libmysqlclient.la -target_defs = -DMYSQL_CLIENT_NO_THREADS -DDONT_USE_RAID @LIB_EXTRA_CCFLAGS@ +target_defs = -DMYSQL_CLIENT_NO_THREADS -DDISABLE_MYSQL_THREAD_H \ + @LIB_EXTRA_CCFLAGS@ + LIBS = @CLIENT_LIBS@ INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \ $(openssl_includes) @ZLIB_INCLUDES@ @@ -31,7 +33,7 @@ include $(srcdir)/Makefile.shared libmysqlclient_la_SOURCES = $(target_sources) libmysqlclient_la_LIBADD = $(target_libadd) $(yassl_las) libmysqlclient_la_LDFLAGS = $(target_ldflags) -EXTRA_DIST = Makefile.shared libmysql.def dll.c CMakeLists.txt +EXTRA_DIST = Makefile.shared libmysql.def CMakeLists.txt noinst_HEADERS = client_settings.h link_sources: @@ -77,11 +79,11 @@ link_sources: # a minimal MySQL client library # # For a really minimal distribution (without debugging code) we could -# keep only the stubs for safemalloc.c and debug.c +# keep only the stubs for debug.c # # A list of needed headers collected from the deps information 000213 -nh = my_global.h config-win32.h dbug.h errmsg.h \ - m_ctype.h m_string.h \ +nh = my_global.h dbug.h errmsg.h \ + m_ctype.h m_string.h password.h \ my_alarm.h my_config.h my_dir.h my_list.h my_net.h my_sys.h \ mysql.h mysql_com.h mysql_version.h mysqld_error.h \ mysys_err.h my_pthread.h thr_alarm.h violite.h hash.h \ @@ -111,6 +113,3 @@ do-lib-dist: echo ' $$(AR) r $$@ $$?' >>$$dir/Makefile; \ gtar cvzf $$dir.tar.gz $$dir; \ cd $$dir; gmake - -# Don't update the files from bitkeeper -%::SCCS/s.% diff --git a/libmysql/Makefile.shared b/libmysql/Makefile.shared index 39c1975888a..887af62229a 100644 --- a/libmysql/Makefile.shared +++ b/libmysql/Makefile.shared @@ -1,4 +1,4 @@ -# Copyright (C) 2000-2004 MySQL AB +# Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 GNU General Public License as @@ -31,13 +31,13 @@ pkglib_LTLIBRARIES = $(target) noinst_PROGRAMS = conf_to_src -target_sources = libmysql.c password.c manager.c \ +target_sources = libmysql.c password.c \ get_password.c errmsg.c mystringsobjects = strmov.lo strxmov.lo strxnmov.lo strnmov.lo \ - strmake.lo strend.lo strtod.lo \ + strmake.lo strend.lo \ strnlen.lo strfill.lo is_prefix.lo \ - int2str.lo str2int.lo strinstr.lo strcont.lo \ + int2str.lo str2int.lo strcont.lo \ strcend.lo ctype-latin1.lo \ bchange.lo bmove.lo bmove_upp.lo longlong2str.lo \ strtoull.lo strtoll.lo llstr.lo my_vsnprintf.lo \ @@ -46,29 +46,29 @@ mystringsobjects = strmov.lo strxmov.lo strxnmov.lo strnmov.lo \ ctype-win1250ch.lo ctype-utf8.lo ctype-extra.lo \ ctype-ucs2.lo ctype-gb2312.lo ctype-gbk.lo \ ctype-sjis.lo ctype-tis620.lo ctype-ujis.lo \ - ctype-uca.lo xml.lo my_strtoll10.lo str_alloc.lo + ctype-uca.lo xml.lo my_strtoll10.lo str_alloc.lo dtoa.lo mystringsextra= strto.c -dbugobjects = dbug.lo # IT IS IN SAFEMALLOC.C sanity.lo +dbugobjects = dbug.lo mysysheaders = mysys_priv.h my_static.h vioheaders = vio_priv.h -mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \ +mysysobjects1 = my_init.lo my_static.lo my_malloc.lo \ my_create.lo my_delete.lo mf_tempfile.lo my_open.lo \ my_file.lo my_read.lo my_write.lo errors.lo \ my_error.lo my_getwd.lo my_div.lo \ - mf_pack.lo my_messnc.lo mf_dirname.lo mf_fn_ext.lo\ - mf_wcomp.lo typelib.lo safemalloc.lo my_alloc.lo \ + mf_pack.lo my_mess.lo mf_dirname.lo mf_fn_ext.lo\ + mf_wcomp.lo typelib.lo my_alloc.lo \ mf_format.lo mf_path.lo mf_unixpath.lo my_fopen.lo \ my_symlink.lo my_fstream.lo mf_arr_appstr.lo \ mf_loadpath.lo my_pthread.lo my_thr_init.lo \ - thr_mutex.lo mulalloc.lo string.lo \ - default.lo default_modify.lo \ - my_compress.lo array.lo my_once.lo list.lo my_net.lo \ + thr_mutex.lo mulalloc.lo string.lo default.lo \ + my_compress.lo array.lo my_once.lo list.lo \ charset.lo charset-def.lo hash.lo mf_iocache.lo \ mf_iocache2.lo my_seek.lo my_sleep.lo \ my_pread.lo mf_cache.lo md5.lo sha1.lo \ my_getopt.lo my_gethostbyname.lo my_port.lo \ - my_rename.lo my_chsize.lo my_sync.lo my_getsystime.lo + my_rename.lo my_chsize.lo my_sync.lo \ + my_getsystime.lo my_symlink2.lo mf_same.lo sqlobjects = net.lo sql_cmn_objects = pack.lo client.lo my_time.lo @@ -89,7 +89,8 @@ DEFS = -DDEFAULT_CHARSET_HOME="\"$(MYSQLBASEdir)\"" \ -DDEFAULT_HOME_ENV=MYSQL_HOME \ -DDEFAULT_GROUP_SUFFIX_ENV=MYSQL_GROUP_SUFFIX \ -DDEFAULT_SYSCONFDIR="\"$(sysconfdir)\"" \ - -DSHAREDIR="\"$(MYSQLSHAREdir)\"" $(target_defs) + -DSHAREDIR="\"$(MYSQLSHAREdir)\"" -DDISABLE_DTRACE \ + $(target_defs) if HAVE_YASSL yassl_las = $(top_builddir)/extra/yassl/src/libyassl.la \ @@ -114,6 +115,3 @@ conf_to_src_LDADD= #force static linking of conf_to_src - essential when linking against #custom installation of libc conf_to_src_LDFLAGS=@NOINST_LDFLAGS@ - -# Don't update the files from bitkeeper -%::SCCS/s.% diff --git a/libmysql/client_settings.h b/libmysql/client_settings.h index f87e625771f..aaec08d1b1e 100644 --- a/libmysql/client_settings.h +++ b/libmysql/client_settings.h @@ -13,12 +13,22 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef CLIENT_SETTINGS_INCLUDED +#define CLIENT_SETTINGS_INCLUDED +#else +#error You have already included an client_settings.h and it should not be included twice +#endif /* CLIENT_SETTINGS_INCLUDED */ + extern uint mysql_port; extern char * mysql_unix_port; -#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | \ - CLIENT_TRANSACTIONS | \ - CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION) +#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | \ + CLIENT_LONG_FLAG | \ + CLIENT_TRANSACTIONS | \ + CLIENT_PROTOCOL_41 | \ + CLIENT_SECURE_CONNECTION | \ + CLIENT_MULTI_RESULTS | \ + CLIENT_PS_MULTI_RESULTS) sig_handler my_pipe_sig_handler(int sig); void read_user_name(char *name); diff --git a/libmysql/dll.c b/libmysql/dll.c deleted file mode 100644 index 8fcf41c792c..00000000000 --- a/libmysql/dll.c +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright (C) 2000-2004 MySQL AB - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation. - - There are special exceptions to the terms and conditions of the GPL as it - is applied to this software. View the full text of the exception in file - EXCEPTIONS-CLIENT in the directory of this software distribution. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -/* -** Handling initialization of the dll library -*/ - -#include <my_global.h> -#include <my_sys.h> -#include <my_pthread.h> - -static my_bool libmysql_inited=0; - -void libmysql_init(void) -{ - if (libmysql_inited) - return; - libmysql_inited=1; - my_init(); - { - DBUG_ENTER("libmysql_init"); -#ifdef LOG_ALL - DBUG_PUSH("d:t:S:O,c::\\tmp\\libmysql.log"); -#else - if (getenv("LIBMYSQL_LOG") != NULL) - DBUG_PUSH(getenv("LIBMYSQL_LOG")); -#endif - DBUG_VOID_RETURN; - } -} - -#ifdef __WIN__ - -static int inited=0,threads=0; -HINSTANCE NEAR s_hModule; /* Saved module handle */ -DWORD main_thread; - -BOOL APIENTRY LibMain(HANDLE hInst,DWORD ul_reason_being_called, - LPVOID lpReserved) -{ - switch (ul_reason_being_called) { - case DLL_PROCESS_ATTACH: /* case of libentry call in win 3.x */ - if (!inited++) - { - s_hModule=hInst; - libmysql_init(); - main_thread=GetCurrentThreadId(); - } - break; - case DLL_THREAD_ATTACH: - threads++; - my_thread_init(); - break; - case DLL_PROCESS_DETACH: /* case of wep call in win 3.x */ - if (!--inited) /* Safety */ - { - /* my_thread_init() */ /* This may give extra safety */ - my_end(0); - } - break; - case DLL_THREAD_DETACH: - /* Main thread will free by my_end() */ - threads--; - if (main_thread != GetCurrentThreadId()) - my_thread_end(); - break; - default: - break; - } /* switch */ - - return TRUE; - - UNREFERENCED_PARAMETER(lpReserved); -} /* LibMain */ - - -static BOOL do_libmain; -int __stdcall DllMain(HANDLE hInst,DWORD ul_reason_being_called,LPVOID lpReserved) -{ - /* - Unless environment variable LIBMYSQL_DLLINIT is set, do nothing. - The environment variable is checked once, during the first call to DllMain() - (in DLL_PROCESS_ATTACH hook). - */ - if (ul_reason_being_called == DLL_PROCESS_ATTACH) - do_libmain = (getenv("LIBMYSQL_DLLINIT") != NULL); - if (do_libmain) - return LibMain(hInst,ul_reason_being_called,lpReserved); - return TRUE; -} - -#elif defined(WINDOWS) - -/**************************************************************************** -** This routine is called by LIBSTART.ASM at module load time. All it -** does in this sample is remember the DLL module handle. The module -** handle is needed if you want to do things like load stuff from the -** resource file (for instance string resources). -****************************************************************************/ - -int _export FAR PASCAL libmain(HANDLE hModule,short cbHeapSize, - UCHAR FAR *lszCmdLine) -{ - s_hModule = hModule; - libmysql_init(); - return TRUE; -} - -#endif diff --git a/libmysql/errmsg.c b/libmysql/errmsg.c index 95ee6862aa8..febbded6af2 100644 --- a/libmysql/errmsg.c +++ b/libmysql/errmsg.c @@ -24,137 +24,6 @@ #include <my_sys.h> #include "errmsg.h" -#ifdef GERMAN -const char *client_errors[]= -{ - "Unbekannter MySQL Fehler", - "Kann UNIX-Socket nicht anlegen (%d)", - "Keine Verbindung zu lokalem MySQL Server, socket: '%-.100s' (%d)", - "Keine Verbindung zu MySQL Server auf %-.100s (%d)", - "Kann TCP/IP-Socket nicht anlegen (%d)", - "Unbekannter MySQL Server Host (%-.100s) (%d)", - "MySQL Server nicht vorhanden", - "Protokolle ungleich; Server Version = %d, Client Version = %d", - "MySQL client ran out of memory", - "Wrong host info", - "Localhost via UNIX socket", - "%-.100s via TCP/IP", - "Error in server handshake", - "Lost connection to MySQL server during query", - "Commands out of sync; you can't run this command now", - "Verbindung ueber Named Pipe: %-.32s", - "Kann nicht auf Named Pipe warten. Host: %-.64s pipe: %-.32s (%lu)", - "Kann Named Pipe nicht oeffnen. Host: %-.64s pipe: %-.32s (%lu)", - "Kann den Status der Named Pipe nicht setzen. Host: %-.64s pipe: %-.32s (%lu)", - "Can't initialize character set %-.32s (path: %-.100s)", - "Got packet bigger than 'max_allowed_packet' bytes", - "Embedded server", - "Error on SHOW SLAVE STATUS:", - "Error on SHOW SLAVE HOSTS:", - "Error connecting to slave:", - "Error connecting to master:", - "SSL connection error", - "Malformed packet", - "This client library is licensed only for use with MySQL servers having '%s' license", - "Invalid use of null pointer", - "Statement not prepared", - "No data supplied for parameters in prepared statement", - "Data truncated", - "No parameters exist in the statement", - "Invalid parameter number", - "Can't send long data for non-string/non-binary data types (parameter: %d)", - "Using unsupported buffer type: %d (parameter: %d)", - "Shared memory: %-.100s", - "Can't open shared memory; client could not create request event (%lu)", - "Can't open shared memory; no answer event received from server (%lu)", - "Can't open shared memory; server could not allocate file mapping (%lu)", - "Can't open shared memory; server could not get pointer to file mapping (%lu)", - "Can't open shared memory; client could not allocate file mapping (%lu)", - "Can't open shared memory; client could not get pointer to file mapping (%lu)", - "Can't open shared memory; client could not create %s event (%lu)", - "Can't open shared memory; no answer from server (%lu)", - "Can't open shared memory; cannot send request event to server (%lu)", - "Wrong or unknown protocol", - "Invalid connection handle", - "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)", - "Row retrieval was canceled by mysql_stmt_close() call", - "Attempt to read column without prior row fetch", - "Prepared statement contains no metadata", - "Attempt to read a row while there is no result set associated with the statement", - "This feature is not implemented yet", - "Lost connection to MySQL server at '%s', system error: %d", - "Statement closed indirectly because of a preceeding %s() call", - "The number of columns in the result set differs from the number of bound buffers. You must reset the statement, rebind the result set columns, and execute the statement again", - "" -}; - -/* Start of code added by Roberto M. Serqueira - martinsc@uol.com.br - 05.24.2001 */ - -#elif defined PORTUGUESE -const char *client_errors[]= -{ - "Erro desconhecido do MySQL", - "Não pode criar 'UNIX socket' (%d)", - "Não pode se conectar ao servidor MySQL local através do 'socket' '%-.100s' (%d)", - "Não pode se conectar ao servidor MySQL em '%-.100s' (%d)", - "Não pode criar 'socket TCP/IP' (%d)", - "'Host' servidor MySQL '%-.100s' (%d) desconhecido", - "Servidor MySQL desapareceu", - "Incompatibilidade de protocolos; versão do servidor = %d, versão do cliente = %d", - "Cliente do MySQL com falta de memória", - "Informação inválida de 'host'", - "Localhost via 'UNIX socket'", - "%-.100s via 'TCP/IP'", - "Erro na negociação de acesso ao servidor", - "Conexão perdida com servidor MySQL durante 'query'", - "Comandos fora de sincronismo; você não pode executar este comando agora", - "Named pipe: %-.32s", - "Não pode esperar pelo 'named pipe' para o 'host' %-.64s - 'pipe' %-.32s (%lu)", - "Não pode abrir 'named pipe' para o 'host' %-.64s - 'pipe' %-.32s (%lu)", - "Não pode estabelecer o estado do 'named pipe' para o 'host' %-.64s - 'pipe' %-.32s (%lu)", - "Não pode inicializar conjunto de caracteres %-.32s (caminho %-.100s)", - "Obteve pacote maior do que 'max_allowed_packet' bytes", - "Embedded server" - "Error on SHOW SLAVE STATUS:", - "Error on SHOW SLAVE HOSTS:", - "Error connecting to slave:", - "Error connecting to master:", - "SSL connection error", - "Malformed packet", - "This client library is licensed only for use with MySQL servers having '%s' license", - "Invalid use of null pointer", - "Statement not prepared", - "No data supplied for parameters in prepared statement", - "Data truncated", - "No parameters exist in the statement", - "Invalid parameter number", - "Can't send long data for non-string/non-binary data types (parameter: %d)", - "Using unsupported buffer type: %d (parameter: %d)", - "Shared memory: %-.100s", - "Can't open shared memory; client could not create request event (%lu)", - "Can't open shared memory; no answer event received from server (%lu)", - "Can't open shared memory; server could not allocate file mapping (%lu)", - "Can't open shared memory; server could not get pointer to file mapping (%lu)", - "Can't open shared memory; client could not allocate file mapping (%lu)", - "Can't open shared memory; client could not get pointer to file mapping (%lu)", - "Can't open shared memory; client could not create %s event (%lu)", - "Can't open shared memory; no answer from server (%lu)", - "Can't open shared memory; cannot send request event to server (%lu)", - "Wrong or unknown protocol", - "Invalid connection handle", - "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)", - "Row retrieval was canceled by mysql_stmt_close() call", - "Attempt to read column without prior row fetch", - "Prepared statement contains no metadata", - "Attempt to read a row while there is no result set associated with the statement", - "This feature is not implemented yet", - "Lost connection to MySQL server at '%s', system error: %d", - "Statement closed indirectly because of a preceeding %s() call", - "The number of columns in the result set differs from the number of bound buffers. You must reset the statement, rebind the result set columns, and execute the statement again", - "" -}; - -#else /* ENGLISH */ const char *client_errors[]= { "Unknown MySQL error", @@ -215,10 +84,14 @@ const char *client_errors[]= "Lost connection to MySQL server at '%s', system error: %d", "Statement closed indirectly because of a preceeding %s() call", "The number of columns in the result set differs from the number of bound buffers. You must reset the statement, rebind the result set columns, and execute the statement again", + "This handle is already connected. Use a separate handle for each connection." "" }; -#endif +const char** get_client_errmsgs() +{ + return client_errors; +} /* Register client error messages for use with my_error(). @@ -232,7 +105,7 @@ const char *client_errors[]= void init_client_errs(void) { - (void) my_error_register(client_errors, CR_ERROR_FIRST, CR_ERROR_LAST); + (void) my_error_register(get_client_errmsgs, CR_ERROR_FIRST, CR_ERROR_LAST); } diff --git a/libmysql/get_password.c b/libmysql/get_password.c index cbe5fce6949..56514a8d864 100644 --- a/libmysql/get_password.c +++ b/libmysql/get_password.c @@ -36,7 +36,7 @@ #include <pwd.h> #endif /* HAVE_PWD_H */ #else /* ! HAVE_GETPASS */ -#if !defined(__WIN__) && !defined(__NETWARE__) +#if !defined(__WIN__) #include <sys/ioctl.h> #ifdef HAVE_TERMIOS_H /* For tty-password */ #include <termios.h> @@ -55,9 +55,7 @@ #include <asm/termiobits.h> #endif #else -#ifndef __NETWARE__ #include <conio.h> -#endif /* __NETWARE__ */ #endif /* __WIN__ */ #endif /* HAVE_GETPASS */ @@ -65,16 +63,8 @@ #define getpass(A) getpassphrase(A) #endif -#if defined( __WIN__) || defined(__NETWARE__) +#if defined(__WIN__) /* were just going to fake it here and get input from the keyboard */ - -#ifdef __NETWARE__ -#undef _getch -#undef _cputs -#define _getch getcharacter -#define _cputs(A) putstring(A) -#endif - char *get_tty_password(const char *opt_message) { char to[80]; diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 8c612b6894e..231b6e2ef76 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -34,7 +34,7 @@ #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> @@ -45,7 +45,7 @@ #ifdef HAVE_SYS_SELECT_H #include <sys/select.h> #endif -#endif /* !defined(MSDOS) && !defined(__WIN__) */ +#endif /* !defined(__WIN__) */ #ifdef HAVE_POLL #include <sys/poll.h> #endif @@ -74,7 +74,7 @@ ulong max_allowed_packet= 1024L*1024L*1024L; my_bool net_flush(NET *net); #endif -#if defined(MSDOS) || defined(__WIN__) +#if defined(__WIN__) /* socket_errno is defined in my_global.h for all platforms */ #define perror(A) #else @@ -128,31 +128,29 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)), init_client_errs(); if (!mysql_port) { + char *env; + struct servent *serv_ptr __attribute__((unused)); + mysql_port = MYSQL_PORT; -#ifndef MSDOS - { - struct servent *serv_ptr; - char *env; - /* - if builder specifically requested a default port, use that - (even if it coincides with our factory default). - only if they didn't do we check /etc/services (and, failing - on that, fall back to the factory default of 3306). - either default can be overridden by the environment variable - MYSQL_TCP_PORT, which in turn can be overridden with command - line options. - */ + /* + if builder specifically requested a default port, use that + (even if it coincides with our factory default). + only if they didn't do we check /etc/services (and, failing + on that, fall back to the factory default of 3306). + either default can be overridden by the environment variable + MYSQL_TCP_PORT, which in turn can be overridden with command + line options. + */ #if MYSQL_PORT_DEFAULT == 0 - if ((serv_ptr = getservbyname("mysql", "tcp"))) - mysql_port = (uint) ntohs((ushort) serv_ptr->s_port); -#endif - if ((env = getenv("MYSQL_TCP_PORT"))) - mysql_port =(uint) atoi(env); - } + if ((serv_ptr= getservbyname("mysql", "tcp"))) + mysql_port= (uint) ntohs((ushort) serv_ptr->s_port); #endif + if ((env= getenv("MYSQL_TCP_PORT"))) + mysql_port=(uint) atoi(env); } + if (!mysql_unix_port) { char *env; @@ -165,7 +163,7 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)), mysql_unix_port = env; } mysql_debug(NullS); -#if defined(SIGPIPE) && !defined(__WIN__) && !defined(__NETWARE__) +#if defined(SIGPIPE) && !defined(__WIN__) (void) signal(SIGPIPE, SIG_IGN); #endif #ifdef EMBEDDED_LIBRARY @@ -216,13 +214,6 @@ void STDCALL mysql_server_end() } mysql_client_init= org_my_init_done= 0; -#ifdef EMBEDDED_SERVER - if (stderror_file) - { - fclose(stderror_file); - stderror_file= 0; - } -#endif } static MYSQL_PARAMETERS mysql_internal_parameters= @@ -249,16 +240,6 @@ void STDCALL mysql_thread_end() #endif } -/* - Let the user specify that we don't want SIGPIPE; This doesn't however work - with threaded applications as we can have multiple read in progress. -*/ -static MYSQL* spawn_init(MYSQL* parent, const char* host, - unsigned int port, - const char* user, - const char* passwd); - - /* Expand wildcard to a sql string @@ -320,7 +301,7 @@ mysql_debug(const char *debug __attribute__((unused))) /************************************************************************** - Close the server connection if we get a SIGPIPE + Ignore SIGPIPE handler ARGSUSED **************************************************************************/ @@ -333,305 +314,6 @@ my_pipe_sig_handler(int sig __attribute__((unused))) #endif } -/* perform query on master */ -my_bool STDCALL mysql_master_query(MYSQL *mysql, const char *q, - unsigned long length) -{ - DBUG_ENTER("mysql_master_query"); - if (mysql_master_send_query(mysql, q, length)) - DBUG_RETURN(1); - DBUG_RETURN((*mysql->methods->read_query_result)(mysql)); -} - -my_bool STDCALL mysql_master_send_query(MYSQL *mysql, const char *q, - unsigned long length) -{ - MYSQL *master = mysql->master; - DBUG_ENTER("mysql_master_send_query"); - if (!master->net.vio && !mysql_real_connect(master,0,0,0,0,0,0,0)) - DBUG_RETURN(1); - master->reconnect= 1; - mysql->last_used_con = master; - DBUG_RETURN(simple_command(master, COM_QUERY, (const uchar*) q, length, 1)); -} - - -/* perform query on slave */ -my_bool STDCALL mysql_slave_query(MYSQL *mysql, const char *q, - unsigned long length) -{ - DBUG_ENTER("mysql_slave_query"); - if (mysql_slave_send_query(mysql, q, length)) - DBUG_RETURN(1); - DBUG_RETURN((*mysql->methods->read_query_result)(mysql)); -} - - -my_bool STDCALL mysql_slave_send_query(MYSQL *mysql, const char *q, - unsigned long length) -{ - MYSQL* last_used_slave, *slave_to_use = 0; - DBUG_ENTER("mysql_slave_send_query"); - - if ((last_used_slave = mysql->last_used_slave)) - slave_to_use = last_used_slave->next_slave; - else - slave_to_use = mysql->next_slave; - /* - Next_slave is always safe to use - we have a circular list of slaves - if there are no slaves, mysql->next_slave == mysql - */ - mysql->last_used_con = mysql->last_used_slave = slave_to_use; - if (!slave_to_use->net.vio && !mysql_real_connect(slave_to_use, 0,0,0, - 0,0,0,0)) - DBUG_RETURN(1); - slave_to_use->reconnect= 1; - DBUG_RETURN(simple_command(slave_to_use, COM_QUERY, (const uchar*) q, - length, 1)); -} - - -/* enable/disable parsing of all queries to decide - if they go on master or slave */ -void STDCALL mysql_enable_rpl_parse(MYSQL* mysql) -{ - mysql->options.rpl_parse = 1; -} - -void STDCALL mysql_disable_rpl_parse(MYSQL* mysql) -{ - mysql->options.rpl_parse = 0; -} - -/* get the value of the parse flag */ -int STDCALL mysql_rpl_parse_enabled(MYSQL* mysql) -{ - return mysql->options.rpl_parse; -} - -/* enable/disable reads from master */ -void STDCALL mysql_enable_reads_from_master(MYSQL* mysql) -{ - mysql->options.no_master_reads = 0; -} - -void STDCALL mysql_disable_reads_from_master(MYSQL* mysql) -{ - mysql->options.no_master_reads = 1; -} - -/* get the value of the master read flag */ -my_bool STDCALL mysql_reads_from_master_enabled(MYSQL* mysql) -{ - return !(mysql->options.no_master_reads); -} - - -/* - We may get an error while doing replication internals. - In this case, we add a special explanation to the original - error -*/ - -static void expand_error(MYSQL* mysql, int error) -{ - char tmp[MYSQL_ERRMSG_SIZE]; - char *p; - uint err_length; - strmake(tmp, mysql->net.last_error, MYSQL_ERRMSG_SIZE-1); - p = strmake(mysql->net.last_error, ER(error), MYSQL_ERRMSG_SIZE-1); - err_length= (uint) (p - mysql->net.last_error); - strmake(p, tmp, MYSQL_ERRMSG_SIZE-1 - err_length); - mysql->net.last_errno = error; -} - -/* - This function assumes we have just called SHOW SLAVE STATUS and have - read the given result and row -*/ - -static my_bool get_master(MYSQL* mysql, MYSQL_RES* res, MYSQL_ROW row) -{ - MYSQL* master; - DBUG_ENTER("get_master"); - if (mysql_num_fields(res) < 3) - DBUG_RETURN(1); /* safety */ - - /* use the same username and password as the original connection */ - if (!(master = spawn_init(mysql, row[0], atoi(row[2]), 0, 0))) - DBUG_RETURN(1); - mysql->master = master; - DBUG_RETURN(0); -} - - -/* - Assuming we already know that mysql points to a master connection, - retrieve all the slaves -*/ - -static my_bool get_slaves_from_master(MYSQL* mysql) -{ - MYSQL_RES* res = 0; - MYSQL_ROW row; - my_bool error = 1; - int has_auth_info; - int port_ind; - DBUG_ENTER("get_slaves_from_master"); - - if (!mysql->net.vio && !mysql_real_connect(mysql,0,0,0,0,0,0,0)) - { - expand_error(mysql, CR_PROBE_MASTER_CONNECT); - DBUG_RETURN(1); - } - mysql->reconnect= 1; - - if (mysql_query(mysql, "SHOW SLAVE HOSTS") || - !(res = mysql_store_result(mysql))) - { - expand_error(mysql, CR_PROBE_SLAVE_HOSTS); - DBUG_RETURN(1); - } - - switch (mysql_num_fields(res)) { - case 5: - has_auth_info = 0; - port_ind=2; - break; - case 7: - has_auth_info = 1; - port_ind=4; - break; - default: - goto err; - } - - while ((row = mysql_fetch_row(res))) - { - MYSQL* slave; - const char* tmp_user, *tmp_pass; - - if (has_auth_info) - { - tmp_user = row[2]; - tmp_pass = row[3]; - } - else - { - tmp_user = mysql->user; - tmp_pass = mysql->passwd; - } - - if (!(slave = spawn_init(mysql, row[1], atoi(row[port_ind]), - tmp_user, tmp_pass))) - goto err; - - /* Now add slave into the circular linked list */ - slave->next_slave = mysql->next_slave; - mysql->next_slave = slave; - } - error = 0; -err: - if (res) - mysql_free_result(res); - DBUG_RETURN(error); -} - - -my_bool STDCALL mysql_rpl_probe(MYSQL* mysql) -{ - MYSQL_RES *res= 0; - MYSQL_ROW row; - my_bool error= 1; - DBUG_ENTER("mysql_rpl_probe"); - - /* - First determine the replication role of the server we connected to - the most reliable way to do this is to run SHOW SLAVE STATUS and see - if we have a non-empty master host. This is still not fool-proof - - it is not a sin to have a master that has a dormant slave thread with - a non-empty master host. However, it is more reliable to check - for empty master than whether the slave thread is actually running - */ - if (mysql_query(mysql, "SHOW SLAVE STATUS") || - !(res = mysql_store_result(mysql))) - { - expand_error(mysql, CR_PROBE_SLAVE_STATUS); - DBUG_RETURN(1); - } - - row= mysql_fetch_row(res); - /* - Check master host for emptiness/NULL - For MySQL 4.0 it's enough to check for row[0] - */ - if (row && row[0] && *(row[0])) - { - /* this is a slave, ask it for the master */ - if (get_master(mysql, res, row) || get_slaves_from_master(mysql)) - goto err; - } - else - { - mysql->master = mysql; - if (get_slaves_from_master(mysql)) - goto err; - } - - error = 0; -err: - if (res) - mysql_free_result(res); - DBUG_RETURN(error); -} - - -/* - Make a not so fool-proof decision on where the query should go, to - the master or the slave. Ideally the user should always make this - decision himself with mysql_master_query() or mysql_slave_query(). - However, to be able to more easily port the old code, we support the - option of an educated guess - this should work for most applications, - however, it may make the wrong decision in some particular cases. If - that happens, the user would have to change the code to call - mysql_master_query() or mysql_slave_query() explicitly in the place - where we have made the wrong decision -*/ - -enum mysql_rpl_type -STDCALL mysql_rpl_query_type(const char* q, int len) -{ - const char *q_end= q + len; - for (; q < q_end; ++q) - { - char c; - if (my_isalpha(&my_charset_latin1, (c= *q))) - { - switch (my_tolower(&my_charset_latin1,c)) { - case 'i': /* insert */ - case 'u': /* update or unlock tables */ - case 'l': /* lock tables or load data infile */ - case 'd': /* drop or delete */ - case 'a': /* alter */ - return MYSQL_RPL_MASTER; - case 'c': /* create or check */ - return my_tolower(&my_charset_latin1,q[1]) == 'h' ? MYSQL_RPL_ADMIN : - MYSQL_RPL_MASTER; - case 's': /* select or show */ - return my_tolower(&my_charset_latin1,q[1]) == 'h' ? MYSQL_RPL_ADMIN : - MYSQL_RPL_SLAVE; - case 'f': /* flush */ - case 'r': /* repair */ - case 'g': /* grant */ - return MYSQL_RPL_ADMIN; - default: - return MYSQL_RPL_SLAVE; - } - } - } - return MYSQL_RPL_MASTER; /* By default, send to master */ -} - /************************************************************************** Connect to sql server @@ -650,7 +332,7 @@ mysql_connect(MYSQL *mysql,const char *host, if (!(res=mysql_real_connect(mysql,host,user,passwd,NullS,0,NullS,0))) { if (mysql->free_me) - my_free((uchar*) mysql,MYF(0)); + my_free(mysql); } mysql->reconnect= 1; DBUG_RETURN(res); @@ -766,9 +448,9 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, if (rc == 0) { /* Free old connect information */ - my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->user); + my_free(mysql->passwd); + my_free(mysql->db); /* alloc new connect information */ mysql->user= my_strdup(user,MYF(MY_WME)); @@ -788,15 +470,7 @@ struct passwd *getpwuid(uid_t); char* getlogin(void); #endif -#if defined(__NETWARE__) -/* Default to value of USER on NetWare, if unset use "UNKNOWN_USER" */ -void read_user_name(char *name) -{ - char *str=getenv("USER"); - strmake(name, str ? str : "UNKNOWN_USER", USERNAME_LENGTH); -} - -#elif !defined(MSDOS) && ! defined(VMS) && !defined(__WIN__) +#if !defined(__WIN__) void read_user_name(char *name) { @@ -826,7 +500,7 @@ void read_user_name(char *name) DBUG_VOID_RETURN; } -#else /* If MSDOS || VMS */ +#else /* If Windows */ void read_user_name(char *name) { @@ -868,7 +542,7 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename) if ((*options->local_infile_init)(&li_ptr, net_filename, options->local_infile_userdata)) { - VOID(my_net_write(net,(const uchar*) "",0)); /* Server needs one packet */ + (void) my_net_write(net,(const uchar*) "",0); /* Server needs one packet */ net_flush(net); strmov(net->sqlstate, unknown_sqlstate); net->last_errno= @@ -913,7 +587,7 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename) err: /* free up memory allocated with _init, usually */ (*options->local_infile_end)(li_ptr); - my_free(buf, MYF(0)); + my_free(buf); DBUG_RETURN(result); } @@ -1024,7 +698,7 @@ static void default_local_infile_end(void *ptr) { if (data->fd >= 0) my_close(data->fd, MYF(MY_WME)); - my_free(ptr, MYF(MY_WME)); + my_free(ptr); } } @@ -1096,68 +770,6 @@ mysql_query(MYSQL *mysql, const char *query) } -static MYSQL* spawn_init(MYSQL* parent, const char* host, - unsigned int port, const char* user, - const char* passwd) -{ - MYSQL* child; - DBUG_ENTER("spawn_init"); - if (!(child= mysql_init(0))) - DBUG_RETURN(0); - - child->options.user= my_strdup((user) ? user : - (parent->user ? parent->user : - parent->options.user), MYF(0)); - child->options.password= my_strdup((passwd) ? passwd : - (parent->passwd ? - parent->passwd : - parent->options.password), MYF(0)); - child->options.port= port; - child->options.host= my_strdup((host) ? host : - (parent->host ? - parent->host : - parent->options.host), MYF(0)); - if (parent->db) - child->options.db= my_strdup(parent->db, MYF(0)); - else if (parent->options.db) - child->options.db= my_strdup(parent->options.db, MYF(0)); - - /* - rpl_pivot is set to 1 in mysql_init(); Reset it as we are not doing - replication here - */ - child->rpl_pivot= 0; - DBUG_RETURN(child); -} - - -int -STDCALL mysql_set_master(MYSQL* mysql, const char* host, - unsigned int port, const char* user, - const char* passwd) -{ - if (mysql->master != mysql && !mysql->master->rpl_pivot) - mysql_close(mysql->master); - if (!(mysql->master = spawn_init(mysql, host, port, user, passwd))) - return 1; - return 0; -} - - -int -STDCALL mysql_add_slave(MYSQL* mysql, const char* host, - unsigned int port, - const char* user, - const char* passwd) -{ - MYSQL* slave; - if (!(slave = spawn_init(mysql, host, port, user, passwd))) - return 1; - slave->next_slave = mysql->next_slave; - mysql->next_slave = slave; - return 0; -} - /************************************************************************** Return next field of the query results **************************************************************************/ @@ -1486,17 +1098,17 @@ MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res) unsigned int STDCALL mysql_field_count(MYSQL *mysql) { - return mysql->last_used_con->field_count; + return mysql->field_count; } my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql) { - return mysql->last_used_con->affected_rows; + return mysql->affected_rows; } my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql) { - return mysql->last_used_con->insert_id; + return mysql->insert_id; } const char *STDCALL mysql_sqlstate(MYSQL *mysql) @@ -1861,7 +1473,6 @@ my_bool cli_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt) MYSQL_DATA *fields_data; DBUG_ENTER("cli_read_prepare_result"); - mysql= mysql->last_used_con; if ((packet_length= cli_safe_read(mysql)) == packet_error) DBUG_RETURN(1); mysql->warning_count= 0; @@ -2095,7 +1706,9 @@ static void alloc_stmt_fields(MYSQL_STMT *stmt) { MYSQL_FIELD *fields, *field, *end; MEM_ROOT *alloc= &stmt->mem_root; - MYSQL *mysql= stmt->mysql->last_used_con; + MYSQL *mysql= stmt->mysql; + + DBUG_ASSERT(mysql->field_count); stmt->field_count= mysql->field_count; @@ -2118,18 +1731,21 @@ static void alloc_stmt_fields(MYSQL_STMT *stmt) field= stmt->fields; field && fields < end; fields++, field++) { - field->db = strdup_root(alloc,fields->db); - field->table = strdup_root(alloc,fields->table); - field->org_table= strdup_root(alloc,fields->org_table); - field->name = strdup_root(alloc,fields->name); - field->org_name = strdup_root(alloc,fields->org_name); - field->charsetnr= fields->charsetnr; - field->length = fields->length; - field->type = fields->type; - field->flags = fields->flags; - field->decimals = fields->decimals; - field->def = fields->def ? strdup_root(alloc,fields->def): 0; - field->max_length= 0; + *field= *fields; /* To copy all numeric parts. */ + field->catalog= strmake_root(alloc, fields->catalog, + fields->catalog_length); + field->db= strmake_root(alloc, fields->db, fields->db_length); + field->table= strmake_root(alloc, fields->table, fields->table_length); + field->org_table= strmake_root(alloc, fields->org_table, + fields->org_table_length); + field->name= strmake_root(alloc, fields->name, fields->name_length); + field->org_name= strmake_root(alloc, fields->org_name, + fields->org_name_length); + field->def= fields->def ? strmake_root(alloc, fields->def, + fields->def_length) : 0; + field->def_length= field->def ? fields->def_length : 0; + field->extension= 0; /* Avoid dangling links. */ + field->max_length= 0; /* max_length is set in mysql_stmt_store_result() */ } } @@ -2482,7 +2098,6 @@ static my_bool execute(MYSQL_STMT *stmt, char *packet, ulong length) DBUG_ENTER("execute"); DBUG_DUMP("packet", (uchar *) packet, length); - mysql->last_used_con= mysql; int4store(buff, stmt->stmt_id); /* Send stmt id to server */ buff[4]= (char) stmt->flags; int4store(buff+5, 1); /* iteration count */ @@ -2581,7 +2196,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt) } result= execute(stmt, param_data, length); stmt->send_types_to_server=0; - my_free(param_data, MYF(MY_WME)); + my_free(param_data); DBUG_RETURN(result); } DBUG_RETURN((int) execute(stmt,0,0)); @@ -2869,6 +2484,33 @@ static void reinit_result_set_metadata(MYSQL_STMT *stmt) } +static void prepare_to_fetch_result(MYSQL_STMT *stmt) +{ + if (stmt->server_status & SERVER_STATUS_CURSOR_EXISTS) + { + stmt->mysql->status= MYSQL_STATUS_READY; + stmt->read_row_func= stmt_read_row_from_cursor; + } + else if (stmt->flags & CURSOR_TYPE_READ_ONLY) + { + /* + This is a single-row result set, a result set with no rows, EXPLAIN, + SHOW VARIABLES, or some other command which either a) bypasses the + cursors framework in the server and writes rows directly to the + network or b) is more efficient if all (few) result set rows are + precached on client and server's resources are freed. + */ + mysql_stmt_store_result(stmt); + } + else + { + stmt->mysql->unbuffered_fetch_owner= &stmt->unbuffered_fetch_cancelled; + stmt->unbuffered_fetch_cancelled= FALSE; + stmt->read_row_func= stmt_read_row_unbuffered; + } +} + + /* Send placeholders data to server (if there are placeholders) and execute prepared statement. @@ -2936,28 +2578,7 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) if (mysql->field_count) { reinit_result_set_metadata(stmt); - if (stmt->server_status & SERVER_STATUS_CURSOR_EXISTS) - { - mysql->status= MYSQL_STATUS_READY; - stmt->read_row_func= stmt_read_row_from_cursor; - } - else if (stmt->flags & CURSOR_TYPE_READ_ONLY) - { - /* - This is a single-row result set, a result set with no rows, EXPLAIN, - SHOW VARIABLES, or some other command which either a) bypasses the - cursors framework in the server and writes rows directly to the - network or b) is more efficient if all (few) result set rows are - precached on client and server's resources are freed. - */ - mysql_stmt_store_result(stmt); - } - else - { - stmt->mysql->unbuffered_fetch_owner= &stmt->unbuffered_fetch_cancelled; - stmt->unbuffered_fetch_cancelled= FALSE; - stmt->read_row_func= stmt_read_row_unbuffered; - } + prepare_to_fetch_result(stmt); } DBUG_RETURN(test(stmt->last_errno)); } @@ -3755,12 +3376,13 @@ static void fetch_long_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, param output buffer descriptor field column metadata value column data - width default number of significant digits used when converting - float/double to string + type either MY_GCVT_ARG_FLOAT or MY_GCVT_ARG_DOUBLE. + Affects the maximum number of significant digits + returned by my_gcvt(). */ static void fetch_float_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, - double value, int width) + double value, my_gcvt_arg_type type) { char *buffer= (char *)param->buffer; double val64 = (value < 0 ? -floor(-value) : floor(value)); @@ -3844,42 +3466,24 @@ static void fetch_float_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, floating point -> string conversion nicely, honor all typecodes and param->offset possibly set in mysql_stmt_fetch_column */ - char buff[MAX_DOUBLE_STRING_REP_LENGTH]; - char *end; - /* TODO: move this to a header shared between client and server. */ -#define NOT_FIXED_DEC 31 + char buff[FLOATING_POINT_BUFFER]; + size_t len; if (field->decimals >= NOT_FIXED_DEC) -#undef NOT_FIXED_DEC - { - /* - DBL_DIG below is to ensure that the server and client has the same - precisions. This will ensure that on the same machine you get the - same value as a string independent of the protocol you use. - */ - sprintf(buff, "%-*.*g", (int) min(sizeof(buff)-1, - param->buffer_length), - min(DBL_DIG, width), value); - end= strcend(buff, ' '); - *end= 0; - } + len= my_gcvt(value, type, + (int) min(sizeof(buff)-1, param->buffer_length), + buff, NULL); else - { - sprintf(buff, "%.*f", (int) field->decimals, value); - end= strend(buff); - } + len= my_fcvt(value, (int) field->decimals, buff, NULL); + if (field->flags & ZEROFILL_FLAG && len < field->length && + field->length < MAX_DOUBLE_STRING_REP_LENGTH - 1) { - size_t length= end - buff; - if (field->flags & ZEROFILL_FLAG && length < field->length && - field->length < MAX_DOUBLE_STRING_REP_LENGTH - 1) - { - bmove_upp((uchar*) buff + field->length, (uchar*) buff + length, - length); - bfill((char*) buff, field->length - length, '0'); - length= field->length; - } - fetch_string_with_conversion(param, buff, length); + bmove_upp((uchar*) buff + field->length, (uchar*) buff + len, + len); + bfill((char*) buff, field->length - len, '0'); + len= field->length; } + fetch_string_with_conversion(param, buff, len); break; } @@ -3924,7 +3528,7 @@ static void fetch_datetime_with_conversion(MYSQL_BIND *param, { ulonglong value= TIME_to_ulonglong(my_time); fetch_float_with_conversion(param, field, - ulonglong2double(value), DBL_DIG); + ulonglong2double(value), MY_GCVT_ARG_DOUBLE); break; } case MYSQL_TYPE_TINY: @@ -4018,7 +3622,7 @@ static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, { float value; float4get(value,*row); - fetch_float_with_conversion(param, field, value, FLT_DIG); + fetch_float_with_conversion(param, field, value, MY_GCVT_ARG_FLOAT); *row+= 4; break; } @@ -4026,7 +3630,7 @@ static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, { double value; float8get(value,*row); - fetch_float_with_conversion(param, field, value, DBL_DIG); + fetch_float_with_conversion(param, field, value, MY_GCVT_ARG_DOUBLE); *row+= 8; break; } @@ -4709,7 +4313,6 @@ int cli_read_binary_rows(MYSQL_STMT *stmt) } net = &mysql->net; - mysql= mysql->last_used_con; while ((pkt_len= cli_safe_read(mysql)) != packet_error) { @@ -4807,8 +4410,6 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) DBUG_RETURN(1); } - mysql= mysql->last_used_con; - if (!stmt->field_count) DBUG_RETURN(0); @@ -5015,7 +4616,7 @@ static my_bool reset_stmt_handle(MYSQL_STMT *stmt, uint flags) if (stmt->field_count && mysql->status != MYSQL_STATUS_READY) { /* There is a result set and it belongs to this statement */ - (*mysql->methods->flush_use_result)(mysql); + (*mysql->methods->flush_use_result)(mysql, FALSE); if (mysql->unbuffered_fetch_owner) *mysql->unbuffered_fetch_owner= TRUE; mysql->status= MYSQL_STATUS_READY; @@ -5099,7 +4700,7 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) Flush result set of the connection. If it does not belong to this statement, set a warning. */ - (*mysql->methods->flush_use_result)(mysql); + (*mysql->methods->flush_use_result)(mysql, TRUE); if (mysql->unbuffered_fetch_owner) *mysql->unbuffered_fetch_owner= TRUE; mysql->status= MYSQL_STATUS_READY; @@ -5112,7 +4713,7 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) } } - my_free((uchar*) stmt, MYF(MY_WME)); + my_free(stmt); DBUG_RETURN(test(rc)); } @@ -5218,8 +4819,7 @@ my_bool STDCALL mysql_more_results(MYSQL *mysql) my_bool res; DBUG_ENTER("mysql_more_results"); - res= ((mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS) ? - 1: 0); + res= ((mysql->server_status & SERVER_MORE_RESULTS_EXISTS) ? 1: 0); DBUG_PRINT("exit",("More results exists ? %d", res)); DBUG_RETURN(res); } @@ -5241,13 +4841,56 @@ int STDCALL mysql_next_result(MYSQL *mysql) net_clear_error(&mysql->net); mysql->affected_rows= ~(my_ulonglong) 0; - if (mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS) + if (mysql->server_status & SERVER_MORE_RESULTS_EXISTS) DBUG_RETURN((*mysql->methods->next_result)(mysql)); DBUG_RETURN(-1); /* No more results */ } +int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt) +{ + MYSQL *mysql= stmt->mysql; + int rc; + DBUG_ENTER("mysql_stmt_next_result"); + + if (!mysql) + DBUG_RETURN(1); + + if (stmt->last_errno) + DBUG_RETURN(stmt->last_errno); + + if (mysql->server_status & SERVER_MORE_RESULTS_EXISTS) + { + if (reset_stmt_handle(stmt, RESET_STORE_RESULT)) + DBUG_RETURN(1); + } + + rc= mysql_next_result(mysql); + + if (rc) + { + set_stmt_errmsg(stmt, &mysql->net); + DBUG_RETURN(rc); + } + + stmt->state= MYSQL_STMT_EXECUTE_DONE; + stmt->bind_result_done= FALSE; + + if (mysql->field_count) + { + alloc_stmt_fields(stmt); + prepare_to_fetch_result(stmt); + } + else + { + stmt->field_count= mysql->field_count; + } + + DBUG_RETURN(0); +} + + MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql) { return (*mysql->methods->use_result)(mysql); diff --git a/libmysql/libmysql.def b/libmysql/libmysql.def index 81f86dc8726..ce85d2a4086 100644 --- a/libmysql/libmysql.def +++ b/libmysql/libmysql.def @@ -1,33 +1,7 @@ LIBRARY LIBMYSQL VERSION 6.0 EXPORTS - _dig_vec_lower - _dig_vec_upper - bmove_upp - delete_dynamic - free_defaults - getopt_compare_strings - getopt_ull_limit_value - handle_options - init_dynamic_array - insert_dynamic - int2str - is_prefix - list_add - list_delete load_defaults - my_end - my_getopt_print_errors - my_init - my_malloc - my_memdup - my_no_flags_free - my_path - mysql_get_parameters - my_print_help - my_print_variables - my_realloc - my_strdup mysql_thread_end mysql_thread_init myodbc_remove_escape @@ -117,37 +91,16 @@ EXPORTS mysql_stmt_sqlstate mysql_sqlstate mysql_get_server_version - set_dynamic - strcend - strcont - strdup_root - strfill - strinstr - strmake - strmov - strxmov mysql_stmt_prepare mysql_stmt_init mysql_stmt_insert_id mysql_stmt_attr_get mysql_stmt_attr_set mysql_stmt_field_count - client_errors mysql_set_local_infile_default mysql_set_local_infile_handler - mysql_disable_reads_from_master - mysql_disable_rpl_parse - mysql_enable_reads_from_master - mysql_enable_rpl_parse - mysql_master_query - mysql_rpl_parse_enabled - mysql_rpl_probe - mysql_rpl_query_type - mysql_slave_query mysql_embedded mysql_server_init mysql_server_end mysql_set_character_set mysql_get_character_set_info - get_defaults_options - modify_defaults_file diff --git a/libmysql/manager.c b/libmysql/manager.c deleted file mode 100644 index 53ffffa55c0..00000000000 --- a/libmysql/manager.c +++ /dev/null @@ -1,269 +0,0 @@ -/* Copyright (C) 2000-2004 MySQL AB - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation. - - There are special exceptions to the terms and conditions of the GPL as it - is applied to this software. View the full text of the exception in file - EXCEPTIONS-CLIENT in the directory of this software distribution. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -#include <my_global.h> -#if defined(THREAD) -#include <my_pthread.h> /* because of signal() */ -#endif -#include "mysql.h" -#include "mysql_version.h" -#include "mysqld_error.h" -#include <my_sys.h> -#include <mysys_err.h> -#include <m_string.h> -#include <m_ctype.h> -#include <my_net.h> -#include <errmsg.h> -#include <violite.h> -#include <sys/stat.h> -#include <signal.h> -#include <errno.h> - -#if defined(__NETWARE__) -#include <netdb.h> -#include <sys/select.h> -#include <sys/utsname.h> -#elif !defined( __WIN__) -#include <sys/resource.h> -#ifdef HAVE_SYS_UN_H -# include <sys/un.h> -#endif -#include <netdb.h> -#ifdef HAVE_SELECT_H -# include <select.h> -#endif -#ifdef HAVE_SYS_SELECT_H -#include <sys/select.h> -#endif -#include <sys/utsname.h> -#endif /* __WIN__ */ - -#ifndef INADDR_NONE -#define INADDR_NONE -1 -#endif - -#define RES_BUF_SHIFT 5 -#define NET_BUF_SIZE 2048 - -MYSQL_MANAGER* STDCALL mysql_manager_init(MYSQL_MANAGER* con) -{ - int net_buf_size=NET_BUF_SIZE; - if (!con) - { - if (!(con=(MYSQL_MANAGER*)my_malloc(sizeof(*con)+net_buf_size, - MYF(MY_WME|MY_ZEROFILL)))) - return 0; - con->free_me=1; - con->net_buf=(char*)con+sizeof(*con); - } - else - { - bzero((char*)con,sizeof(*con)); - if (!(con->net_buf=my_malloc(net_buf_size,MYF(0)))) - return 0; - } - con->net_buf_pos=con->net_data_end=con->net_buf; - con->net_buf_size=net_buf_size; - return con; -} - -MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con, - const char* host, - const char* user, - const char* passwd, - unsigned int port) -{ - my_socket sock; - struct sockaddr_in sock_addr; - in_addr_t ip_addr; - char msg_buf[MAX_MYSQL_MANAGER_MSG]; - int msg_len; - Vio* vio; - my_bool not_used; - - if (!host) - host="localhost"; - if (!user) - user="root"; - if (!passwd) - passwd=""; - - if ((sock=(my_socket)socket(AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET) - { - con->last_errno=errno; - strmov(con->last_error,"Cannot create socket"); - goto err; - } - if (!(vio=vio_new(sock,VIO_TYPE_TCPIP,FALSE))) - { - con->last_errno=ENOMEM; - strmov(con->last_error,"Cannot create network I/O object"); - goto err; - } - vio_blocking(vio, TRUE, ¬_used); - my_net_init(&con->net,vio); - bzero((char*) &sock_addr,sizeof(sock_addr)); - sock_addr.sin_family = AF_INET; - if ((int) (ip_addr = inet_addr(host)) != (int) INADDR_NONE) - { - memcpy_fixed(&sock_addr.sin_addr,&ip_addr,sizeof(ip_addr)); - } - else - { - int tmp_errno; - struct hostent tmp_hostent,*hp; - char buff2[GETHOSTBYNAME_BUFF_SIZE]; - hp = my_gethostbyname_r(host,&tmp_hostent,buff2,sizeof(buff2), - &tmp_errno); - if (!hp) - { - con->last_errno=tmp_errno; - sprintf(con->last_error,"Could not resolve host '%-.64s'",host); - my_gethostbyname_r_free(); - goto err; - } - memcpy(&sock_addr.sin_addr,hp->h_addr, (size_t) hp->h_length); - my_gethostbyname_r_free(); - } - sock_addr.sin_port = (ushort) htons((ushort) port); - if (my_connect(sock,(struct sockaddr *) &sock_addr, sizeof(sock_addr), - 0)) - { - con->last_errno=errno; - sprintf(con->last_error ,"Could not connect to %-.64s", host); - goto err; - } - /* read the greating */ - if (my_net_read(&con->net) == packet_error) - { - con->last_errno=errno; - strmov(con->last_error,"Read error on socket"); - goto err; - } - sprintf(msg_buf,"%-.16s %-.16s\n",user,passwd); - msg_len=strlen(msg_buf); - if (my_net_write(&con->net,(uchar*) msg_buf,msg_len) || net_flush(&con->net)) - { - con->last_errno=con->net.last_errno; - strmov(con->last_error,"Write error on socket"); - goto err; - } - if (my_net_read(&con->net) == packet_error) - { - con->last_errno=errno; - strmov(con->last_error,"Read error on socket"); - goto err; - } - if ((con->cmd_status=atoi((char*) con->net.read_pos)) != MANAGER_OK) - { - strmov(con->last_error,"Access denied"); - goto err; - } - if (!my_multi_malloc(MYF(0), &con->host, (uint)strlen(host)+1, - &con->user, (uint)strlen(user)+1, - &con->passwd, (uint)strlen(passwd)+1, - NullS)) - { - con->last_errno=ENOMEM; - strmov(con->last_error,"Out of memory"); - goto err; - } - strmov(con->host,host); - strmov(con->user,user); - strmov(con->passwd,passwd); - return con; - -err: - { - my_bool free_me=con->free_me; - con->free_me=0; - mysql_manager_close(con); - con->free_me=free_me; - } - return 0; -} - -void STDCALL mysql_manager_close(MYSQL_MANAGER* con) -{ - /* - No need to free con->user and con->passwd, because they were - allocated in my_multimalloc() along with con->host, freeing - con->hosts frees the whole block - */ - my_free((uchar*)con->host,MYF(MY_ALLOW_ZERO_PTR)); - net_end(&con->net); - if (con->free_me) - my_free((uchar*)con,MYF(0)); -} - - -int STDCALL mysql_manager_command(MYSQL_MANAGER* con,const char* cmd, - int cmd_len) -{ - if (!cmd_len) - cmd_len=strlen(cmd); - if (my_net_write(&con->net,(const uchar*)cmd,cmd_len) || net_flush(&con->net)) - { - con->last_errno=errno; - strmov(con->last_error,"Write error on socket"); - return 1; - } - con->eof=0; - return 0; -} - - -int STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con, char* res_buf, - int res_buf_size) -{ - char* res_buf_end=res_buf+res_buf_size; - char* net_buf=(char*) con->net.read_pos, *net_buf_end; - int res_buf_shift=RES_BUF_SHIFT; - ulong num_bytes; - - if (res_buf_size<RES_BUF_SHIFT) - { - con->last_errno=ENOMEM; - strmov(con->last_error,"Result buffer too small"); - return 1; - } - - if ((num_bytes=my_net_read(&con->net)) == packet_error) - { - con->last_errno=errno; - strmov(con->last_error,"socket read failed"); - return 1; - } - - net_buf_end=net_buf+num_bytes; - - if ((con->eof=(net_buf[3]==' '))) - res_buf_shift--; - net_buf+=res_buf_shift; - res_buf_end[-1]=0; - for (;net_buf<net_buf_end && res_buf < res_buf_end;res_buf++,net_buf++) - { - if ((*res_buf=*net_buf) == '\r') - { - *res_buf=0; - break; - } - } - return 0; -} |