diff options
Diffstat (limited to 'libmysqld')
-rw-r--r-- | libmysqld/CMakeLists.txt | 4 | ||||
-rw-r--r-- | libmysqld/embedded_priv.h | 2 | ||||
-rw-r--r-- | libmysqld/lib_sql.cc | 26 | ||||
-rw-r--r-- | libmysqld/libmysqld.c | 4 |
4 files changed, 30 insertions, 6 deletions
diff --git a/libmysqld/CMakeLists.txt b/libmysqld/CMakeLists.txt index 63cdd03e..345c212d 100644 --- a/libmysqld/CMakeLists.txt +++ b/libmysqld/CMakeLists.txt @@ -25,7 +25,7 @@ ${CMAKE_SOURCE_DIR}/tpool ${CMAKE_BINARY_DIR}/sql ${PCRE_INCLUDE_DIRS} ${LIBFMT_INCLUDE_DIR} -${ZLIB_INCLUDE_DIR} +${ZLIB_INCLUDE_DIRS} ${SSL_INCLUDE_DIRS} ${SSL_INTERNAL_INCLUDE_DIRS} ) @@ -180,7 +180,7 @@ ENDIF() SET(LIBS dbug strings mysys mysys_ssl pcre2-8 vio - ${ZLIB_LIBRARY} ${SSL_LIBRARIES} + ${ZLIB_LIBRARIES} ${SSL_LIBRARIES} ${LIBWRAP} ${LIBCRYPT} ${CMAKE_DL_LIBS} ${EMBEDDED_PLUGIN_LIBS} sql_embedded diff --git a/libmysqld/embedded_priv.h b/libmysqld/embedded_priv.h index 22627062..345c3ebd 100644 --- a/libmysqld/embedded_priv.h +++ b/libmysqld/embedded_priv.h @@ -23,6 +23,8 @@ void init_embedded_mysql(MYSQL *mysql, ulong client_flag); void *create_embedded_thd(ulong client_flag); int check_embedded_connection(MYSQL *mysql, const char *db); void free_old_query(MYSQL *mysql); +THD *embedded_get_current_thd(); +void embedded_set_current_thd(THD *thd); extern MYSQL_METHODS embedded_methods; /* This one is used by embedded library to gather returning data */ diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index 0be844fb..cf958c4e 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -111,7 +111,7 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, MYSQL_STMT *stmt) { my_bool result= 1; - THD *thd=(THD *) mysql->thd; + THD *thd=(THD *) mysql->thd, *old_current_thd= current_thd; NET *net= &mysql->net; my_bool stmt_skip= stmt ? stmt->state != MYSQL_STMT_INIT_DONE : FALSE; @@ -122,6 +122,8 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, else { free_embedded_thd(mysql); + if (old_current_thd == thd) + old_current_thd= 0; thd= 0; } } @@ -179,6 +181,8 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, end: thd->reset_globals(); + if (old_current_thd) + old_current_thd->store_globals(); return result; } @@ -265,6 +269,7 @@ static my_bool emb_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt) mysql->server_status|= SERVER_STATUS_IN_TRANS; stmt->fields= mysql->fields; + free_root(&stmt->mem_root, MYF(0)); stmt->mem_root= res->alloc; mysql->fields= NULL; my_free(res); @@ -374,6 +379,7 @@ int emb_read_binary_rows(MYSQL_STMT *stmt) set_stmt_errmsg(stmt, &stmt->mysql->net); return 1; } + free_root(&stmt->result.alloc, MYF(0)); stmt->result= *data; my_free(data); set_stmt_errmsg(stmt, &stmt->mysql->net); @@ -432,12 +438,15 @@ int emb_unbuffered_fetch(MYSQL *mysql, char **row) static void free_embedded_thd(MYSQL *mysql) { - THD *thd= (THD*)mysql->thd; + THD *thd= (THD*)mysql->thd, *org_current_thd= current_thd; server_threads.erase(thd); thd->clear_data_list(); thd->store_globals(); delete thd; - set_current_thd(nullptr); + if (thd == org_current_thd) + set_current_thd(nullptr); + else + set_current_thd(org_current_thd); mysql->thd=0; } @@ -727,6 +736,17 @@ void *create_embedded_thd(ulong client_flag) } +THD *embedded_get_current_thd() +{ + return current_thd; +} + +void embedded_set_current_thd(THD *thd) +{ + set_current_thd(thd); +} + + #ifdef NO_EMBEDDED_ACCESS_CHECKS static void emb_transfer_connect_attrs(MYSQL *mysql) diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c index 14cca6e0..444c1cfb 100644 --- a/libmysqld/libmysqld.c +++ b/libmysqld/libmysqld.c @@ -78,7 +78,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, uint port, const char *unix_socket,ulong client_flag) { char name_buff[USERNAME_LENGTH]; - + THD *org_current_thd= embedded_get_current_thd(); DBUG_ENTER("mysql_real_connect"); DBUG_PRINT("enter",("host: %s db: %s user: %s (libmysqld)", host ? host : "(Null)", @@ -200,6 +200,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, } } } + embedded_set_current_thd(org_current_thd); DBUG_PRINT("exit",("Mysql handler: %p", mysql)); DBUG_RETURN(mysql); @@ -216,6 +217,7 @@ error: mysql_close(mysql); mysql->free_me=free_me; } + embedded_set_current_thd(org_current_thd); DBUG_RETURN(0); } |