summaryrefslogtreecommitdiff
path: root/libmysqld/lib_sql.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libmysqld/lib_sql.cc')
-rw-r--r--libmysqld/lib_sql.cc86
1 files changed, 67 insertions, 19 deletions
diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
index db6cb2bf561..9024ae9321e 100644
--- a/libmysqld/lib_sql.cc
+++ b/libmysqld/lib_sql.cc
@@ -142,7 +142,7 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command,
/* Clear result variables */
thd->clear_error();
- thd->stmt_da->reset_diagnostics_area();
+ thd->get_stmt_da()->reset_diagnostics_area();
mysql->affected_rows= ~(my_ulonglong) 0;
mysql->field_count= 0;
net_clear_error(net);
@@ -253,7 +253,7 @@ static my_bool emb_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt)
stmt->stmt_id= thd->client_stmt_id;
stmt->param_count= thd->client_param_count;
stmt->field_count= 0;
- mysql->warning_count= thd->warning_info->statement_warn_count();
+ mysql->warning_count= thd->get_stmt_da()->current_statement_warn_count();
if (thd->first_data)
{
@@ -344,8 +344,8 @@ static int emb_stmt_execute(MYSQL_STMT *stmt)
thd->client_param_count= stmt->param_count;
thd->client_params= stmt->params;
- res= test(emb_advanced_command(stmt->mysql, COM_STMT_EXECUTE, 0, 0,
- header, sizeof(header), 1, stmt) ||
+ res= MY_TEST(emb_advanced_command(stmt->mysql, COM_STMT_EXECUTE, 0, 0,
+ header, sizeof(header), 1, stmt) ||
emb_read_query_result(stmt->mysql));
stmt->affected_rows= stmt->mysql->affected_rows;
stmt->insert_id= stmt->mysql->insert_id;
@@ -442,7 +442,7 @@ static void emb_free_embedded_thd(MYSQL *mysql)
static const char * emb_read_statistics(MYSQL *mysql)
{
THD *thd= (THD*)mysql->thd;
- return thd->is_error() ? thd->stmt_da->message() : "";
+ return thd->is_error() ? thd->get_stmt_da()->message() : "";
}
@@ -534,7 +534,8 @@ int init_embedded_server(int argc, char **argv, char **groups)
if (!groups)
groups= (char**) fake_groups;
- my_progname= (char *)"mysql_embedded";
+ if (!my_progname)
+ my_progname= (char *)"mysql_embedded";
/*
Perform basic logger initialization logger. Should be called after
@@ -555,6 +556,10 @@ int init_embedded_server(int argc, char **argv, char **groups)
system_charset_info= &my_charset_utf8_general_ci;
sys_var_init();
+ int ho_error= handle_early_options();
+ if (ho_error != 0)
+ return 1;
+
if (init_common_variables())
{
mysql_server_end();
@@ -617,7 +622,7 @@ int init_embedded_server(int argc, char **argv, char **groups)
// FIXME initialize binlog_filter and rpl_filter if not already done
// corresponding delete is in clean_up()
if(!binlog_filter) binlog_filter = new Rpl_filter;
- if(!rpl_filter) rpl_filter = new Rpl_filter;
+ if(!global_rpl_filter) global_rpl_filter = new Rpl_filter;
if (opt_init_file)
{
@@ -647,8 +652,7 @@ void init_embedded_mysql(MYSQL *mysql, int client_flag)
thd->mysql= mysql;
mysql->server_version= server_version;
mysql->client_flag= client_flag;
- //mysql->server_capabilities= client_flag;
- init_alloc_root(&mysql->field_alloc, 8192, 0);
+ init_alloc_root(&mysql->field_alloc, 8192, 0, MYF(0));
}
/**
@@ -680,7 +684,7 @@ void *create_embedded_thd(int client_flag)
if (thd->variables.max_join_size == HA_POS_ERROR)
thd->variables.option_bits |= OPTION_BIG_SELECTS;
thd->proc_info=0; // Remove 'login'
- thd->command=COM_SLEEP;
+ thd->set_command(COM_SLEEP);
thd->set_time();
thd->init_for_queries();
thd->client_capabilities= client_flag;
@@ -710,11 +714,37 @@ err:
#ifdef NO_EMBEDDED_ACCESS_CHECKS
+static void
+emb_transfer_connect_attrs(MYSQL *mysql)
+{
+#ifdef HAVE_PSI_THREAD_INTERFACE
+ if (mysql->options.extension &&
+ mysql->options.extension->connection_attributes_length)
+ {
+ uchar *buf, *ptr;
+ THD *thd= (THD*)mysql->thd;
+ size_t length= mysql->options.extension->connection_attributes_length;
+
+ /* 9 = max length of the serialized length */
+ ptr= buf= (uchar *) my_alloca(length + 9);
+ send_client_connect_attrs(mysql, buf);
+ net_field_length_ll(&ptr);
+ PSI_THREAD_CALL(set_thread_connect_attrs)((char *) ptr, length, thd->charset());
+ my_afree(buf);
+ }
+#endif
+}
+
+
int check_embedded_connection(MYSQL *mysql, const char *db)
{
int result;
LEX_STRING db_str = { (char*)db, db ? strlen(db) : 0 };
THD *thd= (THD*)mysql->thd;
+
+ /* the server does the same as the client */
+ mysql->server_capabilities= mysql->client_flag;
+
thd_init_client_charset(thd, mysql->charset->number);
thd->update_charset();
Security_context *sctx= thd->security_ctx;
@@ -724,6 +754,7 @@ int check_embedded_connection(MYSQL *mysql, const char *db)
sctx->user= my_strdup(mysql->user, MYF(0));
sctx->proxy_user[0]= 0;
sctx->master_access= GLOBAL_ACLS; // Full rights
+ emb_transfer_connect_attrs(mysql);
/* Change database if necessary */
if (!(result= (db && db[0] && mysql_change_db(thd, &db_str, FALSE))))
my_ok(thd);
@@ -739,11 +770,17 @@ int check_embedded_connection(MYSQL *mysql, const char *db)
we emulate a COM_CHANGE_USER user here,
it's easier than to emulate the complete 3-way handshake
*/
- char buf[USERNAME_LENGTH + SCRAMBLE_LENGTH + 1 + 2*NAME_LEN + 2], *end;
+ char *buf, *end;
NET *net= &mysql->net;
THD *thd= (THD*)mysql->thd;
Security_context *sctx= thd->security_ctx;
+ size_t connect_attrs_len=
+ (mysql->options.extension) ?
+ mysql->options.extension->connection_attributes_length : 0;
+ buf= (char *)my_alloca(USERNAME_LENGTH + SCRAMBLE_LENGTH + 1 +
+ 2*NAME_LEN + 2 +
+ connect_attrs_len + 2);
if (mysql->options.client_ip)
{
sctx->host= my_strdup(mysql->options.client_ip, MYF(0));
@@ -777,21 +814,31 @@ int check_embedded_connection(MYSQL *mysql, const char *db)
int2store(end, (ushort) mysql->charset->number);
end+= 2;
+ // There is no pluging compatibility in the embedded server
+ //end= strmake(end, "mysql_native_password", NAME_LEN) + 1;
+
+ /* the server does the same as the client */
+ mysql->server_capabilities= mysql->client_flag;
+
+ end= (char *) send_client_connect_attrs(mysql, (uchar *) end);
+
/* acl_authenticate() takes the data from thd->net->read_pos */
thd->net.read_pos= (uchar*)buf;
if (acl_authenticate(thd, 0, end - buf))
{
- x_free(thd->security_ctx->user);
+ my_free(thd->security_ctx->user);
goto err;
}
+ my_afree(buf);
return 0;
err:
- strmake_buf(net->last_error, thd->main_da.message());
+ strmake_buf(net->last_error, thd->get_stmt_da()->message());
memcpy(net->sqlstate,
- mysql_errno_to_sqlstate(thd->main_da.sql_errno()),
+ mysql_errno_to_sqlstate(thd->get_stmt_da()->sql_errno()),
sizeof(net->sqlstate)-1);
+ my_afree(buf);
return 1;
}
#endif
@@ -900,7 +947,7 @@ write_eof_packet(THD *thd, uint server_status, uint statement_warn_count)
is cleared between substatements, and mysqltest gets confused
*/
thd->cur_data->embedded_info->warning_count=
- (thd->spcont ? 0 : min(statement_warn_count, 65535));
+ (thd->spcont ? 0 : MY_MIN(statement_warn_count, 65535));
return FALSE;
}
@@ -922,8 +969,9 @@ int Protocol::begin_dataset()
if (!data)
return 1;
alloc= &data->alloc;
- init_alloc_root(alloc,8192,0); /* Assume rowlength < 8192 */
- alloc->min_malloc=sizeof(MYSQL_ROWS);
+ /* Assume rowlength < 8192 */
+ init_alloc_root(alloc, 8192, 0, MYF(0));
+ alloc->min_malloc= sizeof(MYSQL_ROWS);
return 0;
}
@@ -1020,7 +1068,7 @@ bool Protocol::send_result_set_metadata(List<Item> *list, uint flags)
thd_cs->mbmaxlen);
}
client_field->type= server_field.type;
- client_field->flags= server_field.flags;
+ client_field->flags= (uint16) server_field.flags;
client_field->decimals= server_field.decimals;
client_field->db_length= strlen(client_field->db);
client_field->table_length= strlen(client_field->table);
@@ -1059,7 +1107,7 @@ bool Protocol::send_result_set_metadata(List<Item> *list, uint flags)
if (flags & SEND_EOF)
write_eof_packet(thd, thd->server_status,
- thd->warning_info->statement_warn_count());
+ thd->get_stmt_da()->current_statement_warn_count());
DBUG_RETURN(prepare_for_send(list->elements));
err: