Commit 97a913e3 authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: freshen up CREATE SERVER code

* pass LEX_STRING's from the parser, don't ignore the length only to strlen later
* init LEX::server_options only for SERVER commands, not for every statement
* don't put temporary values into a global persistent memroot

but really it's just scratching a surface
parent a50ddebb
......@@ -523,21 +523,6 @@ void lex_start(THD *thd)
lex->select_lex.nest_level_base= &lex->unit;
lex->allow_sum_func= 0;
lex->in_sum_func= NULL;
/*
ok, there must be a better solution for this, long-term
I tried "bzero" in the sql_yacc.yy code, but that for
some reason made the values zero, even if they were set
*/
lex->server_options.server_name= 0;
lex->server_options.server_name_length= 0;
lex->server_options.host= 0;
lex->server_options.db= 0;
lex->server_options.username= 0;
lex->server_options.password= 0;
lex->server_options.scheme= 0;
lex->server_options.socket= 0;
lex->server_options.owner= 0;
lex->server_options.port= -1;
lex->is_lex_started= TRUE;
lex->used_tables= 0;
......
......@@ -202,8 +202,13 @@ typedef Mem_root_array<ORDER*, true> Group_list_ptrs;
typedef struct st_lex_server_options
{
long port;
uint server_name_length;
char *server_name, *host, *db, *username, *password, *scheme, *socket, *owner;
LEX_STRING server_name, host, db, username, password, scheme, socket, owner;
void reset(LEX_STRING name)
{
server_name= name;
host= db= username= password= scheme= socket= owner= null_lex_str;
port= -1;
}
} LEX_SERVER_OPTIONS;
......
......@@ -5481,8 +5481,8 @@ create_sp_error:
if ((error= create_server(thd, &lex->server_options)))
{
DBUG_PRINT("info", ("problem creating server <%s>",
lex->server_options.server_name));
my_error(error, MYF(0), lex->server_options.server_name);
lex->server_options.server_name.str));
my_error(error, MYF(0), lex->server_options.server_name.str);
break;
}
my_ok(thd, 1);
......@@ -5500,8 +5500,8 @@ create_sp_error:
if ((error= alter_server(thd, &lex->server_options)))
{
DBUG_PRINT("info", ("problem altering server <%s>",
lex->server_options.server_name));
my_error(error, MYF(0), lex->server_options.server_name);
lex->server_options.server_name.str));
my_error(error, MYF(0), lex->server_options.server_name.str);
break;
}
my_ok(thd, 1);
......@@ -5521,8 +5521,8 @@ create_sp_error:
if (! lex->check_exists && err_code == ER_FOREIGN_SERVER_DOESNT_EXIST)
{
DBUG_PRINT("info", ("problem dropping server %s",
lex->server_options.server_name));
my_error(err_code, MYF(0), lex->server_options.server_name);
lex->server_options.server_name.str));
my_error(err_code, MYF(0), lex->server_options.server_name.str);
}
else
{
......
This diff is collapsed.
......@@ -26,10 +26,10 @@ typedef struct st_mem_root MEM_ROOT;
/* structs */
typedef struct st_federated_server
{
char *server_name;
const char *server_name;
long port;
uint server_name_length;
char *db, *scheme, *username, *password, *socket, *owner, *host, *sport;
const char *db, *scheme, *username, *password, *socket, *owner, *host, *sport;
} FOREIGN_SERVER;
/* cache handlers */
......
......@@ -2494,16 +2494,11 @@ create:
;
server_def:
SERVER_SYM
ident_or_text
FOREIGN DATA_SYM WRAPPER_SYM
ident_or_text
SERVER_SYM ident_or_text
{ Lex->server_options.reset($2); }
FOREIGN DATA_SYM WRAPPER_SYM ident_or_text
OPTIONS_SYM '(' server_options_list ')'
{
Lex->server_options.server_name= $2.str;
Lex->server_options.server_name_length= $2.length;
Lex->server_options.scheme= $6.str;
}
{ Lex->server_options.scheme= $7; }
;
server_options_list:
......@@ -2514,27 +2509,33 @@ server_options_list:
server_option:
USER TEXT_STRING_sys
{
Lex->server_options.username= $2.str;
MYSQL_YYABORT_UNLESS(Lex->server_options.username.str == 0);
Lex->server_options.username= $2;
}
| HOST_SYM TEXT_STRING_sys
{
Lex->server_options.host= $2.str;
MYSQL_YYABORT_UNLESS(Lex->server_options.host.str == 0);
Lex->server_options.host= $2;
}
| DATABASE TEXT_STRING_sys
{
Lex->server_options.db= $2.str;
MYSQL_YYABORT_UNLESS(Lex->server_options.db.str == 0);
Lex->server_options.db= $2;
}
| OWNER_SYM TEXT_STRING_sys
{
Lex->server_options.owner= $2.str;
MYSQL_YYABORT_UNLESS(Lex->server_options.owner.str == 0);
Lex->server_options.owner= $2;
}
| PASSWORD TEXT_STRING_sys
{
Lex->server_options.password= $2.str;
MYSQL_YYABORT_UNLESS(Lex->server_options.password.str == 0);
Lex->server_options.password= $2;
}
| SOCKET_SYM TEXT_STRING_sys
{
Lex->server_options.socket= $2.str;
MYSQL_YYABORT_UNLESS(Lex->server_options.socket.str == 0);
Lex->server_options.socket= $2;
}
| PORT_SYM ulong_num
{
......@@ -7243,13 +7244,12 @@ alter:
LEX *lex= Lex;
lex->alter_tablespace_info->ts_cmd_type= ALTER_ACCESS_MODE_TABLESPACE;
}
| ALTER SERVER_SYM ident_or_text OPTIONS_SYM '(' server_options_list ')'
| ALTER SERVER_SYM ident_or_text
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_ALTER_SERVER;
lex->server_options.server_name= $3.str;
lex->server_options.server_name_length= $3.length;
}
lex->server_options.reset($3);
} OPTIONS_SYM '(' server_options_list ')' { }
;
ev_alter_on_schedule_completion:
......@@ -11863,8 +11863,7 @@ drop:
{
Lex->sql_command = SQLCOM_DROP_SERVER;
Lex->check_exists= $3;
Lex->server_options.server_name= $4.str;
Lex->server_options.server_name_length= $4.length;
Lex->server_options.reset($4);
}
;
......
......@@ -626,17 +626,17 @@ int get_connection(MEM_ROOT *mem_root, FEDERATED_SHARE *share)
at the address of the share.
*/
share->server_name_length= server->server_name_length;
share->server_name= server->server_name;
share->username= server->username;
share->password= server->password;
share->database= server->db;
share->server_name= const_cast<char*>(server->server_name);
share->username= const_cast<char*>(server->username);
share->password= const_cast<char*>(server->password);
share->database= const_cast<char*>(server->db);
share->port= server->port > MIN_PORT && server->port < 65536 ?
(ushort) server->port : MYSQL_PORT;
share->hostname= server->host;
if (!(share->socket= server->socket) &&
share->hostname= const_cast<char*>(server->host);
if (!(share->socket= const_cast<char*>(server->socket)) &&
!strcmp(share->hostname, my_localhost))
share->socket= (char *) MYSQL_UNIX_ADDR;
share->scheme= server->scheme;
share->scheme= const_cast<char*>(server->scheme);
DBUG_PRINT("info", ("share->username %s", share->username));
DBUG_PRINT("info", ("share->password %s", share->password));
......
......@@ -566,17 +566,17 @@ int get_connection(MEM_ROOT *mem_root, FEDERATEDX_SHARE *share)
at the address of the share.
*/
share->server_name_length= server->server_name_length;
share->server_name= server->server_name;
share->username= server->username;
share->password= server->password;
share->database= server->db;
share->server_name= const_cast<char*>(server->server_name);
share->username= const_cast<char*>(server->username);
share->password= const_cast<char*>(server->password);
share->database= const_cast<char*>(server->db);
share->port= server->port > MIN_PORT && server->port < 65536 ?
(ushort) server->port : MYSQL_PORT;
share->hostname= server->host;
if (!(share->socket= server->socket) &&
share->hostname= const_cast<char*>(server->host);
if (!(share->socket= const_cast<char*>(server->socket)) &&
!strcmp(share->hostname, my_localhost))
share->socket= (char *) MYSQL_UNIX_ADDR;
share->scheme= server->scheme;
share->scheme= const_cast<char*>(server->scheme);
DBUG_PRINT("info", ("share->username: %s", share->username));
DBUG_PRINT("info", ("share->password: %s", share->password));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment