Commit fef31470 authored by unknown's avatar unknown

Merge mysql.com:/home/mydev/mysql-4.1-bug14400

into  mysql.com:/home/mydev/mysql-5.0-ateam


libmysqld/libmysqld.c:
  Auto merged
myisam/mi_rkey.c:
  Auto merged
mysql-test/r/func_sapdb.result:
  Auto merged
mysql-test/r/symlink.result:
  Auto merged
mysql-test/t/func_sapdb.test:
  Auto merged
scripts/make_binary_distribution.sh:
  Auto merged
sql/item_geofunc.h:
  Auto merged
sql/item_timefunc.cc:
  Auto merged
sql/sql_class.cc:
  Auto merged
sql/sql_parse.cc:
  Auto merged
libmysqld/lib_sql.cc:
  Manual merge
mysql-test/r/func_time.result:
  Manual merge
mysql-test/r/gis.result:
  Manual merge
mysql-test/t/func_time.test:
  Manual merge
mysql-test/t/gis.test:
  Manual merge
sql-common/client.c:
  Manual merge
parents 516fdb71 752b826e
......@@ -22,6 +22,7 @@ extern const char *not_error_sqlstate;
extern "C" {
#endif
extern CHARSET_INFO *default_client_charset_info;
MYSQL_FIELD *unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
my_bool default_value, uint server_capabilities);
void free_rows(MYSQL_DATA *cur);
......
......@@ -37,6 +37,8 @@ extern "C"
int check_user(THD *thd, enum enum_server_command command,
const char *passwd, uint passwd_len, const char *db,
bool check_count);
void thd_init_client_charset(THD *thd, uint cs_number);
C_MODE_START
#include <mysql.h>
......@@ -600,11 +602,14 @@ err:
return NULL;
}
#ifdef NO_EMBEDDED_ACCESS_CHECKS
int check_embedded_connection(MYSQL *mysql)
{
int result;
THD *thd= (THD*)mysql->thd;
thd_init_client_charset(thd, mysql->charset->number);
thd->update_charset();
Security_context *sctx= thd->security_ctx;
sctx->host_or_ip= sctx->host= (char*) my_localhost;
strmake(sctx->priv_host, (char*) my_localhost, MAX_HOSTNAME-1);
......@@ -623,6 +628,8 @@ int check_embedded_connection(MYSQL *mysql)
char scramble_buff[SCRAMBLE_LENGTH];
int passwd_len;
thd_init_client_charset(thd, mysql->charset->number);
thd->update_charset();
if (mysql->options.client_ip)
{
sctx->host= my_strdup(mysql->options.client_ip, MYF(0));
......
......@@ -90,49 +90,7 @@ static void end_server(MYSQL *mysql)
}
static int mysql_init_charset(MYSQL *mysql)
{
char charset_name_buff[16], *charset_name;
if ((charset_name=mysql->options.charset_name))
{
const char *save=charsets_dir;
if (mysql->options.charset_dir)
charsets_dir=mysql->options.charset_dir;
mysql->charset=get_charset_by_name(mysql->options.charset_name,
MYF(MY_WME));
charsets_dir=save;
}
else if (mysql->server_language)
{
charset_name=charset_name_buff;
sprintf(charset_name,"%d",mysql->server_language); /* In case of errors */
mysql->charset=get_charset((uint8) mysql->server_language, MYF(MY_WME));
}
else
mysql->charset=default_charset_info;
if (!mysql->charset)
{
mysql->net.last_errno=CR_CANT_READ_CHARSET;
strmov(mysql->net.sqlstate, "HY0000");
if (mysql->options.charset_dir)
sprintf(mysql->net.last_error,ER(mysql->net.last_errno),
charset_name ? charset_name : "unknown",
mysql->options.charset_dir);
else
{
char cs_dir_name[FN_REFLEN];
get_charsets_dir(cs_dir_name);
sprintf(mysql->net.last_error,ER(mysql->net.last_errno),
charset_name ? charset_name : "unknown",
cs_dir_name);
}
return mysql->net.last_errno;
}
return 0;
}
int mysql_init_character_set(MYSQL *mysql);
MYSQL * STDCALL
mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
......@@ -222,10 +180,10 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
init_embedded_mysql(mysql, client_flag, db_name);
if (check_embedded_connection(mysql))
if (mysql_init_character_set(mysql))
goto error;
if (mysql_init_charset(mysql))
if (check_embedded_connection(mysql))
goto error;
mysql->server_status= SERVER_STATUS_AUTOCOMMIT;
......
......@@ -68,6 +68,7 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len,
if (fast_mi_readinfo(info))
goto err;
if (share->concurrent_insert)
rw_rdlock(&share->key_root_lock[inx]);
......@@ -90,24 +91,35 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len,
case HA_KEY_ALG_BTREE:
default:
if (!_mi_search(info, keyinfo, key_buff, use_key_length,
myisam_read_vec[search_flag], info->s->state.key_root[inx]))
myisam_read_vec[search_flag], info->s->state.key_root[inx]))
{
while (info->lastpos >= info->state->data_file_length)
/*
If we are searching for an exact key (including the data pointer)
and this was added by an concurrent insert,
then the result is "key not found".
*/
if ((search_flag == HA_READ_KEY_EXACT) &&
(info->lastpos >= info->state->data_file_length))
{
my_errno= HA_ERR_KEY_NOT_FOUND;
info->lastpos= HA_OFFSET_ERROR;
}
else while (info->lastpos >= info->state->data_file_length)
{
/*
Skip rows that are inserted by other threads since we got a lock
Note that this can only happen if we are not searching after an
exact key, because the keys are sorted according to position
*/
if (_mi_search_next(info, keyinfo, info->lastkey,
info->lastkey_length,
myisam_readnext_vec[search_flag],
info->s->state.key_root[inx]))
info->lastkey_length,
myisam_readnext_vec[search_flag],
info->s->state.key_root[inx]))
break;
}
}
}
if (share->concurrent_insert)
rw_unlock(&share->key_root_lock[inx]);
......
......@@ -81,6 +81,12 @@ makedate(1997,1)
select makedate(1997,0);
makedate(1997,0)
NULL
select makedate(9999,365);
makedate(9999,365)
9999-12-31
select makedate(9999,366);
makedate(9999,366)
NULL
select addtime("1997-12-31 23:59:59.999999", "1 1:1:1.000002");
addtime("1997-12-31 23:59:59.999999", "1 1:1:1.000002")
1998-01-02 01:01:01.000001
......
......@@ -360,6 +360,12 @@ extract(SECOND FROM "1999-01-02 10:11:12")
select extract(MONTH FROM "2001-02-00");
extract(MONTH FROM "2001-02-00")
2
SELECT DATE_SUB(str_to_date('9999-12-31 00:01:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE);
DATE_SUB(str_to_date('9999-12-31 00:01:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE)
9999-12-31 00:00:00
SELECT DATE_ADD(str_to_date('9999-12-30 23:59:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE);
DATE_ADD(str_to_date('9999-12-30 23:59:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE)
9999-12-31 00:00:00
SELECT EXTRACT(QUARTER FROM '2004-01-15') AS quarter;
quarter
1
......
......@@ -671,6 +671,15 @@ POINT(10 10)
select (asWKT(geomfromwkb((0x010100000000000000000024400000000000002440))));
(asWKT(geomfromwkb((0x010100000000000000000024400000000000002440))))
POINT(10 10)
create table t1 (g GEOMETRY);
select * from t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def test t1 t1 g g 255 4294967295 0 Y 144 0 63
g
select asbinary(g) from t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def asbinary(g) 252 8192 0 Y 128 0 63
asbinary(g)
create table t1 (s1 geometry not null,s2 char(100));
create trigger t1_bu before update on t1 for each row set new.s1 = null;
insert into t1 values (null,null);
......
......@@ -74,18 +74,24 @@ t9 CREATE TABLE `t9` (
) ENGINE=MyISAM AUTO_INCREMENT=16725 DEFAULT CHARSET=latin1 DATA DIRECTORY='MYSQLTEST_VARDIR/tmp/' INDEX DIRECTORY='MYSQLTEST_VARDIR/run/'
drop database mysqltest;
create table t1 (a int not null) engine=myisam;
Warnings:
Warning 0 DATA DIRECTORY option ignored
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
alter table t1 add b int;
Warnings:
Warning 0 DATA DIRECTORY option ignored
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Warnings:
Warning 0 INDEX DIRECTORY option ignored
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
......
......@@ -43,6 +43,8 @@ select weekofyear("1997-11-30 23:59:59.000001");
select makedate(1997,1);
select makedate(1997,0);
select makedate(9999,365);
select makedate(9999,366);
#Time functions
......
......@@ -140,6 +140,10 @@ select extract(SECOND FROM "1999-01-02 10:11:12");
select extract(MONTH FROM "2001-02-00");
#
# MySQL Bugs: #12356: DATE_SUB or DATE_ADD incorrectly returns null
#
SELECT DATE_SUB(str_to_date('9999-12-31 00:01:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE);
SELECT DATE_ADD(str_to_date('9999-12-30 23:59:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE);
# test EXTRACT QUARTER (Bug #18100)
#
......
......@@ -377,6 +377,11 @@ select (asWKT(geomfromwkb((0x010100000000000000000024400000000000002440))));
# End of 4.1 tests
--enable_metadata
create table t1 (g GEOMETRY);
select * from t1;
select asbinary(g) from t1;
--disable_metadata
#
# Bug #12281 (Geometry: crash in trigger)
#
......
......@@ -178,11 +178,21 @@ if [ $BASE_SYSTEM = "netware" ] ; then
fi
copyfileto $BASE/lib \
libmysql/.libs/libmysqlclient.a libmysql/.libs/libmysqlclient.so* \
libmysql/libmysqlclient.* libmysql_r/.libs/libmysqlclient_r.a \
libmysql_r/.libs/libmysqlclient_r.so* libmysql_r/libmysqlclient_r.* \
libmysql/.libs/libmysqlclient.a \
libmysql/.libs/libmysqlclient.so* \
libmysql/.libs/libmysqlclient.sl* \
libmysql/.libs/libmysqlclient*.dylib \
libmysql/libmysqlclient.* \
libmysql_r/.libs/libmysqlclient_r.a \
libmysql_r/.libs/libmysqlclient_r.so* \
libmysql_r/.libs/libmysqlclient_r.sl* \
libmysql_r/.libs/libmysqlclient_r*.dylib \
libmysql_r/libmysqlclient_r.* \
libmysqld/.libs/libmysqld.a \
libmysqld/.libs/libmysqld.so* \
libmysqld/.libs/libmysqld.sl* \
libmysqld/.libs/libmysqld*.dylib \
mysys/libmysys.a strings/libmystrings.a dbug/libdbug.a \
libmysqld/.libs/libmysqld.a libmysqld/.libs/libmysqld.so* \
libmysqld/libmysqld.a netware/libmysql.imp \
zlib/.libs/libz.a
......
......@@ -130,6 +130,8 @@ static void mysql_close_free(MYSQL *mysql);
static int wait_for_data(my_socket fd, uint timeout);
#endif
CHARSET_INFO *default_client_charset_info = &my_charset_latin1;
/****************************************************************************
A modified version of connect(). my_connect() allows you to specify
......@@ -1431,7 +1433,7 @@ mysql_init(MYSQL *mysql)
bzero((char*) (mysql), sizeof(*(mysql)));
mysql->options.connect_timeout= CONNECT_TIMEOUT;
mysql->last_used_con= mysql->next_slave= mysql->master = mysql;
mysql->charset=default_charset_info;
mysql->charset=default_client_charset_info;
strmov(mysql->net.sqlstate, not_error_sqlstate);
/*
By default, we are a replication pivot. The caller must reset it
......@@ -1660,6 +1662,50 @@ static MYSQL_METHODS client_methods=
#endif
};
C_MODE_START
int mysql_init_character_set(MYSQL *mysql)
{
NET *net= &mysql->net;
/* Set character set */
if (!mysql->options.charset_name &&
!(mysql->options.charset_name=
my_strdup(MYSQL_DEFAULT_CHARSET_NAME,MYF(MY_WME))))
return 1;
{
const char *save= charsets_dir;
if (mysql->options.charset_dir)
charsets_dir=mysql->options.charset_dir;
mysql->charset=get_charset_by_csname(mysql->options.charset_name,
MY_CS_PRIMARY, MYF(MY_WME));
charsets_dir= save;
}
if (!mysql->charset)
{
net->last_errno=CR_CANT_READ_CHARSET;
strmov(net->sqlstate, unknown_sqlstate);
if (mysql->options.charset_dir)
my_snprintf(net->last_error, sizeof(net->last_error)-1,
ER(net->last_errno),
mysql->options.charset_name,
mysql->options.charset_dir);
else
{
char cs_dir_name[FN_REFLEN];
get_charsets_dir(cs_dir_name);
my_snprintf(net->last_error, sizeof(net->last_error)-1,
ER(net->last_errno),
mysql->options.charset_name,
cs_dir_name);
}
return 1;
}
return 0;
}
C_MODE_END
MYSQL *
CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
const char *passwd, const char *db,
......@@ -1997,42 +2043,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
goto error;
}
/* Set character set */
if (!mysql->options.charset_name &&
!(mysql->options.charset_name=
my_strdup(MYSQL_DEFAULT_CHARSET_NAME,MYF(MY_WME))))
goto error;
{
const char *save= charsets_dir;
if (mysql->options.charset_dir)
charsets_dir=mysql->options.charset_dir;
mysql->charset=get_charset_by_csname(mysql->options.charset_name,
MY_CS_PRIMARY, MYF(MY_WME));
charsets_dir= save;
}
if (!mysql->charset)
{
net->last_errno=CR_CANT_READ_CHARSET;
strmov(net->sqlstate, unknown_sqlstate);
if (mysql->options.charset_dir)
my_snprintf(net->last_error, sizeof(net->last_error)-1,
ER(net->last_errno),
mysql->options.charset_name,
mysql->options.charset_dir);
else
{
char cs_dir_name[FN_REFLEN];
get_charsets_dir(cs_dir_name);
my_snprintf(net->last_error, sizeof(net->last_error)-1,
ER(net->last_errno),
mysql->options.charset_name,
cs_dir_name);
}
if (mysql_init_character_set(mysql))
goto error;
}
/* Save connection information */
if (!my_multi_malloc(MYF(0),
......
......@@ -32,6 +32,7 @@ public:
Item_geometry_func(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {}
Item_geometry_func(List<Item> &list) :Item_str_func(list) {}
void fix_length_and_dec();
enum_field_types field_type() const { return MYSQL_TYPE_GEOMETRY; }
};
class Item_func_geometry_from_text: public Item_geometry_func
......@@ -67,6 +68,7 @@ public:
Item_func_as_wkb(Item *a): Item_geometry_func(a) {}
const char *func_name() const { return "aswkb"; }
String *val_str(String *);
enum_field_types field_type() const { return MYSQL_TYPE_BLOB; }
};
class Item_func_geometry_type: public Item_str_func
......
......@@ -27,6 +27,7 @@
/* TODO: Move month and days to language files */
/* Day number for Dec 31st, 9999 */
#define MAX_DAY_NUMBER 3652424L
static const char *month_names[]=
......@@ -408,7 +409,7 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
if (yearday > 0)
{
uint days= calc_daynr(l_time->year,1,1) + yearday - 1;
if (days <= 0 || days >= MAX_DAY_NUMBER)
if (days <= 0 || days > MAX_DAY_NUMBER)
goto err;
get_date_from_daynr(days,&l_time->year,&l_time->month,&l_time->day);
}
......@@ -454,7 +455,7 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
(weekday - 1);
}
if (days <= 0 || days >= MAX_DAY_NUMBER)
if (days <= 0 || days > MAX_DAY_NUMBER)
goto err;
get_date_from_daynr(days,&l_time->year,&l_time->month,&l_time->day);
}
......@@ -2035,7 +2036,7 @@ bool Item_date_add_interval::get_date(TIME *ltime, uint fuzzy_date)
ltime->hour= (uint) (sec/3600);
daynr= calc_daynr(ltime->year,ltime->month,1) + days;
/* Day number from year 0 to 9999-12-31 */
if ((ulonglong) daynr >= MAX_DAY_NUMBER)
if ((ulonglong) daynr > MAX_DAY_NUMBER)
goto invalid_date;
get_date_from_daynr((long) daynr, &ltime->year, &ltime->month,
&ltime->day);
......@@ -2046,7 +2047,7 @@ bool Item_date_add_interval::get_date(TIME *ltime, uint fuzzy_date)
period= (calc_daynr(ltime->year,ltime->month,ltime->day) +
sign * (long) interval.day);
/* Daynumber from year 0 to 9999-12-31 */
if ((ulong) period >= MAX_DAY_NUMBER)
if ((ulong) period > MAX_DAY_NUMBER)
goto invalid_date;
get_date_from_daynr((long) period,&ltime->year,&ltime->month,&ltime->day);
break;
......@@ -2570,7 +2571,7 @@ String *Item_func_makedate::val_str(String *str)
days= calc_daynr(yearnr,1,1) + daynr - 1;
/* Day number from year 0 to 9999-12-31 */
if (days >= 0 && days < MAX_DAY_NUMBER)
if (days >= 0 && days <= MAX_DAY_NUMBER)
{
null_value=0;
get_date_from_daynr(days,&l_time.year,&l_time.month,&l_time.day);
......
......@@ -930,7 +930,7 @@ bool select_send::send_data(List<Item> &items)
Protocol *protocol= thd->protocol;
char buff[MAX_FIELD_WIDTH];
String buffer(buff, sizeof(buff), &my_charset_bin);
DBUG_ENTER("send_data");
DBUG_ENTER("select_send::send_data");
protocol->prepare_for_resend();
Item *item;
......@@ -1140,7 +1140,7 @@ select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
bool select_export::send_data(List<Item> &items)
{
DBUG_ENTER("send_data");
DBUG_ENTER("select_export::send_data");
char buff[MAX_FIELD_WIDTH],null_buff[2],space[MAX_FIELD_WIDTH];
bool space_inited=0;
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
......@@ -1297,7 +1297,7 @@ bool select_dump::send_data(List<Item> &items)
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
tmp.length(0);
Item *item;
DBUG_ENTER("send_data");
DBUG_ENTER("select_dump::send_data");
if (unit->offset_limit_cnt)
{ // using limit offset,count
......
......@@ -775,6 +775,37 @@ static void reset_mqh(LEX_USER *lu, bool get_them= 0)
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
}
void thd_init_client_charset(THD *thd, uint cs_number)
{
/*
Use server character set and collation if
- opt_character_set_client_handshake is not set
- client has not specified a character set
- client character set is the same as the servers
- client character set doesn't exists in server
*/
if (!opt_character_set_client_handshake ||
!(thd->variables.character_set_client= get_charset(cs_number, MYF(0))) ||
!my_strcasecmp(&my_charset_latin1,
global_system_variables.character_set_client->name,
thd->variables.character_set_client->name))
{
thd->variables.character_set_client=
global_system_variables.character_set_client;
thd->variables.collation_connection=
global_system_variables.collation_connection;
thd->variables.character_set_results=
global_system_variables.character_set_results;
}
else
{
thd->variables.character_set_results=
thd->variables.collation_connection=
thd->variables.character_set_client;
}
}
/*
Perform handshake, authorize client and update thd ACL variables.
SYNOPSIS
......@@ -910,33 +941,7 @@ static int check_connection(THD *thd)
thd->client_capabilities|= ((ulong) uint2korr(net->read_pos+2)) << 16;
thd->max_client_packet_length= uint4korr(net->read_pos+4);
DBUG_PRINT("info", ("client_character_set: %d", (uint) net->read_pos[8]));
/*
Use server character set and collation if
- opt_character_set_client_handshake is not set
- client has not specified a character set
- client character set is the same as the servers
- client character set doesn't exists in server
*/
if (!opt_character_set_client_handshake ||
!(thd->variables.character_set_client=
get_charset((uint) net->read_pos[8], MYF(0))) ||
!my_strcasecmp(&my_charset_latin1,
global_system_variables.character_set_client->name,
thd->variables.character_set_client->name))
{
thd->variables.character_set_client=
global_system_variables.character_set_client;
thd->variables.collation_connection=
global_system_variables.collation_connection;
thd->variables.character_set_results=
global_system_variables.character_set_results;
}
else
{
thd->variables.character_set_results=
thd->variables.collation_connection=
thd->variables.character_set_client;
}
thd_init_client_charset(thd, (uint) net->read_pos[8]);
thd->update_charset();
end= (char*) net->read_pos+32;
}
......@@ -3033,6 +3038,12 @@ end_with_restore_list:
}
}
/* Don't yet allow changing of symlinks with ALTER TABLE */
if (lex->create_info.data_file_name)
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
"DATA DIRECTORY option ignored");
if (lex->create_info.index_file_name)
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
"INDEX DIRECTORY option ignored");
lex->create_info.data_file_name=lex->create_info.index_file_name=0;
/* ALTER TABLE ends previous transaction */
if (end_active_trans(thd))
......
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