summaryrefslogtreecommitdiff
path: root/libmysqld
diff options
context:
space:
mode:
Diffstat (limited to 'libmysqld')
-rw-r--r--libmysqld/CMakeLists.txt40
-rw-r--r--libmysqld/emb_qcache.cc7
-rw-r--r--libmysqld/emb_qcache.h1
-rw-r--r--libmysqld/embedded_priv.h11
-rw-r--r--libmysqld/examples/CMakeLists.txt35
-rw-r--r--libmysqld/lib_sql.cc99
-rw-r--r--libmysqld/libmysql.c107
-rw-r--r--libmysqld/libmysqld.c4
8 files changed, 191 insertions, 113 deletions
diff --git a/libmysqld/CMakeLists.txt b/libmysqld/CMakeLists.txt
index e3d170fa47d..30ddf9ec1c3 100644
--- a/libmysqld/CMakeLists.txt
+++ b/libmysqld/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (c) 2006, 2011, Oracle and/or its affiliates.
-# Copyright (c) 2009, 2018, MariaDB Corporation
+# Copyright (c) 2009, 2020, MariaDB Corporation
#
# 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
@@ -21,6 +21,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/libmysqld
${CMAKE_SOURCE_DIR}/sql
+${CMAKE_SOURCE_DIR}/tpool
${CMAKE_BINARY_DIR}/sql
${PCRE_INCLUDES}
${ZLIB_INCLUDE_DIR}
@@ -30,9 +31,9 @@ ${SSL_INTERNAL_INCLUDE_DIRS}
SET(GEN_SOURCES
${CMAKE_BINARY_DIR}/sql/sql_yacc.hh
-${CMAKE_BINARY_DIR}/sql/sql_yacc.cc
-${CMAKE_BINARY_DIR}/sql/sql_yacc_ora.hh
-${CMAKE_BINARY_DIR}/sql/sql_yacc_ora.cc
+${CMAKE_BINARY_DIR}/sql/yy_mariadb.cc
+${CMAKE_BINARY_DIR}/sql/yy_oracle.hh
+${CMAKE_BINARY_DIR}/sql/yy_oracle.cc
${CMAKE_BINARY_DIR}/sql/lex_hash.h
)
@@ -46,7 +47,8 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
../sql/password.c ../sql/discover.cc ../sql/derror.cc
../sql/field.cc ../sql/field_conv.cc ../sql/field_comp.cc
../sql/filesort_utils.cc ../sql/sql_digest.cc
- ../sql/filesort.cc ../sql/gstream.cc ../sql/slave.cc
+ ../sql/filesort.cc ../sql/grant.cc
+ ../sql/gstream.cc ../sql/slave.cc
../sql/signal_handler.cc
../sql/handler.cc ../sql/hash_filo.cc ../sql/hostname.cc
../sql/init.cc ../sql/item_buff.cc ../sql/item_cmpfunc.cc
@@ -55,7 +57,8 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
../sql/item_subselect.cc ../sql/item_sum.cc ../sql/item_timefunc.cc
../sql/item_xmlfunc.cc ../sql/item_jsonfunc.cc
../sql/key.cc ../sql/lock.cc ../sql/log.cc
- ../sql/log_event.cc ../sql/mf_iocache.cc ../sql/my_decimal.cc
+ ../sql/log_event.cc ../sql/log_event_server.cc
+ ../sql/mf_iocache.cc ../sql/my_decimal.cc
../sql/net_serv.cc ../sql/opt_range.cc ../sql/opt_sum.cc
../sql/parse_file.cc ../sql/procedure.cc ../sql/protocol.cc
../sql/records.cc ../sql/repl_failsafe.cc ../sql/rpl_filter.cc
@@ -100,7 +103,9 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
../sql/multi_range_read.cc
../sql/opt_index_cond_pushdown.cc
../sql/opt_subselect.cc
- ../sql/create_options.cc ../sql/rpl_utility.cc
+ ../sql/create_options.cc
+ ../sql/rpl_utility.cc
+ ../sql/rpl_utility_server.cc
../sql/rpl_reporting.cc
../sql/sql_expression_cache.cc
../sql/my_apc.cc ../sql/my_apc.h
@@ -112,9 +117,10 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
../sql/sql_schema.cc
../sql/sql_type.cc ../sql/sql_type.h
../sql/sql_mode.cc
+ ../sql/sql_type_string.cc
../sql/sql_type_json.cc
+ ../sql/sql_type_geom.cc
../sql/table_cache.cc ../sql/mf_iocache_encr.cc
- ../sql/item_inetfunc.cc
../sql/wsrep_dummy.cc ../sql/encryption.cc
../sql/item_windowfunc.cc ../sql/sql_window.cc
../sql/sql_cte.cc
@@ -136,6 +142,9 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
ADD_CONVENIENCE_LIBRARY(sql_embedded ${SQL_EMBEDDED_SOURCES})
DTRACE_INSTRUMENT(sql_embedded)
ADD_DEPENDENCIES(sql_embedded GenError GenServerSource)
+IF(TARGET pcre2)
+ ADD_DEPENDENCIES(sql_embedded pcre2)
+ENDIF()
# On Windows, static embedded server library is called mysqlserver.lib
# On Unix, it is libmysqld.a
@@ -151,7 +160,7 @@ ENDIF()
SET(LIBS
- dbug strings mysys mysys_ssl pcre vio
+ dbug strings mysys mysys_ssl pcre2-8 vio
${ZLIB_LIBRARY} ${SSL_LIBRARIES}
${LIBWRAP} ${LIBCRYPT} ${CMAKE_DL_LIBS}
${EMBEDDED_PLUGIN_LIBS}
@@ -296,7 +305,7 @@ mysql_stmt_next_result
# Charsets
my_charset_bin
my_charset_latin1
-my_charset_utf8_general_ci
+my_charset_utf8mb3_general_ci
# Client plugins
mysql_client_find_plugin
mysql_client_register_plugin
@@ -419,9 +428,15 @@ mysql_net_field_length
mysql_options4
)
+
+SET(CLIENT_API_FUNCTIONS_10_5
+mariadb_field_attr
+)
+
SET(CLIENT_API_FUNCTIONS
${CLIENT_API_FUNCTIONS_5_1}
${CLIENT_API_FUNCTIONS_5_5}
+ ${CLIENT_API_FUNCTIONS_10_5}
)
@@ -451,11 +466,10 @@ IF(NOT DISABLE_SHARED)
# Clean direct output flags, as 2 targets have the same base name
# libmysqld
SET_TARGET_PROPERTIES(libmysqld PROPERTIES CLEAN_DIRECT_OUTPUT 1)
- TARGET_LINK_LIBRARIES(libmysqld LINK_PRIVATE ${CRC32_LIBRARY})
SET_TARGET_PROPERTIES(mysqlserver PROPERTIES CLEAN_DIRECT_OUTPUT 1)
- TARGET_LINK_LIBRARIES(mysqlserver LINK_PRIVATE ${CRC32_LIBRARY})
+ TARGET_LINK_LIBRARIES(mysqlserver LINK_PRIVATE tpool ${CRC32_LIBRARY})
IF(LIBMYSQLD_SO_EXTRA_LIBS)
- TARGET_LINK_LIBRARIES(libmysqld ${LIBMYSQLD_SO_EXTRA_LIBS})
+ TARGET_LINK_LIBRARIES(libmysqld LINK_PRIVATE ${LIBMYSQLD_SO_EXTRA_LIBS})
ENDIF()
ENDIF()
ENDIF()
diff --git a/libmysqld/emb_qcache.cc b/libmysqld/emb_qcache.cc
index 603542e820e..31f4cf111ee 100644
--- a/libmysqld/emb_qcache.cc
+++ b/libmysqld/emb_qcache.cc
@@ -418,7 +418,7 @@ int emb_load_querycache_result(THD *thd, Querycache_stream *src)
if (!data)
goto err;
- init_alloc_root(&data->alloc, "embedded_query_cache", 8192,0,MYF(0));
+ init_alloc_root(PSI_NOT_INSTRUMENTED, &data->alloc, 8192, 0, MYF(0));
f_alloc= &data->alloc;
data->fields= src->load_int();
@@ -445,6 +445,7 @@ int emb_load_querycache_result(THD *thd, Querycache_stream *src)
!(field->catalog= src->load_str(f_alloc, &field->catalog_length)) ||
src->load_safe_str(f_alloc, &field->def, &field->def_length))
goto err;
+ field->extension= NULL;
}
data->rows= rows;
@@ -490,8 +491,8 @@ int emb_load_querycache_result(THD *thd, Querycache_stream *src)
*prev_row= NULL;
data->embedded_info->prev_ptr= prev_row;
return_ok:
- net_send_eof(thd, thd->server_status,
- thd->get_stmt_da()->current_statement_warn_count());
+ thd->protocol->net_send_eof(thd, thd->server_status,
+ thd->get_stmt_da()->current_statement_warn_count());
DBUG_RETURN(0);
err:
DBUG_RETURN(1);
diff --git a/libmysqld/emb_qcache.h b/libmysqld/emb_qcache.h
index c4268752f9a..e3b6339ba3a 100644
--- a/libmysqld/emb_qcache.h
+++ b/libmysqld/emb_qcache.h
@@ -81,4 +81,3 @@ public:
uint emb_count_querycache_size(THD *thd);
int emb_load_querycache_result(THD *thd, Querycache_stream *src);
void emb_store_querycache_result(Querycache_stream *dst, THD* thd);
-bool net_send_eof(THD *thd, uint server_status, uint total_warn_count);
diff --git a/libmysqld/embedded_priv.h b/libmysqld/embedded_priv.h
index 77955ea499e..2262706217e 100644
--- a/libmysqld/embedded_priv.h
+++ b/libmysqld/embedded_priv.h
@@ -19,8 +19,8 @@
C_MODE_START
void lib_connection_phase(NET *net, int phase);
-void init_embedded_mysql(MYSQL *mysql, int client_flag);
-void *create_embedded_thd(int client_flag);
+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);
extern MYSQL_METHODS embedded_methods;
@@ -38,4 +38,11 @@ typedef struct embedded_query_result
char sqlstate[SQLSTATE_LENGTH+1];
} EQR;
+
+typedef struct st_mariadb_field_extension
+{
+ MARIADB_CONST_STRING metadata[MARIADB_FIELD_ATTR_LAST+1]; /* 10.5 */
+} MARIADB_FIELD_EXTENSION;
+
+
C_MODE_END
diff --git a/libmysqld/examples/CMakeLists.txt b/libmysqld/examples/CMakeLists.txt
index 52fbe42aaa2..2a10def8e2e 100644
--- a/libmysqld/examples/CMakeLists.txt
+++ b/libmysqld/examples/CMakeLists.txt
@@ -1,14 +1,14 @@
# Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
-#
+#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
@@ -24,39 +24,40 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
ADD_DEFINITIONS(-DEMBEDDED_LIBRARY -UMYSQL_CLIENT)
-MYSQL_ADD_EXECUTABLE(mysql_embedded ../../client/completion_hash.cc
+MYSQL_ADD_EXECUTABLE(mariadb-embedded ../../client/completion_hash.cc
../../client/mysql.cc ../../client/readline.cc
COMPONENT Client)
-TARGET_LINK_LIBRARIES(mysql_embedded mysqlserver)
+TARGET_LINK_LIBRARIES(mariadb-embedded mysqlserver)
IF(UNIX)
- TARGET_LINK_LIBRARIES(mysql_embedded ${MY_READLINE_LIBRARY})
+ TARGET_LINK_LIBRARIES(mariadb-embedded ${MY_READLINE_LIBRARY})
ENDIF(UNIX)
-MYSQL_ADD_EXECUTABLE(mysqltest_embedded ../../client/mysqltest.cc
+MYSQL_ADD_EXECUTABLE(mariadb-test-embedded ../../client/mysqltest.cc
COMPONENT Test)
-TARGET_LINK_LIBRARIES(mysqltest_embedded mysqlserver pcreposix pcre)
+TARGET_LINK_LIBRARIES(mariadb-test-embedded mysqlserver pcre2-posix pcre2-8)
+SET_SOURCE_FILES_PROPERTIES(../../client/mysqltest.cc PROPERTIES COMPILE_FLAGS "${PCRE2_DEBIAN_HACK}")
IF(CMAKE_GENERATOR MATCHES "Xcode")
# It does not seem possible to tell Xcode the resulting target might need
# to be linked with C++ runtime. The project needs to have at least one C++
# file. Add a dummy one.
- ADD_CUSTOM_COMMAND(OUTPUT
+ ADD_CUSTOM_COMMAND(OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/mysql_client_test_embedded_dummy.cc
- COMMAND ${CMAKE_COMMAND} -E touch
+ COMMAND ${CMAKE_COMMAND} -E touch
${CMAKE_CURRENT_BINARY_DIR}/mysql_client_test_embedded_dummy.cc
)
- MYSQL_ADD_EXECUTABLE(mysql_client_test_embedded
+ MYSQL_ADD_EXECUTABLE(mariadb-client-test-embedded
${CMAKE_CURRENT_BINARY_DIR}/mysql_client_test_embedded_dummy.cc
../../tests/mysql_client_test.c)
ELSE()
- MYSQL_ADD_EXECUTABLE(mysql_client_test_embedded ../../tests/mysql_client_test.c
+ MYSQL_ADD_EXECUTABLE(mariadb-client-test-embedded ../../tests/mysql_client_test.c
COMPONENT Test)
- SET_TARGET_PROPERTIES(mysql_client_test_embedded PROPERTIES HAS_CXX TRUE)
+ SET_TARGET_PROPERTIES(mariadb-client-test-embedded PROPERTIES HAS_CXX TRUE)
ENDIF()
-TARGET_LINK_LIBRARIES(mysql_client_test_embedded mysqlserver)
+TARGET_LINK_LIBRARIES(mariadb-client-test-embedded mysqlserver)
IF(UNIX)
-SET_TARGET_PROPERTIES(mysql_embedded PROPERTIES ENABLE_EXPORTS TRUE)
-SET_TARGET_PROPERTIES(mysqltest_embedded PROPERTIES ENABLE_EXPORTS TRUE)
-SET_TARGET_PROPERTIES(mysql_client_test_embedded PROPERTIES ENABLE_EXPORTS TRUE)
+SET_TARGET_PROPERTIES(mariadb-embedded PROPERTIES ENABLE_EXPORTS TRUE)
+SET_TARGET_PROPERTIES(mariadb-test-embedded PROPERTIES ENABLE_EXPORTS TRUE)
+SET_TARGET_PROPERTIES(mariadb-client-test-embedded PROPERTIES ENABLE_EXPORTS TRUE)
ENDIF()
diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
index 55c6dd6f6e8..32668f7a331 100644
--- a/libmysqld/lib_sql.cc
+++ b/libmysqld/lib_sql.cc
@@ -438,7 +438,7 @@ static void emb_free_embedded_thd(MYSQL *mysql)
thd->clear_data_list();
thd->store_globals();
delete thd;
- my_pthread_setspecific_ptr(THR_THD, 0);
+ set_current_thd(nullptr);
mysql->thd=0;
}
@@ -492,8 +492,8 @@ char **copy_arguments(int argc, char **argv)
for (from=argv ; from != end ; from++)
length+= strlen(*from);
- if ((res= (char**) my_malloc(sizeof(argv)*(argc+1)+length+argc,
- MYF(MY_WME))))
+ if ((res= (char**) my_malloc(PSI_NOT_INSTRUMENTED,
+ sizeof(argv)*(argc+1)+length+argc, MYF(MY_WME))))
{
char **to= res, *to_str= (char*) (res+argc+1);
for (from=argv ; from != end ;)
@@ -561,7 +561,7 @@ int init_embedded_server(int argc, char **argv, char **groups)
remaining_argv= *argvp;
/* Must be initialized early for comparison of options name */
- system_charset_info= &my_charset_utf8_general_ci;
+ system_charset_info= &my_charset_utf8mb3_general_ci;
sys_var_init();
int ho_error= handle_early_options();
@@ -660,13 +660,13 @@ void end_embedded_server()
}
-void init_embedded_mysql(MYSQL *mysql, int client_flag)
+void init_embedded_mysql(MYSQL *mysql, ulong client_flag)
{
THD *thd = (THD *)mysql->thd;
thd->mysql= mysql;
mysql->server_version= server_version;
mysql->client_flag= client_flag;
- init_alloc_root(&mysql->field_alloc, "fields", 8192, 0, MYF(0));
+ init_alloc_root(PSI_NOT_INSTRUMENTED, &mysql->field_alloc, 8192, 0, MYF(0));
}
/**
@@ -680,16 +680,12 @@ void init_embedded_mysql(MYSQL *mysql, int client_flag)
create_new_thread(), and prepare_new_connection_state(). This should
be refactored to avoid code duplication.
*/
-void *create_embedded_thd(int client_flag)
+void *create_embedded_thd(ulong client_flag)
{
THD * thd= new THD(next_thread_id());
thd->thread_stack= (char*) &thd;
- if (thd->store_globals())
- {
- fprintf(stderr,"store_globals failed.\n");
- goto err;
- }
+ thd->store_globals();
lex_start(thd);
/* TODO - add init_connect command execution */
@@ -700,13 +696,13 @@ void *create_embedded_thd(int client_flag)
thd->set_command(COM_SLEEP);
thd->set_time();
thd->init_for_queries();
- thd->client_capabilities= client_flag;
+ thd->client_capabilities= client_flag | MARIADB_CLIENT_EXTENDED_METADATA;
thd->real_id= pthread_self();
thd->db= null_clex_str;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
thd->security_ctx->db_access= DB_ACLS;
- thd->security_ctx->master_access= ~NO_ACCESS;
+ thd->security_ctx->master_access= ALL_KNOWN_ACL;
#endif
thd->cur_data= 0;
thd->first_data= 0;
@@ -716,9 +712,6 @@ void *create_embedded_thd(int client_flag)
thd->mysys_var= 0;
thd->reset_globals();
return thd;
-err:
- delete(thd);
- return NULL;
}
@@ -760,7 +753,7 @@ int check_embedded_connection(MYSQL *mysql, const char *db)
sctx->host_or_ip= sctx->host= (char*) my_localhost;
strmake_buf(sctx->priv_host, (char*) my_localhost);
strmake_buf(sctx->priv_user, mysql->user);
- sctx->user= my_strdup(mysql->user, MYF(0));
+ sctx->user= my_strdup(PSI_NOT_INSTRUMENTED, mysql->user, MYF(0));
sctx->proxy_user[0]= 0;
sctx->master_access= GLOBAL_ACLS; // Full rights
emb_transfer_connect_attrs(mysql);
@@ -894,13 +887,6 @@ static char *dup_str_aux(MEM_ROOT *root, const char *from, uint length,
}
-static char *dup_str_aux(MEM_ROOT *root, const char *from,
- CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
-{
- return dup_str_aux(root, from, (uint) strlen(from), fromcs, tocs);
-}
-
-
static char *dup_str_aux(MEM_ROOT *root, const LEX_CSTRING &from,
CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
{
@@ -927,10 +913,8 @@ MYSQL_DATA *THD::alloc_new_dataset()
{
MYSQL_DATA *data;
struct embedded_query_result *emb_data;
- if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
- &data, sizeof(*data),
- &emb_data, sizeof(*emb_data),
- NULL))
+ if (!my_multi_malloc(PSI_NOT_INSTRUMENTED, MYF(MY_WME | MY_ZEROFILL),
+ &data, sizeof(*data), &emb_data, sizeof(*emb_data), NULL))
return NULL;
emb_data->prev_ptr= &data->data;
@@ -993,7 +977,7 @@ bool Protocol::begin_dataset()
return 1;
alloc= &data->alloc;
/* Assume rowlength < 8192 */
- init_alloc_root(alloc, "protocol", 8192, 0, MYF(0));
+ init_alloc_root(PSI_NOT_INSTRUMENTED, alloc, 8192, 0, MYF(0));
alloc->min_malloc= sizeof(MYSQL_ROWS);
return 0;
}
@@ -1041,6 +1025,39 @@ void Protocol_text::remove_last_row()
}
+
+static MARIADB_CONST_STRING ma_const_string_copy_root(MEM_ROOT *memroot,
+ const char *str,
+ size_t length)
+{
+ MARIADB_CONST_STRING res;
+ if (!str || !(res.str= strmake_root(memroot, str, length)))
+ return null_clex_str;
+ res.length= length;
+ return res;
+}
+
+
+class Client_field_extension: public Sql_alloc,
+ public MARIADB_FIELD_EXTENSION
+{
+public:
+ Client_field_extension()
+ {
+ memset(this, 0, sizeof(*this));
+ }
+ void copy_extended_metadata(MEM_ROOT *memroot,
+ const Send_field_extended_metadata &src)
+ {
+ for (uint i= 0; i <= MARIADB_FIELD_ATTR_LAST; i++)
+ {
+ LEX_CSTRING attr= src.attr(i);
+ metadata[i]= ma_const_string_copy_root(memroot, attr.str, attr.length);
+ }
+ }
+};
+
+
bool Protocol_text::store_field_metadata(const THD * thd,
const Send_field &server_field,
CHARSET_INFO *charset_for_protocol,
@@ -1089,6 +1106,17 @@ bool Protocol_text::store_field_metadata(const THD * thd,
client_field->catalog= dup_str_aux(field_alloc, "def", 3, cs, thd_cs);
client_field->catalog_length= 3;
+ if (server_field.has_extended_metadata())
+ {
+ Client_field_extension *ext= new (field_alloc) Client_field_extension();
+ if ((client_field->extension= static_cast<MARIADB_FIELD_EXTENSION*>(ext)))
+ ext->copy_extended_metadata(field_alloc, server_field);
+ }
+ else
+ {
+ client_field->extension= NULL;
+ }
+
if (IS_NUM(client_field->type))
client_field->flags|= NUM_FLAG;
@@ -1113,7 +1141,7 @@ bool Protocol::send_result_set_metadata(List<Item> *list, uint flags)
for (uint pos= 0 ; (item= it++); pos++)
{
- if (prot.store_field_metadata(thd, item, pos))
+ if (prot.store_item_metadata(thd, item, pos))
goto err;
}
@@ -1228,8 +1256,7 @@ bool Protocol_binary::write()
@retval FALSE Success
*/
-bool
-net_send_ok(THD *thd,
+bool Protocol::net_send_ok(THD *thd,
uint server_status, uint statement_warn_count,
ulonglong affected_rows, ulonglong id, const char *message,
bool, bool)
@@ -1264,7 +1291,7 @@ net_send_ok(THD *thd,
*/
bool
-net_send_eof(THD *thd, uint server_status, uint statement_warn_count)
+Protocol::net_send_eof(THD *thd, uint server_status, uint statement_warn_count)
{
bool error= write_eof_packet(thd, server_status, statement_warn_count);
thd->cur_data= 0;
@@ -1272,8 +1299,8 @@ net_send_eof(THD *thd, uint server_status, uint statement_warn_count)
}
-bool net_send_error_packet(THD *thd, uint sql_errno, const char *err,
- const char *sqlstate)
+bool Protocol::net_send_error_packet(THD *thd, uint sql_errno, const char *err,
+ const char *sqlstate)
{
uint error;
char converted_err[MYSQL_ERRMSG_SIZE];
diff --git a/libmysqld/libmysql.c b/libmysqld/libmysql.c
index 1ebcae0d8d5..9a0858fd067 100644
--- a/libmysqld/libmysql.c
+++ b/libmysqld/libmysql.c
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates
- Copyright (c) 2009, 2017, MariaDB Corporation
+ Copyright (c) 2009, 2020, MariaDB Corporation
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
@@ -64,6 +64,7 @@
#include <sql_common.h>
#include "client_settings.h"
+#include "embedded_priv.h"
#undef net_buffer_length
#undef max_allowed_packet
@@ -400,9 +401,9 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
my_free(saved_db);
/* alloc new connect information */
- mysql->user= my_strdup(mysql->user, MYF(MY_WME));
- mysql->passwd= my_strdup(mysql->passwd, MYF(MY_WME));
- mysql->db= db ? my_strdup(db, MYF(MY_WME)) : 0;
+ mysql->user= my_strdup(PSI_NOT_INSTRUMENTED, mysql->user, MYF(MY_WME));
+ mysql->passwd= my_strdup(PSI_NOT_INSTRUMENTED, mysql->passwd, MYF(MY_WME));
+ mysql->db= db ? my_strdup(PSI_NOT_INSTRUMENTED, db, MYF(MY_WME)) : 0;
}
else
{
@@ -412,7 +413,7 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
mysql->db= saved_db;
}
- DBUG_RETURN(rc);
+ DBUG_RETURN(rc != 0);
}
#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL)
@@ -483,7 +484,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))))
+ if (!(buf=my_malloc(PSI_NOT_INSTRUMENTED, packet_length, MYF(0))))
{
set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
DBUG_RETURN(1);
@@ -581,7 +582,8 @@ static int default_local_infile_init(void **ptr, const char *filename,
char tmp_name[FN_REFLEN];
if (!(*ptr= data= ((default_local_infile_data *)
- my_malloc(sizeof(default_local_infile_data), MYF(0)))))
+ my_malloc(PSI_NOT_INSTRUMENTED,
+ sizeof(default_local_infile_data), MYF(0)))))
return 1; /* out of memory */
data->error_msg[0]= 0;
@@ -735,6 +737,26 @@ mysql_fetch_field(MYSQL_RES *result)
/**************************************************************************
+** Return mysql field metadata
+**************************************************************************/
+int STDCALL
+mariadb_field_attr(MARIADB_CONST_STRING *attr,
+ const MYSQL_FIELD *field,
+ enum mariadb_field_attr_t type)
+{
+ MARIADB_FIELD_EXTENSION *ext= (MARIADB_FIELD_EXTENSION*) field->extension;
+ if (!ext || type > MARIADB_FIELD_ATTR_LAST)
+ {
+ static MARIADB_CONST_STRING null_str= {0,0};
+ *attr= null_str;
+ return 1;
+ }
+ *attr= ext->metadata[type];
+ return 0;
+}
+
+
+/**************************************************************************
Move to a specific row and column
**************************************************************************/
@@ -819,7 +841,8 @@ MYSQL_FIELD *cli_list_fields(MYSQL *mysql)
mysql->field_count= (uint) query->rows;
return unpack_fields(mysql, query,&mysql->field_alloc,
- mysql->field_count, 1, mysql->server_capabilities);
+ mysql->field_count, 1,
+ (uint) mysql->server_capabilities);
}
@@ -846,7 +869,7 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild)
!(fields= (*mysql->methods->list_fields)(mysql)))
DBUG_RETURN(NULL);
- if (!(result = (MYSQL_RES *) my_malloc(sizeof(MYSQL_RES),
+ if (!(result = (MYSQL_RES *) my_malloc(PSI_NOT_INSTRUMENTED, sizeof(MYSQL_RES),
MYF(MY_WME | MY_ZEROFILL))))
DBUG_RETURN(NULL);
@@ -878,7 +901,7 @@ mysql_list_processes(MYSQL *mysql)
protocol_41(mysql) ? 7 : 5)))
DBUG_RETURN(NULL);
if (!(mysql->fields=unpack_fields(mysql, fields,&mysql->field_alloc,field_count,0,
- mysql->server_capabilities)))
+ (uint) mysql->server_capabilities)))
DBUG_RETURN(0);
mysql->status=MYSQL_STATUS_GET_RESULT;
mysql->field_count=field_count;
@@ -1064,11 +1087,6 @@ unsigned int STDCALL mysql_field_count(MYSQL *mysql)
return mysql->field_count;
}
-my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql)
-{
- return mysql->affected_rows;
-}
-
my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql)
{
return mysql->insert_id;
@@ -1209,7 +1227,7 @@ myodbc_remove_escape(MYSQL *mysql,char *name)
{
char *to;
#ifdef USE_MB
- my_bool use_mb_flag=use_mb(mysql->charset);
+ my_bool use_mb_flag= my_ci_use_mb(mysql->charset);
char *UNINIT_VAR(end);
if (use_mb_flag)
for (end=name; *end ; end++) ;
@@ -1469,12 +1487,12 @@ my_bool cli_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt)
if (!(fields_data= (*mysql->methods->read_rows)(mysql,(MYSQL_FIELD*)0,7)))
DBUG_RETURN(1);
if (!(stmt->fields= unpack_fields(mysql, fields_data,&stmt->mem_root,
- field_count,0,
- mysql->server_capabilities)))
+ field_count,0,
+ (uint) mysql->server_capabilities)))
DBUG_RETURN(1);
}
stmt->field_count= field_count;
- stmt->param_count= (ulong) param_count;
+ stmt->param_count= (uint) param_count;
DBUG_PRINT("exit",("field_count: %u param_count: %u warning_count: %u",
field_count, param_count, (uint) mysql->warning_count));
@@ -1525,10 +1543,10 @@ mysql_stmt_init(MYSQL *mysql)
DBUG_ENTER("mysql_stmt_init");
if (!(stmt=
- (MYSQL_STMT *) my_malloc(sizeof (MYSQL_STMT),
+ (MYSQL_STMT *) my_malloc(PSI_NOT_INSTRUMENTED, sizeof (MYSQL_STMT),
MYF(MY_WME | MY_ZEROFILL))) ||
!(stmt->extension=
- (MYSQL_STMT_EXT *) my_malloc(sizeof (MYSQL_STMT_EXT),
+ (MYSQL_STMT_EXT *) my_malloc(PSI_NOT_INSTRUMENTED, sizeof (MYSQL_STMT_EXT),
MYF(MY_WME | MY_ZEROFILL))))
{
set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
@@ -1536,9 +1554,8 @@ mysql_stmt_init(MYSQL *mysql)
DBUG_RETURN(NULL);
}
- init_alloc_root(&stmt->mem_root, "stmt", 2048,2048, MYF(MY_THREAD_SPECIFIC));
- init_alloc_root(&stmt->result.alloc, "result", 4096, 4096,
- MYF(MY_THREAD_SPECIFIC));
+ init_alloc_root(PSI_NOT_INSTRUMENTED, &stmt->mem_root, 2048,2048, MYF(MY_THREAD_SPECIFIC));
+ init_alloc_root(PSI_NOT_INSTRUMENTED, &stmt->result.alloc, 4096, 4096, MYF(MY_THREAD_SPECIFIC));
stmt->result.alloc.min_malloc= sizeof(MYSQL_ROWS);
mysql->stmts= list_add(mysql->stmts, &stmt->list);
stmt->list.data= stmt;
@@ -1549,7 +1566,7 @@ mysql_stmt_init(MYSQL *mysql)
strmov(stmt->sqlstate, not_error_sqlstate);
/* The rest of statement members was bzeroed inside malloc */
- init_alloc_root(&stmt->extension->fields_mem_root, "extension", 2048, 0,
+ init_alloc_root(PSI_NOT_INSTRUMENTED, &stmt->extension->fields_mem_root, 2048, 0,
MYF(MY_THREAD_SPECIFIC));
DBUG_RETURN(stmt);
@@ -1836,7 +1853,7 @@ mysql_stmt_result_metadata(MYSQL_STMT *stmt)
if (!stmt->field_count)
DBUG_RETURN(0);
- if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result),
+ if (!(result=(MYSQL_RES*) my_malloc(PSI_NOT_INSTRUMENTED, sizeof(*result),
MYF(MY_WME | MY_ZEROFILL))))
{
set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate, NULL);
@@ -2006,7 +2023,10 @@ static void net_store_datetime(NET *net, MYSQL_TIME *tm)
static void store_param_date(NET *net, MYSQL_BIND *param)
{
MYSQL_TIME tm= *((MYSQL_TIME *) param->buffer);
- tm.hour= tm.minute= tm.second= tm.second_part= 0;
+ tm.hour= 0;
+ tm.minute= 0;
+ tm.second= 0;
+ tm.second_part= 0;
net_store_datetime(net, &tm);
}
@@ -2043,7 +2063,14 @@ static void store_param_str(NET *net, MYSQL_BIND *param)
static void store_param_null(NET *net, MYSQL_BIND *param)
{
uint pos= param->param_number;
+#if defined __GNUC__ && !defined __clang__ && __GNUC__ == 5
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wconversion" /* GCC 5 needs this */
+#endif
net->buff[pos/8]|= (uchar) (1 << (pos & 7));
+#if defined __GNUC__ && !defined __clang__ && __GNUC__ == 5
+# pragma GCC diagnostic pop
+#endif
}
@@ -2194,7 +2221,7 @@ 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(net->buff, length, MYF(0))))
+ if (!(param_data= my_memdup(PSI_NOT_INSTRUMENTED, net->buff, length, MYF(0))))
{
set_stmt_error(stmt, CR_OUT_OF_MEMORY, unknown_sqlstate, NULL);
DBUG_RETURN(1);
@@ -3064,14 +3091,14 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number,
static void read_binary_time(MYSQL_TIME *tm, uchar **pos)
{
/* net_field_length will set pos to the first byte of data */
- uint length= net_field_length(pos);
+ ulong length= net_field_length(pos);
if (length)
{
uchar *to= *pos;
tm->neg= to[0];
- tm->day= (ulong) sint4korr(to+1);
+ tm->day= (uint) sint4korr(to+1);
tm->hour= (uint) to[5];
tm->minute= (uint) to[6];
tm->second= (uint) to[7];
@@ -3093,7 +3120,7 @@ static void read_binary_time(MYSQL_TIME *tm, uchar **pos)
static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos)
{
- uint length= net_field_length(pos);
+ ulong length= net_field_length(pos);
if (length)
{
@@ -3123,7 +3150,7 @@ static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos)
static void read_binary_date(MYSQL_TIME *tm, uchar **pos)
{
- uint length= net_field_length(pos);
+ ulong length= net_field_length(pos);
if (length)
{
@@ -3201,7 +3228,7 @@ static void fetch_string_with_conversion(MYSQL_BIND *param, char *value, size_t
}
case MYSQL_TYPE_FLOAT:
{
- double data= my_strntod(&my_charset_latin1, value, length, &endptr, &err);
+ double data= my_ci_strntod(&my_charset_latin1, value, length, &endptr, &err);
float fdata= (float) data;
*param->error= (fdata != data) | MY_TEST(err);
floatstore(buffer, fdata);
@@ -3209,7 +3236,7 @@ static void fetch_string_with_conversion(MYSQL_BIND *param, char *value, size_t
}
case MYSQL_TYPE_DOUBLE:
{
- double data= my_strntod(&my_charset_latin1, value, length, &endptr, &err);
+ double data= my_ci_strntod(&my_charset_latin1, value, length, &endptr, &err);
*param->error= MY_TEST(err);
doublestore(buffer, data);
break;
@@ -3364,7 +3391,7 @@ static void fetch_long_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field,
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);
+ size_t length= end-buff;
if (field->flags & ZEROFILL_FLAG && length < field->length &&
field->length < 21)
@@ -3888,8 +3915,10 @@ static my_bool is_binary_compatible(enum enum_field_types type1,
my_bool type1_found= FALSE, type2_found= FALSE;
for (type= *range; *type != MYSQL_TYPE_NULL; type++)
{
- type1_found|= type1 == *type;
- type2_found|= type2 == *type;
+ if (type1 == *type)
+ type1_found= TRUE;
+ if (type2 == *type)
+ type2_found= TRUE;
}
if (type1_found || type2_found)
return type1_found && type2_found;
@@ -4197,7 +4226,7 @@ static int stmt_fetch_row(MYSQL_STMT *stmt, uchar *row)
(*my_bind->fetch_result)(my_bind, field, &row);
truncation_count+= *my_bind->error;
}
- if (!((bit<<=1) & 255))
+ if (!(bit= (uchar) (bit << 1)))
{
bit= 1; /* To next uchar */
null_ptr++;
@@ -4397,7 +4426,7 @@ static void stmt_update_metadata(MYSQL_STMT *stmt, MYSQL_ROWS *data)
if (!(*null_ptr & bit))
(*my_bind->skip_result)(my_bind, field, &row);
DBUG_ASSERT(row <= row_end);
- if (!((bit<<=1) & 255))
+ if (!(bit= (uchar) (bit << 1)))
{
bit= 1; /* To next uchar */
null_ptr++;
diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c
index 6de86927a38..d29126467e2 100644
--- a/libmysqld/libmysqld.c
+++ b/libmysqld/libmysqld.c
@@ -157,7 +157,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
put extra 'my_free's in mysql_close.
So we alloc it with the 'user' string to be freed at once
*/
- mysql->user= my_strdup(user, MYF(0));
+ mysql->user= my_strdup(PSI_NOT_INSTRUMENTED, user, MYF(0));
port=0;
unix_socket=0;
@@ -175,7 +175,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if (db)
client_flag|=CLIENT_CONNECT_WITH_DB;
- mysql->info_buffer= my_malloc(MYSQL_ERRMSG_SIZE, MYF(0));
+ mysql->info_buffer= my_malloc(PSI_NOT_INSTRUMENTED, MYSQL_ERRMSG_SIZE, MYF(0));
mysql->thd= create_embedded_thd(client_flag);
init_embedded_mysql(mysql, client_flag);