Commit 20c3b2ff authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-6311 Add errors on CREATE SERVER

fail CREATE SERVER foreign data wrapper is "mysql"
and neither HOST nor SOCKET are specified.

Also default PORT to 3306 (again, only for foreign
data wrapper "mysql")
parent 97a913e3
......@@ -4,5 +4,22 @@
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(HOST 'localhost');
SELECT * FROM mysql.servers;
Server_name Host Db Username Password Port Socket Wrapper Owner
s1 localhost 0 mysql
s1 localhost 3306 mysql
DROP SERVER s1;
CREATE SERVER s1 FOREIGN DATA WRAPPER foo OPTIONS(USER 'bar');
SELECT * FROM mysql.servers;
Server_name Host Db Username Password Port Socket Wrapper Owner
s1 bar 0 foo
DROP SERVER s1;
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(USER 'bar');
ERROR HY000: Can't create federated table. Foreign data src error: either HOST or SOCKET must be set
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(HOST 'bar');
SELECT * FROM mysql.servers;
Server_name Host Db Username Password Port Socket Wrapper Owner
s1 bar 3306 mysql
DROP SERVER s1;
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(SOCKET 'bar');
SELECT * FROM mysql.servers;
Server_name Host Db Username Password Port Socket Wrapper Owner
s1 3306 bar mysql
DROP SERVER s1;
......@@ -246,7 +246,7 @@ drop user guest_usage@localhost;
drop user guest_select@localhost;
drop table federated.t1;
drop server 's1';
create server 's1' foreign data wrapper 'mysql' options (port 3306);
create server 's1' foreign data wrapper 'mysql' options (host 'foo');
alter server 's1' options
(host 'localhost', database '', user '',
password '', socket '', owner '', port 3306);
......
......@@ -292,7 +292,7 @@ drop server 's1';
#
# Bug#30671 - ALTER SERVER causes the server to crash
#
create server 's1' foreign data wrapper 'mysql' options (port 3306);
create server 's1' foreign data wrapper 'mysql' options (host 'foo');
alter server 's1' options
(host 'localhost', database '', user '',
password '', socket '', owner '', port 3306);
......
......@@ -2143,7 +2143,7 @@ DROP TABLE t1;
#Switch to Connection Slave
DROP TABLE t1;
End of 5.0 tests
create server 's1' foreign data wrapper 'mysql' options (port 3306);
create server 's1' foreign data wrapper 'mysql' options (host 'foo');
drop server 's1';
#
# Bug #32426: FEDERATED query returns corrupt results for ORDER BY on a TEXT
......
......@@ -1966,7 +1966,7 @@ connection default;
--echo End of 5.0 tests
create server 's1' foreign data wrapper 'mysql' options (port 3306);
create server 's1' foreign data wrapper 'mysql' options (host 'foo');
drop server 's1';
......
......@@ -6,3 +6,20 @@
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(HOST 'localhost');
SELECT * FROM mysql.servers;
DROP SERVER s1;
CREATE SERVER s1 FOREIGN DATA WRAPPER foo OPTIONS(USER 'bar');
SELECT * FROM mysql.servers;
DROP SERVER s1;
--error ER_CANT_CREATE_FEDERATED_TABLE
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(USER 'bar');
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(HOST 'bar');
SELECT * FROM mysql.servers;
DROP SERVER s1;
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(SOCKET 'bar');
SELECT * FROM mysql.servers;
DROP SERVER s1;
......@@ -1078,6 +1078,7 @@ static FOREIGN_SERVER *
prepare_server_struct_for_insert(LEX_SERVER_OPTIONS *server_options)
{
FOREIGN_SERVER *server;
ulong default_port= 0;
DBUG_ENTER("prepare_server_struct");
if (!(server= (FOREIGN_SERVER *)alloc_root(&mem, sizeof(FOREIGN_SERVER))))
......@@ -1095,6 +1096,18 @@ prepare_server_struct_for_insert(LEX_SERVER_OPTIONS *server_options)
SET_SERVER_OR_RETURN(server_name, NULL);
SET_SERVER_OR_RETURN(scheme, NULL);
/* scheme-specific checks */
if (!strcasecmp(server->scheme, "mysql"))
{
default_port= MYSQL_PORT;
if (!server_options->host.str && !server_options->socket.str)
{
my_error(ER_CANT_CREATE_FEDERATED_TABLE, MYF(0),
"either HOST or SOCKET must be set");
DBUG_RETURN(NULL);
}
}
SET_SERVER_OR_RETURN(host, "");
SET_SERVER_OR_RETURN(db, "");
SET_SERVER_OR_RETURN(username, "");
......@@ -1104,9 +1117,9 @@ prepare_server_struct_for_insert(LEX_SERVER_OPTIONS *server_options)
server->server_name_length= server_options->server_name.length;
/* set to 0 if not specified */
/* set to default_port if not specified */
server->port= server_options->port > -1 ?
server_options->port : 0;
server_options->port : default_port;
DBUG_RETURN(server);
}
......
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