Commit 42bb0eaf authored by igor@rurik.mysql.com's avatar igor@rurik.mysql.com

Merge ibabaev@bk-internal.mysql.com:/home/bk/mysql-4.1

into rurik.mysql.com:/home/igor/mysql-4.1
parents 46536c3a 7994f27c
...@@ -789,3 +789,14 @@ field(0,NULL,1,0) field("",NULL,"bar","") field(0.0,NULL,1.0,0.0) ...@@ -789,3 +789,14 @@ field(0,NULL,1,0) field("",NULL,"bar","") field(0.0,NULL,1.0,0.0)
select field(NULL,1,2,NULL), field(NULL,1,2,0); select field(NULL,1,2,NULL), field(NULL,1,2,0);
field(NULL,1,2,NULL) field(NULL,1,2,0) field(NULL,1,2,NULL) field(NULL,1,2,0)
0 0 0 0
CREATE TABLE t1 (str varchar(20) PRIMARY KEY);
CREATE TABLE t2 (num int primary key);
INSERT INTO t1 VALUES ('notnumber');
INSERT INTO t2 VALUES (0), (1);
SELECT * FROM t1, t2 WHERE num=str;
str num
notnumber 0
SELECT * FROM t1, t2 WHERE num=substring(str from 1 for 6);
str num
notnumber 0
DROP TABLE t1,t2;
...@@ -527,3 +527,17 @@ DROP TABLE t1, t2; ...@@ -527,3 +527,17 @@ DROP TABLE t1, t2;
# #
select field(0,NULL,1,0), field("",NULL,"bar",""), field(0.0,NULL,1.0,0.0); select field(0,NULL,1,0), field("",NULL,"bar",""), field(0.0,NULL,1.0,0.0);
select field(NULL,1,2,NULL), field(NULL,1,2,0); select field(NULL,1,2,NULL), field(NULL,1,2,0);
#
# Bug #10124: access by integer index with a string key that is not a number
#
CREATE TABLE t1 (str varchar(20) PRIMARY KEY);
CREATE TABLE t2 (num int primary key);
INSERT INTO t1 VALUES ('notnumber');
INSERT INTO t2 VALUES (0), (1);
SELECT * FROM t1, t2 WHERE num=str;
SELECT * FROM t1, t2 WHERE num=substring(str from 1 for 6);
DROP TABLE t1,t2;
...@@ -2480,7 +2480,10 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) ...@@ -2480,7 +2480,10 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
if (error || if (error ||
(from+len != end && table->in_use->count_cuted_fields && (from+len != end && table->in_use->count_cuted_fields &&
!test_if_int(from,len,end,cs))) !test_if_int(from,len,end,cs)))
error= 1; {
if (error != 1)
error= 2;
}
#if SIZEOF_LONG > 4 #if SIZEOF_LONG > 4
if (unsigned_flag) if (unsigned_flag)
{ {
...@@ -2508,10 +2511,7 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) ...@@ -2508,10 +2511,7 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
} }
#endif #endif
if (error) if (error)
{
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
error= 1;
}
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first) if (table->db_low_byte_first)
{ {
...@@ -2776,9 +2776,12 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) ...@@ -2776,9 +2776,12 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs)
if (error || if (error ||
(from+len != end && table->in_use->count_cuted_fields && (from+len != end && table->in_use->count_cuted_fields &&
!test_if_int(from,len,end,cs))) !test_if_int(from,len,end,cs)))
{
if (error != 1)
{ {
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
error= 1; error= 2;
}
} }
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first) if (table->db_low_byte_first)
...@@ -2998,7 +3001,7 @@ int Field_float::store(const char *from,uint len,CHARSET_INFO *cs) ...@@ -2998,7 +3001,7 @@ int Field_float::store(const char *from,uint len,CHARSET_INFO *cs)
double nr= my_strntod(cs,(char*) from,len,&end,&error); double nr= my_strntod(cs,(char*) from,len,&end,&error);
if (error || ((uint) (end-from) != len && table->in_use->count_cuted_fields)) if (error || ((uint) (end-from) != len && table->in_use->count_cuted_fields))
{ {
error= 1; error= 2;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
} }
Field_float::store(nr); Field_float::store(nr);
...@@ -3284,7 +3287,7 @@ int Field_double::store(const char *from,uint len,CHARSET_INFO *cs) ...@@ -3284,7 +3287,7 @@ int Field_double::store(const char *from,uint len,CHARSET_INFO *cs)
double nr= my_strntod(cs,(char*) from, len, &end, &error); double nr= my_strntod(cs,(char*) from, len, &end, &error);
if (error || ((uint) (end-from) != len && table->in_use->count_cuted_fields)) if (error || ((uint) (end-from) != len && table->in_use->count_cuted_fields))
{ {
error= 1; error= 2;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
} }
Field_double::store(nr); Field_double::store(nr);
...@@ -3666,6 +3669,8 @@ int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs) ...@@ -3666,6 +3669,8 @@ int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs)
error= 1; error= 1;
} }
} }
if (error > 1)
error= 2;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first) if (table->db_low_byte_first)
...@@ -3954,7 +3959,7 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs) ...@@ -3954,7 +3959,7 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs)
if (str_to_time(from, len, &ltime, &error)) if (str_to_time(from, len, &ltime, &error))
{ {
tmp=0L; tmp=0L;
error= 1; error= 2;
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED,
from, len, MYSQL_TIMESTAMP_TIME, 1); from, len, MYSQL_TIMESTAMP_TIME, 1);
} }
...@@ -3976,6 +3981,8 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs) ...@@ -3976,6 +3981,8 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs)
from, len, MYSQL_TIMESTAMP_TIME, !error); from, len, MYSQL_TIMESTAMP_TIME, !error);
error= 1; error= 1;
} }
if (error > 1)
error= 2;
} }
if (ltime.neg) if (ltime.neg)
...@@ -4305,7 +4312,7 @@ int Field_date::store(const char *from, uint len,CHARSET_INFO *cs) ...@@ -4305,7 +4312,7 @@ int Field_date::store(const char *from, uint len,CHARSET_INFO *cs)
if (str_to_datetime(from, len, &l_time, 1, &error) <= MYSQL_TIMESTAMP_ERROR) if (str_to_datetime(from, len, &l_time, 1, &error) <= MYSQL_TIMESTAMP_ERROR)
{ {
tmp=0; tmp=0;
error= 1; error= 2;
} }
else else
tmp=(uint32) l_time.year*10000L + (uint32) (l_time.month*100+l_time.day); tmp=(uint32) l_time.year*10000L + (uint32) (l_time.month*100+l_time.day);
...@@ -4496,7 +4503,7 @@ int Field_newdate::store(const char *from,uint len,CHARSET_INFO *cs) ...@@ -4496,7 +4503,7 @@ int Field_newdate::store(const char *from,uint len,CHARSET_INFO *cs)
if (str_to_datetime(from, len, &l_time, 1, &error) <= MYSQL_TIMESTAMP_ERROR) if (str_to_datetime(from, len, &l_time, 1, &error) <= MYSQL_TIMESTAMP_ERROR)
{ {
tmp=0L; tmp=0L;
error= 1; error= 2;
} }
else else
tmp= l_time.day + l_time.month*32 + l_time.year*16*32; tmp= l_time.day + l_time.month*32 + l_time.year*16*32;
...@@ -4938,7 +4945,7 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs) ...@@ -4938,7 +4945,7 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs)
from= tmpstr.ptr(); from= tmpstr.ptr();
length= tmpstr.length(); length= tmpstr.length();
if (conv_errors) if (conv_errors)
error= 1; error= 2;
} }
/* /*
...@@ -4962,7 +4969,7 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs) ...@@ -4962,7 +4969,7 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs)
from+= field_charset->cset->scan(field_charset, from, end, from+= field_charset->cset->scan(field_charset, from, end,
MY_SEQ_SPACES); MY_SEQ_SPACES);
if (from != end) if (from != end)
error= 1; error= 2;
} }
if (error) if (error)
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
...@@ -5217,12 +5224,12 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs) ...@@ -5217,12 +5224,12 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs)
from= tmpstr.ptr(); from= tmpstr.ptr();
length= tmpstr.length(); length= tmpstr.length();
if (conv_errors) if (conv_errors)
error= 1; error= 2;
} }
if (length > field_length) if (length > field_length)
{ {
length=field_length; length=field_length;
error= 1; error= 2;
} }
if (error) if (error)
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
...@@ -5575,7 +5582,7 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs) ...@@ -5575,7 +5582,7 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
from= tmpstr.ptr(); from= tmpstr.ptr();
length= tmpstr.length(); length= tmpstr.length();
if (conv_errors) if (conv_errors)
error= 1; error= 2;
} }
copy_length= max_data_length(); copy_length= max_data_length();
...@@ -5590,7 +5597,7 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs) ...@@ -5590,7 +5597,7 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
copy_length, copy_length,
&well_formed_error); &well_formed_error);
if (copy_length < length) if (copy_length < length)
error= 1; error= 2;
Field_blob::store_length(copy_length); Field_blob::store_length(copy_length);
if (was_conversion || table->copy_blobs || copy_length <= MAX_FIELD_WIDTH) if (was_conversion || table->copy_blobs || copy_length <= MAX_FIELD_WIDTH)
{ // Must make a copy { // Must make a copy
......
...@@ -1361,7 +1361,7 @@ int subselect_uniquesubquery_engine::exec() ...@@ -1361,7 +1361,7 @@ int subselect_uniquesubquery_engine::exec()
TABLE *table= tab->table; TABLE *table= tab->table;
for (store_key **copy=tab->ref.key_copy ; *copy ; copy++) for (store_key **copy=tab->ref.key_copy ; *copy ; copy++)
{ {
if (tab->ref.key_err= (*copy)->copy()) if ((tab->ref.key_err= (*copy)->copy()) & 1)
{ {
table->status= STATUS_NOT_FOUND; table->status= STATUS_NOT_FOUND;
DBUG_RETURN(1); DBUG_RETURN(1);
...@@ -1414,7 +1414,7 @@ int subselect_indexsubquery_engine::exec() ...@@ -1414,7 +1414,7 @@ int subselect_indexsubquery_engine::exec()
for (store_key **copy=tab->ref.key_copy ; *copy ; copy++) for (store_key **copy=tab->ref.key_copy ; *copy ; copy++)
{ {
if (tab->ref.key_err= (*copy)->copy()) if ((tab->ref.key_err= (*copy)->copy()) & 1)
{ {
table->status= STATUS_NOT_FOUND; table->status= STATUS_NOT_FOUND;
DBUG_RETURN(1); DBUG_RETURN(1);
......
...@@ -8221,10 +8221,14 @@ cp_buffer_from_ref(THD *thd, TABLE_REF *ref) ...@@ -8221,10 +8221,14 @@ cp_buffer_from_ref(THD *thd, TABLE_REF *ref)
enum enum_check_fields save_count_cuted_fields= thd->count_cuted_fields; enum enum_check_fields save_count_cuted_fields= thd->count_cuted_fields;
thd->count_cuted_fields= CHECK_FIELD_IGNORE; thd->count_cuted_fields= CHECK_FIELD_IGNORE;
for (store_key **copy=ref->key_copy ; *copy ; copy++) for (store_key **copy=ref->key_copy ; *copy ; copy++)
if ((*copy)->copy()) {
int res;
if ((res= (*copy)->copy()))
{ {
thd->count_cuted_fields= save_count_cuted_fields; thd->count_cuted_fields= save_count_cuted_fields;
return 1; // Something went wrong if ((res= res & 1))
return res; // Something went wrong
}
} }
thd->count_cuted_fields= save_count_cuted_fields; thd->count_cuted_fields= save_count_cuted_fields;
return 0; return 0;
......
...@@ -356,6 +356,7 @@ class store_key :public Sql_alloc ...@@ -356,6 +356,7 @@ class store_key :public Sql_alloc
char *null_ptr; char *null_ptr;
char err; char err;
public: public:
enum store_key_result { STORE_KEY_OK, STORE_KEY_FATAL, STORE_KEY_CONV };
store_key(THD *thd, Field *field_arg, char *ptr, char *null, uint length) store_key(THD *thd, Field *field_arg, char *ptr, char *null, uint length)
:null_ptr(null),err(0) :null_ptr(null),err(0)
{ {
...@@ -371,7 +372,7 @@ class store_key :public Sql_alloc ...@@ -371,7 +372,7 @@ class store_key :public Sql_alloc
} }
} }
virtual ~store_key() {} /* Not actually needed */ virtual ~store_key() {} /* Not actually needed */
virtual bool copy()=0; virtual enum store_key_result copy()=0;
virtual const char *name() const=0; virtual const char *name() const=0;
}; };
...@@ -392,10 +393,10 @@ class store_key_field: public store_key ...@@ -392,10 +393,10 @@ class store_key_field: public store_key
copy_field.set(to_field,from_field,0); copy_field.set(to_field,from_field,0);
} }
} }
bool copy() enum store_key_result copy()
{ {
copy_field.do_copy(&copy_field); copy_field.do_copy(&copy_field);
return err != 0; return err != 0 ? STORE_KEY_FATAL : STORE_KEY_OK;
} }
const char *name() const { return field_name; } const char *name() const { return field_name; }
}; };
...@@ -412,9 +413,11 @@ public: ...@@ -412,9 +413,11 @@ public:
null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ? null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
&err : NullS, length), item(item_arg) &err : NullS, length), item(item_arg)
{} {}
bool copy() enum store_key_result copy()
{ {
return item->save_in_field(to_field, 1) || err != 0; int res= item->save_in_field(to_field, 1);
return (err != 0 || res > 2 ? STORE_KEY_FATAL : (store_key_result) res);
} }
const char *name() const { return "func"; } const char *name() const { return "func"; }
}; };
...@@ -432,15 +435,19 @@ public: ...@@ -432,15 +435,19 @@ public:
&err : NullS, length, item_arg), inited(0) &err : NullS, length, item_arg), inited(0)
{ {
} }
bool copy() enum store_key_result copy()
{ {
int res;
if (!inited) if (!inited)
{ {
inited=1; inited=1;
if (item->save_in_field(to_field, 1)) if ((res= item->save_in_field(to_field, 1)))
err= 1; {
if (!err)
err= res;
}
} }
return err != 0; return (err > 2 ? STORE_KEY_FATAL : (store_key_result) err);
} }
const char *name() const { return "const"; } const char *name() const { return "const"; }
}; };
......
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