Commit 29510745 authored by monty@hundin.mysql.fi's avatar monty@hundin.mysql.fi

Fixed bug with SELECT * ... UNION

parent 2e63f787
......@@ -37,7 +37,7 @@
#include <signal.h>
#include <violite.h>
const char *VER="11.15";
const char *VER="11.16";
/* Don't try to make a nice table if the data is too big */
#define MAX_COLUMN_LENGTH 1024
......
......@@ -1934,7 +1934,7 @@ static void init_var_hash()
static const char *embedded_server_args[] = {
"", /* XXX: argv[0] is program name - we should fix the API */
"--datadir=.",
"--language=/home/tim/my/4/sql/share/english",
"--language=/usr/local/mysql/share/mysql/english",
"--skip-innodb",
NullS
};
......
......@@ -224,7 +224,7 @@ typedef struct st_mysql_res {
/* Set up and bring down the server; to ensure that applications will
* work when linked against either the standard client library or the
* embedded server library, these functions should be called. */
void mysql_server_init(int argc, char **argv, const char **groups);
void mysql_server_init(int argc, const char **argv, const char **groups);
void mysql_server_end();
/* Set up and bring down a thread; these function should be called
......
......@@ -92,10 +92,12 @@ static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to,
const char *from, ulong length);
void mysql_server_init(int argc __attribute__((unused)),
char **argv __attribute__((unused)),
const char **groups __attribute__((unused))) {}
const char **argv __attribute__((unused)),
const char **groups __attribute__((unused)))
{}
void mysql_server_end() {}
void mysql_server_end()
{}
my_bool mysql_thread_init()
{
......
......@@ -203,17 +203,17 @@ check_connections1(THD *thd)
static int
check_connections2(THD * thd)
{
uint connect_errors=0;
uint pkt_len = 0;
NET * net = &thd -> net;
if (protocol_version>9) net -> return_errno=1;
uint connect_errors=0;
uint pkt_len = 0;
NET * net = &thd -> net;
if (protocol_version>9) net -> return_errno=1;
if ( (pkt_len=my_net_read(net)) == packet_error ||
pkt_len < MIN_HANDSHAKE_SIZE)
{
inc_host_errors(&thd->remote.sin_addr);
return(ER_HANDSHAKE_ERROR);
}
if ( (pkt_len=my_net_read(net)) == packet_error ||
pkt_len < MIN_HANDSHAKE_SIZE)
{
inc_host_errors(&thd->remote.sin_addr);
return(ER_HANDSHAKE_ERROR);
}
#ifdef _CUSTOMCONFIG_
#include "_cust_sql_parse.h"
......@@ -245,15 +245,6 @@ if (protocol_version>9) net -> return_errno=1;
}
static bool check_user(THD *thd,enum_server_command command, const char *user,
const char *passwd, const char *db, bool check_count)
{
......@@ -317,7 +308,7 @@ static bool check_user(THD *thd,enum_server_command command, const char *user,
extern "C"{
void mysql_server_init(int argc, char **argv, const char **groups)
void mysql_server_init(int argc, const char **argv, const char **groups)
{
char hostname[FN_REFLEN];
......@@ -331,19 +322,19 @@ void mysql_server_init(int argc, char **argv, const char **groups)
if (argc)
{
argcp = &argc;
argvp = &argv;
argvp = (char***) &argv;
}
else
{
argcp = &fake_argc;
argvp = (char ***)&fake_argv;
argvp = (char ***) &fake_argv;
}
if (!groups)
groups = fake_groups;
my_umask=0660; // Default umask for new files
my_umask_dir=0700; // Default umask for new directories
MY_INIT((char *)"mysqld"); // init my_sys library & pthreads
MY_INIT((char *)"mysqld_server"); // init my_sys library & pthreads
tzset(); // Set tzname
start_time=time((time_t*) 0);
......
......@@ -62,3 +62,7 @@ t2 ALL NULL NULL NULL NULL 4
pseudo
dekad
joce
pseudo pseudo1 same
dekad joce 1
joce testtt 1
joce tsestset 1
......@@ -25,15 +25,21 @@ select a,b from t1 into outfile 'skr' union select a,b from t2;
--error 1216
select a,b from t1 order by a union select a,b from t2;
--error 1217
create table t3 select a,b from t1 union select a from t2;
--error 1216
insert into t3 select a from t1 order by a union select a from t2;
--error 1217
create table t3 select a,b from t1 union select a from t2;
--error 1217
select a,b from t1 union select a from t2;
--error 1217
select * from t1 union select a from t2;
--error 1217
select a from t1 union select * from t2;
# Test CREATE, INSERT and REPLACE
create table t3 select a,b from t1 union all select a,b from t2;
insert into t3 select a,b from t1 union all select a,b from t2;
......@@ -54,4 +60,5 @@ CREATE TABLE t1 (
) TYPE=MyISAM;
INSERT INTO t1 (pseudo,pseudo1,same) VALUES ('joce', 'testtt', 1),('joce', 'tsestset', 1),('dekad', 'joce', 1);
SELECT pseudo FROM t1 WHERE pseudo1='joce' UNION SELECT pseudo FROM t1 WHERE pseudo='joce';
SELECT * FROM t1 WHERE pseudo1='joce' UNION SELECT * FROM t1 WHERE pseudo='joce';
drop table t1;
......@@ -35,7 +35,6 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
TMP_TABLE_PARAM tmp_table_param;
select_union *union_result;
int res;
uint elements;
DBUG_ENTER("mysql_union");
/* Fix tables--to-be-unioned-from list to point at opened tables */
......@@ -48,17 +47,9 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
}
/* Find last select part as it's here ORDER BY and GROUP BY is stored */
elements= lex->select_lex.item_list.elements;
for (last_sl= &lex->select_lex;
last_sl->next;
last_sl=last_sl->next)
{
if (elements != last_sl->next->item_list.elements)
{
my_error(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT,MYF(0));
return -1;
}
}
last_sl=last_sl->next) ;
if (lex->select_lex.options & SELECT_DESCRIBE)
{
......@@ -78,7 +69,7 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
result);
}
DBUG_RETURN(0);
}
}
order = (ORDER *) last_sl->order_list.first;
{
......@@ -93,8 +84,9 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
if (setup_fields(thd,first_table,item_list,0,0,1))
DBUG_RETURN(-1);
}
bzero((char*) &tmp_table_param,sizeof(tmp_table_param));
tmp_table_param.field_count=elements;
tmp_table_param.field_count=item_list.elements;
if (!(table=create_tmp_table(thd, &tmp_table_param, item_list,
(ORDER*) 0, !lex->union_option,
1, 0,
......@@ -188,8 +180,15 @@ select_union::~select_union()
{
}
int select_union::prepare(List<Item> &list)
{
if (list.elements != table->fields)
{
my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT,
ER(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT),MYF(0));
return -1;
}
return 0;
}
......
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