summaryrefslogtreecommitdiff
path: root/libmysql
diff options
context:
space:
mode:
Diffstat (limited to 'libmysql')
-rwxr-xr-xlibmysql/CMakeLists.txt19
-rw-r--r--libmysql/Makefile.am6
-rw-r--r--libmysql/Makefile.shared12
-rw-r--r--libmysql/client_settings.h10
-rw-r--r--libmysql/dll.c25
-rw-r--r--libmysql/errmsg.c6
-rw-r--r--libmysql/get_password.c10
-rw-r--r--libmysql/libmysql.c500
-rw-r--r--libmysql/libmysql.def1
-rw-r--r--libmysql/manager.c16
10 files changed, 326 insertions, 279 deletions
diff --git a/libmysql/CMakeLists.txt b/libmysql/CMakeLists.txt
index cd90b2b1257..55138e4aa06 100755
--- a/libmysql/CMakeLists.txt
+++ b/libmysql/CMakeLists.txt
@@ -38,6 +38,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
# Include and add the directory path
SET(SOURCE_SUBLIBS TRUE)
+SET(LIB_SOURCES "")
INCLUDE(${CMAKE_SOURCE_DIR}/zlib/CMakeLists.txt)
FOREACH(rpath ${ZLIB_SOURCES})
@@ -97,7 +98,7 @@ SET(CLIENT_SOURCES ../mysys/array.c ../strings/bchange.c ../strings/bmove.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
- ${LIB_SOURCES})
+ ../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.
@@ -110,21 +111,21 @@ SET(CLIENT_SOURCES ../mysys/array.c ../strings/bchange.c ../strings/bmove.c
# beond the documented API, and try access the Thread Local Storage.
# The "_notls" means no Tls*() functions used, i.e. "static" TLS.
-ADD_LIBRARY(libmysql SHARED ${CLIENT_SOURCES} dll.c libmysql.def)
ADD_LIBRARY(mysqlclient STATIC ${CLIENT_SOURCES})
-ADD_LIBRARY(mysqlclient_notls STATIC ${CLIENT_SOURCES})
-
-SET_TARGET_PROPERTIES(libmysql mysqlclient PROPERTIES COMPILE_FLAGS "-DUSE_TLS")
-
-ADD_DEPENDENCIES(libmysql GenError)
-TARGET_LINK_LIBRARIES(libmysql wsock32)
-
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)
diff --git a/libmysql/Makefile.am b/libmysql/Makefile.am
index bab3368fbbf..cb6b70b84d2 100644
--- a/libmysql/Makefile.am
+++ b/libmysql/Makefile.am
@@ -20,7 +20,7 @@
# This file is public domain and comes with NO WARRANTY of any kind
target = libmysqlclient.la
-target_defs = -DUNDEF_THREADS_HACK -DDONT_USE_RAID @LIB_EXTRA_CCFLAGS@
+target_defs = -DMYSQL_CLIENT_NO_THREADS -DDONT_USE_RAID @LIB_EXTRA_CCFLAGS@
LIBS = @CLIENT_LIBS@
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \
$(openssl_includes) @ZLIB_INCLUDES@
@@ -33,7 +33,6 @@ libmysqlclient_la_LDFLAGS = $(target_ldflags)
EXTRA_DIST = Makefile.shared libmysql.def dll.c CMakeLists.txt
noinst_HEADERS = client_settings.h
-# This is called from the toplevel makefile
link_sources:
set -x; \
ss=`echo $(mystringsobjects) | sed "s;\.lo;.c;g"`; \
@@ -69,6 +68,7 @@ link_sources:
@LN_CP_F@ $(top_srcdir)/sql/net_serv.cc net.c ; \
rm -f password.c; \
@LN_CP_F@ $(top_srcdir)/sql/password.c password.c
+ echo timestamp > link_sources
# This part requires GNUmake
#
@@ -103,7 +103,7 @@ do-lib-dist:
echo "# A very minimal Makefile to compile" > $$dir/Makefile; \
echo "# the minimized libmysql library" >> $$dir/Makefile; \
echo "# This file is autogenerated from Makefile.am" >> $$dir/Makefile; \
- echo 'CFLAGS= -I. -DUNDEF_THREADS_HACK' >>$$dir/Makefile; \
+ echo 'CFLAGS= -I. -DMYSQL_CLIENT_NO_THREADS' >>$$dir/Makefile; \
echo "obj=$$objs" >>$$dir/Makefile; \
echo 'all: libmysql.a' >>$$dir/Makefile; \
echo 'libmysql.a: $$(obj)' >>$$dir/Makefile; \
diff --git a/libmysql/Makefile.shared b/libmysql/Makefile.shared
index 83ae79ebee2..a27949eb7ca 100644
--- a/libmysql/Makefile.shared
+++ b/libmysql/Makefile.shared
@@ -37,7 +37,7 @@ mystringsobjects = strmov.lo strxmov.lo strxnmov.lo strnmov.lo \
strmake.lo strend.lo strtod.lo \
strnlen.lo strfill.lo is_prefix.lo \
int2str.lo str2int.lo strinstr.lo strcont.lo \
- strcend.lo bcmp.lo ctype-latin1.lo \
+ strcend.lo ctype-latin1.lo \
bchange.lo bmove.lo bmove_upp.lo longlong2str.lo \
strtoull.lo strtoll.lo llstr.lo my_vsnprintf.lo \
ctype.lo ctype-simple.lo ctype-bin.lo ctype-mb.lo \
@@ -67,7 +67,7 @@ mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.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_rename.lo my_chsize.lo my_sync.lo my_getsystime.lo
sqlobjects = net.lo
sql_cmn_objects = pack.lo client.lo my_time.lo
@@ -78,8 +78,11 @@ target_libadd = $(mysysobjects) $(mystringsobjects) $(dbugobjects) \
$(sql_cmn_objects) $(vio_objects) $(sqlobjects)
target_ldflags = -version-info @SHARED_LIB_VERSION@ @LD_VERSION_SCRIPT@
vio_objects= vio.lo viosocket.lo viossl.lo viosslfactories.lo
+
+BUILT_SOURCES = link_sources
+
CLEANFILES = $(target_libadd) $(SHLIBOBJS) \
- $(target)
+ $(target) $(BUILT_SOURCES)
DEFS = -DDEFAULT_CHARSET_HOME="\"$(MYSQLBASEdir)\"" \
-DMYSQL_DATADIR="\"$(MYSQLDATAdir)\"" \
-DDEFAULT_HOME_ENV=MYSQL_HOME \
@@ -102,8 +105,7 @@ clean-local:
`echo $(vio_objects) | sed "s;\.lo;.c;g"` \
`echo $(sql_cmn_objects) | sed "s;\.lo;.c;g"` \
$(CHARSET_SRCS) $(CHARSET_OBJS) \
- $(mystringsextra) $(mysysheaders) $(vioheaders)\
- ../linked_libmysql_sources ../linked_libmysql_r_sources \
+ $(mystringsextra) $(mysysheaders) $(vioheaders) \
net.c
conf_to_src_SOURCES = conf_to_src.c
diff --git a/libmysql/client_settings.h b/libmysql/client_settings.h
index b67fbbc03af..f87e625771f 100644
--- a/libmysql/client_settings.h
+++ b/libmysql/client_settings.h
@@ -14,7 +14,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
extern uint mysql_port;
-extern my_string mysql_unix_port;
+extern char * mysql_unix_port;
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | \
CLIENT_TRANSACTIONS | \
@@ -41,8 +41,8 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename);
void mysql_read_default_options(struct st_mysql_options *options,
const char *filename,const char *group);
-void mysql_detach_stmt_list(LIST **stmt_list);
-MYSQL *
+void mysql_detach_stmt_list(LIST **stmt_list, const char *func_name);
+MYSQL * STDCALL
cli_mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
const char *passwd, const char *db,
uint port, const char *unix_socket,ulong client_flag);
@@ -63,3 +63,7 @@ int cli_read_change_user_result(MYSQL *mysql, char *buff, const char *passwd);
int init_embedded_server(int argc, char **argv, char **groups);
void end_embedded_server();
#endif /*EMBEDDED_LIBRARY*/
+
+C_MODE_START
+extern int mysql_init_character_set(MYSQL *mysql);
+C_MODE_END
diff --git a/libmysql/dll.c b/libmysql/dll.c
index a6a6a155dd3..8654c035c63 100644
--- a/libmysql/dll.c
+++ b/libmysql/dll.c
@@ -24,7 +24,7 @@
#include <my_sys.h>
#include <my_pthread.h>
-static bool libmysql_inited=0;
+static my_bool libmysql_inited=0;
void libmysql_init(void)
{
@@ -122,26 +122,3 @@ int _export FAR PASCAL libmain(HANDLE hModule,short cbHeapSize,
}
#endif
-
-#ifdef OS2
-
-/*
- This function is called automatically by _DLL_InitTerm
- Every dll runtime enviroment is not tz enabled, so tzset()
- must be called to enable TZ handling
- Also timezone is fixed.
-*/
-
-extern "C" unsigned long _System DllMain(unsigned long modhandle,
- unsigned long flag)
-{
- if (flag == 0) {
- tzset(); /* Set tzname */
- time_t currentTime = time(NULL);
- struct tm *ts = localtime(&currentTime);
- if (ts->tm_isdst > 0)
- _timezone -= 3600;
- }
-}
-
-#endif
diff --git a/libmysql/errmsg.c b/libmysql/errmsg.c
index b509c53bc1b..163632127c3 100644
--- a/libmysql/errmsg.c
+++ b/libmysql/errmsg.c
@@ -82,6 +82,8 @@ const char *client_errors[]=
"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",
""
};
@@ -146,6 +148,8 @@ const char *client_errors[]=
"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",
""
};
@@ -208,6 +212,8 @@ const char *client_errors[]=
"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",
""
};
#endif
diff --git a/libmysql/get_password.c b/libmysql/get_password.c
index 80b3c23c2f8..63d4e68541f 100644
--- a/libmysql/get_password.c
+++ b/libmysql/get_password.c
@@ -35,7 +35,7 @@
#include <pwd.h>
#endif /* HAVE_PWD_H */
#else /* ! HAVE_GETPASS */
-#if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__)
+#if !defined(__WIN__) && !defined(__NETWARE__)
#include <sys/ioctl.h>
#ifdef HAVE_TERMIOS_H /* For tty-password */
#include <termios.h>
@@ -64,7 +64,7 @@
#define getpass(A) getpassphrase(A)
#endif
-#if defined( __WIN__) || defined(OS2) || defined(__NETWARE__)
+#if defined( __WIN__) || defined(__NETWARE__)
/* were just going to fake it here and get input from the keyboard */
#ifdef __NETWARE__
@@ -74,7 +74,7 @@
#define _cputs(A) putstring(A)
#endif
-char *get_tty_password(char *opt_message)
+char *get_tty_password(const char *opt_message)
{
char to[80];
char *pos=to,*end=to+sizeof(to)-1;
@@ -117,7 +117,7 @@ char *get_tty_password(char *opt_message)
to will not include the eol characters.
*/
-static void get_password(char *to,uint length,int fd,bool echo)
+static void get_password(char *to,uint length,int fd, my_bool echo)
{
char *pos=to,*end=to+length;
@@ -158,7 +158,7 @@ static void get_password(char *to,uint length,int fd,bool echo)
#endif /* ! HAVE_GETPASS */
-char *get_tty_password(char *opt_message)
+char *get_tty_password(const char *opt_message)
{
#ifdef HAVE_GETPASS
char *passbuff;
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index 7999041378a..91225128a1c 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -130,8 +130,8 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)),
mysql_port = MYSQL_PORT;
#ifndef MSDOS
{
- struct servent *serv_ptr;
- char *env;
+ char *env;
+ struct servent *serv_ptr __attribute__((unused));
/*
if builder specifically requested a default port, use that
@@ -206,11 +206,7 @@ void STDCALL mysql_server_end()
/* If library called my_init(), free memory allocated by it */
if (!org_my_init_done)
{
- my_end(MY_DONT_FREE_DBUG);
-#ifndef THREAD
- /* Remove TRACING, if enabled by mysql_debug() */
- DBUG_POP();
-#endif
+ my_end(0);
}
else
{
@@ -229,7 +225,7 @@ void STDCALL mysql_server_end()
}
static MYSQL_PARAMETERS mysql_internal_parameters=
-{&max_allowed_packet, &net_buffer_length};
+{&max_allowed_packet, &net_buffer_length, 0};
MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void)
{
@@ -331,7 +327,7 @@ sig_handler
my_pipe_sig_handler(int sig __attribute__((unused)))
{
DBUG_PRINT("info",("Hit by signal %d",sig));
-#ifdef DONT_REMEMBER_SIGNAL
+#ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY
(void) signal(SIGPIPE, my_pipe_sig_handler);
#endif
}
@@ -355,7 +351,7 @@ my_bool STDCALL mysql_master_send_query(MYSQL *mysql, const char *q,
DBUG_RETURN(1);
master->reconnect= 1;
mysql->last_used_con = master;
- DBUG_RETURN(simple_command(master, COM_QUERY, q, length, 1));
+ DBUG_RETURN(simple_command(master, COM_QUERY, (const uchar*) q, length, 1));
}
@@ -389,7 +385,8 @@ my_bool STDCALL mysql_slave_send_query(MYSQL *mysql, const char *q,
0,0,0,0))
DBUG_RETURN(1);
slave_to_use->reconnect= 1;
- DBUG_RETURN(simple_command(slave_to_use, COM_QUERY, q, length, 1));
+ DBUG_RETURN(simple_command(slave_to_use, COM_QUERY, (const uchar*) q,
+ length, 1));
}
@@ -652,7 +649,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((gptr) mysql,MYF(0));
+ my_free((uchar*) mysql,MYF(0));
}
mysql->reconnect= 1;
DBUG_RETURN(res);
@@ -683,11 +680,10 @@ int cli_read_change_user_result(MYSQL *mysql, char *buff, const char *passwd)
password in old format. The reply contains scramble_323.
*/
scramble_323(buff, mysql->scramble, passwd);
- if (my_net_write(net, buff, SCRAMBLE_LENGTH_323 + 1) || net_flush(net))
+ if (my_net_write(net, (uchar*) buff, SCRAMBLE_LENGTH_323 + 1) ||
+ net_flush(net))
{
- net->last_errno= CR_SERVER_LOST;
- strmov(net->sqlstate, unknown_sqlstate);
- strmov(net->last_error,ER(net->last_errno));
+ set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
return 1;
}
/* Read what server thinks about out new auth message report */
@@ -697,15 +693,26 @@ int cli_read_change_user_result(MYSQL *mysql, char *buff, const char *passwd)
return 0;
}
-
my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
const char *passwd, const char *db)
{
char buff[USERNAME_LENGTH+SCRAMBLED_PASSWORD_CHAR_LENGTH+NAME_LEN+2];
char *end= buff;
int rc;
+ CHARSET_INFO *saved_cs= mysql->charset;
+
DBUG_ENTER("mysql_change_user");
+ /* Get the connection-default character set. */
+
+ if (mysql_init_character_set(mysql))
+ {
+ mysql->charset= saved_cs;
+ DBUG_RETURN(TRUE);
+ }
+
+ /* Use an empty string instead of NULL. */
+
if (!user)
user="";
if (!passwd)
@@ -737,8 +744,16 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
/* Add database if needed */
end= strmake(end, db ? db : "", NAME_LEN) + 1;
+ /* Add character set number. */
+
+ if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION)
+ {
+ int2store(end, (ushort) mysql->charset->number);
+ end+= 2;
+ }
+
/* Write authentication package */
- simple_command(mysql,COM_CHANGE_USER, buff,(ulong) (end-buff),1);
+ simple_command(mysql,COM_CHANGE_USER, (uchar*) buff, (ulong) (end-buff), 1);
rc= (*mysql->methods->read_change_user_result)(mysql, buff, passwd);
@@ -746,7 +761,7 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
The server will close all statements no matter was the attempt
to change user successful or not.
*/
- mysql_detach_stmt_list(&mysql->stmts);
+ mysql_detach_stmt_list(&mysql->stmts, "mysql_change_user");
if (rc == 0)
{
/* Free old connect information */
@@ -759,6 +774,11 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
mysql->passwd=my_strdup(passwd,MYF(MY_WME));
mysql->db= db ? my_strdup(db,MYF(MY_WME)) : 0;
}
+ else
+ {
+ mysql->charset= saved_cs;
+ }
+
DBUG_RETURN(rc);
}
@@ -775,7 +795,7 @@ void read_user_name(char *name)
strmake(name, str ? str : "UNKNOWN_USER", USERNAME_LENGTH);
}
-#elif !defined(MSDOS) && ! defined(VMS) && !defined(__WIN__) && !defined(OS2)
+#elif !defined(MSDOS) && ! defined(VMS) && !defined(__WIN__)
void read_user_name(char *name)
{
@@ -839,8 +859,7 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename)
/* copy filename into local memory and allocate read buffer */
if (!(buf=my_malloc(packet_length, MYF(0))))
{
- strmov(net->sqlstate, unknown_sqlstate);
- strmov(net->last_error, ER(net->last_errno=CR_OUT_OF_MEMORY));
+ set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
DBUG_RETURN(1);
}
@@ -848,12 +867,13 @@ 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,"",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= (*options->local_infile_error)(li_ptr,
- net->last_error,
- sizeof(net->last_error)-1);
+ net->last_errno=
+ (*options->local_infile_error)(li_ptr,
+ net->last_error,
+ sizeof(net->last_error)-1);
goto err;
}
@@ -862,31 +882,28 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename)
(*options->local_infile_read)(li_ptr, buf,
packet_length)) > 0)
{
- if (my_net_write(net,buf,readcount))
+ if (my_net_write(net, (uchar*) buf, readcount))
{
DBUG_PRINT("error",
("Lost connection to MySQL server during LOAD DATA of local file"));
- strmov(net->sqlstate, unknown_sqlstate);
- net->last_errno=CR_SERVER_LOST;
- strmov(net->last_error,ER(net->last_errno));
+ set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
goto err;
}
}
/* Send empty packet to mark end of file */
- if (my_net_write(net,"",0) || net_flush(net))
+ if (my_net_write(net, (const uchar*) "", 0) || net_flush(net))
{
- strmov(net->sqlstate, unknown_sqlstate);
- net->last_errno=CR_SERVER_LOST;
- sprintf(net->last_error,ER(net->last_errno),errno);
+ set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
goto err;
}
if (readcount < 0)
{
- net->last_errno= (*options->local_infile_error)(li_ptr,
- net->last_error,
- sizeof(net->last_error)-1);
+ net->last_errno=
+ (*options->local_infile_error)(li_ptr,
+ net->last_error,
+ sizeof(net->last_error)-1);
goto err;
}
@@ -977,7 +994,7 @@ static int default_local_infile_read(void *ptr, char *buf, uint buf_len)
int count;
default_local_infile_data*data = (default_local_infile_data *) ptr;
- if ((count= (int) my_read(data->fd, (byte *) buf, buf_len, MYF(0))) < 0)
+ if ((count= (int) my_read(data->fd, (uchar *) buf, buf_len, MYF(0))) < 0)
{
data->error_num= EE_READ; /* the errmsg for not entire file read */
my_snprintf(data->error_msg, sizeof(data->error_msg)-1,
@@ -1260,7 +1277,8 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild)
end=strmake(strmake(buff, table,128)+1,wild ? wild : "",128);
free_old_query(mysql);
- if (simple_command(mysql,COM_FIELD_LIST,buff,(ulong) (end-buff),1) ||
+ if (simple_command(mysql, COM_FIELD_LIST, (uchar*) buff,
+ (ulong) (end-buff), 1) ||
!(fields= (*mysql->methods->list_fields)(mysql)))
DBUG_RETURN(NULL);
@@ -1331,7 +1349,7 @@ mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level)
uchar level[1];
DBUG_ENTER("mysql_shutdown");
level[0]= (uchar) shutdown_level;
- DBUG_RETURN(simple_command(mysql, COM_SHUTDOWN, (char *)level, 1, 0));
+ DBUG_RETURN(simple_command(mysql, COM_SHUTDOWN, level, 1, 0));
}
@@ -1341,14 +1359,14 @@ mysql_refresh(MYSQL *mysql,uint options)
uchar bits[1];
DBUG_ENTER("mysql_refresh");
bits[0]= (uchar) options;
- DBUG_RETURN(simple_command(mysql,COM_REFRESH,(char*) bits,1,0));
+ DBUG_RETURN(simple_command(mysql, COM_REFRESH, bits, 1, 0));
}
int STDCALL
mysql_kill(MYSQL *mysql,ulong pid)
{
- char buff[4];
+ uchar buff[4];
DBUG_ENTER("mysql_kill");
int4store(buff,pid);
DBUG_RETURN(simple_command(mysql,COM_PROCESS_KILL,buff,sizeof(buff),0));
@@ -1358,7 +1376,7 @@ mysql_kill(MYSQL *mysql,ulong pid)
int STDCALL
mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option)
{
- char buff[2];
+ uchar buff[2];
DBUG_ENTER("mysql_set_server_option");
int2store(buff, (uint) option);
DBUG_RETURN(simple_command(mysql, COM_SET_OPTION, buff, sizeof(buff), 0));
@@ -1378,9 +1396,7 @@ const char *cli_read_statistics(MYSQL *mysql)
mysql->net.read_pos[mysql->packet_length]=0; /* End of stat string */
if (!mysql->net.read_pos[0])
{
- strmov(mysql->net.sqlstate, unknown_sqlstate);
- mysql->net.last_errno=CR_WRONG_HOST_INFO;
- strmov(mysql->net.last_error, ER(mysql->net.last_errno));
+ set_mysql_error(mysql, CR_WRONG_HOST_INFO, unknown_sqlstate);
return mysql->net.last_error;
}
return (char*) mysql->net.read_pos;
@@ -1603,7 +1619,7 @@ mysql_hex_string(char *to, const char *from, ulong length)
ulong STDCALL
mysql_escape_string(char *to,const char *from,ulong length)
{
- return escape_string_for_mysql(default_charset_info, to, 0, from, length);
+ return (uint) escape_string_for_mysql(default_charset_info, to, 0, from, length);
}
ulong STDCALL
@@ -1611,22 +1627,8 @@ mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
-}
-
-
-char * STDCALL
-mysql_odbc_escape_string(MYSQL *mysql __attribute__((unused)),
- char *to __attribute__((unused)),
- ulong to_length __attribute__((unused)),
- const char *from __attribute__((unused)),
- ulong from_length __attribute__((unused)),
- void *param __attribute__((unused)),
- char * (*extend_buffer)(void *, char *, ulong *)
- __attribute__((unused)))
-{
- return NULL;
+ return (uint) escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
+ return (uint) escape_string_for_mysql(mysql->charset, to, 0, from, length);
}
void STDCALL
@@ -1703,6 +1705,7 @@ static my_bool setup_one_fetch_function(MYSQL_BIND *, MYSQL_FIELD *field);
#define RESET_SERVER_SIDE 1
#define RESET_LONG_DATA 2
#define RESET_STORE_RESULT 4
+#define RESET_CLEAR_ERROR 8
static my_bool reset_stmt_handle(MYSQL_STMT *stmt, uint flags);
@@ -1767,24 +1770,17 @@ static my_bool my_realloc_str(NET *net, ulong length)
if (buf_length + length > net->max_packet)
{
res= net_realloc(net, buf_length + length);
+ if (res)
+ {
+ strmov(net->sqlstate, unknown_sqlstate);
+ strmov(net->last_error, ER(net->last_errno));
+ }
net->write_pos= net->buff+ buf_length;
}
DBUG_RETURN(res);
}
-/* Clear possible error statee of struct NET */
-
-static void net_clear_error(NET *net)
-{
- if (net->last_errno)
- {
- net->last_errno= 0;
- net->last_error[0]= '\0';
- strmov(net->sqlstate, not_error_sqlstate);
- }
-}
-
static void stmt_clear_error(MYSQL_STMT *stmt)
{
if (stmt->last_errno)
@@ -1795,18 +1791,21 @@ static void stmt_clear_error(MYSQL_STMT *stmt)
}
}
-/*
+/**
Set statement error code, sqlstate, and error message
from given errcode and sqlstate.
*/
-static void set_stmt_error(MYSQL_STMT * stmt, int errcode,
- const char *sqlstate)
+void set_stmt_error(MYSQL_STMT * stmt, int errcode,
+ const char *sqlstate, const char *err)
{
DBUG_ENTER("set_stmt_error");
DBUG_PRINT("enter", ("error: %d '%s'", errcode, ER(errcode)));
DBUG_ASSERT(stmt != 0);
+ if (err == 0)
+ err= ER(errcode);
+
stmt->last_errno= errcode;
strmov(stmt->last_error, ER(errcode));
strmov(stmt->sqlstate, sqlstate);
@@ -1815,21 +1814,26 @@ static void set_stmt_error(MYSQL_STMT * stmt, int errcode,
}
-/*
- Set statement error code, sqlstate, and error message.
+/**
+ Set statement error code, sqlstate, and error message from NET.
+
+ @param stmt a statement handle. Copy the error here.
+ @param net mysql->net. Source of the error.
*/
-void set_stmt_errmsg(MYSQL_STMT * stmt, const char *err, int errcode,
- const char *sqlstate)
+void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net)
{
DBUG_ENTER("set_stmt_errmsg");
- DBUG_PRINT("enter", ("error: %d/%s '%s'", errcode, sqlstate, err));
+ DBUG_PRINT("enter", ("error: %d/%s '%s'",
+ net->last_errno,
+ net->sqlstate,
+ net->last_error));
DBUG_ASSERT(stmt != 0);
- stmt->last_errno= errcode;
- if (err && err[0])
- strmov(stmt->last_error, err);
- strmov(stmt->sqlstate, sqlstate);
+ stmt->last_errno= net->last_errno;
+ if (net->last_error && net->last_error[0])
+ strmov(stmt->last_error, net->last_error);
+ strmov(stmt->sqlstate, net->sqlstate);
DBUG_VOID_RETURN;
}
@@ -2004,7 +2008,7 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length)
if (!mysql)
{
/* mysql can be reset in mysql_close called from mysql_reconnect */
- set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate);
+ set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate, NULL);
DBUG_RETURN(1);
}
@@ -2018,7 +2022,7 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length)
if ((int) stmt->state > (int) MYSQL_STMT_INIT_DONE)
{
/* This is second prepare with another statement */
- char buff[MYSQL_STMT_HEADER]; /* 4 bytes - stmt id */
+ uchar buff[MYSQL_STMT_HEADER]; /* 4 bytes - stmt id */
if (reset_stmt_handle(stmt, RESET_LONG_DATA | RESET_STORE_RESULT))
DBUG_RETURN(1);
@@ -2042,23 +2046,20 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length)
stmt->state= MYSQL_STMT_INIT_DONE;
if (stmt_command(mysql, COM_STMT_CLOSE, buff, 4, stmt))
{
- set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
- mysql->net.sqlstate);
+ set_stmt_errmsg(stmt, &mysql->net);
DBUG_RETURN(1);
}
}
- if (stmt_command(mysql, COM_STMT_PREPARE, query, length, stmt))
+ if (stmt_command(mysql, COM_STMT_PREPARE, (const uchar*) query, length, stmt))
{
- set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
- mysql->net.sqlstate);
+ set_stmt_errmsg(stmt, &mysql->net);
DBUG_RETURN(1);
}
if ((*mysql->methods->read_prepare_result)(mysql, stmt))
{
- set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
- mysql->net.sqlstate);
+ set_stmt_errmsg(stmt, &mysql->net);
DBUG_RETURN(1);
}
@@ -2073,7 +2074,7 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length)
(stmt->param_count +
stmt->field_count))))
{
- set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate);
+ set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate, NULL);
DBUG_RETURN(1);
}
stmt->bind= stmt->params + stmt->param_count;
@@ -2089,7 +2090,7 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length)
To be removed when all commands will fully support prepared mode.
*/
-static unsigned int alloc_stmt_fields(MYSQL_STMT *stmt)
+static void alloc_stmt_fields(MYSQL_STMT *stmt)
{
MYSQL_FIELD *fields, *field, *end;
MEM_ROOT *alloc= &stmt->mem_root;
@@ -2107,7 +2108,10 @@ static unsigned int alloc_stmt_fields(MYSQL_STMT *stmt)
!(stmt->bind= (MYSQL_BIND *) alloc_root(alloc,
sizeof(MYSQL_BIND) *
stmt->field_count)))
- return 0;
+ {
+ set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate, NULL);
+ return;
+ }
for (fields= mysql->fields, end= fields+stmt->field_count,
field= stmt->fields;
@@ -2126,13 +2130,15 @@ static unsigned int alloc_stmt_fields(MYSQL_STMT *stmt)
field->def = fields->def ? strdup_root(alloc,fields->def): 0;
field->max_length= 0;
}
- return stmt->field_count;
}
-/*
+/**
Update result set columns metadata if it was sent again in
reply to COM_STMT_EXECUTE.
+
+ @note If the new field count is different from the original one,
+ an error is set and no update is performed.
*/
static void update_stmt_fields(MYSQL_STMT *stmt)
@@ -2142,7 +2148,22 @@ static void update_stmt_fields(MYSQL_STMT *stmt)
MYSQL_FIELD *stmt_field= stmt->fields;
MYSQL_BIND *my_bind= stmt->bind_result_done ? stmt->bind : 0;
- DBUG_ASSERT(stmt->field_count == stmt->mysql->field_count);
+ if (stmt->field_count != stmt->mysql->field_count)
+ {
+ /*
+ The tables used in the statement were altered,
+ and the query now returns a different number of columns.
+ There is no way to continue without reallocating the bind
+ array:
+ - if the number of columns increased, mysql_stmt_fetch()
+ will write beyond allocated memory
+ - if the number of columns decreased, some user-bound
+ buffers will be left unassigned without user knowing
+ that.
+ */
+ set_stmt_error(stmt, CR_NEW_STMT_METADATA, unknown_sqlstate, NULL);
+ return;
+ }
for (; field < field_end; ++field, ++stmt_field)
{
@@ -2203,7 +2224,7 @@ mysql_stmt_result_metadata(MYSQL_STMT *stmt)
if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result),
MYF(MY_WME | MY_ZEROFILL))))
{
- set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate);
+ set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate, NULL);
DBUG_RETURN(0);
}
@@ -2252,7 +2273,7 @@ mysql_stmt_param_metadata(MYSQL_STMT *stmt)
/* Store type of parameter in network buffer. */
-static void store_param_type(char **pos, MYSQL_BIND *param)
+static void store_param_type(unsigned char **pos, MYSQL_BIND *param)
{
uint typecode= param->buffer_type | (param->is_unsigned ? 32768 : 0);
int2store(*pos, typecode);
@@ -2384,9 +2405,9 @@ static void store_param_str(NET *net, MYSQL_BIND *param)
{
/* param->length is always set in mysql_stmt_bind_param */
ulong length= *param->length;
- char *to= (char *) net_store_length((char *) net->write_pos, length);
+ uchar *to= net_store_length(net->write_pos, length);
memcpy(to, param->buffer, length);
- net->write_pos= (uchar*) to+length;
+ net->write_pos= to+length;
}
@@ -2436,7 +2457,7 @@ static my_bool store_param(MYSQL_STMT *stmt, MYSQL_BIND *param)
*/
if ((my_realloc_str(net, *param->length)))
{
- set_stmt_error(stmt, net->last_errno, unknown_sqlstate);
+ set_stmt_errmsg(stmt, net);
DBUG_RETURN(1);
}
(*param->store_param_func)(net, param);
@@ -2454,12 +2475,11 @@ static my_bool execute(MYSQL_STMT *stmt, char *packet, ulong length)
{
MYSQL *mysql= stmt->mysql;
NET *net= &mysql->net;
- char buff[4 /* size of stmt id */ +
- 5 /* execution flags */];
+ uchar buff[4 /* size of stmt id */ +
+ 5 /* execution flags */];
my_bool res;
-
DBUG_ENTER("execute");
- DBUG_DUMP("packet", (uchar*)packet, length);
+ DBUG_DUMP("packet", (uchar *) packet, length);
mysql->last_used_con= mysql;
int4store(buff, stmt->stmt_id); /* Send stmt id to server */
@@ -2467,16 +2487,23 @@ static my_bool execute(MYSQL_STMT *stmt, char *packet, ulong length)
int4store(buff+5, 1); /* iteration count */
res= test(cli_advanced_command(mysql, COM_STMT_EXECUTE, buff, sizeof(buff),
- packet, length, 1, stmt) ||
+ (uchar*) packet, length, 1, stmt) ||
(*mysql->methods->read_query_result)(mysql));
stmt->affected_rows= mysql->affected_rows;
stmt->server_status= mysql->server_status;
stmt->insert_id= mysql->insert_id;
if (res)
{
- set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
+ /*
+ Don't set stmt error if stmt->mysql is NULL, as the error in this case
+ has already been set by mysql_prune_stmt_list().
+ */
+ if (stmt->mysql)
+ set_stmt_errmsg(stmt, net);
DBUG_RETURN(1);
}
+ else if (mysql->status == MYSQL_STATUS_GET_RESULT)
+ stmt->mysql->status= MYSQL_STATUS_STATEMENT_GET_RESULT;
DBUG_RETURN(0);
}
@@ -2497,22 +2524,22 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
if (!stmt->bind_param_done)
{
- set_stmt_error(stmt, CR_PARAMS_NOT_BOUND, unknown_sqlstate);
+ set_stmt_error(stmt, CR_PARAMS_NOT_BOUND, unknown_sqlstate, NULL);
DBUG_RETURN(1);
}
if (mysql->status != MYSQL_STATUS_READY ||
mysql->server_status & SERVER_MORE_RESULTS_EXISTS)
{
- set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
+ set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate, NULL);
DBUG_RETURN(1);
}
- net_clear(net); /* Sets net->write_pos */
+ net_clear(net, 1); /* Sets net->write_pos */
/* Reserve place for null-marker bytes */
null_count= (stmt->param_count+7) /8;
if (my_realloc_str(net, null_count + 1))
{
- set_stmt_error(stmt, net->last_errno, unknown_sqlstate);
+ set_stmt_errmsg(stmt, net);
DBUG_RETURN(1);
}
bzero((char*) net->write_pos, null_count);
@@ -2525,7 +2552,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
{
if (my_realloc_str(net, 2 * stmt->param_count))
{
- set_stmt_error(stmt, net->last_errno, unknown_sqlstate);
+ set_stmt_errmsg(stmt, net);
DBUG_RETURN(1);
}
/*
@@ -2533,7 +2560,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
that is sent to the server.
*/
for (param= stmt->params; param < param_end ; param++)
- store_param_type((char**) &net->write_pos, param);
+ store_param_type(&net->write_pos, param);
}
for (param= stmt->params; param < param_end; param++)
@@ -2546,9 +2573,9 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
}
length= (ulong) (net->write_pos - net->buff);
/* TODO: Look into avoding the following memdup */
- if (!(param_data= my_memdup((const char*) net->buff, length, MYF(0))))
+ if (!(param_data= my_memdup(net->buff, length, MYF(0))))
{
- set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate);
+ set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate, NULL);
DBUG_RETURN(1);
}
result= execute(stmt, param_data, length);
@@ -2612,20 +2639,19 @@ static int stmt_read_row_unbuffered(MYSQL_STMT *stmt, unsigned char **row)
*/
if (!mysql)
{
- set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate);
+ set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate, NULL);
return 1;
}
- if (mysql->status != MYSQL_STATUS_GET_RESULT)
+ if (mysql->status != MYSQL_STATUS_STATEMENT_GET_RESULT)
{
set_stmt_error(stmt, stmt->unbuffered_fetch_cancelled ?
CR_FETCH_CANCELED : CR_COMMANDS_OUT_OF_SYNC,
- unknown_sqlstate);
+ unknown_sqlstate, NULL);
goto error;
}
if ((*mysql->methods->unbuffered_fetch)(mysql, (char**) row))
{
- set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
- mysql->net.sqlstate);
+ set_stmt_errmsg(stmt, &mysql->net);
/*
If there was an error, there are no more pending rows:
reset statement status to not hang up in following
@@ -2673,8 +2699,8 @@ stmt_read_row_from_cursor(MYSQL_STMT *stmt, unsigned char **row)
MYSQL *mysql= stmt->mysql;
NET *net= &mysql->net;
MYSQL_DATA *result= &stmt->result;
- char buff[4 /* statement id */ +
- 4 /* number of rows to fetch */];
+ uchar buff[4 /* statement id */ +
+ 4 /* number of rows to fetch */];
free_root(&result->alloc, MYF(MY_KEEP_PREALLOC));
result->data= NULL;
@@ -2683,10 +2709,15 @@ stmt_read_row_from_cursor(MYSQL_STMT *stmt, unsigned char **row)
int4store(buff, stmt->stmt_id);
int4store(buff + 4, stmt->prefetch_rows); /* number of rows to fetch */
if ((*mysql->methods->advanced_command)(mysql, COM_STMT_FETCH,
- buff, sizeof(buff), NullS, 0,
+ buff, sizeof(buff), (uchar*) 0, 0,
1, stmt))
{
- set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
+ /*
+ Don't set stmt error if stmt->mysql is NULL, as the error in this case
+ has already been set by mysql_prune_stmt_list().
+ */
+ if (stmt->mysql)
+ set_stmt_errmsg(stmt, net);
return 1;
}
if ((*mysql->methods->read_rows_from_cursor)(stmt))
@@ -2717,7 +2748,7 @@ static int
stmt_read_row_no_result_set(MYSQL_STMT *stmt __attribute__((unused)),
unsigned char **row __attribute__((unused)))
{
- set_stmt_error(stmt, CR_NO_RESULT_SET, unknown_sqlstate);
+ set_stmt_error(stmt, CR_NO_RESULT_SET, unknown_sqlstate, NULL);
return 1;
}
@@ -2767,7 +2798,7 @@ my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt,
}
return FALSE;
err_not_implemented:
- set_stmt_error(stmt, CR_NOT_IMPLEMENTED, unknown_sqlstate);
+ set_stmt_error(stmt, CR_NOT_IMPLEMENTED, unknown_sqlstate, NULL);
return TRUE;
}
@@ -2778,11 +2809,11 @@ my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt,
{
switch (attr_type) {
case STMT_ATTR_UPDATE_MAX_LENGTH:
- *(unsigned long *) value= stmt->update_max_length;
+ *(my_bool*) value= stmt->update_max_length;
break;
case STMT_ATTR_CURSOR_TYPE:
*(ulong*) value= stmt->flags;
- break;
+ break;
case STMT_ATTR_PREFETCH_ROWS:
*(ulong*) value= stmt->prefetch_rows;
break;
@@ -2793,6 +2824,50 @@ my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt,
}
+/**
+ Update statement result set metadata from with the new field
+ information sent during statement execute.
+
+ @pre mysql->field_count is not zero
+
+ @retval TRUE if error: out of memory or the new
+ result set has a different number of columns
+ @retval FALSE success
+*/
+
+static void reinit_result_set_metadata(MYSQL_STMT *stmt)
+{
+ /* Server has sent result set metadata */
+ if (stmt->field_count == 0)
+ {
+ /*
+ This is 'SHOW'/'EXPLAIN'-like query. Current implementation of
+ prepared statements can't send result set metadata for these queries
+ on prepare stage. Read it now.
+ */
+ alloc_stmt_fields(stmt);
+ }
+ else
+ {
+ /*
+ Update result set metadata if it for some reason changed between
+ prepare and execute, i.e.:
+ - in case of 'SELECT ?' we don't know column type unless data was
+ supplied to mysql_stmt_execute, so updated column type is sent
+ now.
+ - if data dictionary changed between prepare and execute, for
+ example a table used in the query was altered.
+ Note, that now (4.1.3) we always send metadata in reply to
+ COM_STMT_EXECUTE (even if it is not necessary), so either this or
+ previous branch always works.
+ TODO: send metadata only when it's really necessary and add a warning
+ 'Metadata changed' when it's sent twice.
+ */
+ update_stmt_fields(stmt);
+ }
+}
+
+
/*
Send placeholders data to server (if there are placeholders)
and execute prepared statement.
@@ -2844,11 +2919,11 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt)
if (!mysql)
{
- set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate);
+ /* Error is already set in mysql_detatch_stmt_list */
DBUG_RETURN(1);
}
- if (reset_stmt_handle(stmt, RESET_STORE_RESULT))
+ if (reset_stmt_handle(stmt, RESET_STORE_RESULT | RESET_CLEAR_ERROR))
DBUG_RETURN(1);
/*
No need to check for stmt->state: if the statement wasn't
@@ -2856,40 +2931,10 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt)
*/
if (mysql->methods->stmt_execute(stmt))
DBUG_RETURN(1);
- if (mysql->field_count)
- {
- /* Server has sent result set metadata */
- if (stmt->field_count == 0)
- {
- /*
- This is 'SHOW'/'EXPLAIN'-like query. Current implementation of
- prepared statements can't send result set metadata for these queries
- on prepare stage. Read it now.
- */
- alloc_stmt_fields(stmt);
- }
- else
- {
- /*
- Update result set metadata if it for some reason changed between
- prepare and execute, i.e.:
- - in case of 'SELECT ?' we don't know column type unless data was
- supplied to mysql_stmt_execute, so updated column type is sent
- now.
- - if data dictionary changed between prepare and execute, for
- example a table used in the query was altered.
- Note, that now (4.1.3) we always send metadata in reply to
- COM_STMT_EXECUTE (even if it is not necessary), so either this or
- previous branch always works.
- TODO: send metadata only when it's really necessary and add a warning
- 'Metadata changed' when it's sent twice.
- */
- update_stmt_fields(stmt);
- }
- }
stmt->state= MYSQL_STMT_EXECUTE_DONE;
- if (stmt->field_count)
+ if (mysql->field_count)
{
+ reinit_result_set_metadata(stmt);
if (stmt->server_status & SERVER_STATUS_CURSOR_EXISTS)
{
mysql->status= MYSQL_STATUS_READY;
@@ -2904,7 +2949,7 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt)
network or b) is more efficient if all (few) result set rows are
precached on client and server's resources are freed.
*/
- DBUG_RETURN(mysql_stmt_store_result(stmt));
+ mysql_stmt_store_result(stmt);
}
else
{
@@ -2913,7 +2958,7 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt)
stmt->read_row_func= stmt_read_row_unbuffered;
}
}
- DBUG_RETURN(0);
+ DBUG_RETURN(test(stmt->last_errno));
}
@@ -3152,7 +3197,7 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *my_bind)
{
if ((int) stmt->state < (int) MYSQL_STMT_PREPARE_DONE)
{
- set_stmt_error(stmt, CR_NO_PREPARE_STMT, unknown_sqlstate);
+ set_stmt_error(stmt, CR_NO_PREPARE_STMT, unknown_sqlstate, NULL);
DBUG_RETURN(1);
}
DBUG_RETURN(0);
@@ -3317,7 +3362,7 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number,
*/
if (param_number >= stmt->param_count)
{
- set_stmt_error(stmt, CR_INVALID_PARAMETER_NO, unknown_sqlstate);
+ set_stmt_error(stmt, CR_INVALID_PARAMETER_NO, unknown_sqlstate, NULL);
DBUG_RETURN(1);
}
@@ -3339,7 +3384,7 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number,
{
MYSQL *mysql= stmt->mysql;
/* Packet header: stmt id (4 bytes), param no (2 bytes) */
- char buff[MYSQL_LONG_DATA_HEADER];
+ uchar buff[MYSQL_LONG_DATA_HEADER];
int4store(buff, stmt->stmt_id);
int2store(buff + 4, param_number);
@@ -3350,11 +3395,15 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number,
This is intentional to save bandwidth.
*/
if ((*mysql->methods->advanced_command)(mysql, COM_STMT_SEND_LONG_DATA,
- buff, sizeof(buff), data,
+ buff, sizeof(buff), (uchar*) data,
length, 1, stmt))
{
- set_stmt_errmsg(stmt, mysql->net.last_error,
- mysql->net.last_errno, mysql->net.sqlstate);
+ /*
+ Don't set stmt error if stmt->mysql is NULL, as the error in this case
+ has already been set by mysql_prune_stmt_list().
+ */
+ if (stmt->mysql)
+ set_stmt_errmsg(stmt, &mysql->net);
DBUG_RETURN(1);
}
}
@@ -3390,7 +3439,7 @@ static void read_binary_time(MYSQL_TIME *tm, uchar **pos)
if (length)
{
uchar *to= *pos;
- tm->neg= (bool) to[0];
+ tm->neg= to[0];
tm->day= (ulong) sint4korr(to+1);
tm->hour= (uint) to[5];
@@ -3567,7 +3616,7 @@ static void fetch_string_with_conversion(MYSQL_BIND *param, char *value,
*/
char *start= value + param->offset;
char *end= value + length;
- size_t copy_length;
+ ulong copy_length;
if (start < end)
{
copy_length= end - start;
@@ -3678,19 +3727,20 @@ static void fetch_long_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field,
}
default:
{
- char buff[22]; /* Enough for longlong */
- char *end= longlong10_to_str(value, buff, is_unsigned ? 10: -10);
+ uchar buff[22]; /* Enough for longlong */
+ uchar *end= (uchar*) longlong10_to_str(value, (char*) buff,
+ is_unsigned ? 10: -10);
/* Resort to string conversion which supports all typecodes */
uint length= (uint) (end-buff);
if (field->flags & ZEROFILL_FLAG && length < field->length &&
field->length < 21)
{
- bmove_upp((char*) buff+field->length,buff+length, length);
- bfill((char*) buff, field->length - length,'0');
+ bmove_upp(buff+field->length,buff+length, length);
+ bfill(buff, field->length - length,'0');
length= field->length;
}
- fetch_string_with_conversion(param, buff, length);
+ fetch_string_with_conversion(param, (char*) buff, length);
break;
}
}
@@ -3822,11 +3872,12 @@ static void fetch_float_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field,
if (field->flags & ZEROFILL_FLAG && length < field->length &&
field->length < MAX_DOUBLE_STRING_REP_LENGTH - 1)
{
- bmove_upp((char*) buff + field->length, buff + length, (uint) length);
+ 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, (uint) length);
+ fetch_string_with_conversion(param, buff, length);
}
break;
@@ -4218,7 +4269,7 @@ static my_bool is_binary_compatible(enum enum_field_types type1,
for (range= range_list; range != range_list_end; ++range)
{
/* check that both type1 and type2 are in the same range */
- bool type1_found= FALSE, type2_found= FALSE;
+ my_bool type1_found= FALSE, type2_found= FALSE;
for (type= *range; *type != MYSQL_TYPE_NULL; type++)
{
type1_found|= type1 == *type;
@@ -4371,11 +4422,11 @@ static my_bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field)
case MYSQL_TYPE_TIME:
field->max_length= 15; /* 19:23:48.123456 */
param->skip_result= skip_result_with_length;
+ break;
case MYSQL_TYPE_DATE:
field->max_length= 10; /* 2003-11-11 */
param->skip_result= skip_result_with_length;
break;
- break;
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIMESTAMP:
param->skip_result= skip_result_with_length;
@@ -4421,7 +4472,7 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *my_bind)
{
int errorcode= (int) stmt->state < (int) MYSQL_STMT_PREPARE_DONE ?
CR_NO_PREPARE_STMT : CR_NO_STMT_METADATA;
- set_stmt_error(stmt, errorcode, unknown_sqlstate);
+ set_stmt_error(stmt, errorcode, unknown_sqlstate, NULL);
DBUG_RETURN(1);
}
@@ -4530,7 +4581,7 @@ static int stmt_fetch_row(MYSQL_STMT *stmt, uchar *row)
}
if (!((bit<<=1) & 255))
{
- bit= 1; /* To next byte */
+ bit= 1; /* To next uchar */
null_ptr++;
}
}
@@ -4601,12 +4652,12 @@ int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *my_bind,
if ((int) stmt->state < (int) MYSQL_STMT_FETCH_DONE)
{
- set_stmt_error(stmt, CR_NO_DATA, unknown_sqlstate);
+ set_stmt_error(stmt, CR_NO_DATA, unknown_sqlstate, NULL);
return 1;
}
if (column >= stmt->field_count)
{
- set_stmt_error(stmt, CR_INVALID_PARAMETER_NO, unknown_sqlstate);
+ set_stmt_error(stmt, CR_INVALID_PARAMETER_NO, unknown_sqlstate, NULL);
DBUG_RETURN(1);
}
@@ -4652,7 +4703,7 @@ int cli_read_binary_rows(MYSQL_STMT *stmt)
if (!mysql)
{
- set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate);
+ set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate, NULL);
DBUG_RETURN(1);
}
@@ -4667,7 +4718,7 @@ int cli_read_binary_rows(MYSQL_STMT *stmt)
if (!(cur= (MYSQL_ROWS*) alloc_root(&result->alloc,
sizeof(MYSQL_ROWS) + pkt_len - 1)))
{
- set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate);
+ set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate, NULL);
goto err;
}
cur->data= (MYSQL_ROW) (cur+1);
@@ -4688,7 +4739,7 @@ int cli_read_binary_rows(MYSQL_STMT *stmt)
DBUG_RETURN(0);
}
}
- set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
+ set_stmt_errmsg(stmt, net);
err:
DBUG_RETURN(1);
@@ -4731,7 +4782,7 @@ static void stmt_update_metadata(MYSQL_STMT *stmt, MYSQL_ROWS *data)
DBUG_ASSERT(row <= row_end);
if (!((bit<<=1) & 255))
{
- bit= 1; /* To next byte */
+ bit= 1; /* To next uchar */
null_ptr++;
}
}
@@ -4751,7 +4802,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
if (!mysql)
{
/* mysql can be reset in mysql_close called from mysql_reconnect */
- set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate);
+ set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate, NULL);
DBUG_RETURN(1);
}
@@ -4762,7 +4813,13 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
if ((int) stmt->state < (int) MYSQL_STMT_EXECUTE_DONE)
{
- set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
+ set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate, NULL);
+ DBUG_RETURN(1);
+ }
+
+ if (stmt->last_errno)
+ {
+ /* An attempt to use an invalid statement handle. */
DBUG_RETURN(1);
}
@@ -4773,22 +4830,27 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
Server side cursor exist, tell server to start sending the rows
*/
NET *net= &mysql->net;
- char buff[4 /* statement id */ +
- 4 /* number of rows to fetch */];
+ uchar buff[4 /* statement id */ +
+ 4 /* number of rows to fetch */];
/* Send row request to the server */
int4store(buff, stmt->stmt_id);
int4store(buff + 4, (int)~0); /* number of rows to fetch */
if (cli_advanced_command(mysql, COM_STMT_FETCH, buff, sizeof(buff),
- NullS, 0, 1, stmt))
+ (uchar*) 0, 0, 1, stmt))
{
- set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
+ /*
+ Don't set stmt error if stmt->mysql is NULL, as the error in this case
+ has already been set by mysql_prune_stmt_list().
+ */
+ if (stmt->mysql)
+ set_stmt_errmsg(stmt, net);
DBUG_RETURN(1);
}
}
- else if (mysql->status != MYSQL_STATUS_GET_RESULT)
+ else if (mysql->status != MYSQL_STATUS_STATEMENT_GET_RESULT)
{
- set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
+ set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate, NULL);
DBUG_RETURN(1);
}
@@ -4964,19 +5026,19 @@ static my_bool reset_stmt_handle(MYSQL_STMT *stmt, uint flags)
Reset the server side statement and close the server side
cursor if it exists.
*/
- char buff[MYSQL_STMT_HEADER]; /* packet header: 4 bytes for stmt id */
+ uchar buff[MYSQL_STMT_HEADER]; /* packet header: 4 bytes for stmt id */
int4store(buff, stmt->stmt_id);
if ((*mysql->methods->advanced_command)(mysql, COM_STMT_RESET, buff,
sizeof(buff), 0, 0, 0, stmt))
{
- set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
- mysql->net.sqlstate);
+ set_stmt_errmsg(stmt, &mysql->net);
stmt->state= MYSQL_STMT_INIT_DONE;
return 1;
}
- stmt_clear_error(stmt);
}
}
+ if (flags & RESET_CLEAR_ERROR)
+ stmt_clear_error(stmt);
stmt->state= MYSQL_STMT_PREPARE_DONE;
}
return 0;
@@ -4987,7 +5049,8 @@ my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt)
DBUG_ENTER("mysql_stmt_free_result");
/* Free the client side and close the server side cursor if there is one */
- DBUG_RETURN(reset_stmt_handle(stmt, RESET_LONG_DATA | RESET_STORE_RESULT));
+ DBUG_RETURN(reset_stmt_handle(stmt, RESET_LONG_DATA | RESET_STORE_RESULT |
+ RESET_CLEAR_ERROR));
}
/********************************************************************
@@ -5025,7 +5088,7 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt)
net_clear_error(&mysql->net);
if ((int) stmt->state > (int) MYSQL_STMT_INIT_DONE)
{
- char buff[MYSQL_STMT_HEADER]; /* 4 bytes - stmt id */
+ uchar buff[MYSQL_STMT_HEADER]; /* 4 bytes - stmt id */
if (mysql->unbuffered_fetch_owner == &stmt->unbuffered_fetch_cancelled)
mysql->unbuffered_fetch_owner= 0;
@@ -5043,13 +5106,12 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt)
int4store(buff, stmt->stmt_id);
if ((rc= stmt_command(mysql, COM_STMT_CLOSE, buff, 4, stmt)))
{
- set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
- mysql->net.sqlstate);
+ set_stmt_errmsg(stmt, &mysql->net);
}
}
}
- my_free((gptr) stmt, MYF(MY_WME));
+ my_free((uchar*) stmt, MYF(MY_WME));
DBUG_RETURN(test(rc));
}
@@ -5065,11 +5127,13 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt)
if (!stmt->mysql)
{
/* mysql can be reset in mysql_close called from mysql_reconnect */
- set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate);
+ set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate, NULL);
DBUG_RETURN(1);
}
/* Reset the client and server sides of the prepared statement */
- DBUG_RETURN(reset_stmt_handle(stmt, RESET_SERVER_SIDE | RESET_LONG_DATA));
+ DBUG_RETURN(reset_stmt_handle(stmt,
+ RESET_SERVER_SIDE | RESET_LONG_DATA |
+ RESET_CLEAR_ERROR));
}
/*
@@ -5169,15 +5233,11 @@ int STDCALL mysql_next_result(MYSQL *mysql)
if (mysql->status != MYSQL_STATUS_READY)
{
- strmov(mysql->net.sqlstate, unknown_sqlstate);
- strmov(mysql->net.last_error,
- ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
+ set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
DBUG_RETURN(1);
}
- mysql->net.last_error[0]= 0;
- mysql->net.last_errno= 0;
- strmov(mysql->net.sqlstate, not_error_sqlstate);
+ net_clear_error(&mysql->net);
mysql->affected_rows= ~(my_ulonglong) 0;
if (mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS)
diff --git a/libmysql/libmysql.def b/libmysql/libmysql.def
index 8c6b71d9553..81f86dc8726 100644
--- a/libmysql/libmysql.def
+++ b/libmysql/libmysql.def
@@ -78,7 +78,6 @@ EXPORTS
mysql_next_result
mysql_num_fields
mysql_num_rows
- mysql_odbc_escape_string
mysql_options
mysql_stmt_param_count
mysql_stmt_param_metadata
diff --git a/libmysql/manager.c b/libmysql/manager.c
index f7ea7bb275b..ef28f1bd323 100644
--- a/libmysql/manager.c
+++ b/libmysql/manager.c
@@ -34,9 +34,7 @@
#include <signal.h>
#include <errno.h>
-#if defined(OS2)
-# include <sys/un.h>
-#elif defined(__NETWARE__)
+#if defined(__NETWARE__)
#include <netdb.h>
#include <sys/select.h>
#include <sys/utsname.h>
@@ -158,8 +156,8 @@ MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con,
goto err;
}
sprintf(msg_buf,"%-.16s %-.16s\n",user,passwd);
- msg_len= (uint) strlen(msg_buf);
- if (my_net_write(&con->net,msg_buf,msg_len) || net_flush(&con->net))
+ 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");
@@ -207,10 +205,10 @@ void STDCALL mysql_manager_close(MYSQL_MANAGER* con)
allocated in my_multimalloc() along with con->host, freeing
con->hosts frees the whole block
*/
- my_free((gptr)con->host,MYF(MY_ALLOW_ZERO_PTR));
+ my_free((uchar*)con->host,MYF(MY_ALLOW_ZERO_PTR));
net_end(&con->net);
if (con->free_me)
- my_free((gptr)con,MYF(0));
+ my_free((uchar*)con,MYF(0));
}
@@ -218,8 +216,8 @@ int STDCALL mysql_manager_command(MYSQL_MANAGER* con,const char* cmd,
int cmd_len)
{
if (!cmd_len)
- cmd_len= (uint) strlen(cmd);
- if (my_net_write(&con->net,(char*)cmd,cmd_len) || net_flush(&con->net))
+ 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");