summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@narttu.mysql.fi>2002-08-30 12:40:40 +0300
committerunknown <monty@narttu.mysql.fi>2002-08-30 12:40:40 +0300
commit9421f1dae99e0f2d6100b31a3641b2cd0ad68e58 (patch)
tree1bb81fd601075133af9ee99bd7ac94baf5ffc46c /sql
parentcfc861537da2f256f11823b3a4997a033eec73dc (diff)
parent1895448e66b39542d58a77e705449b92414ff3f7 (diff)
downloadmariadb-git-9421f1dae99e0f2d6100b31a3641b2cd0ad68e58.tar.gz
Merge with 4.0.3
Some simple optimzations, more comments and indentation changes. Add ` around database in 'use database' in binary log. Moved max_error_count and max_warning_count to variables struct. Removed SHOW_WARNS_COUNT and SHOW_ERRORS_COUNT calls. Changed string functions to use character set of first string argument as default return characterset (Each string function can change the above assumption if needed) BitKeeper/etc/ignore: auto-union BitKeeper/etc/logging_ok: auto-union BUILD/SETUP.sh: Auto merged BitKeeper/deleted/.del-getopt.h~a9ae679fa84f395: Auto merged BitKeeper/deleted/.del-getvar.c~2a29ff383970fd31: Auto merged Docs/manual.texi: Auto merged SSL/cacert.pem: Auto merged SSL/client-cert.pem: Auto merged SSL/client-key.pem: Auto merged SSL/server-cert.pem: Auto merged SSL/server-key.pem: Auto merged client/mysqldump.c: Auto merged include/my_base.h: Auto merged include/my_sys.h: Auto merged include/mysql_com.h: Auto merged isam/isamlog.c: Auto merged isam/pack_isam.c: Auto merged libmysqld/lib_sql.cc: Auto merged myisam/ft_dump.c: Auto merged myisam/ft_parser.c: Auto merged myisam/ft_static.c: Auto merged myisam/ft_test1.c: Auto merged myisam/ft_update.c: Auto merged myisam/mi_create.c: Auto merged myisam/mi_key.c: Auto merged myisam/mi_open.c: Auto merged myisam/mi_static.c: Auto merged myisam/mi_test1.c: Auto merged myisam/mi_test2.c: Auto merged myisam/mi_test3.c: Auto merged myisam/mi_update.c: Auto merged myisam/mi_write.c: Auto merged myisam/myisamchk.c: Auto merged myisam/myisamdef.h: Auto merged myisam/myisamlog.c: Auto merged myisam/myisampack.c: Auto merged mysql-test/mysql-test-run.sh: Auto merged mysql-test/r/create.result: Auto merged mysql-test/r/fulltext.result: Auto merged mysql-test/r/func_math.result: Auto merged mysql-test/r/innodb.result: Auto merged mysql-test/r/merge.result: Auto merged mysql-test/r/myisam.result: Auto merged mysql-test/r/select.result: Auto merged mysql-test/r/select_found.result: Auto merged mysql-test/r/union.result: Auto merged mysql-test/t/create.test: Auto merged mysql-test/t/myisam.test: Auto merged mysql-test/t/select_found.test: Auto merged mysql-test/t/union.test: Auto merged mysys/default.c: Auto merged mysys/mf_iocache2.c: Auto merged mysys/my_error.c: Auto merged mysys/my_init.c: Auto merged scripts/mysql_config.sh: Auto merged sql/convert.cc: Auto merged sql/filesort.cc: Auto merged sql/gen_lex_hash.cc: Auto merged sql/ha_berkeley.cc: Auto merged sql/ha_innodb.cc: Auto merged sql/ha_myisam.cc: Auto merged sql/handler.cc: Auto merged sql/handler.h: Auto merged sql/hostname.cc: Auto merged sql/item.cc: Auto merged sql/item_sum.cc: Auto merged sql/item_sum.h: Auto merged sql/item_timefunc.cc: Auto merged sql/item_timefunc.h: Auto merged sql/key.cc: Auto merged sql/log.cc: Auto merged sql/net_pkg.cc: Auto merged sql/opt_range.cc: Auto merged sql/opt_range.h: Auto merged sql/opt_sum.cc: Auto merged sql/repl_failsafe.cc: Auto merged sql/slave.cc: Auto merged sql/sql_cache.cc: Auto merged sql/sql_db.cc: Auto merged sql/sql_handler.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_lex.cc: Auto merged sql/sql_load.cc: Auto merged sql/sql_string.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_test.cc: Auto merged sql/time.cc: Auto merged sql/unireg.cc: Auto merged strings/Makefile.am: Auto merged strings/ctype-latin1_de.c: Auto merged strings/ctype-tis620.c: Auto merged tools/mysqlmanager.c: Auto merged BitKeeper/deleted/.del-sslopt-case.h~224c80e75dad4997: merge with 4.0.3 BitKeeper/triggers/post-commit: merge with 4.0.3 client/mysql.cc: merge with 4.0.3 + simple optimsation client/mysqltest.c: merge with 4.0.3 (Indentation change) configure.in: merge with 4.0.3 extra/resolve_stack_dump.c: merge with 4.0.3 (Indentation change) include/Makefile.am: merge with 4.0.3 include/myisam.h: merge with 4.0.3 (Indentation change) include/mysql.h: merge with 4.0.3 (removed not used structure) include/mysqld_error.h: merge with 4.0.3 libmysql/Makefile.shared: merge with 4.0.3 libmysql/libmysql.c: merge with 4.0.3 (Indentation change) libmysqld/Makefile.am: merge with 4.0.3 myisam/ft_boolean_search.c: merge with 4.0.3 (Indentation change) myisam/ft_nlq_search.c: merge with 4.0.3 (Indentation change) myisam/mi_check.c: merge with 4.0.3 myisam/mi_search.c: merge with 4.0.3 myisam/mi_unique.c: merge with 4.0.3 mysys/Makefile.am: merge with 4.0.3 mysys/mf_casecnv.c: merge with 4.0.3 sql-bench/server-cfg.sh: Removed 8000 max row limit for Innodb sql/Makefile.am: merge with 4.0.3 sql/field.cc: Indentation cleanup Changed sprintf -> my_sprintf sql/field.h: merge with 4.0.3 sql/ha_heap.cc: merge with 4.0.3 (Indentation change) sql/item.h: merge with 4.0.3 (Indentation change) sql/item_cmpfunc.cc: merge with 4.0.3 sql/item_cmpfunc.h: Removed size_of() from items Indentation cleanup sql/item_create.cc: merge sql/item_create.h: merge sql/item_func.cc: Added comments Changed string functions to use character set of first string argument as default return characterset Simple optimizations. Removed return of uninitalized variable. sql/item_func.h: merge sql/item_strfunc.cc: merge with 4.0.3 (Indentation change) sql/item_strfunc.h: removed size_of() sql/item_uniq.h: removed size_of() sql/lex.h: merge with 4.0.3 (Indentation change) sql/log_event.cc: Add ` around database in 'use database' in binary log. sql/mysql_priv.h: merge with 4.0.3 sql/mysqld.cc: merge with 4.0.3 (Indentation change) sql/share/czech/errmsg.txt: merge sql/share/danish/errmsg.txt: merge sql/share/dutch/errmsg.txt: merge sql/share/english/errmsg.txt: merge sql/share/estonian/errmsg.txt: merge sql/share/french/errmsg.txt: merge sql/share/german/errmsg.txt: merge sql/share/greek/errmsg.txt: merge sql/share/hungarian/errmsg.txt: merge sql/share/italian/errmsg.txt: merge sql/share/japanese/errmsg.txt: merge sql/share/korean/errmsg.txt: merge sql/share/norwegian-ny/errmsg.txt: merge sql/share/norwegian/errmsg.txt: merge sql/share/polish/errmsg.txt: merge sql/share/portuguese/errmsg.txt: merge sql/share/romanian/errmsg.txt: merge sql/share/russian/errmsg.txt: merge sql/share/slovak/errmsg.txt: merge sql/share/spanish/errmsg.txt: merge sql/share/swedish/errmsg.txt: merge sql/share/ukrainian/errmsg.txt: merge sql/sql_acl.cc: merge with 4.0.3 sql/sql_base.cc: More comments Fixed bug in send_fields() when using convert sql/sql_class.cc: merge sql/sql_class.h: Merge with 4.0.3 Moved max_error_count and max_warning_count to variables struct. sql/sql_delete.cc: merge with 4.0.3 (Indentation change) sql/sql_lex.h: merge with 4.0.3 sql/sql_parse.cc: Removed SHOW_WARNS_COUNT and SHOW_ERRORS_COUNT. (Should be retrived from variables) sql/sql_select.cc: merge with 4.0.3 sql/sql_show.cc: merge with 4.0.3 sql/sql_union.cc: merge with 4.0.3 sql/sql_update.cc: merge with 4.0.3 sql/sql_yacc.yy: merge with 4.0.3 Indentation cleanup sql/structs.h: merge with 4.0.3 sql/table.cc: merge with 4.0.3 sql/table.h: merge with 4.0.3
Diffstat (limited to 'sql')
-rw-r--r--sql/Makefile.am13
-rw-r--r--sql/convert.cc12
-rw-r--r--sql/des_key_file.cc5
-rw-r--r--sql/field.cc734
-rw-r--r--sql/field.h236
-rw-r--r--sql/field_conv.cc21
-rw-r--r--sql/filesort.cc45
-rw-r--r--sql/gen_lex_hash.cc2
-rw-r--r--sql/gstream.cc137
-rw-r--r--sql/gstream.h61
-rw-r--r--sql/ha_berkeley.cc2
-rw-r--r--sql/ha_heap.cc204
-rw-r--r--sql/ha_innodb.cc10
-rw-r--r--sql/ha_myisam.cc22
-rw-r--r--sql/handler.cc2
-rw-r--r--sql/handler.h20
-rw-r--r--sql/hash_filo.h4
-rw-r--r--sql/hostname.cc4
-rw-r--r--sql/init.cc12
-rw-r--r--sql/item.cc305
-rw-r--r--sql/item.h85
-rw-r--r--sql/item_cmpfunc.cc160
-rw-r--r--sql/item_cmpfunc.h127
-rw-r--r--sql/item_create.cc170
-rw-r--r--sql/item_create.h40
-rw-r--r--sql/item_func.cc242
-rw-r--r--sql/item_func.h162
-rw-r--r--sql/item_strfunc.cc630
-rw-r--r--sql/item_strfunc.h289
-rw-r--r--sql/item_subselect.cc211
-rw-r--r--sql/item_subselect.h135
-rw-r--r--sql/item_sum.cc37
-rw-r--r--sql/item_sum.h8
-rw-r--r--sql/item_timefunc.cc44
-rw-r--r--sql/item_timefunc.h8
-rw-r--r--sql/item_uniq.h3
-rw-r--r--sql/key.cc5
-rw-r--r--sql/lex.h59
-rw-r--r--sql/log.cc4
-rw-r--r--sql/log_event.cc42
-rw-r--r--sql/mysql_priv.h58
-rw-r--r--sql/mysqld.cc13
-rw-r--r--sql/net_pkg.cc13
-rw-r--r--sql/opt_range.cc134
-rw-r--r--sql/opt_range.h9
-rw-r--r--sql/opt_sum.cc2
-rw-r--r--sql/procedure.cc3
-rw-r--r--sql/repl_failsafe.cc2
-rw-r--r--sql/share/charsets/Index11
-rw-r--r--sql/share/charsets/armscii8.conf93
-rw-r--r--sql/share/charsets/cp1251.conf19
-rw-r--r--sql/share/charsets/cp1257.conf18
-rw-r--r--sql/share/charsets/cp866.conf91
-rw-r--r--sql/share/charsets/croat.conf18
-rw-r--r--sql/share/charsets/danish.conf18
-rw-r--r--sql/share/charsets/dec8.conf18
-rw-r--r--sql/share/charsets/dos.conf21
-rw-r--r--sql/share/charsets/estonia.conf18
-rw-r--r--sql/share/charsets/german1.conf18
-rw-r--r--sql/share/charsets/greek.conf19
-rw-r--r--sql/share/charsets/hebrew.conf19
-rw-r--r--sql/share/charsets/hp8.conf19
-rw-r--r--sql/share/charsets/hungarian.conf18
-rw-r--r--sql/share/charsets/keybcs2.conf91
-rw-r--r--sql/share/charsets/koi8_ru.conf19
-rw-r--r--sql/share/charsets/koi8_ukr.conf18
-rw-r--r--sql/share/charsets/latin1.conf18
-rw-r--r--sql/share/charsets/latin2.conf18
-rw-r--r--sql/share/charsets/latin5.conf18
-rw-r--r--sql/share/charsets/latvian.conf95
-rw-r--r--sql/share/charsets/latvian1.conf94
-rw-r--r--sql/share/charsets/macce.conf91
-rw-r--r--sql/share/charsets/macroman.conf91
-rw-r--r--sql/share/charsets/pclatin2.conf91
-rw-r--r--sql/share/charsets/swe7.conf18
-rw-r--r--sql/share/charsets/usa7.conf18
-rw-r--r--sql/share/charsets/win1250.conf18
-rw-r--r--sql/share/charsets/win1251.conf18
-rw-r--r--sql/share/charsets/win1251ukr.conf18
-rw-r--r--sql/share/czech/errmsg.txt4
-rw-r--r--sql/share/danish/errmsg.txt4
-rw-r--r--sql/share/dutch/errmsg.txt4
-rw-r--r--sql/share/english/errmsg.txt4
-rw-r--r--sql/share/estonian/errmsg.txt4
-rw-r--r--sql/share/french/errmsg.txt4
-rw-r--r--sql/share/german/errmsg.txt4
-rw-r--r--sql/share/greek/errmsg.txt4
-rw-r--r--sql/share/hungarian/errmsg.txt4
-rw-r--r--sql/share/italian/errmsg.txt4
-rw-r--r--sql/share/japanese/errmsg.txt4
-rw-r--r--sql/share/korean/errmsg.txt4
-rw-r--r--sql/share/norwegian-ny/errmsg.txt4
-rw-r--r--sql/share/norwegian/errmsg.txt4
-rw-r--r--sql/share/polish/errmsg.txt4
-rw-r--r--sql/share/portuguese/errmsg.txt4
-rw-r--r--sql/share/romanian/errmsg.txt4
-rw-r--r--sql/share/russian/errmsg.txt4
-rw-r--r--sql/share/serbian/errmsg.txt240
-rw-r--r--sql/share/slovak/errmsg.txt4
-rw-r--r--sql/share/spanish/errmsg.txt4
-rw-r--r--sql/share/swedish/errmsg.txt4
-rw-r--r--sql/share/ukrainian/errmsg.txt4
-rw-r--r--sql/slave.cc13
-rw-r--r--sql/spatial.cc1442
-rw-r--r--sql/spatial.h476
-rw-r--r--sql/sql_acl.cc158
-rw-r--r--sql/sql_analyse.cc37
-rw-r--r--sql/sql_analyse.h5
-rw-r--r--sql/sql_base.cc260
-rw-r--r--sql/sql_cache.cc9
-rw-r--r--sql/sql_class.cc94
-rw-r--r--sql/sql_class.h160
-rw-r--r--sql/sql_db.cc285
-rw-r--r--sql/sql_delete.cc12
-rw-r--r--sql/sql_derived.cc126
-rw-r--r--sql/sql_error.cc219
-rw-r--r--sql/sql_handler.cc6
-rw-r--r--sql/sql_insert.cc16
-rw-r--r--sql/sql_lex.cc288
-rw-r--r--sql/sql_lex.h218
-rw-r--r--sql/sql_list.h123
-rw-r--r--sql/sql_load.cc4
-rw-r--r--sql/sql_parse.cc385
-rw-r--r--sql/sql_prepare.cc709
-rw-r--r--sql/sql_select.cc920
-rw-r--r--sql/sql_select.h81
-rw-r--r--sql/sql_show.cc315
-rw-r--r--sql/sql_string.cc120
-rw-r--r--sql/sql_string.h102
-rw-r--r--sql/sql_table.cc207
-rw-r--r--sql/sql_test.cc5
-rw-r--r--sql/sql_udf.cc7
-rw-r--r--sql/sql_union.cc136
-rw-r--r--sql/sql_update.cc16
-rw-r--r--sql/sql_yacc.yy536
-rw-r--r--sql/structs.h23
-rw-r--r--sql/table.cc137
-rw-r--r--sql/table.h30
-rw-r--r--sql/time.cc53
-rw-r--r--sql/unireg.cc67
140 files changed, 11708 insertions, 2118 deletions
diff --git a/sql/Makefile.am b/sql/Makefile.am
index 51c0a0f1fe8..5527c345078 100644
--- a/sql/Makefile.am
+++ b/sql/Makefile.am
@@ -46,7 +46,7 @@ mysqld_LDADD = @MYSQLD_EXTRA_LDFLAGS@ \
$(LDADD) $(CXXLDFLAGS) $(WRAPLIBS) @LIBDL@ @openssl_libs@
noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
item_strfunc.h item_timefunc.h item_uniq.h \
- item_create.h mysql_priv.h \
+ item_create.h item_subselect.h mysql_priv.h \
procedure.h sql_class.h sql_lex.h sql_list.h \
sql_manager.h sql_map.h sql_string.h unireg.h \
field.h handler.h \
@@ -56,17 +56,19 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
sql_select.h structs.h table.h sql_udf.h hash_filo.h\
lex.h lex_symbol.h sql_acl.h sql_crypt.h \
log_event.h mini_client.h sql_repl.h slave.h \
- stacktrace.h sql_sort.h sql_cache.h set_var.h
+ stacktrace.h sql_sort.h sql_cache.h set_var.h \
+ spatial.h gstream.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \
item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \
- thr_malloc.cc item_create.cc \
+ thr_malloc.cc item_create.cc item_subselect.cc\
field.cc key.cc sql_class.cc sql_list.cc \
net_serv.cc net_pkg.cc lock.cc my_lock.c \
sql_string.cc sql_manager.cc sql_map.cc \
mysqld.cc password.c hash_filo.cc hostname.cc \
convert.cc set_var.cc sql_parse.cc sql_yacc.yy \
sql_base.cc table.cc sql_select.cc sql_insert.cc \
+ sql_prepare.cc sql_error.cc \
sql_update.cc sql_delete.cc uniques.cc sql_do.cc \
procedure.cc item_uniq.cc sql_test.cc \
log.cc log_event.cc init.cc derror.cc sql_acl.cc \
@@ -79,9 +81,10 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \
sql_db.cc sql_table.cc sql_rename.cc sql_crypt.cc \
sql_load.cc mf_iocache.cc field_conv.cc sql_show.cc \
sql_udf.cc sql_analyse.cc sql_analyse.h sql_cache.cc \
- slave.cc sql_repl.cc sql_union.cc \
+ slave.cc sql_repl.cc sql_union.cc sql_derived.cc \
mini_client.cc mini_client_errors.c \
- stacktrace.c repl_failsafe.h repl_failsafe.cc sql_olap.cc
+ stacktrace.c repl_failsafe.h repl_failsafe.cc sql_olap.cc\
+ gstream.cc spatial.cc
gen_lex_hash_SOURCES = gen_lex_hash.cc
gen_lex_hash_LDADD = $(LDADD) $(CXXLDFLAGS)
diff --git a/sql/convert.cc b/sql/convert.cc
index e4ae13d1e07..13a6dfe0392 100644
--- a/sql/convert.cc
+++ b/sql/convert.cc
@@ -433,7 +433,17 @@ CONVERT *get_convert_set(const char *name)
{
for (CONVERT **ptr=convert_tables ; *ptr ; ptr++)
{
- if (!my_strcasecmp((*ptr)->name,name))
+ /*
+ BAR TODO: Monty's comments:
+ Why is this using system_charset_info ?
+ Isn't the character-set string given in the users default charset?
+ Please add a TODO note to the code that this has to be fixed when the user
+ will be able to cast strings to different character sets...
+ The current code will also not work if/when we introduce support for
+ 16 bit characters...
+ (I know that there is a LOT of changes to do if we ever want do this...)
+ */
+ if (!my_strcasecmp(system_charset_info,(*ptr)->name,name))
return (*ptr);
}
return 0;
diff --git a/sql/des_key_file.cc b/sql/des_key_file.cc
index d9c924b5a3c..ca92e38279b 100644
--- a/sql/des_key_file.cc
+++ b/sql/des_key_file.cc
@@ -70,9 +70,10 @@ load_des_key_file(const char *file_name)
{
offset=(char) (offset - '0');
// Remove newline and possible other control characters
- for (start=buf+1 ; isspace(*start) ; start++) ;
+ for (start=buf+1 ; my_isspace(system_charset_info, *start) ; start++) ;
end=buf+length;
- for (end=strend(buf) ; end > start && !isgraph(end[-1]) ; end--) ;
+ for (end=strend(buf) ;
+ end > start && !my_isgraph(system_charset_info, end[-1]) ; end--) ;
if (start != end)
{
diff --git a/sql/field.cc b/sql/field.cc
index 42ddcc3b9d2..c9669c93c04 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -79,7 +79,8 @@ bool test_if_int(const char *str,int length)
{
const char *end=str+length;
- while (str != end && isspace(*str)) // Allow start space
+ // Allow start space
+ while (str != end && my_isspace(system_charset_info,*str))
str++; /* purecov: inspected */
if (str != end && (*str == '-' || *str == '+'))
str++;
@@ -87,7 +88,7 @@ bool test_if_int(const char *str,int length)
return 0; // Error: Empty string
for (; str != end ; str++)
{
- if (!isdigit(*str))
+ if (!my_isdigit(system_charset_info,*str))
{
if (*str == '.')
{ // Allow '.0000'
@@ -95,10 +96,10 @@ bool test_if_int(const char *str,int length)
if (str == end)
return 1;
}
- if (!isspace(*str))
+ if (!my_isspace(system_charset_info,*str))
return 0;
for (str++ ; str != end ; str++)
- if (!isspace(*str))
+ if (!my_isspace(system_charset_info,*str))
return 0;
return 1;
}
@@ -109,7 +110,7 @@ bool test_if_int(const char *str,int length)
static bool test_if_real(const char *str,int length)
{
- while (length && isspace(*str))
+ while (length && my_isspace(system_charset_info,*str))
{ // Allow start space
length--; str++;
}
@@ -118,10 +119,10 @@ static bool test_if_real(const char *str,int length)
if (*str == '+' || *str == '-')
{
length--; str++;
- if (!length || !(isdigit(*str) || *str == '.'))
+ if (!length || !(my_isdigit(system_charset_info,*str) || *str == '.'))
return 0;
}
- while (length && isdigit(*str))
+ while (length && my_isdigit(system_charset_info,*str))
{
length--; str++;
}
@@ -130,7 +131,7 @@ static bool test_if_real(const char *str,int length)
if (*str == '.')
{
length--; str++;
- while (length && isdigit(*str))
+ while (length && my_isdigit(system_charset_info,*str))
{
length--; str++;
}
@@ -139,18 +140,19 @@ static bool test_if_real(const char *str,int length)
return 1;
if (*str == 'E' || *str == 'e')
{
- if (length < 3 || (str[1] != '+' && str[1] != '-') || !isdigit(str[2]))
+ if (length < 3 || (str[1] != '+' && str[1] != '-') ||
+ !my_isdigit(system_charset_info,str[2]))
return 0;
length-=3;
str+=3;
- while (length && isdigit(*str))
+ while (length && my_isdigit(system_charset_info,*str))
{
length--; str++;
}
}
for (; length ; length--, str++)
{ // Allow end space
- if (!isspace(*str))
+ if (!my_isspace(system_charset_info,*str))
return 0;
}
return 1;
@@ -174,6 +176,8 @@ Field::Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
field_length(length_arg),null_bit(null_bit_arg)
{
flags=null_ptr ? 0: NOT_NULL_FLAG;
+ comment.str= (char*) "";
+ comment.length=0;
}
uint Field::offset()
@@ -198,7 +202,7 @@ bool Field::send(THD *thd, String *packet)
if (is_null())
return net_store_null(packet);
char buff[MAX_FIELD_WIDTH];
- String tmp(buff,sizeof(buff));
+ String tmp(buff,sizeof(buff),default_charset_info);
val_str(&tmp,&tmp);
CONVERT *convert;
if ((convert=thd->variables.convert_set))
@@ -218,8 +222,11 @@ void Field_num::add_zerofill_and_unsigned(String &res) const
void Field_num::make_field(Send_field *field)
{
+ /* table_cache_key is not set for temp tables */
+ field->db_name=table->table_cache_key ? table->table_cache_key : "";
+ field->org_table_name=table->real_name;
field->table_name=table_name;
- field->col_name=field_name;
+ field->col_name=field->org_col_name=field_name;
field->length=field_length;
field->type=type();
field->flags=table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
@@ -229,8 +236,11 @@ void Field_num::make_field(Send_field *field)
void Field_str::make_field(Send_field *field)
{
+ /* table_cache_key is not set for temp tables */
+ field->db_name=table->table_cache_key ? table->table_cache_key : "";
+ field->org_table_name=table->real_name;
field->table_name=table_name;
- field->col_name=field_name;
+ field->col_name=field->org_col_name=field_name;
field->length=field_length;
field->type=type();
field->flags=table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
@@ -261,7 +271,7 @@ uint Field::fill_cache_field(CACHE_FIELD *copy)
bool Field::get_date(TIME *ltime,bool fuzzydate)
{
char buff[40];
- String tmp(buff,sizeof(buff)),tmp2,*res;
+ String tmp(buff,sizeof(buff),default_charset_info),tmp2,*res;
if (!(res=val_str(&tmp,&tmp2)) ||
str_to_TIME(res->ptr(),res->length(),ltime,fuzzydate) == TIMESTAMP_NONE)
return 1;
@@ -271,7 +281,7 @@ bool Field::get_date(TIME *ltime,bool fuzzydate)
bool Field::get_time(TIME *ltime)
{
char buff[40];
- String tmp(buff,sizeof(buff)),tmp2,*res;
+ String tmp(buff,sizeof(buff),default_charset_info),tmp2,*res;
if (!(res=val_str(&tmp,&tmp2)) ||
str_to_time(res->ptr(),res->length(),ltime))
return 1;
@@ -285,22 +295,23 @@ void Field::store_time(TIME *ltime,timestamp_type type)
char buff[25];
switch (type) {
case TIMESTAMP_NONE:
- store("",0); // Probably an error
+ store("",0,default_charset_info); // Probably an error
break;
case TIMESTAMP_DATE:
sprintf(buff,"%04d-%02d-%02d", ltime->year,ltime->month,ltime->day);
- store(buff,10);
+ store(buff,10,default_charset_info);
break;
case TIMESTAMP_FULL:
sprintf(buff,"%04d-%02d-%02d %02d:%02d:%02d",
ltime->year,ltime->month,ltime->day,
ltime->hour,ltime->minute,ltime->second);
- store(buff,19);
+ store(buff,19,default_charset_info);
break;
case TIMESTAMP_TIME:
- sprintf(buff, "%02d:%02d:%02d",
- ltime->hour,ltime->minute,ltime->second);
- store(buff,(uint) strlen(buff));
+ {
+ ulong length= my_sprintf(buff, (buff, "%02d:%02d:%02d",
+ ltime->hour,ltime->minute,ltime->second));
+ store(buff,(uint) length, default_charset_info);
break;
}
}
@@ -319,7 +330,7 @@ bool Field::optimize_range(uint idx)
void
Field_decimal::reset(void)
{
- Field_decimal::store("0",1);
+ Field_decimal::store("0",1,default_charset_info);
}
void Field_decimal::overflow(bool negative)
@@ -361,7 +372,7 @@ void Field_decimal::overflow(bool negative)
}
-void Field_decimal::store(const char *from,uint len)
+int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs)
{
const char *end= from+len;
/* The pointer where the field value starts (i.e., "where to write") */
@@ -372,13 +383,13 @@ void Field_decimal::store(const char *from,uint len)
specified), '+' or '-'
*/
char sign_char=0;
- /* The pointers where prezeros start and stop */
+ /* The pointers where prezeros start and stop */
const char *pre_zeros_from, *pre_zeros_end;
- /* The pointers where digits at the left of '.' start and stop */
+ /* The pointers where digits at the left of '.' start and stop */
const char *int_digits_from, *int_digits_end;
- /* The pointers where digits at the right of '.' start and stop */
+ /* The pointers where digits at the right of '.' start and stop */
const char *frac_digits_from, *frac_digits_end;
- /* The sign of the exponent : will be 0 (means no exponent), '+' or '-' */
+ /* The sign of the exponent : will be 0 (means no exponent), '+' or '-' */
char expo_sign_char=0;
uint exponent=0; // value of the exponent
/*
@@ -388,21 +399,21 @@ void Field_decimal::store(const char *from,uint len)
const char *int_digits_tail_from;
/* Number of 0 that need to be added at the left of the '.' (1E3: 3 zeros) */
uint int_digits_added_zeros;
- /*
- Pointer used when digits move from the right of the '.' to the left
- of the '.'
- */
+ /*
+ Pointer used when digits move from the right of the '.' to the left
+ of the '.'
+ */
const char *frac_digits_head_end;
- /* Number of 0 that need to be added at the right of the '.' (for 1E-3) */
+ /* Number of 0 that need to be added at the right of the '.' (for 1E-3) */
uint frac_digits_added_zeros;
char *pos,*tmp_left_pos,*tmp_right_pos;
/* Pointers that are used as limits (begin and end of the field buffer) */
char *left_wall,*right_wall;
char tmp_char;
- /*
- To remember if current_thd->cuted_fields has already been incremented,
- to do that only once
- */
+ /*
+ To remember if current_thd->cuted_fields has already been incremented,
+ to do that only once
+ */
bool is_cuted_fields_incr=0;
LINT_INIT(int_digits_tail_from);
@@ -412,16 +423,18 @@ void Field_decimal::store(const char *from,uint len)
/*
There are three steps in this function :
- - parse the input string
- - modify the position of digits around the decimal dot '.'
- according to the exponent value (if specified)
- - write the formatted number
+ - parse the input string
+ - modify the position of digits around the decimal dot '.'
+ according to the exponent value (if specified)
+ - write the formatted number
*/
if ((tmp_dec=dec))
tmp_dec++;
- for (; from !=end && isspace(*from); from++) ; // Read spaces
+ /* skip pre-space */
+ while (from != end && my_isspace(system_charset_info,*from))
+ from++;
if (from == end)
{
current_thd->cuted_fields++;
@@ -440,11 +453,11 @@ void Field_decimal::store(const char *from,uint len)
if (sign_char=='-')
{
Field_decimal::overflow(1);
- return;
+ return 1;
}
/*
- Defining this will not store "+" for unsigned decimal type even if
- it is passed in numeric string. This will make some tests to fail
+ Defining this will not store "+" for unsigned decimal type even if
+ it is passed in numeric string. This will make some tests to fail
*/
#ifdef DONT_ALLOW_UNSIGNED_PLUS
else
@@ -457,13 +470,13 @@ void Field_decimal::store(const char *from,uint len)
for (; from!=end && *from == '0'; from++) ; // Read prezeros
pre_zeros_end=int_digits_from=from;
/* Read non zero digits at the left of '.'*/
- for (; from!=end && isdigit(*from);from++) ;
+ for (; from != end && my_isdigit(system_charset_info, *from) ; from++) ;
int_digits_end=from;
if (from!=end && *from == '.') // Some '.' ?
from++;
frac_digits_from= from;
/* Read digits at the right of '.' */
- for (;from!=end && isdigit(*from); from++) ;
+ for (;from!=end && my_isdigit(system_charset_info, (*from); from++) ;
frac_digits_end=from;
// Some exponentiation symbol ?
if (from != end && (*from == 'e' || *from == 'E'))
@@ -479,7 +492,7 @@ void Field_decimal::store(const char *from,uint len)
(the value of the field will be overflow anyway, or 0 anyway,
it does not change anything if the exponent is 2^32 or more
*/
- for (;from!=end && isdigit(*from); from++)
+ for (;from!=end && my_isdigit(system_charset_info, (*from)); from++)
exponent=10*exponent+(*from-'0');
}
@@ -504,21 +517,21 @@ void Field_decimal::store(const char *from,uint len)
Now "move" digits around the decimal dot according to the exponent value,
and add necessary zeros.
Examples :
- - 1E+3 : needs 3 more zeros at the left of '.' (int_digits_added_zeros=3)
- - 1E-3 : '1' moves at the right of '.', and 2 more zeros are needed
- between '.' and '1'
+ - 1E+3 : needs 3 more zeros at the left of '.' (int_digits_added_zeros=3)
+ - 1E-3 : '1' moves at the right of '.', and 2 more zeros are needed
+ between '.' and '1'
- 1234.5E-3 : '234' moves at the right of '.'
- These moves are implemented with pointers which point at the begin
- and end of each moved segment. Examples :
+ These moves are implemented with pointers which point at the begin
+ and end of each moved segment. Examples :
- 1234.5E-3 : before the code below is executed, the int_digits part is
- from '1' to '4' and the frac_digits part from '5' to '5'. After the code
- below, the int_digits part is from '1' to '1', the frac_digits_head
- part is from '2' to '4', and the frac_digits part from '5' to '5'.
+ from '1' to '4' and the frac_digits part from '5' to '5'. After the code
+ below, the int_digits part is from '1' to '1', the frac_digits_head
+ part is from '2' to '4', and the frac_digits part from '5' to '5'.
- 1234.5E3 : before the code below is executed, the int_digits part is
- from '1' to '4' and the frac_digits part from '5' to '5'. After the code
- below, the int_digits part is from '1' to '4', the int_digits_tail
- part is from '5' to '5', the frac_digits part is empty, and
- int_digits_added_zeros=2 (to make 1234500).
+ from '1' to '4' and the frac_digits part from '5' to '5'. After the code
+ below, the int_digits part is from '1' to '4', the int_digits_tail
+ part is from '5' to '5', the frac_digits part is empty, and
+ int_digits_added_zeros=2 (to make 1234500).
*/
if (!expo_sign_char)
@@ -573,7 +586,7 @@ void Field_decimal::store(const char *from,uint len)
{
// too big number, change to max or min number
Field_decimal::overflow(sign_char == '-');
- return;
+ return 1;
}
/*
@@ -655,7 +668,7 @@ void Field_decimal::store(const char *from,uint len)
{
if (current_thd->count_cuted_fields && !is_cuted_fields_incr)
break; // Go on below to see if we lose non zero digits
- return;
+ return 0;
}
*pos++='0';
}
@@ -668,7 +681,7 @@ void Field_decimal::store(const char *from,uint len)
{
if (!is_cuted_fields_incr)
current_thd->cuted_fields++;
- return;
+ return 0;
}
continue;
}
@@ -685,7 +698,7 @@ void Field_decimal::store(const char *from,uint len)
{
if (!is_cuted_fields_incr)
current_thd->cuted_fields++;
- return;
+ return 0;
}
continue;
}
@@ -695,25 +708,26 @@ void Field_decimal::store(const char *from,uint len)
while (pos != right_wall)
*pos++='0'; // Fill with zeros at right of '.'
}
+ return 0;
}
-void Field_decimal::store(double nr)
+int Field_decimal::store(double nr)
{
if (unsigned_flag && nr < 0)
{
overflow(1);
- return;
+ return 1;
}
#ifdef HAVE_FINITE
if (!finite(nr)) // Handle infinity as special case
{
overflow(nr < 0.0);
- return;
+ return 1;
}
#endif
-
+
reg4 uint i,length;
char fyllchar,*to;
char buff[320];
@@ -728,30 +742,37 @@ void Field_decimal::store(double nr)
length=(uint) strlen(buff);
if (length > field_length)
+ {
overflow(nr < 0.0);
+ return 1;
+ }
else
{
to=ptr;
for (i=field_length-length ; i-- > 0 ;)
*to++ = fyllchar;
memcpy(to,buff,length);
+ return 0;
}
}
-void Field_decimal::store(longlong nr)
+int Field_decimal::store(longlong nr)
{
if (unsigned_flag && nr < 0)
{
overflow(1);
- return;
+ return 1;
}
char buff[22];
uint length=(uint) (longlong10_to_str(nr,buff,-10)-buff);
uint int_part=field_length- (dec ? dec+1 : 0);
if (length > int_part)
+ {
overflow(test(nr < 0L)); /* purecov: inspected */
+ return 1;
+ }
else
{
char fyllchar = zerofill ? (char) '0' : (char) ' ';
@@ -764,6 +785,7 @@ void Field_decimal::store(longlong nr)
to[length]='.';
bfill(to+length+1,dec,'0');
}
+ return 0;
}
}
@@ -797,7 +819,7 @@ String *Field_decimal::val_str(String *val_buffer __attribute__((unused)),
if (field_length < tmp_length) // Error in data
val_ptr->length(0);
else
- val_ptr->set((const char*) str,field_length-tmp_length);
+ val_ptr->set((const char*) str,field_length-tmp_length,default_charset_info);
return val_ptr;
}
@@ -814,8 +836,10 @@ int Field_decimal::cmp(const char *a_ptr,const char *b_ptr)
for (end=a_ptr+field_length;
a_ptr != end &&
(*a_ptr == *b_ptr ||
- ((isspace(*a_ptr) || *a_ptr == '+' || *a_ptr == '0') &&
- (isspace(*b_ptr) || *b_ptr == '+' || *b_ptr == '0')));
+ ((my_isspace(system_charset_info,*a_ptr) || *a_ptr == '+' ||
+ *a_ptr == '0') &&
+ (my_isspace(system_charset_info,*b_ptr) || *b_ptr == '+' ||
+ *b_ptr == '0')));
a_ptr++,b_ptr++)
{
if (*a_ptr == '-') // If both numbers are negative
@@ -842,8 +866,8 @@ void Field_decimal::sort_string(char *to,uint length)
char *str,*end;
for (str=ptr,end=ptr+length;
str != end &&
- ((isspace(*str) || *str == '+' || *str == '0')) ;
-
+ ((my_isspace(system_charset_info,*str) || *str == '+' ||
+ *str == '0')) ;
str++)
*to++=' ';
if (str == end)
@@ -854,7 +878,7 @@ void Field_decimal::sort_string(char *to,uint length)
*to++=1; // Smaller than any number
str++;
while (str != end)
- if (isdigit(*str))
+ if (my_isdigit(system_charset_info,*str))
*to++= (char) ('9' - *str++);
else
*to++= *str++;
@@ -862,6 +886,7 @@ void Field_decimal::sort_string(char *to,uint length)
else memcpy(to,str,(uint) (end-str));
}
+
void Field_decimal::sql_type(String &res) const
{
uint tmp=field_length;
@@ -878,10 +903,11 @@ void Field_decimal::sql_type(String &res) const
** tiny int
****************************************************************************/
-void Field_tiny::store(const char *from,uint len)
+int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs)
{
- String tmp_str(from,len);
+ String tmp_str(from,len,default_charset_info);
long tmp= strtol(tmp_str.c_ptr(),NULL,10);
+ int error= 0;
if (unsigned_flag)
{
@@ -889,14 +915,19 @@ void Field_tiny::store(const char *from,uint len)
{
tmp=0; /* purecov: inspected */
current_thd->cuted_fields++; /* purecov: inspected */
+ error= 1;
}
else if (tmp > 255)
{
tmp= 255;
current_thd->cuted_fields++;
+ error= 1;
}
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
+ {
current_thd->cuted_fields++;
+ error= 1;
+ }
}
else
{
@@ -904,21 +935,28 @@ void Field_tiny::store(const char *from,uint len)
{
tmp= -128;
current_thd->cuted_fields++;
+ error= 1;
}
else if (tmp >= 128)
{
tmp= 127;
current_thd->cuted_fields++;
+ error= 1;
}
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
+ {
current_thd->cuted_fields++;
+ error= 1;
+ }
}
ptr[0]= (char) tmp;
+ return error;
}
-void Field_tiny::store(double nr)
+int Field_tiny::store(double nr)
{
+ int error= 0;
nr=rint(nr);
if (unsigned_flag)
{
@@ -926,11 +964,13 @@ void Field_tiny::store(double nr)
{
*ptr=0;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > 255.0)
{
*ptr=(char) 255;
current_thd->cuted_fields++;
+ error= 1;
}
else
*ptr=(char) nr;
@@ -941,30 +981,36 @@ void Field_tiny::store(double nr)
{
*ptr= (char) -128;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > 127.0)
{
*ptr=127;
current_thd->cuted_fields++;
+ error= 1;
}
else
*ptr=(char) nr;
}
+ return error;
}
-void Field_tiny::store(longlong nr)
+int Field_tiny::store(longlong nr)
{
+ int error= 0;
if (unsigned_flag)
{
if (nr < 0L)
{
*ptr=0;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > 255L)
{
*ptr= (char) 255;
current_thd->cuted_fields++;
+ error= 1;
}
else
*ptr=(char) nr;
@@ -975,15 +1021,18 @@ void Field_tiny::store(longlong nr)
{
*ptr= (char) -128;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > 127L)
{
*ptr=127;
current_thd->cuted_fields++;
+ error= 1;
}
else
*ptr=(char) nr;
}
+ return error;
}
@@ -1049,24 +1098,30 @@ void Field_tiny::sql_type(String &res) const
// Note: Sometimes this should be fixed to use one strtol() to use
// len and check for garbage after number.
-void Field_short::store(const char *from,uint len)
+int Field_short::store(const char *from,uint len,CHARSET_INFO *cs)
{
- String tmp_str(from,len);
+ String tmp_str(from,len,default_charset_info);
long tmp= strtol(tmp_str.c_ptr(),NULL,10);
+ int error= 0;
if (unsigned_flag)
{
if (tmp < 0)
{
tmp=0;
current_thd->cuted_fields++;
+ error= 1;
}
else if (tmp > (uint16) ~0)
{
tmp=(uint16) ~0;
current_thd->cuted_fields++;
+ error= 1;
}
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
+ {
current_thd->cuted_fields++;
+ error= 1;
+ }
}
else
{
@@ -1074,14 +1129,19 @@ void Field_short::store(const char *from,uint len)
{
tmp= INT_MIN16;
current_thd->cuted_fields++;
+ error= 1;
}
else if (tmp > INT_MAX16)
{
tmp=INT_MAX16;
current_thd->cuted_fields++;
+ error= 1;
}
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
+ {
current_thd->cuted_fields++;
+ error= 1;
+ }
}
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
@@ -1091,11 +1151,13 @@ void Field_short::store(const char *from,uint len)
else
#endif
shortstore(ptr,(short) tmp);
+ return error;
}
-void Field_short::store(double nr)
+int Field_short::store(double nr)
{
+ int error= 0;
int16 res;
nr=rint(nr);
if (unsigned_flag)
@@ -1104,11 +1166,13 @@ void Field_short::store(double nr)
{
res=0;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > (double) (uint16) ~0)
{
res=(int16) (uint16) ~0;
current_thd->cuted_fields++;
+ error= 1;
}
else
res=(int16) (uint16) nr;
@@ -1119,11 +1183,13 @@ void Field_short::store(double nr)
{
res=INT_MIN16;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > (double) INT_MAX16)
{
res=INT_MAX16;
current_thd->cuted_fields++;
+ error= 1;
}
else
res=(int16) nr;
@@ -1136,10 +1202,12 @@ void Field_short::store(double nr)
else
#endif
shortstore(ptr,res);
+ return error;
}
-void Field_short::store(longlong nr)
+int Field_short::store(longlong nr)
{
+ int error= 0;
int16 res;
if (unsigned_flag)
{
@@ -1147,11 +1215,13 @@ void Field_short::store(longlong nr)
{
res=0;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > (longlong) (uint16) ~0)
{
res=(int16) (uint16) ~0;
current_thd->cuted_fields++;
+ error= 1;
}
else
res=(int16) (uint16) nr;
@@ -1162,11 +1232,13 @@ void Field_short::store(longlong nr)
{
res=INT_MIN16;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > INT_MAX16)
{
res=INT_MAX16;
current_thd->cuted_fields++;
+ error= 1;
}
else
res=(int16) nr;
@@ -1179,6 +1251,7 @@ void Field_short::store(longlong nr)
else
#endif
shortstore(ptr,res);
+ return error;
}
@@ -1289,10 +1362,11 @@ void Field_short::sql_type(String &res) const
// Note: Sometimes this should be fixed to use one strtol() to use
// len and check for garbage after number.
-void Field_medium::store(const char *from,uint len)
+int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs)
{
- String tmp_str(from,len);
+ String tmp_str(from,len,default_charset_info);
long tmp= strtol(tmp_str.c_ptr(),NULL,10);
+ int error= 0;
if (unsigned_flag)
{
@@ -1300,14 +1374,19 @@ void Field_medium::store(const char *from,uint len)
{
tmp=0;
current_thd->cuted_fields++;
+ error= 1;
}
else if (tmp >= (long) (1L << 24))
{
tmp=(long) (1L << 24)-1L;
current_thd->cuted_fields++;
+ error= 1;
}
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
+ {
current_thd->cuted_fields++;
+ error= 1;
+ }
}
else
{
@@ -1315,22 +1394,29 @@ void Field_medium::store(const char *from,uint len)
{
tmp= INT_MIN24;
current_thd->cuted_fields++;
+ error= 1;
}
else if (tmp > INT_MAX24)
{
tmp=INT_MAX24;
current_thd->cuted_fields++;
+ error= 1;
}
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
+ {
current_thd->cuted_fields++;
+ error= 1;
+ }
}
int3store(ptr,tmp);
+ return error;
}
-void Field_medium::store(double nr)
+int Field_medium::store(double nr)
{
+ int error= 0;
nr=rint(nr);
if (unsigned_flag)
{
@@ -1338,12 +1424,14 @@ void Field_medium::store(double nr)
{
int3store(ptr,0);
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr >= (double) (long) (1L << 24))
{
uint32 tmp=(uint32) (1L << 24)-1L;
int3store(ptr,tmp);
current_thd->cuted_fields++;
+ error= 1;
}
else
int3store(ptr,(uint32) nr);
@@ -1355,32 +1443,38 @@ void Field_medium::store(double nr)
long tmp=(long) INT_MIN24;
int3store(ptr,tmp);
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > (double) INT_MAX24)
{
long tmp=(long) INT_MAX24;
int3store(ptr,tmp);
current_thd->cuted_fields++;
+ error= 1;
}
else
int3store(ptr,(long) nr);
}
+ return error;
}
-void Field_medium::store(longlong nr)
+int Field_medium::store(longlong nr)
{
+ int error= 0;
if (unsigned_flag)
{
if (nr < 0L)
{
int3store(ptr,0);
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr >= (longlong) (long) (1L << 24))
{
long tmp=(long) (1L << 24)-1L;;
int3store(ptr,tmp);
current_thd->cuted_fields++;
+ error= 1;
}
else
int3store(ptr,(uint32) nr);
@@ -1392,16 +1486,19 @@ void Field_medium::store(longlong nr)
long tmp=(long) INT_MIN24;
int3store(ptr,tmp);
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > (longlong) INT_MAX24)
{
long tmp=(long) INT_MAX24;
int3store(ptr,tmp);
current_thd->cuted_fields++;
+ error= 1;
}
else
int3store(ptr,(long) nr);
}
+ return error;
}
@@ -1474,14 +1571,15 @@ void Field_medium::sql_type(String &res) const
// Note: Sometimes this should be fixed to use one strtol() to use
// len and check for garbage after number.
-void Field_long::store(const char *from,uint len)
+int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
{
- while (len && isspace(*from))
+ while (len && my_isspace(system_charset_info,*from))
{
len--; from++;
}
long tmp;
- String tmp_str(from,len);
+ int error= 0;
+ String tmp_str(from,len,default_charset_info);
errno=0;
if (unsigned_flag)
{
@@ -1489,6 +1587,7 @@ void Field_long::store(const char *from,uint len)
{
tmp=0; // Set negative to 0
errno=ERANGE;
+ error= 1;
}
else
tmp=(long) strtoul(tmp_str.c_ptr(),NULL,10);
@@ -1496,7 +1595,10 @@ void Field_long::store(const char *from,uint len)
else
tmp=strtol(tmp_str.c_ptr(),NULL,10);
if (errno || current_thd->count_cuted_fields && !test_if_int(from,len))
+ {
current_thd->cuted_fields++;
+ error= 1;
+ }
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
{
@@ -1505,11 +1607,13 @@ void Field_long::store(const char *from,uint len)
else
#endif
longstore(ptr,tmp);
+ return error;
}
-void Field_long::store(double nr)
+int Field_long::store(double nr)
{
+ int error= 0;
int32 res;
nr=rint(nr);
if (unsigned_flag)
@@ -1518,11 +1622,13 @@ void Field_long::store(double nr)
{
res=0;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > (double) (ulong) ~0L)
{
res=(int32) (uint32) ~0L;
current_thd->cuted_fields++;
+ error= 1;
}
else
res=(int32) (ulong) nr;
@@ -1533,11 +1639,13 @@ void Field_long::store(double nr)
{
res=(int32) INT_MIN32;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > (double) INT_MAX32)
{
res=(int32) INT_MAX32;
current_thd->cuted_fields++;
+ error= 1;
}
else
res=(int32) nr;
@@ -1550,11 +1658,13 @@ void Field_long::store(double nr)
else
#endif
longstore(ptr,res);
+ return error;
}
-void Field_long::store(longlong nr)
+int Field_long::store(longlong nr)
{
+ int error= 0;
int32 res;
if (unsigned_flag)
{
@@ -1562,11 +1672,13 @@ void Field_long::store(longlong nr)
{
res=0;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr >= (LL(1) << 32))
{
res=(int32) (uint32) ~0L;
current_thd->cuted_fields++;
+ error= 1;
}
else
res=(int32) (uint32) nr;
@@ -1577,11 +1689,13 @@ void Field_long::store(longlong nr)
{
res=(int32) INT_MIN32;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > (longlong) INT_MAX32)
{
res=(int32) INT_MAX32;
current_thd->cuted_fields++;
+ error= 1;
}
else
res=(int32) nr;
@@ -1594,6 +1708,7 @@ void Field_long::store(longlong nr)
else
#endif
longstore(ptr,res);
+ return error;
}
@@ -1702,14 +1817,15 @@ void Field_long::sql_type(String &res) const
** longlong int
****************************************************************************/
-void Field_longlong::store(const char *from,uint len)
+int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs)
{
- while (len && isspace(*from))
+ while (len && my_isspace(system_charset_info,*from))
{ // For easy error check
len--; from++;
}
longlong tmp;
- String tmp_str(from,len);
+ String tmp_str(from,len,default_charset_info);
+ int error= 0;
errno=0;
if (unsigned_flag)
{
@@ -1717,6 +1833,7 @@ void Field_longlong::store(const char *from,uint len)
{
tmp=0; // Set negative to 0
errno=ERANGE;
+ error= 1;
}
else
tmp=(longlong) strtoull(tmp_str.c_ptr(),NULL,10);
@@ -1724,7 +1841,10 @@ void Field_longlong::store(const char *from,uint len)
else
tmp=strtoll(tmp_str.c_ptr(),NULL,10);
if (errno || current_thd->count_cuted_fields && !test_if_int(from,len))
+ {
current_thd->cuted_fields++;
+ error= 1;
+ }
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
{
@@ -1733,11 +1853,13 @@ void Field_longlong::store(const char *from,uint len)
else
#endif
longlongstore(ptr,tmp);
+ return error;
}
-void Field_longlong::store(double nr)
+int Field_longlong::store(double nr)
{
+ int error= 0;
longlong res;
nr=rint(nr);
if (unsigned_flag)
@@ -1746,11 +1868,13 @@ void Field_longlong::store(double nr)
{
res=0;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr >= (double) ~ (ulonglong) 0)
{
res= ~(longlong) 0;
current_thd->cuted_fields++;
+ error= 1;
}
else
res=(longlong) (ulonglong) nr;
@@ -1761,11 +1885,13 @@ void Field_longlong::store(double nr)
{
res=(longlong) LONGLONG_MIN;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr >= (double) LONGLONG_MAX)
{
res=(longlong) LONGLONG_MAX;
current_thd->cuted_fields++;
+ error= 1;
}
else
res=(longlong) nr;
@@ -1778,10 +1904,11 @@ void Field_longlong::store(double nr)
else
#endif
longlongstore(ptr,res);
+ return error;
}
-void Field_longlong::store(longlong nr)
+int Field_longlong::store(longlong nr)
{
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
@@ -1791,6 +1918,7 @@ void Field_longlong::store(longlong nr)
else
#endif
longlongstore(ptr,nr);
+ return 0;
}
@@ -1909,35 +2037,43 @@ void Field_longlong::sql_type(String &res) const
** single precision float
****************************************************************************/
-void Field_float::store(const char *from,uint len)
+int Field_float::store(const char *from,uint len,CHARSET_INFO *cs)
{
- String tmp_str(from,len);
+ String tmp_str(from,len,default_charset_info);
errno=0;
Field_float::store(atof(tmp_str.c_ptr()));
if (errno || current_thd->count_cuted_fields && !test_if_real(from,len))
+ {
current_thd->cuted_fields++;
+ return 1;
+ }
+ return (errno) ? 1 : 0;
}
-void Field_float::store(double nr)
+int Field_float::store(double nr)
{
float j;
+ int error= 0;
if (dec < NOT_FIXED_DEC)
nr=floor(nr*log_10[dec]+0.5)/log_10[dec]; // To fixed point
if (unsigned_flag && nr < 0)
{
current_thd->cuted_fields++;
nr=0;
+ error= 1;
}
if (nr < -FLT_MAX)
{
j= -FLT_MAX;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr > FLT_MAX)
{
j=FLT_MAX;
current_thd->cuted_fields++;
+ error= 1;
}
else
j= (float) nr;
@@ -1949,16 +2085,19 @@ void Field_float::store(double nr)
else
#endif
memcpy_fixed(ptr,(byte*) &j,sizeof(j));
+ return error;
}
-void Field_float::store(longlong nr)
+int Field_float::store(longlong nr)
{
+ int error= 0;
float j= (float) nr;
if (unsigned_flag && j < 0)
{
current_thd->cuted_fields++;
j=0;
+ error= 1;
}
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
@@ -1968,6 +2107,7 @@ void Field_float::store(longlong nr)
else
#endif
memcpy_fixed(ptr,(byte*) &j,sizeof(j));
+ return error;
}
@@ -2159,17 +2299,22 @@ void Field_float::sql_type(String &res) const
** double precision floating point numbers
****************************************************************************/
-void Field_double::store(const char *from,uint len)
+int Field_double::store(const char *from,uint len,CHARSET_INFO *cs)
{
- String tmp_str(from,len);
+ String tmp_str(from,len,default_charset_info);
errno=0;
+ int error= 0;
double j= atof(tmp_str.c_ptr());
if (errno || current_thd->count_cuted_fields && !test_if_real(from,len))
+ {
current_thd->cuted_fields++;
+ error= 1;
+ }
if (unsigned_flag && j < 0)
{
current_thd->cuted_fields++;
j=0;
+ error= 1;
}
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
@@ -2179,17 +2324,20 @@ void Field_double::store(const char *from,uint len)
else
#endif
doublestore(ptr,j);
+ return error;
}
-void Field_double::store(double nr)
+int Field_double::store(double nr)
{
+ int error= 0;
if (dec < NOT_FIXED_DEC)
nr=floor(nr*log_10[dec]+0.5)/log_10[dec]; // To fixed point
if (unsigned_flag && nr < 0)
{
current_thd->cuted_fields++;
nr=0;
+ error= 1;
}
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
@@ -2199,15 +2347,18 @@ void Field_double::store(double nr)
else
#endif
doublestore(ptr,nr);
+ return error;
}
-void Field_double::store(longlong nr)
+int Field_double::store(longlong nr)
{
double j= (double) nr;
+ int error= 0;
if (unsigned_flag && j < 0)
{
current_thd->cuted_fields++;
+ error= 1;
j=0;
}
#ifdef WORDS_BIGENDIAN
@@ -2218,6 +2369,7 @@ void Field_double::store(longlong nr)
else
#endif
doublestore(ptr,j);
+ return error;
}
@@ -2415,7 +2567,7 @@ Field_timestamp::Field_timestamp(char *ptr_arg, uint32 len_arg,
}
-void Field_timestamp::store(const char *from,uint len)
+int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs)
{
long tmp=(long) str_to_timestamp(from,len);
#ifdef WORDS_BIGENDIAN
@@ -2426,6 +2578,7 @@ void Field_timestamp::store(const char *from,uint len)
else
#endif
longstore(ptr,tmp);
+ return 0;
}
void Field_timestamp::fill_and_store(char *from,uint len)
@@ -2457,14 +2610,17 @@ void Field_timestamp::fill_and_store(char *from,uint len)
}
-void Field_timestamp::store(double nr)
+int Field_timestamp::store(double nr)
{
+ int error= 0;
if (nr < 0 || nr > 99991231235959.0)
{
- nr=0; // Avoid overflow on buff
+ nr= 0; // Avoid overflow on buff
current_thd->cuted_fields++;
+ error= 1;
}
- Field_timestamp::store((longlong) rint(nr));
+ error|= Field_timestamp::store((longlong) rint(nr));
+ return error;
}
@@ -2505,7 +2661,7 @@ static longlong fix_datetime(longlong nr)
}
-void Field_timestamp::store(longlong nr)
+int Field_timestamp::store(longlong nr)
{
TIME l_time;
time_t timestamp;
@@ -2533,6 +2689,7 @@ void Field_timestamp::store(longlong nr)
else
#endif
longstore(ptr,(uint32) timestamp);
+ return 0;
}
@@ -2754,12 +2911,16 @@ void Field_timestamp::set_time()
** Stored as a 3 byte unsigned int
****************************************************************************/
-void Field_time::store(const char *from,uint len)
+int Field_time::store(const char *from,uint len,CHARSET_INFO *cs)
{
TIME ltime;
long tmp;
+ int error= 0;
if (str_to_time(from,len,&ltime))
+ {
tmp=0L;
+ error= 1;
+ }
else
{
if (ltime.month)
@@ -2769,26 +2930,31 @@ void Field_time::store(const char *from,uint len)
{
tmp=8385959;
current_thd->cuted_fields++;
+ error= 1;
}
}
if (ltime.neg)
tmp= -tmp;
- Field_time::store((longlong) tmp);
+ error |= Field_time::store((longlong) tmp);
+ return error;
}
-void Field_time::store(double nr)
+int Field_time::store(double nr)
{
long tmp;
+ int error= 0;
if (nr > 8385959.0)
{
tmp=8385959L;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr < -8385959.0)
{
tmp= -8385959L;
current_thd->cuted_fields++;
+ error= 1;
}
else
{
@@ -2799,24 +2965,29 @@ void Field_time::store(double nr)
{
tmp=0;
current_thd->cuted_fields++;
+ error= 1;
}
}
int3store(ptr,tmp);
+ return error;
}
-void Field_time::store(longlong nr)
+int Field_time::store(longlong nr)
{
long tmp;
+ int error= 0;
if (nr > (longlong) 8385959L)
{
tmp=8385959L;
current_thd->cuted_fields++;
+ error= 1;
}
else if (nr < (longlong) -8385959L)
{
tmp= -8385959L;
current_thd->cuted_fields++;
+ error= 1;
}
else
{
@@ -2825,9 +2996,11 @@ void Field_time::store(longlong nr)
{
tmp=0;
current_thd->cuted_fields++;
+ error= 1;
}
}
int3store(ptr,tmp);
+ return error;
}
@@ -2894,7 +3067,7 @@ void Field_time::sort_string(char *to,uint length __attribute__((unused)))
void Field_time::sql_type(String &res) const
{
- res.set("time",4);
+ res.set("time",4,default_charset_info);
}
/****************************************************************************
@@ -2903,16 +3076,16 @@ void Field_time::sql_type(String &res) const
** Can handle 2 byte or 4 byte years!
****************************************************************************/
-void Field_year::store(const char *from, uint len)
+int Field_year::store(const char *from, uint len,CHARSET_INFO *cs)
{
- String tmp_str(from,len);
+ String tmp_str(from,len,default_charset_info);
long nr= strtol(tmp_str.c_ptr(),NULL,10);
if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155)
{
*ptr=0;
current_thd->cuted_fields++;
- return;
+ return 1;
}
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
current_thd->cuted_fields++;
@@ -2924,23 +3097,27 @@ void Field_year::store(const char *from, uint len)
nr-= 1900;
}
*ptr= (char) (unsigned char) nr;
+ return 0;
}
-void Field_year::store(double nr)
+int Field_year::store(double nr)
{
if (nr < 0.0 || nr >= 2155.0)
- Field_year::store((longlong) -1);
+ {
+ (void) Field_year::store((longlong) -1);
+ return 1;
+ }
else
- Field_year::store((longlong) nr);
+ return Field_year::store((longlong) nr);
}
-void Field_year::store(longlong nr)
+int Field_year::store(longlong nr)
{
if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155)
{
*ptr=0;
current_thd->cuted_fields++;
- return;
+ return 1;
}
if (nr != 0 || field_length != 4) // 0000 -> 0; 00 -> 2000
{
@@ -2950,6 +3127,7 @@ void Field_year::store(longlong nr)
nr-= 1900;
}
*ptr= (char) (unsigned char) nr;
+ return 0;
}
@@ -2992,12 +3170,16 @@ void Field_year::sql_type(String &res) const
** Stored as a 4 byte unsigned int
****************************************************************************/
-void Field_date::store(const char *from, uint len)
+int Field_date::store(const char *from, uint len,CHARSET_INFO *cs)
{
TIME l_time;
uint32 tmp;
+ int error= 0;
if (str_to_TIME(from,len,&l_time,1) == TIMESTAMP_NONE)
+ {
tmp=0;
+ error= 1;
+ }
else
tmp=(uint32) l_time.year*10000L + (uint32) (l_time.month*100+l_time.day);
#ifdef WORDS_BIGENDIAN
@@ -3008,18 +3190,21 @@ void Field_date::store(const char *from, uint len)
else
#endif
longstore(ptr,tmp);
+ return error;
}
-void Field_date::store(double nr)
+int Field_date::store(double nr)
{
long tmp;
+ int error= 0;
if (nr >= 19000000000000.0 && nr <= 99991231235959.0)
nr=floor(nr/1000000.0); // Timestamp to date
if (nr < 0.0 || nr > 99991231.0)
{
tmp=0L;
current_thd->cuted_fields++;
+ error= 1;
}
else
tmp=(long) rint(nr);
@@ -3031,18 +3216,21 @@ void Field_date::store(double nr)
else
#endif
longstore(ptr,tmp);
+ return error;
}
-void Field_date::store(longlong nr)
+int Field_date::store(longlong nr)
{
long tmp;
+ int error= 0;
if (nr >= LL(19000000000000) && nr < LL(99991231235959))
nr=nr/LL(1000000); // Timestamp to date
if (nr < 0 || nr > LL(99991231))
{
tmp=0L;
current_thd->cuted_fields++;
+ error= 1;
}
else
tmp=(long) nr;
@@ -3054,6 +3242,7 @@ void Field_date::store(longlong nr)
else
#endif
longstore(ptr,tmp);
+ return error;
}
@@ -3140,7 +3329,7 @@ void Field_date::sort_string(char *to,uint length __attribute__((unused)))
void Field_date::sql_type(String &res) const
{
- res.set("date",4);
+ res.set("date",4,default_charset_info);
}
/****************************************************************************
@@ -3149,35 +3338,45 @@ void Field_date::sql_type(String &res) const
** In number context: YYYYMMDD
****************************************************************************/
-void Field_newdate::store(const char *from,uint len)
+int Field_newdate::store(const char *from,uint len,CHARSET_INFO *cs)
{
TIME l_time;
long tmp;
+ int error= 0;
if (str_to_TIME(from,len,&l_time,1) == TIMESTAMP_NONE)
+ {
tmp=0L;
+ error= 1;
+ }
else
tmp= l_time.day + l_time.month*32 + l_time.year*16*32;
int3store(ptr,tmp);
+ return error;
}
-void Field_newdate::store(double nr)
+int Field_newdate::store(double nr)
{
if (nr < 0.0 || nr > 99991231235959.0)
- Field_newdate::store((longlong) -1);
+ {
+ (void) Field_newdate::store((longlong) -1);
+ return 1;
+ }
else
- Field_newdate::store((longlong) rint(nr));
+ return Field_newdate::store((longlong) rint(nr));
}
-void Field_newdate::store(longlong nr)
+int Field_newdate::store(longlong nr)
{
int32 tmp;
+ int error= 0;
if (nr >= LL(100000000) && nr <= LL(99991231235959))
nr=nr/LL(1000000); // Timestamp to date
if (nr < 0L || nr > 99991231L)
{
tmp=0;
current_thd->cuted_fields++;
+ error= 1;
}
else
{
@@ -3195,11 +3394,13 @@ void Field_newdate::store(longlong nr)
{
tmp=0L; // Don't allow date to change
current_thd->cuted_fields++;
+ error= 1;
}
else
tmp= day + month*32 + (tmp/10000)*16*32;
}
int3store(ptr,(int32) tmp);
+ return error;
}
void Field_newdate::store_time(TIME *ltime,timestamp_type type)
@@ -3291,7 +3492,7 @@ void Field_newdate::sort_string(char *to,uint length __attribute__((unused)))
void Field_newdate::sql_type(String &res) const
{
- res.set("date",4);
+ res.set("date",4,default_charset_info);
}
@@ -3302,7 +3503,7 @@ void Field_newdate::sql_type(String &res) const
** Stored as a 8 byte unsigned int. Should sometimes be change to a 6 byte int.
****************************************************************************/
-void Field_datetime::store(const char *from,uint len)
+int Field_datetime::store(const char *from,uint len,CHARSET_INFO *cs)
{
longlong tmp=str_to_datetime(from,len,1);
#ifdef WORDS_BIGENDIAN
@@ -3313,26 +3514,32 @@ void Field_datetime::store(const char *from,uint len)
else
#endif
longlongstore(ptr,tmp);
+ return 0;
}
-void Field_datetime::store(double nr)
+int Field_datetime::store(double nr)
{
+ int error= 0;
if (nr < 0.0 || nr > 99991231235959.0)
{
nr=0.0;
current_thd->cuted_fields++;
+ error= 1;
}
- Field_datetime::store((longlong) rint(nr));
+ error |= Field_datetime::store((longlong) rint(nr));
+ return error;
}
-void Field_datetime::store(longlong nr)
+int Field_datetime::store(longlong nr)
{
+ int error= 0;
if (nr < 0 || nr > LL(99991231235959))
{
nr=0;
current_thd->cuted_fields++;
+ error= 1;
}
else
nr=fix_datetime(nr);
@@ -3344,6 +3551,7 @@ void Field_datetime::store(longlong nr)
else
#endif
longlongstore(ptr,nr);
+ return error;
}
void Field_datetime::store_time(TIME *ltime,timestamp_type type)
@@ -3508,7 +3716,7 @@ void Field_datetime::sort_string(char *to,uint length __attribute__((unused)))
void Field_datetime::sql_type(String &res) const
{
- res.set("datetime",8);
+ res.set("datetime",8,default_charset_info);
}
/****************************************************************************
@@ -3518,8 +3726,10 @@ void Field_datetime::sql_type(String &res) const
/* Copy a string and fill with space */
-void Field_string::store(const char *from,uint length)
+int Field_string::store(const char *from,uint length,CHARSET_INFO *cs)
{
+ field_charset=cs;
+ int error= 0;
#ifdef USE_TIS620
if (!binary_flag) {
ThNormalize((uchar *)ptr, field_length, (uchar *)from, length);
@@ -3542,33 +3752,35 @@ void Field_string::store(const char *from,uint length)
const char *end=from+length;
for (from+=field_length ; from != end ; from++)
{
- if (!isspace(*from))
+ if (!my_isspace(field_charset,*from))
{
current_thd->cuted_fields++;
+ error=1;
break;
}
}
}
}
#endif /* USE_TIS620 */
+ return error;
}
-void Field_string::store(double nr)
+int Field_string::store(double nr)
{
char buff[MAX_FIELD_WIDTH],*end;
int width=min(field_length,DBL_DIG+5);
sprintf(buff,"%-*.*g",width,max(width-5,0),nr);
end=strcend(buff,' ');
- Field_string::store(buff,(uint) (end - buff));
+ return Field_string::store(buff,(uint) (end - buff), default_charset_info);
}
-void Field_string::store(longlong nr)
+int Field_string::store(longlong nr)
{
char buff[22];
char *end=longlong10_to_str(nr,buff,-10);
- Field_string::store(buff,(uint) (end-buff));
+ return Field_string::store(buff,(uint) (end-buff), default_charset_info);
}
@@ -3603,7 +3815,7 @@ String *Field_string::val_str(String *val_buffer __attribute__((unused)),
#endif
while (end > ptr && end[-1] == ' ')
end--;
- val_ptr->set((const char*) ptr,(uint) (end - ptr));
+ val_ptr->set((const char*) ptr,(uint) (end - ptr),field_charset);
return val_ptr;
}
@@ -3613,7 +3825,7 @@ int Field_string::cmp(const char *a_ptr, const char *b_ptr)
if (binary_flag)
return memcmp(a_ptr,b_ptr,field_length);
else
- return my_sortcmp(a_ptr,b_ptr,field_length);
+ return my_sortcmp(field_charset,a_ptr,b_ptr,field_length);
}
void Field_string::sort_string(char *to,uint length)
@@ -3623,17 +3835,17 @@ void Field_string::sort_string(char *to,uint length)
else
{
#ifdef USE_STRCOLL
- if (use_strcoll(default_charset_info)) {
- uint tmp=my_strnxfrm(default_charset_info,
- (unsigned char *)to, (unsigned char *) ptr,
- length, field_length);
+ if (use_strcoll(field_charset)) {
+ uint tmp=my_strnxfrm(field_charset,
+ (unsigned char *)to, length,
+ (unsigned char *) ptr, field_length);
if (tmp < length)
bzero(to + tmp, length - tmp);
}
else
#endif
for (char *from=ptr,*end=ptr+length ; from != end ;)
- *to++=(char) my_sort_order[(uint) (uchar) *from++];
+ *to++=(char) field_charset->sort_order[(uint) (uchar) *from++];
}
}
@@ -3648,6 +3860,11 @@ void Field_string::sql_type(String &res) const
res.length((uint) strlen(res.ptr()));
if (binary_flag)
res.append(" binary");
+ else
+ {
+ res.append(" character set ");
+ res.append(field_charset->name);
+ }
}
@@ -3682,7 +3899,7 @@ int Field_string::pack_cmp(const char *a, const char *b, uint length)
int cmp= memcmp(a,b,min(a_length,b_length));
return cmp ? cmp : (int) (a_length - b_length);
}
- return my_sortncmp(a,a_length, b,b_length);
+ return my_sortncmp(field_charset, a,a_length, b,b_length);
}
@@ -3699,7 +3916,7 @@ int Field_string::pack_cmp(const char *b, uint length)
int cmp= memcmp(ptr,b,min(a_length,b_length));
return cmp ? cmp : (int) (a_length - b_length);
}
- return my_sortncmp(ptr,a_length, b, b_length);
+ return my_sortncmp(field_charset, ptr,a_length, b, b_length);
}
@@ -3722,8 +3939,10 @@ uint Field_string::max_packed_col_length(uint max_length)
****************************************************************************/
-void Field_varstring::store(const char *from,uint length)
+int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs)
{
+ int error= 0;
+ field_charset=cs;
#ifdef USE_TIS620
if (!binary_flag)
{
@@ -3739,27 +3958,29 @@ void Field_varstring::store(const char *from,uint length)
length=field_length;
memcpy(ptr+2,from,field_length);
current_thd->cuted_fields++;
+ error= 1;
}
#endif /* USE_TIS620 */
int2store(ptr,length);
+ return error;
}
-void Field_varstring::store(double nr)
+int Field_varstring::store(double nr)
{
char buff[MAX_FIELD_WIDTH],*end;
int width=min(field_length,DBL_DIG+5);
sprintf(buff,"%-*.*g",width,max(width-5,0),nr);
end=strcend(buff,' ');
- Field_varstring::store(buff,(uint) (end - buff));
+ return Field_varstring::store(buff,(uint) (end - buff), default_charset_info);
}
-void Field_varstring::store(longlong nr)
+int Field_varstring::store(longlong nr)
{
char buff[22];
char *end=longlong10_to_str(nr,buff,-10);
- Field_varstring::store(buff,(uint) (end-buff));
+ return Field_varstring::store(buff,(uint) (end-buff), default_charset_info);
}
@@ -3791,7 +4012,7 @@ String *Field_varstring::val_str(String *val_buffer __attribute__((unused)),
String *val_ptr)
{
uint length=uint2korr(ptr);
- val_ptr->set((const char*) ptr+2,length);
+ val_ptr->set((const char*) ptr+2,length,field_charset);
return val_ptr;
}
@@ -3804,7 +4025,7 @@ int Field_varstring::cmp(const char *a_ptr, const char *b_ptr)
if (binary_flag)
diff=memcmp(a_ptr+2,b_ptr+2,min(a_length,b_length));
else
- diff=my_sortcmp(a_ptr+2,b_ptr+2,min(a_length,b_length));
+ diff=my_sortcmp(field_charset, a_ptr+2,b_ptr+2,min(a_length,b_length));
return diff ? diff : (int) (a_length - b_length);
}
@@ -3816,10 +4037,10 @@ void Field_varstring::sort_string(char *to,uint length)
else
{
#ifdef USE_STRCOLL
- if (use_strcoll(default_charset_info))
- tot_length=my_strnxfrm(default_charset_info,
- (unsigned char *) to, (unsigned char *)ptr+2,
- length, tot_length);
+ if (use_strcoll(field_charset))
+ tot_length=my_strnxfrm(field_charset,
+ (unsigned char *) to, length,
+ (unsigned char *)ptr+2, tot_length);
else
{
#endif
@@ -3827,7 +4048,7 @@ void Field_varstring::sort_string(char *to,uint length)
if (tot_length > length)
tot_length=length;
for (char *from=ptr+2,*end=from+tot_length ; from != end ;)
- *tmp++=(char) my_sort_order[(uint) (uchar) *from++];
+ *tmp++=(char) field_charset->sort_order[(uint) (uchar) *from++];
#ifdef USE_STRCOLL
}
#endif
@@ -3843,6 +4064,11 @@ void Field_varstring::sql_type(String &res) const
res.length((uint) strlen(res.ptr()));
if (binary_flag)
res.append(" binary");
+ else
+ {
+ res.append(" character set ");
+ res.append(field_charset->name);
+ }
}
char *Field_varstring::pack(char *to, const char *from, uint max_length)
@@ -3898,7 +4124,7 @@ int Field_varstring::pack_cmp(const char *a, const char *b, uint key_length)
int cmp= memcmp(a,b,min(a_length,b_length));
return cmp ? cmp : (int) (a_length - b_length);
}
- return my_sortncmp(a,a_length, b,b_length);
+ return my_sortncmp(field_charset, a,a_length, b,b_length);
}
int Field_varstring::pack_cmp(const char *b, uint key_length)
@@ -3919,7 +4145,7 @@ int Field_varstring::pack_cmp(const char *b, uint key_length)
int cmp= memcmp(a,b,min(a_length,b_length));
return cmp ? cmp : (int) (a_length - b_length);
}
- return my_sortncmp(a,a_length, b,b_length);
+ return my_sortncmp(field_charset, a,a_length, b,b_length);
}
uint Field_varstring::packed_col_length(const char *ptr, uint length)
@@ -3944,11 +4170,11 @@ uint Field_varstring::max_packed_col_length(uint max_length)
Field_blob::Field_blob(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
enum utype unireg_check_arg, const char *field_name_arg,
struct st_table *table_arg,uint blob_pack_length,
- bool binary_arg)
+ bool binary_arg, CHARSET_INFO *cs)
:Field_str(ptr_arg, (1L << min(blob_pack_length,3)*8)-1L,
null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg,
- table_arg),
- packlength(blob_pack_length),binary_flag(binary_arg)
+ table_arg, cs),
+ packlength(blob_pack_length),binary_flag(binary_arg), geom_flag(true)
{
flags|= BLOB_FLAG;
if (binary_arg)
@@ -4039,8 +4265,9 @@ uint32 Field_blob::get_length(const char *pos)
}
-void Field_blob::store(const char *from,uint len)
+int Field_blob::store(const char *from,uint len,CHARSET_INFO *cs)
{
+ field_charset=cs;
if (!len)
{
bzero(ptr,Field_blob::pack_length());
@@ -4072,20 +4299,23 @@ void Field_blob::store(const char *from,uint len)
}
bmove(ptr+packlength,(char*) &from,sizeof(char*));
}
+ return 0;
}
-void Field_blob::store(double nr)
+int Field_blob::store(double nr)
{
value.set(nr);
- Field_blob::store(value.ptr(),(uint) value.length());
+ return Field_blob::store(value.ptr(),(uint) value.length(),
+ default_charset_info);
}
-void Field_blob::store(longlong nr)
+int Field_blob::store(longlong nr)
{
value.set(nr);
- Field_blob::store(value.ptr(), (uint) value.length());
+ return Field_blob::store(value.ptr(), (uint) value.length(),
+ default_charset_info);
}
@@ -4128,9 +4358,9 @@ String *Field_blob::val_str(String *val_buffer __attribute__((unused)),
char *blob;
memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
if (!blob)
- val_ptr->set("",0); // A bit safer than ->length(0)
+ val_ptr->set("",0,field_charset); // A bit safer than ->length(0)
else
- val_ptr->set((const char*) blob,get_length(ptr));
+ val_ptr->set((const char*) blob,get_length(ptr),field_charset);
return val_ptr;
}
@@ -4142,7 +4372,7 @@ int Field_blob::cmp(const char *a,uint32 a_length, const char *b,
if (binary_flag)
diff=memcmp(a,b,min(a_length,b_length));
else
- diff=my_sortcmp(a,b,min(a_length,b_length));
+ diff=my_sortcmp(field_charset, a,b,min(a_length,b_length));
return diff ? diff : (int) (a_length - b_length);
}
@@ -4190,11 +4420,30 @@ int Field_blob::cmp_binary(const char *a_ptr, const char *b_ptr,
/* The following is used only when comparing a key */
-void Field_blob::get_key_image(char *buff,uint length)
+void Field_blob::get_key_image(char *buff,uint length, imagetype type)
{
- length-=HA_KEY_BLOB_LENGTH;
- uint32 blob_length=get_length(ptr);
+ length-= HA_KEY_BLOB_LENGTH;
+ uint32 blob_length= get_length(ptr);
char *blob;
+
+ if (type == itMBR)
+ {
+ if (!blob_length)
+ return;
+ get_ptr(&blob);
+
+ MBR mbr;
+ Geometry gobj;
+ gobj.create_from_wkb(blob,blob_length);
+ gobj.get_mbr(&mbr);
+ float8store(buff, mbr.xmin);
+ float8store(buff+8, mbr.xmax);
+ float8store(buff+16, mbr.ymin);
+ float8store(buff+24, mbr.ymax);
+ return;
+ }
+
+ length-=HA_KEY_BLOB_LENGTH;
if ((uint32) length > blob_length)
{
#ifdef HAVE_purify
@@ -4210,9 +4459,34 @@ void Field_blob::get_key_image(char *buff,uint length)
void Field_blob::set_key_image(char *buff,uint length)
{
length=uint2korr(buff);
- Field_blob::store(buff+2,length);
+ (void) Field_blob::store(buff+2,length, default_charset_info);
}
+
+void Field_geom::get_key_image(char *buff,uint length, imagetype type)
+{
+ length-=HA_KEY_BLOB_LENGTH;
+ ulong blob_length=get_length(ptr);
+ char *blob;
+ get_ptr(&blob);
+ memcpy(buff+2,blob,length);
+
+ MBR mbr;
+ Geometry gobj;
+ gobj.create_from_wkb(blob,blob_length);
+ gobj.get_mbr(&mbr);
+ float8store(buff, mbr.xmin);
+ float8store(buff+8, mbr.xmax);
+ float8store(buff+16, mbr.ymin);
+ float8store(buff+24, mbr.ymax);
+ return;
+}
+
+void Field_geom::set_key_image(char *buff,uint length)
+{
+}
+
+
int Field_blob::key_cmp(const byte *key_ptr, uint max_key_length)
{
char *blob1;
@@ -4252,11 +4526,11 @@ void Field_blob::sort_string(char *to,uint length)
else
{
#ifdef USE_STRCOLL
- if (use_strcoll(default_charset_info))
+ if (use_strcoll(field_charset))
{
- blob_length=my_strnxfrm(default_charset_info,
- (unsigned char *)to,(unsigned char *)blob,
- length,blob_org_length);
+ blob_length=my_strnxfrm(field_charset,
+ (unsigned char *)to, length,
+ (unsigned char *)blob, blob_org_length);
if (blob_length >= length)
return;
to+=blob_length;
@@ -4264,7 +4538,7 @@ void Field_blob::sort_string(char *to,uint length)
else
#endif
for (char *end=blob+blob_length ; blob != end ;)
- *to++=(char) my_sort_order[(uint) (uchar) *blob++];
+ *to++=(char) field_charset->sort_order[(uint) (uchar) *blob++];
}
bzero(to,length-blob_length);
}
@@ -4280,8 +4554,13 @@ void Field_blob::sql_type(String &res) const
case 3: str="medium"; break;
case 4: str="long"; break;
}
- res.set(str,(uint) strlen(str));
+ res.set(str,(uint) strlen(str),default_charset_info);
res.append(binary_flag ? "blob" : "text");
+ if (!binary_flag)
+ {
+ res.append(" character set ");
+ res.append(field_charset->name);
+ }
}
@@ -4342,7 +4621,7 @@ int Field_blob::pack_cmp(const char *a, const char *b, uint key_length)
int cmp= memcmp(a,b,min(a_length,b_length));
return cmp ? cmp : (int) (a_length - b_length);
}
- return my_sortncmp(a,a_length, b,b_length);
+ return my_sortncmp(field_charset, a,a_length, b,b_length);
}
@@ -4368,7 +4647,7 @@ int Field_blob::pack_cmp(const char *b, uint key_length)
int cmp= memcmp(a,b,min(a_length,b_length));
return cmp ? cmp : (int) (a_length - b_length);
}
- return my_sortncmp(a,a_length, b,b_length);
+ return my_sortncmp(field_charset, a,a_length, b,b_length);
}
/* Create a packed key that will be used for storage from a MySQL row */
@@ -4479,14 +4758,16 @@ void Field_enum::store_type(ulonglong value)
uint find_enum(TYPELIB *lib,const char *x, uint length)
{
const char *end=x+length;
- while (end > x && isspace(end[-1]))
+ while (end > x && my_isspace(system_charset_info,end[-1]))
end--;
const char *i;
const char *j;
for (uint pos=0 ; (j=lib->type_names[pos]) ; pos++)
{
- for (i=x ; i != end && toupper(*i) == toupper(*j) ; i++, j++) ;
+ for (i=x ; i != end &&
+ my_toupper(system_charset_info,*i) ==
+ my_toupper(system_charset_info,*j) ; i++, j++) ;
if (i == end && ! *j)
return(pos+1);
}
@@ -4499,8 +4780,9 @@ uint find_enum(TYPELIB *lib,const char *x, uint length)
** (if there isn't a empty value in the enum)
*/
-void Field_enum::store(const char *from,uint length)
+int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs)
{
+ int error= 0;
uint tmp=find_enum(typelib,from,length);
if (!tmp)
{
@@ -4520,29 +4802,34 @@ void Field_enum::store(const char *from,uint length)
{
tmp=0;
current_thd->cuted_fields++;
+ error=1;
}
}
else
current_thd->cuted_fields++;
}
store_type((ulonglong) tmp);
+ return error;
}
-void Field_enum::store(double nr)
+int Field_enum::store(double nr)
{
- Field_enum::store((longlong) nr);
+ return Field_enum::store((longlong) nr);
}
-void Field_enum::store(longlong nr)
+int Field_enum::store(longlong nr)
{
+ int error= 0;
if ((uint) nr > typelib->count || nr == 0)
{
current_thd->cuted_fields++;
nr=0;
+ error=1;
}
store_type((ulonglong) (uint) nr);
+ return error;
}
@@ -4605,7 +4892,8 @@ String *Field_enum::val_str(String *val_buffer __attribute__((unused)),
val_ptr->length(0);
else
val_ptr->set((const char*) typelib->type_names[tmp-1],
- (uint) strlen(typelib->type_names[tmp-1]));
+ (uint) strlen(typelib->type_names[tmp-1]),
+ default_charset_info);
return val_ptr;
}
@@ -4642,9 +4930,7 @@ void Field_enum::sql_type(String &res) const
{
if (flag)
res.append(',');
- res.append('\'');
- append_unescaped(&res,*pos);
- res.append('\'');
+ append_unescaped(&res, *pos, strlen(*pos));
flag=1;
}
res.append(')');
@@ -4663,14 +4949,14 @@ void Field_enum::sql_type(String &res) const
ulonglong find_set(TYPELIB *lib,const char *x,uint length)
{
const char *end=x+length;
- while (end > x && isspace(end[-1]))
+ while (end > x && my_isspace(system_charset_info, end[-1]))
end--;
ulonglong found=0;
if (x != end)
{
const char *start=x;
- bool error=0;
+ bool error= 0;
for (;;)
{
const char *pos=start;
@@ -4691,8 +4977,9 @@ ulonglong find_set(TYPELIB *lib,const char *x,uint length)
}
-void Field_set::store(const char *from,uint length)
+int Field_set::store(const char *from,uint length,CHARSET_INFO *cs)
{
+ int error= 0;
ulonglong tmp=find_set(typelib,from,length);
if (!tmp && length && length < 22)
{
@@ -4708,23 +4995,30 @@ void Field_set::store(const char *from,uint length)
tmp=strtoull(conv,&end,10);
if (my_errno || end != conv+length ||
tmp > (ulonglong) (((longlong) 1 << typelib->count) - (longlong) 1))
+ {
tmp=0;
+ error=1;
+ }
else
current_thd->cuted_fields--; // Remove warning from find_set
}
store_type(tmp);
+ return error;
}
-void Field_set::store(longlong nr)
+int Field_set::store(longlong nr)
{
+ int error= 0;
if ((ulonglong) nr > (ulonglong) (((longlong) 1 << typelib->count) -
(longlong) 1))
{
nr&= (longlong) (((longlong) 1 << typelib->count) - (longlong) 1);
current_thd->cuted_fields++;
+ error=1;
}
store_type((ulonglong) nr);
+ return error;
}
@@ -4742,7 +5036,8 @@ String *Field_set::val_str(String *val_buffer,
if (val_buffer->length())
val_buffer->append(field_separator);
String str(typelib->type_names[bitnr],
- (uint) strlen(typelib->type_names[bitnr]));
+ (uint) strlen(typelib->type_names[bitnr]),
+ default_charset_info);
val_buffer->append(str);
}
tmp>>=1;
@@ -4762,9 +5057,7 @@ void Field_set::sql_type(String &res) const
{
if (flag)
res.append(',');
- res.append('\'');
- append_unescaped(&res,*pos);
- res.append('\'');
+ append_unescaped(&res, *pos, strlen(*pos));
flag=1;
}
res.append(')');
@@ -4789,7 +5082,8 @@ bool Field_enum::eq_def(Field *field)
if (typelib->count < from_lib->count)
return 0;
for (uint i=0 ; i < from_lib->count ; i++)
- if (my_strcasecmp(typelib->type_names[i],from_lib->type_names[i]))
+ if (my_strcasecmp(field_charset,
+ typelib->type_names[i],from_lib->type_names[i]))
return 0;
return 1;
}
@@ -4864,6 +5158,7 @@ uint pack_length_to_packflag(uint type)
Field *make_field(char *ptr, uint32 field_length,
uchar *null_pos, uchar null_bit,
uint pack_flag,
+ enum_field_types field_type,
Field::utype unireg_check,
TYPELIB *interval,
const char *field_name,
@@ -4879,7 +5174,8 @@ Field *make_field(char *ptr, uint32 field_length,
if (!f_is_packed(pack_flag))
return new Field_string(ptr,field_length,null_pos,null_bit,
unireg_check, field_name, table,
- f_is_binary(pack_flag) != 0);
+ f_is_binary(pack_flag) != 0,
+ default_charset_info);
uint pack_length=calc_pack_length((enum_field_types)
f_packtype(pack_flag),
@@ -4888,7 +5184,13 @@ Field *make_field(char *ptr, uint32 field_length,
if (f_is_blob(pack_flag))
return new Field_blob(ptr,null_pos,null_bit,
unireg_check, field_name, table,
+ pack_length,f_is_binary(pack_flag) != 0,
+ default_charset_info);
+ if (f_is_geom(pack_flag))
+ return new Field_geom(ptr,null_pos,null_bit,
+ unireg_check, field_name, table,
pack_length,f_is_binary(pack_flag) != 0);
+
if (interval)
{
if (f_is_enum(pack_flag))
@@ -4902,7 +5204,7 @@ Field *make_field(char *ptr, uint32 field_length,
}
}
- switch ((enum enum_field_types) f_packtype(pack_flag)) {
+ switch (field_type) {
case FIELD_TYPE_DECIMAL:
return new Field_decimal(ptr,field_length,null_pos,null_bit,
unireg_check, field_name, table,
@@ -4983,6 +5285,8 @@ create_field::create_field(Field *old_field,Field *orig_field)
unireg_check=old_field->unireg_check;
pack_length=old_field->pack_length();
sql_type= old_field->real_type();
+ charset= old_field->charset(); // May be NULL ptr
+ comment= old_field->comment;
/* Fix if the original table had 4 byte pointer blobs */
if (flags & BLOB_FLAG)
@@ -4991,6 +5295,7 @@ create_field::create_field(Field *old_field,Field *orig_field)
decimals= old_field->decimals();
if (sql_type == FIELD_TYPE_STRING)
{
+ /* Change CHAR -> VARCHAR if dynamic record length */
sql_type=old_field->type();
decimals=0;
}
@@ -5004,7 +5309,8 @@ create_field::create_field(Field *old_field,Field *orig_field)
orig_field)
{
char buff[MAX_FIELD_WIDTH],*pos;
- String tmp(buff,sizeof(buff));
+ CHARSET_INFO *field_charset= charset ? charset : default_charset_info;
+ String tmp(buff,sizeof(buff),field_charset);
/* Get the value from record[2] (the default value row) */
my_ptrdiff_t diff= (my_ptrdiff_t) (orig_field->table->rec_buff_length*2);
@@ -5016,7 +5322,7 @@ create_field::create_field(Field *old_field,Field *orig_field)
{
pos= (char*) sql_memdup(tmp.ptr(),tmp.length()+1);
pos[tmp.length()]=0;
- def=new Item_string(pos,tmp.length());
+ def=new Item_string(pos,tmp.length(),field_charset);
}
}
}
diff --git a/sql/field.h b/sql/field.h
index 0f0225da3d2..551619abc6f 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -41,12 +41,16 @@ public:
uchar *null_ptr; // Byte where null_bit is
struct st_table *table; // Pointer for table
const char *table_name,*field_name;
+ LEX_STRING comment;
ulong query_id; // For quick test of used fields
/* Field is part of the following keys */
key_map key_start,part_of_key,part_of_sortkey;
enum utype { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
BIT_FIELD, TIMESTAMP_FIELD,CAPITALIZE,BLOB_FIELD};
+
+ enum imagetype { itRAW, itMBR};
+
utype unireg_check;
uint32 field_length; // Length of field
uint16 flags;
@@ -56,9 +60,9 @@ public:
utype unireg_check_arg, const char *field_name_arg,
struct st_table *table_arg);
virtual ~Field() {}
- virtual void store(const char *to,uint length)=0;
- virtual void store(double nr)=0;
- virtual void store(longlong nr)=0;
+ virtual int store(const char *to,uint length,CHARSET_INFO *cs)=0;
+ virtual int store(double nr)=0;
+ virtual int store(longlong nr)=0;
virtual void store_time(TIME *ltime,timestamp_type t_type);
virtual double val_real(void)=0;
virtual longlong val_int(void)=0;
@@ -145,17 +149,12 @@ public:
{ memcpy(buff,ptr,length); }
inline void set_image(char *buff,uint length)
{ memcpy(ptr,buff,length); }
- virtual void get_key_image(char *buff,uint length)
+ virtual void get_key_image(char *buff,uint length, imagetype type)
{ get_image(buff,length); }
virtual void set_key_image(char *buff,uint length)
{ set_image(buff,length); }
inline int cmp_image(char *buff,uint length)
- {
- if (binary())
- return memcmp(ptr,buff,length);
- else
- return my_casecmp(ptr,buff,length);
- }
+ { return memcmp(ptr,buff,length); }
inline longlong val_int_offset(uint row_offset)
{
ptr+=row_offset;
@@ -199,6 +198,7 @@ public:
uint fill_cache_field(struct st_cache_field *copy);
virtual bool get_date(TIME *ltime,bool fuzzydate);
virtual bool get_time(TIME *ltime);
+ virtual CHARSET_INFO *charset(void) { return 0; }
friend bool reopen_table(THD *,struct st_table *,bool);
friend int cre_myisam(my_string name, register TABLE *form, uint options,
ulonglong auto_increment_value);
@@ -246,19 +246,31 @@ public:
class Field_str :public Field {
+protected:
+ CHARSET_INFO *field_charset;
public:
Field_str(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
uchar null_bit_arg, utype unireg_check_arg,
const char *field_name_arg,
- struct st_table *table_arg)
+ struct st_table *table_arg,CHARSET_INFO *charset)
:Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg, table_arg)
- {}
+ { field_charset=charset; }
Item_result result_type () const { return STRING_RESULT; }
uint decimals() const { return NOT_FIXED_DEC; }
- friend class create_field;
void make_field(Send_field *);
uint size_of() const { return sizeof(*this); }
+ CHARSET_INFO *charset(void) { return field_charset; }
+
+ inline void set_charset(CHARSET_INFO *charset) { field_charset=charset; }
+ inline int cmp_image(char *buff,uint length)
+ {
+ if (binary())
+ return memcmp(ptr,buff,length);
+ else
+ return my_strncasecmp(field_charset,ptr,buff,length);
+ }
+ friend class create_field;
};
@@ -277,9 +289,9 @@ public:
enum ha_base_keytype key_type() const
{ return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; }
void reset(void);
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
double val_real(void);
longlong val_int(void);
String *val_str(String*,String *);
@@ -306,9 +318,9 @@ public:
enum_field_types type() const { return FIELD_TYPE_TINY;}
enum ha_base_keytype key_type() const
{ return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
void reset(void) { ptr[0]=0; }
double val_real(void);
longlong val_int(void);
@@ -335,9 +347,9 @@ public:
enum_field_types type() const { return FIELD_TYPE_SHORT;}
enum ha_base_keytype key_type() const
{ return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;}
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
void reset(void) { ptr[0]=ptr[1]=0; }
double val_real(void);
longlong val_int(void);
@@ -364,9 +376,9 @@ public:
enum_field_types type() const { return FIELD_TYPE_INT24;}
enum ha_base_keytype key_type() const
{ return unsigned_flag ? HA_KEYTYPE_UINT24 : HA_KEYTYPE_INT24; }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; }
double val_real(void);
longlong val_int(void);
@@ -398,9 +410,9 @@ public:
enum_field_types type() const { return FIELD_TYPE_LONG;}
enum ha_base_keytype key_type() const
{ return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; }
double val_real(void);
longlong val_int(void);
@@ -434,9 +446,9 @@ public:
enum_field_types type() const { return FIELD_TYPE_LONGLONG;}
enum ha_base_keytype key_type() const
{ return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; }
double val_real(void);
longlong val_int(void);
@@ -462,9 +474,9 @@ public:
{}
enum_field_types type() const { return FIELD_TYPE_FLOAT;}
enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
void reset(void) { bzero(ptr,sizeof(float)); }
double val_real(void);
longlong val_int(void);
@@ -494,9 +506,9 @@ public:
{}
enum_field_types type() const { return FIELD_TYPE_DOUBLE;}
enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
void reset(void) { bzero(ptr,sizeof(double)); }
double val_real(void);
longlong val_int(void);
@@ -517,12 +529,12 @@ public:
enum utype unireg_check_arg, const char *field_name_arg,
struct st_table *table_arg)
:Field_str(ptr_arg, len_arg, null, 1,
- unireg_check_arg, field_name_arg, table_arg)
+ unireg_check_arg, field_name_arg, table_arg, default_charset_info)
{}
enum_field_types type() const { return FIELD_TYPE_NULL;}
- void store(const char *to, uint length) { null[0]=1; }
- void store(double nr) { null[0]=1; }
- void store(longlong nr) { null[0]=1; }
+ int store(const char *to, uint length, CHARSET_INFO *cs) { null[0]=1; return 0; }
+ int store(double nr) { null[0]=1; return 0; }
+ int store(longlong nr) { null[0]=1; return 0; }
void reset(void) {}
double val_real(void) { return 0.0;}
longlong val_int(void) { return 0;}
@@ -531,7 +543,7 @@ public:
int cmp(const char *a, const char *b) { return 0;}
void sort_string(char *buff, uint length) {}
uint32 pack_length() const { return 0; }
- void sql_type(String &str) const { str.set("null",4); }
+ void sql_type(String &str) const { str.set("null",4,default_charset_info); }
uint size_of() const { return sizeof(*this); }
};
@@ -544,9 +556,9 @@ public:
enum Item_result result_type () const { return field_length == 8 || field_length == 14 ? INT_RESULT : STRING_RESULT; }
enum_field_types type() const { return FIELD_TYPE_TIMESTAMP;}
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; }
double val_real(void);
longlong val_int(void);
@@ -588,9 +600,9 @@ public:
unireg_check_arg, field_name_arg, table_arg, 1, 1)
{}
enum_field_types type() const { return FIELD_TYPE_YEAR;}
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
double val_real(void);
longlong val_int(void);
String *val_str(String*,String *);
@@ -604,18 +616,18 @@ public:
enum utype unireg_check_arg, const char *field_name_arg,
struct st_table *table_arg)
:Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
- unireg_check_arg, field_name_arg, table_arg)
+ unireg_check_arg, field_name_arg, table_arg, default_charset_info)
{}
Field_date(bool maybe_null_arg, const char *field_name_arg,
struct st_table *table_arg)
:Field_str((char*) 0,10, maybe_null_arg ? (uchar*) "": 0,0,
- NONE, field_name_arg, table_arg) {}
+ NONE, field_name_arg, table_arg, default_charset_info) {}
enum_field_types type() const { return FIELD_TYPE_DATE;}
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
enum Item_result cmp_type () const { return INT_RESULT; }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; }
double val_real(void);
longlong val_int(void);
@@ -634,15 +646,15 @@ public:
enum utype unireg_check_arg, const char *field_name_arg,
struct st_table *table_arg)
:Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
- unireg_check_arg, field_name_arg, table_arg)
+ unireg_check_arg, field_name_arg, table_arg, default_charset_info)
{}
enum_field_types type() const { return FIELD_TYPE_DATE;}
enum_field_types real_type() const { return FIELD_TYPE_NEWDATE; }
enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; }
enum Item_result cmp_type () const { return INT_RESULT; }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
void store_time(TIME *ltime,timestamp_type type);
void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; }
double val_real(void);
@@ -665,18 +677,18 @@ public:
enum utype unireg_check_arg, const char *field_name_arg,
struct st_table *table_arg)
:Field_str(ptr_arg, 8, null_ptr_arg, null_bit_arg,
- unireg_check_arg, field_name_arg, table_arg)
+ unireg_check_arg, field_name_arg, table_arg, default_charset_info)
{}
Field_time(bool maybe_null_arg, const char *field_name_arg,
struct st_table *table_arg)
:Field_str((char*) 0,8, maybe_null_arg ? (uchar*) "": 0,0,
- NONE, field_name_arg, table_arg) {}
+ NONE, field_name_arg, table_arg, default_charset_info) {}
enum_field_types type() const { return FIELD_TYPE_TIME;}
enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; }
enum Item_result cmp_type () const { return INT_RESULT; }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; }
double val_real(void);
longlong val_int(void);
@@ -697,20 +709,20 @@ public:
enum utype unireg_check_arg, const char *field_name_arg,
struct st_table *table_arg)
:Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg,
- unireg_check_arg, field_name_arg, table_arg)
+ unireg_check_arg, field_name_arg, table_arg, default_charset_info)
{}
Field_datetime(bool maybe_null_arg, const char *field_name_arg,
struct st_table *table_arg)
:Field_str((char*) 0,19, maybe_null_arg ? (uchar*) "": 0,0,
- NONE, field_name_arg, table_arg) {}
+ NONE, field_name_arg, table_arg, default_charset_info) {}
enum_field_types type() const { return FIELD_TYPE_DATETIME;}
#ifdef HAVE_LONG_LONG
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; }
#endif
enum Item_result cmp_type () const { return INT_RESULT; }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
void store_time(TIME *ltime,timestamp_type type);
void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; }
double val_real(void);
@@ -733,18 +745,18 @@ public:
Field_string(char *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
uchar null_bit_arg,
enum utype unireg_check_arg, const char *field_name_arg,
- struct st_table *table_arg,bool binary_arg)
+ struct st_table *table_arg,bool binary_arg, CHARSET_INFO *cs)
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
- unireg_check_arg, field_name_arg, table_arg),
+ unireg_check_arg, field_name_arg, table_arg,cs),
binary_flag(binary_arg)
{
if (binary_arg)
flags|=BINARY_FLAG;
}
Field_string(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
- struct st_table *table_arg, bool binary_arg)
+ struct st_table *table_arg, bool binary_arg, CHARSET_INFO *cs)
:Field_str((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0,0,
- NONE, field_name_arg, table_arg),
+ NONE, field_name_arg, table_arg, cs),
binary_flag(binary_arg)
{
if (binary_arg)
@@ -762,9 +774,9 @@ public:
bool zero_pack() const { return 0; }
bool binary() const { return binary_flag; }
void reset(void) { bfill(ptr,field_length,' '); }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
double val_real(void);
longlong val_int(void);
String *val_str(String*,String *);
@@ -788,18 +800,18 @@ public:
Field_varstring(char *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
uchar null_bit_arg,
enum utype unireg_check_arg, const char *field_name_arg,
- struct st_table *table_arg,bool binary_arg)
+ struct st_table *table_arg,bool binary_arg, CHARSET_INFO *cs)
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
- unireg_check_arg, field_name_arg, table_arg),
+ unireg_check_arg, field_name_arg, table_arg, cs),
binary_flag(binary_arg)
{
if (binary_arg)
flags|=BINARY_FLAG;
}
Field_varstring(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
- struct st_table *table_arg, bool binary_arg)
+ struct st_table *table_arg, bool binary_arg, CHARSET_INFO *cs)
:Field_str((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0,0,
- NONE, field_name_arg, table_arg),
+ NONE, field_name_arg, table_arg, cs),
binary_flag(binary_arg)
{
if (binary_arg)
@@ -814,9 +826,9 @@ public:
void reset(void) { bzero(ptr,field_length+2); }
uint32 pack_length() const { return (uint32) field_length+2; }
uint32 key_length() const { return (uint32) field_length; }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
double val_real(void);
longlong val_int(void);
String *val_str(String*,String *);
@@ -838,16 +850,17 @@ class Field_blob :public Field_str {
uint packlength;
String value; // For temporaries
bool binary_flag;
+ bool geom_flag;
public:
Field_blob(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
enum utype unireg_check_arg, const char *field_name_arg,
struct st_table *table_arg,uint blob_pack_length,
- bool binary_arg);
+ bool binary_arg, CHARSET_INFO *cs);
Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
- struct st_table *table_arg, bool binary_arg)
+ struct st_table *table_arg, bool binary_arg, CHARSET_INFO *cs)
:Field_str((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0,0,
- NONE, field_name_arg, table_arg),
- packlength(3),binary_flag(binary_arg)
+ NONE, field_name_arg, table_arg, cs),
+ packlength(3),binary_flag(binary_arg), geom_flag(true)
{
flags|= BLOB_FLAG;
if (binary_arg)
@@ -856,9 +869,9 @@ public:
enum_field_types type() const { return FIELD_TYPE_BLOB;}
enum ha_base_keytype key_type() const
{ return binary_flag ? HA_KEYTYPE_VARBINARY : HA_KEYTYPE_VARTEXT; }
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
double val_real(void);
longlong val_int(void);
String *val_str(String*,String *);
@@ -894,7 +907,7 @@ public:
store_length(length);
memcpy_fixed(ptr+packlength,&data,sizeof(char*));
}
- void get_key_image(char *buff,uint length);
+ void get_key_image(char *buff,uint length, imagetype type);
void set_key_image(char *buff,uint length);
void sql_type(String &str) const;
inline bool copy()
@@ -923,6 +936,26 @@ public:
};
+class Field_geom :public Field_blob {
+public:
+ Field_geom(char *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg,
+ enum utype unireg_check_arg, const char *field_name_arg,
+ struct st_table *table_arg,uint blob_pack_length,
+ bool binary_arg)
+ :Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
+ field_name_arg, table_arg, blob_pack_length,binary_arg,
+ default_charset_info) {}
+ Field_geom(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
+ struct st_table *table_arg, bool binary_arg)
+ :Field_blob(len_arg, maybe_null_arg, field_name_arg,
+ table_arg, binary_arg, default_charset_info) {}
+ enum ha_base_keytype key_type() const { return HA_KEYTYPE_VARBINARY; }
+
+ void get_key_image(char *buff,uint length, imagetype type);
+ void set_key_image(char *buff,uint length);
+};
+
+
class Field_enum :public Field_str {
protected:
uint packlength;
@@ -934,7 +967,7 @@ public:
struct st_table *table_arg,uint packlength_arg,
TYPELIB *typelib_arg)
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
- unireg_check_arg, field_name_arg, table_arg),
+ unireg_check_arg, field_name_arg, table_arg, default_charset_info),
packlength(packlength_arg),typelib(typelib_arg)
{
flags|=ENUM_FLAG;
@@ -942,9 +975,9 @@ public:
enum_field_types type() const { return FIELD_TYPE_STRING; }
enum Item_result cmp_type () const { return INT_RESULT; }
enum ha_base_keytype key_type() const;
- void store(const char *to,uint length);
- void store(double nr);
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr);
+ int store(longlong nr);
void reset() { bzero(ptr,packlength); }
double val_real(void);
longlong val_int(void);
@@ -977,9 +1010,9 @@ public:
{
flags=(flags & ~ENUM_FLAG) | SET_FLAG;
}
- void store(const char *to,uint length);
- void store(double nr) { Field_set::store((longlong) nr); }
- void store(longlong nr);
+ int store(const char *to,uint length,CHARSET_INFO *charset);
+ int store(double nr) { return Field_set::store((longlong) nr); }
+ int store(longlong nr);
virtual bool zero_pack() const { return 1; }
String *val_str(String*,String *);
void sql_type(String &str) const;
@@ -996,6 +1029,7 @@ public:
const char *field_name;
const char *change; // If done with alter table
const char *after; // Put column after this one
+ LEX_STRING comment; // Comment for field
Item *def; // Default value
enum enum_field_types sql_type;
uint32 length;
@@ -1017,7 +1051,9 @@ public:
class Send_field {
public:
- const char *table_name,*col_name;
+ const char *db_name;
+ const char *table_name,*org_table_name;
+ const char *col_name,*org_col_name;
uint length,flags,decimals;
enum_field_types type;
Send_field() {}
@@ -1050,7 +1086,8 @@ public:
Field *make_field(char *ptr, uint32 field_length,
uchar *null_pos, uchar null_bit,
- uint pack_flag, Field::utype unireg_check,
+ uint pack_flag, enum_field_types field_type,
+ Field::utype unireg_check,
TYPELIB *interval, const char *field_name,
struct st_table *table);
uint pack_length_to_packflag(uint type);
@@ -1072,6 +1109,8 @@ bool test_if_int(const char *str,int length);
#define FIELDFLAG_INTERVAL 256
#define FIELDFLAG_BITFIELD 512 // mangled with dec!
#define FIELDFLAG_BLOB 1024 // mangled with dec!
+#define FIELDFLAG_GEOM 2048
+
#define FIELDFLAG_LEFT_FULLSCREEN 8192
#define FIELDFLAG_RIGHT_FULLSCREEN 16384
#define FIELDFLAG_FORMAT_NUMBER 16384 // predit: ###,,## in output
@@ -1098,6 +1137,7 @@ bool test_if_int(const char *str,int length);
#define f_is_enum(x) ((x) & FIELDFLAG_INTERVAL)
#define f_is_bitfield(x) ((x) & FIELDFLAG_BITFIELD)
#define f_is_blob(x) (((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
+#define f_is_geom(x) ((x) & FIELDFLAG_GEOM)
#define f_is_equ(x) ((x) & (1+2+FIELDFLAG_PACK+31*256))
#define f_settype(x) (((int) x) << FIELDFLAG_PACK_SHIFT)
#define f_maybe_null(x) (x & FIELDFLAG_MAYBE_NULL)
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index c7a6d778953..da7a1187a47 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -228,7 +228,7 @@ static void do_conv_blob(Copy_field *copy)
{
copy->from_field->val_str(&copy->tmp,&copy->tmp);
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
- copy->tmp.length());
+ copy->tmp.length(),default_charset_info);
}
/* Save blob in copy->tmp for GROUP BY */
@@ -236,20 +236,20 @@ static void do_conv_blob(Copy_field *copy)
static void do_save_blob(Copy_field *copy)
{
char buff[MAX_FIELD_WIDTH];
- String res(buff,sizeof(buff));
+ String res(buff,sizeof(buff),default_charset_info);
copy->from_field->val_str(&res,&res);
copy->tmp.copy(res);
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
- copy->tmp.length());
+ copy->tmp.length(),default_charset_info);
}
static void do_field_string(Copy_field *copy)
{
char buff[MAX_FIELD_WIDTH];
- copy->tmp.set_quick(buff,sizeof(buff));
+ copy->tmp.set_quick(buff,sizeof(buff),default_charset_info);
copy->from_field->val_str(&copy->tmp,&copy->tmp);
- copy->to_field->store(copy->tmp.c_ptr_quick(),copy->tmp.length());
+ copy->to_field->store(copy->tmp.c_ptr_quick(),copy->tmp.length(),default_charset_info);
}
@@ -276,7 +276,7 @@ static void do_cut_string(Copy_field *copy)
ptr != end ;
ptr++)
{
- if (!isspace(*ptr))
+ if (!my_isspace(system_charset_info, *ptr))
{
current_thd->cuted_fields++; // Give a warning
break;
@@ -508,7 +508,8 @@ void field_conv(Field *to,Field *from)
if (!blob->value.is_alloced() &&
from->real_type() != FIELD_TYPE_STRING)
blob->value.copy();
- blob->store(blob->value.ptr(),blob->value.length());
+ blob->store(blob->value.ptr(),blob->value.length(),
+ to->binary()?default_charset_info:((Field_str*)to)->charset());
return;
}
if ((from->result_type() == STRING_RESULT &&
@@ -518,9 +519,11 @@ void field_conv(Field *to,Field *from)
to->type() == FIELD_TYPE_DECIMAL)
{
char buff[MAX_FIELD_WIDTH];
- String result(buff,sizeof(buff));
+ String result(buff,sizeof(buff),default_charset_info);
from->val_str(&result,&result);
- to->store(result.c_ptr_quick(),result.length());
+ to->store(result.c_ptr_quick(),result.length(),
+ to->binary()?default_charset_info:((Field_str*)to)->charset());
+ // QQ: what to do if "from" and "to" are of dirrent charsets?
}
else if (from->result_type() == REAL_RESULT)
to->store(from->val_real());
diff --git a/sql/filesort.cc b/sql/filesort.cc
index c6782aa0d93..398ba4875d3 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -79,10 +79,19 @@ ha_rows filesort(TABLE *table, SORT_FIELD *sortorder, uint s_length,
DBUG_ENTER("filesort");
DBUG_EXECUTE("info",TEST_filesort(sortorder,s_length,special););
+ CHARSET_INFO *charset=table->table_charset;
+ uint i;
#ifdef SKIP_DBUG_IN_FILESORT
DBUG_PUSH(""); /* No DBUG here */
#endif
+ // BAR TODO: this is not absolutely correct, but OK for now
+ for(i=0;i<table->fields;i++)
+ if (!table->field[i]->binary())
+ charset=((Field_str*)(table->field[i]))->charset();
+ charset=charset?charset:default_charset_info;
+ // /BAR TODO
+
outfile= table->io_cache;
my_b_clear(&tempfile);
my_b_clear(&buffpek_pointers);
@@ -131,7 +140,7 @@ ha_rows filesort(TABLE *table, SORT_FIELD *sortorder, uint s_length,
records=param.max_rows; /* purecov: inspected */
#ifdef USE_STRCOLL
- if (use_strcoll(default_charset_info) &&
+ if (use_strcoll(charset) &&
!(param.tmp_buffer=my_malloc(param.sort_length,MYF(MY_WME))))
goto err;
#endif
@@ -208,7 +217,7 @@ ha_rows filesort(TABLE *table, SORT_FIELD *sortorder, uint s_length,
err:
#ifdef USE_STRCOLL
- if (use_strcoll(default_charset_info))
+ if (param.tmp_buffer)
x_free(param.tmp_buffer);
#endif
x_free((gptr) sort_keys);
@@ -474,7 +483,7 @@ static void make_sortkey(register SORTPARAM *param,
if (item->maybe_null)
*to++=1;
/* All item->str() to use some extra byte for end null.. */
- String tmp((char*) to,sort_field->length+4);
+ String tmp((char*) to,sort_field->length+4,default_charset_info);
String *res=item->val_str(&tmp);
if (!res)
{
@@ -489,6 +498,7 @@ static void make_sortkey(register SORTPARAM *param,
break;
}
length=res->length();
+ CHARSET_INFO *cs=res->charset();
int diff=(int) (sort_field->length-length);
if (diff < 0)
{
@@ -496,7 +506,7 @@ static void make_sortkey(register SORTPARAM *param,
length=sort_field->length;
}
#ifdef USE_STRCOLL
- if (use_strcoll(default_charset_info))
+ if(use_strcoll(cs))
{
if (item->binary)
{
@@ -513,10 +523,8 @@ static void make_sortkey(register SORTPARAM *param,
memcpy(param->tmp_buffer,from,length);
from=param->tmp_buffer;
}
- uint tmp_length=my_strnxfrm(default_charset_info,
- to,(unsigned char *) from,
- sort_field->length,
- length);
+ uint tmp_length=my_strnxfrm(cs,to,sort_field->length,
+ (unsigned char *) from, length);
if (tmp_length < sort_field->length)
bzero((char*) to+tmp_length,sort_field->length-tmp_length);
}
@@ -528,7 +536,7 @@ static void make_sortkey(register SORTPARAM *param,
memcpy(to,res->ptr(),length);
bzero((char *)to+length,diff);
if (!item->binary)
- case_sort((char*) to,length);
+ case_sort(cs, (char*) to,length);
#ifdef USE_STRCOLL
}
#endif
@@ -926,8 +934,12 @@ sortlength(SORT_FIELD *sortorder, uint s_length)
{
sortorder->length=sortorder->field->pack_length();
#ifdef USE_STRCOLL
- if (use_strcoll(default_charset_info) && !sortorder->field->binary())
- sortorder->length= sortorder->length*MY_STRXFRM_MULTIPLY;
+ if (!sortorder->field->binary())
+ {
+ CHARSET_INFO *cs=((Field_str*)(sortorder->field))->charset();
+ if (use_strcoll(cs))
+ sortorder->length= sortorder->length*cs->strxfrm_multiply;
+ }
#endif
}
if (sortorder->field->maybe_null())
@@ -935,12 +947,19 @@ sortlength(SORT_FIELD *sortorder, uint s_length)
}
else
{
+#ifdef USE_STRCOLL
+
+#endif
switch ((sortorder->result_type=sortorder->item->result_type())) {
case STRING_RESULT:
sortorder->length=sortorder->item->max_length;
#ifdef USE_STRCOLL
- if (use_strcoll(default_charset_info) && !sortorder->item->binary)
- sortorder->length= sortorder->length*MY_STRXFRM_MULTIPLY;
+ if (!sortorder->item->binary)
+ {
+ CHARSET_INFO *cs=sortorder->item->str_value.charset();
+ if (use_strcoll(cs))
+ sortorder->length= sortorder->length*cs->strxfrm_multiply;
+ }
#endif
break;
case INT_RESULT:
diff --git a/sql/gen_lex_hash.cc b/sql/gen_lex_hash.cc
index c24e7b6d124..4da5496c201 100644
--- a/sql/gen_lex_hash.cc
+++ b/sql/gen_lex_hash.cc
@@ -30,7 +30,7 @@ my_bool opt_search;
int opt_verbose;
ulong opt_count;
-#define max_allowed_array 8000 // Don't generate bigger arrays than this
+#define max_allowed_array 16000 // Don't generate bigger arrays than this
#define max_symbol 32767 // Use this for 'not found'
#define how_much_for_plus 8 // 2-8
#define type_count 1 // 1-5
diff --git a/sql/gstream.cc b/sql/gstream.cc
new file mode 100644
index 00000000000..5a58fef6744
--- /dev/null
+++ b/sql/gstream.cc
@@ -0,0 +1,137 @@
+#include "mysql_priv.h"
+
+int GTextReadStream::get_next_toc_type() const
+{
+ const char *cur = m_cur;
+ while((*cur)&&(strchr(" \t\r\n",*cur)))
+ {
+ cur++;
+ }
+ if(!(*cur))
+ {
+ return eostream;
+ }
+
+ if(((*cur>='a') && (*cur<='z')) || ((*cur>='A') && (*cur<='Z')) || (*cur=='_'))
+ {
+ return word;
+ }
+
+ if(((*cur>='0') && (*cur<='9')) || (*cur=='-') || (*cur=='+') || (*cur=='.'))
+ {
+ return numeric;
+ }
+
+ if(*cur == '(')
+ {
+ return l_bra;
+ }
+
+ if(*cur == ')')
+ {
+ return r_bra;
+ }
+
+ if(*cur == ',')
+ {
+ return comma;
+ }
+
+ return unknown;
+}
+
+const char *GTextReadStream::get_next_word(int *word_len)
+{
+ const char *cur = m_cur;
+ while((*cur)&&(strchr(" \t\r\n",*cur)))
+ {
+ cur++;
+ }
+ m_last_text_position = cur;
+
+ if(!(*cur))
+ {
+ return 0;
+ }
+
+ const char *wd_start = cur;
+
+ if(((*cur<'a') || (*cur>'z')) && ((*cur<'A') || (*cur>'Z')) && (*cur!='_'))
+ {
+ return NULL;
+ }
+
+ ++cur;
+
+ while(((*cur>='a') && (*cur<='z')) || ((*cur>='A') && (*cur<='Z')) || (*cur=='_') ||
+ ((*cur>='0') && (*cur<='9')))
+ {
+ ++cur;
+ }
+
+ *word_len = cur - wd_start;
+
+ m_cur = cur;
+
+ return wd_start;
+}
+
+int GTextReadStream::get_next_number(double *d)
+{
+ const char *cur = m_cur;
+ while((*cur)&&(strchr(" \t\r\n",*cur)))
+ {
+ cur++;
+ }
+
+ m_last_text_position = cur;
+ if(!(*cur))
+ {
+ set_error_msg("Numeric constant expected");
+ return 1;
+ }
+
+ if(((*cur<'0') || (*cur>'9')) && (*cur!='-') && (*cur!='+') && (*cur!='.'))
+ {
+ set_error_msg("Numeric constant expected");
+ return 1;
+ }
+
+ char *endptr;
+
+ *d = strtod(cur, &endptr);
+
+ if(endptr)
+ {
+ m_cur = endptr;
+ }
+
+ return 0;
+}
+
+char GTextReadStream::get_next_symbol()
+{
+ const char *cur = m_cur;
+ while((*cur)&&(strchr(" \t\r\n",*cur)))
+ {
+ cur++;
+ }
+ if(!(*cur))
+ {
+ return 0;
+ }
+
+ m_cur = cur + 1;
+ m_last_text_position = cur;
+
+ return *cur;
+}
+
+void GTextReadStream::set_error_msg(const char *msg)
+{
+ size_t len = strlen(msg);
+ m_err_msg = (char *)my_realloc(m_err_msg, len + 1, MYF(MY_ALLOW_ZERO_PTR));
+ memcpy(m_err_msg, msg, len + 1);
+}
+
+
diff --git a/sql/gstream.h b/sql/gstream.h
new file mode 100644
index 00000000000..f8df6e337b0
--- /dev/null
+++ b/sql/gstream.h
@@ -0,0 +1,61 @@
+#ifndef GSTREAM_H
+#define GSTREAM_H
+
+#ifdef WITHOUT_MYSQL
+ #include ".\rtree\myisamdef.h"
+#else
+ #include "mysql_priv.h"
+#endif
+
+class GTextReadStream
+{
+public:
+ enum TokTypes
+ {
+ unknown,
+ eostream,
+ word,
+ numeric,
+ l_bra,
+ r_bra,
+ comma,
+ };
+ GTextReadStream(const char *buffer, int size) :
+ m_cur(buffer), m_limit(buffer + size), m_last_text_position(buffer), m_err_msg(NULL) {}
+ GTextReadStream() : m_cur(NULL), m_limit(NULL), m_err_msg(NULL) {}
+
+ ~GTextReadStream()
+ {
+ my_free(m_err_msg, MYF(MY_ALLOW_ZERO_PTR));
+ }
+
+ int get_next_toc_type() const;
+ const char *get_next_word(int *word_len);
+ int get_next_number(double *d);
+ char get_next_symbol();
+
+ const char *get_last_text_position() const
+ {
+ return m_last_text_position;
+ }
+
+ void set_error_msg(const char *msg);
+
+// caller should free this pointer
+ char *get_error_msg()
+ {
+ char *err_msg = m_err_msg;
+ m_err_msg = NULL;
+ return err_msg;
+ }
+protected:
+ const char *m_cur;
+ const char *m_limit;
+ const char *m_last_text_position;
+ char *m_err_msg;
+};
+
+#endif
+
+
+
diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc
index e34bfdea2dd..131e38a6bc3 100644
--- a/sql/ha_berkeley.cc
+++ b/sql/ha_berkeley.cc
@@ -168,7 +168,7 @@ bool berkeley_init(void)
db_env=0; /* purecov: inspected */
}
- (void) hash_init(&bdb_open_tables,32,0,0,
+ (void) hash_init(&bdb_open_tables,system_charset_info,32,0,0,
(hash_get_key) bdb_get_key,0,0);
pthread_mutex_init(&bdb_mutex,MY_MUTEX_INIT_FAST);
DBUG_RETURN(db_env == 0);
diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc
index e6d7871b016..271f00428a5 100644
--- a/sql/ha_heap.cc
+++ b/sql/ha_heap.cc
@@ -33,69 +33,12 @@ const char **ha_heap::bas_ext() const
int ha_heap::open(const char *name, int mode, uint test_if_locked)
{
- uint key,parts,mem_per_row=0;
- ulong max_rows;
- HP_KEYDEF *keydef;
- HP_KEYSEG *seg;
- THD *thd= current_thd;
-
- for (key=parts=0 ; key < table->keys ; key++)
- parts+=table->key_info[key].key_parts;
-
- if (!(keydef=(HP_KEYDEF*) my_malloc(table->keys*sizeof(HP_KEYDEF)+
- parts*sizeof(HP_KEYSEG),MYF(MY_WME))))
- return my_errno;
- seg=my_reinterpret_cast(HP_KEYSEG*) (keydef+table->keys);
- for (key=0 ; key < table->keys ; key++)
+ if (!(file= heap_open(name, mode)) && my_errno == ENOENT)
{
- KEY *pos=table->key_info+key;
- KEY_PART_INFO *key_part= pos->key_part;
- KEY_PART_INFO *key_part_end= key_part+pos->key_parts;
-
- mem_per_row += (pos->key_length + (sizeof(char*) * 2));
-
- keydef[key].keysegs=(uint) pos->key_parts;
- keydef[key].flag = (pos->flags & (HA_NOSAME | HA_NULL_ARE_EQUAL));
- keydef[key].seg=seg;
-
- for (; key_part != key_part_end ; key_part++, seg++)
- {
- uint flag=key_part->key_type;
- Field *field=key_part->field;
- if (!f_is_packed(flag) &&
- f_packtype(flag) == (int) FIELD_TYPE_DECIMAL &&
- !(flag & FIELDFLAG_BINARY))
- seg->type= (int) HA_KEYTYPE_TEXT;
- else
- seg->type= (int) HA_KEYTYPE_BINARY;
- seg->start=(uint) key_part->offset;
- seg->length=(uint) key_part->length;
- if (field->null_ptr)
- {
- seg->null_bit=field->null_bit;
- seg->null_pos= (uint) (field->null_ptr-
- (uchar*) table->record[0]);
- }
- else
- {
- seg->null_bit=0;
- seg->null_pos=0;
- }
- }
+ if (!create(name, table, NULL))
+ file= heap_open(name, mode);
}
- mem_per_row += MY_ALIGN(table->reclength+1, sizeof(char*));
- max_rows = (ulong) (thd->variables.max_heap_table_size / mem_per_row);
- file=heap_open(name,mode,
- table->keys,keydef,
- table->reclength,
- ((table->max_rows < max_rows && table->max_rows) ?
- table->max_rows : max_rows),
- table->min_rows);
- my_free((gptr) keydef,MYF(0));
- if (file)
- info(HA_STATUS_NO_LOCK | HA_STATUS_CONST | HA_STATUS_VARIABLE);
- ref_length=sizeof(HEAP_PTR);
- return (!file ? errno : 0);
+ return (file ? 0 : 1);
}
int ha_heap::close(void)
@@ -125,25 +68,21 @@ int ha_heap::delete_row(const byte * buf)
return heap_delete(file,buf);
}
-int ha_heap::index_read(byte * buf, const byte * key,
- uint key_len __attribute__((unused)),
- enum ha_rkey_function find_flag
- __attribute__((unused)))
+int ha_heap::index_read(byte * buf, const byte * key, uint key_len,
+ enum ha_rkey_function find_flag)
{
- statistic_increment(ha_read_key_count,&LOCK_status);
- int error=heap_rkey(file,buf,active_index, key);
- table->status=error ? STATUS_NOT_FOUND: 0;
+ statistic_increment(ha_read_key_count, &LOCK_status);
+ int error = heap_rkey(file,buf,active_index, key, key_len, find_flag);
+ table->status = error ? STATUS_NOT_FOUND : 0;
return error;
}
int ha_heap::index_read_idx(byte * buf, uint index, const byte * key,
- uint key_len __attribute__((unused)),
- enum ha_rkey_function find_flag
- __attribute__((unused)))
+ uint key_len, enum ha_rkey_function find_flag)
{
- statistic_increment(ha_read_key_count,&LOCK_status);
- int error=heap_rkey(file, buf, index, key);
- table->status=error ? STATUS_NOT_FOUND: 0;
+ statistic_increment(ha_read_key_count, &LOCK_status);
+ int error = heap_rkey(file, buf, index, key, key_len, find_flag);
+ table->status = error ? STATUS_NOT_FOUND : 0;
return error;
}
@@ -167,7 +106,7 @@ int ha_heap::index_prev(byte * buf)
int ha_heap::index_first(byte * buf)
{
statistic_increment(ha_read_first_count,&LOCK_status);
- int error=heap_rfirst(file, buf);
+ int error=heap_rfirst(file, buf, active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
}
@@ -175,7 +114,7 @@ int ha_heap::index_first(byte * buf)
int ha_heap::index_last(byte * buf)
{
statistic_increment(ha_read_last_count,&LOCK_status);
- int error=heap_rlast(file, buf);
+ int error=heap_rlast(file, buf, active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
}
@@ -255,7 +194,6 @@ THR_LOCK_DATA **ha_heap::store_lock(THD *thd,
return to;
}
-
/*
We have to ignore ENOENT entries as the HEAP table is created on open and
not when doing a CREATE on the table.
@@ -272,7 +210,6 @@ int ha_heap::rename_table(const char * from, const char * to)
return heap_rename(from,to);
}
-
ha_rows ha_heap::records_in_range(int inx,
const byte *start_key,uint start_key_len,
enum ha_rkey_function start_search_flag,
@@ -280,18 +217,111 @@ ha_rows ha_heap::records_in_range(int inx,
enum ha_rkey_function end_search_flag)
{
KEY *pos=table->key_info+inx;
- if (start_key_len != end_key_len ||
- start_key_len != pos->key_length ||
- start_search_flag != HA_READ_KEY_EXACT ||
- end_search_flag != HA_READ_AFTER_KEY)
- return HA_POS_ERROR; // Can't only use exact keys
- return 10; // Good guess
+ if (pos->algorithm == HA_KEY_ALG_BTREE)
+ {
+ return hp_rb_records_in_range(file, inx, start_key, start_key_len,
+ start_search_flag, end_key, end_key_len,
+ end_search_flag);
+ }
+ else
+ {
+ if (start_key_len != end_key_len ||
+ start_key_len != pos->key_length ||
+ start_search_flag != HA_READ_KEY_EXACT ||
+ end_search_flag != HA_READ_AFTER_KEY)
+ return HA_POS_ERROR; // Can't only use exact keys
+ return 10; // Good guess
+ }
}
-int ha_heap::create(const char *name, TABLE *form, HA_CREATE_INFO *create_info)
-
+int ha_heap::create(const char *name, TABLE *table,
+ HA_CREATE_INFO *create_info)
{
+ uint key, parts, mem_per_row= 0;
+ ulong max_rows;
+ HP_KEYDEF *keydef;
+ HA_KEYSEG *seg;
char buff[FN_REFLEN];
- return heap_create(fn_format(buff,name,"","",4+2));
+ int error;
+
+ for (key= parts= 0; key < table->keys; key++)
+ {
+ parts+= table->key_info[key].key_parts;
+ if (table->key_info[key].algorithm == HA_KEY_ALG_BTREE)
+ parts++; /* additional HA_KEYTYPE_END keyseg */
+ }
+
+ if (!(keydef= (HP_KEYDEF*) my_malloc(table->keys * sizeof(HP_KEYDEF) +
+ parts * sizeof(HA_KEYSEG),
+ MYF(MY_WME))))
+ return my_errno;
+ seg= my_reinterpret_cast(HA_KEYSEG*) (keydef + table->keys);
+ for (key= 0; key < table->keys; key++)
+ {
+ KEY *pos= table->key_info+key;
+ KEY_PART_INFO *key_part= pos->key_part;
+ KEY_PART_INFO *key_part_end= key_part + pos->key_parts;
+
+ mem_per_row+= (pos->key_length + (sizeof(char*) * 2));
+
+ keydef[key].keysegs= (uint) pos->key_parts;
+ keydef[key].flag= (pos->flags & (HA_NOSAME | HA_NULL_ARE_EQUAL));
+ keydef[key].seg= seg;
+ keydef[key].algorithm= ((pos->algorithm == HA_KEY_ALG_UNDEF) ?
+ HA_KEY_ALG_HASH : pos->algorithm);
+
+ for (; key_part != key_part_end; key_part++, seg++)
+ {
+ uint flag= key_part->key_type;
+ Field *field= key_part->field;
+ if (pos->algorithm == HA_KEY_ALG_BTREE)
+ seg->type= field->key_type();
+ else
+ {
+ if (!f_is_packed(flag) &&
+ f_packtype(flag) == (int) FIELD_TYPE_DECIMAL &&
+ !(flag & FIELDFLAG_BINARY))
+ seg->type= (int) HA_KEYTYPE_TEXT;
+ else
+ seg->type= (int) HA_KEYTYPE_BINARY;
+ }
+ seg->start= (uint) key_part->offset;
+ seg->length= (uint) key_part->length;
+ seg->flag = 0;
+ seg->charset= field->binary() ? NULL : ((Field_str*)field)->charset();
+ if (field->null_ptr)
+ {
+ seg->null_bit= field->null_bit;
+ seg->null_pos= (uint) (field->null_ptr - (uchar*) table->record[0]);
+ }
+ else
+ {
+ seg->null_bit= 0;
+ seg->null_pos= 0;
+ }
+ }
+ if (pos->algorithm == HA_KEY_ALG_BTREE)
+ {
+ /* additional HA_KEYTYPE_END keyseg */
+ seg->type= HA_KEYTYPE_END;
+ seg->length= sizeof(byte*);
+ seg->flag= 0;
+ seg->null_bit= 0;
+ seg++;
+ }
+ }
+ mem_per_row+= MY_ALIGN(table->reclength + 1, sizeof(char*));
+ max_rows = (ulong) (current_thd->variables.max_heap_table_size /
+ mem_per_row);
+ error= heap_create(fn_format(buff,name,"","",4+2),
+ table->keys,keydef, table->reclength,
+ ((table->max_rows < max_rows && table->max_rows) ?
+ table->max_rows : max_rows),
+ table->min_rows);
+ my_free((gptr) keydef, MYF(0));
+ if (file)
+ info(HA_STATUS_NO_LOCK | HA_STATUS_CONST | HA_STATUS_VARIABLE);
+ ref_length= sizeof(HEAP_PTR);
+ return (error);
}
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index b6b86a1988a..d42311b43b6 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -582,9 +582,8 @@ innobase_init(void)
DBUG_RETURN(1);
}
-
- (void) hash_init(&innobase_open_tables,32,0,0,
- (hash_get_key) innobase_get_key,0,0);
+ (void) hash_init(&innobase_open_tables,system_charset_info,32,0,0,
+ (hash_get_key) innobase_get_key,0,0);
pthread_mutex_init(&innobase_mutex,MY_MUTEX_INIT_FAST);
/* If this is a replication slave and we needed to do a crash recovery,
@@ -1184,7 +1183,10 @@ innobase_mysql_cmp(
case FIELD_TYPE_STRING:
case FIELD_TYPE_VAR_STRING:
- ret = my_sortncmp((const char*) a, a_length,
+ // BAR TODO: Discuss with heikki.tuuri@innodb.com
+ // so that he sends CHARSET_INFO for the field to this function.
+ ret = my_sortncmp(default_charset_info,
+ (const char*) a, a_length,
(const char*) b, b_length);
if (ret < 0) {
return(-1);
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 6ff59babeb4..e9ef5b4ce12 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -28,6 +28,7 @@
#include "../srclib/myisam/myisamdef.h"
#else
#include "../myisam/myisamdef.h"
+#include "../myisam/rt_index.h"
#endif
ulong myisam_recover_options= HA_RECOVER_NONE;
@@ -122,8 +123,12 @@ const char **ha_myisam::bas_ext() const
const char *ha_myisam::index_type(uint key_number)
{
- return ((table->key_info[key_number].flags & HA_FULLTEXT) ?
+ return ((table->key_info[key_number].flags & HA_FULLTEXT) ?
"FULLTEXT" :
+ (table->key_info[key_number].flags & HA_SPATIAL) ?
+ "SPATIAL" :
+ (table->key_info[key_number].algorithm == HA_KEY_ALG_RTREE) ?
+ "RTREE" :
"BTREE");
}
@@ -761,7 +766,7 @@ int ha_myisam::index_read(byte * buf, const byte * key,
uint key_len, enum ha_rkey_function find_flag)
{
statistic_increment(ha_read_key_count,&LOCK_status);
- int error=mi_rkey(file,buf,active_index, key, key_len, find_flag);
+ int error=mi_rkey(file,buf,active_index, key, key_len, (enum ha_rkey_function)find_flag);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
}
@@ -770,7 +775,7 @@ int ha_myisam::index_read_idx(byte * buf, uint index, const byte * key,
uint key_len, enum ha_rkey_function find_flag)
{
statistic_increment(ha_read_key_count,&LOCK_status);
- int error=mi_rkey(file,buf,index, key, key_len, find_flag);
+ int error=mi_rkey(file,buf,index, key, key_len, (enum ha_rkey_function)find_flag);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
}
@@ -1000,7 +1005,7 @@ int ha_myisam::create(const char *name, register TABLE *table,
KEY *pos;
MI_KEYDEF *keydef;
MI_COLUMNDEF *recinfo,*recinfo_pos;
- MI_KEYSEG *keyseg;
+ HA_KEYSEG *keyseg;
uint options=table->db_options_in_use;
DBUG_ENTER("ha_myisam::create");
@@ -1009,14 +1014,16 @@ int ha_myisam::create(const char *name, register TABLE *table,
&recinfo,(table->fields*2+2)*sizeof(MI_COLUMNDEF),
&keydef, table->keys*sizeof(MI_KEYDEF),
&keyseg,
- ((table->key_parts + table->keys) * sizeof(MI_KEYSEG)),
+ ((table->key_parts + table->keys) * sizeof(HA_KEYSEG)),
0)))
DBUG_RETURN(1);
pos=table->key_info;
for (i=0; i < table->keys ; i++, pos++)
{
- keydef[i].flag= (pos->flags & (HA_NOSAME | HA_FULLTEXT));
+ keydef[i].flag= (pos->flags & (HA_NOSAME | HA_FULLTEXT | HA_SPATIAL));
+ keydef[i].key_alg=pos->algorithm == HA_KEY_ALG_UNDEF ?
+ HA_KEY_ALG_BTREE : pos->algorithm;
keydef[i].seg=keyseg;
keydef[i].keysegs=pos->key_parts;
for (j=0 ; j < pos->key_parts ; j++)
@@ -1051,7 +1058,8 @@ int ha_myisam::create(const char *name, register TABLE *table,
keydef[i].seg[j].start= pos->key_part[j].offset;
keydef[i].seg[j].length= pos->key_part[j].length;
keydef[i].seg[j].bit_start=keydef[i].seg[j].bit_end=0;
- keydef[i].seg[j].language=MY_CHARSET_CURRENT;
+ keydef[i].seg[j].language = field->binary() ? MY_CHARSET_CURRENT :
+ ((Field_str*)field)->charset()->number;
if (field->null_ptr)
{
diff --git a/sql/handler.cc b/sql/handler.cc
index 7aba6817eca..f60c3449075 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -688,7 +688,7 @@ void handler::print_error(int error, myf errflag)
{
/* Write the dupplicated key in the error message */
char key[MAX_KEY_LENGTH];
- String str(key,sizeof(key));
+ String str(key,sizeof(key),default_charset_info);
key_unpack(&str,table,(uint) key_nr);
uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(ER(ER_DUP_ENTRY));
if (str.length() >= max_length)
diff --git a/sql/handler.h b/sql/handler.h
index 4e854aa00a6..adbfff8c55c 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -137,6 +137,7 @@ enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED,
#define HA_CREATE_USED_MAX_ROWS 32
#define HA_CREATE_USED_AVG_ROW_LENGTH 64
#define HA_CREATE_USED_PACK_KEYS 128
+#define HA_CREATE_USED_CHARSET 256
typedef struct st_thd_trans {
void *bdb_tid;
@@ -149,22 +150,23 @@ enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED,
typedef struct st_ha_create_information
{
- ulong table_options;
- enum db_type db_type;
- enum row_type row_type;
- ulong avg_row_length;
- ulonglong max_rows,min_rows;
- ulonglong auto_increment_value;
+ CHARSET_INFO *table_charset;
char *comment,*password;
char *data_file_name, *index_file_name;
char *create_statement;
- uint options; /* OR of HA_CREATE_ options */
- uint raid_type,raid_chunks;
+ ulonglong max_rows,min_rows;
+ ulonglong auto_increment_value;
+ ulong table_options;
+ ulong avg_row_length;
ulong raid_chunksize;
- bool if_not_exists;
ulong used_fields;
SQL_LIST merge_list;
+ enum db_type db_type;
+ enum row_type row_type;
+ uint options; /* OR of HA_CREATE_ options */
+ uint raid_type,raid_chunks;
uint merge_insert_method;
+ bool if_not_exists;
} HA_CREATE_INFO;
diff --git a/sql/hash_filo.h b/sql/hash_filo.h
index b8d45f0d3be..4d746d9b9bd 100644
--- a/sql/hash_filo.h
+++ b/sql/hash_filo.h
@@ -75,8 +75,8 @@ public:
if (!locked)
(void) pthread_mutex_lock(&lock);
(void) hash_free(&cache);
- (void) hash_init(&cache,size,key_offset, key_length, get_key, free_element,
- 0);
+ (void) hash_init(&cache,system_charset_info,size,key_offset,
+ key_length, get_key, free_element,0);
if (!locked)
(void) pthread_mutex_unlock(&lock);
first_link=last_link=0;
diff --git a/sql/hostname.cc b/sql/hostname.cc
index abccc466a22..3da752f3b64 100644
--- a/sql/hostname.cc
+++ b/sql/hostname.cc
@@ -221,10 +221,10 @@ my_string ip_to_hostname(struct in_addr *in, uint *errors)
/* Don't accept hostnames that starts with digits because they may be
false ip:s */
- if (isdigit(name[0]))
+ if (my_isdigit(system_charset_info,name[0]))
{
char *pos;
- for (pos= name+1 ; isdigit(*pos); pos++) ;
+ for (pos= name+1 ; my_isdigit(system_charset_info,*pos); pos++) ;
if (*pos == '.')
{
DBUG_PRINT("error",("mysqld doesn't accept hostnames that starts with a number followed by a '.'"));
diff --git a/sql/init.cc b/sql/init.cc
index df06ddd41ef..052ee16925e 100644
--- a/sql/init.cc
+++ b/sql/init.cc
@@ -24,6 +24,7 @@ void unireg_init(ulong options)
{
uint i;
double nr;
+ CHARSET_INFO *cs;
DBUG_ENTER("unireg_init");
MYSYS_PROGRAM_DONT_USE_CURSES();
@@ -52,17 +53,6 @@ void unireg_init(ulong options)
}
specialflag|=options; /* Set options from argv */
- // The following is needed because of like optimization in select.cc
-
- uchar max_char=my_sort_order[(uchar) max_sort_char];
- for (i = 0; i < 256; i++)
- {
- if ((uchar) my_sort_order[i] > max_char)
- {
- max_char=(uchar) my_sort_order[i];
- max_sort_char= (char) i;
- }
- }
thread_stack_min=thread_stack - STACK_MIN_SIZE;
DBUG_VOID_RETURN;
}
diff --git a/sql/item.cc b/sql/item.cc
index bb39a141e9f..7693ef428c6 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -50,7 +50,7 @@ void Item::set_name(char *str,uint length)
name=str; // Used by AS
else
{
- while (length && !isgraph(*str))
+ while (length && !my_isgraph(system_charset_info,*str))
{ // Fix problem with yacc
length--;
str++;
@@ -66,7 +66,7 @@ void Item::set_name(char *str,uint length)
bool Item::eq(const Item *item, bool binary_cmp) const
{
return type() == item->type() && name && item->name &&
- !my_strcasecmp(name,item->name);
+ !my_strcasecmp(system_charset_info,name,item->name);
}
bool Item_string::eq(const Item *item, bool binary_cmp) const
@@ -89,7 +89,7 @@ bool Item_string::eq(const Item *item, bool binary_cmp) const
bool Item::get_date(TIME *ltime,bool fuzzydate)
{
char buff[40];
- String tmp(buff,sizeof(buff)),*res;
+ String tmp(buff,sizeof(buff),default_charset_info),*res;
if (!(res=val_str(&tmp)) ||
str_to_TIME(res->ptr(),res->length(),ltime,fuzzydate) == TIMESTAMP_NONE)
{
@@ -107,7 +107,7 @@ bool Item::get_date(TIME *ltime,bool fuzzydate)
bool Item::get_time(TIME *ltime)
{
char buff[40];
- String tmp(buff,sizeof(buff)),*res;
+ String tmp(buff,sizeof(buff),default_charset_info),*res;
if (!(res=val_str(&tmp)) ||
str_to_time(res->ptr(),res->length(),ltime))
{
@@ -133,6 +133,9 @@ void Item_field::set_field(Field *field_par)
field_name=field_par->field_name;
binary=field_par->binary();
unsigned_flag=test(field_par->flags & UNSIGNED_FLAG);
+ /* For string fields copy character set from original field */
+ if (!field_par->binary())
+ str_value.set_charset(((Field_str*)field_par)->charset());
}
const char *Item_ident::full_name() const
@@ -287,6 +290,137 @@ String *Item_null::val_str(String *str)
{ null_value=1; return 0;}
+/* Item_param related */
+void Item_param::set_null()
+{
+ maybe_null=null_value=1;
+}
+
+void Item_param::set_int(longlong i)
+{
+ int_value=(longlong)i;
+ item_result_type = INT_RESULT;
+ item_type = INT_ITEM;
+}
+
+void Item_param::set_double(double i)
+{
+ double value = (double)i;
+ real_value=value;
+ item_result_type = REAL_RESULT;
+ item_type = REAL_ITEM;
+}
+
+void Item_param::set_double(float i)
+{
+ float value = (float)i;
+ real_value=(double)value;
+ item_result_type = REAL_RESULT;
+ item_type = REAL_ITEM;
+}
+
+void Item_param::set_value(const char *str, uint length)
+{
+ str_value.set(str,length,default_charset_info);
+ item_result_type = STRING_RESULT;
+ item_type = STRING_ITEM;
+}
+
+void Item_param::set_longdata(const char *str, ulong length)
+{
+ /* TODO: Fix this for binary handling by making use of
+ buffer_type..
+ */
+ str_value.append(str,length);
+}
+
+void Item_param::set_long_end()
+{
+ long_data_supplied = true;
+ item_result_type = STRING_RESULT;
+};
+
+int Item_param::save_in_field(Field *field)
+{
+ if (null_value)
+ return set_field_to_null(field);
+
+ field->set_notnull();
+ if (item_result_type == INT_RESULT)
+ {
+ longlong nr=val_int();
+ return (field->store(nr)) ? -1 : 0;
+ }
+ if (item_result_type == REAL_RESULT)
+ {
+ double nr=val();
+ return (field->store(nr)) ? -1 : 0;
+ }
+ String *result;
+ CHARSET_INFO *cs=default_charset_info;//fix this
+ result=val_str(&str_value);
+ return (field->store(result->ptr(),result->length(),cs)) ? -1 : 0;
+}
+
+void Item_param::make_field(Send_field *tmp_field)
+{
+ init_make_field(tmp_field,FIELD_TYPE_STRING);
+}
+
+double Item_param::val()
+{
+ /* Cross check whether we need need this conversions ? or direct
+ return(real_value) is enough ?
+ */
+
+ switch(item_result_type) {
+
+ case STRING_RESULT:
+ return (double)atof(str_value.ptr());
+ case INT_RESULT:
+ return (double)int_value;
+ default:
+ return real_value;
+ }
+}
+
+longlong Item_param::val_int()
+{
+ /* Cross check whether we need need this conversions ? or direct
+ return(int_value) is enough ?
+ */
+
+ switch(item_result_type) {
+
+ case STRING_RESULT:
+ return (longlong)strtoll(str_value.ptr(),(char**) 0,10);
+ case REAL_RESULT:
+ return (longlong) (real_value+(real_value > 0 ? 0.5 : -0.5));
+ default:
+ return int_value;
+ }
+}
+
+String *Item_param::val_str(String* str)
+{
+ /* Cross check whether we need need this conversions ? or direct
+ return(&str_value) is enough ?
+ */
+
+ switch(item_result_type) {
+
+ case INT_RESULT:
+ str->set(int_value);
+ return str;
+ case REAL_RESULT:
+ str->set(real_value);
+ return str;
+ default:
+ return (String*) &str_value;
+ }
+}
+/* End of Item_param related */
+
void Item_copy_string::copy()
{
String *res=item->val_str(&str_value);
@@ -309,18 +443,58 @@ String *Item_copy_string::val_str(String *str)
/* ARGSUSED */
bool Item::fix_fields(THD *thd,
- struct st_table_list *list)
+ struct st_table_list *list,
+ Item ** ref)
{
return 0;
}
-bool Item_field::fix_fields(THD *thd,TABLE_LIST *tables)
+bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
if (!field) // If field is not checked
{
Field *tmp;
if (!(tmp=find_field_in_tables(thd,this,tables)))
- return 1;
+ {
+ /*
+ We can't find table field in table list of current select,
+ consequently we have to find it in outer subselect(s).
+ We can't join lists of outer & current select, because of scope
+ of view rules. For example if both tables (outer & current) have
+ field 'field' it is not mistake to refer to this field without
+ mention of table name, but if we join tables in one list it will
+ cause error ER_NON_UNIQ_ERROR in find_field_in_tables.
+ */
+ SELECT_LEX *last= 0;
+ for (SELECT_LEX *sl= thd->lex.select->outer_select();
+ sl && !tmp;
+ sl= sl->outer_select())
+ tmp=find_field_in_tables(thd, this,
+ (TABLE_LIST*)(last= sl)->table_list.first);
+ if (!tmp)
+ return 1;
+ else
+ {
+ depended_from= last;
+ /*
+ Mark all selects from resolved to 1 before select where was
+ found table as depended (of select where was found table)
+ */
+ for (SELECT_LEX *s= thd->lex.select;
+ s &&s != last;
+ s= s->outer_select())
+ if( !s->depended )
+ {
+ s->depended= 1; //Select is depended of outer select
+ //Tables will be reopened many times
+ for (TABLE_LIST *tbl=
+ (TABLE_LIST*)s->table_list.first;
+ tbl;
+ tbl= tbl->next)
+ tbl->shared= 1;
+ }
+ }
+ }
set_field(tmp);
}
else if (thd && thd->set_query_id && field->query_id != thd->query_id)
@@ -331,13 +505,24 @@ bool Item_field::fix_fields(THD *thd,TABLE_LIST *tables)
table->used_fields++;
table->used_keys&=field->part_of_key;
}
+ if (depended_from != 0 && depended_from->having_fix_field)
+ {
+ *ref= new Item_ref((char *)db_name, (char *)table_name,
+ (char *)field_name);
+ if (!*ref)
+ return 1;
+ return (*ref)->fix_fields(thd, tables, ref);
+ }
return 0;
}
void Item::init_make_field(Send_field *tmp_field,
enum enum_field_types field_type)
-{
+{
+ tmp_field->db_name=(char*) "";
+ tmp_field->org_table_name=(char*) "";
+ tmp_field->org_col_name=(char*) "";
tmp_field->table_name=(char*) "";
tmp_field->col_name=name;
tmp_field->flags=maybe_null ? 0 : NOT_NULL_FLAG;
@@ -429,7 +614,7 @@ void Item_field::save_org_in_field(Field *to)
}
}
-bool Item_field::save_in_field(Field *to)
+int Item_field::save_in_field(Field *to)
{
if (result_field->is_null())
{
@@ -446,27 +631,29 @@ bool Item_field::save_in_field(Field *to)
}
-bool Item_null::save_in_field(Field *field)
+int Item_null::save_in_field(Field *field)
{
return set_field_to_null(field);
}
-bool Item::save_in_field(Field *field)
+int Item::save_in_field(Field *field)
{
+ int error;
if (result_type() == STRING_RESULT ||
result_type() == REAL_RESULT &&
field->result_type() == STRING_RESULT)
{
String *result;
+ CHARSET_INFO *cs=field->binary()?default_charset_info:((Field_str*)field)->charset();
char buff[MAX_FIELD_WIDTH]; // Alloc buffer for small columns
- str_value.set_quick(buff,sizeof(buff));
+ str_value.set_quick(buff,sizeof(buff),cs);
result=val_str(&str_value);
if (null_value)
return set_field_to_null(field);
field->set_notnull();
- field->store(result->ptr(),result->length());
- str_value.set_quick(0, 0);
+ error=field->store(result->ptr(),result->length(),cs);
+ str_value.set_quick(0, 0, cs);
}
else if (result_type() == REAL_RESULT)
{
@@ -474,7 +661,7 @@ bool Item::save_in_field(Field *field)
if (null_value)
return set_field_to_null(field);
field->set_notnull();
- field->store(nr);
+ error=field->store(nr);
}
else
{
@@ -482,40 +669,38 @@ bool Item::save_in_field(Field *field)
if (null_value)
return set_field_to_null(field);
field->set_notnull();
- field->store(nr);
+ error=field->store(nr);
}
- return 0;
+ return (error) ? -1 : 0;
}
-bool Item_string::save_in_field(Field *field)
+int Item_string::save_in_field(Field *field)
{
String *result;
+ CHARSET_INFO *cs=field->binary()?default_charset_info:((Field_str*)field)->charset();
result=val_str(&str_value);
if (null_value)
return set_field_to_null(field);
field->set_notnull();
- field->store(result->ptr(),result->length());
- return 0;
+ return (field->store(result->ptr(),result->length(),cs)) ? -1 : 0;
}
-bool Item_int::save_in_field(Field *field)
+int Item_int::save_in_field(Field *field)
{
longlong nr=val_int();
if (null_value)
return set_field_to_null(field);
field->set_notnull();
- field->store(nr);
- return 0;
+ return (field->store(nr)) ? -1 : 0;
}
-bool Item_real::save_in_field(Field *field)
+int Item_real::save_in_field(Field *field)
{
double nr=val();
if (null_value)
return set_field_to_null(field);
field->set_notnull();
- field->store(nr);
- return 0;
+ return (field->store(nr)) ? -1 : 0;
}
/****************************************************************************
@@ -531,14 +716,14 @@ inline uint char_val(char X)
X-'a'+10);
}
-Item_varbinary::Item_varbinary(const char *str, uint str_length)
+Item_varbinary::Item_varbinary(const char *str, uint str_length, CHARSET_INFO *cs)
{
name=(char*) str-2; // Lex makes this start with 0x
max_length=(str_length+1)/2;
char *ptr=(char*) sql_alloc(max_length+1);
if (!ptr)
return;
- str_value.set(ptr,max_length);
+ str_value.set(ptr,max_length,cs);
char *end=ptr+max_length;
if (max_length*2 != str_length)
*ptr++=char_val(*str++); // Not even, assume 0 prefix
@@ -563,19 +748,21 @@ longlong Item_varbinary::val_int()
}
-bool Item_varbinary::save_in_field(Field *field)
+int Item_varbinary::save_in_field(Field *field)
{
+ int error;
+ CHARSET_INFO *cs=field->binary()?default_charset_info:((Field_str*)field)->charset();
field->set_notnull();
if (field->result_type() == STRING_RESULT)
{
- field->store(str_value.ptr(),str_value.length());
+ error=field->store(str_value.ptr(),str_value.length(),cs);
}
else
{
longlong nr=val_int();
- field->store(nr);
+ error=field->store(nr);
}
- return 0;
+ return (error) ? -1 : 0;
}
@@ -592,7 +779,7 @@ bool Item::send(THD *thd, String *packet)
{
char buff[MAX_FIELD_WIDTH];
CONVERT *convert;
- String s(buff,sizeof(buff)),*res;
+ String s(buff,sizeof(buff),packet->charset()),*res;
if (!(res=val_str(&s)))
return net_store_null(packet);
if ((convert=thd->variables.convert_set))
@@ -610,12 +797,50 @@ bool Item_null::send(THD *thd, String *packet)
Find field in select list having the same name
*/
-bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables)
+bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
{
if (!ref)
{
- if (!(ref=find_item_in_list(this,thd->lex.select->item_list)))
- return 1;
+ if (!(ref= find_item_in_list(this,thd->lex.select->item_list)))
+ {
+ /*
+ We can't find table field in table list of current select,
+ consequently we have to find it in outer subselect(s).
+ We can't join lists of outer & current select, because of scope
+ of view rules. For example if both tables (outer & current) have
+ field 'field' it is not mistake to refer to this field without
+ mention of table name, but if we join tables in one list it will
+ cause error ER_NON_UNIQ_ERROR in find_field_in_tables.
+ */
+ SELECT_LEX *last=0;
+ for (SELECT_LEX *sl= thd->lex.select->outer_select();
+ sl && !ref;
+ sl= sl->outer_select())
+ ref= find_item_in_list(this, (last= sl)->item_list);
+ if (!ref)
+ return 1;
+ else
+ {
+ depended_from= last;
+ /*
+ Mark all selects from resolved to 1 before select where was
+ found table as depended (of select where was found table)
+ */
+ for (SELECT_LEX *s= thd->lex.select;
+ s &&s != last;
+ s= s->outer_select())
+ if( !s->depended )
+ {
+ s->depended= 1; //Select is depended of outer select
+ //Tables will be reopened many times
+ for (TABLE_LIST *tbl=
+ (TABLE_LIST*)s->table_list.first;
+ tbl;
+ tbl= tbl->next)
+ tbl->shared= 1;
+ }
+ }
+ }
max_length= (*ref)->max_length;
maybe_null= (*ref)->maybe_null;
decimals= (*ref)->decimals;
@@ -651,7 +876,7 @@ Item *resolve_const_item(Item *item,Item *comp_item)
if (res_type == STRING_RESULT)
{
char buff[MAX_FIELD_WIDTH];
- String tmp(buff,sizeof(buff)),*result;
+ String tmp(buff,sizeof(buff),default_charset_info),*result;
result=item->val_str(&tmp);
if (item->null_value)
{
@@ -665,7 +890,7 @@ Item *resolve_const_item(Item *item,Item *comp_item)
#ifdef DELETE_ITEMS
delete item;
#endif
- return new Item_string(name,tmp_str,length);
+ return new Item_string(name,tmp_str,length,default_charset_info);
}
if (res_type == INT_RESULT)
{
@@ -706,8 +931,8 @@ bool field_is_equal_to_item(Field *field,Item *item)
{
char item_buff[MAX_FIELD_WIDTH];
char field_buff[MAX_FIELD_WIDTH];
- String item_tmp(item_buff,sizeof(item_buff)),*item_result;
- String field_tmp(field_buff,sizeof(field_buff));
+ String item_tmp(item_buff,sizeof(item_buff),default_charset_info),*item_result;
+ String field_tmp(field_buff,sizeof(field_buff),default_charset_info);
item_result=item->val_str(&item_tmp);
if (item->null_value)
return 1; // This must be true
diff --git a/sql/item.h b/sql/item.h
index 70729afe28e..206d7b5bd78 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -32,7 +32,8 @@ public:
enum Type {FIELD_ITEM,FUNC_ITEM,SUM_FUNC_ITEM,STRING_ITEM,
INT_ITEM,REAL_ITEM,NULL_ITEM,VARBIN_ITEM,
COPY_STR_ITEM,FIELD_AVG_ITEM, DEFAULT_ITEM,
- PROC_ITEM,COND_ITEM,REF_ITEM,FIELD_STD_ITEM, CONST_ITEM};
+ PROC_ITEM,COND_ITEM,REF_ITEM,FIELD_STD_ITEM, CONST_ITEM,
+ SUBSELECT_ITEM};
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
String str_value; /* used to store value */
@@ -46,14 +47,13 @@ public:
my_bool unsigned_flag;
my_bool with_sum_func;
-
// alloc & destruct is done as start of select using sql_alloc
Item();
virtual ~Item() { name=0; } /*lint -e1509 */
void set_name(char* str,uint length=0);
void init_make_field(Send_field *tmp_field,enum enum_field_types type);
- virtual bool fix_fields(THD *,struct st_table_list *);
- virtual bool save_in_field(Field *field);
+ virtual bool fix_fields(THD *, struct st_table_list *, Item **);
+ virtual int save_in_field(Field *field);
virtual void save_org_in_field(Field *field)
{ (void) save_in_field(field); }
virtual bool send(THD *thd, String *str);
@@ -86,15 +86,18 @@ public:
};
+class st_select_lex;
class Item_ident :public Item
{
public:
const char *db_name;
const char *table_name;
const char *field_name;
+ st_select_lex *depended_from;
Item_ident(const char *db_name_par,const char *table_name_par,
const char *field_name_par)
- :db_name(db_name_par),table_name(table_name_par),field_name(field_name_par)
+ :db_name(db_name_par),table_name(table_name_par),
+ field_name(field_name_par), depended_from(0)
{ name = (char*) field_name_par; }
const char *full_name() const;
unsigned int size_of() { return sizeof(*this);}
@@ -126,8 +129,8 @@ public:
return result_field->send(thd,str_arg);
}
void make_field(Send_field *field);
- bool fix_fields(THD *,struct st_table_list *);
- bool save_in_field(Field *field);
+ bool fix_fields(THD *, struct st_table_list *, Item **);
+ int save_in_field(Field *field);
void save_org_in_field(Field *field);
table_map used_tables() const;
enum Item_result result_type () const
@@ -153,7 +156,7 @@ public:
longlong val_int();
String *val_str(String *str);
void make_field(Send_field *field);
- bool save_in_field(Field *field);
+ int save_in_field(Field *field);
enum Item_result result_type () const
{ return STRING_RESULT; }
bool send(THD *thd, String *str);
@@ -163,6 +166,40 @@ public:
unsigned int size_of() { return sizeof(*this);}
};
+class Item_param :public Item
+{
+public:
+ longlong int_value;
+ double real_value;
+ enum Item_result item_result_type;
+ enum Type item_type;
+ enum enum_field_types buffer_type;
+ my_bool long_data_supplied;
+
+ Item_param(char *name_par=0){
+ name= name_par ? name_par : (char*) "?";
+ long_data_supplied = false;
+ item_type = STRING_ITEM; item_result_type = STRING_RESULT;
+ }
+ enum Type type() const { return item_type; }
+ double val();
+ longlong val_int();
+ String *val_str(String*);
+ void make_field(Send_field *field);
+ int save_in_field(Field *field);
+ void set_null();
+ void set_int(longlong i);
+ void set_double(float i);
+ void set_double(double i);
+ void set_value(const char *str, uint length);
+ void set_long_str(const char *str, ulong length);
+ void set_long_binary(const char *str, ulong length);
+ void set_longdata(const char *str, ulong length);
+ void set_long_end();
+ enum Item_result result_type () const
+ { return item_result_type; }
+ Item *new_item() { return new Item_param(name); }
+};
class Item_int :public Item
{
@@ -186,7 +223,7 @@ public:
double val() { return (double) value; }
String *val_str(String*);
void make_field(Send_field *field);
- bool save_in_field(Field *field);
+ int save_in_field(Field *field);
bool basic_const_item() const { return 1; }
Item *new_item() { return new Item_int(name,value,max_length); }
void print(String *str);
@@ -228,7 +265,7 @@ public:
max_length=length;
}
Item_real(double value_par) :value(value_par) {}
- bool save_in_field(Field *field);
+ int save_in_field(Field *field);
enum Type type() const { return REAL_ITEM; }
double val() { return value; }
longlong val_int() { return (longlong) (value+(value > 0 ? 0.5 : -0.5));}
@@ -254,16 +291,16 @@ public:
class Item_string :public Item
{
public:
- Item_string(const char *str,uint length)
+ Item_string(const char *str,uint length,CHARSET_INFO *cs)
{
- str_value.set(str,length);
+ str_value.set(str,length,cs);
max_length=length;
name=(char*) str_value.ptr();
decimals=NOT_FIXED_DEC;
}
- Item_string(const char *name_par,const char *str,uint length)
+ Item_string(const char *name_par,const char *str,uint length,CHARSET_INFO *cs)
{
- str_value.set(str,length);
+ str_value.set(str,length,cs);
max_length=length;
name=(char*) name_par;
decimals=NOT_FIXED_DEC;
@@ -273,12 +310,12 @@ public:
double val() { return atof(str_value.ptr()); }
longlong val_int() { return strtoll(str_value.ptr(),(char**) 0,10); }
String *val_str(String*) { return (String*) &str_value; }
- bool save_in_field(Field *field);
+ int save_in_field(Field *field);
void make_field(Send_field *field);
enum Item_result result_type () const { return STRING_RESULT; }
bool basic_const_item() const { return 1; }
bool eq(const Item *item, bool binary_cmp) const;
- Item *new_item() { return new Item_string(name,str_value.ptr(),max_length); }
+ Item *new_item() { return new Item_string(name,str_value.ptr(),max_length,default_charset_info); }
String *const_string() { return &str_value; }
inline void append(char *str,uint length) { str_value.append(str,length); }
void print(String *str);
@@ -312,7 +349,7 @@ public:
class Item_datetime :public Item_string
{
public:
- Item_datetime(const char *item_name): Item_string(item_name,"",0)
+ Item_datetime(const char *item_name): Item_string(item_name,"",0,default_charset_info)
{ max_length=19;}
void make_field(Send_field *field);
unsigned int size_of() { return sizeof(*this);}
@@ -321,7 +358,7 @@ public:
class Item_empty_string :public Item_string
{
public:
- Item_empty_string(const char *header,uint length) :Item_string("",0)
+ Item_empty_string(const char *header,uint length) :Item_string("",0,default_charset_info)
{ name=(char*) header; max_length=length;}
unsigned int size_of() { return sizeof(*this);}
};
@@ -329,13 +366,13 @@ public:
class Item_varbinary :public Item
{
public:
- Item_varbinary(const char *str,uint str_length);
+ Item_varbinary(const char *str,uint str_length,CHARSET_INFO *cs);
~Item_varbinary() {}
enum Type type() const { return VARBIN_ITEM; }
double val() { return (double) Item_varbinary::val_int(); }
longlong val_int();
String *val_str(String*) { return &str_value; }
- bool save_in_field(Field *field);
+ int save_in_field(Field *field);
void make_field(Send_field *field);
enum Item_result result_type () const { return INT_RESULT; }
unsigned int size_of() { return sizeof(*this);}
@@ -396,8 +433,8 @@ public:
}
bool send(THD *thd, String *tmp) { return (*ref)->send(thd, tmp); }
void make_field(Send_field *field) { (*ref)->make_field(field); }
- bool fix_fields(THD *,struct st_table_list *);
- bool save_in_field(Field *field) { return (*ref)->save_in_field(field); }
+ bool fix_fields(THD *, struct st_table_list *, Item **);
+ int save_in_field(Field *field) { return (*ref)->save_in_field(field); }
void save_org_in_field(Field *field) { (*ref)->save_org_in_field(field); }
enum Item_result result_type () const { return (*ref)->result_type(); }
table_map used_tables() const { return (*ref)->used_tables(); }
@@ -417,7 +454,7 @@ class Item_int_with_ref :public Item_int
public:
Item_int_with_ref(longlong i, Item *ref_arg) :Item_int(i), ref(ref_arg)
{}
- bool save_in_field(Field *field)
+ int save_in_field(Field *field)
{
return ref->save_in_field(field);
}
@@ -425,12 +462,14 @@ public:
};
+#include "spatial.h"
#include "item_sum.h"
#include "item_func.h"
#include "item_cmpfunc.h"
#include "item_strfunc.h"
#include "item_timefunc.h"
#include "item_uniq.h"
+#include "item_subselect.h"
class Item_copy_string :public Item
{
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 923bbccde24..10215f406c3 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -24,6 +24,7 @@
#include "mysql_priv.h"
#include <m_ctype.h>
+
/*
Test functions
These returns 0LL if false and 1LL if true and null if some arg is null
@@ -42,14 +43,17 @@ longlong Item_func_not::val_int()
This is done when comparing DATE's of different formats and
also when comparing bigint to strings (in which case the string
is converted once to a bigint).
+
+ RESULT VALUES
+ 0 Can't convert item
+ 1 Item was replaced with an integer version of the item
*/
static bool convert_constant_item(Field *field, Item **item)
{
if ((*item)->const_item() && (*item)->type() != Item::INT_ITEM)
{
- if (!(*item)->save_in_field(field) &&
- !((*item)->null_value))
+ if (!(*item)->save_in_field(field) && !((*item)->null_value))
{
Item *tmp=new Item_int_with_ref(field->val_int(), *item);
if (tmp)
@@ -716,7 +720,7 @@ String *Item_func_case::val_str(String *str)
longlong Item_func_case::val_int()
{
char buff[MAX_FIELD_WIDTH];
- String dummy_str(buff,sizeof(buff));
+ String dummy_str(buff,sizeof(buff),default_charset_info);
Item *item=find_item(&dummy_str);
longlong res;
@@ -733,7 +737,7 @@ longlong Item_func_case::val_int()
double Item_func_case::val()
{
char buff[MAX_FIELD_WIDTH];
- String dummy_str(buff,sizeof(buff));
+ String dummy_str(buff,sizeof(buff),default_charset_info);
Item *item=find_item(&dummy_str);
double res;
@@ -749,12 +753,12 @@ double Item_func_case::val()
bool
-Item_func_case::fix_fields(THD *thd,TABLE_LIST *tables)
+Item_func_case::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
- if (first_expr && first_expr->fix_fields(thd,tables) ||
- else_expr && else_expr->fix_fields(thd,tables))
+ if (first_expr && first_expr->fix_fields(thd, tables, &first_expr) ||
+ else_expr && else_expr->fix_fields(thd, tables, &else_expr))
return 1;
- if (Item_func::fix_fields(thd,tables))
+ if (Item_func::fix_fields(thd, tables, ref))
return 1;
if (first_expr)
{
@@ -905,7 +909,7 @@ int in_vector::find(Item *item)
in_string::in_string(uint elements,qsort_cmp cmp_func)
- :in_vector(elements,sizeof(String),cmp_func),tmp(buff,sizeof(buff))
+ :in_vector(elements,sizeof(String),cmp_func),tmp(buff,sizeof(buff),default_charset_info)
{}
in_string::~in_string()
@@ -920,6 +924,9 @@ void in_string::set(uint pos,Item *item)
String *res=item->val_str(str);
if (res && res != str)
*str= *res;
+ // BAR TODO: I'm not sure this is absolutely correct
+ if (!str->charset())
+ str->set_charset(default_charset_info);
}
byte *in_string::get_value(Item *item)
@@ -1093,7 +1100,7 @@ longlong Item_func_bit_and::val_int()
bool
-Item_cond::fix_fields(THD *thd,TABLE_LIST *tables)
+Item_cond::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
List_iterator<Item> li(list);
Item *item;
@@ -1115,7 +1122,7 @@ Item_cond::fix_fields(THD *thd,TABLE_LIST *tables)
#endif
item= *li.ref(); // new current item
}
- if (item->fix_fields(thd,tables))
+ if (item->fix_fields(thd, tables, li.ref()))
return 1; /* purecov: inspected */
used_tables_cache|=item->used_tables();
with_sum_func= with_sum_func || item->with_sum_func;
@@ -1291,9 +1298,9 @@ Item_func::optimize_type Item_func_like::select_optimize() const
return OPTIMIZE_NONE;
}
-bool Item_func_like::fix_fields(THD *thd,struct st_table_list *tlist)
+bool Item_func_like::fix_fields(THD *thd, TABLE_LIST *tlist, Item ** ref)
{
- if (Item_bool_func2::fix_fields(thd, tlist))
+ if (Item_bool_func2::fix_fields(thd, tlist, ref))
return 1;
/*
@@ -1343,9 +1350,10 @@ bool Item_func_like::fix_fields(THD *thd,struct st_table_list *tlist)
#ifdef USE_REGEX
bool
-Item_func_regex::fix_fields(THD *thd,TABLE_LIST *tables)
+Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
- if (args[0]->fix_fields(thd,tables) || args[1]->fix_fields(thd,tables))
+ if (args[0]->fix_fields(thd, tables, args) ||
+ args[1]->fix_fields(thd,tables, args + 1))
return 1; /* purecov: inspected */
with_sum_func=args[0]->with_sum_func || args[1]->with_sum_func;
max_length=1; decimals=0;
@@ -1355,7 +1363,7 @@ Item_func_regex::fix_fields(THD *thd,TABLE_LIST *tables)
if (!regex_compiled && args[1]->const_item())
{
char buff[MAX_FIELD_WIDTH];
- String tmp(buff,sizeof(buff));
+ String tmp(buff,sizeof(buff),default_charset_info);
String *res=args[1]->val_str(&tmp);
if (args[1]->null_value)
{ // Will always return NULL
@@ -1365,7 +1373,8 @@ Item_func_regex::fix_fields(THD *thd,TABLE_LIST *tables)
int error;
if ((error=regcomp(&preg,res->c_ptr(),
binary ? REG_EXTENDED | REG_NOSUB :
- REG_EXTENDED | REG_NOSUB | REG_ICASE)))
+ REG_EXTENDED | REG_NOSUB | REG_ICASE,
+ res->charset())))
{
(void) regerror(error,&preg,buff,sizeof(buff));
my_printf_error(ER_REGEXP_ERROR,ER(ER_REGEXP_ERROR),MYF(0),buff);
@@ -1382,7 +1391,7 @@ Item_func_regex::fix_fields(THD *thd,TABLE_LIST *tables)
longlong Item_func_regex::val_int()
{
char buff[MAX_FIELD_WIDTH];
- String *res, tmp(buff,sizeof(buff));
+ String *res, tmp(buff,sizeof(buff),default_charset_info);
res=args[0]->val_str(&tmp);
if (args[0]->null_value)
@@ -1393,7 +1402,7 @@ longlong Item_func_regex::val_int()
if (!regex_is_const)
{
char buff2[MAX_FIELD_WIDTH];
- String *res2, tmp2(buff2,sizeof(buff2));
+ String *res2, tmp2(buff2,sizeof(buff2),default_charset_info);
res2= args[1]->val_str(&tmp2);
if (args[1]->null_value)
@@ -1411,7 +1420,8 @@ longlong Item_func_regex::val_int()
}
if (regcomp(&preg,res2->c_ptr(),
binary ? REG_EXTENDED | REG_NOSUB :
- REG_EXTENDED | REG_NOSUB | REG_ICASE))
+ REG_EXTENDED | REG_NOSUB | REG_ICASE,
+ res->charset()))
{
null_value=1;
@@ -1438,9 +1448,9 @@ Item_func_regex::~Item_func_regex()
#ifdef LIKE_CMP_TOUPPER
-#define likeconv(A) (uchar) toupper(A)
+#define likeconv(cs,A) (uchar) (cs)->toupper(A)
#else
-#define likeconv(A) (uchar) my_sort_order[(uchar) (A)]
+#define likeconv(cs,A) (uchar) (cs)->sort_order[(uchar) (A)]
#endif
@@ -1454,7 +1464,8 @@ void Item_func_like::turboBM_compute_suffixes(int* suff)
const int plm1 = pattern_len - 1;
int f = 0;
int g = plm1;
- int* const splm1 = suff + plm1;
+ int *const splm1 = suff + plm1;
+ CHARSET_INFO *cs=system_charset_info; // QQ Needs to be fixed
*splm1 = pattern_len;
@@ -1490,7 +1501,8 @@ void Item_func_like::turboBM_compute_suffixes(int* suff)
if (i < g)
g = i; // g = min(i, g)
f = i;
- while (g >= 0 && likeconv(pattern[g]) == likeconv(pattern[g + plm1 - f]))
+ while (g >= 0 && likeconv(cs, pattern[g]) ==
+ likeconv(cs, pattern[g + plm1 - f]))
g--;
suff[i] = f - g;
}
@@ -1551,19 +1563,25 @@ void Item_func_like::turboBM_compute_good_suffix_shifts(int* suff)
void Item_func_like::turboBM_compute_bad_character_shifts()
{
- int* i;
- int* end = bmBc + alphabet_size;
+ int *i;
+ int *end = bmBc + alphabet_size;
+ int j;
+ const int plm1 = pattern_len - 1;
+ CHARSET_INFO *cs=system_charset_info; // QQ Needs to be fixed
+
for (i = bmBc; i < end; i++)
*i = pattern_len;
- int j;
- const int plm1 = pattern_len - 1;
if (binary)
+ {
for (j = 0; j < plm1; j++)
bmBc[pattern[j]] = plm1 - j;
+ }
else
+ {
for (j = 0; j < plm1; j++)
- bmBc[likeconv(pattern[j])] = plm1 - j;
+ bmBc[likeconv(cs,pattern[j])] = plm1 - j;
+ }
}
@@ -1579,6 +1597,7 @@ bool Item_func_like::turboBM_matches(const char* text, int text_len) const
int shift = pattern_len;
int j = 0;
int u = 0;
+ CHARSET_INFO *cs=system_charset_info; // QQ Needs to be fixed
const int plm1 = pattern_len - 1;
const int tlmpl = text_len - pattern_len;
@@ -1620,7 +1639,7 @@ bool Item_func_like::turboBM_matches(const char* text, int text_len) const
while (j <= tlmpl)
{
register int i = plm1;
- while (i >= 0 && likeconv(pattern[i]) == likeconv(text[i + j]))
+ while (i >= 0 && likeconv(cs,pattern[i]) == likeconv(cs,text[i + j]))
{
i--;
if (i == plm1 - shift)
@@ -1631,7 +1650,7 @@ bool Item_func_like::turboBM_matches(const char* text, int text_len) const
register const int v = plm1 - i;
turboShift = u - v;
- bcShift = bmBc[likeconv(text[i + j])] - plm1 + i;
+ bcShift = bmBc[likeconv(cs, text[i + j])] - plm1 + i;
shift = max(turboShift, bcShift);
shift = max(shift, bmGs[i]);
if (shift == bmGs[i])
@@ -1686,3 +1705,82 @@ longlong Item_cond_xor::val_int()
}
return (longlong) result;
}
+
+/****************************************************************
+ Classes and functions for spatial relations
+*****************************************************************/
+
+longlong Item_func_spatial_rel::val_int()
+{
+ String *res1=args[0]->val_str(&tmp_value1);
+ String *res2=args[1]->val_str(&tmp_value2);
+ Geometry g1, g2;
+ MBR mbr1,mbr2;
+
+ if ((null_value=(args[0]->null_value ||
+ args[1]->null_value ||
+ g1.create_from_wkb(res1->ptr(),res1->length()) ||
+ g2.create_from_wkb(res2->ptr(),res2->length()) ||
+ g1.get_mbr(&mbr1) ||
+ g2.get_mbr(&mbr2))))
+ return 0;
+
+ switch (spatial_rel)
+ {
+ case SP_CONTAINS_FUNC:
+ return mbr1.contains(&mbr2);
+ case SP_WITHIN_FUNC:
+ return mbr1.within(&mbr2);
+ case SP_EQUALS_FUNC:
+ return mbr1.equals(&mbr2);
+ case SP_DISJOINT_FUNC:
+ return mbr1.disjoint(&mbr2);
+ case SP_INTERSECTS_FUNC:
+ return mbr1.intersects(&mbr2);
+ case SP_TOUCHES_FUNC:
+ return mbr1.touches(&mbr2);
+ case SP_OVERLAPS_FUNC:
+ return mbr1.overlaps(&mbr2);
+ case SP_CROSSES_FUNC:
+ return 0;
+ default:
+ break;
+ }
+
+ null_value=1;
+ return 0;
+}
+
+longlong Item_func_isempty::val_int()
+{
+ String tmp;
+ null_value=0;
+ return args[0]->null_value ? 1 : 0;
+}
+
+longlong Item_func_issimple::val_int()
+{
+ String tmp;
+ String *wkb=args[0]->val_str(&tmp);
+
+ if ((null_value= (!wkb || args[0]->null_value )))
+ return 0;
+ /* TODO: Ramil or Holyfoot, add real IsSimple calculation */
+ return 0;
+}
+
+longlong Item_func_isclosed::val_int()
+{
+ String tmp;
+ String *wkb=args[0]->val_str(&tmp);
+ Geometry geom;
+ int isclosed;
+
+ null_value= (!wkb ||
+ args[0]->null_value ||
+ geom.create_from_wkb(wkb->ptr(),wkb->length()) ||
+ !GEOM_METHOD_PRESENT(geom,is_closed) ||
+ geom.is_closed(&isclosed));
+
+ return (longlong) isclosed;
+}
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index 9d83a8a9673..c0dcc2bba8f 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -28,7 +28,6 @@ public:
Item_bool_func(Item *a) :Item_int_func(a) {}
Item_bool_func(Item *a,Item *b) :Item_int_func(a,b) {}
void fix_length_and_dec() { decimals=0; max_length=1; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_bool_func2 :public Item_int_func
@@ -48,7 +47,6 @@ public:
bool have_rev_func() const { return rev_functype() != UNKNOWN_FUNC; }
void print(String *str) { Item_func::print_op(str); }
bool is_null() { return test(args[0]->is_null() || args[1]->is_null()); }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -82,7 +80,6 @@ public:
enum Functype rev_functype() const { return EQUAL_FUNC; }
cond_result eq_cmp_result() const { return COND_TRUE; }
const char *func_name() const { return "<=>"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -180,15 +177,15 @@ public:
Item_func_interval(Item *a,List<Item> &list)
:Item_int_func(list),item(a),intervals(0) {}
longlong val_int();
- bool fix_fields(THD *thd,struct st_table_list *tlist)
+ bool fix_fields(THD *thd, struct st_table_list *tlist, Item **ref)
{
- return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
+ return (item->fix_fields(thd, tlist, &item) ||
+ Item_func::fix_fields(thd, tlist, ref));
}
void fix_length_and_dec();
~Item_func_interval() { delete item; }
const char *func_name() const { return "interval"; }
void update_used_tables();
- unsigned int size_of() { return sizeof(*this);}
};
@@ -203,7 +200,6 @@ public:
enum Item_result result_type () const { return cached_result_type; }
void fix_length_and_dec();
const char *func_name() const { return "ifnull"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -218,7 +214,6 @@ public:
enum Item_result result_type () const { return cached_result_type; }
void fix_length_and_dec();
const char *func_name() const { return "if"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -233,7 +228,6 @@ public:
enum Item_result result_type () const { return cached_result_type; }
void fix_length_and_dec();
const char *func_name() const { return "nullif"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -248,7 +242,6 @@ public:
void fix_length_and_dec();
enum Item_result result_type () const { return cached_result_type; }
const char *func_name() const { return "coalesce"; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_case :public Item_func
@@ -267,9 +260,8 @@ public:
enum Item_result result_type () const { return cached_result_type; }
const char *func_name() const { return "case"; }
void print(String *str);
- bool fix_fields(THD *thd,struct st_table_list *tlist);
+ bool fix_fields(THD *thd, struct st_table_list *tlist, Item **ref);
Item *find_item(String *str);
- unsigned int size_of() { return sizeof(*this);}
};
@@ -350,7 +342,7 @@ class cmp_item_sort_string :public cmp_item {
char value_buff[80];
String value,*value_res;
public:
- cmp_item_sort_string() :value(value_buff,sizeof(value_buff)) {}
+ cmp_item_sort_string() :value(value_buff,sizeof(value_buff),default_charset_info) {}
void store_value(Item *item)
{
value_res=item->val_str(&value);
@@ -358,7 +350,7 @@ public:
int cmp(Item *arg)
{
char buff[80];
- String tmp(buff,sizeof(buff)),*res;
+ String tmp(buff,sizeof(buff),default_charset_info),*res;
if (!(res=arg->val_str(&tmp)))
return 1; /* Can't be right */
return sortcmp(value_res,res);
@@ -371,7 +363,7 @@ public:
int cmp(Item *arg)
{
char buff[80];
- String tmp(buff,sizeof(buff)),*res;
+ String tmp(buff,sizeof(buff),default_charset_info),*res;
if (!(res=arg->val_str(&tmp)))
return 1; /* Can't be right */
return stringcmp(value_res,res);
@@ -418,9 +410,10 @@ class Item_func_in :public Item_int_func
Item_func_in(Item *a,List<Item> &list)
:Item_int_func(list),item(a),array(0),in_item(0) {}
longlong val_int();
- bool fix_fields(THD *thd,struct st_table_list *tlist)
+ bool fix_fields(THD *thd, struct st_table_list *tlist, Item **ref)
{
- return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
+ return (item->fix_fields(thd, tlist, &item) ||
+ Item_func::fix_fields(thd, tlist, ref));
}
void fix_length_and_dec();
~Item_func_in() { delete item; delete array; delete in_item; }
@@ -431,7 +424,6 @@ class Item_func_in :public Item_int_func
enum Functype functype() const { return IN_FUNC; }
const char *func_name() const { return " IN "; }
void update_used_tables();
- unsigned int size_of() { return sizeof(*this);}
};
@@ -469,7 +461,6 @@ public:
}
}
optimize_type select_optimize() const { return OPTIMIZE_NULL; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_isnotnull :public Item_bool_func
@@ -484,7 +475,6 @@ public:
}
const char *func_name() const { return "isnotnull"; }
optimize_type select_optimize() const { return OPTIMIZE_NULL; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_like :public Item_bool_func2
@@ -517,8 +507,7 @@ public:
cond_result eq_cmp_result() const { return COND_TRUE; }
const char *func_name() const { return "like"; }
void fix_length_and_dec();
- bool fix_fields(THD *thd,struct st_table_list *tlist);
- unsigned int size_of() { return sizeof(*this);}
+ bool fix_fields(THD *thd, struct st_table_list *tlist, Item **ref);
};
#ifdef USE_REGEX
@@ -536,9 +525,8 @@ public:
regex_compiled(0),regex_is_const(0) {}
~Item_func_regex();
longlong val_int();
- bool fix_fields(THD *thd,struct st_table_list *tlist);
+ bool fix_fields(THD *thd, struct st_table_list *tlist, Item **ref);
const char *func_name() const { return "regex"; }
- unsigned int size_of() { return sizeof(*this);}
};
#else
@@ -566,7 +554,7 @@ public:
{ list.push_back(i1); list.push_back(i2); }
~Item_cond() { list.delete_elements(); }
bool add(Item *item) { return list.push_back(item); }
- bool fix_fields(THD *,struct st_table_list *);
+ bool fix_fields(THD *, struct st_table_list *, Item **ref);
enum Type type() const { return COND_ITEM; }
List<Item>* argument_list() { return &list; }
@@ -575,7 +563,6 @@ public:
void print(String *str);
void split_sum_func(List<Item> &fields);
friend int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds);
- unsigned int size_of() { return sizeof(*this);}
};
@@ -600,6 +587,17 @@ public:
};
+class Item_cond_xor :public Item_cond
+{
+public:
+ Item_cond_xor() :Item_cond() {}
+ Item_cond_xor(Item *i1,Item *i2) :Item_cond(i1,i2) {}
+ enum Functype functype() const { return COND_XOR_FUNC; }
+ longlong val_int();
+ const char *func_name() const { return "xor"; }
+};
+
+
/* Some usefull inline functions */
inline Item *and_conds(Item *a,Item *b)
@@ -612,12 +610,79 @@ inline Item *and_conds(Item *a,Item *b)
return cond;
}
-class Item_cond_xor :public Item_cond
+
+/**************************************************************
+ Spatial relations
+***************************************************************/
+
+class Item_func_spatial_rel :public Item_bool_func2
{
+ enum Functype spatial_rel;
public:
- Item_cond_xor() :Item_cond() {}
- Item_cond_xor(Item *i1,Item *i2) :Item_cond(i1,i2) {}
- enum Functype functype() const { return COND_XOR_FUNC; }
+ Item_func_spatial_rel(Item *a,Item *b, enum Functype sp_rel) :
+ Item_bool_func2(a,b) { spatial_rel = sp_rel; }
longlong val_int();
- const char *func_name() const { return "xor"; }
+ enum Functype functype() const
+ {
+ switch (spatial_rel) {
+ case SP_CONTAINS_FUNC:
+ return SP_WITHIN_FUNC;
+ case SP_WITHIN_FUNC:
+ return SP_CONTAINS_FUNC;
+ default:
+ return spatial_rel;
+ }
+ }
+ enum Functype rev_functype() const { return spatial_rel; }
+ const char *func_name() const
+ {
+ switch (spatial_rel) {
+ case SP_CONTAINS_FUNC:
+ return "contains";
+ case SP_WITHIN_FUNC:
+ return "within";
+ case SP_EQUALS_FUNC:
+ return "equals";
+ case SP_DISJOINT_FUNC:
+ return "disjoint";
+ case SP_INTERSECTS_FUNC:
+ return "intersects";
+ case SP_TOUCHES_FUNC:
+ return "touches";
+ case SP_CROSSES_FUNC:
+ return "crosses";
+ case SP_OVERLAPS_FUNC:
+ return "overlaps";
+ default:
+ return "sp_unknown";
+ }
+ }
+};
+
+
+class Item_func_isempty :public Item_bool_func
+{
+public:
+ Item_func_isempty(Item *a) :Item_bool_func(a) {}
+ longlong val_int();
+ optimize_type select_optimize() const { return OPTIMIZE_NONE; }
+ const char *func_name() const { return "isempty"; }
+};
+
+class Item_func_issimple :public Item_bool_func
+{
+public:
+ Item_func_issimple(Item *a) :Item_bool_func(a) {}
+ longlong val_int();
+ optimize_type select_optimize() const { return OPTIMIZE_NONE; }
+ const char *func_name() const { return "issimple"; }
+};
+
+class Item_func_isclosed :public Item_bool_func
+{
+public:
+ Item_func_isclosed(Item *a) :Item_bool_func(a) {}
+ longlong val_int();
+ optimize_type select_optimize() const { return OPTIMIZE_NONE; }
+ const char *func_name() const { return "isclosed"; }
};
diff --git a/sql/item_create.cc b/sql/item_create.cc
index f28e3248c61..e4c9a160686 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -96,6 +96,11 @@ Item *create_func_cot(Item* a)
new Item_func_tan(a));
}
+Item *create_func_crc32(Item* a)
+{
+ return new Item_func_crc32(a);
+}
+
Item *create_func_date_format(Item* a,Item *b)
{
return new Item_func_date_format(a,b,0);
@@ -242,7 +247,7 @@ Item *create_func_lpad(Item* a, Item *b, Item *c)
Item *create_func_ltrim(Item* a)
{
- return new Item_func_ltrim(a,new Item_string(" ",1));
+ return new Item_func_ltrim(a,new Item_string(" ",1,default_charset_info));
}
Item *create_func_md5(Item* a)
@@ -324,7 +329,7 @@ Item *create_func_rpad(Item* a, Item *b, Item *c)
Item *create_func_rtrim(Item* a)
{
- return new Item_func_rtrim(a,new Item_string(" ",1));
+ return new Item_func_rtrim(a,new Item_string(" ",1,default_charset_info));
}
Item *create_func_sec_to_time(Item* a)
@@ -349,7 +354,7 @@ Item *create_func_sha(Item* a)
Item *create_func_space(Item *a)
{
- return new Item_func_repeat(new Item_string(" ",1),a);
+ return new Item_func_repeat(new Item_string(" ",1,default_charset_info),a);
}
Item *create_func_soundex(Item* a)
@@ -394,7 +399,9 @@ Item *create_func_ucase(Item* a)
Item *create_func_version(void)
{
- return new Item_string(NullS,server_version, (uint) strlen(server_version));
+ return new Item_string(NullS,server_version,
+ (uint) strlen(server_version),
+ default_charset_info);
}
Item *create_func_weekday(Item* a)
@@ -444,3 +451,158 @@ Item *create_func_quote(Item* a)
{
return new Item_func_quote(a);
}
+
+Item *create_func_geometry_from_text(Item* a)
+{
+ return new Item_func_geometry_from_text(a);
+}
+
+Item *create_func_as_text(Item* a)
+{
+ return new Item_func_as_text(a);
+}
+
+Item *create_func_startpoint(Item* a)
+{
+ return new Item_func_spatial_decomp(a, Item_func::SP_STARTPOINT);
+}
+
+Item *create_func_endpoint(Item* a)
+{
+ return new Item_func_spatial_decomp(a, Item_func::SP_ENDPOINT);
+}
+
+Item *create_func_exteriorring(Item* a)
+{
+ return new Item_func_spatial_decomp(a, Item_func::SP_EXTERIORRING);
+}
+
+Item *create_func_pointn(Item* a, Item* b)
+{
+ return new Item_func_spatial_decomp_n(a,b,Item_func::SP_POINTN);
+}
+
+Item *create_func_interiorringn(Item* a, Item* b)
+{
+ return new Item_func_spatial_decomp_n(a,b,Item_func::SP_INTERIORRINGN);
+}
+
+Item *create_func_geometryn(Item* a, Item* b)
+{
+ return new Item_func_spatial_decomp_n(a,b,Item_func::SP_GEOMETRYN);
+}
+
+Item *create_func_centroid(Item* a)
+{
+ return new Item_func_centroid(a);
+}
+
+Item *create_func_envelope(Item* a)
+{
+ return new Item_func_envelope(a);
+}
+
+Item *create_func_equals(Item* a, Item* b)
+{
+ return new Item_func_spatial_rel(a, b, Item_func::SP_EQUALS_FUNC);
+}
+
+Item *create_func_disjoint(Item* a, Item* b)
+{
+ return new Item_func_spatial_rel(a, b, Item_func::SP_DISJOINT_FUNC);
+}
+
+Item *create_func_intersects(Item* a, Item* b)
+{
+ return new Item_func_spatial_rel(a, b, Item_func::SP_INTERSECTS_FUNC);
+}
+
+Item *create_func_touches(Item* a, Item* b)
+{
+ return new Item_func_spatial_rel(a, b, Item_func::SP_TOUCHES_FUNC);
+}
+
+Item *create_func_crosses(Item* a, Item* b)
+{
+ return new Item_func_spatial_rel(a, b, Item_func::SP_CROSSES_FUNC);
+}
+
+Item *create_func_within(Item* a, Item* b)
+{
+ return new Item_func_spatial_rel(a, b, Item_func::SP_WITHIN_FUNC);
+}
+
+Item *create_func_contains(Item* a, Item* b)
+{
+ return new Item_func_spatial_rel(a, b, Item_func::SP_CONTAINS_FUNC);
+}
+
+Item *create_func_overlaps(Item* a, Item* b)
+{
+ return new Item_func_spatial_rel(a, b, Item_func::SP_OVERLAPS_FUNC);
+}
+
+Item *create_func_isempty(Item* a)
+{
+ return new Item_func_isempty(a);
+}
+
+Item *create_func_issimple(Item* a)
+{
+ return new Item_func_issimple(a);
+}
+
+Item *create_func_isclosed(Item* a)
+{
+ return new Item_func_isclosed(a);
+}
+
+Item *create_func_geometry_type(Item* a)
+{
+ return new Item_func_geometry_type(a);
+}
+
+Item *create_func_dimension(Item* a)
+{
+ return new Item_func_dimension(a);
+}
+
+Item *create_func_x(Item* a)
+{
+ return new Item_func_x(a);
+}
+
+Item *create_func_y(Item* a)
+{
+ return new Item_func_y(a);
+}
+
+Item *create_func_numpoints(Item* a)
+{
+ return new Item_func_numpoints(a);
+}
+
+Item *create_func_numinteriorring(Item* a)
+{
+ return new Item_func_numinteriorring(a);
+}
+
+Item *create_func_numgeometries(Item* a)
+{
+ return new Item_func_numgeometries(a);
+}
+
+Item *create_func_area(Item* a)
+{
+ return new Item_func_area(a);
+}
+
+Item *create_func_glength(Item* a)
+{
+ return new Item_func_glength(a);
+}
+
+Item *create_func_point(Item* a, Item* b)
+{
+ return new Item_func_point(a,b);
+}
diff --git a/sql/item_create.h b/sql/item_create.h
index 28fbd61df8f..6d9cef04c13 100644
--- a/sql/item_create.h
+++ b/sql/item_create.h
@@ -27,10 +27,12 @@ Item *create_func_bit_count(Item* a);
Item *create_func_bit_length(Item* a);
Item *create_func_ceiling(Item* a);
Item *create_func_char_length(Item* a);
+Item *create_func_cast(Item *a, Item_cast cast_type);
Item *create_func_connection_id(void);
Item *create_func_conv(Item* a, Item *b, Item *c);
Item *create_func_cos(Item* a);
Item *create_func_cot(Item* a);
+Item *create_func_crc32(Item* a);
Item *create_func_date_format(Item* a,Item *b);
Item *create_func_dayname(Item* a);
Item *create_func_dayofmonth(Item* a);
@@ -94,3 +96,41 @@ Item *create_load_file(Item* a);
Item *create_wait_for_master_pos(Item* a, Item* b);
Item *create_func_is_free_lock(Item* a);
Item *create_func_quote(Item* a);
+
+Item *create_func_geometry_from_text(Item* a);
+Item *create_func_as_text(Item* a);
+Item *create_func_startpoint(Item* a);
+Item *create_func_endpoint(Item* a);
+Item *create_func_exteriorring(Item* a);
+Item *create_func_centroid(Item* a);
+Item *create_func_envelope(Item* a);
+Item *create_func_pointn(Item* a, Item* b);
+Item *create_func_interiorringn(Item* a, Item* b);
+Item *create_func_geometryn(Item* a, Item* b);
+
+Item *create_func_equals(Item* a, Item* b);
+Item *create_func_disjoint(Item* a, Item* b);
+Item *create_func_intersects(Item* a, Item* b);
+Item *create_func_touches(Item* a, Item* b);
+Item *create_func_crosses(Item* a, Item* b);
+Item *create_func_within(Item* a, Item* b);
+Item *create_func_contains(Item* a, Item* b);
+Item *create_func_overlaps(Item* a, Item* b);
+
+Item *create_func_isempty(Item* a);
+Item *create_func_issimple(Item* a);
+Item *create_func_isclosed(Item* a);
+
+Item *create_func_geometry_type(Item* a);
+Item *create_func_dimension(Item* a);
+Item *create_func_x(Item* a);
+Item *create_func_y(Item* a);
+Item *create_func_area(Item* a);
+Item *create_func_glength(Item* a);
+
+Item *create_func_numpoints(Item* a);
+Item *create_func_numinteriorring(Item* a);
+Item *create_func_numgeometries(Item* a);
+
+Item *create_func_point(Item* a,Item* b);
+
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 8b05109b289..bd811726b47 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -26,7 +26,10 @@
#include <hash.h>
#include <time.h>
#include <ft_global.h>
+#include <zlib.h>
#include "slave.h" // for wait_for_master_pos
+#include "gstream.h"
+
/* return TRUE if item is a constant */
@@ -55,8 +58,43 @@ Item_func::Item_func(List<Item> &list)
list.empty(); // Fields are used
}
+
+/*
+ Resolve references to table column for a function and it's argument
+
+ SYNOPSIS:
+ fix_fields()
+ thd Thread object
+ tables List of all open tables involved in the query
+ ref Pointer to where this object is used. This reference
+ is used if we want to replace this object with another
+ one (for example in the summary functions).
+
+ DESCRIPTION
+ Call fix_fields() for all arguments to the function. The main intention
+ is to allow all Item_field() objects to setup pointers to the table fields.
+
+ Sets as a side effect the following class variables:
+ maybe_null Set if any argument may return NULL
+ binary Set if any of the arguments is binary
+ with_sum_func Set if any of the arguments contains a sum function
+ used_table_cache Set to union of the arguments used table
+
+ str_value.charset If this is a string function, set this to the
+ character set for the first argument.
+
+ If for any item any of the defaults are wrong, then this can
+ be fixed in the fix_length_and_dec() function that is called
+ after this one or by writing a specialized fix_fields() for the
+ item.
+
+ RETURN VALUES
+ 0 ok
+ 1 Got error. Stored with my_error().
+*/
+
bool
-Item_func::fix_fields(THD *thd,TABLE_LIST *tables)
+Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
Item **arg,**arg_end;
char buff[STACK_BUFF_ALLOC]; // Max argument in function
@@ -70,7 +108,7 @@ Item_func::fix_fields(THD *thd,TABLE_LIST *tables)
{ // Print purify happy
for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++)
{
- if ((*arg)->fix_fields(thd,tables))
+ if ((*arg)->fix_fields(thd, tables, arg))
return 1; /* purecov: inspected */
if ((*arg)->maybe_null)
maybe_null=1;
@@ -80,6 +118,12 @@ Item_func::fix_fields(THD *thd,TABLE_LIST *tables)
used_tables_cache|=(*arg)->used_tables();
const_item_cache&= (*arg)->const_item();
}
+ /*
+ Set return character set to first argument if we are returning a
+ string.
+ */
+ if (result_type() == STRING_RESULT)
+ str_value.set_charset((*args)->str_value.charset());
}
fix_length_and_dec();
return 0;
@@ -847,6 +891,18 @@ longlong Item_func_min_max::val_int()
return value;
}
+longlong Item_func_crc32::val_int()
+{
+ String *res=args[0]->val_str(&value);
+ if (!res)
+ {
+ null_value=1;
+ return 0; /* purecov: inspected */
+ }
+ null_value=0;
+ return (longlong) crc32(0L, (Bytef*)res->ptr(), res->length());
+}
+
longlong Item_func_length::val_int()
{
@@ -892,7 +948,7 @@ longlong Item_func_locate::val_int()
{
start=(uint) args[2]->val_int()-1;
#ifdef USE_MB
- if (use_mb(default_charset_info))
+ if (use_mb(a->charset()))
{
start0=start;
if (!binary_str)
@@ -905,7 +961,7 @@ longlong Item_func_locate::val_int()
if (!b->length()) // Found empty string at start
return (longlong) (start+1);
#ifdef USE_MB
- if (use_mb(default_charset_info) && !binary_str)
+ if (use_mb(a->charset()) && !binary_str)
{
const char *ptr=a->ptr()+start;
const char *search=b->ptr();
@@ -924,7 +980,8 @@ longlong Item_func_locate::val_int()
return (longlong) start0+1;
}
skipp:
- if ((l=my_ismbchar(default_charset_info,ptr,strend))) ptr+=l;
+ if ((l=my_ismbchar(a->charset(),ptr,strend)))
+ ptr+=l;
else ++ptr;
++start0;
}
@@ -975,12 +1032,12 @@ longlong Item_func_ord::val_int()
null_value=0;
if (!res->length()) return 0;
#ifdef USE_MB
- if (use_mb(default_charset_info) && !args[0]->binary)
+ if (use_mb(res->charset()) && !args[0]->binary)
{
register const char *str=res->ptr();
- register uint32 n=0, l=my_ismbchar(default_charset_info,
- str,str+res->length());
- if (!l) return (longlong)((uchar) *str);
+ register uint32 n=0, l=my_ismbchar(res->charset(),str,str+res->length());
+ if (!l)
+ return (longlong)((uchar) *str);
while (l--)
n=(n<<8)|(uint32)((uchar) *str++);
return (longlong) n;
@@ -1040,6 +1097,7 @@ longlong Item_func_find_in_set::val_int()
null_value=0;
int diff;
+ CHARSET_INFO *charset= find->charset();
if ((diff=buffer->length() - find->length()) >= 0)
{
const char *f_pos=find->ptr();
@@ -1053,7 +1111,7 @@ longlong Item_func_find_in_set::val_int()
const char *pos= f_pos;
while (pos != f_end)
{
- if (toupper(*str) != toupper(*pos))
+ if (my_toupper(charset,*str) != my_toupper(charset,*pos))
goto not_found;
str++;
pos++;
@@ -1148,7 +1206,7 @@ udf_handler::~udf_handler()
bool
-udf_handler::fix_fields(THD *thd,TABLE_LIST *tables,Item_result_field *func,
+udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func,
uint arg_count, Item **arguments)
{
char buff[STACK_BUFF_ALLOC]; // Max argument in function
@@ -1192,7 +1250,7 @@ udf_handler::fix_fields(THD *thd,TABLE_LIST *tables,Item_result_field *func,
arg != arg_end ;
arg++,i++)
{
- if ((*arg)->fix_fields(thd,tables))
+ if ((*arg)->fix_fields(thd, tables, arg))
return 1;
if ((*arg)->binary)
func->binary=1;
@@ -1358,7 +1416,7 @@ String *udf_handler::val_str(String *str,String *save_str)
str->length(res_length);
return str;
}
- save_str->set(res, res_length);
+ save_str->set(res, res_length, default_charset_info);
return save_str;
}
@@ -1483,7 +1541,8 @@ char *ull_get_key(const ULL *ull,uint *length,
void item_user_lock_init(void)
{
pthread_mutex_init(&LOCK_user_locks,MY_MUTEX_INIT_SLOW);
- hash_init(&hash_user_locks,16,0,0,(hash_get_key) ull_get_key,NULL,0);
+ hash_init(&hash_user_locks,system_charset_info,
+ 16,0,0,(hash_get_key) ull_get_key,NULL,0);
}
void item_user_lock_free(void)
@@ -1497,9 +1556,9 @@ void item_user_lock_release(ULL *ull)
if (mysql_bin_log.is_open())
{
char buf[256];
- String tmp(buf,sizeof(buf));
- tmp.length(0);
- tmp.append("DO RELEASE_LOCK(\"");
+ const char *command="DO RELEASE_LOCK(\"";
+ String tmp(buf,sizeof(buf), system_charset_info);
+ tmp.copy(command, strlen(command));
tmp.append(ull->key,ull->key_length);
tmp.append("\")");
Query_log_event qev(current_thd,tmp.ptr(), tmp.length());
@@ -1757,7 +1816,7 @@ longlong Item_func_set_last_insert_id::val_int()
longlong Item_func_benchmark::val_int()
{
char buff[MAX_FIELD_WIDTH];
- String tmp(buff,sizeof(buff));
+ String tmp(buff,sizeof(buff), default_charset_info);
THD *thd=current_thd;
for (ulong loop=0 ; loop < loop_count && !thd->killed; loop++)
@@ -1812,11 +1871,12 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name,
}
-bool Item_func_set_user_var::fix_fields(THD *thd,TABLE_LIST *tables)
+bool Item_func_set_user_var::fix_fields(THD *thd, TABLE_LIST *tables,
+ Item **ref)
{
if (!thd)
thd=current_thd; // Should never happen
- if (Item_func::fix_fields(thd,tables) ||
+ if (Item_func::fix_fields(thd, tables, ref) ||
!(entry= get_variable(&thd->user_vars, name, 1)))
return 1;
entry->update_query_id=thd->query_id;
@@ -1895,7 +1955,7 @@ Item_func_set_user_var::update()
break;
case STRING_RESULT:
char buffer[MAX_FIELD_WIDTH];
- String tmp(buffer,sizeof(buffer));
+ String tmp(buffer,sizeof(buffer),default_charset_info);
(void) val_str(&tmp);
break;
}
@@ -2070,7 +2130,7 @@ longlong Item_func_inet_aton::val_int()
char c = '.'; // we mark c to indicate invalid IP in case length is 0
char buff[36];
- String *s,tmp(buff,sizeof(buff));
+ String *s,tmp(buff,sizeof(buff),default_charset_info);
if (!(s = args[0]->val_str(&tmp))) // If null value
goto err;
null_value=0;
@@ -2108,7 +2168,9 @@ void Item_func_match::init_search(bool no_order)
return;
if (key == NO_SUCH_KEY)
- concat= new Item_func_concat_ws(new Item_string(" ",1), fields);
+ concat=new Item_func_concat_ws(new Item_string(" ",1,
+ default_charset_info),
+ fields);
if (master)
{
@@ -2119,15 +2181,15 @@ void Item_func_match::init_search(bool no_order)
return;
}
- String *ft_tmp=0;
+ String *ft_tmp= 0;
char tmp1[FT_QUERY_MAXLEN];
- String tmp2(tmp1,sizeof(tmp1));
+ String tmp2(tmp1,sizeof(tmp1),default_charset_info);
// MATCH ... AGAINST (NULL) is meaningless, but possible
if (!(ft_tmp=key_item()->val_str(&tmp2)))
{
ft_tmp= &tmp2;
- tmp2.set("",0);
+ tmp2.set("",0,default_charset_info);
}
ft_handler=table->file->ft_init_ext(mode, key,
@@ -2143,7 +2205,7 @@ void Item_func_match::init_search(bool no_order)
}
-bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist)
+bool Item_func_match::fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref)
{
List_iterator<Item> li(fields);
Item *item;
@@ -2157,7 +2219,7 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist)
modifications to find_best and auto_close as complement to auto_init code
above.
*/
- if (Item_func::fix_fields(thd,tlist) || !const_item())
+ if (Item_func::fix_fields(thd, tlist, ref) || !const_item())
{
my_error(ER_WRONG_ARGUMENTS,MYF(0),"AGAINST");
return 1;
@@ -2165,7 +2227,7 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist)
while ((item=li++))
{
- if (item->fix_fields(thd,tlist))
+ if (item->fix_fields(thd, tlist, li.ref()))
return 1;
if (item->type() == Item::REF_ITEM)
li.replace(item= *((Item_ref *)item)->ref);
@@ -2311,6 +2373,7 @@ double Item_func_match::val()
return ft_handler->please->find_relevance(ft_handler, record, 0);
}
+
longlong Item_func_bit_xor::val_int()
{
ulonglong arg1= (ulonglong) args[0]->val_int();
@@ -2386,3 +2449,124 @@ longlong Item_func_is_free_lock::val_int()
return 1;
return 0;
}
+
+
+/**************************************************************************
+ Spatial functions
+***************************************************************************/
+
+longlong Item_func_dimension::val_int()
+{
+ uint32 dim;
+ String *wkb=args[0]->val_str(&value);
+ Geometry geom;
+
+ null_value= (!wkb ||
+ args[0]->null_value ||
+ geom.create_from_wkb(wkb->ptr(),wkb->length()) ||
+ geom.dimension(&dim));
+
+ return (longlong) dim;
+}
+
+longlong Item_func_numinteriorring::val_int()
+{
+ uint32 num;
+ String *wkb=args[0]->val_str(&value);
+ Geometry geom;
+
+ null_value= (!wkb ||
+ geom.create_from_wkb(wkb->ptr(),wkb->length()) ||
+ !GEOM_METHOD_PRESENT(geom,num_interior_ring) ||
+ geom.num_interior_ring(&num));
+
+ return (longlong) num;
+}
+
+longlong Item_func_numgeometries::val_int()
+{
+ uint32 num=0;
+ String *wkb=args[0]->val_str(&value);
+ Geometry geom;
+
+ null_value= (!wkb ||
+ geom.create_from_wkb(wkb->ptr(),wkb->length()) ||
+ !GEOM_METHOD_PRESENT(geom,num_geometries) ||
+ geom.num_geometries(&num));
+
+ return (longlong) num;
+}
+
+longlong Item_func_numpoints::val_int()
+{
+ uint32 num=0;
+ String *wkb=args[0]->val_str(&value);
+ Geometry geom;
+
+ null_value= (!wkb ||
+ args[0]->null_value ||
+ geom.create_from_wkb(wkb->ptr(),wkb->length()) ||
+ !GEOM_METHOD_PRESENT(geom,num_points) ||
+ geom.num_points(&num));
+
+ return (longlong) num;
+}
+
+
+double Item_func_x::val()
+{
+ double res=0;
+ String *wkb=args[0]->val_str(&value);
+ Geometry geom;
+
+ null_value= (!wkb ||
+ geom.create_from_wkb(wkb->ptr(),wkb->length()) ||
+ !GEOM_METHOD_PRESENT(geom,get_x) ||
+ geom.get_x(&res));
+
+ return res;
+}
+
+
+double Item_func_y::val()
+{
+ double res=0;
+ String *wkb=args[0]->val_str(&value);
+ Geometry geom;
+
+ null_value= (!wkb ||
+ geom.create_from_wkb(wkb->ptr(),wkb->length()) ||
+ !GEOM_METHOD_PRESENT(geom,get_y) ||
+ geom.get_y(&res));
+
+ return res;
+}
+
+
+double Item_func_area::val()
+{
+ double res=0;
+ String *wkb=args[0]->val_str(&value);
+ Geometry geom;
+
+ null_value= (!wkb ||
+ geom.create_from_wkb(wkb->ptr(),wkb->length()) ||
+ !GEOM_METHOD_PRESENT(geom,area) ||
+ geom.area(&res));
+
+ return res;
+}
+
+
+double Item_func_glength::val()
+{
+ double res=0;
+ String *wkb=args[0]->val_str(&value);
+ Geometry geom;
+
+ null_value= (!wkb ||
+ geom.create_from_wkb(wkb->ptr(),wkb->length()) ||
+ !GEOM_METHOD_PRESENT(geom,length) ||
+ geom.length(&res));
+ return res;
+}
diff --git a/sql/item_func.h b/sql/item_func.h
index 736616b016a..45427bec017 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -39,7 +39,13 @@ public:
enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC,
GE_FUNC,GT_FUNC,FT_FUNC,
LIKE_FUNC,NOTLIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC,
- COND_AND_FUNC,COND_OR_FUNC,COND_XOR_FUNC,BETWEEN,IN_FUNC,INTERVAL_FUNC};
+ COND_AND_FUNC, COND_OR_FUNC, CONX_XOR_FUNC, BETWEEN, IN_FUNC,
+ INTERVAL_FUNC,
+ SP_EQUALS_FUNC, SP_DISJOINT_FUNC,SP_INTERSECTS_FUNC,
+ SP_TOUCHES_FUNC,SP_CROSSES_FUNC,SP_WITHIN_FUNC,
+ SP_CONTAINS_FUNC,SP_OVERLAPS_FUNC,
+ SP_STARTPOINT,SP_ENDPOINT,SP_EXTERIORRING,
+ SP_POINTN,SP_GEOMETRYN,SP_INTERIORRINGN};
enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL };
enum Type type() const { return FUNC_ITEM; }
virtual enum Functype functype() const { return UNKNOWN_FUNC; }
@@ -94,7 +100,7 @@ public:
}
Item_func(List<Item> &list);
~Item_func() {} /* Nothing to do; Items are freed automaticly */
- bool fix_fields(THD *,struct st_table_list *);
+ bool fix_fields(THD *,struct st_table_list *, Item **ref);
void make_field(Send_field *field);
table_map used_tables() const;
void update_used_tables();
@@ -121,7 +127,6 @@ public:
}
bool is_null() { (void) val_int(); return null_value; }
friend class udf_handler;
- unsigned int size_of() { return sizeof(*this);}
Field *tmp_table_field(TABLE *t_arg);
};
@@ -137,7 +142,6 @@ public:
longlong val_int() { return (longlong) val(); }
enum Item_result result_type () const { return REAL_RESULT; }
void fix_length_and_dec() { decimals=NOT_FIXED_DEC; max_length=float_length(decimals); }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -153,7 +157,6 @@ public:
enum Item_result result_type () const { return hybrid_type; }
void fix_length_and_dec() { fix_num_length_and_dec(); }
bool is_null() { (void) val(); return null_value; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -169,7 +172,6 @@ class Item_num_op :public Item_func
void fix_length_and_dec() { fix_num_length_and_dec(); find_num_type(); }
void find_num_type(void);
bool is_null() { (void) val(); return null_value; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -459,7 +461,6 @@ public:
const char *func_name() const { return truncate ? "truncate" : "round"; }
double val();
void fix_length_and_dec();
- unsigned int size_of() { return sizeof(*this);}
};
@@ -495,7 +496,6 @@ class Item_func_units :public Item_real_func
double val();
const char *func_name() const { return name; }
void fix_length_and_dec() { decimals=NOT_FIXED_DEC; max_length=float_length(decimals); }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -512,7 +512,6 @@ public:
String *val_str(String *);
void fix_length_and_dec();
enum Item_result result_type () const { return cmp_type; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_min :public Item_func_min_max
@@ -529,6 +528,16 @@ public:
const char *func_name() const { return "greatest"; }
};
+class Item_func_crc32 :public Item_int_func
+{
+ String value;
+public:
+ Item_func_crc32(Item *a) :Item_int_func(a) {}
+ longlong val_int();
+ const char *func_name() const { return "crc32"; }
+ void fix_length_and_dec() { max_length=10; }
+};
+
class Item_func_length :public Item_int_func
{
@@ -538,7 +547,6 @@ public:
longlong val_int();
const char *func_name() const { return "length"; }
void fix_length_and_dec() { max_length=10; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_bit_length :public Item_func_length
@@ -557,7 +565,6 @@ public:
longlong val_int();
const char *func_name() const { return "char_length"; }
void fix_length_and_dec() { max_length=10; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_locate :public Item_int_func
@@ -569,7 +576,6 @@ public:
const char *func_name() const { return "locate"; }
longlong val_int();
void fix_length_and_dec() { maybe_null=0; max_length=11; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -581,9 +587,10 @@ public:
Item_func_field(Item *a,List<Item> &list) :Item_int_func(list),item(a) {}
~Item_func_field() { delete item; }
longlong val_int();
- bool fix_fields(THD *thd,struct st_table_list *tlist)
+ bool fix_fields(THD *thd,struct st_table_list *tlist, Item **ref)
{
- return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
+ return (item->fix_fields(thd, tlist, &item) ||
+ Item_func::fix_fields(thd, tlist, ref));
}
void update_used_tables()
{
@@ -599,7 +606,6 @@ public:
const_item_cache&= item->const_item();
with_sum_func= with_sum_func || item->with_sum_func;
}
- unsigned int size_of() { return sizeof(*this);}
};
@@ -611,7 +617,6 @@ public:
longlong val_int();
const char *func_name() const { return "ascii"; }
void fix_length_and_dec() { max_length=3; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_ord :public Item_int_func
@@ -621,7 +626,6 @@ public:
Item_func_ord(Item *a) :Item_int_func(a) {}
longlong val_int();
const char *func_name() const { return "ord"; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_find_in_set :public Item_int_func
@@ -634,7 +638,6 @@ public:
longlong val_int();
const char *func_name() const { return "find_in_set"; }
void fix_length_and_dec();
- unsigned int size_of() { return sizeof(*this);}
};
@@ -710,7 +713,6 @@ class Item_func_benchmark :public Item_int_func
longlong val_int();
const char *func_name() const { return "benchmark"; }
void fix_length_and_dec() { max_length=1; maybe_null=0; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -727,15 +729,14 @@ public:
:Item_func(list), udf(udf_arg) {}
~Item_udf_func() {}
const char *func_name() const { return udf.name(); }
- bool fix_fields(THD *thd,struct st_table_list *tables)
+ bool fix_fields(THD *thd, struct st_table_list *tables, Item **ref)
{
- bool res=udf.fix_fields(thd,tables,this,arg_count,args);
- used_tables_cache=udf.used_tables_cache;
- const_item_cache=udf.const_item_cache;
+ bool res= udf.fix_fields(thd, tables, this, arg_count, args);
+ used_tables_cache= udf.used_tables_cache;
+ const_item_cache= udf.const_item_cache;
return res;
}
Item_result result_type () const { return udf.result_type(); }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -844,7 +845,6 @@ class Item_func_get_lock :public Item_int_func
longlong val_int();
const char *func_name() const { return "get_lock"; }
void fix_length_and_dec() { max_length=1; maybe_null=1;}
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_release_lock :public Item_int_func
@@ -855,7 +855,6 @@ class Item_func_release_lock :public Item_int_func
longlong val_int();
const char *func_name() const { return "release_lock"; }
void fix_length_and_dec() { max_length=1; maybe_null=1;}
- unsigned int size_of() { return sizeof(*this);}
};
/* replication functions */
@@ -868,7 +867,6 @@ class Item_master_pos_wait :public Item_int_func
longlong val_int();
const char *func_name() const { return "master_pos_wait"; }
void fix_length_and_dec() { max_length=1; maybe_null=1;}
- unsigned int size_of() { return sizeof(*this);}
};
@@ -890,11 +888,10 @@ public:
void update_hash(void *ptr, uint length, enum Item_result type);
bool update();
enum Item_result result_type () const { return cached_result_type; }
- bool fix_fields(THD *thd,struct st_table_list *tables);
+ bool fix_fields(THD *thd, struct st_table_list *tables, Item **ref);
void fix_length_and_dec();
void print(String *str);
const char *func_name() const { return "set_user_var"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -919,7 +916,6 @@ public:
table_map used_tables() const
{ return const_var_flag ? 0 : RAND_TABLE_BIT; }
bool eq(const Item *item, bool binary_cmp) const;
- unsigned int size_of() { return sizeof(*this);}
};
@@ -968,14 +964,97 @@ public:
}
enum Functype functype() const { return FT_FUNC; }
void update_used_tables() {}
- bool fix_fields(THD *thd,struct st_table_list *tlist);
+ bool fix_fields(THD *thd, struct st_table_list *tlist, Item **ref);
bool eq(const Item *, bool binary_cmp) const;
longlong val_int() { return val()!=0.0; }
double val();
bool fix_index();
void init_search(bool no_order);
- unsigned int size_of() { return sizeof(*this);}
+};
+
+
+class Item_func_dimension :public Item_int_func
+{
+ String value;
+public:
+ Item_func_dimension(Item *a) :Item_int_func(a) {}
+ longlong val_int();
+ const char *func_name() const { return "dimension"; }
+ void fix_length_and_dec() { max_length=10; }
+};
+
+
+class Item_func_x :public Item_real_func
+{
+ String value;
+public:
+ Item_func_x(Item *a) :Item_real_func(a) {}
+ double val();
+ const char *func_name() const { return "x"; }
+};
+
+
+class Item_func_y :public Item_real_func
+{
+ String value;
+public:
+ Item_func_y(Item *a) :Item_real_func(a) {}
+ double val();
+ const char *func_name() const { return "y"; }
+};
+
+
+class Item_func_numgeometries :public Item_int_func
+{
+ String value;
+public:
+ Item_func_numgeometries(Item *a) :Item_int_func(a) {}
+ longlong val_int();
+ const char *func_name() const { return "numgeometries"; }
+ void fix_length_and_dec() { max_length=10; }
+};
+
+
+class Item_func_numinteriorring :public Item_int_func
+{
+ String value;
+public:
+ Item_func_numinteriorring(Item *a) :Item_int_func(a) {}
+ longlong val_int();
+ const char *func_name() const { return "numinteriorring"; }
+ void fix_length_and_dec() { max_length=10; }
+};
+
+
+class Item_func_numpoints :public Item_int_func
+{
+ String value;
+public:
+ Item_func_numpoints(Item *a) :Item_int_func(a) {}
+ longlong val_int();
+ const char *func_name() const { return "numpoints"; }
+ void fix_length_and_dec() { max_length=10; }
+};
+
+
+class Item_func_area :public Item_real_func
+{
+ String value;
+public:
+ Item_func_area(Item *a) :Item_real_func(a) {}
+ double val();
+ const char *func_name() const { return "area"; }
+};
+
+
+class Item_func_glength :public Item_real_func
+{
+ String value;
+public:
+ Item_func_glength(Item *a) :Item_real_func(a) {}
+ double val();
+ const char *func_name() const { return "glength"; }
};
@@ -998,16 +1077,6 @@ public:
const char *func_name() const { return "match_bool"; }
};
-/* For type casts */
-
-enum Item_cast
-{
- ITEM_CAST_BINARY, ITEM_CAST_SIGNED_INT, ITEM_CAST_UNSIGNED_INT,
- ITEM_CAST_DATE, ITEM_CAST_TIME, ITEM_CAST_DATETIME
-};
-
-Item *create_func_cast(Item *a, Item_cast cast_type);
-
class Item_func_bit_xor : public Item_int_func
{
@@ -1026,5 +1095,12 @@ public:
longlong val_int();
const char *func_name() const { return "check_lock"; }
void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1;}
- unsigned int size_of() { return sizeof(*this);}
+};
+
+/* For type casts */
+
+enum Item_cast
+{
+ ITEM_CAST_BINARY, ITEM_CAST_SIGNED_INT, ITEM_CAST_UNSIGNED_INT,
+ ITEM_CAST_DATE, ITEM_CAST_TIME, ITEM_CAST_DATETIME
};
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 720313f4be7..2bc9b170fc1 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -37,14 +37,14 @@
#include "sha1.h"
#include "my_aes.h"
-String empty_string("");
+String empty_string("",default_charset_info);
uint nr_of_decimals(const char *str)
{
if ((str=strchr(str,'.')))
{
const char *start= ++str;
- for (; isdigit(*str) ; str++) ;
+ for (; my_isdigit(system_charset_info,*str) ; str++) ;
return (uint) (str-start);
}
return 0;
@@ -480,7 +480,7 @@ error:
String *Item_func_concat_ws::val_str(String *str)
{
char tmp_str_buff[10];
- String tmp_sep_str(tmp_str_buff, sizeof(tmp_str_buff)),
+ String tmp_sep_str(tmp_str_buff, sizeof(tmp_str_buff),default_charset_info),
*sep_str, *res, *res2,*use_as_buff;
uint i;
@@ -619,7 +619,7 @@ String *Item_func_reverse::val_str(String *str)
ptr = (char *) res->ptr();
end=ptr+res->length();
#ifdef USE_MB
- if (use_mb(default_charset_info) && !binary)
+ if (use_mb(res->charset()) && !binary)
{
String tmpstr;
tmpstr.copy(*res);
@@ -627,7 +627,7 @@ String *Item_func_reverse::val_str(String *str)
register uint32 l;
while (ptr < end)
{
- if ((l=my_ismbchar(default_charset_info, ptr,end)))
+ if ((l=my_ismbchar(res->charset(), ptr,end)))
tmp-=l, memcpy(tmp,ptr,l), ptr+=l;
else
*--tmp=*ptr++;
@@ -670,8 +670,7 @@ String *Item_func_replace::val_str(String *str)
#ifdef USE_MB
const char *ptr,*end,*strend,*search,*search_end;
register uint32 l;
- bool binary_str = (args[0]->binary || args[1]->binary ||
- !use_mb(default_charset_info));
+ bool binary_str;
#endif
null_value=0;
@@ -682,6 +681,10 @@ String *Item_func_replace::val_str(String *str)
if (args[1]->null_value)
goto null;
+#ifdef USE_MB
+ binary_str = (args[0]->binary || args[1]->binary || !use_mb(res->charset()));
+#endif
+
if (res2->length() == 0)
return res;
#ifndef USE_MB
@@ -728,7 +731,7 @@ redo:
goto redo;
}
skipp:
- if ((l=my_ismbchar(default_charset_info, ptr,strend))) ptr+=l;
+ if ((l=my_ismbchar(res->charset(), ptr,strend))) ptr+=l;
else ++ptr;
}
}
@@ -787,7 +790,7 @@ String *Item_func_insert::val_str(String *str)
args[3]->null_value)
goto null; /* purecov: inspected */
#ifdef USE_MB
- if (use_mb(default_charset_info) && !args[0]->binary)
+ if (use_mb(res->charset()) && !args[0]->binary)
{
start=res->charpos(start);
length=res->charpos(length,start);
@@ -860,7 +863,7 @@ String *Item_func_left::val_str(String *str)
if (length <= 0)
return &empty_string;
#ifdef USE_MB
- if (use_mb(default_charset_info) && !binary)
+ if (use_mb(res->charset()) && !binary)
length = res->charpos(length);
#endif
if (res->length() > (ulong) length)
@@ -868,6 +871,7 @@ String *Item_func_left::val_str(String *str)
if (!res->alloced_length())
{ // Don't change const str
str_value= *res; // Not malloced string
+ str_value.set_charset(res->charset());
res= &str_value;
}
res->length((uint) length);
@@ -908,7 +912,7 @@ String *Item_func_right::val_str(String *str)
if (res->length() <= (uint) length)
return res; /* purecov: inspected */
#ifdef USE_MB
- if (use_mb(default_charset_info) && !binary)
+ if (use_mb(res->charset()) && !binary)
{
uint start=res->numchars()-(uint) length;
if (start<=0) return res;
@@ -941,7 +945,7 @@ String *Item_func_substr::val_str(String *str)
(arg_count == 3 && args[2]->null_value))))
return 0; /* purecov: inspected */
#ifdef USE_MB
- if (use_mb(default_charset_info) && !binary)
+ if (use_mb(res->charset()) && !binary)
{
start=res->charpos(start);
length=res->charpos(length,start);
@@ -1001,7 +1005,7 @@ String *Item_func_substr_index::val_str(String *str)
return &empty_string; // Wrong parameters
#ifdef USE_MB
- if (use_mb(default_charset_info) && !binary)
+ if (use_mb(res->charset()) && !binary)
{
const char *ptr=res->ptr();
const char *strend = ptr+res->length();
@@ -1026,7 +1030,7 @@ String *Item_func_substr_index::val_str(String *str)
continue;
}
skipp:
- if ((l=my_ismbchar(default_charset_info, ptr,strend))) ptr+=l;
+ if ((l=my_ismbchar(res->charset(), ptr,strend))) ptr+=l;
else ++ptr;
} /* either not found or got total number when count<0 */
if (pass == 0) /* count<0 */
@@ -1098,7 +1102,7 @@ String *Item_func_ltrim::val_str(String *str)
if ((null_value=args[0]->null_value))
return 0; /* purecov: inspected */
char buff[MAX_FIELD_WIDTH];
- String tmp(buff,sizeof(buff));
+ String tmp(buff,sizeof(buff),res->charset());
String *remove_str=args[1]->val_str(&tmp);
uint remove_length;
LINT_INIT(remove_length);
@@ -1136,7 +1140,7 @@ String *Item_func_rtrim::val_str(String *str)
if ((null_value=args[0]->null_value))
return 0; /* purecov: inspected */
char buff[MAX_FIELD_WIDTH];
- String tmp(buff,sizeof(buff));
+ String tmp(buff,sizeof(buff),res->charset());
String *remove_str=args[1]->val_str(&tmp);
uint remove_length;
LINT_INIT(remove_length);
@@ -1155,11 +1159,11 @@ String *Item_func_rtrim::val_str(String *str)
{
char chr=(*remove_str)[0];
#ifdef USE_MB
- if (use_mb(default_charset_info) && !binary)
+ if (use_mb(res->charset()) && !binary)
{
while (ptr < end)
{
- if ((l=my_ismbchar(default_charset_info, ptr,end))) ptr+=l,p=ptr;
+ if ((l=my_ismbchar(res->charset(), ptr,end))) ptr+=l,p=ptr;
else ++ptr;
}
ptr=p;
@@ -1172,12 +1176,12 @@ String *Item_func_rtrim::val_str(String *str)
{
const char *r_ptr=remove_str->ptr();
#ifdef USE_MB
- if (use_mb(default_charset_info) && !binary)
+ if (use_mb(res->charset()) && !binary)
{
loop:
while (ptr + remove_length < end)
{
- if ((l=my_ismbchar(default_charset_info, ptr,end))) ptr+=l;
+ if ((l=my_ismbchar(res->charset(), ptr,end))) ptr+=l;
else ++ptr;
}
if (ptr + remove_length == end && !memcmp(ptr,r_ptr,remove_length))
@@ -1208,7 +1212,7 @@ String *Item_func_trim::val_str(String *str)
if ((null_value=args[0]->null_value))
return 0; /* purecov: inspected */
char buff[MAX_FIELD_WIDTH];
- String tmp(buff,sizeof(buff));
+ String tmp(buff,sizeof(buff),res->charset());
String *remove_str=args[1]->val_str(&tmp);
uint remove_length;
LINT_INIT(remove_length);
@@ -1223,14 +1227,14 @@ String *Item_func_trim::val_str(String *str)
while (ptr+remove_length <= end && !memcmp(ptr,r_ptr,remove_length))
ptr+=remove_length;
#ifdef USE_MB
- if (use_mb(default_charset_info) && !binary)
+ if (use_mb(res->charset()) && !binary)
{
char *p=ptr;
register uint32 l;
loop:
while (ptr + remove_length < end)
{
- if ((l=my_ismbchar(default_charset_info, ptr,end))) ptr+=l;
+ if ((l=my_ismbchar(res->charset(), ptr,end))) ptr+=l;
else ++ptr;
}
if (ptr + remove_length == end && !memcmp(ptr,r_ptr,remove_length))
@@ -1263,7 +1267,7 @@ String *Item_func_password::val_str(String *str)
if (res->length() == 0)
return &empty_string;
make_scrambled_password(tmp_value,res->c_ptr());
- str->set(tmp_value,16);
+ str->set(tmp_value,16,res->charset());
return str;
}
@@ -1297,7 +1301,7 @@ String *Item_func_encrypt::val_str(String *str)
}
pthread_mutex_lock(&LOCK_crypt);
char *tmp=crypt(res->c_ptr(),salt_ptr);
- str->set(tmp,(uint) strlen(tmp));
+ str->set(tmp,(uint) strlen(tmp),res->charset());
str->copy();
pthread_mutex_unlock(&LOCK_crypt);
return str;
@@ -1349,7 +1353,7 @@ String *Item_func_database::val_str(String *str)
if (!current_thd->db)
str->length(0);
else
- str->set((const char*) current_thd->db,(uint) strlen(current_thd->db));
+ str->set((const char*) current_thd->db,(uint) strlen(current_thd->db), default_charset_info);
return str;
}
@@ -1380,9 +1384,9 @@ extern "C" {
extern const char *soundex_map; // In mysys/static.c
}
-static char get_scode(char *ptr)
+static char get_scode(CHARSET_INFO *cs,char *ptr)
{
- uchar ch=toupper(*ptr);
+ uchar ch=my_toupper(cs,*ptr);
if (ch < 'A' || ch > 'Z')
{
// Thread extended alfa (country spec)
@@ -1404,21 +1408,21 @@ String *Item_func_soundex::val_str(String *str)
char *to= (char *) tmp_value.ptr();
char *from= (char *) res->ptr(), *end=from+res->length();
- while (from != end && isspace(*from)) // Skip pre-space
+ while (from != end && my_isspace(str->charset(),*from)) // Skip pre-space
from++; /* purecov: inspected */
if (from == end)
return &empty_string; // No alpha characters.
- *to++ = toupper(*from); // Copy first letter
- last_ch = get_scode(from); // code of the first letter
+ *to++ = my_toupper(str->charset(),*from);// Copy first letter
+ last_ch = get_scode(str->charset(),from);// code of the first letter
// for the first 'double-letter check.
// Loop on input letters until
// end of input (null) or output
// letter code count = 3
for (from++ ; from < end ; from++)
{
- if (!isalpha(*from))
+ if (!my_isalpha(str->charset(),*from))
continue;
- ch=get_scode(from);
+ ch=get_scode(str->charset(),from);
if ((ch != '0') && (ch != last_ch)) // if not skipped or double
{
*to++ = ch; // letter, copy to output
@@ -1888,6 +1892,228 @@ String *Item_func_conv::val_str(String *str)
}
+String *Item_func_conv_charset::val_str(String *str)
+{
+ my_wc_t wc;
+ int cnvres;
+ const uchar *s, *se;
+ uchar *d, *d0, *de;
+ uint32 dmaxlen;
+ String *arg= args[0]->val_str(str);
+ CHARSET_INFO *from,*to;
+
+ if (!arg)
+ {
+ null_value=1;
+ return 0;
+ }
+ null_value=0;
+
+ from=arg->charset();
+ to=conv_charset;
+
+ s=(const uchar*)arg->ptr();
+ se=s+arg->length();
+
+ dmaxlen=arg->length()*(to->mbmaxlen?to->mbmaxlen:1)+1;
+ str->alloc(dmaxlen);
+ d0=d=(unsigned char*)str->ptr();
+ de=d+dmaxlen;
+
+ while( s < se && d < de){
+
+ cnvres=from->mb_wc(from,&wc,s,se);
+ if (cnvres>0)
+ {
+ s+=cnvres;
+ }
+ else if (cnvres==MY_CS_ILSEQ)
+ {
+ s++;
+ wc='?';
+ }
+ else
+ break;
+
+outp:
+ cnvres=to->wc_mb(to,wc,d,de);
+ if (cnvres>0)
+ {
+ d+=cnvres;
+ }
+ else if (cnvres==MY_CS_ILUNI && wc!='?')
+ {
+ wc='?';
+ goto outp;
+ }
+ else
+ break;
+ };
+
+ str->length((uint32) (d-d0));
+ str->set_charset(to);
+ return str;
+}
+
+void Item_func_conv_charset::fix_length_and_dec()
+{
+ max_length = args[0]->max_length*(conv_charset->mbmaxlen?conv_charset->mbmaxlen:1);
+ str_value.set_charset(conv_charset);
+}
+
+
+
+String *Item_func_conv_charset3::val_str(String *str)
+{
+ my_wc_t wc;
+ int cnvres;
+ const uchar *s, *se;
+ uchar *d, *d0, *de;
+ uint32 dmaxlen;
+ String *arg= args[0]->val_str(str);
+ String *to_cs= args[1]->val_str(str);
+ String *from_cs= args[2]->val_str(str);
+ CHARSET_INFO *from_charset;
+ CHARSET_INFO *to_charset;
+
+ if (!arg || args[0]->null_value ||
+ !to_cs || args[1]->null_value ||
+ !from_cs || args[2]->null_value ||
+ !(from_charset=get_charset_by_name(from_cs->ptr(), MYF(MY_WME))) ||
+ !(to_charset=get_charset_by_name(to_cs->ptr(), MYF(MY_WME))))
+ {
+ null_value=1;
+ return 0;
+ }
+
+ s=(const uchar*)arg->ptr();
+ se=s+arg->length();
+
+ dmaxlen=arg->length()*(to_charset->mbmaxlen?to_charset->mbmaxlen:1)+1;
+ str->alloc(dmaxlen);
+ d0=d=(unsigned char*)str->ptr();
+ de=d+dmaxlen;
+
+ while( s < se && d < de){
+
+ cnvres=from_charset->mb_wc(from_charset,&wc,s,se);
+ if (cnvres>0)
+ {
+ s+=cnvres;
+ }
+ else if (cnvres==MY_CS_ILSEQ)
+ {
+ s++;
+ wc='?';
+ }
+ else
+ break;
+
+outp:
+ cnvres=to_charset->wc_mb(to_charset,wc,d,de);
+ if (cnvres>0)
+ {
+ d+=cnvres;
+ }
+ else if (cnvres==MY_CS_ILUNI && wc!='?')
+ {
+ wc='?';
+ goto outp;
+ }
+ else
+ break;
+ };
+
+ str->length((uint32) (d-d0));
+ str->set_charset(to_charset);
+ return str;
+}
+
+
+bool Item_func_conv_charset::fix_fields(THD *thd,struct st_table_list *tables, Item **ref)
+{
+ char buff[STACK_BUFF_ALLOC]; // Max argument in function
+ binary=0;
+ used_tables_cache=0;
+ const_item_cache=1;
+
+ if (thd && check_stack_overrun(thd,buff))
+ return 0; // Fatal error if flag is set!
+ if (args[0]->fix_fields(thd, tables, args))
+ return 1;
+ maybe_null=args[0]->maybe_null;
+ binary=args[0]->binary;
+ const_item_cache=args[0]->const_item();
+ str_value.set_charset(conv_charset);
+ fix_length_and_dec();
+ return 0;
+}
+
+
+void Item_func_conv_charset3::fix_length_and_dec()
+{
+ max_length = args[0]->max_length;
+}
+
+String *Item_func_set_collation::val_str(String *str)
+{
+ str=args[0]->val_str(str);
+ null_value=args[0]->null_value;
+ str->set_charset(set_collation);
+ return str;
+}
+
+bool Item_func_set_collation::fix_fields(THD *thd,struct st_table_list *tables, Item **ref)
+{
+ char buff[STACK_BUFF_ALLOC]; // Max argument in function
+ binary=0;
+ used_tables_cache=0;
+ const_item_cache=1;
+
+ if (thd && check_stack_overrun(thd,buff))
+ return 0; // Fatal error if flag is set!
+ if (args[0]->fix_fields(thd, tables, args))
+ return 1;
+ maybe_null=args[0]->maybe_null;
+ binary=args[0]->binary;
+ const_item_cache=args[0]->const_item();
+ str_value.set_charset(set_collation);
+ fix_length_and_dec();
+ return 0;
+}
+
+bool Item_func_set_collation::eq(const Item *item, bool binary_cmp) const
+{
+ /* Assume we don't have rtti */
+ if (this == item)
+ return 1;
+ if (item->type() != FUNC_ITEM)
+ return 0;
+ Item_func *item_func=(Item_func*) item;
+ if (arg_count != item_func->arg_count ||
+ func_name() != item_func->func_name())
+ return 0;
+ Item_func_set_collation *item_func_sc=(Item_func_set_collation*) item;
+ if (set_collation != item_func_sc->set_collation)
+ return 0;
+ for (uint i=0; i < arg_count ; i++)
+ if (!args[i]->eq(item_func_sc->args[i], binary_cmp))
+ return 0;
+ return 1;
+}
+
+
+String *Item_func_charset::val_str(String *str)
+{
+ String *res = args[0]->val_str(str);
+
+ if ((null_value=(args[0]->null_value || !res->charset())))
+ return 0;
+ str->copy(res->charset()->name,strlen(res->charset()->name));
+ return str;
+}
+
+
String *Item_func_hex::val_str(String *str)
{
if (args[0]->result_type() != STRING_RESULT)
@@ -2007,7 +2233,7 @@ String* Item_func_export_set::val_str(String* str)
}
break;
case 3:
- sep_buf.set(",", 1);
+ sep_buf.set(",", 1, default_charset_info);
sep = &sep_buf;
}
null_value=0;
@@ -2071,6 +2297,7 @@ String* Item_func_inet_ntoa::val_str(String* str)
return str;
}
+
/*
QUOTE() function returns argument string in single quotes suitable for
using in a SQL statement.
@@ -2161,3 +2388,338 @@ null:
null_value= 1;
return 0;
}
+
+
+/*******************************************************
+General functions for spatial objects
+********************************************************/
+
+#include "gstream.h"
+
+String *Item_func_geometry_from_text::val_str(String *str)
+{
+ Geometry geom;
+ String *wkt = args[0]->val_str(str);
+ GTextReadStream trs(wkt->ptr(), wkt->length());
+
+ str->length(0);
+ if ((null_value=(args[0]->null_value || geom.create_from_wkt(&trs, str, 0))))
+ return 0;
+ return str;
+}
+
+
+void Item_func_geometry_from_text::fix_length_and_dec()
+{
+ max_length=MAX_BLOB_WIDTH;
+}
+
+
+String *Item_func_as_text::val_str(String *str)
+{
+ String *wkt = args[0]->val_str(str);
+ Geometry geom;
+
+ if ((null_value=(args[0]->null_value ||
+ geom.create_from_wkb(wkt->ptr(),wkt->length()))))
+ return 0;
+
+ str->length(0);
+
+ if ((null_value=geom.as_wkt(str)))
+ return 0;
+
+ return str;
+}
+
+void Item_func_as_text::fix_length_and_dec()
+{
+ max_length=MAX_BLOB_WIDTH;
+}
+
+String *Item_func_geometry_type::val_str(String *str)
+{
+ String *wkt = args[0]->val_str(str);
+ Geometry geom;
+
+ if ((null_value=(args[0]->null_value ||
+ geom.create_from_wkb(wkt->ptr(),wkt->length()))))
+ return 0;
+ str->copy(geom.get_class_info()->m_name,strlen(geom.get_class_info()->m_name));
+ return str;
+}
+
+
+String *Item_func_envelope::val_str(String *str)
+{
+ String *wkb = args[0]->val_str(str);
+ Geometry geom;
+
+ null_value = args[0]->null_value ||
+ geom.create_from_wkb(wkb->ptr(),wkb->length()) ||
+ geom.envelope(str);
+
+ return null_value ? 0 : str;
+}
+
+
+String *Item_func_centroid::val_str(String *str)
+{
+ String *wkb = args[0]->val_str(str);
+ Geometry geom;
+
+ null_value = args[0]->null_value ||
+ geom.create_from_wkb(wkb->ptr(),wkb->length()) ||
+ !GEOM_METHOD_PRESENT(geom,centroid) ||
+ geom.centroid(str);
+
+ return null_value ? 0: str;
+}
+
+
+/***********************************************
+ Spatial decomposition functions
+***********************************************/
+
+String *Item_func_spatial_decomp::val_str(String *str)
+{
+ String *wkb = args[0]->val_str(str);
+ Geometry geom;
+
+ if ((null_value = (args[0]->null_value ||
+ geom.create_from_wkb(wkb->ptr(),wkb->length()))))
+ return 0;
+
+ null_value=1;
+ switch(decomp_func)
+ {
+ case SP_STARTPOINT:
+ if (!GEOM_METHOD_PRESENT(geom,start_point) || geom.start_point(str))
+ goto ret;
+ break;
+
+ case SP_ENDPOINT:
+ if (!GEOM_METHOD_PRESENT(geom,end_point) || geom.end_point(str))
+ goto ret;
+ break;
+
+ case SP_EXTERIORRING:
+ if (!GEOM_METHOD_PRESENT(geom,exterior_ring) || geom.exterior_ring(str))
+ goto ret;
+ break;
+
+ default:
+ goto ret;
+ }
+ null_value=0;
+
+ret:
+ return null_value ? 0 : str;
+}
+
+
+String *Item_func_spatial_decomp_n::val_str(String *str)
+{
+ String *wkb = args[0]->val_str(str);
+ long n = (long) args[1]->val_int();
+ Geometry geom;
+
+ if ((null_value = (args[0]->null_value ||
+ args[1]->null_value ||
+ geom.create_from_wkb(wkb->ptr(),wkb->length()) )))
+ return 0;
+
+ null_value=1;
+
+ switch(decomp_func_n)
+ {
+ case SP_POINTN:
+ if (!GEOM_METHOD_PRESENT(geom,point_n) ||
+ geom.point_n(n,str))
+ goto ret;
+ break;
+
+ case SP_GEOMETRYN:
+ if (!GEOM_METHOD_PRESENT(geom,geometry_n) ||
+ geom.geometry_n(n,str))
+ goto ret;
+ break;
+
+ case SP_INTERIORRINGN:
+ if (!GEOM_METHOD_PRESENT(geom,interior_ring_n) ||
+ geom.interior_ring_n(n,str))
+ goto ret;
+ break;
+
+ default:
+ goto ret;
+ }
+ null_value=0;
+
+ret:
+ return null_value ? 0 : str;
+}
+
+
+
+/***********************************************
+Functions to concatinate various spatial objects
+************************************************/
+
+
+/*
+* Concatinate doubles into Point
+*/
+
+
+String *Item_func_point::val_str(String *str)
+{
+ if ( (null_value = (args[0]->null_value ||
+ args[1]->null_value ||
+ str->realloc(1+4+8+8))))
+ return 0;
+
+ str->length(0);
+ str->q_append((char)Geometry::wkbNDR);
+ str->q_append((uint32)Geometry::wkbPoint);
+ str->q_append((double)args[0]->val());
+ str->q_append((double)args[1]->val());
+ return str;
+}
+
+
+/*
+ Concatinates various items into various collections
+ with checkings for valid wkb type of items.
+ For example, MultiPoint can be a collection of Points only.
+ coll_type contains wkb type of target collection.
+ item_type contains a valid wkb type of items.
+ In the case when coll_type is wkbGeometryCollection,
+ we do not check wkb type of items, any is valid.
+*/
+
+String *Item_func_spatial_collection::val_str(String *str)
+{
+ uint i;
+
+ null_value=1;
+
+ str->length(0);
+ if(str->reserve(9,512))
+ return 0;
+
+ str->q_append((char)Geometry::wkbNDR);
+ str->q_append((uint32)coll_type);
+ str->q_append((uint32)arg_count);
+
+ for (i = 0; i < arg_count; ++i)
+ {
+ if (args[i]->null_value)
+ goto ret;
+
+ String *res = args[i]->val_str(str);
+
+ if ( coll_type == Geometry::wkbGeometryCollection )
+ {
+ /*
+ In the case of GeometryCollection we don't need
+ any checkings for item types, so just copy them
+ into target collection
+ */
+ if ((null_value=(str->reserve(res->length(),512))))
+ goto ret;
+
+ str->q_append(res->ptr(),res->length());
+ }
+ else
+ {
+ enum Geometry::wkbType wkb_type;
+ uint32 len=res->length();
+ const char *data=res->ptr()+1;
+
+ /*
+ In the case of named collection we must to
+ check that items are of specific type, let's
+ do this checking now
+ */
+
+ if (len < 5)
+ goto ret;
+ wkb_type= (Geometry::wkbType) uint4korr(data);
+ data+=4;
+ len-=5;
+ if (wkb_type != item_type)
+ goto ret;
+
+ switch (coll_type) {
+ case Geometry::wkbMultiPoint:
+ case Geometry::wkbMultiLineString:
+ case Geometry::wkbMultiPolygon:
+ if (len < WKB_HEADER_SIZE)
+ goto ret;
+
+ data+=WKB_HEADER_SIZE;
+ len-=WKB_HEADER_SIZE;
+ if (str->reserve(len,512))
+ goto ret;
+ str->q_append(data,len);
+ break;
+
+ case Geometry::wkbLineString:
+ if (str->reserve(POINT_DATA_SIZE,512))
+ goto ret;
+ str->q_append(data,POINT_DATA_SIZE);
+ break;
+
+ case Geometry::wkbPolygon:
+ {
+ uint32 n_points;
+ double x1, y1, x2, y2;
+
+ if (len < WKB_HEADER_SIZE + 4 + 8 + 8)
+ goto ret;
+ data+=WKB_HEADER_SIZE;
+ len-=WKB_HEADER_SIZE;
+
+ uint32 llen=len;
+ const char *ldata=data;
+
+ n_points=uint4korr(data);
+ data+=4;
+ float8get(x1,data);
+ data+=8;
+ float8get(y1,data);
+ data+=8;
+
+ len-= 4 + 8 + 8;
+
+ if (len < n_points * POINT_DATA_SIZE)
+ goto ret;
+ data+=(n_points-2) * POINT_DATA_SIZE;
+
+ float8get(x2,data);
+ float8get(y2,data+8);
+
+ if ((x1 != x2) || (y1 != y2))
+ goto ret;
+
+ if (str->reserve(llen,512))
+ goto ret;
+ str->q_append(ldata, llen);
+ }
+ break;
+
+ default:
+ goto ret;
+ }
+ }
+ }
+
+ if (str->length() > max_allowed_packet)
+ goto ret;
+
+ null_value = 0;
+
+ret:
+ return null_value ? 0 : str;
+}
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 3bbec149e9c..4ac1b118863 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -35,10 +35,8 @@ public:
double val();
enum Item_result result_type () const { return STRING_RESULT; }
void left_right_max_length();
- unsigned int size_of() { return sizeof(*this);}
};
-
class Item_func_md5 :public Item_str_func
{
String tmp_value;
@@ -47,7 +45,6 @@ public:
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "md5"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -88,7 +85,6 @@ public:
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "concat"; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_concat_ws :public Item_str_func
@@ -103,13 +99,12 @@ public:
String *val_str(String *);
void fix_length_and_dec();
void update_used_tables();
- bool fix_fields(THD *thd,struct st_table_list *tlist)
+ bool fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref)
{
- return (separator->fix_fields(thd,tlist)
- || Item_func::fix_fields(thd,tlist));
+ return (separator->fix_fields(thd, tlist, &separator)
+ || Item_func::fix_fields(thd, tlist, ref));
}
const char *func_name() const { return "concat_ws"; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_reverse :public Item_str_func
@@ -130,7 +125,6 @@ public:
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "replace"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -143,7 +137,6 @@ public:
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "insert"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -190,7 +183,6 @@ public:
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "right"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -203,7 +195,6 @@ public:
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "substr"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -215,7 +206,6 @@ public:
String *val_str(String *);
void fix_length_and_dec() { max_length= args[0]->max_length; }
const char *func_name() const { return "substr_index"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -227,7 +217,6 @@ public:
String *val_str(String *);
void fix_length_and_dec() { max_length= args[0]->max_length; }
const char *func_name() const { return "ltrim"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -239,7 +228,6 @@ public:
String *val_str(String *);
void fix_length_and_dec() { max_length= args[0]->max_length; }
const char *func_name() const { return "rtrim"; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_trim :public Item_str_func
@@ -250,7 +238,6 @@ public:
String *val_str(String *);
void fix_length_and_dec() { max_length= args[0]->max_length; }
const char *func_name() const { return "trim"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -262,7 +249,6 @@ public:
String *val_str(String *);
void fix_length_and_dec() { max_length = 16; }
const char *func_name() const { return "password"; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_des_encrypt :public Item_str_func
@@ -275,7 +261,6 @@ public:
void fix_length_and_dec()
{ maybe_null=1; max_length = args[0]->max_length+8; }
const char *func_name() const { return "des_encrypt"; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_des_decrypt :public Item_str_func
@@ -287,7 +272,6 @@ public:
String *val_str(String *);
void fix_length_and_dec() { maybe_null=1; max_length = args[0]->max_length; }
const char *func_name() const { return "des_decrypt"; }
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_encrypt :public Item_str_func
@@ -298,7 +282,6 @@ public:
Item_func_encrypt(Item *a, Item *b): Item_str_func(a,b) {}
String *val_str(String *);
void fix_length_and_dec() { maybe_null=1; max_length = 13; }
- unsigned int size_of() { return sizeof(*this);}
};
#include "sql_crypt.h"
@@ -312,7 +295,6 @@ public:
Item_str_func(a),sql_crypt(seed) {}
String *val_str(String *);
void fix_length_and_dec();
- unsigned int size_of() { return sizeof(*this);}
};
class Item_func_decode :public Item_func_encode
@@ -350,7 +332,6 @@ public:
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "soundex"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -364,14 +345,14 @@ public:
double val();
longlong val_int();
String *val_str(String *str);
- bool fix_fields(THD *thd,struct st_table_list *tlist)
+ bool fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref)
{
- return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
+ return (item->fix_fields(thd, tlist, &item) ||
+ Item_func::fix_fields(thd, tlist, ref));
}
void fix_length_and_dec();
void update_used_tables();
const char *func_name() const { return "elt"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -384,14 +365,14 @@ public:
Item_func_make_set(Item *a,List<Item> &list) :Item_str_func(list),item(a) {}
~Item_func_make_set() { delete item; }
String *val_str(String *str);
- bool fix_fields(THD *thd,struct st_table_list *tlist)
+ bool fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref)
{
- return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
+ return (item->fix_fields(thd, tlist, &item) ||
+ Item_func::fix_fields(thd, tlist, ref));
}
void fix_length_and_dec();
void update_used_tables();
const char *func_name() const { return "make_set"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -406,7 +387,6 @@ public:
max_length=args[0]->max_length+(args[0]->max_length-args[0]->decimals)/3;
}
const char *func_name() const { return "format"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -428,7 +408,6 @@ public:
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "repeat"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -441,7 +420,6 @@ public:
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "rpad"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -454,7 +432,6 @@ public:
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "lpad"; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -476,7 +453,6 @@ public:
const char *func_name() const { return "hex"; }
String *val_str(String *);
void fix_length_and_dec() { decimals=0; max_length=args[0]->max_length*2; }
- unsigned int size_of() { return sizeof(*this);}
};
@@ -501,7 +477,6 @@ public:
const char *func_name() const { return "load_file"; }
void fix_length_and_dec()
{ binary=1; maybe_null=1; max_length=MAX_BLOB_WIDTH;}
- unsigned int size_of() { return sizeof(*this);}
};
@@ -516,7 +491,7 @@ class Item_func_export_set: public Item_str_func
const char *func_name() const { return "export_set"; }
};
- class Item_func_inet_ntoa : public Item_str_func
+class Item_func_inet_ntoa : public Item_str_func
{
public:
Item_func_inet_ntoa(Item *a) :Item_str_func(a)
@@ -535,3 +510,247 @@ public:
String *val_str(String *);
void fix_length_and_dec() { max_length= args[0]->max_length * 2 + 2; }
};
+
+class Item_func_conv_charset :public Item_str_func
+{
+ CHARSET_INFO *conv_charset;
+public:
+ Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a)
+ { conv_charset=cs; }
+ bool fix_fields(THD *thd,struct st_table_list *tables,Item **ref);
+ String *val_str(String *);
+ void fix_length_and_dec();
+ const char *func_name() const { return "conv_charset"; }
+};
+
+class Item_func_set_collation :public Item_str_func
+{
+ CHARSET_INFO *set_collation;
+public:
+ Item_func_set_collation(Item *a, CHARSET_INFO *cs) :Item_str_func(a)
+ { set_collation=cs; }
+ bool fix_fields(THD *thd,struct st_table_list *tables, Item **ref);
+ String *val_str(String *);
+ void fix_length_and_dec()
+ {
+ max_length = args[0]->max_length;
+ str_value.set_charset(set_collation);
+ }
+ bool eq(const Item *item, bool binary_cmp) const;
+ const char *func_name() const { return "set_collation"; }
+};
+
+class Item_func_conv_charset3 :public Item_str_func
+{
+public:
+ Item_func_conv_charset3(Item *arg1,Item *arg2,Item *arg3)
+ :Item_str_func(arg1,arg2,arg3) {}
+ String *val_str(String *);
+ void fix_length_and_dec();
+ const char *func_name() const { return "conv_charset3"; }
+};
+
+class Item_func_charset :public Item_str_func
+{
+public:
+ Item_func_charset(Item *a) :Item_str_func(a) {}
+ String *val_str(String *);
+ const char *func_name() const { return "charset"; }
+ void fix_length_and_dec()
+ {
+ max_length=20; // should be enough
+ };
+};
+
+
+/*******************************************************
+Spatial functions
+********************************************************/
+
+class Item_func_geometry_from_text :public Item_str_func
+{
+public:
+ Item_func_geometry_from_text(Item *a) :Item_str_func(a) {}
+ const char *func_name() const { return "geometryfromtext"; }
+ String *val_str(String *);
+ void fix_length_and_dec();
+};
+
+class Item_func_as_text :public Item_str_func
+{
+public:
+ Item_func_as_text(Item *a) :Item_str_func(a) {}
+ const char *func_name() const { return "astext"; }
+ String *val_str(String *);
+ void fix_length_and_dec();
+};
+
+class Item_func_geometry_type :public Item_str_func
+{
+public:
+ Item_func_geometry_type(Item *a) :Item_str_func(a) {}
+ String *val_str(String *);
+ const char *func_name() const { return "geometrytype"; }
+ void fix_length_and_dec()
+ {
+ max_length=20; // "GeometryCollection" is the most long
+ };
+};
+
+class Item_func_centroid :public Item_str_func
+{
+public:
+ Item_func_centroid(Item *a) :Item_str_func(a) {}
+ const char *func_name() const { return "centroid"; }
+ String *val_str(String *);
+ void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;}
+};
+
+class Item_func_envelope :public Item_str_func
+{
+public:
+ Item_func_envelope(Item *a) :Item_str_func(a) {}
+ const char *func_name() const { return "envelope"; }
+ String *val_str(String *);
+ void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;}
+};
+
+class Item_func_point :public Item_str_func
+{
+public:
+ Item_func_point(Item *a,Item *b) :Item_str_func(a,b) {}
+ const char *func_name() const { return "point"; }
+ String *val_str(String *);
+ void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;}
+};
+
+class Item_func_spatial_decomp :public Item_str_func
+{
+ enum Functype decomp_func;
+public:
+ Item_func_spatial_decomp(Item *a, Item_func::Functype ft) :
+ Item_str_func(a) { decomp_func = ft; }
+ const char *func_name() const
+ {
+ switch (decomp_func)
+ {
+ case SP_STARTPOINT:
+ return "startpoint";
+ case SP_ENDPOINT:
+ return "endpoint";
+ case SP_EXTERIORRING:
+ return "exteriorring";
+ default:
+ return "spatial_decomp_unknown";
+ }
+ }
+ String *val_str(String *);
+ void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;}
+};
+
+class Item_func_spatial_decomp_n :public Item_str_func
+{
+ enum Functype decomp_func_n;
+public:
+ Item_func_spatial_decomp_n(Item *a, Item *b, Item_func::Functype ft) :
+ Item_str_func(a, b) { decomp_func_n = ft; }
+ const char *func_name() const
+ {
+ switch (decomp_func_n)
+ {
+ case SP_POINTN:
+ return "pointn";
+ case SP_GEOMETRYN:
+ return "geometryn";
+ case SP_INTERIORRINGN:
+ return "interiorringn";
+ default:
+ return "spatial_decomp_n_unknown";
+ }
+ }
+ String *val_str(String *);
+ void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;}
+};
+
+
+class Item_func_spatial_collection :public Item_str_func
+{
+ String tmp_value;
+ enum Geometry::wkbType coll_type;
+ enum Geometry::wkbType item_type;
+public:
+ Item_func_spatial_collection(
+ List<Item> &list, enum Geometry::wkbType ct, enum Geometry::wkbType it) :
+ Item_str_func(list)
+ {
+ coll_type=ct;
+ item_type=it;
+ }
+ String *val_str(String *);
+ void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;}
+ const char *func_name() const { return "multipoint"; }
+};
+
+
+/*
+class Item_func_multipoint :public Item_str_func
+{
+ String tmp_value;
+public:
+ Item_func_multipoint(List<Item> &list) :Item_str_func(list) {}
+ String *val_str(String *);
+ void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;}
+ const char *func_name() const { return "multipoint"; }
+};
+
+class Item_func_linestring :public Item_str_func
+{
+ String tmp_value;
+public:
+ Item_func_linestring(List<Item> &list) :Item_str_func(list) {}
+ String *val_str(String *);
+ void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;}
+ const char *func_name() const { return "linestring"; }
+};
+
+class Item_func_multilinestring :public Item_str_func
+{
+ String tmp_value;
+public:
+ Item_func_multilinestring(List<Item> &list) :Item_str_func(list) {}
+ String *val_str(String *);
+ void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;}
+ const char *func_name() const { return "multilinestring"; }
+};
+
+class Item_func_polygon :public Item_str_func
+{
+ String tmp_value;
+public:
+ Item_func_polygon(List<Item> &list) :Item_str_func(list) {}
+ String *val_str(String *);
+ void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;}
+ const char *func_name() const { return "polygon"; }
+};
+
+class Item_func_multipolygon :public Item_str_func
+{
+ String tmp_value;
+public:
+ Item_func_multipolygon(List<Item> &list) :Item_str_func(list) {}
+ String *val_str(String *);
+ void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;}
+ const char *func_name() const { return "multipolygon"; }
+};
+
+class Item_func_geometrycollection :public Item_str_func
+{
+ String tmp_value;
+public:
+ Item_func_geometrycollection(List<Item> &list) :Item_str_func(list) {}
+ String *val_str(String *);
+ void fix_length_and_dec(){max_length=MAX_BLOB_WIDTH;}
+ const char *func_name() const { return "geometrycollection"; }
+};
+
+*/
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
new file mode 100644
index 00000000000..b0a94f0b8e6
--- /dev/null
+++ b/sql/item_subselect.cc
@@ -0,0 +1,211 @@
+/* Copyright (C) 2000 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/*
+ subselect Item
+
+SUBSELECT TODO:
+ - add function from mysql_select that use JOIN* as parameter to JOIN methods
+ (sql_select.h/sql_select.cc)
+ - remove double 'having' & 'having_list' from JOIN
+ (sql_select.h/sql_select.cc)
+
+ - subselect in HAVING clause
+ - add subselect union select (sql_union.cc)
+
+*/
+
+#ifdef __GNUC__
+#pragma implementation // gcc: Class implementation
+#endif
+
+#include "mysql_priv.h"
+#include "sql_select.h"
+
+Item_subselect::Item_subselect(THD *thd, st_select_lex *select_lex,
+ select_subselect *result):
+ assigned(0), executed(0), optimized(0), error(0)
+{
+ DBUG_ENTER("Item_subselect::Item_subselect");
+ DBUG_PRINT("subs", ("select_lex 0x%xl", (long) select_lex));
+ this->result= result;
+ SELECT_LEX_UNIT *unit= select_lex->master_unit();
+ unit->offset_limit_cnt= unit->global_parameters->offset_limit;
+ unit->select_limit_cnt= unit->global_parameters->select_limit+
+ unit->global_parameters ->offset_limit;
+ if (unit->select_limit_cnt < unit->global_parameters->select_limit)
+ unit->select_limit_cnt= HA_POS_ERROR; // no limit
+ if (unit->select_limit_cnt == HA_POS_ERROR)
+ select_lex->options&= ~OPTION_FOUND_ROWS;
+ join= new JOIN(thd, select_lex->item_list, select_lex->options, result);
+ if (!join || !result)
+ {
+ //out of memory
+ thd->fatal_error= 1;
+ my_printf_error(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
+ }
+ this->select_lex= select_lex;
+ assign_null();
+ /*
+ item value is NULL if select_subselect not changed this value
+ (i.e. some rows will be found returned)
+ */
+ null_value= 1;
+ DBUG_VOID_RETURN;
+}
+
+void Item_subselect::make_field (Send_field *tmp_field)
+{
+ if (null_value)
+ {
+ init_make_field(tmp_field,FIELD_TYPE_NULL);
+ tmp_field->length=4;
+ } else {
+ init_make_field(tmp_field, ((result_type() == STRING_RESULT) ?
+ FIELD_TYPE_VAR_STRING :
+ (result_type() == INT_RESULT) ?
+ FIELD_TYPE_LONGLONG : FIELD_TYPE_DOUBLE));
+ }
+}
+
+bool Item_subselect::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
+{
+ // Is it one field subselect?
+ if (select_lex->item_list.elements > max_columns)
+ {
+ my_printf_error(ER_SUBSELECT_NO_1_COL, ER(ER_SUBSELECT_NO_1_COL), MYF(0));
+ return 1;
+ }
+ SELECT_LEX *save_select= thd->lex.select;
+ thd->lex.select= select_lex;
+ if(join->prepare((TABLE_LIST*) select_lex->table_list.first,
+ select_lex->where,
+ (ORDER*) select_lex->order_list.first,
+ (ORDER*) select_lex->group_list.first,
+ select_lex->having,
+ (ORDER*) 0, select_lex,
+ select_lex->master_unit()))
+ return 1;
+ thd->lex.select= save_select;
+ return 0;
+}
+
+int Item_subselect::exec()
+{
+ DBUG_ENTER("Item_subselect::exec");
+ if (!optimized)
+ {
+ optimized=1;
+ if (join->optimize())
+ {
+ executed= 1;
+ DBUG_RETURN(join->error?join->error:1);
+ }
+ }
+ if (join->select_lex->depended && executed)
+ {
+ if (join->reinit())
+ {
+ error= 1;
+ DBUG_RETURN(1);
+ }
+ assign_null();
+ executed= assigned= 0;
+ }
+ if (!executed)
+ {
+ SELECT_LEX *save_select= join->thd->lex.select;
+ join->thd->lex.select= select_lex;
+ join->exec();
+ join->thd->lex.select= save_select;
+ executed= 1;
+ DBUG_RETURN(join->error);
+ }
+ DBUG_RETURN(0);
+}
+
+inline table_map Item_subselect::used_tables() const
+{
+ return (table_map) select_lex->depended ? 1L : 0L;
+}
+
+Item_singleval_subselect::Item_singleval_subselect(THD *thd,
+ st_select_lex *select_lex):
+ Item_subselect(thd, select_lex, new select_singleval_subselect(this))
+{
+ max_columns= 1;
+ maybe_null= 1;
+}
+
+Item::Type Item_subselect::type() const
+{
+ return SUBSELECT_ITEM;
+}
+
+double Item_singleval_subselect::val ()
+{
+ if (exec())
+ return 0;
+ return real_value;
+}
+
+longlong Item_singleval_subselect::val_int ()
+{
+ if (exec())
+ return 0;
+ return int_value;
+}
+
+String *Item_singleval_subselect::val_str (String *str)
+{
+ if (exec() || null_value)
+ return 0;
+ return &str_value;
+}
+
+Item_exists_subselect::Item_exists_subselect(THD *thd,
+ st_select_lex *select_lex):
+ Item_subselect(thd, select_lex, new select_exists_subselect(this))
+{
+ max_columns= UINT_MAX;
+ null_value= 0; //can't be NULL
+ maybe_null= 0; //can't be NULL
+ value= 0;
+ select_lex->select_limit= 1; // we need only 1 row to determinate existence
+}
+
+double Item_exists_subselect::val ()
+{
+ if (exec())
+ return 0;
+ return (double) value;
+}
+
+longlong Item_exists_subselect::val_int ()
+{
+ if (exec())
+ return 0;
+ return value;
+}
+
+String *Item_exists_subselect::val_str(String *str)
+{
+ if (exec())
+ return 0;
+ str->set(value);
+ return str;
+}
+
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
new file mode 100644
index 00000000000..88ea01f9c68
--- /dev/null
+++ b/sql/item_subselect.h
@@ -0,0 +1,135 @@
+/* Copyright (C) 2000 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* subselect Item */
+
+#ifdef __GNUC__
+#pragma interface /* gcc class implementation */
+#endif
+
+class st_select_lex;
+class JOIN;
+class select_subselect;
+
+/* base class for subselects */
+
+class Item_subselect :public Item
+{
+protected:
+ uint max_columns;
+ my_bool assigned; /* value already assigned to subselect */
+ my_bool executed; /* simple subselect is executed */
+ my_bool optimized; /* simple subselect is optimized */
+ my_bool error; /* error in query */
+
+ int exec();
+ virtual void assign_null()
+ {
+ null_value= 1;
+ }
+public:
+ st_select_lex *select_lex;
+ JOIN *join;
+ select_subselect *result;
+
+ Item_subselect(THD *thd, st_select_lex *select_lex,
+ select_subselect* result);
+ Item_subselect(Item_subselect *item)
+ {
+ null_value= item->null_value;
+ decimals= item->decimals;
+ max_columns= item->max_columns;
+ assigned= item->assigned;
+ executed= item->executed;
+ select_lex= item->select_lex;
+ join= item->join;
+ result= item->result;
+ name= item->name;
+ error= item->error;
+ }
+ enum Type type() const;
+ bool is_null() { return null_value; }
+ void make_field (Send_field *);
+ bool fix_fields(THD *thd, TABLE_LIST *tables, Item **ref);
+ table_map used_tables() const;
+
+ friend class select_subselect;
+};
+
+
+/* single value subselect */
+
+class Item_singleval_subselect :public Item_subselect
+{
+protected:
+ longlong int_value;
+ double real_value;
+ enum Item_result res_type;
+
+ virtual void assign_null()
+ {
+ null_value= 1;
+ int_value= 0;
+ real_value= 0;
+ max_length= 4;
+ res_type= STRING_RESULT;
+ }
+public:
+ Item_singleval_subselect(THD *thd, st_select_lex *select_lex);
+ Item_singleval_subselect(Item_singleval_subselect *item):
+ Item_subselect(item)
+ {
+ int_value= item->int_value;
+ real_value= item->real_value;
+ max_length= item->max_length;
+ decimals= item->decimals;
+ res_type= item->res_type;
+ }
+ double val ();
+ longlong val_int ();
+ String *val_str (String *);
+ Item *new_item() { return new Item_singleval_subselect(this); }
+ enum Item_result result_type() const { return res_type; }
+
+ friend class select_singleval_subselect;
+};
+
+/* exists subselect */
+
+class Item_exists_subselect :public Item_subselect
+{
+protected:
+ longlong value;
+
+ virtual void assign_null()
+ {
+ value= 0;
+ }
+public:
+ Item_exists_subselect(THD *thd, st_select_lex *select_lex);
+ Item_exists_subselect(Item_exists_subselect *item):
+ Item_subselect(item)
+ {
+ value= item->value;
+ }
+ Item *new_item() { return new Item_exists_subselect(this); }
+ enum Item_result result_type() const { return INT_RESULT;}
+ longlong val_int();
+ double val();
+ String *val_str(String*);
+
+ friend class select_exists_subselect;
+};
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index bdf48b3ac54..93ced79005f 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -60,8 +60,9 @@ void Item_sum::make_field(Send_field *tmp_field)
result_type() == REAL_RESULT ? FIELD_TYPE_DOUBLE :
FIELD_TYPE_VAR_STRING);
}
- tmp_field->table_name=(char*)"";
- tmp_field->col_name=name;
+ tmp_field->db_name=(char*)"";
+ tmp_field->org_table_name=tmp_field->table_name=(char*)"";
+ tmp_field->org_col_name=tmp_field->col_name=name;
}
void Item_sum::print(String *str)
@@ -111,7 +112,7 @@ Item_sum_int::val_str(String *str)
bool
-Item_sum_num::fix_fields(THD *thd,TABLE_LIST *tables)
+Item_sum_num::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
if (!thd->allow_sum_func)
{
@@ -123,7 +124,7 @@ Item_sum_num::fix_fields(THD *thd,TABLE_LIST *tables)
maybe_null=0;
for (uint i=0 ; i < arg_count ; i++)
{
- if (args[i]->fix_fields(thd,tables))
+ if (args[i]->fix_fields(thd, tables, args + i))
return 1;
if (decimals < args[i]->decimals)
decimals=args[i]->decimals;
@@ -139,7 +140,7 @@ Item_sum_num::fix_fields(THD *thd,TABLE_LIST *tables)
bool
-Item_sum_hybrid::fix_fields(THD *thd,TABLE_LIST *tables)
+Item_sum_hybrid::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
Item *item=args[0];
if (!thd->allow_sum_func)
@@ -148,7 +149,7 @@ Item_sum_hybrid::fix_fields(THD *thd,TABLE_LIST *tables)
return 1;
}
thd->allow_sum_func=0; // No included group funcs
- if (item->fix_fields(thd,tables))
+ if (item->fix_fields(thd, tables, args))
return 1;
hybrid_type=item->result_type();
if (hybrid_type == INT_RESULT)
@@ -513,7 +514,7 @@ void Item_sum_hybrid::reset_field()
if (hybrid_type == STRING_RESULT)
{
char buff[MAX_FIELD_WIDTH];
- String tmp(buff,sizeof(buff)),*res;
+ String tmp(buff,sizeof(buff),default_charset_info),*res;
res=args[0]->val_str(&tmp);
if (args[0]->null_value)
@@ -524,7 +525,7 @@ void Item_sum_hybrid::reset_field()
else
{
result_field->set_notnull();
- result_field->store(res->ptr(),res->length());
+ result_field->store(res->ptr(),res->length(),tmp.charset());
}
}
else if (hybrid_type == INT_RESULT)
@@ -694,7 +695,7 @@ Item_sum_hybrid::min_max_update_str_field(int offset)
if (result_field->is_null() ||
(cmp_sign * (binary ? stringcmp(res_str,&tmp_value) :
sortcmp(res_str,&tmp_value)) < 0))
- result_field->store(res_str->ptr(),res_str->length());
+ result_field->store(res_str->ptr(),res_str->length(),res_str->charset());
else
{ // Use old value
char *res=result_field->ptr;
@@ -864,7 +865,8 @@ static int simple_raw_key_cmp(void* arg, byte* key1, byte* key2)
static int simple_str_key_cmp(void* arg, byte* key1, byte* key2)
{
- return my_sortcmp((char*) key1, (char*) key2, *(uint*) arg);
+ /* BAR TODO: remove default_charset_info */
+ return my_sortcmp(default_charset_info,(char*) key1, (char*) key2, *(uint*) arg);
}
/*
@@ -928,9 +930,10 @@ Item_sum_count_distinct::~Item_sum_count_distinct()
}
-bool Item_sum_count_distinct::fix_fields(THD *thd,TABLE_LIST *tables)
+bool Item_sum_count_distinct::fix_fields(THD *thd, TABLE_LIST *tables,
+ Item **ref)
{
- if (Item_sum_num::fix_fields(thd,tables) ||
+ if (Item_sum_num::fix_fields(thd, tables, ref) ||
!(tmp_table_param= new TMP_TABLE_PARAM))
return 1;
return 0;
@@ -939,6 +942,7 @@ bool Item_sum_count_distinct::fix_fields(THD *thd,TABLE_LIST *tables)
bool Item_sum_count_distinct::setup(THD *thd)
{
List<Item> list;
+ SELECT_LEX *select_lex= current_lex->select;
/* Create a table with an unique key over all parameters */
for (uint i=0; i < arg_count ; i++)
{
@@ -960,9 +964,10 @@ bool Item_sum_count_distinct::setup(THD *thd)
free_tmp_table(thd, table);
tmp_table_param->cleanup();
}
- if (!(table=create_tmp_table(thd, tmp_table_param, list, (ORDER*) 0, 1,
- 0, 0,
- current_lex->select->options | thd->options)))
+ if (!(table= create_tmp_table(thd, tmp_table_param, list, (ORDER*) 0, 1,
+ 0, 0,
+ select_lex->options | thd->options,
+ select_lex->master_unit())))
return 1;
table->file->extra(HA_EXTRA_NO_ROWS); // Don't update rows
table->no_rows=1;
@@ -1106,7 +1111,7 @@ bool Item_sum_count_distinct::add()
if (tree_to_myisam())
return 1;
}
- else if (!tree_insert(&tree, table->record[0] + rec_offset, 0))
+ else if (!tree_insert(&tree, table->record[0] + rec_offset, 0, tree.custom_arg))
return 1;
}
else if ((error=table->file->write_row(table->record[0])))
diff --git a/sql/item_sum.h b/sql/item_sum.h
index 2cf92343ebb..3c86370c189 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -81,7 +81,7 @@ public:
Item_sum_num(Item *item_par) :Item_sum(item_par) {}
Item_sum_num(Item *a, Item* b) :Item_sum(a,b) {}
Item_sum_num(List<Item> &list) :Item_sum(list) {}
- bool fix_fields(THD *,struct st_table_list *);
+ bool fix_fields(THD *, TABLE_LIST *, Item **);
longlong val_int() { return (longlong) val(); } /* Real as default */
String *val_str(String*str);
void reset_field();
@@ -151,7 +151,7 @@ class Item_sum_count_distinct :public Item_sum_int
{
TABLE *table;
table_map used_table_cache;
- bool fix_fields(THD *thd,TABLE_LIST *tables);
+ bool fix_fields(THD *thd, TABLE_LIST *tables, Item **ref);
uint32 *field_lengths;
TMP_TABLE_PARAM *tmp_table_param;
TREE tree;
@@ -293,7 +293,7 @@ class Item_sum_hybrid :public Item_sum
Item_sum_hybrid(Item *item_par,int sign) :Item_sum(item_par),cmp_sign(sign),
used_table_cache(~(table_map) 0)
{}
- bool fix_fields(THD *,struct st_table_list *);
+ bool fix_fields(THD *, TABLE_LIST *, Item **);
table_map used_tables() const { return used_table_cache; }
bool const_item() const { return !used_table_cache; }
@@ -398,7 +398,7 @@ public:
{ quick_group=0;}
~Item_udf_sum() {}
const char *func_name() const { return udf.name(); }
- bool fix_fields(THD *thd,struct st_table_list *tables)
+ bool fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
return udf.fix_fields(thd,tables,this,this->arg_count,this->args);
}
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 1e222fddcfc..566097893a8 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -29,11 +29,31 @@
** Todo: Move month and days to language files
*/
-static String month_names[] = { "January", "February", "March", "April",
- "May", "June", "July", "August",
- "September", "October", "November", "December" };
-static String day_names[] = { "Monday", "Tuesday", "Wednesday",
- "Thursday", "Friday", "Saturday" ,"Sunday" };
+static String month_names[] =
+{
+ String("January", default_charset_info),
+ String("February", default_charset_info),
+ String("March", default_charset_info),
+ String("April", default_charset_info),
+ String("May", default_charset_info),
+ String("June", default_charset_info),
+ String("July", default_charset_info),
+ String("August", default_charset_info),
+ String("September", default_charset_info),
+ String("October", default_charset_info),
+ String("November", default_charset_info),
+ String("December", default_charset_info)
+};
+static String day_names[] =
+{
+ String("Monday", default_charset_info),
+ String("Tuesday", default_charset_info),
+ String("Wednesday", default_charset_info),
+ String("Thursday", default_charset_info),
+ String("Friday", default_charset_info),
+ String("Saturday", default_charset_info),
+ String("Sunday", default_charset_info)
+};
/*
** Get a array of positive numbers from a string object.
@@ -49,16 +69,16 @@ bool get_interval_info(const char *str,uint length,uint count,
{
const char *end=str+length;
uint i;
- while (str != end && !isdigit(*str))
+ while (str != end && !my_isdigit(system_charset_info,*str))
str++;
for (i=0 ; i < count ; i++)
{
long value;
- for (value=0; str != end && isdigit(*str) ; str++)
+ for (value=0; str != end && my_isdigit(system_charset_info,*str) ; str++)
value=value*10L + (long) (*str - '0');
values[i]= value;
- while (str != end && !isdigit(*str))
+ while (str != end && !my_isdigit(system_charset_info,*str))
str++;
if (str == end && i != count-1)
{
@@ -289,7 +309,7 @@ static bool get_interval_value(Item *args,interval_type int_type,
/* record negative intervalls in t->neg */
str=res->ptr();
const char *end=str+res->length();
- while (str != end && isspace(*str))
+ while (str != end && my_isspace(system_charset_info,*str))
str++;
if (str != end && *str == '-')
{
@@ -376,7 +396,7 @@ String *Item_date::val_str(String *str)
return (String*) 0;
if (!value) // zero daynr
{
- str->copy("0000-00-00");
+ str->copy("0000-00-00",10);
return str;
}
if (str->alloc(11))
@@ -390,7 +410,7 @@ String *Item_date::val_str(String *str)
}
-bool Item_date::save_in_field(Field *field)
+int Item_date::save_in_field(Field *field)
{
TIME ltime;
timestamp_type t_type=TIMESTAMP_FULL;
@@ -505,7 +525,7 @@ bool Item_func_now::get_date(TIME *res,
}
-bool Item_func_now::save_in_field(Field *to)
+int Item_func_now::save_in_field(Field *to)
{
to->set_notnull();
to->store_time(&ltime,TIMESTAMP_FULL);
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index 0fe487b7983..a45ea159014 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -231,7 +231,7 @@ public:
double val() { return (double) val_int(); }
const char *func_name() const { return "date"; }
void fix_length_and_dec() { decimals=0; max_length=10; }
- bool save_in_field(Field *to);
+ int save_in_field(Field *to);
void make_field(Send_field *tmp_field)
{
init_make_field(tmp_field,FIELD_TYPE_DATE);
@@ -275,7 +275,7 @@ public:
double val() { return (double) value; }
longlong val_int() { return value; }
String *val_str(String *str)
- { str_value.set(buff,buff_length); return &str_value; }
+ { str_value.set(buff,buff_length,default_charset_info); return &str_value; }
const char *func_name() const { return "curtime"; }
void fix_length_and_dec();
void make_field(Send_field *tmp_field)
@@ -316,9 +316,9 @@ public:
enum Item_result result_type () const { return STRING_RESULT; }
double val() { return (double) value; }
longlong val_int() { return value; }
- bool save_in_field(Field *to);
+ int save_in_field(Field *to);
String *val_str(String *str)
- { str_value.set(buff,buff_length); return &str_value; }
+ { str_value.set(buff,buff_length,default_charset_info); return &str_value; }
const char *func_name() const { return "now"; }
void fix_length_and_dec();
bool get_date(TIME *res,bool fuzzy_date);
diff --git a/sql/item_uniq.h b/sql/item_uniq.h
index cc087832f49..6ab01d55e2f 100644
--- a/sql/item_uniq.h
+++ b/sql/item_uniq.h
@@ -43,6 +43,5 @@ public:
bool add() { return 0; }
void reset_field() {}
void update_field(int offset) {}
- bool fix_fields(THD *thd,struct st_table_list *tlist) { return 0;}
- unsigned int size_of() { return sizeof(*this);}
+ bool fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref) { return 0;}
};
diff --git a/sql/key.cc b/sql/key.cc
index d103c07eb72..fa09a0a6d44 100644
--- a/sql/key.cc
+++ b/sql/key.cc
@@ -192,8 +192,9 @@ int key_cmp(TABLE *table,const byte *key,uint idx,uint key_length)
if (!(key_part->key_type & (FIELDFLAG_NUMBER+FIELDFLAG_BINARY+
FIELDFLAG_PACK)))
{
- if (my_sortcmp((char*) key,(char*) table->record[0]+key_part->offset,
- length))
+ /* BAR TODO: I'm not sure this should be system_charset_info */
+ if (my_sortcmp(system_charset_info,(char*) key,
+ (char*) table->record[0]+key_part->offset,length))
return 1;
}
else if (memcmp(key,table->record[0]+key_part->offset,length))
diff --git a/sql/lex.h b/sql/lex.h
index 0a1505581cd..83890e75c20 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+/* Copyright (C) 2000-2002 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -74,12 +74,14 @@ static SYMBOL symbols[] = {
{ "BOOL", SYM(BOOL_SYM),0,0},
{ "BOOLEAN", SYM(BOOLEAN_SYM),0,0},
{ "BOTH", SYM(BOTH),0,0},
+ { "BTREE", SYM(BTREE_SYM),0,0},
{ "BY", SYM(BY),0,0},
{ "CACHE", SYM(CACHE_SYM),0,0},
{ "CASCADE", SYM(CASCADE),0,0},
{ "CASE", SYM(CASE_SYM),0,0},
{ "CHAR", SYM(CHAR_SYM),0,0},
{ "CHARACTER", SYM(CHAR_SYM),0,0},
+ { "CHARSET", SYM(CHARSET),0,0},
{ "CHANGE", SYM(CHANGE),0,0},
{ "CHANGED", SYM(CHANGED),0,0},
{ "CHECK", SYM(CHECK_SYM),0,0},
@@ -87,6 +89,7 @@ static SYMBOL symbols[] = {
{ "CIPHER", SYM(CIPHER_SYM),0,0},
{ "CLIENT", SYM(CLIENT_SYM),0,0},
{ "CLOSE", SYM(CLOSE_SYM),0,0},
+ { "COLLATE", SYM(COLLATE_SYM),0,0},
{ "COLUMN", SYM(COLUMN_SYM),0,0},
{ "COLUMNS", SYM(COLUMNS),0,0},
{ "COMMENT", SYM(COMMENT_SYM),0,0},
@@ -128,6 +131,7 @@ static SYMBOL symbols[] = {
{ "DROP", SYM(DROP),0,0},
{ "DUMPFILE", SYM(DUMPFILE),0,0},
{ "DYNAMIC", SYM(DYNAMIC_SYM),0,0},
+ { "ERRORS", SYM(ERRORS),0,0},
{ "END", SYM(END),0,0},
{ "ELSE", SYM(ELSE),0,0},
{ "ESCAPE", SYM(ESCAPE_SYM),0,0},
@@ -159,12 +163,14 @@ static SYMBOL symbols[] = {
{ "FULL", SYM(FULL),0,0},
{ "FULLTEXT", SYM(FULLTEXT_SYM),0,0},
{ "FUNCTION", SYM(UDF_SYM),0,0},
+ { "GEOMETRY", SYM(GEOMETRY_SYM),0,0},
{ "GLOBAL", SYM(GLOBAL_SYM),0,0},
{ "GRANT", SYM(GRANT),0,0},
{ "GRANTS", SYM(GRANTS),0,0},
{ "GROUP", SYM(GROUP),0,0},
{ "HAVING", SYM(HAVING),0,0},
{ "HANDLER", SYM(HANDLER_SYM),0,0},
+ { "HASH", SYM(HASH_SYM),0,0},
{ "HEAP", SYM(HEAP_SYM),0,0},
{ "HIGH_PRIORITY", SYM(HIGH_PRIORITY),0,0},
{ "HOUR", SYM(HOUR_SYM),0,0},
@@ -302,22 +308,26 @@ static SYMBOL symbols[] = {
{ "ROLLUP", SYM(ROLLUP_SYM),0,0},
{ "ROW", SYM(ROW_SYM),0,0},
{ "ROWS", SYM(ROWS_SYM),0,0},
+ { "RTREE", SYM(RTREE_SYM),0,0},
{ "SECOND", SYM(SECOND_SYM),0,0},
{ "SELECT", SYM(SELECT_SYM),0,0},
{ "SERIALIZABLE", SYM(SERIALIZABLE_SYM),0,0},
{ "SESSION", SYM(SESSION_SYM),0,0},
{ "SET", SYM(SET),0,0},
{ "SIGNED", SYM(SIGNED_SYM),0,0},
+ { "SIMPLE", SYM(SIMPLE_SYM),0,0},
{ "SHARE", SYM(SHARE_SYM),0,0},
{ "SHOW", SYM(SHOW),0,0},
{ "SHUTDOWN", SYM(SHUTDOWN),0,0},
{ "SLAVE", SYM(SLAVE),0,0},
{ "SMALLINT", SYM(SMALLINT),0,0},
{ "SONAME", SYM(UDF_SONAME_SYM),0,0},
+ { "SPATIAL", SYM(SPATIAL_SYM),0,0},
{ "SQL_BIG_RESULT", SYM(SQL_BIG_RESULT),0,0},
{ "SQL_BUFFER_RESULT", SYM(SQL_BUFFER_RESULT),0,0},
{ "SQL_CACHE", SYM(SQL_CACHE_SYM), 0, 0},
{ "SQL_CALC_FOUND_ROWS", SYM(SQL_CALC_FOUND_ROWS),0,0},
+ { "SQL_ERROR_COUNT", SYM(SQL_ERROR_COUNT),0,0},
{ "SQL_NO_CACHE", SYM(SQL_NO_CACHE_SYM), 0, 0},
{ "SQL_SMALL_RESULT", SYM(SQL_SMALL_RESULT),0,0},
{ "SQL_THREAD", SYM(SQL_THREAD),0,0},
@@ -347,6 +357,7 @@ static SYMBOL symbols[] = {
{ "TRUNCATE", SYM(TRUNCATE_SYM),0,0},
{ "TO", SYM(TO_SYM),0,0},
{ "TYPE", SYM(TYPE_SYM),0,0},
+ { "TYPES", SYM(TYPES_SYM),0,0},
{ "UNCOMMITTED", SYM(UNCOMMITTED_SYM),0,0},
{ "UNION", SYM(UNION_SYM),0,0},
{ "UNIQUE", SYM(UNIQUE_SYM),0,0},
@@ -362,6 +373,7 @@ static SYMBOL symbols[] = {
{ "VARIABLES", SYM(VARIABLES),0,0},
{ "VARYING", SYM(VARYING),0,0},
{ "VARBINARY", SYM(VARBINARY),0,0},
+ { "WARNINGS", SYM(WARNINGS),0,0},
{ "WITH", SYM(WITH),0,0},
{ "WORK", SYM(WORK_SYM),0,0},
{ "WRITE", SYM(WRITE_SYM),0,0},
@@ -382,8 +394,10 @@ static SYMBOL sql_functions[] = {
{ "ADDDATE", SYM(DATE_ADD_INTERVAL),0,0},
{ "AES_ENCRYPT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_aes_encrypt)},
{ "AES_DECRYPT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_aes_decrypt)},
+ { "AREA", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_area)},
{ "ASCII", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ascii)},
{ "ASIN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_asin)},
+ { "ASTEXT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_as_text)},
{ "ATAN", SYM(ATAN),0,0},
{ "ATAN2", SYM(ATAN),0,0},
{ "BENCHMARK", SYM(BENCHMARK_SYM),0,0},
@@ -394,17 +408,21 @@ static SYMBOL sql_functions[] = {
{ "CAST", SYM(CAST_SYM),0,0},
{ "CEILING", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ceiling)},
{ "BIT_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_bit_length)},
+ { "CENTROID", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_centroid)},
{ "CHAR_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_char_length)},
{ "CHARACTER_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_char_length)},
{ "COALESCE", SYM(COALESCE),0,0},
{ "CONCAT", SYM(CONCAT),0,0},
{ "CONCAT_WS", SYM(CONCAT_WS),0,0},
{ "CONNECTION_ID", SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_connection_id)},
+ { "CONTAINS", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_contains)},
{ "CONV", SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_conv)},
{ "CONVERT", SYM(CONVERT_SYM),0,0},
{ "COUNT", SYM(COUNT_SYM),0,0},
{ "COS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cos)},
{ "COT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cot)},
+ { "CRC32", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_crc32)},
+ { "CROSSES", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_crosses)},
{ "CURDATE", SYM(CURDATE),0,0},
{ "CURTIME", SYM(CURTIME),0,0},
{ "DATE_ADD", SYM(DATE_ADD_INTERVAL),0,0},
@@ -418,9 +436,15 @@ static SYMBOL sql_functions[] = {
{ "DEGREES", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_degrees)},
{ "DES_ENCRYPT", SYM(DES_ENCRYPT_SYM),0,0},
{ "DES_DECRYPT", SYM(DES_DECRYPT_SYM),0,0},
+ { "DIMENSION", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_dimension)},
+ { "DISJOINT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_disjoint)},
{ "ELT", SYM(ELT_FUNC),0,0},
{ "ENCODE", SYM(ENCODE_SYM),0,0},
{ "ENCRYPT", SYM(ENCRYPT),0,0},
+ { "ENDPOINT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_endpoint)},
+ { "ENVELOPE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_envelope)},
+ { "EQUALS", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_equals)},
+ { "EXTERIORRING", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_exteriorring)},
{ "EXTRACT", SYM(EXTRACT_SYM),0,0},
{ "EXP", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_exp)},
{ "EXPORT_SET", SYM(EXPORT_SET),0,0},
@@ -432,6 +456,12 @@ static SYMBOL sql_functions[] = {
{ "FROM_DAYS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_from_days)},
{ "FROM_UNIXTIME", SYM(FROM_UNIXTIME),0,0},
{ "GET_LOCK", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_get_lock)},
+ { "GEOMETRYCOLLECTION",SYM(GEOMETRYCOLLECTION),0,0},
+ { "GEOMETRYN", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_geometryn)},
+ { "GEOMETRYTYPE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_geometry_type)},
+ { "GEOMCOLLFROMTEXT", SYM(GEOMCOLLFROMTEXT),0,0},
+ { "GEOMFROMTEXT", SYM(GEOMFROMTEXT),0,0},
+ { "GLENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_glength)},
{ "GREATEST", SYM(GREATEST_SYM),0,0},
{ "GROUP_UNIQUE_USERS", SYM(GROUP_UNIQUE_USERS),0,0},
{ "HEX", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_hex)},
@@ -439,13 +469,20 @@ static SYMBOL sql_functions[] = {
{ "INET_ATON", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_inet_aton)},
{ "INET_NTOA", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_inet_ntoa)},
{ "INSTR", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_instr)},
+ { "INTERIORRINGN", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_interiorringn)},
+ { "INTERSECTS", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_intersects)},
+ { "ISCLOSED", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_isclosed)},
+ { "ISEMPTY", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_isempty)},
{ "ISNULL", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_isnull)},
{ "IS_FREE_LOCK", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_is_free_lock)},
{ "LAST_INSERT_ID", SYM(LAST_INSERT_ID),0,0},
+ { "ISSIMPLE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_issimple)},
{ "LCASE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_lcase)},
{ "LEAST", SYM(LEAST_SYM),0,0},
{ "LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_length)},
{ "LN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ln)},
+ { "LINEFROMTEXT", SYM(LINEFROMTEXT),0,0},
+ { "LINESTRING", SYM(LINESTRING),0,0},
{ "LOAD_FILE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_load_file)},
{ "LOCATE", SYM(LOCATE),0,0},
{ "LOG", SYM(LOG_SYM),0,0},
@@ -462,15 +499,30 @@ static SYMBOL sql_functions[] = {
{ "MID", SYM(SUBSTRING),0,0}, /* unireg function */
{ "MIN", SYM(MIN_SYM),0,0},
{ "MOD", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_mod)},
+ { "MLINEFROMTEXT", SYM(MLINEFROMTEXT),0,0},
+ { "MPOINTFROMTEXT", SYM(MPOINTFROMTEXT),0,0},
+ { "MPOLYFROMTEXT", SYM(MPOLYFROMTEXT),0,0},
+ { "MULTILINESTRING", SYM(MULTILINESTRING),0,0},
+ { "MULTIPOINT", SYM(MULTIPOINT),0,0},
+ { "MULTIPOLYGON", SYM(MULTIPOLYGON),0,0},
{ "MONTHNAME", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_monthname)},
{ "NOW", SYM(NOW_SYM),0,0},
{ "NULLIF", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_nullif)},
+ { "NUMGEOMETRIES", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_numgeometries)},
+ { "NUMINTERIORRING", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_numinteriorring)},
+ { "NUMPOINTS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_numpoints)},
{ "OCTET_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_length)},
{ "OCT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_oct)},
{ "ORD", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ord)},
+ { "OVERLAPS", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_overlaps)},
{ "PERIOD_ADD", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_period_add)},
{ "PERIOD_DIFF", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_period_diff)},
{ "PI", SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_pi)},
+ { "POINT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_point)},
+ { "POINTFROMTEXT", SYM(POINTFROMTEXT),0,0},
+ { "POINTN", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_pointn)},
+ { "POLYFROMTEXT", SYM(POLYFROMTEXT),0,0},
+ { "POLYGON", SYM(POLYGON),0,0},
{ "POSITION", SYM(POSITION_SYM),0,0},
{ "POW", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_pow)},
{ "POWER", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_pow)},
@@ -494,6 +546,7 @@ static SYMBOL sql_functions[] = {
{ "SOUNDEX", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_soundex)},
{ "SPACE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_space)},
{ "SQRT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sqrt)},
+ { "STARTPOINT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_startpoint)},
{ "STD", SYM(STD_SYM),0,0},
{ "STDDEV", SYM(STD_SYM),0,0},
{ "STRCMP", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_strcmp)},
@@ -506,6 +559,7 @@ static SYMBOL sql_functions[] = {
{ "TIME_FORMAT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_time_format)},
{ "TIME_TO_SEC", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_time_to_sec)},
{ "TO_DAYS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_to_days)},
+ { "TOUCHES", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_touches)},
{ "TRIM", SYM(TRIM),0,0},
{ "UCASE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ucase)},
{ "UNIQUE_USERS", SYM(UNIQUE_USERS),0,0},
@@ -515,5 +569,8 @@ static SYMBOL sql_functions[] = {
{ "VERSION", SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_version)},
{ "WEEK", SYM(WEEK_SYM),0,0},
{ "WEEKDAY", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_weekday)},
+ { "WITHIN", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_within)},
+ { "X", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_x)},
+ { "Y", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_y)},
{ "YEARWEEK", SYM(YEARWEEK),0,0}
};
diff --git a/sql/log.cc b/sql/log.cc
index 9194d3f7c07..b3ce1226210 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -1455,7 +1455,7 @@ static bool test_if_number(register const char *str,
while (*str++ == ' ') ;
if (*--str == '-' || *str == '+')
str++;
- while (isdigit(*str) || (allow_wildcards &&
+ while (my_isdigit(system_charset_info,*str) || (allow_wildcards &&
(*str == wild_many || *str == wild_one)))
{
flag=1;
@@ -1464,7 +1464,7 @@ static bool test_if_number(register const char *str,
if (*str == '.')
{
for (str++ ;
- isdigit(*str) ||
+ my_isdigit(system_charset_info,*str) ||
(allow_wildcards && (*str == wild_many || *str == wild_one)) ;
str++, flag=1) ;
}
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 1f7a4013d80..23622bc0141 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -220,13 +220,13 @@ void Log_event::pack_info(String* packet)
void Query_log_event::pack_info(String* packet)
{
char buf[256];
- String tmp(buf, sizeof(buf));
+ String tmp(buf, sizeof(buf), system_charset_info);
tmp.length(0);
if (db && db_len)
{
- tmp.append("use ");
+ tmp.append("use `", 5);
tmp.append(db, db_len);
- tmp.append("; ", 2);
+ tmp.append("`; ", 3);
}
if (query && q_len)
@@ -237,7 +237,7 @@ void Query_log_event::pack_info(String* packet)
void Start_log_event::pack_info(String* packet)
{
char buf1[256];
- String tmp(buf1, sizeof(buf1));
+ String tmp(buf1, sizeof(buf1), system_charset_info);
tmp.length(0);
char buf[22];
@@ -251,7 +251,7 @@ void Start_log_event::pack_info(String* packet)
void Load_log_event::pack_info(String* packet)
{
char buf[256];
- String tmp(buf, sizeof(buf));
+ String tmp(buf, sizeof(buf), system_charset_info);
tmp.length(0);
if (db && db_len)
{
@@ -327,7 +327,7 @@ void Load_log_event::pack_info(String* packet)
void Rotate_log_event::pack_info(String* packet)
{
char buf1[256], buf[22];
- String tmp(buf1, sizeof(buf1));
+ String tmp(buf1, sizeof(buf1), system_charset_info);
tmp.length(0);
tmp.append(new_log_ident, ident_len);
tmp.append(";pos=");
@@ -340,7 +340,7 @@ void Rotate_log_event::pack_info(String* packet)
void Intvar_log_event::pack_info(String* packet)
{
char buf1[256], buf[22];
- String tmp(buf1, sizeof(buf1));
+ String tmp(buf1, sizeof(buf1), system_charset_info);
tmp.length(0);
tmp.append(get_var_type_name());
tmp.append('=');
@@ -351,7 +351,7 @@ void Intvar_log_event::pack_info(String* packet)
void Slave_log_event::pack_info(String* packet)
{
char buf1[256], buf[22], *end;
- String tmp(buf1, sizeof(buf1));
+ String tmp(buf1, sizeof(buf1), system_charset_info);
tmp.length(0);
tmp.append("host=");
tmp.append(master_host);
@@ -1456,7 +1456,7 @@ void Create_file_log_event::print(FILE* file, bool short_form,
void Create_file_log_event::pack_info(String* packet)
{
char buf1[256],buf[22], *end;
- String tmp(buf1, sizeof(buf1));
+ String tmp(buf1, sizeof(buf1), system_charset_info);
tmp.length(0);
tmp.append("db=");
tmp.append(db, db_len);
@@ -1480,6 +1480,7 @@ Append_block_log_event::Append_block_log_event(THD* thd_arg, char* block_arg,
{
}
#endif
+
Append_block_log_event::Append_block_log_event(const char* buf, int len)
:Log_event(buf, 0),block(0)
@@ -1520,11 +1521,12 @@ void Append_block_log_event::pack_info(String* packet)
net_store_data(packet, buf1);
}
+
Delete_file_log_event::Delete_file_log_event(THD* thd_arg)
:Log_event(thd_arg),file_id(thd_arg->file_id)
{
}
-#endif
+#endif
Delete_file_log_event::Delete_file_log_event(const char* buf, int len)
@@ -1553,7 +1555,7 @@ void Delete_file_log_event::print(FILE* file, bool short_form,
fputc('\n', file);
fprintf(file, "#Delete_file: file_id=%u\n", file_id);
}
-#endif
+#endif
#ifndef MYSQL_CLIENT
void Delete_file_log_event::pack_info(String* packet)
@@ -1572,6 +1574,7 @@ Execute_load_log_event::Execute_load_log_event(THD* thd_arg)
}
#endif
+
Execute_load_log_event::Execute_load_log_event(const char* buf,int len)
:Log_event(buf, 0),file_id(0)
{
@@ -1580,6 +1583,7 @@ Execute_load_log_event::Execute_load_log_event(const char* buf,int len)
file_id = uint4korr(buf + LOG_EVENT_HEADER_LEN + EL_FILE_ID_OFFSET);
}
+
int Execute_load_log_event::write_data(IO_CACHE* file)
{
byte buf[EXEC_LOAD_HEADER_LEN];
@@ -1729,12 +1733,16 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli)
handle_dup = DUP_REPLACE;
sql_exchange ex((char*)fname, sql_ex.opt_flags &&
DUMPFILE_FLAG );
- String field_term(sql_ex.field_term,sql_ex.field_term_len);
- String enclosed(sql_ex.enclosed,sql_ex.enclosed_len);
- String line_term(sql_ex.line_term,sql_ex.line_term_len);
- String line_start(sql_ex.line_start,sql_ex.line_start_len);
- String escaped(sql_ex.escaped,sql_ex.escaped_len);
-
+ String field_term(sql_ex.field_term,sql_ex.field_term_len,
+ system_charset_info);
+ String enclosed(sql_ex.enclosed,sql_ex.enclosed_len,
+ system_charset_info);
+ String line_term(sql_ex.line_term,sql_ex.line_term_len,
+ system_charset_info);
+ String line_start(sql_ex.line_start,sql_ex.line_start_len,
+ system_charset_info);
+ String escaped(sql_ex.escaped,sql_ex.escaped_len, system_charset_info);
+
ex.opt_enclosed = (sql_ex.opt_flags & OPT_ENCLOSED_FLAG);
if (sql_ex.empty_flags & FIELD_TERM_EMPTY)
ex.field_term->length(0);
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 7e3a5aa98d3..61973c5af91 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -291,7 +291,10 @@ inline THD *_current_thd(void)
#define query_cache_invalidate_by_MyISAM_filename_ref NULL
#endif /*HAVE_QUERY_CACHE*/
-int mysql_create_db(THD *thd, char *db, uint create_info, bool silent);
+#define prepare_execute(A) ((A)->command == COM_EXECUTE)
+
+int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
+int mysql_alter_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent);
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags);
int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists);
@@ -306,7 +309,7 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list);
bool mysql_change_db(THD *thd,const char *name);
void mysql_parse(THD *thd,char *inBuf,uint length);
void mysql_init_select(LEX *lex);
-bool mysql_new_select(LEX *lex);
+bool mysql_new_select(LEX *lex, bool move_down);
void mysql_init_multi_delete(LEX *lex);
void init_max_user_conn(void);
void free_max_user_conn(void);
@@ -371,12 +374,17 @@ bool net_store_data(String *packet, CONVERT *convert, const char *from);
SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length);
int setup_order(THD *thd,TABLE_LIST *tables, List<Item> &fields,
List <Item> &all_fields, ORDER *order);
+int setup_group(THD *thd,TABLE_LIST *tables,List<Item> &fields,
+ List<Item> &all_fields, ORDER *order,
+ bool *hidden_group_fields);
int handle_select(THD *thd, LEX *lex, select_result *result);
int mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &list,COND *conds,
ORDER *order, ORDER *group,Item *having,ORDER *proc_param,
- ulong select_type,select_result *result);
-int mysql_union(THD *thd,LEX *lex,select_result *result);
+ ulong select_type,select_result *result,
+ SELECT_LEX_UNIT *unit);
+int mysql_union(THD *thd, LEX *lex,select_result *result);
+int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *s, TABLE_LIST *t);
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
Item_result_field ***copy_func, Field **from_field,
bool group,bool modify_item);
@@ -458,7 +466,7 @@ bool load_des_key_file(const char *file_name);
/* sql_do.cc */
int mysql_do(THD *thd, List<Item> &values);
-/* sql_list.c */
+/* sql_show.cc */
int mysqld_show_dbs(THD *thd,const char *wild);
int mysqld_show_open_tables(THD *thd,const char *wild);
int mysqld_show_tables(THD *thd,const char *db,const char *wild);
@@ -470,12 +478,33 @@ int mysqld_show_logs(THD *thd);
void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
int mysqld_dump_create_info(THD *thd, TABLE *table, int fd = -1);
int mysqld_show_create(THD *thd, TABLE_LIST *table_list);
+int mysqld_show_create_db(THD *thd, const char *dbname);
void mysqld_list_processes(THD *thd,const char *user,bool verbose);
int mysqld_show_status(THD *thd);
int mysqld_show_variables(THD *thd,const char *wild);
int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
enum enum_var_type value_type);
+int mysqld_show_charsets(THD *thd,const char *wild);
+int mysqld_show_table_types(THD *thd);
+int mysqld_show_privileges(THD *thd);
+int mysqld_show_column_types(THD *thd);
+
+/* sql_prepare.cc */
+void mysql_com_prepare(THD *thd,char*packet,uint packet_length);
+void mysql_init_query(THD *thd);/* sql_parse. cc */
+void mysql_com_execute(THD *thd);
+void mysql_com_longdata(THD *thd);
+int check_insert_fields(THD *thd,TABLE *table,List<Item> &fields,
+ List<Item> &values, ulong counter);
+
+/* sql_error.cc */
+void push_error(uint code, const char *msg);
+void push_warning(uint code, const char *msg);
+int mysqld_show_warnings(THD *thd);
+int mysqld_show_errors(THD *thd);
+int mysqld_show_warnings_count(THD *thd);
+int mysqld_show_errors_count(THD *);
/* sql_handler.cc */
int mysql_ha_open(THD *thd, TABLE_LIST *tables);
@@ -487,8 +516,9 @@ int mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *,
void set_item_name(Item *item,char *pos,uint length);
bool add_field_to_list(char *field_name, enum enum_field_types type,
char *length, char *decimal,
- uint type_modifier, Item *default_value,char *change,
- TYPELIB *interval);
+ uint type_modifier,
+ Item *default_value, Item *comment,
+ char *change, TYPELIB *interval,CHARSET_INFO *cs);
void store_position_for_column(const char *name);
bool add_to_list(SQL_LIST &list,Item *group,bool asc=0);
TABLE_LIST *add_table_to_list(Table_ident *table,LEX_STRING *alias,
@@ -592,7 +622,7 @@ bool open_log(MYSQL_LOG *log, const char *hostname,
extern time_t start_time;
extern char *mysql_data_home,server_version[SERVER_VERSION_LENGTH],
- max_sort_char, mysql_real_data_home[], *charsets_list;
+ mysql_real_data_home[], *charsets_list;
extern my_string mysql_tmpdir;
extern const char *command_name[];
extern const char *first_keyword, *localhost, *delayed_user;
@@ -666,6 +696,10 @@ extern MY_BITMAP temp_pool;
extern DATE_FORMAT dayord;
extern String empty_string;
extern SHOW_VAR init_vars[],status_vars[], internal_vars[];
+extern struct show_table_type_st table_type_vars[];
+extern SHOW_COMP_OPTION have_isam;
+extern SHOW_COMP_OPTION have_innodb;
+extern SHOW_COMP_OPTION have_berkeley_db;
extern struct system_variables global_system_variables;
extern struct system_variables max_system_variables;
@@ -752,7 +786,7 @@ ulong get_form_pos(File file, uchar *head, TYPELIB *save_names);
ulong make_new_entry(File file,uchar *fileinfo,TYPELIB *formnames,
const char *newname);
ulong next_io_size(ulong pos);
-void append_unescaped(String *res,const char *pos);
+void append_unescaped(String *res, const char *pos, uint length);
int create_frm(char *name,uint reclength,uchar *fileinfo,
HA_CREATE_INFO *create_info, uint keys);
void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
@@ -761,11 +795,11 @@ bool check_db_name(const char *db);
bool check_column_name(const char *name);
bool check_table_name(const char *name, uint length);
char *get_field(MEM_ROOT *mem,TABLE *table,uint fieldnr);
-int wild_case_compare(const char *str,const char *wildstr);
+int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr);
int wild_compare(const char *str,const char *str_end,
const char *wildstr,const char *wildend,char escape);
-int wild_case_compare(const char *str,const char *str_end,
- const char *wildstr,const char *wildend,char escape);
+int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *str_end,
+ const char *wildstr,const char *wildend,char escape);
/* from hostname.cc */
struct in_addr;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 4ecded767d1..89f1c07b2fe 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -939,7 +939,7 @@ static void set_user(const char *user)
{
// allow a numeric uid to be used
const char *pos;
- for (pos=user; isdigit(*pos); pos++) ;
+ for (pos=user; my_isdigit(system_charset_info,*pos); pos++) ;
if (*pos) // Not numeric id
{
fprintf(stderr,"Fatal error: Can't change to run as user '%s' ; Please check that the user exists!\n",user);
@@ -1881,7 +1881,7 @@ int main(int argc, char **argv)
if (set_default_charset_by_name(sys_charset.value, MYF(MY_WME)))
exit(1);
- charsets_list = list_charsets(MYF(MY_COMPILED_SETS|MY_CONFIG_SETS));
+ charsets_list= list_charsets(MYF(MY_CS_COMPILED | MY_CS_CONFIG));
#ifdef HAVE_OPENSSL
if (opt_ssl_key || opt_ssl_cert || opt_ssl_ca || opt_ssl_capath ||
@@ -4036,7 +4036,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
exit(1);
}
val= p--;
- while (isspace(*p) && p > argument)
+ while (my_isspace(system_charset_info, *p) && p > argument)
*p-- = 0;
if (p == argument)
{
@@ -4046,7 +4046,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
}
*val= 0;
val+= 2;
- while (*val && isspace(*val))
+ while (*val && my_isspace(system_charset_info, *val))
*val++;
if (!*val)
{
@@ -4189,7 +4189,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
have_symlink=SHOW_OPTION_DISABLED;
break;
case (int) OPT_BIND_ADDRESS:
- if (argument && isdigit(argument[0]))
+ if (argument && my_isdigit(system_charset_info, argument[0]))
{
my_bind_addr = (ulong) inet_addr(argument);
}
@@ -4597,7 +4597,8 @@ static ulong find_bit_type(const char *x, TYPELIB *bit_lib)
j=pos;
while (j != end)
{
- if (toupper(*i++) != toupper(*j++))
+ if (my_toupper(system_charset_info,*i++) !=
+ my_toupper(system_charset_info,*j++))
goto skipp;
}
found_int=bit;
diff --git a/sql/net_pkg.cc b/sql/net_pkg.cc
index 55c9bd3cfab..1e7536e3007 100644
--- a/sql/net_pkg.cc
+++ b/sql/net_pkg.cc
@@ -48,6 +48,7 @@ void send_error(NET *net, uint sql_errno, const char *err)
}
}
}
+ push_error(sql_errno, err);
if (net->vio == 0)
{
if (thd && thd->bootstrap)
@@ -82,7 +83,14 @@ void send_error(NET *net, uint sql_errno, const char *err)
void send_warning(NET *net, uint sql_errno, const char *err)
{
- DBUG_ENTER("send_warning");
+ DBUG_ENTER("send_warning");
+ push_warning(sql_errno, err ? err : ER(sql_errno));
+
+ /*
+ TODO :
+ Try to return ok with warning status to client, instead
+ of returning error ..
+ */
send_error(net,sql_errno,err);
DBUG_VOID_RETURN;
}
@@ -124,6 +132,7 @@ net_printf(NET *net, uint errcode, ...)
length=sizeof(net->last_error)-1; /* purecov: inspected */
va_end(args);
+ push_error(errcode, text_pos);
if (net->vio == 0)
{
if (thd && thd->bootstrap)
@@ -335,7 +344,7 @@ net_store_data(String *packet,struct tm *tmp)
bool net_store_data(String* packet, I_List<i_string>* str_list)
{
char buf[256];
- String tmp(buf, sizeof(buf));
+ String tmp(buf, sizeof(buf), default_charset_info);
tmp.length(0);
I_List_iterator<i_string> it(*str_list);
i_string* s;
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 4d8290628a7..b0636869d68 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -174,8 +174,9 @@ public:
void store(uint length,char **min_key,uint min_key_flag,
char **max_key, uint max_key_flag)
{
- if (!(min_flag & NO_MIN_RANGE) &&
- !(min_key_flag & (NO_MIN_RANGE | NEAR_MIN)))
+ if ((min_flag & GEOM_FLAG) ||
+ (!(min_flag & NO_MIN_RANGE) &&
+ !(min_key_flag & (NO_MIN_RANGE | NEAR_MIN))))
{
if (maybe_null && *min_value)
{
@@ -661,6 +662,8 @@ int SQL_SELECT::test_quick_select(key_map keys_to_use, table_map prev_tables,
key_parts->null_bit= key_info->key_part[part].null_bit;
if (key_parts->field->type() == FIELD_TYPE_BLOB)
key_parts->part_length+=HA_KEY_BLOB_LENGTH;
+ key_parts->image_type =
+ (key_info->flags & HA_SPATIAL) ? Field::itMBR : Field::itRAW;
}
param.real_keynr[param.keys++]=idx;
}
@@ -678,6 +681,7 @@ int SQL_SELECT::test_quick_select(key_map keys_to_use, table_map prev_tables,
{
SEL_ARG **key,**end,**best_key=0;
+
for (idx=0,key=tree->keys, end=key+param.keys ;
key != end ;
key++,idx++)
@@ -928,7 +932,7 @@ get_mm_leaf(PARAM *param, Field *field, KEY_PART *key_part,
{
bool like_error;
char buff1[MAX_FIELD_WIDTH],*min_str,*max_str;
- String tmp(buff1,sizeof(buff1)),*res;
+ String tmp(buff1,sizeof(buff1),default_charset_info),*res;
uint length,offset,min_length,max_length;
if (!field->optimize_range((uint) key_part->key))
@@ -972,9 +976,10 @@ get_mm_leaf(PARAM *param, Field *field, KEY_PART *key_part,
&min_length,&max_length);
else
{
+ CHARSET_INFO *charset=((Field_str*)(field))->charset();
#ifdef USE_STRCOLL
- if (use_strcoll(default_charset_info))
- like_error= my_like_range(default_charset_info,
+ if (use_strcoll(charset))
+ like_error= my_like_range(charset,
res->ptr(),res->length(),wild_prefix,
field_length, min_str+maybe_null,
max_str+maybe_null,&min_length,&max_length);
@@ -983,7 +988,8 @@ get_mm_leaf(PARAM *param, Field *field, KEY_PART *key_part,
like_error=like_range(res->ptr(),res->length(),wild_prefix,
field_length,
min_str+offset,max_str+offset,
- max_sort_char,&min_length,&max_length);
+ charset->max_sort_char,
+ &min_length,&max_length);
}
if (like_error) // Can't optimize with LIKE
DBUG_RETURN(0);
@@ -1024,7 +1030,7 @@ get_mm_leaf(PARAM *param, Field *field, KEY_PART *key_part,
field->cmp_type() != value->result_type())
DBUG_RETURN(0);
- if (value->save_in_field(field))
+ if (value->save_in_field(field) == 1)
{
// TODO; Check if we can we remove the following block.
if (type == Item_func::EQUAL_FUNC)
@@ -1046,7 +1052,7 @@ get_mm_leaf(PARAM *param, Field *field, KEY_PART *key_part,
DBUG_RETURN(0);
if (maybe_null)
*str=0; // Not NULL
- field->get_key_image(str+maybe_null,key_part->part_length);
+ field->get_key_image(str+maybe_null,key_part->part_length, key_part->image_type);
if (!(tree=new SEL_ARG(field,str,str)))
DBUG_RETURN(0);
@@ -1071,6 +1077,41 @@ get_mm_leaf(PARAM *param, Field *field, KEY_PART *key_part,
case Item_func::GE_FUNC:
tree->max_flag=NO_MAX_RANGE;
break;
+ case Item_func::SP_EQUALS_FUNC:
+ tree->min_flag=GEOM_FLAG | HA_READ_MBR_EQUAL;// NEAR_MIN;//512;
+ tree->max_flag=NO_MAX_RANGE;
+ break;
+ case Item_func::SP_DISJOINT_FUNC:
+ tree->min_flag=GEOM_FLAG | HA_READ_MBR_DISJOINT;// NEAR_MIN;//512;
+ tree->max_flag=NO_MAX_RANGE;
+ break;
+ case Item_func::SP_INTERSECTS_FUNC:
+ tree->min_flag=GEOM_FLAG | HA_READ_MBR_INTERSECT;// NEAR_MIN;//512;
+ tree->max_flag=NO_MAX_RANGE;
+ break;
+ case Item_func::SP_TOUCHES_FUNC:
+ tree->min_flag=GEOM_FLAG | HA_READ_MBR_INTERSECT;// NEAR_MIN;//512;
+ tree->max_flag=NO_MAX_RANGE;
+ break;
+
+ case Item_func::SP_CROSSES_FUNC:
+ tree->min_flag=GEOM_FLAG | HA_READ_MBR_INTERSECT;// NEAR_MIN;//512;
+ tree->max_flag=NO_MAX_RANGE;
+ break;
+ case Item_func::SP_WITHIN_FUNC:
+ tree->min_flag=GEOM_FLAG | HA_READ_MBR_WITHIN;// NEAR_MIN;//512;
+ tree->max_flag=NO_MAX_RANGE;
+ break;
+
+ case Item_func::SP_CONTAINS_FUNC:
+ tree->min_flag=GEOM_FLAG | HA_READ_MBR_CONTAIN;// NEAR_MIN;//512;
+ tree->max_flag=NO_MAX_RANGE;
+ break;
+ case Item_func::SP_OVERLAPS_FUNC:
+ tree->min_flag=GEOM_FLAG | HA_READ_MBR_INTERSECT;// NEAR_MIN;//512;
+ tree->max_flag=NO_MAX_RANGE;
+ break;
+
default:
break;
}
@@ -2192,18 +2233,30 @@ check_quick_keys(PARAM *param,uint idx,SEL_ARG *key_tree,
!memcmp(param->min_key,param->max_key,min_key_length))
tmp=1; // Max one record
else
+ {
+ if(tmp_min_flag & GEOM_FLAG)
+ {
+ tmp=param->table->file->
+ records_in_range((int) keynr,(byte*)(param->min_key + 1),
+ min_key_length, (ha_rkey_function)(tmp_min_flag ^ GEOM_FLAG),
+ (byte *)NullS,0,HA_READ_KEY_EXACT);
+ }
+ else
+ {
tmp=param->table->file->
records_in_range((int) keynr,
(byte*) (!min_key_length ? NullS :
param->min_key),
min_key_length,
- (tmp_min_flag & NEAR_MIN ?
- HA_READ_AFTER_KEY : HA_READ_KEY_EXACT),
+ tmp_min_flag & NEAR_MIN ?
+ HA_READ_AFTER_KEY : HA_READ_KEY_EXACT,
(byte*) (!max_key_length ? NullS :
param->max_key),
max_key_length,
(tmp_max_flag & NEAR_MAX ?
HA_READ_BEFORE_KEY : HA_READ_AFTER_KEY));
+ }
+ }
end:
if (tmp == HA_POS_ERROR) // Impossible range
return tmp;
@@ -2299,19 +2352,24 @@ get_quick_keys(PARAM *param,QUICK_SELECT *quick,KEY_PART *key,
}
}
else
- flag=key_tree->min_flag | key_tree->max_flag;
+ {
+ flag = (key_tree->min_flag & GEOM_FLAG) ?
+ key_tree->min_flag : key_tree->min_flag | key_tree->max_flag;
+ }
/* Ensure that some part of min_key and max_key are used. If not,
regard this as no lower/upper range */
- if (tmp_min_key != param->min_key)
- flag&= ~NO_MIN_RANGE;
- else
- flag|= NO_MIN_RANGE;
- if (tmp_max_key != param->max_key)
- flag&= ~NO_MAX_RANGE;
- else
- flag|= NO_MAX_RANGE;
-
+ if((flag & GEOM_FLAG) == 0)
+ {
+ if (tmp_min_key != param->min_key)
+ flag&= ~NO_MIN_RANGE;
+ else
+ flag|= NO_MIN_RANGE;
+ if (tmp_max_key != param->max_key)
+ flag&= ~NO_MAX_RANGE;
+ else
+ flag|= NO_MAX_RANGE;
+ }
if (flag == 0)
{
uint length= (uint) (tmp_min_key - param->min_key);
@@ -2444,13 +2502,19 @@ int QUICK_SELECT::get_next()
int result;
if (range)
{ // Already read through key
- result=((range->flag & EQ_RANGE) ?
+/* result=((range->flag & EQ_RANGE) ?
file->index_next_same(record, (byte*) range->min_key,
range->min_length) :
file->index_next(record));
+*/
+ result=((range->flag & (EQ_RANGE | GEOM_FLAG) ) ?
+ file->index_next_same(record, (byte*) range->min_key,
+ range->min_length) :
+ file->index_next(record));
+
if (!result)
{
- if (!cmp_next(*it.ref()))
+ if ((range->flag & GEOM_FLAG) || !cmp_next(*it.ref()))
DBUG_RETURN(0);
}
else if (result != HA_ERR_END_OF_FILE)
@@ -2459,6 +2523,23 @@ int QUICK_SELECT::get_next()
if (!(range=it++))
DBUG_RETURN(HA_ERR_END_OF_FILE); // All ranges used
+
+ if(range->flag & GEOM_FLAG)
+ {
+ if ((result = file->index_read(record,
+ (byte*) (range->min_key + ((range->flag & GEOM_FLAG) > 0)),
+ range->min_length,
+ (ha_rkey_function)(range->flag ^ GEOM_FLAG))))
+
+ {
+ if (result != HA_ERR_KEY_NOT_FOUND)
+ DBUG_RETURN(result);
+ range=0; // Not found, to next range
+ continue;
+ }
+ DBUG_RETURN(0);
+ }
+
if (range->flag & NO_MIN_RANGE) // Read first record
{
int error;
@@ -2469,13 +2550,14 @@ int QUICK_SELECT::get_next()
range=0; // No matching records; go to next range
continue;
}
- if ((result = file->index_read(record,(byte*) range->min_key,
+ if ((result = file->index_read(record,
+ (byte*) (range->min_key + ((range->flag & GEOM_FLAG) > 0)),
range->min_length,
- ((range->flag & NEAR_MIN) ?
+ (range->flag & NEAR_MIN) ?
HA_READ_AFTER_KEY:
(range->flag & EQ_RANGE) ?
HA_READ_KEY_EXACT :
- HA_READ_KEY_OR_NEXT))))
+ HA_READ_KEY_OR_NEXT)))
{
if (result != HA_ERR_KEY_NOT_FOUND)
@@ -2758,7 +2840,7 @@ static void
print_key(KEY_PART *key_part,const char *key,uint used_length)
{
char buff[1024];
- String tmp(buff,sizeof(buff));
+ String tmp(buff,sizeof(buff),default_charset_info);
for (uint length=0;
length < used_length ;
diff --git a/sql/opt_range.h b/sql/opt_range.h
index af977eb3093..e96c3792f24 100644
--- a/sql/opt_range.h
+++ b/sql/opt_range.h
@@ -31,11 +31,14 @@
#define UNIQUE_RANGE 16
#define EQ_RANGE 32
#define NULL_RANGE 64
+#define GEOM_FLAG 128
+
typedef struct st_key_part {
- uint16 key,part,part_length;
- uint8 null_bit;
- Field *field;
+ uint16 key,part,part_length;
+ uint8 null_bit;
+ Field *field;
+ Field::imagetype image_type;
} KEY_PART;
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index 74e7b2ef3be..38365dbb546 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -351,7 +351,7 @@ static bool find_range_key(TABLE_REF *ref, Field* field, COND *cond)
// Save found constant
if (part->null_bit)
*key_ptr++= (byte) test(part->field->is_null());
- part->field->get_key_image((char*) key_ptr,part->length);
+ part->field->get_key_image((char*) key_ptr,part->length, Field::itRAW);
key_ptr+=part->store_length - test(part->null_bit);
left_length-=part->store_length;
}
diff --git a/sql/procedure.cc b/sql/procedure.cc
index 437bd82d6e5..7779f5ce085 100644
--- a/sql/procedure.cc
+++ b/sql/procedure.cc
@@ -57,7 +57,8 @@ setup_procedure(THD *thd,ORDER *param,select_result *result,
DBUG_RETURN(0);
for (i=0 ; i < array_elements(sql_procs) ; i++)
{
- if (!my_strcasecmp((*param->item)->name,sql_procs[i].name))
+ if (!my_strcasecmp(system_charset_info,
+ (*param->item)->name,sql_procs[i].name))
{
Procedure *proc=(*sql_procs[i].init)(thd,param,result,field_list);
*error= !proc;
diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc
index 0c537da474e..04f1ffce00e 100644
--- a/sql/repl_failsafe.cc
+++ b/sql/repl_failsafe.cc
@@ -204,7 +204,7 @@ static void slave_info_free(void *s)
void init_slave_list()
{
- hash_init(&slave_list, SLAVE_LIST_CHUNK, 0, 0,
+ hash_init(&slave_list, system_charset_info, SLAVE_LIST_CHUNK, 0, 0,
(hash_get_key) slave_list_key, slave_info_free, 0);
pthread_mutex_init(&LOCK_slave_list, MY_MUTEX_INIT_FAST);
}
diff --git a/sql/share/charsets/Index b/sql/share/charsets/Index
index 5cf30682cc0..c8ae877887e 100644
--- a/sql/share/charsets/Index
+++ b/sql/share/charsets/Index
@@ -36,3 +36,14 @@ gbk 28
cp1257 29
latin5 30
latin1_de 31
+armscii8 32
+utf8 33
+win1250ch 34
+ucs2 35
+cp866 36
+keybcs2 37
+macce 38
+macroman 39
+pclatin2 40
+latvian 41
+latvian1 42
diff --git a/sql/share/charsets/armscii8.conf b/sql/share/charsets/armscii8.conf
new file mode 100644
index 00000000000..54d2d0fec47
--- /dev/null
+++ b/sql/share/charsets/armscii8.conf
@@ -0,0 +1,93 @@
+# Configuration file for the armscii8 (armenian) character set
+
+# ctype array (must have 257 elements)
+ 00
+ 20 20 20 20 20 20 20 20 20 28 28 28 28 28 20 20
+ 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
+ 48 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
+ 84 84 84 84 84 84 84 84 84 84 10 10 10 10 10 10
+ 10 81 81 81 81 81 81 01 01 01 01 01 01 01 01 01
+ 01 01 01 01 01 01 01 01 01 01 01 10 10 10 10 10
+ 10 82 82 82 82 82 82 02 02 02 02 02 02 02 02 02
+ 02 02 02 02 02 02 02 02 02 02 02 10 10 10 10 20
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 48 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
+ 10 10 01 02 01 02 01 02 01 02 01 02 01 02 01 02
+ 01 02 01 02 01 02 01 02 01 02 01 02 01 02 01 02
+ 01 02 01 02 01 02 01 02 01 02 01 02 01 02 01 02
+ 01 02 01 02 01 02 01 02 01 02 01 02 01 02 01 02
+ 01 02 01 02 01 02 01 02 01 02 01 02 01 02 10 10
+
+# to_lower array (must have 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 5B 5C 5D 5E 5F
+ 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
+ 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
+ 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
+ A0 A1 A2 A3 A4 A5 A6 A7 B8 A9 AA AB AC AD AE AF
+ B0 B1 B3 B3 B5 B5 B7 B7 B9 B9 BB BB BD BD BF BF
+ C1 C1 C3 C3 C5 C5 C7 C7 C9 C9 CB CB CD CD CF CF
+ D1 D1 D3 D3 D5 D5 D7 D7 D9 D9 DB DB DD DD DF DF
+ E1 E1 E3 E3 E5 E5 E7 E7 E9 E9 EB EB ED ED EF EF
+ F1 F1 F3 F3 F5 F5 F7 F7 F9 F9 FB FB FD FD FE FF
+
+# to_upper array (must have 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
+ 60 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 7B 7C 7D 7E 7F
+ 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
+ 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
+ A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
+ B0 B1 B2 B2 B4 B4 B6 B6 B8 B8 BA BA BC BC BE BE
+ C0 C0 C2 C2 C4 C4 C6 C6 C8 C8 CA CA CC CC CE CE
+ D0 D0 D2 D2 D4 D4 D6 D6 D8 D8 DA DA DC DC DE DE
+ E0 E0 E2 E2 E4 E4 E6 E6 E8 E8 EA EA EC EC EE EE
+ F0 F0 F2 F2 F4 F4 F6 F6 F8 F8 FA FA FC FC FE FF
+
+# sort_order array (must have 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
+ 60 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 7B 7C 7D 7E 7F
+ 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
+ 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
+ A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
+ B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
+ C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
+ D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
+ E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
+ F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 2741 00A7 0589 0029 0028 00BB 00AB 2014 002E 055D 002C 002D 055F 2026 055C
+055B 055E 0531 0561 0532 0562 0533 0563 0534 0564 0535 0565 0536 0566 0537 0567
+0538 0568 0539 0569 053A 056A 053B 056B 053C 056C 053D 056D 053E 056E 053F 056F
+0540 0570 0541 0571 0542 0572 0543 0573 0544 0574 0545 0575 0546 0576 0547 0577
+0548 0578 0549 0579 054A 057A 054B 057B 054C 057C 054D 057D 054E 057E 054F 057F
+0550 0580 0551 0581 0552 0582 0553 0583 0554 0584 0555 0585 0556 0586 2019 0027
diff --git a/sql/share/charsets/cp1251.conf b/sql/share/charsets/cp1251.conf
index 6af97c891b8..653f7d26879 100644
--- a/sql/share/charsets/cp1251.conf
+++ b/sql/share/charsets/cp1251.conf
@@ -72,3 +72,22 @@
6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B
5B 5C 5D 5E 5F 60 62 63 64 65 66 67 68 69 6A 6B
6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B
+
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0402 0403 201A 0453 201E 2026 2020 2021 0000 2030 0409 2039 040A 040C 040B 040F
+0452 2018 2019 201C 201D 2022 2013 2014 0000 2122 0459 203A 045A 045C 045B 045F
+00A0 040E 045E 0408 00A4 0490 00A6 00A7 0401 00A9 0404 00AB 00AC 00AD 00AE 0407
+00B0 00B1 0406 0456 0491 00B5 00B6 00B7 0451 2116 0454 00BB 0458 0405 0455 0457
+0410 0411 0412 0413 0414 0415 0416 0417 0418 0419 041A 041B 041C 041D 041E 041F
+0420 0421 0422 0423 0424 0425 0426 0427 0428 0429 042A 042B 042C 042D 042E 042F
+0430 0431 0432 0433 0434 0435 0436 0437 0438 0439 043A 043B 043C 043D 043E 043F
+0440 0441 0442 0443 0444 0445 0446 0447 0448 0449 044A 044B 044C 044D 044E 044F
diff --git a/sql/share/charsets/cp1257.conf b/sql/share/charsets/cp1257.conf
index 610ed5a646f..8338f99c83b 100644
--- a/sql/share/charsets/cp1257.conf
+++ b/sql/share/charsets/cp1257.conf
@@ -72,3 +72,21 @@
5A FF FF FF FF FF FF FF 5E FF FF 5D FF FF FF FF
FF 4F FF FF FF FF 48 FF 45 FF FF 49 FF FF FF FF
5A FF FF FF FF FF FF FF 5E FF FF 5D FF FF FF FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+20AC 0000 201A 0000 201E 2026 2020 2021 0000 2030 0000 2039 0000 00A8 02C7 00B8
+0000 2018 2019 201C 201D 2022 2013 2014 0000 2122 0000 203A 0000 00AF 02DB 0000
+00A0 0000 00A2 00A3 00A4 0000 00A6 00A7 00D8 00A9 0156 00AB 00AC 00AD 00AE 00C6
+00B0 00B1 00B2 00B3 00B4 00B5 00B6 00B7 00F8 00B9 0157 00BB 00BC 00BD 00BE 00E6
+0104 012E 0100 0106 00C4 00C5 0118 0112 010C 00C9 0179 0116 0122 0136 012A 013B
+0160 0143 0145 00D3 014C 00D5 00D6 00D7 0172 0141 015A 016A 00DC 017B 017D 00DF
+0105 012F 0101 0107 00E4 00E5 0119 0113 010D 00E9 017A 0117 0123 0137 012B 013C
+0161 0144 0146 00F3 014D 00F5 00F6 00F7 0173 0142 015B 016B 00FC 017C 017E 02D9
diff --git a/sql/share/charsets/cp866.conf b/sql/share/charsets/cp866.conf
new file mode 100644
index 00000000000..e6b5c064fd7
--- /dev/null
+++ b/sql/share/charsets/cp866.conf
@@ -0,0 +1,91 @@
+# ctype array (must be 257 elements)
+ 00
+ 20 20 20 20 20 20 20 20 20 28 28 28 28 28 20 20
+ 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
+ 48 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
+ 84 84 84 84 84 84 84 84 84 84 10 10 10 10 10 10
+ 10 81 81 81 81 81 81 01 01 01 01 01 01 01 01 01
+ 01 01 01 01 01 01 01 01 01 01 01 10 10 10 10 10
+ 10 82 82 82 82 82 82 02 02 02 02 02 02 02 02 02
+ 02 02 02 02 02 02 02 02 02 02 02 10 10 10 10 00
+ 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
+ 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
+ 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
+ 01 02 01 02 01 02 01 02 00 00 00 00 00 00 00 48
+
+# to_lower array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 5B 5C 5D 5E 5F
+ 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
+ A0 A1 A2 A3 A4 A5 86 87 88 89 AA AB AC AD AE AF
+ E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
+ A0 A1 A2 A3 A4 A5 86 87 88 89 AA AB AC AD AE AF
+ B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
+ C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
+ D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
+ E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
+ F1 F1 F3 F3 F5 F5 F7 F7 F8 F9 FA FB FC FD FE FF
+
+# to_upper array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
+ 60 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 7B 7C 7D 7E 7F
+ 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
+ 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
+ 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
+ B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
+ C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
+ D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
+ 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
+ F0 F0 F2 F2 F4 F4 F6 F6 F8 F9 FA FB FC FD FE FF
+
+# sort_order array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 42 43 44 45 56 57 58 59 5A 5B 5C 5E 5F 62
+ 67 68 69 6C 71 74 75 76 77 78 7B B0 B1 B2 B3 B4
+ B5 41 42 43 44 45 56 57 58 59 5A 5B 5C 5E 5F 62
+ 67 68 69 6C 71 74 75 76 77 78 7B B6 B7 B8 B9 BA
+ 80 81 82 83 84 85 88 89 8A 8C 8D 8E 8F 90 91 92
+ 93 94 95 96 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3
+ 80 81 82 83 84 85 88 89 8A 8C 8D 8E 8F 90 91 92
+ BB BD BE C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC
+ CE CF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD
+ DE DF E0 E1 E2 E3 E4 E5 E6 E7 E8 F3 F4 F5 F6 F7
+ 93 94 95 96 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3
+ 86 86 87 87 8B 8B 97 97 F8 F9 FA FB FC FD FE FF
+
+# Unicode mappping (must be 256 elements)
+ 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+ 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+ 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+ 0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+ 0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+ 0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+ 0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+ 0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+ 0410 0411 0412 0413 0414 0415 0416 0417 0418 0419 041A 041B 041C 041D 041E 041F
+ 0420 0421 0422 0423 0424 0425 0426 0427 0428 0429 042A 042B 042C 042D 042E 042F
+ 0430 0431 0432 0433 0434 0435 0436 0437 0438 0439 043A 043B 043C 043D 043E 043F
+ 2591 2592 2593 2502 2524 2561 2562 2556 2555 2563 2551 2557 255D 255C 255B 2510
+ 2514 2534 252C 251C 2500 253C 255E 255F 255A 2554 2569 2566 2560 2550 256C 2567
+ 2568 2564 2565 2559 2558 2552 2553 256B 256A 2518 250C 2588 2584 258C 2590 2580
+ 0440 0441 0442 0443 0444 0445 0446 0447 0448 0449 044A 044B 044C 044D 044E 044F
+ 0401 0451 0404 0454 0407 0457 040E 045E 00B0 2219 00B7 221A 207F 00B2 25A0 00A0
+
diff --git a/sql/share/charsets/croat.conf b/sql/share/charsets/croat.conf
index fbbe3328547..bc8c1a376eb 100644
--- a/sql/share/charsets/croat.conf
+++ b/sql/share/charsets/croat.conf
@@ -72,3 +72,21 @@
47 4E 4F 4F 4F 4F 5D D7 D8 55 55 55 59 59 DE DF
41 41 41 41 5C 5B 45 43 44 45 45 45 49 49 49 49
47 4E 4F 4F 4F 4F 5D F7 D8 55 55 55 59 59 DE FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 0104 02D8 0141 00A4 013D 015A 00A7 00A8 0160 015E 0164 0179 00AD 017D 017B
+00B0 0105 02DB 0142 00B4 013E 015B 02C7 00B8 0161 015F 0165 017A 02DD 017E 017C
+0154 00C1 00C2 0102 00C4 0139 0106 00C7 010C 00C9 0118 00CB 011A 00CD 00CE 010E
+0110 0143 0147 00D3 00D4 0150 00D6 00D7 0158 016E 00DA 0170 00DC 00DD 0162 00DF
+0155 00E1 00E2 0103 00E4 013A 0107 00E7 010D 00E9 0119 00EB 011B 00ED 00EE 010F
+0111 0144 0148 00F3 00F4 0151 00F6 00F7 0159 016F 00FA 0171 00FC 00FD 0163 02D9
diff --git a/sql/share/charsets/danish.conf b/sql/share/charsets/danish.conf
index f99590ed6f3..1543a64d7c3 100644
--- a/sql/share/charsets/danish.conf
+++ b/sql/share/charsets/danish.conf
@@ -72,3 +72,21 @@
44 4E 4F 4F 4F 4F 5C D7 5C 55 55 55 59 59 DE DF
41 41 41 41 5B 5D 5B 43 45 45 45 45 49 49 49 49
44 4E 4F 4F 4F 4F 5C F7 5C 55 55 55 59 59 DE FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 00A1 00A2 00A3 00A4 00A5 00A6 00A7 00A8 00A9 00AA 00AB 00AC 00AD 00AE 00AF
+00B0 00B1 00B2 00B3 00B4 00B5 00B6 00B7 00B8 00B9 00BA 00BB 00BC 00BD 00BE 00BF
+00C0 00C1 00C2 00C3 00C4 00C5 00C6 00C7 00C8 00C9 00CA 00CB 00CC 00CD 00CE 00CF
+00D0 00D1 00D2 00D3 00D4 00D5 00D6 00D7 00D8 00D9 00DA 00DB 00DC 00DD 00DE 00DF
+00E0 00E1 00E2 00E3 00E4 00E5 00E6 00E7 00E8 00E9 00EA 00EB 00EC 00ED 00EE 00EF
+00F0 00F1 00F2 00F3 00F4 00F5 00F6 00F7 00F8 00F9 00FA 00FB 00FC 00FD 00FE 00FF
diff --git a/sql/share/charsets/dec8.conf b/sql/share/charsets/dec8.conf
index a4849aaa04c..d1ffe45032d 100644
--- a/sql/share/charsets/dec8.conf
+++ b/sql/share/charsets/dec8.conf
@@ -72,3 +72,21 @@
44 4E 4F 4F 4F 4F 5D D7 D8 55 55 55 59 59 DE DF
41 41 41 41 5C 5B 5C 43 45 45 45 45 49 49 49 49
44 4E 4F 4F 4F 4F 5D F7 D8 55 55 55 59 59 DE FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 00A1 00A2 00A3 0000 00A5 0000 00A7 00A4 00A9 00AA 00AB 0000 0000 0000 0000
+00B0 00B1 00B2 00B3 0000 00B5 00B6 00B7 0000 00B9 00BA 00BB 00BC 00BD 0000 00BF
+00C0 00C1 00C2 00C3 00C4 00C5 00C6 00C7 00C8 00C9 00CA 00CB 00CC 00CD 00CE 00CF
+0000 00D1 00D2 00D3 00D4 00D5 00D6 0152 00D8 00D9 00DA 00DB 00DC 0178 0000 00DF
+00E0 00E1 00E2 00E3 00E4 00E5 00E6 00E7 00E8 00E9 00EA 00EB 00EC 00ED 00EE 00EF
+0000 00F1 00F2 00F3 00F4 00F5 00F6 0153 00F8 00F9 00FA 00FB 00FC 00FF 0000 0000
diff --git a/sql/share/charsets/dos.conf b/sql/share/charsets/dos.conf
index dda86d0f3e8..205202711b8 100644
--- a/sql/share/charsets/dos.conf
+++ b/sql/share/charsets/dos.conf
@@ -1,4 +1,4 @@
-# Configuration file for the dos character set
+# Configuration file for the dos (aka cp437 DOSLatinUS) character set
# ctype array (must have 257 elements)
00
@@ -72,3 +72,22 @@
D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# Unicode mapping (256 elements)
+
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000a 000b 000c 000d 000e 000f
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001a 001b 001c 001d 001e 001f
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002a 002b 002c 002d 002e 002f
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003a 003b 003c 003d 003e 003f
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004a 004b 004c 004d 004e 004f
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005a 005b 005c 005d 005e 005f
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006a 006b 006c 006d 006e 006f
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007a 007b 007c 007d 007e 007f
+00c7 00fc 00e9 00e2 00e4 00e0 00e5 00e7 00ea 00eb 00e8 00ef 00ee 00ec 00c4 00c5
+00c9 00e6 00c6 00f4 00f6 00f2 00fb 00f9 00ff 00d6 00dc 00a2 00a3 00a5 20a7 0192
+00e1 00ed 00f3 00fa 00f1 00d1 00aa 00ba 00bf 2310 00ac 00bd 00bc 00a1 00ab 00bb
+2591 2592 2593 2502 2524 2561 2562 2556 2555 2563 2551 2557 255d 255c 255b 2510
+2514 2534 252c 251c 2500 253c 255e 255f 255a 2554 2569 2566 2560 2550 256c 2567
+2568 2564 2565 2559 2558 2552 2553 256b 256a 2518 250c 2588 2584 258c 2590 2580
+03b1 00df 0393 03c0 03a3 03c3 00b5 03c4 03a6 0398 03a9 03b4 221e 03c6 03b5 2229
+2261 00b1 2265 2264 2320 2321 00f7 2248 00b0 2219 00b7 221a 207f 00b2 25a0 00a0
diff --git a/sql/share/charsets/estonia.conf b/sql/share/charsets/estonia.conf
index 76bbc021b0c..0226fd1fe82 100644
--- a/sql/share/charsets/estonia.conf
+++ b/sql/share/charsets/estonia.conf
@@ -72,3 +72,21 @@
DB C2 C4 C8 CA F2 F6 64 EC BC D8 EA F8 E1 E3 DA
8D B1 89 95 F5 8B A3 A1 97 9D E0 9F A9 B7 AF BB
DC C3 C5 C9 CB F3 F7 65 ED BD D9 EB F9 E2 E4 53
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 201D 00A2 00A3 00A4 201E 00A6 00A7 00D8 00A9 0156 00AB 00AC 00AD 00AE 00C6
+00B0 00B1 00B2 00B3 201C 00B5 00B6 00B7 00F8 00B9 0157 00BB 00BC 00BD 00BE 00E6
+0104 012E 0100 0106 00C4 00C5 0118 0112 010C 00C9 0179 0116 0122 0136 012A 013B
+0160 0143 0145 00D3 014C 00D5 00D6 00D7 0172 0141 015A 016A 00DC 017B 017D 00DF
+0105 012F 0101 0107 00E4 00E5 0119 0113 010D 00E9 017A 0117 0123 0137 012B 013C
+0161 0144 0146 00F3 014D 00F5 00F6 00F7 0173 0142 015B 016B 00FC 017C 017E 2019
diff --git a/sql/share/charsets/german1.conf b/sql/share/charsets/german1.conf
index 3090c921ebe..64f27da3499 100644
--- a/sql/share/charsets/german1.conf
+++ b/sql/share/charsets/german1.conf
@@ -72,3 +72,21 @@
D0 4E 4F 4F 4F 4F 4F D7 4F 55 55 55 55 59 DE 53
41 41 41 41 41 41 41 43 45 45 45 45 49 49 49 49
D0 4E 4F 4F 4F 4F 4F F7 4F 55 55 55 55 59 DE FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 00A1 00A2 00A3 00A4 00A5 00A6 00A7 00A8 00A9 00AA 00AB 00AC 00AD 00AE 00AF
+00B0 00B1 00B2 00B3 00B4 00B5 00B6 00B7 00B8 00B9 00BA 00BB 00BC 00BD 00BE 00BF
+00C0 00C1 00C2 00C3 00C4 00C5 00C6 00C7 00C8 00C9 00CA 00CB 00CC 00CD 00CE 00CF
+00D0 00D1 00D2 00D3 00D4 00D5 00D6 00D7 00D8 00D9 00DA 00DB 00DC 00DD 00DE 00DF
+00E0 00E1 00E2 00E3 00E4 00E5 00E6 00E7 00E8 00E9 00EA 00EB 00EC 00ED 00EE 00EF
+00F0 00F1 00F2 00F3 00F4 00F5 00F6 00F7 00F8 00F9 00FA 00FB 00FC 00FD 00FE 00FF
diff --git a/sql/share/charsets/greek.conf b/sql/share/charsets/greek.conf
index 73d67d6ee71..5eb38e2efbe 100644
--- a/sql/share/charsets/greek.conf
+++ b/sql/share/charsets/greek.conf
@@ -72,3 +72,22 @@
D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 C9 D5 C1 C5 C7 C9
D5 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
D0 D1 D3 D3 D4 D5 D6 D7 D8 D9 C9 D5 CF D5 D9 FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 02BD 02BC 00A3 0000 0000 00A6 00A7 00A8 00A9 0000 00AB 00AC 00AD 0000 2015
+00B0 00B1 00B2 00B3 0384 0385 0386 00B7 0388 0389 038A 00BB 038C 00BD 038E 038F
+0390 0391 0392 0393 0394 0395 0396 0397 0398 0399 039A 039B 039C 039D 039E 039F
+03A0 03A1 0000 03A3 03A4 03A5 03A6 03A7 03A8 03A9 03AA 03AB 03AC 03AD 03AE 03AF
+03B0 03B1 03B2 03B3 03B4 03B5 03B6 03B7 03B8 03B9 03BA 03BB 03BC 03BD 03BE 03BF
+03C0 03C1 03C2 03C3 03C4 03C5 03C6 03C7 03C8 03C9 03CA 03CB 03CC 03CD 03CE 0000
+ \ No newline at end of file
diff --git a/sql/share/charsets/hebrew.conf b/sql/share/charsets/hebrew.conf
index 6a5f88eb228..84581f6f1bb 100644
--- a/sql/share/charsets/hebrew.conf
+++ b/sql/share/charsets/hebrew.conf
@@ -72,3 +72,22 @@
D0 D1 D2 D3 D4 D5 D6 F7 D8 D9 DA DB DC DD DE FF
E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 0000 00A2 00A3 00A4 00A5 00A6 00A7 00A8 00A9 00D7 00AB 00AC 00AD 00AE 203E
+00B0 00B1 00B2 00B3 00B4 00B5 00B6 00B7 00B8 00B9 00F7 00BB 00BC 00BD 00BE 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 2017
+05D0 05D1 05D2 05D3 05D4 05D5 05D6 05D7 05D8 05D9 05DA 05DB 05DC 05DD 05DE 05DF
+05E0 05E1 05E2 05E3 05E4 05E5 05E6 05E7 05E8 05E9 05EA 0000 0000 0000 0000 0000
+ \ No newline at end of file
diff --git a/sql/share/charsets/hp8.conf b/sql/share/charsets/hp8.conf
index e9fadacbf76..07036d6f186 100644
--- a/sql/share/charsets/hp8.conf
+++ b/sql/share/charsets/hp8.conf
@@ -72,3 +72,22 @@
D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 00C0 00C2 00C8 00CA 00CB 00CE 00CF 00B4 02CB 02C6 00A8 02DC 00D9 00DB 20A4
+00AF 00DD 00FD 00B0 00C7 00E7 00D1 00F1 00A1 00BF 00A4 00A3 00A5 00A7 0192 00A2
+00E2 00EA 00F4 00FB 00E1 00E9 00F3 00FA 00E0 00E8 00F2 00F9 00E4 00EB 00F6 00FC
+00C5 00EE 00D8 00C6 00E5 00ED 00F8 00E6 00C4 00EC 00D6 00DC 00C9 00EF 00DF 00D4
+00C1 00C3 00E3 00D0 00F0 00CD 00CC 00D3 00D2 00D5 00F5 0160 0161 00DA 0178 00FF
+00DE 00FE 00B7 00B5 00B6 00BE 2014 00BC 00BD 00AA 00BA 00AB 25A0 00BB 00B1 0000
+
diff --git a/sql/share/charsets/hungarian.conf b/sql/share/charsets/hungarian.conf
index db58d62575f..dffaff9348d 100644
--- a/sql/share/charsets/hungarian.conf
+++ b/sql/share/charsets/hungarian.conf
@@ -72,3 +72,21 @@
FF 62 63 64 66 67 67 FF 6D 77 75 78 78 7E 74 FF
64 41 44 45 46 5F 49 4B 4A 4E 51 78 50 56 58 4D
FF 62 63 64 66 67 67 FF 6D 77 75 78 78 7E 74 FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 0104 02D8 0141 00A4 013D 015A 00A7 00A8 0160 015E 0164 0179 00AD 017D 017B
+00B0 0105 02DB 0142 00B4 013E 015B 02C7 00B8 0161 015F 0165 017A 02DD 017E 017C
+0154 00C1 00C2 0102 00C4 0139 0106 00C7 010C 00C9 0118 00CB 011A 00CD 00CE 010E
+0110 0143 0147 00D3 00D4 0150 00D6 00D7 0158 016E 00DA 0170 00DC 00DD 0162 00DF
+0155 00E1 00E2 0103 00E4 013A 0107 00E7 010D 00E9 0119 00EB 011B 00ED 00EE 010F
+0111 0144 0148 00F3 00F4 0151 00F6 00F7 0159 016F 00FA 0171 00FC 00FD 0163 02D9
diff --git a/sql/share/charsets/keybcs2.conf b/sql/share/charsets/keybcs2.conf
new file mode 100644
index 00000000000..f272960b683
--- /dev/null
+++ b/sql/share/charsets/keybcs2.conf
@@ -0,0 +1,91 @@
+# ctype array (must be 257 elements)
+ 00
+ 20 20 20 20 20 20 20 20 20 28 28 28 28 28 20 20
+ 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
+ 48 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
+ 84 84 84 84 84 84 84 84 84 84 10 10 10 10 10 10
+ 10 81 81 81 81 81 81 01 01 01 01 01 01 01 01 01
+ 01 01 01 01 01 01 01 01 01 01 01 10 10 10 10 10
+ 10 82 82 82 82 82 82 02 02 02 02 02 02 02 02 02
+ 02 02 02 02 02 02 02 02 02 02 02 10 10 10 10 00
+ 01 02 82 02 02 01 01 02 82 81 01 01 02 02 01 01
+ 81 02 01 02 02 01 02 01 02 01 01 01 01 01 01 02
+ 02 02 02 02 02 01 01 01 02 02 02 01 00 00 00 00
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ 02 02 01 02 01 02 00 02 01 01 01 02 00 02 02 00
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 48
+
+# to_lower array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 5B 5C 5D 5E 5F
+ 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
+ 87 81 82 83 84 83 86 87 88 88 8D A1 8C 8D 84 A0
+ 82 91 91 93 94 A2 96 A3 98 94 81 9B 8C 98 A9 9F
+ A0 A1 A2 A3 A4 A4 96 93 9B A9 AA AA AC AD AE AF
+ B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
+ C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
+ D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
+ E0 E1 E2 E3 E4 E5 E6 E7 ED E9 EA EB EC ED EE EF
+ F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# to_upper array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
+ 60 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 68 59 5A 7B 7C 7D 7E 7F
+ 87 9A 90 85 8E 85 86 80 89 89 8A 8B 9C 8A 8E 8F
+ 90 92 92 A7 99 95 A6 97 9D 99 9A A8 9C 9D 9E 9F
+ 8F 8B 95 97 A5 A5 A6 A7 A8 9E AB AB AC AD AE AF
+ B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
+ C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
+ D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
+ E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC E8 EE EF
+ F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# sort_order array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 44 45 47 49 50 51 52 53 54 55 56 57 58 5A
+ 5E 5F 60 63 66 68 6C 6D 6E 6F 72 90 91 92 93 94
+ 95 41 44 45 47 49 50 51 52 53 54 55 56 57 58 5A
+ 5E 5F 60 63 66 68 6C 6D 6E 6F 72 96 97 98 99 9A
+ 45 68 49 47 41 47 66 45 49 49 56 53 56 56 41 41
+ 49 72 72 5A 5A 5A 68 68 6F 5A 68 63 56 6F 60 66
+ 41 53 5A 68 58 58 68 5A 63 60 60 60 A0 A1 A2 A3
+ A4 A5 A6 B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC
+ BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC
+ CD CE CF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC
+ 80 65 83 87 88 89 DD 8A 85 8B 84 81 DE 85 82 DF
+ F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# Unicode mappping (must be 256 elements)
+ 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+ 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+ 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+ 0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+ 0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+ 0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+ 0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+ 0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+ 010C 00FC 00E9 010F 00E4 010E 0164 010D 011B 011A 0139 00CD 013E 013A 00C4 00C1
+ 00C9 017E 017D 00F4 00F6 00D3 016F 00DA 00FD 00D6 00DC 0160 013D 00DD 0158 0165
+ 00E1 00ED 00F3 00FA 0148 0147 016E 00D4 0161 0159 0155 0154 00BC 00A1 00AB 00BB
+ 2591 2592 2593 2502 2524 2561 2562 2556 2555 2563 2551 2557 255D 255C 255B 2510
+ 2514 2534 252C 251C 2500 253C 255E 255F 255A 2554 2569 2566 2560 2550 256C 2567
+ 2568 2564 2565 2559 2558 2552 2553 256B 256A 2518 250C 2588 2584 258C 2590 2580
+ 03B1 00DF 0393 03C0 03A3 03C3 00B5 03C4 03A6 0398 03A9 03B4 221E 03C6 03B5 2229
+ 2261 00B1 2265 2264 2320 2321 00F7 2248 00B0 2219 00B7 221A 207F 00B2 25A0 00A0
+
diff --git a/sql/share/charsets/koi8_ru.conf b/sql/share/charsets/koi8_ru.conf
index 4cfee67a236..b1d9755173f 100644
--- a/sql/share/charsets/koi8_ru.conf
+++ b/sql/share/charsets/koi8_ru.conf
@@ -72,3 +72,22 @@
EF FF F0 F1 F2 F3 E6 E1 FC FB E7 F8 FD F9 F7 FA
FE DF E0 F6 E3 E4 F4 E2 F5 E8 E9 EA EB EC ED EE
EF FF F0 F1 F2 F3 E6 E1 FC FB E7 F8 FD F9 F7 FA
+
+# Unicode mapping table (256 elements)
+
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000a 000b 000c 000d 000e 000f
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001a 001b 001c 001d 001e 001f
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002a 002b 002c 002d 002e 002f
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003a 003b 003c 003d 003e 003f
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004a 004b 004c 004d 004e 004f
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005a 005b 005c 005d 005e 005f
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006a 006b 006c 006d 006e 006f
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007a 007b 007c 007d 007e 007f
+2500 2502 250c 2510 2514 2518 251c 2524 252c 2534 253c 2580 2584 2588 258c 2590
+2591 2592 2593 2320 25a0 2219 221a 2248 2264 2265 00a0 2321 00b0 00b2 00b7 00f7
+2550 2551 2552 0451 2553 2554 2555 2556 2557 2558 2559 255a 255b 255c 255d 255e
+255f 2560 2561 0401 2562 2563 2564 2565 2566 2567 2568 2569 256a 256b 256c 00a9
+044e 0430 0431 0446 0434 0435 0444 0433 0445 0438 0439 043a 043b 043c 043d 043e
+043f 044f 0440 0441 0442 0443 0436 0432 044c 044b 0437 0448 044d 0449 0447 044a
+042e 0410 0411 0426 0414 0415 0424 0413 0425 0418 0419 041a 041b 041c 041d 041e
+041f 042f 0420 0421 0422 0423 0416 0412 042c 042b 0417 0428 042d 0429 0427 042a
diff --git a/sql/share/charsets/koi8_ukr.conf b/sql/share/charsets/koi8_ukr.conf
index 3e2c8e27325..5a552900544 100644
--- a/sql/share/charsets/koi8_ukr.conf
+++ b/sql/share/charsets/koi8_ukr.conf
@@ -72,3 +72,21 @@
94 A4 95 96 97 98 89 82 A1 A0 8A 9D A2 9E 9C 9F
A3 80 81 9B 85 86 99 83 9A 8B 8E 8F 90 91 92 93
94 A4 95 96 97 98 89 82 A1 A0 8A 9D A2 9E 9C 9F
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+2500 2502 250C 2510 2514 2518 251C 2524 252C 2534 253C 2580 2584 2588 258C 2590
+2591 2592 2593 2320 25A0 2022 221A 2248 2264 2265 00A0 2321 00B0 00B2 00B7 00F7
+2550 2551 2552 0451 0454 2554 0456 0457 2557 2558 2559 255A 255B 0491 255D 255E
+255F 2560 2561 0401 0404 2563 0406 0407 2566 2567 2568 2569 256A 0490 256C 00A9
+044E 0430 0431 0446 0434 0435 0444 0433 0445 0438 0439 043A 043B 043C 043D 043E
+043F 044F 0440 0441 0442 0443 0436 0432 044C 044B 0437 0448 044D 0449 0447 044A
+042E 0410 0411 0426 0414 0415 0424 0413 0425 0418 0419 041A 041B 041C 041D 041E
+041F 042F 0420 0421 0422 0423 0416 0412 042C 042B 0417 0428 042D 0429 0427 042A
diff --git a/sql/share/charsets/latin1.conf b/sql/share/charsets/latin1.conf
index cf974aefa14..7cb5cfb3cfd 100644
--- a/sql/share/charsets/latin1.conf
+++ b/sql/share/charsets/latin1.conf
@@ -72,3 +72,21 @@
44 4E 4F 4F 4F 4F 5D D7 D8 55 55 55 59 59 DE DF
41 41 41 41 5C 5B 5C 43 45 45 45 45 49 49 49 49
44 4E 4F 4F 4F 4F 5D F7 D8 55 55 55 59 59 DE FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 00A1 00A2 00A3 00A4 00A5 00A6 00A7 00A8 00A9 00AA 00AB 00AC 00AD 00AE 00AF
+00B0 00B1 00B2 00B3 00B4 00B5 00B6 00B7 00B8 00B9 00BA 00BB 00BC 00BD 00BE 00BF
+00C0 00C1 00C2 00C3 00C4 00C5 00C6 00C7 00C8 00C9 00CA 00CB 00CC 00CD 00CE 00CF
+00D0 00D1 00D2 00D3 00D4 00D5 00D6 00D7 00D8 00D9 00DA 00DB 00DC 00DD 00DE 00DF
+00E0 00E1 00E2 00E3 00E4 00E5 00E6 00E7 00E8 00E9 00EA 00EB 00EC 00ED 00EE 00EF
+00F0 00F1 00F2 00F3 00F4 00F5 00F6 00F7 00F8 00F9 00FA 00FB 00FC 00FD 00FE 00FF
diff --git a/sql/share/charsets/latin2.conf b/sql/share/charsets/latin2.conf
index cc18c22c0a2..cc21af9faa1 100644
--- a/sql/share/charsets/latin2.conf
+++ b/sql/share/charsets/latin2.conf
@@ -72,3 +72,21 @@
FF 55 54 57 56 56 56 FF 5A 5F 5F 5F 5F 63 5E FF
5A 43 43 43 43 51 46 45 47 49 4A 49 49 4E 4E 48
FF 55 54 57 56 56 56 FF 5A 5F 5F 5F 5F 63 5E FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 0104 02D8 0141 00A4 013D 015A 00A7 00A8 0160 015E 0164 0179 00AD 017D 017B
+00B0 0105 02DB 0142 00B4 013E 015B 02C7 00B8 0161 015F 0165 017A 02DD 017E 017C
+0154 00C1 00C2 0102 00C4 0139 0106 00C7 010C 00C9 0118 00CB 011A 00CD 00CE 010E
+0110 0143 0147 00D3 00D4 0150 00D6 00D7 0158 016E 00DA 0170 00DC 00DD 0162 00DF
+0155 00E1 00E2 0103 00E4 013A 0107 00E7 010D 00E9 0119 00EB 011B 00ED 00EE 010F
+0111 0144 0148 00F3 00F4 0151 00F6 00F7 0159 016F 00FA 0171 00FC 00FD 0163 02D9
diff --git a/sql/share/charsets/latin5.conf b/sql/share/charsets/latin5.conf
index 92fbd2299bb..d603d019ce6 100644
--- a/sql/share/charsets/latin5.conf
+++ b/sql/share/charsets/latin5.conf
@@ -76,3 +76,21 @@
49 DB DC DD DE DF 53 E0 E1 E2 E3 E4 5B 4C 58 E5
CC CD CE CF D0 D1 D2 44 D3 D4 D5 D6 D7 D8 D9 DA
49 DB DC DD DE DF 53 FA E1 E2 E3 E4 5B 4B 58 FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 00A1 00A2 00A3 00A4 00A5 00A6 00A7 00A8 00A9 00AA 00AB 00AC 00AD 00AE 00AF
+00B0 00B1 00B2 00B3 00B4 00B5 00B6 00B7 00B8 00B9 00BA 00BB 00BC 00BD 00BE 00BF
+00C0 00C1 00C2 00C3 00C4 00C5 00C6 00C7 00C8 00C9 00CA 00CB 00CC 00CD 00CE 00CF
+011E 00D1 00D2 00D3 00D4 00D5 00D6 00D7 00D8 00D9 00DA 00DB 00DC 0130 015E 00DF
+00E0 00E1 00E2 00E3 00E4 00E5 00E6 00E7 00E8 00E9 00EA 00EB 00EC 00ED 00EE 00EF
+011F 00F1 00F2 00F3 00F4 00F5 00F6 00F7 00F8 00F9 00FA 00FB 00FC 0131 015F 00FF
diff --git a/sql/share/charsets/latvian.conf b/sql/share/charsets/latvian.conf
new file mode 100644
index 00000000000..c3dee95d55c
--- /dev/null
+++ b/sql/share/charsets/latvian.conf
@@ -0,0 +1,95 @@
+# Configuration file for the latvian character set.
+# Created for case-sensitive record search
+# Created accord with windows-1257 (iso-8859-4) codepage
+# Created by Andis Grasis & Rihards Grasis e-mail:andis@cata.lv
+
+# The ctype array must have 257 elements.
+ 00
+ 20 20 20 20 20 20 20 20 20 28 28 28 28 28 20 20
+ 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
+ 48 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
+ 84 84 84 84 84 84 84 84 84 84 10 10 10 10 10 10
+ 10 81 81 81 81 81 81 01 01 01 01 01 01 01 01 01
+ 01 01 01 01 01 01 01 01 01 01 01 10 10 10 10 10
+ 10 82 82 82 82 82 82 02 02 02 02 02 02 02 02 02
+ 02 02 02 02 02 02 02 02 02 02 02 10 10 10 10 20
+ 01 20 10 20 10 10 00 00 20 10 20 10 20 10 10 10
+ 20 10 10 10 10 10 10 10 20 00 20 10 20 10 10 20
+ 48 20 10 10 10 20 10 10 10 10 01 10 10 10 10 01
+ 10 10 10 10 10 10 10 10 10 10 02 10 10 10 10 02
+ 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
+ 01 01 01 01 01 01 01 10 01 01 01 01 01 01 01 02
+ 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
+ 02 02 02 02 02 02 02 10 02 02 02 02 02 02 02 10
+
+# The to_lower array must have 256 elements.
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 5B 5C 5D 5E 5F
+ 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
+ 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
+ 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
+ A0 A1 A2 A3 A4 A5 A6 A7 B8 A9 BA AB AC AD AE BF
+ B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
+ E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
+ F0 F1 F2 F3 F4 F5 F6 D7 F8 F9 FA FB FC FD FE DF
+ E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
+ F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# The to_upper array must have 256 elements.
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
+ 60 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 7B 7C 7D 7E 7F
+ 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
+ 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
+ A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
+ B0 B1 B2 B3 B4 B5 B6 B7 A8 B9 AA BB BC BD BE AF
+ C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
+ D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
+ C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
+ D0 D1 D2 D3 D4 D5 D6 F7 D8 D9 DA DB DC DD DE FF
+
+# The sort_order array must have 256 elements.
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 30 32 33 34 35 36 37 2B 38 39 3A 5C 3B 2C 3C 3D
+ 76 7A 7C 7E 80 81 82 83 84 85 3E 3F 5D 5E 5F 40
+ 41 86 92 94 9A 9C A6 A8 AC AE B4 B6 BA C0 C2 C8
+ D4 D6 D8 DC E3 E6 EE F0 F2 F4 F6 42 43 44 45 46
+ 47 87 93 95 9B 9D A7 A9 AD AF B5 B7 BB C1 C3 C9
+ D5 D7 D9 DD E4 E7 EF F1 F3 F5 F7 48 49 4A 4B 20
+ 75 21 56 22 59 73 70 71 23 74 24 5A 25 4D 51 50
+ 26 54 55 57 58 72 2E 2F 27 E5 28 5B 29 4E 53 2A
+ 31 FE 65 66 67 FF 4C 68 D3 69 DA 61 6A 2D 6B 90
+ 6C 60 7D 7F 4F 6D 6E 6F D2 7B DB 62 77 78 79 91
+ 8E B2 8A 96 88 8C A4 A2 98 9E F8 A0 AA B8 B0 BE
+ E1 C4 C6 CA CE D0 CC 63 EC BC DE EA E8 FA FC E0
+ 8F B3 8B 97 89 8D A5 A3 99 9F F9 A1 AB B9 B1 BF
+ E2 C5 C7 CB CF D1 CD 64 ED BD DF EB E9 FB FD 52
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 201D 00A2 00A3 00A4 201E 00A6 00A7 00D8 00A9 0156 00AB 00AC 00AD 00AE 00C6
+00B0 00B1 00B2 00B3 201C 00B5 00B6 00B7 00F8 00B9 0157 00BB 00BC 00BD 00BE 00E6
+0104 012E 0100 0106 00C4 00C5 0118 0112 010C 00C9 0179 0116 0122 0136 012A 013B
+0160 0143 0145 00D3 014C 00D5 00D6 00D7 0172 0141 015A 016A 00DC 017B 017D 00DF
+0105 012F 0101 0107 00E4 00E5 0119 0113 010D 00E9 017A 0117 0123 0137 012B 013C
+0161 0144 0146 00F3 014D 00F5 00F6 00F7 0173 0142 015B 016B 00FC 017C 017E 2019
diff --git a/sql/share/charsets/latvian1.conf b/sql/share/charsets/latvian1.conf
new file mode 100644
index 00000000000..3094525052d
--- /dev/null
+++ b/sql/share/charsets/latvian1.conf
@@ -0,0 +1,94 @@
+# Configuration file for the latvian character set.
+# Created for case-insensitive record search
+# Created by Andis & Rihards
+
+# The ctype array must have 257 elements.
+ 00
+ 20 20 20 20 20 20 20 20 20 28 28 28 28 28 20 20
+ 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
+ 48 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
+ 84 84 84 84 84 84 84 84 84 84 10 10 10 10 10 10
+ 10 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
+ 01 01 01 01 01 01 01 01 01 01 01 10 10 10 10 10
+ 10 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
+ 02 02 02 02 02 02 02 02 02 02 02 10 10 10 10 20
+ 00 00 10 00 10 10 00 00 00 00 00 10 00 10 10 10
+ 00 10 10 10 10 10 10 10 00 00 00 10 00 10 10 00
+ 48 00 10 10 10 00 10 10 10 10 01 10 10 10 10 10
+ 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
+ 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
+ 01 01 01 01 01 01 01 10 01 01 01 01 01 01 01 02
+ 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
+ 02 02 02 02 02 02 02 10 02 02 02 02 02 02 02 10
+
+# The to_lower array must have 256 elements.
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 5B 5C 5D 5E 5F
+ 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
+ 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
+ 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
+ A0 A1 A2 A3 A4 A5 A6 A7 B8 A9 BA AB AC AD AE BF
+ B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
+ E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
+ F0 F1 F2 F3 F4 F5 F6 D7 F8 F9 FA FB FC FD FE DF
+ E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
+ F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# The to_upper array must have 256 elements.
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
+ 60 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 7B 7C 7D 7E 7F
+ 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
+ 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
+ A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
+ B0 B1 B2 B3 B4 B5 B6 B7 A8 B9 AA BB BC BD BE AF
+ C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
+ D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
+ C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
+ D0 D1 D2 D3 D4 D5 D6 F7 D8 D9 DA DB DC DD DE FF
+
+# The sort_order array must have 256 elements.
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 30 32 33 34 35 36 37 2B 38 39 3A 5C 3B 2C 3C 3D
+ 76 7A 7C 7E 80 81 82 83 84 85 3E 3F 5D 5E 5F 40
+ 41 86 92 94 9A 9C A6 A8 AC AE B4 B6 BA C0 C2 C8
+ D4 D6 D8 DC E3 E6 EE F0 F2 F4 F6 42 43 44 45 46
+ 47 86 92 94 9A 9C A6 A8 AC AE B4 B6 BA C0 C2 C8
+ D4 D6 D8 DC E2 E6 EE F0 F2 F4 F6 48 49 4A 4B 20
+ 75 21 56 22 59 73 70 71 23 74 24 5A 25 4D 51 50
+ 26 54 55 57 58 72 2E 2F 27 E5 28 5B 29 4E 53 2A
+ 31 FE 65 66 67 FF 4C 68 2D 69 DA 61 6A 2D 6B 90
+ 6C 60 7D 7F 4F 6D 6E 6F D3 7B DB 62 77 78 79 90
+ 8E B2 8A 96 88 8C A4 A2 98 9E F8 A0 AA B8 B0 BE
+ E1 C4 C6 CA CE D0 CC 63 EC BC DE EA E8 FA FC E0
+ 8E B2 8A 96 88 8C A4 A2 98 9E F8 A0 AA B8 B0 BE
+ E1 C4 C6 CA CE D0 CC 64 EC BC DE EA E8 FA FC 52
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 008E 008F
+0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F
+00A0 201D 00A2 00A3 00A4 201E 00A6 00A7 00D8 00A9 0156 00AB 00AC 00AD 00AE 00C6
+00B0 00B1 00B2 00B3 201C 00B5 00B6 00B7 00F8 00B9 0157 00BB 00BC 00BD 00BE 00E6
+0104 012E 0100 0106 00C4 00C5 0118 0112 010C 00C9 0179 0116 0122 0136 012A 013B
+0160 0143 0145 00D3 014C 00D5 00D6 00D7 0172 0141 015A 016A 00DC 017B 017D 00DF
+0105 012F 0101 0107 00E4 00E5 0119 0113 010D 00E9 017A 0117 0123 0137 012B 013C
+0161 0144 0146 00F3 014D 00F5 00F6 00F7 0173 0142 015B 016B 00FC 017C 017E 2019
diff --git a/sql/share/charsets/macce.conf b/sql/share/charsets/macce.conf
new file mode 100644
index 00000000000..f3ac08df087
--- /dev/null
+++ b/sql/share/charsets/macce.conf
@@ -0,0 +1,91 @@
+# ctype array (must be 257 elements)
+ 00
+ 20 20 20 20 20 20 20 20 20 28 28 28 28 28 20 20
+ 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
+ 48 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
+ 84 84 84 84 84 84 84 84 84 84 10 10 10 10 10 10
+ 10 81 81 81 81 81 81 01 01 01 01 01 01 01 01 01
+ 01 01 01 01 01 01 01 01 01 01 01 10 10 10 10 10
+ 10 82 82 82 82 82 82 02 02 02 02 02 02 02 02 02
+ 02 02 02 02 02 02 02 02 02 02 02 10 10 10 10 00
+ 01 01 02 01 01 01 01 02 02 01 02 02 01 02 02 01
+ 02 01 02 02 01 02 01 02 02 02 02 02 02 01 02 02
+ 00 00 01 00 00 00 00 02 00 00 00 02 00 00 02 01
+ 02 01 00 00 02 01 00 00 02 01 02 01 02 01 02 01
+ 02 01 00 00 02 01 00 00 00 00 00 02 01 01 02 01
+ 00 00 00 00 00 00 00 00 02 01 02 01 00 00 02 01
+ 02 01 00 00 02 01 02 01 01 02 01 01 02 01 01 01
+ 02 01 01 02 01 02 01 02 01 02 02 01 01 02 01 00
+
+# to_lower array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 54 75 76 77 78 79 7A 5B 5C 5D 5E 5F
+ 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 54 75 76 77 78 79 7A 7B 7C 7D 7E 7F
+ 8A 82 82 8E 88 9A 9F 87 88 8B 8A 8B 8D 8D 8E 90
+ 90 93 92 93 95 95 98 97 98 99 9A 9B 9C 9E 9E 9F
+ A0 A1 AB A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE B0
+ B0 B4 B2 B3 B4 FA B6 B7 B8 BA BA BC BC BE BE C0
+ C0 C4 C2 C3 C4 CB C6 C7 C8 C9 CA CB CE 9B CE D8
+ D0 D1 D2 D3 D4 D5 D6 D7 D8 DA DA DE DC DD DE E0
+ E0 E4 E2 E3 E4 E6 E6 87 E9 E9 92 EC EC F0 97 99
+ F0 F3 9C F3 F5 F5 F7 F7 F9 F9 FA FD B8 FD AE FF
+
+# to_upper array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 74 55 56 57 58 59 5A 5B 5C 5D 5E 5F
+ 60 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 74 55 56 57 58 59 5A 7B 7C 7D 7E 7F
+ 80 81 81 83 84 85 86 E7 84 89 80 89 8C 8C 83 8F
+ 8F 91 EA 91 94 94 96 EE 96 EF 85 CD F2 9D 9D 86
+ A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA A2 AC AD FE AF
+ AF B1 B2 B3 B1 B5 B6 B7 FC B9 B9 BB BB BD BD BF
+ BF C1 C2 C3 C1 C5 C6 C7 C8 C9 CA C5 CC CD CC CF
+ D0 D1 D2 D3 D4 D5 D6 D7 CF D9 D9 DB DC DD DB DF
+ DF E1 E2 E3 E1 E5 E5 E7 E8 E8 EA EB EB ED EE EF
+ ED F1 F2 F1 F4 F4 F6 F6 F8 F8 B5 FB FC FB FE FF
+
+# sort_order array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 46 47 4A 4C 52 53 55 56 5A 5B 5D 62 62 67
+ 6F 70 71 75 79 81 88 89 8A 8B 8D 90 91 92 93 94
+ 95 41 46 47 4A 4C 52 53 55 56 5A 5B 5D 62 62 67
+ 6F 70 71 75 79 81 88 89 8A 8B 8D 96 97 98 99 9A
+ 41 41 41 4C 41 67 81 41 41 47 41 47 47 47 4C 8D
+ 8D 4A 56 4A 4C 4C 4C 67 4C 67 67 67 81 4C 4C 81
+ A0 A1 4C A3 A4 A5 A6 75 A8 A9 AA 4C AC AD 53 56
+ 56 56 B2 B3 56 5B B6 B7 5D 5D 5D 5D 5D 5D 5D 62
+ 62 62 C2 C3 62 62 C6 C7 C8 C9 CA 62 67 67 67 67
+ D0 D1 D2 D3 D4 D5 D6 D7 67 71 71 71 DC DD 71 71
+ 71 75 E2 E3 75 75 75 41 79 79 56 8D 8D 81 67 67
+ 81 81 81 81 81 81 81 81 8B 8B 5B 8D 5D 8D 53 FF
+
+# Unicode mappping (must be 256 elements)
+ 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+ 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+ 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+ 0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+ 0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+ 0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+ 0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+ 0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+ 00C4 0100 0101 00C9 0104 00D6 00DC 00E1 0105 010C 00E4 010D 0106 0107 00E9 0179
+ 017A 010E 00ED 010F 0112 0113 0116 00F3 0117 00F4 00F6 00F5 00FA 011A 011B 00FC
+ 2020 00B0 0118 00A3 00A7 2022 00B6 00DF 00AE 00A9 2122 0119 00A8 2260 0123 012E
+ 012F 012A 2264 2265 012B 0136 2202 2211 0142 013B 013C 013D 013E 0139 013A 0145
+ 0146 0143 00AC 221A 0144 0147 2206 00AB 00BB 2026 00A0 0148 0150 00D5 0151 014C
+ 2013 2014 201C 201D 2018 2019 00F7 25CA 014D 0154 0155 0158 2039 203A 0159 0156
+ 0157 0160 201A 201E 0161 015A 015B 00C1 0164 0165 00CD 017D 017E 016A 00D3 00D4
+ 016B 016E 00DA 016F 0170 0171 0172 0173 00DD 00FD 0137 017B 0141 017C 0122 02C7
+
diff --git a/sql/share/charsets/macroman.conf b/sql/share/charsets/macroman.conf
new file mode 100644
index 00000000000..11cbee40e94
--- /dev/null
+++ b/sql/share/charsets/macroman.conf
@@ -0,0 +1,91 @@
+# ctype array (must be 257 elements)
+ 00
+ 20 20 20 20 20 20 20 20 20 28 28 28 28 28 20 20
+ 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
+ 48 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
+ 84 84 84 84 84 84 84 84 84 84 10 10 10 10 10 10
+ 10 81 81 81 81 81 81 01 01 01 01 01 01 01 01 01
+ 01 01 01 01 01 01 01 01 01 01 01 10 10 10 10 10
+ 10 82 82 82 82 82 82 02 02 02 02 02 02 02 02 02
+ 02 02 02 02 02 02 02 02 02 02 02 10 10 10 10 10
+ 20 01 01 01 01 01 01 02 02 02 02 02 02 02 02 02
+ 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
+ 00 00 00 00 00 00 00 02 00 00 00 00 00 00 01 01
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 02
+ 00 00 00 00 02 00 00 00 00 00 00 20 01 01 00 00
+ 00 00 00 00 00 00 00 00 02 01 00 00 00 00 00 00
+ 00 00 00 00 00 20 01 01 01 01 01 01 01 01 01 01
+ 00 01 01 01 01 02 00 00 00 00 00 00 00 00 00 00
+
+# to_lower array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 5B 5C 5D 5E 5F
+ 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
+ 8A 8C 8D 8E 96 9A 9F 87 88 89 8A 8B 8C 8D 8E 8F
+ 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
+ A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD BE BF
+ B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
+ C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA 88 8B 9B CE CF
+ D0 D1 D2 D3 D4 D5 D6 D7 D8 D8 DA DB DC DD DE DF
+ E0 E1 E2 E3 E4 89 90 87 91 8F 92 94 95 93 97 99
+ F0 98 9C 9E 9D F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# to_upper array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
+ 60 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 7B 7C 7D 7E 7F
+ 80 81 82 83 84 85 86 E7 CB E5 80 CC 81 82 83 E9
+ E6 E8 EA ED EB EC 84 EE F1 EF 85 CD F2 F4 F3 86
+ A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
+ B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD AE AF
+ C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
+ D0 D1 D2 D3 D4 D5 D6 D7 D9 D9 DA DB DC DD DE DF
+ E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
+ F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# sort_order array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 49 50 52 53 57 59 60 61 67 68 69 70 71 72
+ 79 80 81 82 84 85 90 91 92 93 95 A0 A1 A2 A3 A4
+ A5 41 49 50 52 53 57 59 60 61 67 68 69 70 71 72
+ 79 80 81 82 84 85 90 91 92 93 95 A6 A7 A8 A9 AA
+ 41 41 50 53 71 72 85 41 41 41 41 41 41 50 53 53
+ 53 53 61 61 61 61 71 72 72 72 72 72 85 85 85 85
+ AB AC AD AE AF B0 B1 82 B2 B3 B4 B5 B6 B7 48 72
+ B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 48 72
+ C6 C7 C8 C9 57 CA CB CC CD CE CF 41 41 72 D0 D1
+ D2 D3 D4 D5 D6 D7 D8 D9 93 93 DA DB DC DD DE DF
+ E0 E1 E2 E3 E4 41 53 41 53 53 61 61 61 61 72 72
+ F0 72 85 85 85 61 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# Unicode mappping (must be 256 elements)
+ 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+ 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+ 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+ 0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+ 0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+ 0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+ 0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+ 0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+ 00C4 00C5 00C7 00C9 00D1 00D6 00DC 00E1 00E0 00E2 00E4 00E3 00E5 00E7 00E9 00E8
+ 00EA 00EB 00ED 00EC 00EE 00EF 00F1 00F3 00F2 00F4 00F6 00F5 00FA 00F9 00FB 00FC
+ 2020 00B0 00A2 00A3 00A7 2022 00B6 00DF 00AE 00A9 2122 00B4 00A8 2260 00C6 00D8
+ 221E 00B1 2264 2265 00A5 00B5 2202 2211 220F 03C0 222B 00AA 00BA 03A9 00E6 00F8
+ 00BF 00A1 00AC 221A 0192 2248 2206 00AB 00BB 2026 00A0 00C0 00C3 00D5 0152 0153
+ 2013 2014 201C 201D 2018 2019 00F7 25CA 00FF 0178 2044 20AC 2039 203A FB01 FB02
+ 2021 00B7 201A 201E 2030 00C2 00CA 00C1 00CB 00C8 00CD 00CE 00CF 00CC 00D3 00D4
+ F8FF 00D2 00DA 00DB 00D9 0131 02C6 02DC 00AF 02D8 02D9 02DA 00B8 02DD 02DB 02C7
+
diff --git a/sql/share/charsets/pclatin2.conf b/sql/share/charsets/pclatin2.conf
new file mode 100644
index 00000000000..dea8d085595
--- /dev/null
+++ b/sql/share/charsets/pclatin2.conf
@@ -0,0 +1,91 @@
+# ctype array (must be 257 elements)
+ 00
+ 20 20 20 20 20 20 20 20 20 28 28 28 28 28 20 20
+ 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
+ 48 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
+ 84 84 84 84 84 84 84 84 84 84 10 10 10 10 10 10
+ 10 81 81 81 81 81 81 01 01 01 01 01 01 01 01 01
+ 01 01 01 01 01 01 01 01 01 01 01 10 10 10 10 10
+ 10 82 82 82 82 82 82 02 02 02 02 02 02 02 02 02
+ 02 02 02 02 02 02 02 02 02 02 02 10 10 10 10 00
+ 01 02 02 02 02 02 02 02 02 02 01 02 02 01 01 01
+ 01 01 02 02 02 01 02 01 02 01 01 01 02 01 00 02
+ 02 02 02 02 01 02 01 02 01 02 00 02 01 01 00 00
+ 00 00 00 00 00 01 01 01 02 00 00 00 00 01 02 00
+ 00 00 00 00 00 00 01 02 00 00 00 00 00 00 00 00
+ 02 01 01 01 02 01 01 01 02 00 00 00 00 01 01 00
+ 01 02 01 01 02 02 01 02 01 01 02 01 02 01 02 00
+ 00 00 00 00 00 00 00 00 00 00 00 02 01 02 00 48
+
+# to_lower array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 5B 5C 5D 5E 5F
+ 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
+ 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
+ 87 81 82 83 84 85 86 87 88 89 8B 8B 8C AB 84 86
+ 82 92 92 93 94 96 96 98 98 94 81 9C 9C 88 9E 9F
+ A0 A1 A2 A3 A5 A5 A7 A7 A9 A9 AA AB 9F B8 AE AF
+ B0 B1 B2 B3 B4 A0 83 D8 B8 B9 BA BB BC BE BE BF
+ C0 C1 C2 C3 C4 C5 C7 C7 C8 C9 CA CB CC CD CE CF
+ D0 D0 D4 89 D4 E5 A1 8C D8 D9 DA DB DC EE 85 DF
+ A2 E1 93 E4 E4 E5 E7 E7 EA A3 E8 FB EC EC EE EF
+ F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# to_upper array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
+ 60 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
+ 50 51 52 53 54 55 56 57 58 59 5A 7B 7C 7D 7E 7F
+ 80 9A 90 B6 8E DE 8F 80 9D D3 8A 8A D7 8D 8E 8F
+ 90 91 91 E2 99 95 95 97 97 99 9A 9B 9B 9D 9E AC
+ B5 D6 E0 E9 A4 A4 A6 A6 A8 A8 AA 8D AC AD AE AF
+ B0 B1 B2 B3 B4 B5 B6 B7 AD B9 BA BB BC BE BD BF
+ C0 C1 C2 C3 C4 C5 C6 C6 C8 C9 CA CB CC CD CE CF
+ D1 D1 D2 D3 D2 D5 D6 D7 B7 D9 DA DB DC DD DE DF
+ E0 E1 E2 E3 E3 D5 E6 E6 E8 E9 E8 EB ED ED DD EF
+ F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA EB FC FC FE FF
+
+# sort_order array (must be 256 elements)
+ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
+ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
+ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
+ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
+ 40 41 47 48 4C 4F 54 55 56 57 5A 5B 5C 5E 5F 62
+ 67 68 69 6C 71 74 75 76 77 78 7B 90 91 92 93 94
+ 95 41 47 48 4C 4F 54 55 56 57 5A 5B 5C 5E 5F 62
+ 67 68 69 6C 71 74 75 76 77 78 7B 96 97 98 99 9A
+ 48 74 4F 41 41 74 48 48 5C 4F 62 62 57 7B 41 48
+ 4F 5C 5C 62 62 5C 5C 6C 6C 62 74 71 71 5C 9E 48
+ 41 57 62 74 41 41 7B 7B 4F 4F AA 7B 48 6C AE AF
+ B0 B1 B2 B3 B4 41 41 4F 6C B5 BA BB BC 7B 7B BF
+ C0 C1 C2 C3 C4 C5 41 41 C8 C9 CA CB CC CD CE CF
+ 4C 4C 4C 4F 4C 60 57 57 4F D9 DA DB DC 71 74 DF
+ 62 70 62 60 60 60 6C 6C 69 74 69 74 78 78 71 EF
+ F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA 74 69 69 FE FF
+
+# Unicode mappping (must be 256 elements)
+ 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+ 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+ 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+ 0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+ 0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+ 0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+ 0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+ 0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+ 00C7 00FC 00E9 00E2 00E4 016F 0107 00E7 0142 00EB 0150 0151 00EE 0179 00C4 0106
+ 00C9 0139 013A 00F4 00F6 013D 013E 015A 015B 00D6 00DC 0164 0165 0141 00D7 010D
+ 00E1 00ED 00F3 00FA 0104 0105 017D 017E 0118 0119 00AC 017A 010C 015F 00AB 00BB
+ 2591 2592 2593 2502 2524 00C1 00C2 011A 015E 2563 2551 2557 255D 017B 017C 2510
+ 2514 2534 252C 251C 2500 253C 0102 0103 255A 2554 2569 2566 2560 2550 256C 00A4
+ 0111 0110 010E 00CB 010F 0147 00CD 00CE 011B 2518 250C 2588 2584 0162 016E 2580
+ 00D3 00DF 00D4 0143 0144 0148 0160 0161 0154 00DA 0155 0170 00FD 00DD 0163 00B4
+ 00AD 02DD 02DB 02C7 02D8 00A7 00F7 00B8 00B0 00A8 02D9 0171 0158 0159 25A0 00A0
+
diff --git a/sql/share/charsets/swe7.conf b/sql/share/charsets/swe7.conf
index d2de48b4d1c..49938800f39 100644
--- a/sql/share/charsets/swe7.conf
+++ b/sql/share/charsets/swe7.conf
@@ -72,3 +72,21 @@
D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+00C9 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 00C4 00D6 00C5 00DC 005F
+00E9 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 00E4 00F6 00E5 00FC 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
diff --git a/sql/share/charsets/usa7.conf b/sql/share/charsets/usa7.conf
index b9e7a44c894..380fc9b5d8b 100644
--- a/sql/share/charsets/usa7.conf
+++ b/sql/share/charsets/usa7.conf
@@ -72,3 +72,21 @@
D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
+0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
diff --git a/sql/share/charsets/win1250.conf b/sql/share/charsets/win1250.conf
index 31d253d7381..0a5b5074bde 100644
--- a/sql/share/charsets/win1250.conf
+++ b/sql/share/charsets/win1250.conf
@@ -72,3 +72,21 @@
47 53 53 55 55 55 55 D7 58 5C 5C 5C 5C 60 5B 59
58 41 41 41 41 50 45 43 44 49 49 49 49 4D 4D 46
47 53 53 55 55 55 55 F7 58 5C 5C 5C 5C 60 5B FF
+
+# Unicode mapping table (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+20AC 0000 201A 0000 201E 2026 2020 2021 0000 2030 0160 2039 015A 0164 017D 0179
+0000 2018 2019 201C 201D 2022 2013 2014 0000 2122 0161 203A 015B 0165 017E 017A
+00A0 02C7 02D8 0141 00A4 0104 00A6 00A7 00A8 00A9 015E 00AB 00AC 00AD 00AE 017B
+00B0 00B1 02DB 0142 00B4 00B5 00B6 00B7 00B8 0105 015F 00BB 013D 02DD 013E 017C
+0154 00C1 00C2 0102 00C4 0139 0106 00C7 010C 00C9 0118 00CB 011A 00CD 00CE 010E
+0110 0143 0147 00D3 00D4 0150 00D6 00D7 0158 016E 00DA 0170 00DC 00DD 0162 00DF
+0155 00E1 00E2 0103 00E4 013A 0107 00E7 010D 00E9 0119 00EB 011B 00ED 00EE 010F
+0111 0144 0148 00F3 00F4 0151 00F6 00F7 0159 016F 00FA 0171 00FC 00FD 0163 02D9
diff --git a/sql/share/charsets/win1251.conf b/sql/share/charsets/win1251.conf
index a5ccc3190ad..2164cb36b9e 100644
--- a/sql/share/charsets/win1251.conf
+++ b/sql/share/charsets/win1251.conf
@@ -80,3 +80,21 @@
D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF E0
C0 C1 C2 C3 C4 C5 C7 C8 C9 CA CB CC CD CE CF D0
D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF E0
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0402 0403 201A 0453 201E 2026 2020 2021 0000 2030 0409 2039 040A 040C 040B 040F
+0452 2018 2019 201C 201D 2022 2013 2014 0000 2122 0459 203A 045A 045C 045B 045F
+00A0 040E 045E 0408 00A4 0490 00A6 00A7 0401 00A9 0404 00AB 00AC 00AD 00AE 0407
+00B0 00B1 0406 0456 0491 00B5 00B6 00B7 0451 2116 0454 00BB 0458 0405 0455 0457
+0410 0411 0412 0413 0414 0415 0416 0417 0418 0419 041A 041B 041C 041D 041E 041F
+0420 0421 0422 0423 0424 0425 0426 0427 0428 0429 042A 042B 042C 042D 042E 042F
+0430 0431 0432 0433 0434 0435 0436 0437 0438 0439 043A 043B 043C 043D 043E 043F
+0440 0441 0442 0443 0444 0445 0446 0447 0448 0449 044A 044B 044C 044D 044E 044F
diff --git a/sql/share/charsets/win1251ukr.conf b/sql/share/charsets/win1251ukr.conf
index e693958910e..da08e4c7d6f 100644
--- a/sql/share/charsets/win1251ukr.conf
+++ b/sql/share/charsets/win1251ukr.conf
@@ -75,3 +75,21 @@
95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4
80 81 82 83 85 86 89 8A 8B 8E 8F 90 91 92 93 94
95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4
+
+# Unicode mapping (256 elements)
+0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
+0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B 001C 001D 001E 001F
+0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F
+0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F
+0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E 004F
+0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005F
+0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D 006E 006F
+0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 007A 007B 007C 007D 007E 007F
+0402 0403 201A 0453 201E 2026 2020 2021 0000 2030 0409 2039 040A 040C 040B 040F
+0452 2018 2019 201C 201D 2022 2013 2014 0000 2122 0459 203A 045A 045C 045B 045F
+00A0 040E 045E 0408 00A4 0490 00A6 00A7 0401 00A9 0404 00AB 00AC 00AD 00AE 0407
+00B0 00B1 0406 0456 0491 00B5 00B6 00B7 0451 2116 0454 00BB 0458 0405 0455 0457
+0410 0411 0412 0413 0414 0415 0416 0417 0418 0419 041A 041B 041C 041D 041E 041F
+0420 0421 0422 0423 0424 0425 0426 0427 0428 0429 042A 042B 042C 042D 042E 042F
+0430 0431 0432 0433 0434 0435 0436 0437 0438 0439 043A 043B 043C 043D 043E 043F
+0440 0441 0442 0443 0444 0445 0446 0447 0448 0449 044A 044B 044C 044D 044E 044F
diff --git a/sql/share/czech/errmsg.txt b/sql/share/czech/errmsg.txt
index 18b32447dc9..e9f3b997a96 100644
--- a/sql/share/czech/errmsg.txt
+++ b/sql/share/czech/errmsg.txt
@@ -247,3 +247,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/danish/errmsg.txt b/sql/share/danish/errmsg.txt
index d6528753195..71785bb8ba2 100644
--- a/sql/share/danish/errmsg.txt
+++ b/sql/share/danish/errmsg.txt
@@ -241,3 +241,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/dutch/errmsg.txt b/sql/share/dutch/errmsg.txt
index 514b4ee0780..e129b1cc30e 100644
--- a/sql/share/dutch/errmsg.txt
+++ b/sql/share/dutch/errmsg.txt
@@ -249,3 +249,7 @@
"Foutieve toepassing/plaatsing van '%s'",
"Deze versie van MySQL ondersteunt nog geen '%s'",
"Kreeg fatale fout %d: '%-.128s' van master tijdens lezen van data uit binaire log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/english/errmsg.txt b/sql/share/english/errmsg.txt
index 450b3453b01..88ab604fbcf 100644
--- a/sql/share/english/errmsg.txt
+++ b/sql/share/english/errmsg.txt
@@ -238,3 +238,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/estonian/errmsg.txt b/sql/share/estonian/errmsg.txt
index f160be03e89..9f412bb1594 100644
--- a/sql/share/estonian/errmsg.txt
+++ b/sql/share/estonian/errmsg.txt
@@ -243,3 +243,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/french/errmsg.txt b/sql/share/french/errmsg.txt
index c8d92d72b5f..33cf1a9e377 100644
--- a/sql/share/french/errmsg.txt
+++ b/sql/share/french/errmsg.txt
@@ -238,3 +238,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/german/errmsg.txt b/sql/share/german/errmsg.txt
index 6de6e911cd0..1056dccba2b 100644
--- a/sql/share/german/errmsg.txt
+++ b/sql/share/german/errmsg.txt
@@ -241,3 +241,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/greek/errmsg.txt b/sql/share/greek/errmsg.txt
index 6a58bfb6ea8..a344ed2df9e 100644
--- a/sql/share/greek/errmsg.txt
+++ b/sql/share/greek/errmsg.txt
@@ -238,3 +238,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/hungarian/errmsg.txt b/sql/share/hungarian/errmsg.txt
index 8da5eb6d8d6..9e88f2c3e2c 100644
--- a/sql/share/hungarian/errmsg.txt
+++ b/sql/share/hungarian/errmsg.txt
@@ -240,3 +240,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/italian/errmsg.txt b/sql/share/italian/errmsg.txt
index 0aa2ce07545..c9275a70878 100644
--- a/sql/share/italian/errmsg.txt
+++ b/sql/share/italian/errmsg.txt
@@ -238,3 +238,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/japanese/errmsg.txt b/sql/share/japanese/errmsg.txt
index e81feded9d7..07bdcd6bee5 100644
--- a/sql/share/japanese/errmsg.txt
+++ b/sql/share/japanese/errmsg.txt
@@ -240,3 +240,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/korean/errmsg.txt b/sql/share/korean/errmsg.txt
index 45d049e2545..57f990fdc04 100644
--- a/sql/share/korean/errmsg.txt
+++ b/sql/share/korean/errmsg.txt
@@ -238,3 +238,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/norwegian-ny/errmsg.txt b/sql/share/norwegian-ny/errmsg.txt
index 6fd054fa5f2..37f7f2fac01 100644
--- a/sql/share/norwegian-ny/errmsg.txt
+++ b/sql/share/norwegian-ny/errmsg.txt
@@ -240,3 +240,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/norwegian/errmsg.txt b/sql/share/norwegian/errmsg.txt
index a241a99b179..93f4090d697 100644
--- a/sql/share/norwegian/errmsg.txt
+++ b/sql/share/norwegian/errmsg.txt
@@ -240,3 +240,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/polish/errmsg.txt b/sql/share/polish/errmsg.txt
index 7184acf2495..3b43ce539c7 100644
--- a/sql/share/polish/errmsg.txt
+++ b/sql/share/polish/errmsg.txt
@@ -242,3 +242,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/portuguese/errmsg.txt b/sql/share/portuguese/errmsg.txt
index e5de0d85b03..fcdbf607807 100644
--- a/sql/share/portuguese/errmsg.txt
+++ b/sql/share/portuguese/errmsg.txt
@@ -238,3 +238,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/romanian/errmsg.txt b/sql/share/romanian/errmsg.txt
index 406c1ba3c70..ce237d755d4 100644
--- a/sql/share/romanian/errmsg.txt
+++ b/sql/share/romanian/errmsg.txt
@@ -242,3 +242,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/russian/errmsg.txt b/sql/share/russian/errmsg.txt
index ec6f7d2818c..35b9c8080c2 100644
--- a/sql/share/russian/errmsg.txt
+++ b/sql/share/russian/errmsg.txt
@@ -241,3 +241,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"ðÏÄÚÁÐÒÏÓ ×ÏÚ×ÒÁÝÁÅÔ ÂÏÌÅÅ ÏÄÎÏÇÏ ÐÏÌÑ",
+"ðÏÄÚÁÐÒÏÓ ×ÏÚ×ÒÁÝÁÅÔ ÂÏÌÅÅ ÏÄÎÏÊ ÚÁÐÉÓÉ",
diff --git a/sql/share/serbian/errmsg.txt b/sql/share/serbian/errmsg.txt
new file mode 100644
index 00000000000..78febb65c3c
--- /dev/null
+++ b/sql/share/serbian/errmsg.txt
@@ -0,0 +1,240 @@
+/* Copyright Abandoned 1997 TCX DataKonsult AB & Monty Program KB & Detron HB
+ This file is public domain and comes with NO WARRANTY of any kind */
+
+/* Serbian Translation, version 1.0:
+ Copyright 2002 Vladimir Kraljevic, vladimir_kraljevic@yahoo.com
+ This file is public domain and comes with NO WARRANTY of any kind.
+ Charset: cp1250
+*/
+
+"hashchk",
+"isamchk",
+"NE",
+"DA",
+"Ne mogu da kreiram file '%-.64s' (errno: %d)",
+"Ne mogu da kreiram tabelu '%-.64s' (errno: %d)",
+"Ne mogu da kreiram bazu '%-.64s'. (errno: %d)",
+"Ne mogu da kreiram bazu '%-.64s'. Baza veæ postoji.",
+"Ne mogu da izbrišem bazu '%-.64s'. Baza ne postoji.",
+"Ne mogu da izbrišem bazu (ne mogu da izbrišem '%-.64s', errno: %d)",
+"Ne mogu da izbrišem bazu (ne mogu da izbrišem direktorijum '%-.64s', errno: %d)",
+"Greška pri brisanju '%-.64s' (errno: %d)",
+"Ne mogu da proèitam slog iz sistemske tabele",
+"Ne mogu da dobijem stanje file-a '%-.64s' (errno: %d)",
+"Ne mogu da dobijem trenutni direktorijum (errno: %d)",
+"Ne mogu da zakljuèam file (errno: %d)",
+"Ne mogu da otvorim file: '%-.64s'. (errno: %d)",
+"Ne mogu da pronaðem file: '%-.64s' (errno: %d)",
+"Ne mogu da proèitam direktorijum '%-.64s' (errno: %d)",
+"Ne mogu da promenim direktorijum na '%-.64s' (errno: %d)",
+"Slog je promenjen od zadnjeg èitanja tabele '%-.64s'",
+"Disk je pun (%s). Èekam nekoga da doðe i oslobodi nešto mesta....",
+"Ne mogu da pišem pošto postoji duplirani kljuè u tabeli '%-.64s'",
+"Greška pri zatvaranju '%-.64s' (errno: %d)",
+"Greška pri èitanju file-a '%-.64s' (errno: %d)",
+"Greška pri promeni imena '%-.64s' na '%-.64s' (errno: %d)",
+"Greška pri upisu '%-.64s' (errno: %d)",
+"'%-.64s' je zakljuèan za upis",
+"Sortiranje je prekinuto",
+"View '%-.64s' ne postoji za '%-.64s'",
+"Handler tabela je vratio grešku %d",
+"Handler tabela za '%-.64s' nema ovu opciju",
+"Ne mogu da pronaðem slog u '%-.64s'",
+"Pogrešna informacija u file-u: '%-.64s'",
+"Pogrešan key file za tabelu: '%-.64s'. Probajte da ga ispravite",
+"Zastareo key file za tabelu '%-.64s'; Ispravite ga",
+"Tabelu '%-.64s' je dozvoljeno samo èitati",
+"Nema memorije. Restartujte MySQL server i probajte ponovo (potrebno je %d byte-ova)",
+"Nema memorije za sortiranje. Poveæajte velièinu sort buffer-a MySQL server-u",
+"Neoèekivani kraj pri èitanju file-a '%-.64s' (errno: %d)",
+"Previše konekcija",
+"Nema memorije; Proverite da li MySQL server ili neki drugi proces koristi svu slobodnu memoriju. (UNIX: Ako ne, probajte da upotrebite 'ulimit' komandu da biste dozvolili daemon-u da koristi više memorije ili probajte da dodate više swap memorije)",
+"Ne mogu da dobijem ime host-a za vašu IP adresu",
+"Loš poèetak komunikacije (handshake)",
+"Pristup je zabranjen korisniku '%-.32s@%-.64s' za bazu '%-.64s'",
+"Pristup je zabranjen korisniku '%-.32s@%-.64s' (koristi lozinku: '%s')",
+"Ni jedna baza nije selektovana",
+"Nepoznata komanda",
+"Kolona '%-.64s' ne može biti NULL",
+"Nepoznata baza '%-.64s'",
+"Tabela '%-.64s' veæ postoji",
+"Nepoznata tabela '%-.64s'",
+"Kolona '%-.64s' u %-.64s nije jedinstvena u kontekstu",
+"Gašenje servera je u toku",
+"Nepoznata kolona '%-.64s' u '%-.64s'",
+"Entitet '%-.64s' nije naveden u komandi 'GROUP BY'",
+"Ne mogu da grupišem po '%-.64s'",
+"Izraz ima 'SUM' agregatnu funkciju i kolone u isto vreme",
+"Broj kolona ne odgovara broju vrednosti",
+"Ime '%-.100s' je predugaèko",
+"Duplirano ime kolone '%-.64s'",
+"Duplirano ime kljuèa '%-.64s'",
+"Dupliran unos '%-.64s' za kljuè '%d'",
+"Pogrešan naziv kolone za kolonu '%-.64s'",
+"'%s' u iskazu '%-.80s' na liniji %d",
+"Upit je bio prazan",
+"Tabela ili alias nisu bili jedinstveni: '%-.64s'",
+"Loša default vrednost za '%-.64s'",
+"Definisani višestruki primarni kljuèevi",
+"Navedeno je previše kljuèeva. Maksimum %d kljuèeva je dozvoljeno",
+"Navedeno je previše delova kljuèa. Maksimum %d delova je dozvoljeno",
+"Navedeni kljuè je predug. Maksimalna dužina kljuèa je %d",
+"Kljuèna kolona '%-.64s' ne postoji u tabeli",
+"BLOB kolona '%-.64s' ne može biti upotrebljena za navoðenje kljuèa sa tipom tabele koji se trenutno koristi",
+"Previše podataka za kolonu '%-.64s' (maksimum je %d). Upotrebite BLOB polje",
+"Pogrešna definicija tabele; U tabeli može postojati samo jedna 'AUTO' kolona i ona mora biti istovremeno definisana kao kolona kljuèa",
+"%s: Spreman za konekcije\n",
+"%s: Normalno gašenje\n",
+"%s: Dobio signal %d. Prekidam!\n",
+"%s: Gašenje završeno\n",
+"%s: Usiljeno gašenje thread-a %ld koji pripada korisniku: '%-.32s'\n",
+"Ne mogu da kreiram IP socket",
+"Tabela '%-.64s' nema isti indeks kao onaj upotrebljen pri komandi 'CREATE INDEX'. Napravite tabelu ponovo",
+"Argument separatora polja nije ono što se oèekivalo. Proverite uputstvo MySQL server-a",
+"Ne možete koristiti fiksnu velièinu sloga kada imate BLOB polja. Molim koristite 'fields terminated by' opciju.",
+"File '%-.64s' mora biti u direktorijumu gde su file-ovi baze i mora imati odgovarajuæa prava pristupa",
+"File '%-.80s' veæ postoji",
+"Slogova: %ld Izbrisano: %ld Preskoèeno: %ld Upozorenja: %ld",
+"Slogova: %ld Duplikata: %ld",
+"Pogrešan pod-kljuè dela kljuèa. Upotrebljeni deo kljuèa nije string, upotrebljena dužina je veæa od dela kljuèa ili handler tabela ne podržava jedinstvene pod-kljuèeve",
+"Ne možete da izbrišete sve kolone pomoæu komande 'ALTER TABLE'. Upotrebite komandu 'DROP TABLE' ako želite to da uradite",
+"Ne mogu da izvršim komandu drop 'DROP' na '%-.64s'. Proverite da li ta kolona (odnosno kljuè) postoji",
+"Slogova: %ld Duplikata: %ld Upozorenja: %ld",
+"Komanda 'INSERT TABLE' na '%-.64s' nije dozvoljena u listi 'FROM' tabela",
+"Nepoznat thread identifikator: %lu",
+"Vi niste vlasnik thread-a %lu",
+"Nema upotrebljenih tabela",
+"Previše string-ova za kolonu '%-.64s' i komandu 'SET'",
+"Ne mogu da generišem jedinstveno ime log-file-a: '%-.64s.(1-999)'\n",
+"Tabela '%-.64s' je zakljuèana READ lock-om; iz nje se može samo èitati ali u nju se ne može pisati",
+"Tabela '%-.64s' nije bila zakljuèana komandom 'LOCK TABLES'",
+"BLOB kolona '%-.64s' ne može imati default vrednost",
+"Pogrešno ime baze '%-.100s'",
+"Pogrešno ime tabele '%-.100s'",
+"Komanda 'SELECT' æe ispitati previše slogova i potrošiti previše vremena. Proverite vaš 'WHERE' filter i upotrebite 'SET OPTION SQL_BIG_SELECTS=1' ako želite baš ovakvu komandu",
+"Nepoznata greška",
+"Nepoznata procedura '%-.64s'",
+"Pogrešan broj parametara za proceduru '%-.64s'",
+"Pogrešni parametri prosleðeni proceduri '%-.64s'",
+"Nepoznata tabela '%-.64s' u '%-.32s'",
+"Kolona '%-.64s' je navedena dva puta",
+"Pogrešna upotreba 'GROUP' funkcije",
+"Tabela '%-.64s' koristi ekstenziju koje ne postoji u ovoj verziji MySQL-a",
+"Tabela mora imati najmanje jednu kolonu",
+"Tabela '%-.64s' je popunjena do kraja",
+"Nepoznati karakter-set: '%-.64s'",
+"Previše tabela. MySQL može upotrebiti maksimum %d tabela pri 'JOIN' operaciji",
+"Previše kolona",
+"Prevelik slog. Maksimalna velièina sloga, ne raèunajuæi BLOB polja, je %d. Trebali bi da promenite tip nekih polja u BLOB",
+"Prepisivanje thread stack-a: Upotrebljeno: %ld od %ld stack memorije. Upotrebite 'mysqld -O thread_stack=#' da navedete veæi stack ako je potrebno",
+"Unakrsna zavisnost pronaðena u komandi 'OUTER JOIN'. Istražite vaše 'ON' uslove",
+"Kolona '%-.64s' je upotrebljena kao 'UNIQUE' ili 'INDEX' ali nije definisana kao 'NOT NULL'",
+"Ne mogu da uèitam funkciju '%-.64s'",
+"Ne mogu da inicijalizujem funkciju '%-.64s'; %-.80s",
+"Ne postoje dozvoljene putanje do share-ovane biblioteke",
+"Funkcija '%-.64s' veæ postoji",
+"Ne mogu da otvorim share-ovanu biblioteku '%-.64s' (errno: %d %-.64s)",
+"Ne mogu da pronadjem funkciju '%-.64s' u biblioteci",
+"Funkcija '%-.64s' nije definisana",
+"Host '%-.64s' je blokiran zbog previše grešaka u konekciji. Možete ga odblokirati pomoæu komande 'mysqladmin flush-hosts'",
+"Host-u '%-.64s' nije dozvoljeno da se konektuje na ovaj MySQL server",
+"Vi koristite MySQL kao anonimni korisnik a anonimnim korisnicima nije dozvoljeno da menjaju lozinke",
+"Morate imati privilegije da možete da update-ujete odreðene tabele ako želite da menjate lozinke za druge korisnike",
+"Ne mogu da pronaðem odgovarajuæi slog u 'user' tabeli",
+"Odgovarajuæih slogova: %ld Promenjeno: %ld Upozorenja: %ld",
+"Ne mogu da kreiram novi thread (errno %d). Ako imate još slobodne memorije, trebali biste da pogledate u priruèniku da li je ovo specifièna greška vašeg operativnog sistema",
+"Broj kolona ne odgovara broju vrednosti u slogu %ld",
+"Ne mogu da ponovo otvorim tabelu '%-.64s'",
+"Pogrešna upotreba vrednosti NULL",
+"Funkcija regexp je vratila grešku '%-.64s'",
+"Upotreba agregatnih funkcija (MIN(),MAX(),COUNT()...) bez 'GROUP' kolona je pogrešna ako ne postoji 'GROUP BY' iskaz",
+"Ne postoji odobrenje za pristup korisniku '%-.32s' na host-u '%-.64s'",
+"%-.16s komanda zabranjena za korisnika '%-.32s@%-.64s' za tabelu '%-.64s'",
+"%-.16s komanda zabranjena za korisnika '%-.32s@%-.64s' za kolonu '%-.64s' iz tabele '%-.64s'",
+"Pogrešna 'GRANT' odnosno 'REVOKE' komanda. Molim Vas pogledajte u priruèniku koje vrednosti mogu biti upotrebljene.",
+"Argument 'host' ili 'korisnik' prosleðen komandi 'GRANT' je predugaèak",
+"Tabela '%-.64s.%-.64s' ne postoji",
+"Ne postoji odobrenje za pristup korisniku '%-.32s' na host-u '%-.64s' tabeli '%-.64s'",
+"Upotrebljena komanda nije dozvoljena sa ovom verzijom MySQL servera",
+"Imate grešku u vašoj SQL sintaksi",
+"Prolongirani 'INSERT' thread nije mogao da dobije traženo zakljuèavanje tabele '%-.64s'",
+"Previše prolongiranih thread-ova je u upotrebi",
+"Prekinuta konekcija broj %ld ka bazi: '%-.64s' korisnik je bio: '%-.32s' (%-.64s)",
+"Primio sam mrežni paket veæi od definisane vrednosti 'max_allowed_packet'",
+"Greška pri èitanju podataka sa pipe-a",
+"Greška pri izvršavanju funkcije fcntl()",
+"Primio sam mrežne pakete van reda",
+"Ne mogu da dekompresujem mrežne pakete",
+"Greška pri primanju mrežnih paketa",
+"Vremenski limit za èitanje mrežnih paketa je istekao",
+"Greška pri slanju mrežnih paketa",
+"Vremenski limit za slanje mrežnih paketa je istekao",
+"Rezultujuèi string je duži nego što to dozvoljava parametar servera 'max_allowed_packet'",
+"Iskorišteni tip tabele ne podržava kolone tipa 'BLOB' odnosno 'TEXT'",
+"Iskorišteni tip tabele ne podržava kolone tipa 'AUTO_INCREMENT'",
+"Komanda 'INSERT DELAYED' ne može biti iskorištena u tabeli '%-.64s', zbog toga što je zakljuèana komandom 'LOCK TABLES'",
+"Pogrešno ime kolone '%-.100s'",
+"Handler tabele ne može da indeksira kolonu '%-.64s'",
+"Tabele iskorištene u 'MERGE' tabeli nisu definisane na isti naèin",
+"Zbog provere jedinstvenosti ne mogu da upišem podatke u tabelu '%-.64s'",
+"BLOB kolona '%-.64s' je upotrebljena u specifikaciji kljuèa bez navoðenja dužine kljuèa",
+"Svi delovi primarnog kljuèa moraju biti razlièiti od NULL; Ako Vam ipak treba NULL vrednost u kljuèu, upotrebite 'UNIQUE'",
+"Rezultat je saèinjen od više slogova",
+"Ovaj tip tabele zahteva da imate definisan primarni kljuè",
+"Ova verzija MySQL servera nije kompajlirana sa podrškom za RAID ureðaje",
+"Vi koristite safe update mod servera, a probali ste da promenite podatke bez 'WHERE' komande koja koristi kolonu kljuèa",
+"Kljuè '%-.64s' ne postoji u tabeli '%-.64s'",
+"Ne mogu da otvorim tabelu",
+"Handler za ovu tabelu ne dozvoljava 'check' odnosno 'repair' komande",
+"Nije Vam dozvoljeno da izvršite ovu komandu u transakciji",
+"Greška %d za vreme izvršavanja komande 'COMMIT'",
+"Greška %d za vreme izvršavanja komande 'ROLLBACK'",
+"Greška %d za vreme izvršavanja komande 'FLUSH_LOGS'",
+"Greška %d za vreme izvršavanja komande 'CHECKPOINT'",
+"Prekinuta konekcija broj %ld ka bazi: '%-.64s' korisnik je bio: '%-.32s' a host: `%-.64s' (%-.64s)",
+"Handler tabele ne podržava binarni dump tabele",
+"Binarni log file zatvoren, ne mogu da izvršim komandu 'RESET MASTER'",
+"Izgradnja indeksa dump-ovane tabele '%-.64s' nije uspela",
+"Greška iz glavnog servera '%-.64s' u klasteru",
+"Greška u primanju mrežnih paketa sa glavnog servera u klasteru",
+"Greška u slanju mrežnih paketa na glavni server u klasteru",
+"Ne mogu da pronaðem 'FULLTEXT' indeks koli odgovara listi kolona",
+"Ne mogu da izvršim datu komandu zbog toga što su tabele zakljuèane ili je transakcija u toku",
+"Nepoznata sistemska promenljiva '%-.64'",
+"Tabela '%-.64s' je markirana kao ošteæena i trebala bi biti popravljena",
+"Tabela '%-.64s' je markirana kao ošteæena, a zadnja (automatska?) popravka je bila neuspela",
+"Upozorenje: Neke izmenjene tabele ne podržavaju komandu 'ROLLBACK'",
+"Transakcija sa više stavki zahtevala je više od 'max_binlog_cache_size' bajtova skladišnog prostora. Uveæajte ovu promenljivu servera i pokušajte ponovo',
+"Ova operacija ne može biti izvršena dok je aktivan podreðeni server. Zadajte prvo komandu 'SLAVE STOP' da zaustavite podreðeni server.",
+"Ova operacija zahteva da je aktivan podreðeni server. Konfigurišite prvo podreðeni server i onda izvršite komandu 'SLAVE START'",
+"Server nije konfigurisan kao podreðeni server, ispravite konfiguracioni file ili na njemu izvršite komandu 'CHANGE MASTER TO'",
+"Nisam mogao da inicijalizujem informacionu strukturu glavnog servera, proverite da li imam privilegije potrebne za pristup file-u 'master.info'",
+"Nisam mogao da startujem thread za podreðeni server, proverite sistemske resurse",
+"Korisnik %-.64s veæ ima više aktivnih konekcija nego što je to odreðeno 'max_user_connections' promenljivom",
+"Možete upotrebiti samo konstantan iskaz sa komandom 'SET'",
+"Vremenski limit za zakljuèavanje tabele je istekao; Probajte da ponovo startujete transakciju",
+"Broj totalnih zakljuèavanja tabele premašuje velièinu tabele zakljuèavanja",
+"Zakljuèavanja izmena ne mogu biti realizovana sve dok traje 'READ UNCOMMITTED' transakcija",
+"Komanda 'DROP DATABASE' nije dozvoljena dok thread globalno zakljuèava èitanje podataka",
+"Komanda 'CREATE DATABASE' nije dozvoljena dok thread globalno zakljuèava èitanje podataka",
+"Pogrešni argumenti prosleðeni na %s",
+"Korisniku %-.32s@%-.64s nije dozvoljeno da kreira nove korisnike",
+"Pogrešna definicija tabele; Sve 'MERGE' tabele moraju biti u istoj bazi podataka",
+"Unakrsno zakljuèavanje pronaðeno kada sam pokušao da dobijem pravo na zakljuèavanje; Probajte da restartujete transakciju",
+"Upotrebljeni tip tabele ne podržava 'FULLTEXT' indekse",
+"Ne mogu da dodam proveru spoljnog kljuèa",
+"Ne mogu da dodam slog: provera spoljnog kljuèa je neuspela",
+"Ne mogu da izbrišem roditeljski slog: provera spoljnog kljuèa je neuspela",
+"Greška pri povezivanju sa glavnim serverom u klasteru: %-.128s",
+"Greška pri izvršavanju upita na glavnom serveru u klasteru: %-.128s",
+"Greška pri izvršavanju komande %s: %-.128s",
+"Pogrešna upotreba %s i %s",
+"Upotrebljene 'SELECT' komande adresiraju razlièit broj kolona",
+"Ne mogu da izvršim upit zbog toga što imate zakljuèavanja èitanja podataka u konfliktu",
+"Mešanje tabela koje podržavaju transakcije i onih koje ne podržavaju transakcije je iskljuèeno",
+"Opcija '%s' je upotrebljena dva puta u istom iskazu",
+"User '%-.64s' has exceeded the '%s' resource (current value: %ld)",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/slovak/errmsg.txt b/sql/share/slovak/errmsg.txt
index 2e14be90bc0..9912e4c9191 100644
--- a/sql/share/slovak/errmsg.txt
+++ b/sql/share/slovak/errmsg.txt
@@ -246,3 +246,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/spanish/errmsg.txt b/sql/share/spanish/errmsg.txt
index fb1ab3c9b7d..118970141bc 100644
--- a/sql/share/spanish/errmsg.txt
+++ b/sql/share/spanish/errmsg.txt
@@ -239,3 +239,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/swedish/errmsg.txt b/sql/share/swedish/errmsg.txt
index 1a352f16225..f6553f247b6 100644
--- a/sql/share/swedish/errmsg.txt
+++ b/sql/share/swedish/errmsg.txt
@@ -238,3 +238,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"Subselect return more than 1 field",
+"Subselect return more than 1 record",
diff --git a/sql/share/ukrainian/errmsg.txt b/sql/share/ukrainian/errmsg.txt
index 3a8a1abc429..e37fae8f923 100644
--- a/sql/share/ukrainian/errmsg.txt
+++ b/sql/share/ukrainian/errmsg.txt
@@ -243,3 +243,7 @@
"Wrong usage/placement of '%s'",
"This version of MySQL doesn't yet support '%s'",
"Got fatal error %d: '%-.128s' from master when reading data from binary log",
+"Wrong foreign key definition for '%-.64s': %s",
+"Key reference and table reference doesn't match",
+"ðiÄÚÁÐÉÔ ÐÏ×ÅÒÔÁ¤ ÂiÌØÛ ÎiÖ 1 ÓÔÏ×ÂÅÃØ",
+"ðiÄÚÁÐÉÔ ÐÏ×ÅÒÔÁ¤ ÂiÌØÛ ÎiÖ 1 ÚÁÐÉÓ",
diff --git a/sql/slave.cc b/sql/slave.cc
index 27e9030c000..01f6233a2e0 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -289,9 +289,9 @@ void init_slave_skip_errors(const char* arg)
exit(1);
}
use_slave_mask = 1;
- for (;isspace(*arg);++arg)
+ for (;my_isspace(system_charset_info,*arg);++arg)
/* empty */;
- if (!my_casecmp(arg,"all",3))
+ if (!my_strncasecmp(system_charset_info,arg,"all",3))
{
bitmap_set_all(&slave_error_mask);
return;
@@ -303,7 +303,7 @@ void init_slave_skip_errors(const char* arg)
break;
if (err_code < MAX_SLAVE_ERROR)
bitmap_set_bit(&slave_error_mask,(uint)err_code);
- while (!isdigit(*p) && *p)
+ while (!my_isdigit(system_charset_info,*p) && *p)
p++;
}
}
@@ -554,7 +554,7 @@ int start_slave_threads(bool need_slave_mutex, bool wait_for_start,
void init_table_rule_hash(HASH* h, bool* h_inited)
{
- hash_init(h, TABLE_RULE_HASH_SIZE,0,0,
+ hash_init(h, system_charset_info,TABLE_RULE_HASH_SIZE,0,0,
(hash_get_key) get_table_key,
(void (*)(void*)) free_table_ent, 0);
*h_inited = 1;
@@ -576,7 +576,8 @@ static TABLE_RULE_ENT* find_wild(DYNAMIC_ARRAY *a, const char* key, int len)
{
TABLE_RULE_ENT* e ;
get_dynamic(a, (gptr)&e, i);
- if (!wild_case_compare(key, key_end, (const char*)e->db,
+ if (!wild_case_compare(system_charset_info, key, key_end,
+ (const char*)e->db,
(const char*)(e->db + e->key_len),'\\'))
return e;
}
@@ -1182,9 +1183,11 @@ static bool wait_for_relay_log_space(RELAY_LOG_INFO* rli)
THD* thd = mi->io_thd;
DBUG_ENTER("wait_for_relay_log_space");
+
pthread_mutex_lock(&rli->log_space_lock);
save_proc_info = thd->proc_info;
thd->proc_info = "Waiting for relay log space to free";
+
while (rli->log_space_limit < rli->log_space_total &&
!(slave_killed=io_slave_killed(thd,mi)))
{
diff --git a/sql/spatial.cc b/sql/spatial.cc
new file mode 100644
index 00000000000..b21d30e4b53
--- /dev/null
+++ b/sql/spatial.cc
@@ -0,0 +1,1442 @@
+#include "mysql_priv.h"
+
+
+#define MAX_DIGITS_IN_DOUBLE 16
+
+/***************************** GClassInfo *******************************/
+
+#define IMPLEMENT_GEOM(class_name, type_id, name) \
+{ \
+ (GF_InitFromText) &class_name::init_from_text, \
+ (GF_GetDataAsText) &class_name::get_data_as_text, \
+ (GF_GetDataSize) &class_name::get_data_size, \
+ (GF_GetMBR) &class_name::get_mbr, \
+ (GF_GetD) &class_name::get_x, \
+ (GF_GetD) &class_name::get_y, \
+ (GF_GetD) &class_name::length, \
+ (GF_GetD) &class_name::area, \
+ (GF_GetI) &class_name::is_closed, \
+ (GF_GetUI) &class_name::num_interior_ring, \
+ (GF_GetUI) &class_name::num_points, \
+ (GF_GetUI) &class_name::num_geometries, \
+ (GF_GetUI) &class_name::dimension, \
+ (GF_GetWS) &class_name::start_point, \
+ (GF_GetWS) &class_name::end_point, \
+ (GF_GetWS) &class_name::exterior_ring, \
+ (GF_GetWS) &class_name::centroid, \
+ (GF_GetUIWS) &class_name::point_n, \
+ (GF_GetUIWS) &class_name::interior_ring_n, \
+ (GF_GetUIWS) &class_name::geometry_n, \
+ class_name::type_id, \
+ name, \
+ NULL \
+},
+
+
+static Geometry::GClassInfo ci_collection[] =
+{
+ IMPLEMENT_GEOM(GPoint, wkbPoint, "POINT")
+ IMPLEMENT_GEOM(GLineString, wkbLineString, "LINESTRING")
+ IMPLEMENT_GEOM(GPolygon, wkbPolygon, "POLYGON")
+ IMPLEMENT_GEOM(GMultiPoint, wkbMultiPoint, "MULTIPOINT")
+ IMPLEMENT_GEOM(GMultiLineString, wkbMultiLineString, "MULTILINESTRING")
+ IMPLEMENT_GEOM(GMultiPolygon, wkbMultiPolygon, "MULTIPOLYGON")
+ IMPLEMENT_GEOM(GGeometryCollection, wkbGeometryCollection, "GEOMETRYCOLLECTION")
+};
+
+static Geometry::GClassInfo *ci_collection_end = ci_collection + sizeof(ci_collection);
+
+/***************************** Geometry *******************************/
+
+Geometry::GClassInfo *Geometry::find_class(int type_id)
+{
+ for (GClassInfo *cur_rt = ci_collection; cur_rt < ci_collection_end; ++cur_rt)
+ {
+ if (cur_rt->m_type_id == type_id)
+ {
+ return cur_rt;
+ }
+ }
+ return NULL;
+}
+
+Geometry::GClassInfo *Geometry::find_class(const char *name, size_t len)
+{
+ for (GClassInfo *cur_rt = ci_collection;
+ cur_rt < ci_collection_end; ++cur_rt)
+ {
+ if ((cur_rt->m_name[len] == 0) &&
+ (strncmp(cur_rt->m_name, name, len) == 0))
+ {
+ return cur_rt;
+ }
+ }
+ return NULL;
+}
+
+int Geometry::create_from_wkb(const char *data, uint32 data_len)
+{
+ uint32 geom_type;
+
+ if (data_len < 1+4)
+ return 1;
+ data += sizeof(char);
+
+//FIXME: check byte ordering
+ geom_type = uint4korr(data);
+ data += 4;
+ m_vmt = find_class(geom_type);
+ if (!m_vmt) return -1;
+ m_data = data;
+ m_data_end = data + data_len;
+ return 0;
+}
+
+int Geometry::create_from_wkt(GTextReadStream *trs, String *wkt, int init_stream)
+{
+ int name_len;
+ const char *name = trs->get_next_word(&name_len);
+ if (!name)
+ {
+ trs->set_error_msg("Geometry name expected");
+ return -1;
+ }
+ if (!(m_vmt = find_class(name, name_len)))
+ return -1;
+ if (wkt->reserve(1 + 4, 512))
+ return 1;
+ wkt->q_append((char)wkbNDR);
+ wkt->q_append((uint32)get_class_info()->m_type_id);
+ if (trs->get_next_symbol() != '(')
+ {
+ trs->set_error_msg("'(' expected");
+ return -1;
+ }
+ if (init_from_text(trs, wkt)) return 1;
+ if (trs->get_next_symbol() != ')')
+ {
+ trs->set_error_msg("')' expected");
+ return -1;
+ }
+ if (init_stream)
+ {
+ init_from_wkb(wkt->ptr(), wkt->length());
+ shift_wkb_header();
+ }
+ return 0;
+}
+
+int Geometry::envelope(String *result) const
+{
+ MBR mbr;
+
+ get_mbr(&mbr);
+
+ if (result->reserve(1+4*3+sizeof(double)*10))
+ return 1;
+
+ result->q_append((char)wkbNDR);
+ result->q_append((uint32)wkbPolygon);
+ result->q_append((uint32)1);
+ result->q_append((uint32)5);
+ result->q_append(mbr.xmin);
+ result->q_append(mbr.ymin);
+ result->q_append(mbr.xmax);
+ result->q_append(mbr.ymin);
+ result->q_append(mbr.xmax);
+ result->q_append(mbr.ymax);
+ result->q_append(mbr.xmin);
+ result->q_append(mbr.ymax);
+ result->q_append(mbr.xmin);
+ result->q_append(mbr.ymin);
+
+ return 0;
+}
+
+/***************************** Point *******************************/
+
+size_t GPoint::get_data_size() const
+{
+ return POINT_DATA_SIZE;
+}
+
+int GPoint::init_from_text(GTextReadStream *trs, String *wkb)
+{
+ double x, y;
+ if (wkb->reserve(sizeof(double)*2))
+ return 1;
+ if (trs->get_next_number(&x))
+ return 1;
+ if (trs->get_next_number(&y))
+ return 1;
+ wkb->q_append(x);
+ wkb->q_append(y);
+
+ return 0;
+}
+
+int GPoint::get_data_as_text(String *txt) const
+{
+ double x, y;
+ if (get_xy(&x, &y))
+ return 1;
+ if (txt->reserve(MAX_DIGITS_IN_DOUBLE * 2 + 1))
+ return 1;
+ txt->qs_append(x);
+ txt->qs_append(' ');
+ txt->qs_append(y);
+ return 0;
+}
+
+int GPoint::get_mbr(MBR *mbr) const
+{
+ double x, y;
+ if (get_xy(&x, &y))
+ return 1;
+ mbr->add_xy(x, y);
+ return 0;
+}
+
+/***************************** LineString *******************************/
+
+size_t GLineString::get_data_size() const
+{
+ uint32 n_points = uint4korr(m_data);
+
+ return 4 + n_points*POINT_DATA_SIZE;
+}
+
+int GLineString::init_from_text(GTextReadStream *trs, String *wkb)
+{
+ uint32 n_points = 0;
+ int np_pos = wkb->length();
+ GPoint p;
+
+ if (wkb->reserve(4, 512))
+ return 1;
+
+ wkb->q_append((uint32)n_points);
+
+ for (;;)
+ {
+ if (p.init_from_text(trs, wkb))
+ return 1;
+ ++n_points;
+ if (trs->get_next_toc_type() == GTextReadStream::comma)
+ trs->get_next_symbol();
+ else break;
+ }
+
+ if (n_points<2)
+ {
+ trs->set_error_msg("Too few points in LINESTRING");
+ return 1;
+ }
+
+ wkb->WriteAtPosition(np_pos, n_points);
+
+ return 0;
+}
+
+int GLineString::get_data_as_text(String *txt) const
+{
+ uint32 n_points;
+ const char *data = m_data;
+
+ if (no_data(data, 4))
+ return 1;
+
+ n_points = uint4korr(data);
+ data += 4;
+
+ if (no_data(data, sizeof(double) * 2 * n_points))
+ return 1;
+
+ if (txt->reserve(((MAX_DIGITS_IN_DOUBLE + 1)*2 + 1) * n_points))
+ return 1;
+ for (; n_points>0; --n_points)
+ {
+ double x, y;
+ float8get(x, data);
+ data += sizeof(double);
+ float8get(y, data);
+ data += sizeof(double);
+ txt->qs_append(x);
+ txt->qs_append(' ');
+ txt->qs_append(y);
+ txt->qs_append(',');
+ }
+ txt->length(txt->length() - 1);
+ return 0;
+}
+
+int GLineString::get_mbr(MBR *mbr) const
+{
+ uint32 n_points;
+ const char *data = m_data;
+
+ if (no_data(data, 4))
+ return 1;
+
+ n_points = uint4korr(data);
+ data += 4;
+
+ if (no_data(data, sizeof(double) * 2 * n_points))
+ return 1;
+ for (; n_points>0; --n_points)
+ {
+ mbr->add_xy(data, data + 8);
+ data += 8+8;
+ }
+
+ return 0;
+}
+
+int GLineString::length(double *len) const
+{
+ uint32 n_points;
+ double prev_x, prev_y;
+ const char *data = m_data;
+
+ *len=0;
+ if (no_data(data, 4))
+ return 1;
+ n_points = uint4korr(data);
+ data += 4;
+
+ if (no_data(data, sizeof(double) * 2 * n_points))
+ return 1;
+
+ --n_points;
+ float8get(prev_x, data);
+ data += 8;
+ float8get(prev_y, data);
+ data += 8;
+
+ for (; n_points>0; --n_points)
+ {
+ double x, y;
+ float8get(x, data);
+ data += 8;
+ float8get(y, data);
+ data += 8;
+ *len+=sqrt(pow(prev_x-x,2)+pow(prev_y-y,2));
+ prev_x=x;
+ prev_y=y;
+ }
+ return 0;
+}
+
+int GLineString::is_closed(int *closed) const
+
+{
+ uint32 n_points;
+ double x1, y1, x2, y2;
+
+ const char *data = m_data;
+
+ if (no_data(data, 4))
+ return 1;
+ n_points = uint4korr(data);
+ data += 4;
+ if (no_data(data, (8+8) * n_points))
+ return 1;
+ float8get(x1, data);
+ data += 8;
+ float8get(y1, data);
+ data += 8 + (n_points-2)*POINT_DATA_SIZE;
+ float8get(x2, data);
+ data += 8;
+ float8get(y2, data);
+
+ *closed=(x1==x2)&&(y1==y2);
+
+ return 0;
+}
+
+int GLineString::num_points(uint32 *n_points) const
+{
+ *n_points = uint4korr(m_data);
+ return 0;
+}
+
+int GLineString::start_point(String *result) const
+{
+ const char *data = m_data + 4;
+ if (no_data(data, 8+8))
+ return 1;
+
+ if (result->reserve(1 + 4 + sizeof(double) * 2))
+ return 1;
+
+ result->q_append((char)wkbNDR);
+ result->q_append((uint32)wkbPoint);
+ result->q_append((double *)data);
+ result->q_append((double *)(data + 8));
+
+ return 0;
+}
+
+int GLineString::end_point(String *result) const
+{
+ const char *data = m_data;
+ uint32 n_points;
+
+ if (no_data(data, 4))
+ return 1;
+ n_points = uint4korr(data);
+
+ data += 4 + (n_points-1)*POINT_DATA_SIZE;
+
+ if (no_data(data, 8+8))
+ return 1;
+
+ if (result->reserve(1 + 4 + sizeof(double) * 2))
+ return 1;
+ result->q_append((char)wkbNDR);
+ result->q_append((uint32)wkbPoint);
+ result->q_append((double *)data);
+ result->q_append((double *)(data + 8));
+
+ return 0;
+}
+
+
+int GLineString::point_n(uint32 num, String *result) const
+{
+ const char *data = m_data;
+ uint32 n_points;
+
+ if (no_data(data, 4))
+ return 1;
+ n_points = uint4korr(data);
+
+ if ((uint32)(num-1) >= n_points) // really means (num > n_points || num < 1)
+ return 1;
+
+ data += 4 + (num - 1)*POINT_DATA_SIZE;
+
+ if (no_data(data, 8+8))
+ return 1;
+ if (result->reserve(1 + 4 + sizeof(double) * 2))
+ return 1;
+
+ result->q_append((char)wkbNDR);
+ result->q_append((uint32)wkbPoint);
+ result->q_append((double *)data);
+ result->q_append((double *)(data + 8));
+
+ return 0;
+}
+
+/***************************** Polygon *******************************/
+
+size_t GPolygon::get_data_size() const
+{
+ uint32 n_linear_rings = 0;
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+
+ n_linear_rings = uint4korr(data);
+ data += 4;
+ for (; n_linear_rings>0; --n_linear_rings)
+ {
+ if (no_data(data, 4))
+ return 1;
+ data += 4 + uint4korr(data)*POINT_DATA_SIZE;
+ }
+ return data - m_data;
+}
+
+int GPolygon::init_from_text(GTextReadStream *trs, String *wkb)
+{
+ uint32 n_linear_rings = 0;
+ int lr_pos = wkb->length();
+
+ if (wkb->reserve(4, 512))
+ return 1;
+
+ wkb->q_append((uint32)n_linear_rings);
+
+ for (;;)
+ {
+ GLineString ls;
+ size_t ls_pos=wkb->length();
+ if (trs->get_next_symbol() != '(')
+ {
+ trs->set_error_msg("'(' expected");
+ return 1;
+ }
+ if (ls.init_from_text(trs, wkb))
+ return 1;
+ if (trs->get_next_symbol() != ')')
+ {
+ trs->set_error_msg("')' expected");
+ return 1;
+ }
+ ls.init_from_wkb(wkb->ptr()+ls_pos, wkb->length()-ls_pos);
+ int closed;
+ ls.is_closed(&closed);
+ if (!closed)
+ {
+ trs->set_error_msg("POLYGON's linear ring isn't closed");
+ return 1;
+ }
+ ++n_linear_rings;
+ if (trs->get_next_toc_type() == GTextReadStream::comma)
+ trs->get_next_symbol();
+ else
+ break;
+ }
+ wkb->WriteAtPosition(lr_pos, n_linear_rings);
+ return 0;
+}
+
+int GPolygon::get_data_as_text(String *txt) const
+{
+ uint32 n_linear_rings;
+ const char *data = m_data;
+
+ if (no_data(data, 4))
+ return 1;
+
+ n_linear_rings = uint4korr(data);
+ data += 4;
+
+ for (; n_linear_rings>0; --n_linear_rings)
+ {
+ if(no_data(data, 4))
+ return 1;
+ uint32 n_points = uint4korr(data);
+ data += 4;
+ if (no_data(data, (8+8) * n_points))
+ return 1;
+
+ if (txt->reserve(2 + ((MAX_DIGITS_IN_DOUBLE + 1)*2 + 1) * n_points))
+ return 1;
+ txt->qs_append('(');
+ for (; n_points>0; --n_points)
+ {
+ txt->qs_append((double *)data);
+ txt->qs_append(' ');
+ txt->qs_append((double *)(data + 8));
+ txt->qs_append(',');
+
+ data += 8+8;
+ }
+ (*txt)[txt->length()-1] = ')';
+ txt->qs_append(',');
+ }
+ txt->length(txt->length() - 1);
+ return 0;
+}
+
+int GPolygon::get_mbr(MBR *mbr) const
+{
+ uint32 n_linear_rings;
+
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_linear_rings = uint4korr(data);
+ data += 4;
+ for (; n_linear_rings>0; --n_linear_rings)
+ {
+ if (no_data(data, 4))
+ return 1;
+ uint32 n_points = uint4korr(data);
+ data += 4;
+ if (no_data(data, (8+8) * n_points))
+ return 1;
+ for (; n_points>0; --n_points)
+ {
+ mbr->add_xy(data, data + 8);
+ data += 8+8;
+ }
+ }
+ return 0;
+}
+
+int GPolygon::area(double *ar) const
+{
+ uint32 n_linear_rings;
+ double result = -1.0;
+
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_linear_rings = uint4korr(data);
+ data += 4;
+ for (; n_linear_rings>0; --n_linear_rings)
+ {
+ double prev_x, prev_y;
+ double lr_area=0;
+ if (no_data(data, 4))
+ return 1;
+ uint32 n_points = uint4korr(data);
+ if (no_data(data, (8+8) * n_points))
+ return 1;
+ float8get(prev_x, data+4);
+ float8get(prev_y, data+(4+8));
+ data += (4+8+8);
+
+ --n_points;
+ for (; n_points>0; --n_points)
+ {
+ double x, y;
+ float8get(x, data);
+ float8get(y, data + 8);
+ lr_area+=(prev_x+x)*(prev_y-y);
+ prev_x=x;
+ prev_y=y;
+ data += (8+8);
+ }
+ lr_area=fabs(lr_area)/2;
+ if(result==-1) result=lr_area;
+ else result-=lr_area;
+ }
+ *ar=fabs(result);
+ return 0;
+}
+
+
+int GPolygon::exterior_ring(String *result) const
+{
+ uint32 n_points;
+ const char *data = m_data + 4; // skip n_linerings
+
+ if (no_data(data, 4))
+ return 1;
+ n_points = uint4korr(data);
+ data += 4;
+ if (no_data(data, n_points * POINT_DATA_SIZE))
+ return 1;
+
+ if (result->reserve(1+4+4+ n_points * POINT_DATA_SIZE))
+ return 1;
+
+ result->q_append((char)wkbNDR);
+ result->q_append((uint32)wkbLineString);
+ result->q_append(n_points);
+ result->q_append(data, n_points * POINT_DATA_SIZE);
+
+ return 0;
+}
+
+int GPolygon::num_interior_ring(uint32 *n_int_rings) const
+{
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ *n_int_rings = uint4korr(data);
+ --(*n_int_rings);
+
+ return 0;
+}
+
+int GPolygon::interior_ring_n(uint32 num, String *result) const
+{
+ const char *data = m_data;
+ uint32 n_linear_rings;
+ uint32 n_points;
+
+ if (no_data(data, 4))
+ return 1;
+
+ n_linear_rings = uint4korr(data);
+ data += 4;
+ if ((num >= n_linear_rings) || (num < 1))
+ return -1;
+
+ for (; num > 0; --num)
+ {
+ if (no_data(data, 4))
+ return 1;
+ data += 4 + uint4korr(data) * POINT_DATA_SIZE;
+ }
+ if (no_data(data, 4))
+ return 1;
+ n_points = uint4korr(data);
+ int points_size = n_points * POINT_DATA_SIZE;
+ data += 4;
+ if (no_data(data, points_size))
+ return 1;
+
+ if (result->reserve(1+4+4+ points_size))
+ return 1;
+
+ result->q_append((char)wkbNDR);
+ result->q_append((uint32)wkbLineString);
+ result->q_append(n_points);
+ result->q_append(data, points_size);
+
+ return 0;
+}
+
+int GPolygon::centroid_xy(double *x, double *y) const
+{
+ uint32 n_linear_rings;
+ uint32 i;
+ double res_area, res_cx, res_cy;
+ const char *data = m_data;
+ LINT_INIT(res_area);
+ LINT_INIT(res_cx);
+ LINT_INIT(res_cy);
+
+ if (no_data(data, 4))
+ return 1;
+ n_linear_rings = uint4korr(data);
+ data += 4;
+
+ for (i = 0; i < n_linear_rings; ++i)
+ {
+ if (no_data(data, 4))
+ return 1;
+ uint32 n_points = uint4korr(data);
+ double prev_x, prev_y;
+ double cur_area = 0;
+ double cur_cx = 0;
+ double cur_cy = 0;
+
+ data += 4;
+ if (no_data(data, (8+8) * n_points))
+ return 1;
+ float8get(prev_x, data);
+ float8get(prev_y, data+8);
+ data += (8+8);
+
+ uint32 n = n_points - 1;
+ for (; n > 0; --n)
+ {
+ double x, y;
+ float8get(x, data);
+ float8get(y, data + 8);
+
+ cur_area += (prev_x + x) * (prev_y - y);
+ cur_cx += x;
+ cur_cy += y;
+ prev_x = x;
+ prev_y = y;
+ data += (8+8);
+ }
+ cur_area = fabs(cur_area) / 2;
+ cur_cx = cur_cx / (n_points - 1);
+ cur_cy = cur_cy / (n_points - 1);
+
+ if (i)
+ {
+ double d_area = res_area - cur_area;
+ if (d_area <= 0)
+ return 1;
+ res_cx = (res_area * res_cx - cur_area * cur_cx) / d_area;
+ res_cy = (res_area * res_cy - cur_area * cur_cy) / d_area;
+ }
+ else
+ {
+ res_area = cur_area;
+ res_cx = cur_cx;
+ res_cy = cur_cy;
+ }
+ }
+
+ *x = res_cx;
+ *y = res_cy;
+
+ return 0;
+}
+
+int GPolygon::centroid(String *result) const
+{
+ double x, y;
+
+ this->centroid_xy(&x, &y);
+ if (result->reserve(1 + 4 + sizeof(double) * 2))
+ return 1;
+
+ result->q_append((char)wkbNDR);
+ result->q_append((uint32)wkbPoint);
+ result->q_append(x);
+ result->q_append(y);
+
+ return 0;
+}
+
+
+/***************************** MultiPoint *******************************/
+
+size_t GMultiPoint::get_data_size() const
+{
+ return 4 + uint4korr(m_data)*(POINT_DATA_SIZE + WKB_HEADER_SIZE);
+}
+
+int GMultiPoint::init_from_text(GTextReadStream *trs, String *wkb)
+{
+ uint32 n_points = 0;
+ int np_pos = wkb->length();
+ GPoint p;
+
+ if (wkb->reserve(4, 512))
+ return 1;
+ wkb->q_append((uint32)n_points);
+
+ for (;;)
+ {
+ if (wkb->reserve(1+4, 512))
+ return 1;
+ wkb->q_append((char)wkbNDR);
+ wkb->q_append((uint32)wkbPoint);
+ if (p.init_from_text(trs, wkb))
+ return 1;
+ ++n_points;
+ if (trs->get_next_toc_type() == GTextReadStream::comma)
+ trs->get_next_symbol();
+ else
+ break;
+ }
+ wkb->WriteAtPosition(np_pos, n_points);
+
+ return 0;
+}
+
+int GMultiPoint::get_data_as_text(String *txt) const
+{
+ uint32 n_points;
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+
+ n_points = uint4korr(data);
+ data += 4;
+ if (no_data(data, n_points * (8+8+WKB_HEADER_SIZE)))
+ return 1;
+
+ if (txt->reserve(((MAX_DIGITS_IN_DOUBLE + 1)*2 + 1) * n_points))
+ return 1;
+
+ for (; n_points>0; --n_points)
+ {
+ txt->qs_append((double *)(data + WKB_HEADER_SIZE));
+ txt->qs_append(' ');
+ txt->qs_append((double *)(data + (8 + WKB_HEADER_SIZE)));
+ txt->qs_append(',');
+ data += 8+8+WKB_HEADER_SIZE;
+ }
+ txt->length(txt->length()-1);
+ return 0;
+}
+
+int GMultiPoint::get_mbr(MBR *mbr) const
+{
+ uint32 n_points;
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_points = uint4korr(data);
+ data += 4;
+ if (no_data(data, n_points * (8+8+WKB_HEADER_SIZE)))
+ return 1;
+ for (; n_points>0; --n_points)
+ {
+ mbr->add_xy(data + WKB_HEADER_SIZE, data + 8 + WKB_HEADER_SIZE);
+ data += (8+8+WKB_HEADER_SIZE);
+ }
+ return 0;
+}
+
+/***************************** MultiLineString *******************************/
+
+size_t GMultiLineString::get_data_size() const
+{
+ uint32 n_line_strings = 0;
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_line_strings = uint4korr(data);
+ data += 4;
+
+ for (; n_line_strings>0; --n_line_strings)
+ {
+ if (no_data(data, WKB_HEADER_SIZE + 4))
+ return 1;
+ data += WKB_HEADER_SIZE + 4 + uint4korr(data + WKB_HEADER_SIZE) * POINT_DATA_SIZE;
+ }
+ return data - m_data;
+}
+
+int GMultiLineString::init_from_text(GTextReadStream *trs, String *wkb)
+{
+ uint32 n_line_strings = 0;
+ int ls_pos = wkb->length();
+
+ if (wkb->reserve(4, 512))
+ return 1;
+
+ wkb->q_append((uint32)n_line_strings);
+
+ for (;;)
+ {
+ GLineString ls;
+
+ if (wkb->reserve(1+4, 512))
+ return 1;
+ wkb->q_append((char)wkbNDR);
+ wkb->q_append((uint32)wkbLineString);
+
+ if (trs->get_next_symbol() != '(')
+ {
+ trs->set_error_msg("'(' expected");
+ return 1;
+ }
+ if (ls.init_from_text(trs, wkb))
+ return 1;
+
+ if (trs->get_next_symbol() != ')')
+ {
+ trs->set_error_msg("')' expected");
+ return 1;
+ }
+ ++n_line_strings;
+ if (trs->get_next_toc_type() == GTextReadStream::comma)
+ trs->get_next_symbol();
+ else
+ break;
+ }
+ wkb->WriteAtPosition(ls_pos, n_line_strings);
+
+ return 0;
+}
+
+int GMultiLineString::get_data_as_text(String *txt) const
+{
+ uint32 n_line_strings;
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_line_strings = uint4korr(data);
+ data += 4;
+ for (; n_line_strings>0; --n_line_strings)
+ {
+ if (no_data(data, (WKB_HEADER_SIZE + 4)))
+ return 1;
+ uint32 n_points = uint4korr(data + WKB_HEADER_SIZE);
+ data += WKB_HEADER_SIZE + 4;
+ if (no_data(data, n_points * (8+8)))
+ return 1;
+
+ if (txt->reserve(2 + ((MAX_DIGITS_IN_DOUBLE + 1)*2 + 1) * n_points))
+ return 1;
+ txt->qs_append('(');
+ for (; n_points>0; --n_points)
+ {
+ txt->qs_append((double *)data);
+ txt->qs_append(' ');
+ txt->qs_append((double *)(data + 8));
+ txt->qs_append(',');
+ data += 8+8;
+ }
+ (*txt)[txt->length()-1] = ')';
+ txt->qs_append(',');
+ }
+ txt->length(txt->length() - 1);
+ return 0;
+}
+
+int GMultiLineString::get_mbr(MBR *mbr) const
+{
+ uint32 n_line_strings;
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_line_strings = uint4korr(data);
+ data += 4;
+
+ for (; n_line_strings>0; --n_line_strings)
+ {
+ if (no_data(data, WKB_HEADER_SIZE + 4))
+ return 1;
+ uint32 n_points = uint4korr(data + WKB_HEADER_SIZE);
+ data += 4+WKB_HEADER_SIZE;
+ if (no_data(data, (8+8)*n_points))
+ return 1;
+
+ for (; n_points>0; --n_points)
+ {
+ mbr->add_xy(data, data + 8);
+ data += 8+8;
+ }
+ }
+ return 0;
+}
+
+int GMultiLineString::length(double *len) const
+{
+ uint32 n_line_strings;
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_line_strings = uint4korr(data);
+ data += 4;
+ *len=0;
+ for (; n_line_strings>0; --n_line_strings)
+ {
+ double ls_len;
+ GLineString ls;
+ data += WKB_HEADER_SIZE;
+ ls.init_from_wkb(data, m_data_end - data);
+ if (ls.length(&ls_len))
+ return 1;
+ *len+=ls_len;
+ data += ls.get_data_size();
+ }
+ return 0;
+}
+
+int GMultiLineString::is_closed(int *closed) const
+{
+ uint32 n_line_strings;
+ const char *data = m_data;
+ if (no_data(data, 1))
+ return 1;
+ n_line_strings = uint4korr(data);
+ data += 4 + WKB_HEADER_SIZE;
+ for (; n_line_strings>0; --n_line_strings)
+ {
+ GLineString ls;
+ ls.init_from_wkb(data, m_data_end - data);
+ if (ls.is_closed(closed))
+ return 1;
+ if (!*closed)
+ return 0;
+ data += ls.get_data_size() + WKB_HEADER_SIZE;
+ }
+ return 0;
+}
+
+/***************************** MultiPolygon *******************************/
+
+size_t GMultiPolygon::get_data_size() const
+{
+ uint32 n_polygons;
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_polygons = uint4korr(data);
+ data += 4;
+
+ for (; n_polygons>0; --n_polygons)
+ {
+ if (no_data(data, 4 + WKB_HEADER_SIZE))
+ return 1;
+ uint32 n_linear_rings = uint4korr(data + WKB_HEADER_SIZE);
+ data += 4 + WKB_HEADER_SIZE;
+
+ for (; n_linear_rings > 0; --n_linear_rings)
+ {
+ data += 4 + uint4korr(data) * POINT_DATA_SIZE;
+ }
+ }
+ return data - m_data;
+}
+
+int GMultiPolygon::init_from_text(GTextReadStream *trs, String *wkb)
+{
+ uint32 n_polygons = 0;
+ int np_pos = wkb->length();
+ GPolygon p;
+
+ if (wkb->reserve(4, 512))
+ return 1;
+
+ wkb->q_append((uint32)n_polygons);
+
+ for (;;)
+ {
+ if (wkb->reserve(1+4, 512))
+ return 1;
+ wkb->q_append((char)wkbNDR);
+ wkb->q_append((uint32)wkbPolygon);
+
+ if (trs->get_next_symbol() != '(')
+ {
+ trs->set_error_msg("'(' expected");
+ return 1;
+ }
+ if (p.init_from_text(trs, wkb))
+ return 1;
+ if (trs->get_next_symbol() != ')')
+ {
+ trs->set_error_msg("')' expected");
+ return 1;
+ }
+ ++n_polygons;
+ if (trs->get_next_toc_type() == GTextReadStream::comma)
+ trs->get_next_symbol();
+ else
+ break;
+ }
+ wkb->WriteAtPosition(np_pos, n_polygons);
+ return 0;
+}
+
+int GMultiPolygon::get_data_as_text(String *txt) const
+{
+ uint32 n_polygons;
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_polygons = uint4korr(data);
+ data += 4;
+
+ for (; n_polygons>0; --n_polygons)
+ {
+ if (no_data(data, 4 + WKB_HEADER_SIZE))
+ return 1;
+ data += WKB_HEADER_SIZE;
+ uint32 n_linear_rings = uint4korr(data);
+ data += 4;
+
+ if (txt->reserve(1, 512))
+ return 1;
+ txt->q_append('(');
+ for (; n_linear_rings>0; --n_linear_rings)
+ {
+ if (no_data(data, 4))
+ return 1;
+ uint32 n_points = uint4korr(data);
+ data += 4;
+ if (no_data(data, (8+8)*n_points)) return 1;
+
+ if (txt->reserve(2 + ((MAX_DIGITS_IN_DOUBLE + 1)*2 + 1) * n_points,
+ 512)) return 1;
+ txt->qs_append('(');
+ for (; n_points>0; --n_points)
+ {
+ txt->qs_append((double *)data);
+ txt->qs_append(' ');
+ txt->qs_append((double *)(data + 8));
+ txt->qs_append(',');
+ data += 8+8;
+ }
+ (*txt)[txt->length()-1] = ')';
+ txt->qs_append(',');
+ }
+ (*txt)[txt->length()-1] = ')';
+ txt->qs_append(',');
+ }
+ txt->length(txt->length() - 1);
+ return 0;
+}
+
+int GMultiPolygon::get_mbr(MBR *mbr) const
+{
+ uint32 n_polygons;
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_polygons = uint4korr(data);
+ data += 4;
+
+ for (; n_polygons>0; --n_polygons)
+ {
+ if (no_data(data, 4+WKB_HEADER_SIZE))
+ return 1;
+ uint32 n_linear_rings = uint4korr(data + WKB_HEADER_SIZE);
+ data += WKB_HEADER_SIZE + 4;
+
+ for (; n_linear_rings>0; --n_linear_rings)
+ {
+ if (no_data(data, 4))
+ return 1;
+ uint32 n_points = uint4korr(data);
+ data += 4;
+ if (no_data(data, (8+8)*n_points))
+ return 1;
+
+ for (; n_points>0; --n_points)
+ {
+ mbr->add_xy(data, data + 8);
+ data += 8+8;
+ }
+ }
+ }
+ return 0;
+}
+
+
+int GMultiPolygon::area(double *ar) const
+{
+ uint32 n_polygons;
+ const char *data = m_data;
+ double result = 0;
+ if (no_data(data, 4))
+ return 1;
+ n_polygons = uint4korr(data);
+ data += 4;
+
+ for (; n_polygons>0; --n_polygons)
+ {
+ double p_area;
+
+ GPolygon p;
+ data += WKB_HEADER_SIZE;
+ p.init_from_wkb(data, m_data_end - data);
+ if (p.area(&p_area))
+ return 1;
+ result += p_area;
+ data += p.get_data_size();
+ }
+ *ar = result;
+ return 0;
+}
+
+int GMultiPolygon::centroid(String *result) const
+{
+ uint32 n_polygons;
+ uint i;
+ GPolygon p;
+ double res_area, res_cx, res_cy;
+ double cur_area, cur_cx, cur_cy;
+
+ LINT_INIT(res_area);
+ LINT_INIT(res_cx);
+ LINT_INIT(res_cy);
+
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_polygons = uint4korr(data);
+ data += 4;
+
+ for (i = 0; i < n_polygons; ++i)
+ {
+ data += WKB_HEADER_SIZE;
+ p.init_from_wkb(data, m_data_end - data);
+ if (p.area(&cur_area))
+ return 1;
+
+ if (p.centroid_xy(&cur_cx, &cur_cy))
+ return 1;
+
+ if (i)
+ {
+ double sum_area = res_area + cur_area;
+ res_cx = (res_area * res_cx + cur_area * cur_cx) / sum_area;
+ res_cy = (res_area * res_cy + cur_area * cur_cy) / sum_area;
+ }
+ else
+ {
+ res_area = cur_area;
+ res_cx = cur_cx;
+ res_cy = cur_cy;
+ }
+
+ data += p.get_data_size();
+ }
+
+ if (result->reserve(1 + 4 + sizeof(double) * 2))
+ return 1;
+ result->q_append((char)wkbNDR);
+ result->q_append((uint32)wkbPoint);
+ result->q_append(res_cx);
+ result->q_append(res_cy);
+
+ return 0;
+}
+
+/***************************** GeometryCollection *******************************/
+
+size_t GGeometryCollection::get_data_size() const
+{
+ uint32 n_objects;
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_objects = uint4korr(data);
+ data += 4;
+
+ for (; n_objects>0; --n_objects)
+ {
+ if (no_data(data, WKB_HEADER_SIZE))
+ return 1;
+ uint32 wkb_type = uint4korr(data + sizeof(char));
+ data += WKB_HEADER_SIZE;
+
+ Geometry geom;
+
+ if (geom.init(wkb_type))
+ return 0;
+
+ geom.init_from_wkb(data, m_data_end - data);
+ size_t object_size=geom.get_data_size();
+ data += object_size;
+ }
+ return data - m_data;
+}
+
+int GGeometryCollection::init_from_text(GTextReadStream *trs, String *wkb)
+{
+ uint32 n_objects = 0;
+ int no_pos = wkb->length();
+ Geometry g;
+
+ if (wkb->reserve(4, 512))
+ return 1;
+ wkb->q_append((uint32)n_objects);
+
+ for (;;)
+ {
+ if (g.create_from_wkt(trs, wkb))
+ return 1;
+
+ if (g.get_class_info()->m_type_id==wkbGeometryCollection)
+ {
+ trs->set_error_msg("Unexpected GEOMETRYCOLLECTION");
+ return 1;
+ }
+ ++n_objects;
+ if (trs->get_next_toc_type() == GTextReadStream::comma)
+ trs->get_next_symbol();
+ else break;
+ }
+ wkb->WriteAtPosition(no_pos, n_objects);
+
+ return 0;
+}
+
+int GGeometryCollection::get_data_as_text(String *txt) const
+{
+ uint32 n_objects;
+ const char *data = m_data;
+ Geometry geom;
+ if (no_data(data, 4))
+ return 1;
+ n_objects = uint4korr(data);
+ data += 4;
+
+ for (; n_objects>0; --n_objects)
+ {
+ if (no_data(data, WKB_HEADER_SIZE))
+ return 1;
+ uint32 wkb_type = uint4korr(data + sizeof(char));
+ data += WKB_HEADER_SIZE;
+
+ if (geom.init(wkb_type))
+ return 1;
+ geom.init_from_wkb(data, m_data_end - data);
+ if (geom.as_wkt(txt))
+ return 1;
+ data += geom.get_data_size();
+ txt->reserve(1, 512);
+ txt->q_append(',');
+ }
+ txt->length(txt->length() - 1);
+ return 0;
+}
+
+int GGeometryCollection::get_mbr(MBR *mbr) const
+{
+ uint32 n_objects;
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_objects = uint4korr(data);
+ data += 4;
+ for (; n_objects>0; --n_objects)
+ {
+ if(no_data(data, WKB_HEADER_SIZE))
+ return 1;
+ uint32 wkb_type = uint4korr(data + sizeof(char));
+ data += WKB_HEADER_SIZE;
+ Geometry geom;
+
+ if (geom.init(wkb_type))
+ return 1;
+ geom.init_from_wkb(data, m_data_end - data);
+ geom.get_mbr(mbr);
+ data += geom.get_data_size();
+ }
+ return 0;
+}
+
+int GGeometryCollection::num_geometries(uint32 *num) const
+{
+ *num = uint4korr(m_data);
+ return 0;
+}
+
+int GGeometryCollection::geometry_n(uint32 num, String *result) const
+{
+ const char *data = m_data;
+ uint32 n_objects;
+ if (no_data(data, 4))
+ return 1;
+ n_objects = uint4korr(data);
+ data += 4;
+
+ if ((num > n_objects) || (num < 1))
+ {
+ return -1;
+ }
+ for (; num > 0; --num)
+ {
+ if (no_data(data, WKB_HEADER_SIZE))
+ return 1;
+ uint32 wkb_type = uint4korr(data + sizeof(char));
+ data += WKB_HEADER_SIZE;
+
+ Geometry geom;
+ if (geom.init(wkb_type))
+ return 1;
+ geom.init_from_wkb(data, m_data_end - data);
+ if (num == 1)
+ {
+ if (result->reserve(1+4+geom.get_data_size()))
+ return 1;
+ result->q_append((char)wkbNDR);
+ result->q_append((uint32)wkb_type);
+ result->q_append(data, geom.get_data_size());
+ break;
+ }
+ else
+ {
+ data += geom.get_data_size();
+ }
+ }
+ return 0;
+}
+
+int GGeometryCollection::dimension(uint32 *dim) const
+{
+ uint32 n_objects;
+ *dim = 0;
+ const char *data = m_data;
+ if (no_data(data, 4))
+ return 1;
+ n_objects = uint4korr(data);
+ data += 4;
+
+ for (; n_objects > 0; --n_objects)
+ {
+ if (no_data(data, WKB_HEADER_SIZE))
+ return 1;
+ uint32 wkb_type = uint4korr(data + sizeof(char));
+ data += WKB_HEADER_SIZE;
+
+ uint32 d;
+
+ Geometry geom;
+ if (geom.init(wkb_type))
+ return 1;
+ geom.init_from_wkb(data, m_data_end - data);
+ if (geom.dimension(&d))
+ return 1;
+
+ if (d > *dim)
+ *dim = d;
+ data += geom.get_data_size();
+ }
+ return 0;
+}
+
+/***************************** /objects *******************************/
diff --git a/sql/spatial.h b/sql/spatial.h
new file mode 100644
index 00000000000..c6e30a44fbf
--- /dev/null
+++ b/sql/spatial.h
@@ -0,0 +1,476 @@
+#ifndef _spatial_h
+#define _spatial_h
+
+#include "gstream.h"
+
+const uint POINT_DATA_SIZE = 8+8;
+const uint WKB_HEADER_SIZE = 1+4;
+
+struct stPoint2D
+{
+ double x;
+ double y;
+};
+
+struct stLinearRing
+{
+ size_t n_points;
+ stPoint2D points;
+};
+
+/***************************** MBR *******************************/
+
+struct MBR
+{
+ MBR()
+ {
+ xmin=DBL_MAX;
+ ymin=DBL_MAX;
+ xmax=-DBL_MAX;
+ ymax=-DBL_MAX;
+ }
+
+ MBR(const double &_xmin, const double &_ymin, const double &_xmax, const double &_ymax)
+ {
+ xmin=_xmin;
+ ymin=_ymin;
+ xmax=_xmax;
+ ymax=_ymax;
+ }
+
+ MBR(const stPoint2D &min, const stPoint2D &max)
+ {
+ xmin=min.x;
+ ymin=min.y;
+ xmax=max.x;
+ ymax=max.y;
+ }
+
+ double xmin;
+ double ymin;
+ double xmax;
+ double ymax;
+
+ void add_xy(double x, double y)
+ { /* Not using "else" for proper one point MBR calculation */
+ if (x<xmin)
+ {
+ xmin=x;
+ }
+ if (x>xmax)
+ {
+ xmax=x;
+ }
+ if (y<ymin)
+ {
+ ymin=y;
+ }
+ if (y>ymax)
+ {
+ ymax=y;
+ }
+ }
+
+ void add_xy(const char *px, const char *py)
+ { /* Not using "else" for proper one point MBR calculation */
+ double x, y;
+ float8get(x, px);
+ float8get(y, py);
+ if (x<xmin)
+ {
+ xmin=x;
+ }
+ if (x>xmax)
+ {
+ xmax=x;
+ }
+ if (y<ymin)
+ {
+ ymin=y;
+ }
+ if (y>ymax)
+ {
+ ymax=y;
+ }
+ }
+
+ void add_mbr(const MBR *mbr)
+ {
+ if (mbr->xmin<xmin)
+ {
+ xmin=mbr->xmin;
+ }
+ if (mbr->xmax>xmax)
+ {
+ xmax=mbr->xmax;
+ }
+ if (mbr->ymin<ymin)
+ {
+ ymin=mbr->ymin;
+ }
+ if (mbr->ymax>ymax)
+ {
+ ymax=mbr->ymax;
+ }
+ }
+
+ int equals(const MBR *mbr)
+ {
+ return (mbr->xmin==xmin)&&(mbr->ymin==ymin)&&(mbr->xmax==xmax)&&(mbr->ymax==ymax);
+ }
+
+ int disjoint(const MBR *mbr)
+ {
+ return (mbr->xmin>xmax)||(mbr->ymin>ymax)||(mbr->xmax<xmin)||(mbr->ymax<ymin);
+ }
+
+ int intersects(const MBR *mbr)
+ {
+ return !disjoint(mbr);
+ }
+
+ int touches(const MBR *mbr)
+ {
+ return (((mbr->xmin==xmax) || (mbr->xmax==xmin)) &&
+ ((mbr->ymin>=ymin) && (mbr->ymin<=ymax) ||
+ (mbr->ymax>=ymin) && (mbr->ymax<=ymax))) ||
+ (((mbr->ymin==ymax) || (mbr->ymax==ymin)) &&
+ ((mbr->xmin>=xmin) && (mbr->xmin<=xmax) ||
+ (mbr->xmax>=xmin)&&(mbr->xmax<=xmax)));
+ }
+
+ int within(const MBR *mbr)
+ {
+ return (mbr->xmin<=xmin) && (mbr->ymin<=ymin) &&
+ (mbr->xmax>=xmax) && (mbr->ymax>=ymax);
+ }
+
+ int contains(const MBR *mbr)
+ {
+ return (mbr->xmin>=xmin) && (mbr->ymin>=ymin) &&
+ (mbr->xmax<=xmax) && (mbr->ymax<=ymax);
+ }
+
+ bool inner_point(double x, double y) const
+ {
+ return (xmin<x) && (xmax>x) && (ymin<y) && (ymax>x);
+ }
+
+ int overlaps(const MBR *mbr)
+ {
+ int lb = mbr->inner_point(xmin, ymin);
+ int rb = mbr->inner_point(xmax, ymin);
+ int rt = mbr->inner_point(xmax, ymax);
+ int lt = mbr->inner_point(xmin, ymax);
+
+ int a = lb+rb+rt+lt;
+ return (a>0) && (a<4) && (!within(mbr));
+ }
+};
+
+
+/***************************** Geometry *******************************/
+
+class Geometry;
+
+typedef int (Geometry::*GF_InitFromText)(GTextReadStream *, String *);
+typedef int (Geometry::*GF_GetDataAsText)(String *) const;
+typedef size_t (Geometry::*GF_GetDataSize)() const;
+typedef int (Geometry::*GF_GetMBR)(MBR *) const;
+
+typedef int (Geometry::*GF_GetD)(double *) const;
+typedef int (Geometry::*GF_GetI)(int *) const;
+typedef int (Geometry::*GF_GetUI)(uint32 *) const;
+typedef int (Geometry::*GF_GetWS)(String *) const;
+typedef int (Geometry::*GF_GetUIWS)(uint32, String *) const;
+
+#define GEOM_METHOD_PRESENT(geom_obj, method)\
+ (geom_obj.m_vmt->method != &Geometry::method)
+
+class Geometry
+{
+public:
+ enum wkbType
+ {
+ wkbPoint = 1,
+ wkbLineString = 2,
+ wkbPolygon = 3,
+ wkbMultiPoint = 4,
+ wkbMultiLineString = 5,
+ wkbMultiPolygon = 6,
+ wkbGeometryCollection = 7
+ };
+ enum wkbByteOrder
+ {
+ wkbXDR = 0, /* Big Endian */
+ wkbNDR = 1 /* Little Endian */
+ };
+
+
+ class GClassInfo
+ {
+ public:
+ GF_InitFromText init_from_text;
+ GF_GetDataAsText get_data_as_text;
+ GF_GetDataSize get_data_size;
+ GF_GetMBR get_mbr;
+ GF_GetD get_x;
+ GF_GetD get_y;
+ GF_GetD length;
+ GF_GetD area;
+
+ GF_GetI is_closed;
+
+ GF_GetUI num_interior_ring;
+ GF_GetUI num_points;
+ GF_GetUI num_geometries;
+ GF_GetUI dimension;
+
+ GF_GetWS start_point;
+ GF_GetWS end_point;
+ GF_GetWS exterior_ring;
+ GF_GetWS centroid;
+
+ GF_GetUIWS point_n;
+ GF_GetUIWS interior_ring_n;
+ GF_GetUIWS geometry_n;
+
+ int m_type_id;
+ const char *m_name;
+ GClassInfo *m_next_rt;
+ };
+ GClassInfo *m_vmt;
+
+ const GClassInfo *get_class_info() const { return m_vmt; }
+ size_t get_data_size() const { return (this->*m_vmt->get_data_size)(); }
+
+ int init_from_text(GTextReadStream *trs, String *wkb)
+ { return (this->*m_vmt->init_from_text)(trs, wkb); }
+
+ int get_data_as_text(String *txt) const
+ { return (this->*m_vmt->get_data_as_text)(txt); }
+
+ int get_mbr(MBR *mbr) const { return (this->*m_vmt->get_mbr)(mbr); }
+ int dimension(uint32 *dim) const
+ { return (this->*m_vmt->dimension)(dim); }
+
+ int get_x(double *x) const { return (this->*m_vmt->get_x)(x); }
+ int get_y(double *y) const { return (this->*m_vmt->get_y)(y); }
+ int length(double *len) const { return (this->*m_vmt->length)(len); }
+ int area(double *ar) const { return (this->*m_vmt->area)(ar); }
+
+ int is_closed(int *closed) const { return (this->*m_vmt->is_closed)(closed); }
+
+ int num_interior_ring(uint32 *n_int_rings) const
+ { return (this->*m_vmt->num_interior_ring)(n_int_rings); }
+ int num_points(uint32 *n_points) const
+ { return (this->*m_vmt->num_points)(n_points); }
+
+ int num_geometries(uint32 *num) const
+ { return (this->*m_vmt->num_geometries)(num); }
+
+ int start_point(String *point) const
+ { return (this->*m_vmt->start_point)(point); }
+ int end_point(String *point) const
+ { return (this->*m_vmt->end_point)(point); }
+ int exterior_ring(String *ring) const
+ { return (this->*m_vmt->exterior_ring)(ring); }
+ int centroid(String *point) const
+ { return (this->*m_vmt->centroid)(point); }
+
+ int point_n(uint32 num, String *result) const
+ { return (this->*m_vmt->point_n)(num, result); }
+ int interior_ring_n(uint32 num, String *result) const
+ { return (this->*m_vmt->interior_ring_n)(num, result); }
+ int geometry_n(uint32 num, String *result) const
+ { return (this->*m_vmt->geometry_n)(num, result); }
+
+public:
+ int create_from_wkb(const char *data, uint32 data_len);
+ int create_from_wkt(GTextReadStream *trs, String *wkt, int init_stream=1);
+ int init(int type_id)
+ {
+ m_vmt = find_class(type_id);
+ return !m_vmt;
+ }
+ int new_geometry(const char *name, size_t len)
+ {
+ m_vmt = find_class(name, len);
+ return !m_vmt;
+ }
+
+ int as_wkt(String *wkt) const
+ {
+ if(wkt->reserve(strlen(get_class_info()->m_name) + 2, 512))
+ return 1;
+ wkt->qs_append(get_class_info()->m_name);
+ wkt->qs_append('(');
+ if(get_data_as_text(wkt))
+ return 1;
+ wkt->qs_append(')');
+ return 0;
+ }
+
+ void init_from_wkb(const char *data, uint32 data_len)
+ {
+ m_data = data;
+ m_data_end = data + data_len;
+ }
+
+ void shift_wkb_header()
+ {
+ m_data += WKB_HEADER_SIZE;
+ }
+
+ int envelope(String *result) const;
+
+protected:
+ static GClassInfo *find_class(int type_id);
+ static GClassInfo *find_class(const char *name, size_t len);
+
+ bool no_data(const char *cur_data, uint32 data_amount) const
+ {
+ return cur_data + data_amount > m_data_end;
+ }
+
+ const char *m_data;
+ const char *m_data_end;
+};
+
+/***************************** Point *******************************/
+
+class GPoint: public Geometry
+{
+public:
+ size_t get_data_size() const;
+ int init_from_text(GTextReadStream *trs, String *wkb);
+ int get_data_as_text(String *txt) const;
+ int get_mbr(MBR *mbr) const;
+
+ int get_xy(double *x, double *y) const
+ {
+ const char *data = m_data;
+ if(no_data(data, sizeof(double)) * 2) return 1;
+ float8get(*x, data);
+ float8get(*y, data + sizeof(double));
+ return 0;
+ }
+
+ int get_x(double *x) const
+ {
+ if(no_data(m_data, sizeof(double))) return 1;
+ float8get(*x, m_data);
+ return 0;
+ }
+
+ int get_y(double *y) const
+ {
+ const char *data = m_data;
+ if(no_data(data, sizeof(double)) * 2) return 1;
+ float8get(*y, data + sizeof(double));
+ return 0;
+ }
+
+ int dimension(uint32 *dim) const { *dim = 0; return 0; }
+};
+
+/***************************** LineString *******************************/
+
+class GLineString: public Geometry
+{
+public:
+ size_t get_data_size() const;
+ int init_from_text(GTextReadStream *trs, String *wkb);
+ int get_data_as_text(String *txt) const;
+ int get_mbr(MBR *mbr) const;
+
+ int length(double *len) const;
+ int is_closed(int *closed) const;
+ int num_points(uint32 *n_points) const;
+ int start_point(String *point) const;
+ int end_point(String *point) const;
+ int point_n(uint32 n, String *result) const;
+ int dimension(uint32 *dim) const { *dim = 1; return 0; }
+// IsRing
+};
+
+/***************************** Polygon *******************************/
+
+class GPolygon: public Geometry
+{
+public:
+ size_t get_data_size() const;
+ int init_from_text(GTextReadStream *trs, String *wkb);
+ int get_data_as_text(String *txt) const;
+ int get_mbr(MBR *mbr) const;
+
+ int area(double *ar) const;
+ int exterior_ring(String *result) const;
+ int num_interior_ring(uint32 *n_int_rings) const;
+ int interior_ring_n(uint32 num, String *result) const;
+ int centroid_xy(double *x, double *y) const;
+ int centroid(String *result) const;
+ int dimension(uint32 *dim) const { *dim = 2; return 0; }
+// PointOnSurface
+};
+
+/***************************** MultiPoint *******************************/
+
+class GMultiPoint: public Geometry
+{
+public:
+ size_t get_data_size() const;
+ int init_from_text(GTextReadStream *trs, String *wkb);
+ int get_data_as_text(String *txt) const;
+ int get_mbr(MBR *mbr) const;
+ int dimension(uint32 *dim) const { *dim = 0; return 0; }
+};
+
+/***************************** MultiLineString *******************************/
+
+class GMultiLineString: public Geometry
+{
+public:
+ size_t get_data_size() const;
+ int init_from_text(GTextReadStream *trs, String *wkb);
+ int get_data_as_text(String *txt) const;
+ int get_mbr(MBR *mbr) const;
+
+ int length(double *len) const;
+ int is_closed(int *closed) const;
+ int dimension(uint32 *dim) const { *dim = 1; return 0; }
+};
+
+/***************************** MultiPolygon *******************************/
+
+class GMultiPolygon: public Geometry
+{
+public:
+ size_t get_data_size() const;
+ int init_from_text(GTextReadStream *trs, String *wkb);
+ int get_data_as_text(String *txt) const;
+ int get_mbr(MBR *mbr) const;
+
+ int area(double *ar) const;
+ int centroid(String *result) const;
+ int dimension(uint32 *dim) const { *dim = 2; return 0; }
+// PointOnSurface
+};
+
+/***************************** GeometryCollection *******************************/
+
+class GGeometryCollection: public Geometry
+{
+public:
+ size_t get_data_size() const;
+ int init_from_text(GTextReadStream *trs, String *wkb);
+ int get_data_as_text(String *txt) const;
+ int get_mbr(MBR *mbr) const;
+
+ int num_geometries(uint32 *num) const;
+ int geometry_n(uint32 num, String *result) const;
+
+ int dimension(uint32 *dim) const;
+};
+
+#endif
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 5e32da07aad..1069e779e86 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -429,7 +429,7 @@ static ulong get_access(TABLE *form, uint fieldnr)
{
ulong access_bits=0,bit;
char buff[2];
- String res(buff,sizeof(buff));
+ String res(buff,sizeof(buff),default_charset_info);
Field **pos;
for (pos=form->field+fieldnr, bit=1;
@@ -438,7 +438,7 @@ static ulong get_access(TABLE *form, uint fieldnr)
pos++ , bit<<=1)
{
(*pos)->val_str(&res,&res);
- if (toupper(res[0]) == 'Y')
+ if (my_toupper(system_charset_info, res[0]) == 'Y')
access_bits|= bit;
}
return access_bits;
@@ -789,7 +789,7 @@ ulong acl_get(const char *host, const char *ip, const char *bin_ip,
end=strmov((tmp_db=strmov(key+sizeof(struct in_addr),user)+1),db);
if (lower_case_table_names)
{
- casedn_str(tmp_db);
+ my_casedn_str(system_charset_info, tmp_db);
db=tmp_db;
}
key_length=(uint) (end-key);
@@ -853,7 +853,7 @@ exit:
}
-int wild_case_compare(const char *str,const char *wildstr)
+int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr)
{
reg3 int flag;
DBUG_ENTER("wild_case_compare");
@@ -864,7 +864,8 @@ int wild_case_compare(const char *str,const char *wildstr)
{
if (*wildstr == wild_prefix && wildstr[1])
wildstr++;
- if (toupper(*wildstr++) != toupper(*str++)) DBUG_RETURN(1);
+ if (my_toupper(cs, *wildstr++) !=
+ my_toupper(cs, *str++)) DBUG_RETURN(1);
}
if (! *wildstr ) DBUG_RETURN (*str != 0);
if (*wildstr++ == wild_one)
@@ -882,12 +883,12 @@ int wild_case_compare(const char *str,const char *wildstr)
char cmp;
if ((cmp= *wildstr) == wild_prefix && wildstr[1])
cmp=wildstr[1];
- cmp=toupper(cmp);
- while (*str && toupper(*str) != cmp)
+ cmp=my_toupper(cs, cmp);
+ while (*str && my_toupper(cs, *str) != cmp)
str++;
if (!*str) DBUG_RETURN (1);
}
- if (wild_case_compare(str,wildstr) == 0) DBUG_RETURN (0);
+ if (wild_case_compare(cs, str,wildstr) == 0) DBUG_RETURN (0);
} while (*str++);
DBUG_RETURN(1);
}
@@ -906,7 +907,7 @@ static void init_check_host(void)
DBUG_ENTER("init_check_host");
VOID(my_init_dynamic_array(&acl_wild_hosts,sizeof(struct acl_host_and_ip),
acl_users.elements,1));
- VOID(hash_init(&acl_check_hosts,acl_users.elements,0,0,
+ VOID(hash_init(&acl_check_hosts,system_charset_info,acl_users.elements,0,0,
(hash_get_key) check_get_key,0,HASH_CASE_INSENSITIVE));
if (!allow_all_hosts)
{
@@ -922,7 +923,8 @@ static void init_check_host(void)
{ // Check if host already exists
acl_host_and_ip *acl=dynamic_element(&acl_wild_hosts,j,
acl_host_and_ip *);
- if (!my_strcasecmp(acl_user->host.hostname,acl->hostname))
+ if (!my_strcasecmp(system_charset_info,
+ acl_user->host.hostname, acl->hostname))
break; // already stored
}
if (j == acl_wild_hosts.elements) // If new
@@ -1000,7 +1002,7 @@ bool check_change_password(THD *thd, const char *host, const char *user)
}
if (!thd->slave_thread &&
(strcmp(thd->user,user) ||
- my_strcasecmp(host,thd->host ? thd->host : thd->ip)))
+ my_strcasecmp(system_charset_info, host,thd->host_or_ip)))
{
if (check_access(thd, UPDATE_ACL, "mysql",0,1))
return(1);
@@ -1145,7 +1147,8 @@ static bool compare_hostname(const acl_host_and_ip *host, const char *hostname,
return (tmp & host->ip_mask) == host->ip;
}
return (!host->hostname ||
- (hostname && !wild_case_compare(hostname,host->hostname)) ||
+ (hostname && !wild_case_compare(system_charset_info,
+ hostname,host->hostname)) ||
(ip && !wild_compare(ip,host->hostname)));
}
@@ -1168,8 +1171,8 @@ static bool update_user_table(THD *thd, const char *host, const char *user,
tables.db=(char*) "mysql";
if (!(table=open_ltable(thd,&tables,TL_WRITE)))
DBUG_RETURN(1); /* purecov: deadcode */
- table->field[0]->store(host,(uint) strlen(host));
- table->field[1]->store(user,(uint) strlen(user));
+ table->field[0]->store(host,(uint) strlen(host), system_charset_info);
+ table->field[1]->store(user,(uint) strlen(user), system_charset_info);
if (table->file->index_read_idx(table->record[0],0,
(byte*) table->field[0]->ptr,0,
@@ -1179,7 +1182,7 @@ static bool update_user_table(THD *thd, const char *host, const char *user,
DBUG_RETURN(1); /* purecov: deadcode */
}
store_record(table,1);
- table->field[2]->store(new_password,(uint) strlen(new_password));
+ table->field[2]->store(new_password,(uint) strlen(new_password), system_charset_info);
if ((error=table->file->update_row(table->record[1],table->record[0])))
{
table->file->print_error(error,MYF(0)); /* purecov: deadcode */
@@ -1244,8 +1247,8 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
password=combo.password.str;
}
- table->field[0]->store(combo.host.str,combo.host.length);
- table->field[1]->store(combo.user.str,combo.user.length);
+ table->field[0]->store(combo.host.str,combo.host.length, system_charset_info);
+ table->field[1]->store(combo.user.str,combo.user.length, system_charset_info);
table->file->index_init(0);
if (table->file->index_read(table->record[0],
(byte*) table->field[0]->ptr,0,
@@ -1266,17 +1269,17 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
goto end;
}
old_row_exists = 0;
- restore_record(table,2); // cp empty row from record[2]
- table->field[0]->store(combo.host.str,combo.host.length);
- table->field[1]->store(combo.user.str,combo.user.length);
- table->field[2]->store(password,(uint) strlen(password));
+ restore_record(table,2); // cp empty row from record[2]
+ table->field[0]->store(combo.host.str,combo.host.length, system_charset_info);
+ table->field[1]->store(combo.user.str,combo.user.length, system_charset_info);
+ table->field[2]->store(password,(uint) strlen(password), system_charset_info);
}
else
{
old_row_exists = 1;
store_record(table,1); // Save copy for update
if (combo.password.str) // If password given
- table->field[2]->store(password,(uint) strlen(password));
+ table->field[2]->store(password,(uint) strlen(password), system_charset_info);
}
/* Update table columns with new privileges */
@@ -1289,7 +1292,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
tmp_field++, priv <<= 1)
{
if (priv & rights) // set requested privileges
- (*tmp_field)->store(&what,1);
+ (*tmp_field)->store(&what, 1, system_charset_info);
}
rights=get_access(table,3);
DBUG_PRINT("info",("table->fields: %d",table->fields));
@@ -1297,30 +1300,30 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
{
#ifdef HAVE_OPENSSL
/* We write down SSL related ACL stuff */
- table->field[25]->store("",0);
- table->field[26]->store("",0);
- table->field[27]->store("",0);
+ table->field[25]->store("", 0, system_charset_info);
+ table->field[26]->store("", 0, system_charset_info);
+ table->field[27]->store("", 0, system_charset_info);
switch (thd->lex.ssl_type) {
case SSL_TYPE_ANY:
- table->field[24]->store("ANY",3);
+ table->field[24]->store("ANY",3, system_charset_info);
break;
case SSL_TYPE_X509:
- table->field[24]->store("X509",4);
+ table->field[24]->store("X509",4, system_charset_info);
break;
case SSL_TYPE_SPECIFIED:
- table->field[24]->store("SPECIFIED",9);
+ table->field[24]->store("SPECIFIED",9, system_charset_info);
if (thd->lex.ssl_cipher)
table->field[25]->store(thd->lex.ssl_cipher,
- strlen(thd->lex.ssl_cipher));
+ strlen(thd->lex.ssl_cipher), system_charset_info);
if (thd->lex.x509_issuer)
table->field[26]->store(thd->lex.x509_issuer,
- strlen(thd->lex.x509_issuer));
+ strlen(thd->lex.x509_issuer), system_charset_info);
if (thd->lex.x509_subject)
table->field[27]->store(thd->lex.x509_subject,
- strlen(thd->lex.x509_subject));
+ strlen(thd->lex.x509_subject), system_charset_info);
break;
default:
- table->field[24]->store("",0);
+ table->field[24]->store("", 0, system_charset_info);
}
#endif /* HAVE_OPENSSL */
@@ -1409,9 +1412,9 @@ static int replace_db_table(TABLE *table, const char *db,
DBUG_RETURN(-1);
}
- table->field[0]->store(combo.host.str,combo.host.length);
- table->field[1]->store(db,(uint) strlen(db));
- table->field[2]->store(combo.user.str,combo.user.length);
+ table->field[0]->store(combo.host.str,combo.host.length, system_charset_info);
+ table->field[1]->store(db,(uint) strlen(db), system_charset_info);
+ table->field[2]->store(combo.user.str,combo.user.length, system_charset_info);
table->file->index_init(0);
if (table->file->index_read(table->record[0],(byte*) table->field[0]->ptr,0,
HA_READ_KEY_EXACT))
@@ -1424,9 +1427,9 @@ static int replace_db_table(TABLE *table, const char *db,
}
old_row_exists = 0;
restore_record(table,2); // cp empty row from record[2]
- table->field[0]->store(combo.host.str,combo.host.length);
- table->field[1]->store(db,(uint) strlen(db));
- table->field[2]->store(combo.user.str,combo.user.length);
+ table->field[0]->store(combo.host.str,combo.host.length, system_charset_info);
+ table->field[1]->store(db,(uint) strlen(db), system_charset_info);
+ table->field[2]->store(combo.user.str,combo.user.length, system_charset_info);
}
else
{
@@ -1438,7 +1441,7 @@ static int replace_db_table(TABLE *table, const char *db,
for (i= 3, priv= 1; i < table->fields; i++, priv <<= 1)
{
if (priv & store_rights) // do it if priv is chosen
- table->field [i]->store(&what,1); // set requested privileges
+ table->field [i]->store(&what,1, system_charset_info);// set requested privileges
}
rights=get_access(table,3);
rights=fix_rights_for_db(rights);
@@ -1519,13 +1522,14 @@ public:
tname= strdup_root(&memex,t);
if (lower_case_table_names)
{
- casedn_str(db);
- casedn_str(tname);
+ my_casedn_str(system_charset_info, db);
+ my_casedn_str(system_charset_info, tname);
}
key_length =(uint) strlen(d)+(uint) strlen(u)+(uint) strlen(t)+3;
hash_key = (char*) alloc_root(&memex,key_length);
strmov(strmov(strmov(hash_key,user)+1,db)+1,tname);
- (void) hash_init(&hash_columns,0,0,0, (hash_get_key) get_key_column,0,
+ (void) hash_init(&hash_columns,system_charset_info,
+ 0,0,0, (hash_get_key) get_key_column,0,
HASH_CASE_INSENSITIVE);
}
@@ -1547,8 +1551,8 @@ public:
}
if (lower_case_table_names)
{
- casedn_str(db);
- casedn_str(tname);
+ my_casedn_str(system_charset_info, db);
+ my_casedn_str(system_charset_info, tname);
}
key_length = ((uint) strlen(db) + (uint) strlen(user) +
(uint) strlen(tname) + 3);
@@ -1559,21 +1563,22 @@ public:
privs = fix_rights_for_table(privs);
cols = fix_rights_for_column(cols);
- (void) hash_init(&hash_columns,0,0,0, (hash_get_key) get_key_column,0,
+ (void) hash_init(&hash_columns,system_charset_info,
+ 0,0,0, (hash_get_key) get_key_column,0,
HASH_CASE_INSENSITIVE);
if (cols)
{
int key_len;
- col_privs->field[0]->store(host,(uint) strlen(host));
- col_privs->field[1]->store(db,(uint) strlen(db));
- col_privs->field[2]->store(user,(uint) strlen(user));
- col_privs->field[3]->store(tname,(uint) strlen(tname));
+ col_privs->field[0]->store(host,(uint) strlen(host), system_charset_info);
+ col_privs->field[1]->store(db,(uint) strlen(db), system_charset_info);
+ col_privs->field[2]->store(user,(uint) strlen(user), system_charset_info);
+ col_privs->field[3]->store(tname,(uint) strlen(tname), system_charset_info);
key_len=(col_privs->field[0]->pack_length()+
col_privs->field[1]->pack_length()+
col_privs->field[2]->pack_length()+
col_privs->field[3]->pack_length());
key_copy(key,col_privs,0,key_len);
- col_privs->field[4]->store("",0);
+ col_privs->field[4]->store("",0, system_charset_info);
col_privs->file->index_init(0);
if (col_privs->file->index_read(col_privs->record[0],
(byte*) col_privs->field[0]->ptr,
@@ -1644,8 +1649,10 @@ static GRANT_TABLE *table_hash_search(const char *host,const char* ip,
}
else
{
- if ((host && !wild_case_compare(host,grant_table->host)) ||
- (ip && !wild_case_compare(ip,grant_table->host)))
+ if ((host && !wild_case_compare(system_charset_info,
+ host,grant_table->host)) ||
+ (ip && !wild_case_compare(system_charset_info,
+ ip,grant_table->host)))
found=grant_table; // Host ok
}
}
@@ -1672,10 +1679,10 @@ static int replace_column_table(GRANT_TABLE *g_t,
byte key[MAX_KEY_LENGTH];
DBUG_ENTER("replace_column_table");
- table->field[0]->store(combo.host.str,combo.host.length);
- table->field[1]->store(db,(uint) strlen(db));
- table->field[2]->store(combo.user.str,combo.user.length);
- table->field[3]->store(table_name,(uint) strlen(table_name));
+ table->field[0]->store(combo.host.str,combo.host.length, system_charset_info);
+ table->field[1]->store(db,(uint) strlen(db), system_charset_info);
+ table->field[2]->store(combo.user.str,combo.user.length, system_charset_info);
+ table->field[3]->store(table_name,(uint) strlen(table_name), system_charset_info);
key_length=(table->field[0]->pack_length()+ table->field[1]->pack_length()+
table->field[2]->pack_length()+ table->field[3]->pack_length());
key_copy(key,table,0,key_length);
@@ -1692,7 +1699,7 @@ static int replace_column_table(GRANT_TABLE *g_t,
ulong privileges = xx->rights;
bool old_row_exists=0;
key_restore(table,key,0,key_length);
- table->field[4]->store(xx->column.ptr(),xx->column.length());
+ table->field[4]->store(xx->column.ptr(),xx->column.length(),system_charset_info);
if (table->file->index_read(table->record[0],(byte*) table->field[0]->ptr,
0, HA_READ_KEY_EXACT))
@@ -1706,9 +1713,9 @@ static int replace_column_table(GRANT_TABLE *g_t,
continue; /* purecov: inspected */
}
old_row_exists = 0;
- restore_record(table,2); // Get empty record
+ restore_record(table,2); // Get empty record
key_restore(table,key,0,key_length);
- table->field[4]->store(xx->column.ptr(),xx->column.length());
+ table->field[4]->store(xx->column.ptr(),xx->column.length(), system_charset_info);
}
else
{
@@ -1780,7 +1787,7 @@ static int replace_column_table(GRANT_TABLE *g_t,
{
GRANT_COLUMN *grant_column = NULL;
char colum_name_buf[HOSTNAME_LENGTH+1];
- String column_name(colum_name_buf,sizeof(colum_name_buf));
+ String column_name(colum_name_buf,sizeof(colum_name_buf),system_charset_info);
privileges&= ~rights;
table->field[6]->store((longlong)
@@ -1850,10 +1857,10 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table,
}
restore_record(table,2); // Get empty record
- table->field[0]->store(combo.host.str,combo.host.length);
- table->field[1]->store(db,(uint) strlen(db));
- table->field[2]->store(combo.user.str,combo.user.length);
- table->field[3]->store(table_name,(uint) strlen(table_name));
+ table->field[0]->store(combo.host.str,combo.host.length, system_charset_info);
+ table->field[1]->store(db,(uint) strlen(db), system_charset_info);
+ table->field[2]->store(combo.user.str,combo.user.length, system_charset_info);
+ table->field[3]->store(table_name,(uint) strlen(table_name), system_charset_info);
store_record(table,1); // store at pos 1
if (table->file->index_read_idx(table->record[0],0,
@@ -1898,7 +1905,7 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table,
}
}
- table->field[4]->store(grantor,(uint) strlen(grantor));
+ table->field[4]->store(grantor,(uint) strlen(grantor), system_charset_info);
table->field[6]->store((longlong) store_table_rights);
table->field[7]->store((longlong) store_col_rights);
rights=fix_rights_for_table(store_table_rights);
@@ -2155,7 +2162,7 @@ int mysql_grant (THD *thd, const char *db, List <LEX_USER> &list,
if (lower_case_table_names && db)
{
strmov(tmp_db,db);
- casedn_str(tmp_db);
+ my_casedn_str(system_charset_info, tmp_db);
db=tmp_db;
}
@@ -2243,7 +2250,8 @@ int grant_init (void)
DBUG_ENTER("grant_init");
grant_option = FALSE;
- (void) hash_init(&hash_tables,0,0,0, (hash_get_key) get_grant_table,
+ (void) hash_init(&hash_tables,system_charset_info,
+ 0,0,0, (hash_get_key) get_grant_table,
(hash_free_key) free_grant_table,0);
init_sql_alloc(&memex,1024,0);
@@ -2577,8 +2585,10 @@ bool check_grant_db(THD *thd,const char *db)
GRANT_TABLE *grant_table = (GRANT_TABLE*) hash_element(&hash_tables,idx);
if (len < grant_table->key_length &&
!memcmp(grant_table->hash_key,helping,len) &&
- (thd->host && !wild_case_compare(thd->host,grant_table->host) ||
- (thd->ip && !wild_case_compare(thd->ip,grant_table->host))))
+ (thd->host && !wild_case_compare(system_charset_info,
+ thd->host,grant_table->host) ||
+ (thd->ip && !wild_case_compare(system_charset_info,
+ thd->ip,grant_table->host))))
{
error=0; // Found match
break;
@@ -2707,7 +2717,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
DBUG_RETURN(-1);
}
- Item_string *field=new Item_string("",0);
+ Item_string *field=new Item_string("",0,system_charset_info);
List<Item> field_list;
field->name=buff;
field->max_length=1024;
@@ -2723,7 +2733,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
if (acl_user->access || acl_user->password)
{
want_access=acl_user->access;
- String global(buff,sizeof(buff));
+ String global(buff,sizeof(buff),system_charset_info);
global.length(0);
global.append("GRANT ",6);
@@ -2849,7 +2859,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
want_access=acl_db->access;
if (want_access)
{
- String db(buff,sizeof(buff));
+ String db(buff,sizeof(buff),system_charset_info);
db.length(0);
db.append("GRANT ",6);
@@ -2908,7 +2918,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
want_access=grant_table->privs;
if ((want_access | grant_table->cols) != 0)
{
- String global(buff,sizeof(buff));
+ String global(buff,sizeof(buff),system_charset_info);
global.length(0);
global.append("GRANT ",6);
diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc
index bbe82653190..91d6b967929 100644
--- a/sql/sql_analyse.cc
+++ b/sql/sql_analyse.cc
@@ -168,7 +168,7 @@ bool test_if_number(NUM_INFO *info, const char *str, uint str_len)
MySQL removes any endspaces of a string, so we must take care only of
spaces in front of a string
*/
- for (; str != end && isspace(*str); str++) ;
+ for (; str != end && my_isspace(system_charset_info, *str); str++) ;
if (str == end)
return 0;
@@ -181,10 +181,10 @@ bool test_if_number(NUM_INFO *info, const char *str, uint str_len)
else
info->negative = 0;
begin = str;
- for (; str != end && isdigit(*str); str++)
+ for (; str != end && my_isdigit(system_charset_info,*str); str++)
{
if (!info->integers && *str == '0' && (str + 1) != end &&
- isdigit(*(str + 1)))
+ my_isdigit(system_charset_info,*(str + 1)))
info->zerofill = 1; // could be a postnumber for example
info->integers++;
}
@@ -210,7 +210,7 @@ bool test_if_number(NUM_INFO *info, const char *str, uint str_len)
str++;
if (*str != '-' && *str != '+')
return 0;
- for (str++; str != end && isdigit(*str); str++) ;
+ for (str++; str != end && my_isdigit(system_charset_info,*str); str++) ;
if (str == end)
{
info->is_float = 1; // we can't use variable decimals here
@@ -225,7 +225,7 @@ bool test_if_number(NUM_INFO *info, const char *str, uint str_len)
info->ullval = (ulonglong) strtoull(begin, NULL, 10);
return 1;
}
- for (; str != end && isdigit(*str); str++)
+ for (; str != end && my_isdigit(system_charset_info,*str); str++)
info->decimals++;
if (str == end)
{
@@ -275,7 +275,7 @@ void free_string(String *s)
void field_str::add()
{
char buff[MAX_FIELD_WIDTH], *ptr;
- String s(buff, sizeof(buff)), *res;
+ String s(buff, sizeof(buff),default_charset_info), *res;
ulong length;
if (!(res = item->val_str(&s)))
@@ -314,10 +314,10 @@ void field_str::add()
{
if (res != &s)
s.copy(*res);
- if (!tree_search(&tree, (void*) &s)) // If not in tree
+ if (!tree_search(&tree, (void*) &s, tree.custom_arg)) // If not in tree
{
s.copy(); // slow, when SAFE_MALLOC is in use
- if (!tree_insert(&tree, (void*) &s, 0))
+ if (!tree_insert(&tree, (void*) &s, 0, tree.custom_arg))
{
room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree);
@@ -416,7 +416,7 @@ void field_real::add()
if (room_in_tree)
{
- if (!(element = tree_insert(&tree, (void*) &num, 0)))
+ if (!(element = tree_insert(&tree, (void*) &num, 0, tree.custom_arg)))
{
room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree);
@@ -469,7 +469,7 @@ void field_longlong::add()
if (room_in_tree)
{
- if (!(element = tree_insert(&tree, (void*) &num, 0)))
+ if (!(element = tree_insert(&tree, (void*) &num, 0, tree.custom_arg)))
{
room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree);
@@ -523,7 +523,7 @@ void field_ulonglong::add()
if (room_in_tree)
{
- if (!(element = tree_insert(&tree, (void*) &num, 0)))
+ if (!(element = tree_insert(&tree, (void*) &num, 0, tree.custom_arg)))
{
room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree);
@@ -578,8 +578,9 @@ bool analyse::end_of_records()
{
field_info **f = f_info;
char buff[MAX_FIELD_WIDTH];
- String *res, s_min(buff, sizeof(buff)), s_max(buff, sizeof(buff)),
- ans(buff, sizeof(buff));
+ String *res, s_min(buff, sizeof(buff),default_charset_info),
+ s_max(buff, sizeof(buff),default_charset_info),
+ ans(buff, sizeof(buff),default_charset_info);
for (; f != f_end; f++)
{
@@ -625,14 +626,14 @@ bool analyse::end_of_records()
((*f)->tree.elements_in_tree * 3 - 1 + 6))))
{
char tmp[331]; //331, because one double prec. num. can be this long
- String tmp_str(tmp, sizeof(tmp));
+ String tmp_str(tmp, sizeof(tmp),default_charset_info);
TREE_INFO tree_info;
tree_info.str = &tmp_str;
tree_info.found = 0;
tree_info.item = (*f)->item;
- tmp_str.set("ENUM(", 5);
+ tmp_str.set("ENUM(", 5,default_charset_info);
tree_walk(&(*f)->tree, (*f)->collect_enum(), (char*) &tree_info,
left_root_right);
tmp_str.append(')');
@@ -896,7 +897,7 @@ int collect_real(double *element, element_count count __attribute__((unused)),
TREE_INFO *info)
{
char buff[MAX_FIELD_WIDTH];
- String s(buff, sizeof(buff));
+ String s(buff, sizeof(buff),default_charset_info);
if (info->found)
info->str->append(',');
@@ -915,7 +916,7 @@ int collect_longlong(longlong *element,
TREE_INFO *info)
{
char buff[MAX_FIELD_WIDTH];
- String s(buff, sizeof(buff));
+ String s(buff, sizeof(buff),default_charset_info);
if (info->found)
info->str->append(',');
@@ -934,7 +935,7 @@ int collect_ulonglong(ulonglong *element,
TREE_INFO *info)
{
char buff[MAX_FIELD_WIDTH];
- String s(buff, sizeof(buff));
+ String s(buff, sizeof(buff),default_charset_info);
if (info->found)
info->str->append(',');
diff --git a/sql/sql_analyse.h b/sql/sql_analyse.h
index 1c60d0c150f..3e8ddd67023 100644
--- a/sql/sql_analyse.h
+++ b/sql/sql_analyse.h
@@ -110,8 +110,9 @@ class field_str :public field_info
EV_NUM_INFO ev_num_info;
public:
- field_str(Item* a, analyse* b) :field_info(a,b), min_arg(""),
- max_arg(""), sum(0),
+ field_str(Item* a, analyse* b) :field_info(a,b),
+ min_arg("",default_charset_info),
+ max_arg("",default_charset_info), sum(0),
must_be_blob(0), was_zero_fill(0),
was_maybe_zerofill(0), can_be_still_num(1)
{ init_tree(&tree, 0, 0, sizeof(String), a->binary ?
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 307de1a319e..a8115c15412 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -49,7 +49,8 @@ static byte *cache_key(const byte *record,uint *length,
void table_cache_init(void)
{
- VOID(hash_init(&open_cache,table_cache_size+16,0,0,cache_key,
+ VOID(hash_init(&open_cache,system_charset_info,
+ table_cache_size+16,0,0,cache_key,
(void (*)(void*)) free_cache_entry,0));
mysql_rm_tmp_tables();
}
@@ -195,34 +196,36 @@ OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *wild)
}
-/******************************************************************************
-** Send name and type of result to client.
-** Sum fields has table name empty and field_name.
-** flag is a bit mask with the following functions:
-** 1 send number of rows
-** 2 send default values
-** 4 Don't convert field names
-******************************************************************************/
+/*
+ Send name and type of result to client converted to a given char set
+
+ SYNOPSIS
+ send_convert_fields()
+ THD Thread data object
+ list List of items to send to client
+ convert object used to convertation to another character set
+ flag Bit mask with the following functions:
+ 2 send default values
+ 4 Don't convert field names
+
+ DESCRIPTION
+ Sum fields has table name empty and field_name.
+
+ RETURN VALUES
+ 0 ok
+ 1 Error (Note that in this case the error is not sent to the client)
+*/
bool
-send_fields(THD *thd,List<Item> &list,uint flag)
+send_convert_fields(THD *thd,List<Item> &list,CONVERT *convert,uint flag)
{
List_iterator_fast<Item> it(list);
Item *item;
char buff[80];
- CONVERT *convert= (flag & 4) ? (CONVERT*) 0 : thd->variables.convert_set;
+ String tmp((char*) buff,sizeof(buff),default_charset_info);
+ String *res,*packet= &thd->packet;
DBUG_ENTER("send_fields");
- String tmp((char*) buff,sizeof(buff)),*res,*packet= &thd->packet;
-
- if (thd->fatal_error) // We have got an error
- goto err;
-
- if (flag & 1)
- { // Packet with number of elements
- char *pos=net_store_length(buff,(uint) list.elements);
- (void) my_net_write(&thd->net, buff,(uint) (pos-buff));
- }
while ((item=it++))
{
char *pos;
@@ -230,19 +233,30 @@ send_fields(THD *thd,List<Item> &list,uint flag)
item->make_field(&field);
packet->length(0);
- if (convert)
+ if (thd->client_capabilities & CLIENT_PROTOCOL_41)
{
- if (convert->store(packet,field.table_name,
+ if (convert->store(packet,field.db_name,
+ (uint) strlen(field.db_name)) ||
+ convert->store(packet,field.table_name,
(uint) strlen(field.table_name)) ||
+ convert->store(packet,field.org_table_name,
+ (uint) strlen(field.org_table_name)) ||
convert->store(packet,field.col_name,
(uint) strlen(field.col_name)) ||
+ convert->store(packet,field.org_col_name,
+ (uint) strlen(field.org_col_name)) ||
packet->realloc(packet->length()+10))
goto err;
+ }
+ else
+ {
+ if (convert->store(packet,field.table_name,
+ (uint) strlen(field.table_name)) ||
+ convert->store(packet,field.col_name,
+ (uint) strlen(field.col_name)) ||
+ packet->realloc(packet->length()+10))
+ goto err;
}
- else if (net_store_data(packet,field.table_name) ||
- net_store_data(packet,field.col_name) ||
- packet->realloc(packet->length()+10))
- goto err; /* purecov: inspected */
pos= (char*) packet->ptr()+packet->length();
if (!(thd->client_capabilities & CLIENT_LONG_FLAG))
@@ -266,15 +280,160 @@ send_fields(THD *thd,List<Item> &list,uint flag)
if (net_store_null(packet))
goto err;
}
- else if (net_store_data(packet,res->ptr(),res->length()))
+ else if (convert->store(packet,res->ptr(),res->length()))
goto err;
}
if (my_net_write(&thd->net, (char*) packet->ptr(),packet->length()))
break; /* purecov: inspected */
}
- send_eof(&thd->net,1);
- DBUG_RETURN(0);
- err:
+ return 0;
+
+err:
+ return 1;
+}
+
+
+/*
+ Send name and type of result to client.
+
+ SYNOPSIS
+ send_non_convert_fields()
+ THD Thread data object
+ list List of items to send to client
+ flag Bit mask with the following functions:
+ 2 send default values
+ 4 Don't convert field names
+
+ DESCRIPTION
+ Sum fields has table name empty and field_name.
+
+ RETURN VALUES
+ 0 ok
+ 1 Error
+*/
+
+bool
+send_non_convert_fields(THD *thd,List<Item> &list,uint flag)
+{
+ List_iterator_fast<Item> it(list);
+ Item *item;
+ char buff[80];
+
+ String tmp((char*) buff,sizeof(buff),default_charset_info);
+ String *res,*packet= &thd->packet;
+
+ while ((item=it++))
+ {
+ char *pos;
+ Send_field field;
+ item->make_field(&field);
+ packet->length(0);
+
+ if (thd->client_capabilities & CLIENT_PROTOCOL_41)
+ {
+ if (net_store_data(packet,field.db_name) ||
+ net_store_data(packet,field.table_name) ||
+ net_store_data(packet,field.org_table_name) ||
+ net_store_data(packet,field.col_name) ||
+ net_store_data(packet,field.org_col_name) ||
+ packet->realloc(packet->length()+10))
+ return 1;
+ }
+ else
+ {
+ if (net_store_data(packet,field.table_name) ||
+ net_store_data(packet,field.col_name) ||
+ packet->realloc(packet->length()+10))
+ return 1;
+ }
+
+ pos= (char*) packet->ptr()+packet->length();
+
+ if (!(thd->client_capabilities & CLIENT_LONG_FLAG))
+ {
+ packet->length(packet->length()+9);
+ pos[0]=3; int3store(pos+1,field.length);
+ pos[4]=1; pos[5]=field.type;
+ pos[6]=2; pos[7]=(char) field.flags; pos[8]= (char) field.decimals;
+ }
+ else
+ {
+ packet->length(packet->length()+10);
+ pos[0]=3; int3store(pos+1,field.length);
+ pos[4]=1; pos[5]=field.type;
+ pos[6]=3; int2store(pos+7,field.flags); pos[9]= (char) field.decimals;
+ }
+ if (flag & 2)
+ { // Send default value
+ if (!(res=item->val_str(&tmp)))
+ {
+ if (net_store_null(packet))
+ return 1;
+ }
+ else if (net_store_data(packet,res->ptr(),res->length()))
+ return 1;
+ }
+ if (my_net_write(&thd->net, (char*) packet->ptr(),packet->length()))
+ break;
+ }
+ return 0;
+}
+
+
+/*
+ Send name and type of result to client.
+
+ SYNOPSIS
+ send_fields()
+ THD Thread data object
+ list List of items to send to client
+ convert object used to convertation to another character set
+ flag Bit mask with the following functions:
+ 1 send number of rows
+ 2 send default values
+ 4 Don't convert field names
+
+ DESCRIPTION
+ Sum fields has table name empty and field_name.
+ Uses send_fields_convert() and send_fields() depending on
+ if we have an active character set convert or not.
+
+ RETURN VALUES
+ 0 ok
+ 1 Error (Note that in this case the error is not sent to the client)
+*/
+
+bool
+send_fields(THD *thd, List<Item> &list, uint flag)
+{
+ CONVERT *convert= (flag & 4) ? (CONVERT*) 0 : thd->convert_set;
+ DBUG_ENTER("send_fields");
+
+ if (thd->fatal_error) // We have got an error
+ goto err;
+
+ if (flag & 1)
+ { // Packet with number of elements
+ char *pos=net_store_length(buff,(uint) list.elements);
+ (void) my_net_write(&thd->net, buff,(uint) (pos-buff));
+ }
+
+ /*
+ Avoid check conditions on convert() for each field
+ by having two different functions
+ */
+ if (convert)
+ {
+ if (send_convert_fields(thd, list, convert, flag))
+ goto err;
+ }
+ else if (send_non_convert_fields(thd, list, flag))
+ goto err;
+
+ send_eof(&thd->net);
+ return 0;
+
+err:
send_error(&thd->net,ER_OUT_OF_RESOURCES); /* purecov: inspected */
DBUG_RETURN(1); /* purecov: inspected */
}
@@ -812,7 +971,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name,
{
if (table->key_length == key_length &&
!memcmp(table->table_cache_key,key,key_length) &&
- !my_strcasecmp(table->table_name,alias))
+ !my_strcasecmp(system_charset_info,table->table_name,alias))
goto reset;
}
my_printf_error(ER_TABLE_NOT_LOCKED,ER(ER_TABLE_NOT_LOCKED),MYF(0),alias);
@@ -1593,11 +1752,12 @@ Field *find_field_in_table(THD *thd,TABLE *table,const char *name,uint length,
Field **ptr=table->field;
while ((field = *ptr++))
{
- if (!my_strcasecmp(field->field_name, name))
+ if (!my_strcasecmp(system_charset_info, field->field_name, name))
goto found;
}
}
- if (allow_rowid && !my_strcasecmp(name,"_rowid") &&
+ if (allow_rowid &&
+ !my_strcasecmp(system_charset_info, name, "_rowid") &&
(field=table->rowid_field))
goto found;
return (Field*) 0;
@@ -1720,7 +1880,8 @@ find_item_in_list(Item *find,List<Item> &items)
{
if (field_name && item->type() == Item::FIELD_ITEM)
{
- if (!my_strcasecmp(((Item_field*) item)->name,field_name))
+ if (!my_strcasecmp(system_charset_info,
+ ((Item_field*) item)->name,field_name))
{
if (!table_name)
{
@@ -1743,8 +1904,9 @@ find_item_in_list(Item *find,List<Item> &items)
}
}
else if (!table_name && (item->eq(find,0) ||
- find->name &&
- !my_strcasecmp(item->name,find->name)))
+ find->name &&
+ !my_strcasecmp(system_charset_info,
+ item->name,find->name)))
{
found=li.ref();
break;
@@ -1783,7 +1945,7 @@ int setup_fields(THD *thd, TABLE_LIST *tables, List<Item> &fields,
}
else
{
- if (item->fix_fields(thd,tables))
+ if (item->fix_fields(thd, tables, it.ref()))
DBUG_RETURN(-1); /* purecov: inspected */
if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM &&
sum_func_list)
@@ -1935,7 +2097,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
if (*conds)
{
thd->where="where clause";
- if ((*conds)->fix_fields(thd,tables))
+ if ((*conds)->fix_fields(thd, tables, conds))
DBUG_RETURN(1);
}
@@ -1946,7 +2108,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
{
/* Make a join an a expression */
thd->where="on clause";
- if (table->on_expr->fix_fields(thd,tables))
+ if (table->on_expr->fix_fields(thd, tables, &table->on_expr))
DBUG_RETURN(1);
thd->cond_count++;
@@ -1973,7 +2135,8 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
// TODO: This could be optimized to use hashed names if t2 had a hash
for (j=0 ; j < t2->fields ; j++)
{
- if (!my_strcasecmp(t1->field[i]->field_name,
+ if (!my_strcasecmp(system_charset_info,
+ t1->field[i]->field_name,
t2->field[j]->field_name))
{
Item_func_eq *tmp=new Item_func_eq(new Item_field(t1->field[i]),
@@ -2022,7 +2185,7 @@ fill_record(List<Item> &fields,List<Item> &values)
while ((field=(Item_field*) f++))
{
value=v++;
- if (value->save_in_field(field->field))
+ if (value->save_in_field(field->field) == 1)
DBUG_RETURN(1);
}
DBUG_RETURN(0);
@@ -2040,7 +2203,7 @@ fill_record(Field **ptr,List<Item> &values)
while ((field = *ptr++))
{
value=v++;
- if (value->save_in_field(field))
+ if (value->save_in_field(field) == 1)
DBUG_RETURN(1);
}
DBUG_RETURN(0);
@@ -2078,10 +2241,10 @@ static void mysql_rm_tmp_tables(void)
/*
-** CREATE INDEX and DROP INDEX are implemented by calling ALTER TABLE with
-** the proper arguments. This isn't very fast but it should work for most
-** cases.
-** One should normally create all indexes with CREATE TABLE or ALTER TABLE.
+ CREATE INDEX and DROP INDEX are implemented by calling ALTER TABLE with
+ the proper arguments. This isn't very fast but it should work for most
+ cases.
+ One should normally create all indexes with CREATE TABLE or ALTER TABLE.
*/
int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
@@ -2093,6 +2256,8 @@ int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
DBUG_ENTER("mysql_create_index");
bzero((char*) &create_info,sizeof(create_info));
create_info.db_type=DB_TYPE_DEFAULT;
+ /* TODO: Fix to use database character set */
+ create_info.table_charset=default_charset_info;
DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
&create_info, table_list,
fields, keys, drop, alter, (ORDER*)0, FALSE,
@@ -2109,6 +2274,7 @@ int mysql_drop_index(THD *thd, TABLE_LIST *table_list, List<Alter_drop> &drop)
DBUG_ENTER("mysql_drop_index");
bzero((char*) &create_info,sizeof(create_info));
create_info.db_type=DB_TYPE_DEFAULT;
+ create_info.table_charset=default_charset_info;
DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
&create_info, table_list,
fields, keys, drop, alter, (ORDER*)0, FALSE,
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 1acdc3149ab..26fa0bb0481 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -888,8 +888,9 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
Test if the query is a SELECT
(pre-space is removed in dispatch_command)
*/
- if (toupper(sql[0]) != 'S' || toupper(sql[1]) != 'E' ||
- toupper(sql[2]) !='L')
+ if (my_toupper(system_charset_info, sql[0]) != 'S' ||
+ my_toupper(system_charset_info, sql[1]) != 'E' ||
+ my_toupper(system_charset_info,sql[2]) !='L')
{
DBUG_PRINT("qcache", ("The statement is not a SELECT; Not cached"));
goto err;
@@ -1354,9 +1355,9 @@ ulong Query_cache::init_cache()
DUMP(this);
- VOID(hash_init(&queries,def_query_hash_size, 0, 0,
+ VOID(hash_init(&queries,system_charset_info,def_query_hash_size, 0, 0,
query_cache_query_get_key, 0, 0));
- VOID(hash_init(&tables,def_table_hash_size, 0, 0,
+ VOID(hash_init(&tables,system_charset_info,def_table_hash_size, 0, 0,
query_cache_table_get_key, 0, 0));
queries_in_cache = 0;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 5c0d2b31d4e..41def4aa1b5 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -78,8 +78,8 @@ static void free_var(user_var_entry *entry)
****************************************************************************/
THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
- insert_id_used(0),in_lock_tables(0),
- global_read_lock(0),bootstrap(0)
+ insert_id_used(0), in_lock_tables(0),
+ global_read_lock(0), bootstrap(0)
{
host=user=priv_user=db=query=ip=0;
host_or_ip="unknown ip";
@@ -103,6 +103,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
slave_proxy_id = 0;
file_id = 0;
cond_count=0;
+ db_charset=default_charset_info;
mysys_var=0;
#ifndef DBUG_OFF
dbug_sentry=THD_SENTRY_MAGIC;
@@ -140,8 +141,9 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
/* Initialize sub structures */
bzero((char*) &mem_root,sizeof(mem_root));
bzero((char*) &transaction.mem_root,sizeof(transaction.mem_root));
+ bzero((char*) &con_root,sizeof(con_root));
user_connect=(USER_CONN *)0;
- hash_init(&user_vars, USER_VARS_HASH_SIZE, 0, 0,
+ hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
(hash_get_key) get_var_key,
(void (*)(void*)) free_var,0);
#ifdef USING_TRANSACTIONS
@@ -219,6 +221,7 @@ THD::~THD()
safeFree(db);
safeFree(ip);
free_root(&mem_root,MYF(0));
+ free_root(&con_root,MYF(0));
free_root(&transaction.mem_root,MYF(0));
mysys_var=0; // Safety (shouldn't be needed)
pthread_mutex_destroy(&LOCK_delete);
@@ -365,8 +368,10 @@ select_result::select_result()
thd=current_thd;
}
-static String default_line_term("\n"),default_escaped("\\"),
- default_field_term("\t");
+static String
+ default_line_term("\n",default_charset_info),
+ default_escaped("\\",default_charset_info),
+ default_field_term("\t",default_charset_info);
sql_exchange::sql_exchange(char *name,bool flag)
:file_name(name), opt_enclosed(0), dumpfile(flag), skip_lines(0)
@@ -391,9 +396,9 @@ bool select_send::send_data(List<Item> &items)
String *packet= &thd->packet;
DBUG_ENTER("send_data");
- if (thd->offset_limit)
+ if (unit->offset_limit_cnt)
{ // using limit offset,count
- thd->offset_limit--;
+ unit->offset_limit_cnt--;
DBUG_RETURN(0);
}
packet->length(0); // Reset packet
@@ -441,11 +446,12 @@ select_export::~select_export()
}
int
-select_export::prepare(List<Item> &list)
+select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
{
char path[FN_REFLEN];
uint option=4;
bool blob_flag=0;
+ unit= u;
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
option|=1; // Force use of db directory
#endif
@@ -509,12 +515,12 @@ bool select_export::send_data(List<Item> &items)
DBUG_ENTER("send_data");
char buff[MAX_FIELD_WIDTH],null_buff[2],space[MAX_FIELD_WIDTH];
bool space_inited=0;
- String tmp(buff,sizeof(buff)),*res;
+ String tmp(buff,sizeof(buff),default_charset_info),*res;
tmp.length(0);
- if (thd->offset_limit)
+ if (unit->offset_limit_cnt)
{ // using limit offset,count
- thd->offset_limit--;
+ unit->offset_limit_cnt--;
DBUG_RETURN(0);
}
row_count++;
@@ -680,9 +686,11 @@ select_dump::~select_dump()
}
int
-select_dump::prepare(List<Item> &list __attribute__((unused)))
+select_dump::prepare(List<Item> &list __attribute__((unused)),
+ SELECT_LEX_UNIT *u)
{
uint option=4;
+ unit= u;
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
option|=1; // Force use of db directory
#endif
@@ -716,14 +724,14 @@ bool select_dump::send_data(List<Item> &items)
{
List_iterator_fast<Item> li(items);
char buff[MAX_FIELD_WIDTH];
- String tmp(buff,sizeof(buff)),*res;
+ String tmp(buff,sizeof(buff),default_charset_info),*res;
tmp.length(0);
Item *item;
DBUG_ENTER("send_data");
- if (thd->offset_limit)
+ if (unit->offset_limit_cnt)
{ // using limit offset,count
- thd->offset_limit--;
+ unit->offset_limit_cnt--;
DBUG_RETURN(0);
}
if (row_count++ > 1)
@@ -760,7 +768,6 @@ void select_dump::send_error(uint errcode,const char *err)
file= -1;
}
-
bool select_dump::send_eof()
{
int error=test(end_io_cache(&cache));
@@ -773,3 +780,58 @@ bool select_dump::send_eof()
file= -1;
return error;
}
+
+select_subselect::select_subselect(Item_subselect *item)
+{
+ this->item=item;
+}
+
+bool select_singleval_subselect::send_data(List<Item> &items)
+{
+ DBUG_ENTER("select_singleval_subselect::send_data");
+ Item_singleval_subselect *it= (Item_singleval_subselect *)item;
+ if (it->assigned){
+ my_printf_error(ER_SUBSELECT_NO_1_ROW, ER(ER_SUBSELECT_NO_1_ROW), MYF(0));
+ DBUG_RETURN(1);
+ }
+ if (unit->offset_limit_cnt)
+ { // Using limit offset,count
+ unit->offset_limit_cnt--;
+ DBUG_RETURN(0);
+ }
+ List_iterator_fast<Item> li(items);
+ Item *val_item= li++; // Only one (single value subselect)
+ /*
+ Following val() call have to be first, because function AVG() & STD()
+ calculate value on it & determinate "is it NULL?".
+ */
+ it->real_value= val_item->val();
+ if ((it->null_value= val_item->is_null()))
+ {
+ it->assign_null();
+ } else {
+ it->max_length= val_item->max_length;
+ it->decimals= val_item->decimals;
+ it->binary= val_item->binary;
+ val_item->val_str(&it->str_value);
+ it->int_value= val_item->val_int();
+ it->res_type= val_item->result_type();
+ }
+ it->assigned= 1;
+ DBUG_RETURN(0);
+}
+
+bool select_exists_subselect::send_data(List<Item> &items)
+{
+ DBUG_ENTER("select_exists_subselect::send_data");
+ Item_exists_subselect *it= (Item_exists_subselect *)item;
+ if (unit->offset_limit_cnt)
+ { // Using limit offset,count
+ unit->offset_limit_cnt--;
+ DBUG_RETURN(0);
+ }
+ it->value= 1;
+ it->assigned= 1;
+ DBUG_RETURN(0);
+}
+
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 5b35b4e7ea0..8b2e9400613 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -73,14 +73,14 @@ class MYSQL_LOG {
// current file sequence number for load data infile binary logging
uint file_id;
uint open_count; // For replication
+ volatile enum_log_type log_type;
+ enum cache_type io_cache_type;
+ bool write_error,inited;
/*
For binlog - if log name can never change we should not try to rotate it
or write any rotation events. The user should use FLUSH MASTER instead
of FLUSH LOGS for purging.
*/
- volatile enum_log_type log_type;
- enum cache_type io_cache_type;
- bool write_error,inited;
bool no_rotate;
bool need_start_event;
bool no_auto_events; // for relay binlog
@@ -220,19 +220,40 @@ public:
class Key :public Sql_alloc {
public:
- enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FULLTEXT };
+ enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FULLTEXT, SPATIAL, FOREIGN_KEY};
enum Keytype type;
enum ha_key_alg algorithm;
List<key_part_spec> columns;
- const char *Name;
+ const char *name;
- Key(enum Keytype type_par,const char *name_arg,List<key_part_spec> &cols)
- :type(type_par), algorithm(HA_KEY_ALG_UNDEF), columns(cols), Name(name_arg)
+ Key(enum Keytype type_par, const char *name_arg, enum ha_key_alg alg_par,
+ List<key_part_spec> &cols)
+ :type(type_par), algorithm(alg_par), columns(cols), name(name_arg)
{}
~Key() {}
- const char *name() { return Name; }
};
+class Table_ident;
+
+class foreign_key: public Key {
+public:
+ enum fk_match_opt { FK_MATCH_UNDEF, FK_MATCH_FULL,
+ FK_MATCH_PARTIAL, FK_MATCH_SIMPLE};
+ enum fk_option { FK_OPTION_UNDEF, FK_OPTION_RESTRICT, FK_OPTION_CASCADE,
+ FK_OPTION_SET_NULL, FK_OPTION_NO_ACTION, FK_OPTION_DEFAULT};
+
+ Table_ident *ref_table;
+ List<key_part_spec> ref_columns;
+ uint delete_opt, update_opt, match_opt;
+ foreign_key(const char *name_arg, List<key_part_spec> &cols,
+ Table_ident *table, List<key_part_spec> &ref_cols,
+ uint delete_opt_arg, uint update_opt_arg, uint match_opt_arg)
+ :Key(FOREIGN_KEY, name_arg, HA_KEY_ALG_UNDEF, cols),
+ ref_table(table), ref_columns(cols),
+ delete_opt(delete_opt_arg), update_opt(update_opt_arg),
+ match_opt(match_opt_arg)
+ {}
+};
typedef struct st_mysql_lock
{
@@ -252,8 +273,8 @@ public:
#include "sql_lex.h" /* Must be here */
-// needed to be able to have an I_List of char* strings.in mysqld.cc where we cannot use String
-// because it is Sql_alloc'ed
+/* Needed to be able to have an I_List of char* strings in mysqld.cc. */
+
class i_string: public ilink
{
public:
@@ -262,7 +283,7 @@ public:
i_string(char* s) : ptr(s) {}
};
-//needed for linked list of two strings for replicate-rewrite-db
+/* needed for linked list of two strings for replicate-rewrite-db */
class i_string_pair: public ilink
{
public:
@@ -271,7 +292,30 @@ public:
i_string_pair():key(0),val(0) { }
i_string_pair(char* key_arg, char* val_arg) : key(key_arg),val(val_arg) {}
};
+#define MYSQL_DEFAULT_ERROR_COUNT 500
+class mysql_st_error
+{
+public:
+ uint code;
+ char msg[MYSQL_ERRMSG_SIZE+1];
+ char query[NAME_LEN+1];
+
+ static void *operator new(size_t size)
+ {
+ return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE));
+ }
+ static void operator delete(void* ptr_arg, size_t size)
+ {
+ my_free((gptr)ptr_arg, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
+ }
+ mysql_st_error(uint ecode, const char *emsg, const char *equery)
+ {
+ code = ecode;
+ strmov(msg, emsg);
+ strnmov(query, equery ? equery : "", NAME_LEN);
+ }
+};
class delayed_insert;
@@ -292,6 +336,8 @@ struct system_variables
ulong max_sort_length;
ulong max_join_size;
ulong max_tmp_tables;
+ ulong max_error_count;
+ ulong max_warning_count;
ulong myisam_sort_buff_size;
ulong net_buffer_length;
ulong net_interactive_timeout;
@@ -325,6 +371,7 @@ public:
NET net; // client connection descriptor
LEX lex; // parse tree descriptor
MEM_ROOT mem_root; // 1 command-life memory pool
+ MEM_ROOT con_root; // connection-life memory
HASH user_vars; // hash for user variables
String packet; // dynamic buffer for network I/O
struct sockaddr_in remote; // client socket address
@@ -343,8 +390,7 @@ public:
host - host of the client
user - user of the client, set to NULL until the user has been read from
the connection
- priv_user - not sure why we have it, but it is set to "boot" when we run
- with --bootstrap
+ priv_user - The user privilege we are using. May be '' for anonymous user.
db - currently selected database
ip - client IP
*/
@@ -371,7 +417,8 @@ public:
*/
TABLE *open_tables,*temporary_tables, *handler_tables;
// TODO: document the variables below
- MYSQL_LOCK *lock,*locked_tables;
+ MYSQL_LOCK *lock; /* Current locks */
+ MYSQL_LOCK *locked_tables; /* Tables locked with LOCK */
ULL *ull;
#ifndef DBUG_OFF
uint dbug_sentry; // watch out for memory corruption
@@ -418,7 +465,9 @@ public:
sent_row_count, examined_row_count;
table_map used_tables;
USER_CONN *user_connect;
- ulong query_id,version, options,thread_id, col_access;
+ CHARSET_INFO *db_charset;
+ ulong query_id, version, options, thread_id, col_access;
+ ulong param_count,current_param_number;
long dbug_thread_id;
pthread_t real_id;
uint current_tablenr,tmp_table,cond_count;
@@ -437,6 +486,11 @@ public:
bool query_error, bootstrap, cleanup_done;
bool safe_to_cache_query;
bool volatile killed;
+ bool prepare_command;
+ Error<mysql_st_error> err_list;
+ Error<mysql_st_error> warn_list;
+ Item_param *current_param;
+
/*
If we do a purge of binary logs, log index info of the threads
that are currently reading it needs to be adjusted. To do that
@@ -450,7 +504,6 @@ public:
ulong slave_proxy_id;
NET* slave_net; // network connection from slave -> m.
my_off_t log_pos;
-
/* Used by the sys_var class to store temporary values */
union
{
@@ -580,7 +633,7 @@ public:
#include "log_event.h"
/*
-** This is used to get result from a select
+ This is used to get result from a select
*/
class JOIN;
@@ -590,10 +643,15 @@ void send_error(NET *net,uint sql_errno=0, const char *err=0);
class select_result :public Sql_alloc {
protected:
THD *thd;
+ SELECT_LEX_UNIT *unit;
public:
select_result();
virtual ~select_result() {};
- virtual int prepare(List<Item> &list) { return 0; }
+ virtual int prepare(List<Item> &list, SELECT_LEX_UNIT *u)
+ {
+ unit= u;
+ return 0;
+ }
virtual bool send_fields(List<Item> &list,uint flag)=0;
virtual bool send_data(List<Item> &items)=0;
virtual void initialize_tables (JOIN *join=0) {}
@@ -626,7 +684,7 @@ class select_export :public select_result {
public:
select_export(sql_exchange *ex) :exchange(ex),file(-1),row_count(0L) {}
~select_export();
- int prepare(List<Item> &list);
+ int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
bool send_fields(List<Item> &list,
uint flag) { return 0; }
bool send_data(List<Item> &items);
@@ -645,7 +703,7 @@ public:
select_dump(sql_exchange *ex) :exchange(ex),file(-1),row_count(0L)
{ path[0]=0; }
~select_dump();
- int prepare(List<Item> &list);
+ int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
bool send_fields(List<Item> &list,
uint flag) { return 0; }
bool send_data(List<Item> &items);
@@ -668,7 +726,7 @@ class select_insert :public select_result {
info.handle_duplicates=duplic;
}
~select_insert();
- int prepare(List<Item> &list);
+ int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
bool send_fields(List<Item> &list, uint flag)
{ return 0; }
bool send_data(List<Item> &items);
@@ -697,7 +755,7 @@ public:
create_info(create_info_par),
lock(0)
{}
- int prepare(List<Item> &list);
+ int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
bool send_data(List<Item> &values);
bool send_eof();
void abort();
@@ -712,7 +770,7 @@ class select_union :public select_result {
select_union(TABLE *table_par);
~select_union();
- int prepare(List<Item> &list);
+ int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
bool send_fields(List<Item> &list, uint flag)
{ return 0; }
bool send_data(List<Item> &items);
@@ -720,6 +778,36 @@ class select_union :public select_result {
bool flush();
};
+/* Base subselect interface class */
+class select_subselect :public select_result
+{
+protected:
+ Item_subselect *item;
+public:
+ select_subselect(Item_subselect *item);
+ bool send_fields(List<Item> &list, uint flag) { return 0; };
+ bool send_data(List<Item> &items)=0;
+ bool send_eof() { return 0; };
+
+ friend class Ttem_subselect;
+};
+
+/* Single value subselect interface class */
+class select_singleval_subselect :public select_subselect
+{
+public:
+ select_singleval_subselect(Item_subselect *item):select_subselect(item){}
+ bool send_data(List<Item> &items);
+};
+
+/* EXISTS subselect interface class */
+class select_exists_subselect :public select_subselect
+{
+public:
+ select_exists_subselect(Item_subselect *item):select_subselect(item){}
+ bool send_data(List<Item> &items);
+};
+
/* Structs used when sorting */
typedef struct st_sort_field {
@@ -746,17 +834,28 @@ class Table_ident :public Sql_alloc {
public:
LEX_STRING db;
LEX_STRING table;
- inline Table_ident(LEX_STRING db_arg,LEX_STRING table_arg,bool force)
- :table(table_arg)
+ SELECT_LEX_UNIT *sel;
+ inline Table_ident(LEX_STRING db_arg, LEX_STRING table_arg, bool force)
+ :table(table_arg), sel((SELECT_LEX_UNIT *)0)
{
if (!force && (current_thd->client_capabilities & CLIENT_NO_SCHEMA))
db.str=0;
else
db= db_arg;
}
- inline Table_ident(LEX_STRING table_arg) :table(table_arg) {db.str=0;}
+ inline Table_ident(LEX_STRING table_arg)
+ :table(table_arg), sel((SELECT_LEX_UNIT *)0)
+ {
+ db.str=0;
+ }
+ inline Table_ident(SELECT_LEX_UNIT *s) : sel(s)
+ {
+ db.str=0; table.str=(char *)""; table.length=0;
+ }
inline void change_db(char *db_name)
- { db.str= db_name; db.length=(uint) strlen(db_name); }
+ {
+ db.str= db_name; db.length= (uint) strlen(db_name);
+ }
};
// this is needed for user_vars hash
@@ -789,7 +888,7 @@ public:
{
if (tree.elements_in_tree > max_elements && flush())
return 1;
- return !tree_insert(&tree,ptr,0);
+ return !tree_insert(&tree, ptr, 0, tree.custom_arg);
}
bool get(TABLE *table);
@@ -816,7 +915,7 @@ public:
multi_delete(THD *thd, TABLE_LIST *dt, thr_lock_type lock_option_arg,
uint num_of_tables);
~multi_delete();
- int prepare(List<Item> &list);
+ int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
bool send_fields(List<Item> &list,
uint flag) { return 0; }
bool send_data(List<Item> &items);
@@ -828,7 +927,6 @@ public:
class multi_update : public select_result {
TABLE_LIST *update_tables, *table_being_updated;
-// Unique **tempfiles;
COPY_INFO *infos;
TABLE **tmp_tables;
THD *thd;
@@ -845,7 +943,7 @@ public:
enum enum_duplicates handle_duplicates,
thr_lock_type lock_option_arg, uint num);
~multi_update();
- int prepare(List<Item> &list);
+ int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
bool send_fields(List<Item> &list,
uint flag) { return 0; }
bool send_data(List<Item> &items);
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index 0e2cfba1b30..dee26aae4be 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -25,20 +25,114 @@
#include <direct.h>
#endif
+#define MY_DB_OPT_FILE ".db.opt"
+
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp,
const char *db, const char *path,
uint level);
+/*
+ Create database options file:
+ Currently databse default charset is only stored there.
+*/
+
+static int write_db_opt(THD *thd,const char *db,HA_CREATE_INFO *create,char *fn)
+{
+ register File file;
+ char buf[256]; // Should be enough
+ int error=0;
+
+ if ((file=my_create(fn,CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
+ {
+ sprintf(buf,"default-character-set=%s\n",
+ (create && create->table_charset) ?
+ create->table_charset->name : "DEFAULT");
+
+ if (my_write(file,(byte*)buf,strlen(buf),MYF(MY_NABP+MY_WME)))
+ {
+ // QQ : should we send more suitable error message?
+ my_error(ER_CANT_CREATE_DB,MYF(0),db,my_errno);
+ error = -1;
+ goto exit;
+ }
+ my_close(file,MYF(0));
+ }
+ else
+ {
+ // QQ : should we send more suitable error message?
+ my_error(ER_CANT_CREATE_DB,MYF(0),db,my_errno);
+ error = -1;
+ goto exit;
+ }
+exit:
+ return error;
+}
+
+
+ /*
+ Load database options file:
+ */
+static int load_db_opt(THD *thd,const char *db,HA_CREATE_INFO *create,char *fn)
+{
+ register File file;
+ char buf[256]="";
+
+ if ((file=my_open(fn,O_RDWR|O_BINARY,MYF(MY_WME))) >= 0)
+ {
+ int nbytes=my_read(file,(byte*)buf,sizeof(buf)-1,MYF(0));
+ if ( nbytes >= 0 )
+ {
+ char *ln=buf;
+ char *pe=buf+nbytes;
+
+ buf[nbytes]='\0';
+
+ for ( ln=buf; ln<pe; )
+ {
+ char *le,*val;
+ for ( le=ln, val=0 ; le<pe ; le++ )
+ {
+ switch(le[0])
+ {
+ case '=':
+ le[0]='\0';
+ val=le+1;
+ le++;
+ break;
+ case '\r':
+ case '\n':
+ le[0]='\0';
+ le++;
+ for( ; (le[0]=='\r' || le[0]=='\n') ; le++);
+ if (!strcmp(ln,"default-character-set") && val && val[0])
+ {
+ create->table_charset=get_charset_by_name(val, MYF(0));
+ }
+ goto cnt;
+ break;
+ }
+ }
+cnt:
+ ln=le;
+ }
+ }
+ my_close(file,MYF(0));
+ }
+ return 0;
+}
+
/* db-name is already validated when we come here */
-int mysql_create_db(THD *thd, char *db, uint create_options, bool silent)
+int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, bool silent)
{
char path[FN_REFLEN+16];
MY_DIR *dirp;
long result=1;
int error = 0;
+ uint create_options = create_info ? create_info->options : 0;
+
DBUG_ENTER("mysql_create_db");
-
+
VOID(pthread_mutex_lock(&LOCK_mysql_create_db));
// do not create database if another thread is holding read lock
@@ -73,6 +167,12 @@ int mysql_create_db(THD *thd, char *db, uint create_options, bool silent)
}
}
+ strcat(path,"/");
+ unpack_dirname(path,path);
+ strcat(path,MY_DB_OPT_FILE);
+ if ((error=write_db_opt(thd,db,create_info,path)))
+ goto exit;
+
if (!silent)
{
if (!thd->query)
@@ -85,6 +185,76 @@ int mysql_create_db(THD *thd, char *db, uint create_options, bool silent)
mysql_update_log.write(thd,thd->query, thd->query_length);
if (mysql_bin_log.is_open())
{
+ Query_log_event qinfo(thd, thd->query);
+ mysql_bin_log.write(&qinfo);
+ }
+ }
+ if (thd->query == path)
+ {
+ thd->query = 0; // just in case
+ thd->query_length = 0;
+ }
+ send_ok(&thd->net, result);
+ }
+
+exit:
+ start_waiting_global_read_lock(thd);
+exit2:
+ VOID(pthread_mutex_unlock(&LOCK_mysql_create_db));
+ DBUG_RETURN(error);
+}
+
+
+/* db-name is already validated when we come here */
+
+int mysql_alter_db(THD *thd, char *db, HA_CREATE_INFO *create_info, bool silent)
+{
+ char path[FN_REFLEN+16];
+ MY_DIR *dirp;
+ long result=1;
+ int error = 0;
+ DBUG_ENTER("mysql_create_db");
+ register File file;
+ uint create_options = create_info ? create_info->options : 0;
+
+ VOID(pthread_mutex_lock(&LOCK_mysql_create_db));
+
+ // do not alter database if another thread is holding read lock
+ if (wait_if_global_read_lock(thd,0))
+ {
+ error= -1;
+ goto exit2;
+ }
+
+ /* Check directory */
+ (void)sprintf(path,"%s/%s", mysql_data_home, db);
+ strcat(path,"/");
+ unpack_dirname(path,path); // Convert if not unix
+ strcat(path,MY_DB_OPT_FILE);
+ if ((error=write_db_opt(thd,db,create_info,path)))
+ goto exit;
+
+ /*
+ Change options if current
+ database is being altered
+ */
+ if (thd->db && !strcmp(thd->db,db))
+ {
+ thd->db_charset= create_info ? create_info->table_charset : NULL;
+ }
+
+ if (!silent)
+ {
+ if (!thd->query)
+ {
+ thd->query = path;
+ thd->query_length = (uint) (strxmov(path,"alter database ", db, NullS)-
+ path);
+ }
+ {
+ mysql_update_log.write(thd,thd->query, thd->query_length);
+ if (mysql_bin_log.is_open())
+ {
Query_log_event qinfo(thd, thd->query, thd->query_length);
mysql_bin_log.write(&qinfo);
}
@@ -104,7 +274,11 @@ exit2:
DBUG_RETURN(error);
}
-const char *del_exts[]= {".frm", ".BAK", ".TMD", NullS};
+
+
+
+
+const char *del_exts[]= {".frm", ".BAK", ".TMD",".opt", NullS};
static TYPELIB deletable_extentions=
{array_elements(del_exts)-1,"del_exts", del_exts};
@@ -220,7 +394,8 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
DBUG_PRINT("info",("Examining: %s", file->name));
/* Check if file is a raid directory */
- if (isdigit(file->name[0]) && isdigit(file->name[1]) &&
+ if (my_isdigit(system_charset_info,file->name[0]) &&
+ my_isdigit(system_charset_info,file->name[1]) &&
!file->name[2] && !level)
{
char newpath[FN_REFLEN];
@@ -245,7 +420,8 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
continue;
}
strxmov(filePath,org_path,"/",file->name,NullS);
- if (db && !my_strcasecmp(fn_ext(file->name), reg_ext))
+ if (db && !my_strcasecmp(system_charset_info,
+ fn_ext(file->name), reg_ext))
{
/* Drop the table nicely */
*fn_ext(file->name)=0; // Remove extension
@@ -333,6 +509,8 @@ bool mysql_change_db(THD *thd,const char *name)
char *dbname=my_strdup((char*) name,MYF(MY_WME));
char path[FN_REFLEN];
uint db_access;
+ HA_CREATE_INFO create;
+
DBUG_ENTER("mysql_change_db");
if (!dbname || !(db_length=strip_sp(dbname)))
@@ -385,5 +563,102 @@ bool mysql_change_db(THD *thd,const char *name)
thd->db=dbname;
thd->db_length=db_length;
thd->db_access=db_access;
+
+ strcat(path,"/");
+ unpack_dirname(path,path);
+ strcat(path,MY_DB_OPT_FILE);
+ bzero(&create,sizeof(create));
+ load_db_opt(thd,name,&create,path);
+ thd->db_charset=create.table_charset;
+
+ DBUG_RETURN(0);
+}
+
+
+int mysqld_show_create_db(THD *thd,const char *name)
+{
+ int length, db_length;
+ char *dbname=my_strdup((char*) name,MYF(MY_WME));
+ char path[FN_REFLEN];
+ uint db_access;
+ HA_CREATE_INFO create;
+ CONVERT *convert=thd->convert_set;
+
+ DBUG_ENTER("mysql_show_create_db");
+
+ if (!dbname || !(db_length=strip_sp(dbname)))
+ {
+ x_free(dbname); /* purecov: inspected */
+ send_error(&thd->net,ER_NO_DB_ERROR); /* purecov: inspected */
+ DBUG_RETURN(1); /* purecov: inspected */
+ }
+
+ if ((db_length > NAME_LEN) || check_db_name(dbname))
+ {
+ net_printf(&thd->net,ER_WRONG_DB_NAME, dbname);
+ x_free(dbname);
+ DBUG_RETURN(1);
+ }
+
+ if (test_all_bits(thd->master_access,DB_ACLS))
+ db_access=DB_ACLS;
+ else
+ db_access= (acl_get(thd->host,thd->ip,(char*) &thd->remote.sin_addr,
+ thd->priv_user,dbname) |
+ thd->master_access);
+ if (!(db_access & DB_ACLS) && (!grant_option || check_grant_db(thd,dbname)))
+ {
+ net_printf(&thd->net,ER_DBACCESS_DENIED_ERROR,
+ thd->priv_user,
+ thd->host_or_ip,
+ dbname);
+ mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR),
+ thd->priv_user,
+ thd->host_or_ip,
+ dbname);
+ my_free(dbname,MYF(0));
+ DBUG_RETURN(1);
+ }
+
+ (void) sprintf(path,"%s/%s",mysql_data_home,dbname);
+ length=unpack_dirname(path,path); // Convert if not unix
+ if (length && path[length-1] == FN_LIBCHAR)
+ path[length-1]=0; // remove ending '\'
+ if (access(path,F_OK))
+ {
+ net_printf(&thd->net,ER_BAD_DB_ERROR,dbname);
+ my_free(dbname,MYF(0));
+ DBUG_RETURN(1);
+ }
+
+ strcat(path,"/");
+ unpack_dirname(path,path);
+ strcat(path,MY_DB_OPT_FILE);
+ bzero(&create,sizeof(create));
+ load_db_opt(thd,name,&create,path);
+
+ List<Item> field_list;
+ field_list.push_back(new Item_empty_string("Database",NAME_LEN));
+ field_list.push_back(new Item_empty_string("Create Database",1024));
+
+ if (send_fields(thd,field_list,1))
+ DBUG_RETURN(1);
+
+ String *packet = &thd->packet;
+ packet->length(0);
+ net_store_data(packet, convert, name);
+ sprintf(path, "CREATE DATABASE %s", name);
+ if (create.table_charset)
+ {
+ strcat(path," DEFAULT CHARACTER SET ");
+ strcat(path,create.table_charset->name);
+ }
+ net_store_data(packet, convert, path);
+
+ if (my_net_write(&thd->net,(char*) packet->ptr(),packet->length()))
+ DBUG_RETURN(1);
+
+ send_eof(&thd->net);
+
DBUG_RETURN(0);
}
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index eaa8c6c2a67..fc98cfb90c5 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -222,9 +222,10 @@ multi_delete::multi_delete(THD *thd_arg, TABLE_LIST *dt,
int
-multi_delete::prepare(List<Item> &values)
+multi_delete::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
{
DBUG_ENTER("multi_delete::prepare");
+ unit= u;
do_delete = true;
thd->proc_info="deleting from main table";
@@ -520,8 +521,9 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
table->file->info(HA_STATUS_AUTO | HA_STATUS_NO_LOCK);
bzero((char*) &create_info,sizeof(create_info));
create_info.auto_increment_value= table->file->auto_increment_value;
- db_type table_type=table->db_type;
+ create_info.table_charset=default_charset_info;
+ db_type table_type=table->db_type;
strmov(path,table->path);
*table_ptr= table->next; // Unlink table from list
close_temporary(table,0);
@@ -532,8 +534,8 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
table_list->real_name, 1))))
(void) rm_temporary_table(table_type, path);
/*
- Sasha: if we return here we will not have binloged the truncation and
- we will not send_ok() to the client.
+ If we return here we will not have logged the truncation to the bin log
+ and we will not send_ok() to the client.
*/
goto end;
}
@@ -562,6 +564,8 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
}
bzero((char*) &create_info,sizeof(create_info));
+ create_info.table_charset=default_charset_info;
+
*fn_ext(path)=0; // Remove the .frm extension
error= ha_create_table(path,&create_info,1) ? -1 : 0;
query_cache_invalidate3(thd, table_list, 0);
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc
new file mode 100644
index 00000000000..fb40a85fd91
--- /dev/null
+++ b/sql/sql_derived.cc
@@ -0,0 +1,126 @@
+/* Copyright (C) 2000 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+/*
+ Derived tables
+ These were introduced by Monty and Sinisa <sinisa@mysql.com>
+*/
+
+
+#include "mysql_priv.h"
+#include "sql_select.h"
+#include "sql_acl.h"
+
+static const char *any_db="*any*"; // Special symbol for check_access
+
+
+int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t)
+{
+ /*
+ TODO: make derived tables with union inside (now only 1 SELECT may be
+ procesed)
+ */
+ SELECT_LEX *sl= unit->first_select();
+ List<Item> item_list;
+ TABLE *table;
+ int res;
+ select_union *derived_result;
+ TABLE_LIST *tables= (TABLE_LIST *)sl->table_list.first;
+ TMP_TABLE_PARAM tmp_table_param;
+ DBUG_ENTER("mysql_derived");
+
+ if (tables)
+ res= check_table_access(thd,SELECT_ACL, tables);
+ else
+ res= check_access(thd, SELECT_ACL, any_db);
+ if (res)
+ DBUG_RETURN(-1);
+
+ for (TABLE_LIST *cursor= (TABLE_LIST *)tables;
+ cursor;
+ cursor=cursor->next)
+ {
+ if (cursor->derived)
+ {
+ res=mysql_derived(thd, lex, (SELECT_LEX_UNIT *)cursor->derived, cursor);
+ if (res) DBUG_RETURN(res);
+ }
+ }
+ Item *item;
+ List_iterator<Item> it(sl->item_list);
+
+ while ((item= it++))
+ item_list.push_back(item);
+
+ if (!(res=open_and_lock_tables(thd,tables)))
+ {
+ if (tables && setup_fields(thd,tables,item_list,0,0,1))
+ {
+ res=-1;
+ goto exit;
+ }
+ bzero((char*) &tmp_table_param,sizeof(tmp_table_param));
+ tmp_table_param.field_count=item_list.elements;
+ if (!(table=create_tmp_table(thd, &tmp_table_param, item_list,
+ (ORDER*) 0, 0, 1, 0,
+ (sl->options | thd->options |
+ TMP_TABLE_ALL_COLUMNS),
+ unit)))
+ {
+ res=-1;
+ goto exit;
+ }
+
+ if ((derived_result=new select_union(table)))
+ {
+ unit->offset_limit_cnt= sl->offset_limit;
+ unit->select_limit_cnt= sl->select_limit+sl->offset_limit;
+ if (unit->select_limit_cnt < sl->select_limit)
+ unit->select_limit_cnt= HA_POS_ERROR;
+ if (unit->select_limit_cnt == HA_POS_ERROR)
+ sl->options&= ~OPTION_FOUND_ROWS;
+
+ res=mysql_select(thd, tables, sl->item_list,
+ sl->where, (ORDER *) sl->order_list.first,
+ (ORDER*) sl->group_list.first,
+ sl->having, (ORDER*) NULL,
+ sl->options | thd->options | SELECT_NO_UNLOCK,
+ derived_result, unit);
+ if (!res)
+ {
+// Here we entirely fix both TABLE_LIST and list of SELECT's as there were no derived tables
+ if (derived_result->flush())
+ res=1;
+ else
+ {
+ t->real_name=table->real_name;
+ t->table=table;
+ sl->exclude();
+ t->derived=(SELECT_LEX *)0; // just in case ...
+ }
+ }
+ delete derived_result;
+ }
+ if (res)
+ free_tmp_table(thd,table);
+exit:
+ close_thread_tables(thd);
+ if (res > 0)
+ send_error(&thd->net, ER_UNKNOWN_COM_ERROR); // temporary only ...
+ }
+ DBUG_RETURN(res);
+}
diff --git a/sql/sql_error.cc b/sql/sql_error.cc
new file mode 100644
index 00000000000..13466f454c5
--- /dev/null
+++ b/sql/sql_error.cc
@@ -0,0 +1,219 @@
+/* Copyright (C) 1995-2002 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/**********************************************************************
+This file contains the implementation of error and warnings related
+
+ - Whenever an error or warning occured, it pushes the same to
+ the respective list along with sending it to client.
+
+ - When client requests the information using SHOW command, then
+ server processes from this list and returns back in the form of
+ resultset.
+
+ syntax : SHOW [COUNT(*)] ERRORS [LIMIT [offset,] rows]
+ SHOW [COUNT(*)] WARNINGS [LIMIT [offset,] rows]
+
+***********************************************************************/
+/* Handles errors and warnings .. */
+
+#include "mysql_priv.h"
+
+/*
+ Push the error to error list
+*/
+
+void push_error(uint code, const char *msg)
+{
+ THD *thd=current_thd;
+
+ mysql_st_error *err = new mysql_st_error(code,msg,(const char*)thd->query);
+
+ if (thd->err_list.elements >= thd->max_error_count)
+ {
+ /* Remove the old elements and always maintain the max size
+ equal to sql_error_count.
+
+ If one max_error_count using sets sql_error_count less than
+ the current list size, then make sure it always grows upto
+ sql_error_count size only
+
+ ** BUG ** : Doesn't work in removing the old one
+ from the list, and thus SET SQL_ERROR_COUNT=x doesn't work
+ */
+ for (uint count=thd->err_list.elements-1;
+ count <= thd->max_error_count-1; count++)
+ {
+ thd->err_list.remove_last();
+ }
+ }
+ thd->err_list.push_front(err);
+}
+
+/*
+ Push the warning to warning list
+*/
+
+void push_warning(uint code, const char *msg)
+{
+ THD *thd=current_thd;
+
+ mysql_st_error *warn = new mysql_st_error(code,msg,(const char *)thd->query);
+
+ if (thd->warn_list.elements >= thd->max_warning_count)
+ {
+ /* Remove the old elements and always maintian the max size
+ equal to sql_error_count
+ */
+ for (uint count=thd->warn_list.elements;
+ count <= thd->max_warning_count-1; count++)
+ {
+ thd->warn_list.remove_last();
+ }
+ }
+ thd->warn_list.push_front(warn);
+}
+
+/*
+ List all errors
+*/
+
+int mysqld_show_errors(THD *thd)
+{
+ List<Item> field_list;
+ DBUG_ENTER("mysqld_show_errors");
+
+ field_list.push_back(new Item_int("CODE",0,4));
+ field_list.push_back(new Item_empty_string("MESSAGE",MYSQL_ERRMSG_SIZE));
+ field_list.push_back(new Item_empty_string("QUERY",NAME_LEN));
+
+ if (send_fields(thd,field_list,1))
+ DBUG_RETURN(1);
+
+ mysql_st_error *err;
+ SELECT_LEX *sel=&thd->lex.select_lex;
+ ha_rows offset = sel->offset_limit,limit = sel->select_limit;
+ uint num_rows = 0;
+
+ Error_iterator<mysql_st_error> it(thd->err_list);
+
+ while(offset-- && (err = it++));/* Should be fixed with overloaded
+ operator '+' or with new funtion
+ goto() in list ?
+ */
+
+ while((num_rows++ < limit) && (err = it++))
+ {
+ thd->packet.length(0);
+ net_store_data(&thd->packet,(uint32)err->code);
+ net_store_data(&thd->packet,err->msg);
+ net_store_data(&thd->packet,err->query);
+
+ if (my_net_write(&thd->net,(char*)thd->packet.ptr(),thd->packet.length()))
+ DBUG_RETURN(-1);
+ }
+ send_eof(&thd->net);
+ DBUG_RETURN(0);
+}
+
+/*
+ Return errors count
+*/
+
+int mysqld_show_errors_count(THD *thd)
+{
+ List<Item> field_list;
+ DBUG_ENTER("mysqld_show_errors_count");
+
+ field_list.push_back(new Item_int("COUNT(*)",0,4));
+
+ if (send_fields(thd,field_list,1))
+ DBUG_RETURN(1);
+
+ thd->packet.length(0);
+ net_store_data(&thd->packet,(uint32)thd->err_list.elements);
+
+ if (my_net_write(&thd->net,(char*) thd->packet.ptr(),thd->packet.length()))
+ DBUG_RETURN(-1);
+
+ send_eof(&thd->net);
+ DBUG_RETURN(0);
+}
+
+/*
+ List all warnings
+*/
+
+int mysqld_show_warnings(THD *thd)
+{
+ List<Item> field_list;
+ DBUG_ENTER("mysqld_show_warnings");
+
+ field_list.push_back(new Item_int("CODE",0,21));
+ field_list.push_back(new Item_empty_string("MESSAGE",MYSQL_ERRMSG_SIZE));
+ field_list.push_back(new Item_empty_string("QUERY",NAME_LEN));
+
+ if (send_fields(thd,field_list,1))
+ DBUG_RETURN(1);
+
+ mysql_st_error *warn;
+
+
+ SELECT_LEX *sel=&thd->lex.select_lex;
+ ha_rows offset = sel->offset_limit,limit = sel->select_limit;
+ uint num_rows = 0;
+
+ Error_iterator<mysql_st_error> it(thd->warn_list);
+ while(offset-- && (warn = it++));
+ while((num_rows++ < limit) && (warn = it++))
+ {
+ thd->packet.length(0);
+ net_store_data(&thd->packet,(uint32)warn->code);
+ net_store_data(&thd->packet,warn->msg);
+ net_store_data(&thd->packet,warn->query);
+
+ if (my_net_write(&thd->net,(char*) thd->packet.ptr(),thd->packet.length()))
+ DBUG_RETURN(-1);
+ }
+ send_eof(&thd->net);
+ DBUG_RETURN(0);
+}
+
+/*
+ Return warnings count
+*/
+
+int mysqld_show_warnings_count(THD *thd)
+{
+ List<Item> field_list;
+ DBUG_ENTER("mysqld_show_warnings_count");
+
+ field_list.push_back(new Item_int("COUNT(*)",0,21));
+
+ if (send_fields(thd,field_list,1))
+ DBUG_RETURN(1);
+
+ thd->packet.length(0);
+ net_store_data(&thd->packet,(uint32)thd->warn_list.elements);
+
+ if (my_net_write(&thd->net,(char*)thd->packet.ptr(),thd->packet.length()))
+ DBUG_RETURN(-1);
+
+ send_eof(&thd->net);
+ DBUG_RETURN(0);
+}
+
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index 046ab87d18b..7fa24faf6c4 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -106,7 +106,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
}
tables->table=table;
- if (cond && cond->fix_fields(thd,tables))
+ if (cond && cond->fix_fields(thd, tables, &cond))
return -1;
if (keyname)
@@ -180,7 +180,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
Item *item;
for (key_len=0 ; (item=it_ke++) ; key_part++)
{
- item->save_in_field(key_part->field);
+ (void) item->save_in_field(key_part->field);
key_len+=key_part->store_length;
}
if (!(key= (byte*) sql_calloc(ALIGN_SIZE(key_len))))
@@ -271,7 +271,7 @@ static TABLE **find_table_ptr_by_name(THD *thd, const char *db,
for (TABLE *table=*ptr; table ; table=*ptr)
{
if (!memcmp(table->table_cache_key, db, dblen) &&
- !my_strcasecmp(table->table_name,table_name))
+ !my_strcasecmp(system_charset_info,table->table_name,table_name))
break;
ptr=&(table->next);
}
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 5624ef0539c..b02fd99e358 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -44,7 +44,7 @@ static void unlink_blobs(register TABLE *table);
Resets form->time_stamp if a timestamp value is set
*/
-static int
+int
check_insert_fields(THD *thd,TABLE *table,List<Item> &fields,
List<Item> &values, ulong counter)
{
@@ -1274,10 +1274,11 @@ bool delayed_insert::handle_inserts(void)
***************************************************************************/
int
-select_insert::prepare(List<Item> &values)
+select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
{
DBUG_ENTER("select_insert::prepare");
+ unit= u;
save_time_stamp=table->time_stamp;
if (check_insert_fields(thd,table,*fields,values,1))
DBUG_RETURN(1);
@@ -1310,9 +1311,9 @@ select_insert::~select_insert()
bool select_insert::send_data(List<Item> &values)
{
- if (thd->offset_limit)
+ if (unit->offset_limit_cnt)
{ // using limit offset,count
- thd->offset_limit--;
+ unit->offset_limit_cnt--;
return 0;
}
if (fields->elements)
@@ -1391,10 +1392,11 @@ bool select_insert::send_eof()
***************************************************************************/
int
-select_create::prepare(List<Item> &values)
+select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
{
DBUG_ENTER("select_create::prepare");
+ unit= u;
table=create_table_from_items(thd, create_info, db, name,
extra_fields, keys, &values, &lock);
if (!table)
@@ -1424,9 +1426,9 @@ select_create::prepare(List<Item> &values)
bool select_create::send_data(List<Item> &values)
{
- if (thd->offset_limit)
+ if (unit->offset_limit_cnt)
{ // using limit offset,count
- thd->offset_limit--;
+ unit->offset_limit_cnt--;
return 0;
}
fill_record(field,values);
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 9a6eb05ac5d..dc9019de2c8 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -92,15 +92,15 @@ void lex_init(void)
/* Fill state_map with states to get a faster parser */
for (i=0; i < 256 ; i++)
{
- if (isalpha(i))
+ if (my_isalpha(system_charset_info,i))
state_map[i]=(uchar) STATE_IDENT;
- else if (isdigit(i))
+ else if (my_isdigit(system_charset_info,i))
state_map[i]=(uchar) STATE_NUMBER_IDENT;
#if defined(USE_MB) && defined(USE_MB_IDENT)
- else if (use_mb(default_charset_info) && my_ismbhead(default_charset_info, i))
+ else if (use_mb(system_charset_info) && my_ismbhead(system_charset_info, i))
state_map[i]=(uchar) STATE_IDENT;
#endif
- else if (!isgraph(i))
+ else if (!my_isgraph(system_charset_info,i))
state_map[i]=(uchar) STATE_SKIP;
else
state_map[i]=(uchar) STATE_CHAR;
@@ -223,8 +223,8 @@ static char *get_text(LEX *lex)
c = yyGet();
#ifdef USE_MB
int l;
- if (use_mb(default_charset_info) &&
- (l = my_ismbchar(default_charset_info,
+ if (use_mb(system_charset_info) &&
+ (l = my_ismbchar(system_charset_info,
(const char *)lex->ptr-1,
(const char *)lex->end_of_query))) {
lex->ptr += l-1;
@@ -268,8 +268,8 @@ static char *get_text(LEX *lex)
{
#ifdef USE_MB
int l;
- if (use_mb(default_charset_info) &&
- (l = my_ismbchar(default_charset_info,
+ if (use_mb(system_charset_info) &&
+ (l = my_ismbchar(system_charset_info,
(const char *)str, (const char *)end))) {
while (l--)
*to++ = *str++;
@@ -474,11 +474,11 @@ int yylex(void *arg)
break;
}
#if defined(USE_MB) && defined(USE_MB_IDENT)
- if (use_mb(default_charset_info))
+ if (use_mb(system_charset_info))
{
- if (my_ismbhead(default_charset_info, yyGetLast()))
+ if (my_ismbhead(system_charset_info, yyGetLast()))
{
- int l = my_ismbchar(default_charset_info,
+ int l = my_ismbchar(system_charset_info,
(const char *)lex->ptr-1,
(const char *)lex->end_of_query);
if (l == 0) {
@@ -490,10 +490,10 @@ int yylex(void *arg)
while (state_map[c=yyGet()] == STATE_IDENT ||
state_map[c] == STATE_NUMBER_IDENT)
{
- if (my_ismbhead(default_charset_info, c))
+ if (my_ismbhead(system_charset_info, c))
{
int l;
- if ((l = my_ismbchar(default_charset_info,
+ if ((l = my_ismbchar(system_charset_info,
(const char *)lex->ptr-1,
(const char *)lex->end_of_query)) == 0)
break;
@@ -526,7 +526,19 @@ int yylex(void *arg)
yylval->lex_str=get_token(lex,length);
if (lex->convert_set)
lex->convert_set->convert((char*) yylval->lex_str.str,lex->yytoklen);
- return(IDENT);
+
+ /*
+ Note: "SELECT _bla AS 'alias'"
+ _bla should be considered as a IDENT if charset haven't been found.
+ So we don't use MYF(MY_WME) with get_charset_by_name to avoid
+ producing an error.
+ */
+
+ if ((yylval->lex_str.str[0]=='_') &&
+ (lex->charset=get_charset_by_name(yylval->lex_str.str+1,MYF(0))))
+ return(UNDERSCORE_CHARSET);
+ else
+ return(IDENT);
case STATE_IDENT_SEP: // Found ident and now '.'
lex->next_state=STATE_IDENT_START;// Next is an ident (not a keyword)
@@ -536,7 +548,7 @@ int yylex(void *arg)
return((int) c);
case STATE_NUMBER_IDENT: // number or ident which num-start
- while (isdigit((c = yyGet()))) ;
+ while (my_isdigit(system_charset_info,(c = yyGet()))) ;
if (state_map[c] != STATE_IDENT)
{ // Can't be identifier
state=STATE_INT_OR_REAL;
@@ -545,12 +557,13 @@ int yylex(void *arg)
if (c == 'e' || c == 'E')
{
// The following test is written this way to allow numbers of type 1e1
- if (isdigit(yyPeek()) || (c=(yyGet())) == '+' || c == '-')
+ if (my_isdigit(system_charset_info,yyPeek()) ||
+ (c=(yyGet())) == '+' || c == '-')
{ // Allow 1E+10
- if (isdigit(yyPeek())) // Number must have digit after sign
+ if (my_isdigit(system_charset_info,yyPeek())) // Number must have digit after sign
{
yySkip();
- while (isdigit(yyGet())) ;
+ while (my_isdigit(system_charset_info,yyGet())) ;
yylval->lex_str=get_token(lex,yyLength());
return(FLOAT_NUM);
}
@@ -560,7 +573,7 @@ int yylex(void *arg)
else if (c == 'x' && (lex->ptr - lex->tok_start) == 2 &&
lex->tok_start[0] == '0' )
{ // Varbinary
- while (isxdigit((c = yyGet()))) ;
+ while (my_isxdigit(system_charset_info,(c = yyGet()))) ;
if ((lex->ptr - lex->tok_start) >= 4 && state_map[c] != STATE_IDENT)
{
yylval->lex_str=get_token(lex,yyLength());
@@ -574,11 +587,11 @@ int yylex(void *arg)
// fall through
case STATE_IDENT_START: // Incomplete ident
#if defined(USE_MB) && defined(USE_MB_IDENT)
- if (use_mb(default_charset_info))
+ if (use_mb(system_charset_info))
{
- if (my_ismbhead(default_charset_info, yyGetLast()))
+ if (my_ismbhead(system_charset_info, yyGetLast()))
{
- int l = my_ismbchar(default_charset_info,
+ int l = my_ismbchar(system_charset_info,
(const char *)lex->ptr-1,
(const char *)lex->end_of_query);
if (l == 0)
@@ -591,10 +604,10 @@ int yylex(void *arg)
while (state_map[c=yyGet()] == STATE_IDENT ||
state_map[c] == STATE_NUMBER_IDENT)
{
- if (my_ismbhead(default_charset_info, c))
+ if (my_ismbhead(system_charset_info, c))
{
int l;
- if ((l = my_ismbchar(default_charset_info,
+ if ((l = my_ismbchar(system_charset_info,
(const char *)lex->ptr-1,
(const char *)lex->end_of_query)) == 0)
break;
@@ -621,15 +634,15 @@ int yylex(void *arg)
case STATE_USER_VARIABLE_DELIMITER:
lex->tok_start=lex->ptr; // Skip first `
#ifdef USE_MB
- if (use_mb(default_charset_info))
+ if (use_mb(system_charset_info))
{
while ((c=yyGet()) && state_map[c] != STATE_USER_VARIABLE_DELIMITER &&
c != (uchar) NAMES_SEP_CHAR)
{
- if (my_ismbhead(default_charset_info, c))
+ if (my_ismbhead(system_charset_info, c))
{
int l;
- if ((l = my_ismbchar(default_charset_info,
+ if ((l = my_ismbchar(system_charset_info,
(const char *)lex->ptr-1,
(const char *)lex->end_of_query)) == 0)
break;
@@ -654,17 +667,18 @@ int yylex(void *arg)
if (prev_state == STATE_OPERATOR_OR_IDENT)
{
if (c == '-' && yyPeek() == '-' &&
- (isspace(yyPeek2()) || iscntrl(yyPeek2())))
+ (my_isspace(system_charset_info,yyPeek2()) ||
+ my_iscntrl(system_charset_info,yyPeek2())))
state=STATE_COMMENT;
else
state= STATE_CHAR; // Must be operator
break;
}
- if (!isdigit(c=yyGet()) || yyPeek() == 'x')
+ if (!my_isdigit(system_charset_info,c=yyGet()) || yyPeek() == 'x')
{
if (c != '.')
{
- if (c == '-' && isspace(yyPeek()))
+ if (c == '-' && my_isspace(system_charset_info,yyPeek()))
state=STATE_COMMENT;
else
state = STATE_CHAR; // Return sign as single char
@@ -672,9 +686,9 @@ int yylex(void *arg)
}
yyUnget(); // Fix for next loop
}
- while (isdigit(c=yyGet())) ; // Incomplete real or int number
+ while (my_isdigit(system_charset_info,c=yyGet())) ; // Incomplete real or int number
if ((c == 'e' || c == 'E') &&
- (yyPeek() == '+' || yyPeek() == '-' || isdigit(yyPeek())))
+ (yyPeek() == '+' || yyPeek() == '-' || my_isdigit(system_charset_info,yyPeek())))
{ // Real number
yyUnget();
c= '.'; // Fool next test
@@ -688,19 +702,19 @@ int yylex(void *arg)
}
// fall through
case STATE_REAL: // Incomplete real number
- while (isdigit(c = yyGet())) ;
+ while (my_isdigit(system_charset_info,c = yyGet())) ;
if (c == 'e' || c == 'E')
{
c = yyGet();
if (c == '-' || c == '+')
c = yyGet(); // Skip sign
- if (!isdigit(c))
+ if (!my_isdigit(system_charset_info,c))
{ // No digit after sign
state= STATE_CHAR;
break;
}
- while (isdigit(yyGet())) ;
+ while (my_isdigit(system_charset_info,yyGet())) ;
yylval->lex_str=get_token(lex,yyLength());
return(FLOAT_NUM);
}
@@ -709,7 +723,7 @@ int yylex(void *arg)
case STATE_HEX_NUMBER: // Found x'hexstring'
yyGet(); // Skip '
- while (isxdigit((c = yyGet()))) ;
+ while (my_isxdigit(system_charset_info,(c = yyGet()))) ;
length=(lex->ptr - lex->tok_start); // Length of hexnum+3
if (!(length & 1) || c != '\'')
{
@@ -789,7 +803,7 @@ int yylex(void *arg)
ulong version=MYSQL_VERSION_ID;
yySkip();
state=STATE_START;
- if (isdigit(yyPeek()))
+ if (my_isdigit(system_charset_info,yyPeek()))
{ // Version number
version=strtol((char*) lex->ptr,(char**) &lex->ptr,10);
}
@@ -844,7 +858,7 @@ int yylex(void *arg)
// Actually real shouldn't start
// with . but allow them anyhow
case STATE_REAL_OR_POINT:
- if (isdigit(yyPeek()))
+ if (my_isdigit(system_charset_info,yyPeek()))
state = STATE_REAL; // Real
else
{
@@ -869,7 +883,7 @@ int yylex(void *arg)
return((int) '@');
case STATE_HOSTNAME: // end '@' of user@hostname
for (c=yyGet() ;
- isalnum(c) || c == '.' || c == '_' || c == '$';
+ my_isalnum(system_charset_info,c) || c == '.' || c == '_' || c == '$';
c= yyGet()) ;
yylval->lex_str=get_token(lex,yyLength());
return(LEX_HOSTNAME);
@@ -903,3 +917,199 @@ int yylex(void *arg)
}
}
}
+
+/*
+ st_select_lex structures initialisations
+*/
+
+void st_select_lex_node::init_query()
+{
+ next= master= slave= link_next= 0;
+ prev= link_prev= 0;
+}
+
+void st_select_lex_node::init_select()
+{
+ order_list.elements= 0;
+ order_list.first= 0;
+ order_list.next= (byte**) &order_list.first;
+ select_limit= HA_POS_ERROR;
+ offset_limit= 0;
+}
+
+void st_select_lex_unit::init_query()
+{
+ linkage= GLOBAL_OPTIONS_TYPE;
+ st_select_lex_node::init_query();
+ global_parameters= this;
+ select_limit_cnt= HA_POS_ERROR;
+ offset_limit_cnt= 0;
+}
+
+void st_select_lex::init_query()
+{
+ st_select_lex_node::init_query();
+ table_list.elements= 0;
+ table_list.first= 0;
+ table_list.next= (byte**) &table_list.first;
+ item_list.empty();
+}
+
+void st_select_lex::init_select()
+{
+ st_select_lex_node::init_select();
+ group_list.elements= 0;
+ group_list.first= 0;
+ group_list.next= (byte**) &group_list.first;
+ options= 0;
+ where= having= 0;
+ when_list.empty();
+ expr_list.empty();
+ interval_list.empty();
+ use_index.empty();
+ ftfunc_list.empty();
+ linkage= UNSPECIFIED_TYPE;
+ depended= having_fix_field= 0;
+}
+
+/*
+ st_select_lex structures linking
+*/
+
+/* include on level down */
+void st_select_lex_node::include_down(st_select_lex_node *upper)
+{
+ if ((next= upper->slave))
+ next->prev= &next;
+ prev= &upper->slave;
+ upper->slave= this;
+ master= upper;
+}
+
+/* include neighbour (on same level) */
+void st_select_lex_node::include_neighbour(st_select_lex_node *before)
+{
+ if ((next= before->next))
+ next->prev= &next;
+ prev= &before->next;
+ before->next= this;
+ master= before->master;
+}
+
+/* including in global SELECT_LEX list */
+void st_select_lex_node::include_global(st_select_lex_node **plink)
+{
+ if ((link_next= *plink))
+ link_next->link_prev= &link_next;
+ link_prev= plink;
+ *plink= this;
+}
+
+//excluding from global list (internal function)
+void st_select_lex_node::fast_exclude()
+{
+ if(link_prev)
+ {
+ if ((*link_prev= link_next))
+ link_next->link_prev= link_prev;
+ // Remove slave structure
+ for (; slave; slave= slave->next)
+ slave->fast_exclude();
+ }
+}
+
+/*
+ excluding select_lex structure (except first (first select can't be
+ deleted, because it is most upper select))
+*/
+void st_select_lex_node::exclude()
+{
+ //exclude from global list
+ fast_exclude();
+ //exclude from other structures
+ if ((*prev= next))
+ next->prev= prev;
+ /*
+ We do not need following statements, because prev pointer of first
+ list element point to master->slave
+ if (master->slave == this)
+ master->slave= next;
+ */
+}
+
+/*
+ This is used for UNION & subselect to create a new table list of all used
+ tables.
+ The table_list->table entry in all used tables are set to point
+ to the entries in this list.
+*/
+
+// interface
+bool st_select_lex_unit::create_total_list(THD *thd, st_lex *lex,
+ TABLE_LIST **result)
+{
+ *result= 0;
+ return create_total_list_n_last_return(thd, lex, &result);
+}
+
+// list creator
+bool st_select_lex_unit::create_total_list_n_last_return(THD *thd, st_lex *lex,
+ TABLE_LIST ***result)
+{
+ TABLE_LIST *slave_list_first=0, **slave_list_last= &slave_list_first;
+ TABLE_LIST **new_table_list= *result, *aux;
+ SELECT_LEX *sl= (SELECT_LEX*)slave;
+ for (; sl; sl= sl->next_select())
+ {
+ // check usage of ORDER BY in union
+ if (sl->order_list.first && sl->next_select() && !sl->braces)
+ {
+ net_printf(&thd->net,ER_WRONG_USAGE,"UNION","ORDER BY");
+ return 1;
+ }
+ for (SELECT_LEX_UNIT *inner= sl->first_inner_unit();
+ inner;
+ inner= inner->next_unit())
+ if (inner->create_total_list_n_last_return(thd, lex,
+ &slave_list_last))
+ return 1;
+ if ((aux= (TABLE_LIST*) sl->table_list.first))
+ {
+ TABLE_LIST *next;
+ for (; aux; aux= next)
+ {
+ TABLE_LIST *cursor;
+ next= aux->next;
+ for (cursor= **result; cursor; cursor= cursor->next)
+ if (!strcmp(cursor->db, aux->db) &&
+ !strcmp(cursor->real_name, aux->real_name) &&
+ !strcmp(cursor->name, aux->name))
+ break;
+ if (!cursor)
+ {
+ /* Add not used table to the total table list */
+ aux->lock_type= lex->lock_option;
+ if (!(cursor= (TABLE_LIST *) thd->memdup((char*) aux,
+ sizeof(*aux))))
+ {
+ send_error(&thd->net,0);
+ return 1;
+ }
+ *new_table_list= cursor;
+ new_table_list= &cursor->next;
+ *new_table_list= 0; // end result list
+ }
+ else
+ aux->shared= 1; // Mark that it's used twice
+ aux->table_list= cursor;
+ }
+ }
+ }
+ if (slave_list_first)
+ {
+ *new_table_list= slave_list_first;
+ new_table_list= slave_list_last;
+ }
+ *result= new_table_list;
+ return 0;
+}
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 9be8703b6c5..6aef99886e9 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -46,10 +46,12 @@ enum enum_sql_command {
SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_LOGS, SQLCOM_SHOW_STATUS,
SQLCOM_SHOW_INNODB_STATUS,
SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
- SQLCOM_SHOW_GRANTS, SQLCOM_SHOW_CREATE,
+ SQLCOM_SHOW_GRANTS, SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
+ SQLCOM_SHOW_CREATE_DB,
SQLCOM_LOAD,SQLCOM_SET_OPTION,SQLCOM_LOCK_TABLES,SQLCOM_UNLOCK_TABLES,
- SQLCOM_GRANT, SQLCOM_CHANGE_DB, SQLCOM_CREATE_DB, SQLCOM_DROP_DB,
+ SQLCOM_GRANT,
+ SQLCOM_CHANGE_DB, SQLCOM_CREATE_DB, SQLCOM_DROP_DB, SQLCOM_ALTER_DB,
SQLCOM_REPAIR, SQLCOM_REPLACE, SQLCOM_REPLACE_SELECT,
SQLCOM_CREATE_FUNCTION, SQLCOM_DROP_FUNCTION,
SQLCOM_REVOKE,SQLCOM_OPTIMIZE, SQLCOM_CHECK,
@@ -62,7 +64,8 @@ enum enum_sql_command {
SQLCOM_HA_OPEN, SQLCOM_HA_CLOSE, SQLCOM_HA_READ,
SQLCOM_SHOW_SLAVE_HOSTS, SQLCOM_DELETE_MULTI, SQLCOM_MULTI_UPDATE,
SQLCOM_SHOW_BINLOG_EVENTS, SQLCOM_SHOW_NEW_MASTER, SQLCOM_DO,
- SQLCOM_EMPTY_QUERY,
+ SQLCOM_SHOW_WARNS, SQLCOM_EMPTY_QUERY, SQLCOM_SHOW_ERRORS,
+ SQLCOM_SHOW_COLUMN_TYPES, SQLCOM_SHOW_TABLE_TYPES, SQLCOM_SHOW_PRIVILEGES,
SQLCOM_END
};
@@ -78,6 +81,7 @@ enum lex_states
STATE_IDENT_OR_KEYWORD
};
+
typedef List<Item> List_item;
typedef struct st_lex_master_info
@@ -93,7 +97,8 @@ typedef struct st_lex_master_info
enum sub_select_type
{
- UNSPECIFIED_TYPE, UNION_TYPE, INTERSECT_TYPE, EXCEPT_TYPE, OLAP_TYPE, NOT_A_SELECT
+ UNSPECIFIED_TYPE,UNION_TYPE, INTERSECT_TYPE,
+ EXCEPT_TYPE, GLOBAL_OPTIONS_TYPE, DERIVED_TABLE_TYPE, OLAP_TYPE
};
enum olap_type
@@ -101,27 +106,182 @@ enum olap_type
UNSPECIFIED_OLAP_TYPE, CUBE_TYPE, ROLLUP_TYPE
};
-/* The state of the lex parsing for selects */
+/*
+ The state of the lex parsing for selects
+
+ All select describing structures linked with following pointers:
+ - list of neighbors (next/prev) (prev of first element point to slave
+ pointer of upper structure)
+ - one level units for unit (union) structure
+ - member of one union(unit) for ordinary select_lex
+ - pointer to master
+ - outer select_lex for unit (union)
+ - unit structure for ordinary select_lex
+ - pointer to slave
+ - first list element of select_lex belonged to this unit for unit
+ - first unit in list of units that belong to this select_lex (as
+ subselects or derived tables) for ordinary select_lex
+ - list of all select_lex (for group operation like correcting list of opened
+ tables)
+ for example for following query:
-typedef struct st_select_lex
-{
+ select *
+ from table1
+ where table1.field IN (select * from table1_1_1 union
+ select * from table1_1_2)
+ union
+ select *
+ from table2
+ where table2.field=(select (select f1 from table2_1_1_1_1
+ where table2_1_1_1_1.f2=table2_1_1.f3)
+ from table2_1_1
+ where table2_1_1.f1=table2.f2)
+ union
+ select * from table3;
+
+ we will have following structure:
+
+
+ main unit
+ select1 select2 select3
+ |^^ |^
+ s||| ||master
+ l||| |+---------------------------------+
+ a||| +---------------------------------+|
+ v|||master slave ||
+ e||+-------------------------+ ||
+ V| neighbor | V|
+ unit 1.1<==================>unit1.2 unit2.1
+ select1.1.1 select 1.1.2 select1.2.1 select2.1.1 select2.1.2
+ |^
+ ||
+ V|
+ unit2.1.1.1
+ select2.1.1.1.1
+
+
+ relation in main unit will be following:
+
+ main unit
+ |^^^
+ ||||
+ |||+------------------------------+
+ ||+--------------+ |
+ slave||master | |
+ V| neighbor | neighbor |
+ select1<========>select2<========>select3
+
+ list of all select_lex will be following (as it will be constructed by
+ parser):
+
+ select1->select2->select3->select2.1.1->select 2.1.2->select2.1.1.1.1-+
+ |
+ +---------------------------------------------------------------------+
+ |
+ +->select1.1.1->select1.1.2
+
+*/
+
+/*
+ Base class for st_select_lex (SELECT_LEX) &
+ st_select_lex_unit (SELECT_LEX_UNIT)
+*/
+class st_select_lex_node {
+protected:
+ st_select_lex_node *next, **prev, /* neighbor list */
+ *master, *slave, /* vertical links */
+ *link_next, **link_prev; /* list of whole SELECT_LEX */
+public:
+ ulong options;
enum sub_select_type linkage;
+ SQL_LIST order_list; /* ORDER clause */
+ ha_rows select_limit, offset_limit; /* LIMIT clause parameters */
+ void init_query();
+ void init_select();
+ void include_down(st_select_lex_node *upper);
+ void include_neighbour(st_select_lex_node *before);
+ void include_global(st_select_lex_node **plink);
+ void exclude();
+private:
+ void fast_exclude();
+};
+
+/*
+ SELECT_LEX_UNIT - unit of selects (UNION, INTERSECT, ...) group
+ SELECT_LEXs
+*/
+class st_lex;
+class st_select_lex;
+class st_select_lex_unit: public st_select_lex_node {
+public:
+ /*
+ Pointer to 'last' select or pointer to unit where stored
+ global parameters for union
+ */
+ st_select_lex_node *global_parameters;
+ /* LIMIT clause runtime counters */
+ ha_rows select_limit_cnt, offset_limit_cnt;
+ void init_query();
+ bool create_total_list(THD *thd, st_lex *lex, TABLE_LIST **result);
+ st_select_lex* outer_select() { return (st_select_lex*) master; }
+ st_select_lex* first_select() { return (st_select_lex*) slave; }
+ st_select_lex_unit* next_unit() { return (st_select_lex_unit*) next; }
+
+ friend void mysql_init_query(THD *thd);
+private:
+ bool create_total_list_n_last_return(THD *thd, st_lex *lex,
+ TABLE_LIST ***result);
+};
+typedef class st_select_lex_unit SELECT_LEX_UNIT;
+
+/*
+ SELECT_LEX - store information of parsed SELECT_LEX statment
+*/
+class JOIN;
+class st_select_lex: public st_select_lex_node {
+public:
+ char *db, *db1, *table1, *db2, *table2; /* For outer join using .. */
+ Item *where, *having; /* WHERE & HAVING clauses */
enum olap_type olap;
- char *db,*db1,*table1,*db2,*table2; /* For outer join using .. */
- Item *where,*having;
- ha_rows select_limit,offset_limit;
- ulong options;
List<List_item> expr_list;
- List<List_item> when_list;
- SQL_LIST order_list,table_list,group_list;
- List<Item> item_list;
- List<String> interval_list,use_index, *use_index_ptr,
+ List<List_item> when_list; /* WHEN clause */
+ SQL_LIST table_list, group_list; /* FROM & GROUP BY clauses */
+ List<Item> item_list; /* list of fields & expressions */
+ List<String> interval_list, use_index, *use_index_ptr,
ignore_index, *ignore_index_ptr;
List<Item_func_match> ftfunc_list;
- uint in_sum_expr, sort_default;
- bool create_refs, braces;
- st_select_lex *next;
-} SELECT_LEX;
+ JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
+ uint in_sum_expr;
+ bool create_refs;
+ bool braces; /* SELECT ... UNION (SELECT ... ) <- this braces */
+ bool depended; /* depended from outer select subselect */
+ /* TRUE when having fix field called in processing of this SELECT */
+ bool having_fix_field;
+
+ void init_query();
+ void init_select();
+ st_select_lex_unit* master_unit() { return (st_select_lex_unit*) master; }
+ st_select_lex_unit* first_inner_unit()
+ {
+ return (st_select_lex_unit*) slave;
+ }
+ st_select_lex* outer_select()
+ {
+ return (st_select_lex*) master_unit()->outer_select();
+ }
+ st_select_lex* next_select() { return (st_select_lex*) next; }
+ st_select_lex* next_select_in_list()
+ {
+ return (st_select_lex*) link_next;
+ }
+ st_select_lex_node** next_select_in_list_addr()
+ {
+ return &link_next;
+ }
+
+ friend void mysql_init_query(THD *thd);
+};
+typedef class st_select_lex SELECT_LEX;
/* The state of the lex parsing. This is saved in the THD struct */
@@ -130,7 +290,10 @@ typedef struct st_lex
{
uint yylineno,yytoklen; /* Simulate lex */
LEX_YYSTYPE yylval;
- SELECT_LEX select_lex, *select, *last_selects;
+ SELECT_LEX_UNIT unit; /* most upper unit */
+ SELECT_LEX select_lex, /* first SELECT_LEX */
+ /* current SELECT_LEX in parsing */
+ *select;
uchar *ptr,*tok_start,*tok_end,*end_of_query;
char *length,*dec,*change,*name;
char *backup_dir; /* For RESTORE/BACKUP */
@@ -141,6 +304,7 @@ typedef struct st_lex
sql_exchange *exchange;
List<key_part_spec> col_list;
+ List<key_part_spec> ref_list;
List<Alter_drop> drop_list;
List<Alter_column> alter_list;
List<String> interval_list;
@@ -151,10 +315,11 @@ typedef struct st_lex
List<Item> *insert_list,field_list,value_list;
List<List_item> many_values;
List<set_var_base> var_list;
+ List<Item> param_list;
SQL_LIST proc_list, auxilliary_table_list;
TYPELIB *interval;
create_field *last_field;
- Item *default_value;
+ Item *default_value, *comment;
CONVERT *convert_set;
CONVERT *thd_convert_set; // Set with SET CHAR SET
LEX_USER *grant_user;
@@ -167,6 +332,7 @@ typedef struct st_lex
USER_RESOURCES mqh;
ulong thread_id,type;
enum_sql_command sql_command;
+ thr_lock_type lock_option;
enum lex_states next_state;
enum enum_duplicates duplicates;
enum enum_tx_isolation tx_isolation;
@@ -174,11 +340,13 @@ typedef struct st_lex
enum ha_rkey_function ha_rkey_mode;
enum enum_enable_or_disable alter_keys_onoff;
enum enum_var_type option_type;
- uint grant,grant_tot_col,which_columns, union_option;
- thr_lock_type lock_option;
- bool drop_primary,drop_if_exists,local_file, olap;
- bool in_comment,ignore_space,verbose,simple_alter;
+ uint grant, grant_tot_col, which_columns, union_option;
+ uint fk_delete_opt, fk_update_opt, fk_match_option;
+ bool drop_primary, drop_if_exists, local_file, olap;
+ bool in_comment, ignore_space, verbose, simple_alter;
+ bool derived_tables;
uint slave_thd_opt;
+ CHARSET_INFO *charset;
} LEX;
diff --git a/sql/sql_list.h b/sql/sql_list.h
index 542eef623f0..ef8a0c41a1b 100644
--- a/sql/sql_list.h
+++ b/sql/sql_list.h
@@ -82,6 +82,7 @@ public:
first=tmp.first;
last=tmp.last;
}
+ inline base_list(bool error) { }
inline bool push_back(void *info)
{
if (((*last)=new list_node(info, &end_of_list)))
@@ -122,11 +123,15 @@ public:
last= &first;
return tmp->info;
}
+ inline list_node* last_node() { return *last; }
+ inline list_node* first_node() { return first;}
inline void *head() { return first->info; }
inline void **head_ref() { return first != &end_of_list ? &first->info : 0; }
inline bool is_empty() { return first == &end_of_list ; }
inline list_node *last_ref() { return &end_of_list; }
friend class base_list_iterator;
+ friend class error_list;
+ friend class error_list_iterator;
protected:
void after(void *info,list_node *node)
@@ -204,6 +209,7 @@ public:
{
return el == &list->last_ref()->next;
}
+ friend class error_list_iterator;
};
@@ -356,3 +362,120 @@ public:
I_List_iterator(I_List<T> &a) : base_ilist_iterator(a) {}
inline T* operator++(int) { return (T*) base_ilist_iterator::next(); }
};
+
+/*
+ New error list without mem_root from THD, to have the life of the
+ allocation becomes connection level . by ovveriding new from Sql_alloc.
+*/
+class Error_alloc
+{
+public:
+ static void *operator new(size_t size)
+ {
+ return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE));
+ }
+#if 0
+ static void operator delete(void* ptr_arg, size_t size)
+ {
+ my_free((gptr)ptr_arg, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
+ }
+#endif
+ friend class error_node;
+ friend class error_list;
+};
+
+class error_node :public Error_alloc, public list_node
+{
+public:
+ static void *operator new(size_t size)
+ {
+ return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE));
+ }
+#if 0
+ static void operator delete(void* ptr_arg, size_t size)
+ {
+ my_free((gptr)ptr_arg, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
+ }
+#endif
+ error_node(void *info_par,list_node *next_par):list_node(info_par,next_par){};
+ error_node() : list_node() {};
+ friend class error_list;
+ friend class error_list_iterator;
+};
+
+class error_list: public Error_alloc, public base_list
+{
+public:
+ inline error_list() : base_list() { };
+ inline error_list(const error_list &tmp) : base_list(tmp)
+ {
+ elements=tmp.elements;
+ first=tmp.first;
+ last=tmp.last;
+ }
+ inline bool push_front(void *info)
+ {
+ error_node *node=new error_node(info,first);
+ if (node)
+ {
+ if (last == &first)
+ last= &node->next;
+ first=node;
+ elements++;
+ return 0;
+ }
+ return 1;
+ }
+ inline void remove_last(void)
+ {
+ remove(last);
+ }
+protected:
+ void after(void *info,list_node *node)
+ {
+ error_node *new_node=new error_node(info,node->next);
+ node->next=new_node;
+ elements++;
+ if (last == &(node->next))
+ last= &new_node->next;
+ }
+};
+
+class error_list_iterator : public base_list_iterator
+{
+ inline error_list_iterator(base_list &base_ptr): base_list_iterator(base_ptr) {};
+};
+
+template <class T> class Error :public error_list
+{
+public:
+ inline Error() :error_list() {}
+ inline Error(const Error<T> &tmp) :error_list(tmp) {}
+ inline bool push_back(T *a) { return error_list::push_back(a); }
+ inline bool push_front(T *a) { return error_list::push_front(a); }
+ inline T* head() {return (T*) error_list::head(); }
+ inline T** head_ref() {return (T**) error_list::head_ref(); }
+ inline T* pop() {return (T*) error_list::pop(); }
+ void delete_elements(void)
+ {
+ error_node *element,*next;
+ for (element=first; element != &error_end_of_list; element=next)
+ {
+ next=element->next;
+ delete (T*) element->info;
+ }
+ empty();
+ }
+};
+
+template <class T> class Error_iterator :public base_list_iterator
+{
+public:
+ Error_iterator(Error<T> &a) : base_list_iterator(a) {}
+ inline T* operator++(int) { return (T*) base_list_iterator::next(); }
+ inline T *replace(T *a) { return (T*) base_list_iterator::replace(a); }
+ inline T *replace(Error<T> &a) { return (T*) base_list_iterator::replace(a); }
+ inline void after(T *a) { base_list_iterator::after(a); }
+ inline T** ref(void) { return (T**) base_list_iterator::ref(); }
+};
+
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 50e0ea9d5c8..ad25ef85e75 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -368,7 +368,7 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields,
field->field_length)
length=field->field_length;
save_chr=pos[length]; pos[length]='\0'; // Safeguard aganst malloc
- field->store((char*) pos,length);
+ field->store((char*) pos,length,default_charset_info);
pos[length]=save_chr;
if ((pos+=length) > read_info.row_end)
pos= read_info.row_end; /* Fills rest with space */
@@ -437,7 +437,7 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
}
field->set_notnull();
read_info.row_end[0]=0; // Safe to change end marker
- field->store((char*) read_info.row_start,length);
+ field->store((char*) read_info.row_start,length,default_charset_info);
}
if (read_info.error)
break;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index e38a3a5d340..b889b9ee29f 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -62,12 +62,10 @@ static void decrease_user_connections(USER_CONN *uc);
static bool check_db_used(THD *thd,TABLE_LIST *tables);
static bool check_merge_table_access(THD *thd, char *db, TABLE_LIST *tables);
static bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
-static void mysql_init_query(THD *thd);
static void remove_escape(char *name);
static void refresh_status(void);
static bool append_file_to_dir(THD *thd, char **filename_ptr,
char *table_name);
-static bool create_total_list(THD *thd, LEX *lex, TABLE_LIST **result);
const char *any_db="*any*"; // Special symbol for check_access
@@ -75,7 +73,8 @@ const char *command_name[]={
"Sleep", "Quit", "Init DB", "Query", "Field List", "Create DB",
"Drop DB", "Refresh", "Shutdown", "Statistics", "Processlist",
"Connect","Kill","Debug","Ping","Time","Delayed_insert","Change user",
- "Binlog Dump","Table Dump", "Connect Out", "Register Slave"
+ "Binlog Dump","Table Dump", "Connect Out", "Register Slave",
+ "Prepare", "Prepare Execute", "Long Data"
};
bool volatile abort_slave = 0;
@@ -277,7 +276,8 @@ static void free_user(struct user_conn *uc)
void init_max_user_conn(void)
{
- (void) hash_init(&hash_user_connections,max_connections,0,0,
+ (void) hash_init(&hash_user_connections,system_charset_info,max_connections,
+ 0,0,
(hash_get_key) get_key_conn, (void (*)(void*)) free_user,
0);
}
@@ -479,7 +479,7 @@ check_connections(THD *thd)
{
/* buff[] needs to big enough to hold the server_version variable */
char buff[SERVER_VERSION_LENGTH + SCRAMBLE_LENGTH+32],*end;
- int client_flags = CLIENT_LONG_FLAG | CLIENT_CONNECT_WITH_DB;
+ int client_flags = CLIENT_LONG_FLAG | CLIENT_CONNECT_WITH_DB | CLIENT_PROTOCOL_41;
if (opt_using_transactions)
client_flags|=CLIENT_TRANSACTIONS;
@@ -730,7 +730,8 @@ pthread_handler_decl(handle_bootstrap,arg)
while (fgets(buff, thd->net.max_packet, file))
{
uint length=(uint) strlen(buff);
- while (length && (isspace(buff[length-1]) || buff[length-1] == ';'))
+ while (length && (my_isspace(system_charset_info, buff[length-1]) ||
+ buff[length-1] == ';'))
length--;
buff[length]=0;
thd->current_tablenr=0;
@@ -950,18 +951,33 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thd->password=test(passwd[0]);
break;
}
-
+ case COM_EXECUTE:
+ {
+ mysql_com_execute(thd);
+ break;
+ }
+ case COM_LONG_DATA:
+ {
+ mysql_com_longdata(thd);
+ break;
+ }
+ case COM_PREPARE:
+ {
+ mysql_com_prepare(thd,packet,packet_length);
+ break;
+ }
case COM_QUERY:
{
packet_length--; // Remove end null
/* Remove garage at start and end of query */
- while (isspace(packet[0]) && packet_length > 0)
+ while (my_isspace(system_charset_info,packet[0]) && packet_length > 0)
{
packet++;
packet_length--;
}
char *pos=packet+packet_length; // Point at end null
- while (packet_length > 0 && (pos[-1] == ';' || isspace(pos[-1])))
+ while (packet_length > 0 &&
+ (pos[-1] == ';' || my_isspace(system_charset_info,pos[-1])))
{
pos--;
packet_length--;
@@ -1225,11 +1241,12 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
void
mysql_execute_command(void)
{
- int res=0;
- THD *thd=current_thd;
+ int res= 0;
+ THD *thd= current_thd;
LEX *lex= &thd->lex;
- TABLE_LIST *tables=(TABLE_LIST*) lex->select_lex.table_list.first;
- SELECT_LEX *select_lex = lex->select;
+ TABLE_LIST *tables= (TABLE_LIST*) lex->select_lex.table_list.first;
+ SELECT_LEX *select_lex= lex->select;
+ SELECT_LEX_UNIT *unit= &lex->unit;
DBUG_ENTER("mysql_execute_command");
if (thd->slave_thread)
@@ -1258,7 +1275,18 @@ mysql_execute_command(void)
Skip if we are in the slave thread, some table rules have been given
and the table list says the query should not be replicated
*/
- if ((lex->select_lex.next && create_total_list(thd,lex,&tables)) ||
+ if (lex->derived_tables)
+ {
+ for (TABLE_LIST *cursor= tables;
+ cursor;
+ cursor= cursor->next)
+ if (cursor->derived && mysql_derived(thd, lex,
+ (SELECT_LEX_UNIT *)cursor->derived,
+ cursor))
+ DBUG_VOID_RETURN;
+ }
+ if ((lex->select_lex.next_select_in_list() &&
+ lex->unit.create_total_list(thd, lex, &tables)) ||
(table_rules_on && tables && thd->slave_thread &&
!tables_ok(thd,tables)))
DBUG_VOID_RETURN;
@@ -1286,11 +1314,12 @@ mysql_execute_command(void)
break; // Error message is given
}
- thd->offset_limit=select_lex->offset_limit;
- thd->select_limit=select_lex->select_limit+select_lex->offset_limit;
- if (thd->select_limit < select_lex->select_limit)
- thd->select_limit= HA_POS_ERROR; // no limit
- if (thd->select_limit == HA_POS_ERROR)
+ unit->offset_limit_cnt= unit->global_parameters->offset_limit;
+ unit->select_limit_cnt= unit->global_parameters->select_limit+
+ unit->global_parameters->offset_limit;
+ if (unit->select_limit_cnt < unit->global_parameters->select_limit)
+ unit->select_limit_cnt= HA_POS_ERROR; // no limit
+ if (unit->select_limit_cnt == HA_POS_ERROR)
select_lex->options&= ~OPTION_FOUND_ROWS;
if (lex->exchange)
@@ -1357,6 +1386,16 @@ mysql_execute_command(void)
res = purge_master_logs(thd, lex->to_log);
break;
}
+ case SQLCOM_SHOW_WARNS:
+ {
+ res = mysqld_show_warnings(thd);
+ break;
+ }
+ case SQLCOM_SHOW_ERRORS:
+ {
+ res = mysqld_show_errors(thd);
+ break;
+ }
case SQLCOM_SHOW_NEW_MASTER:
{
if (check_global_access(thd, REPL_SLAVE_ACL))
@@ -1531,10 +1570,11 @@ mysql_execute_command(void)
for (table = tables->next ; table ; table=table->next)
table->lock_type= lex->lock_option;
}
- thd->offset_limit=select_lex->offset_limit;
- thd->select_limit=select_lex->select_limit+select_lex->offset_limit;
- if (thd->select_limit < select_lex->select_limit)
- thd->select_limit= HA_POS_ERROR; // No limit
+ unit->offset_limit_cnt= select_lex->offset_limit;
+ unit->select_limit_cnt= select_lex->select_limit+
+ select_lex->offset_limit;
+ if (unit->select_limit_cnt < select_lex->select_limit)
+ unit->select_limit_cnt= HA_POS_ERROR; // No limit
/* Skip first table, which is the table we are creating */
lex->select_lex.table_list.first=
@@ -1556,7 +1596,7 @@ mysql_execute_command(void)
res = mysql_create_table(thd,tables->db ? tables->db : thd->db,
tables->real_name, &lex->create_info,
lex->create_list,
- lex->key_list,0, 0); // do logging
+ lex->key_list,0,0,0); // do logging
if (!res)
send_ok(&thd->net);
}
@@ -1747,6 +1787,7 @@ mysql_execute_command(void)
bzero((char*) &create_info,sizeof(create_info));
create_info.db_type=DB_TYPE_DEFAULT;
create_info.row_type=ROW_TYPE_DEFAULT;
+ create_info.table_charset=default_charset_info;
res= mysql_alter_table(thd, NullS, NullS, &create_info,
tables, lex->create_list,
lex->key_list, lex->drop_list, lex->alter_list,
@@ -1795,25 +1836,26 @@ mysql_execute_command(void)
table_count++;
auxi->lock_type=TL_WRITE;
}
+
if (select_lex->order_list.elements)
msg="ORDER BY";
else if (select_lex->select_limit && select_lex->select_limit !=
HA_POS_ERROR)
msg="LIMIT";
-
if (msg)
{
net_printf(&thd->net, ER_WRONG_USAGE, "UPDATE", msg);
res= 1;
break;
}
+
tables->grant.want_privilege=(SELECT_ACL & ~tables->grant.privilege);
if ((res=open_and_lock_tables(thd,tables)))
break;
- thd->select_limit=HA_POS_ERROR;
+ unit->select_limit_cnt= HA_POS_ERROR;
if (!setup_fields(thd,tables,select_lex->item_list,1,0,0) &&
- !setup_fields(thd,tables,lex->value_list,0,0,0) &&
- ! thd->fatal_error &&
+ !setup_fields(thd,tables,lex->value_list,0,0,0) &&
+ !thd->fatal_error &&
(result=new multi_update(thd,tables,select_lex->item_list,
lex->duplicates, lex->lock_option,
table_count)))
@@ -1827,13 +1869,13 @@ mysql_execute_command(void)
while ((item=value_list++))
total_list.push_back(item);
- res=mysql_select(thd,tables,total_list,
- select_lex->where,
- (ORDER *)NULL,(ORDER *)NULL,(Item *)NULL,
- (ORDER *)NULL,
- select_lex->options | thd->options |
- SELECT_NO_JOIN_CACHE,
- result);
+ res= mysql_select(thd, tables, total_list,
+ select_lex->where,
+ (ORDER *)NULL, (ORDER *)NULL, (Item *)NULL,
+ (ORDER *)NULL,
+ select_lex->options | thd->options |
+ SELECT_NO_JOIN_CACHE,
+ result, unit);
delete result;
}
else
@@ -1885,10 +1927,10 @@ mysql_execute_command(void)
}
select_result *result;
- thd->offset_limit=select_lex->offset_limit;
- thd->select_limit=select_lex->select_limit+select_lex->offset_limit;
- if (thd->select_limit < select_lex->select_limit)
- thd->select_limit= HA_POS_ERROR; // No limit
+ unit->offset_limit_cnt= select_lex->offset_limit;
+ unit->select_limit_cnt= select_lex->select_limit+select_lex->offset_limit;
+ if (unit->select_limit_cnt < select_lex->select_limit)
+ unit->select_limit_cnt= HA_POS_ERROR; // No limit
if (check_dup(tables->db, tables->real_name, tables->next))
{
@@ -1981,20 +2023,19 @@ mysql_execute_command(void)
goto error;
}
auxi->lock_type=walk->lock_type=TL_WRITE;
- auxi->table= (TABLE *) walk; // Remember corresponding table
+ auxi->table_list= walk; // Remember corresponding table
}
if (add_item_to_list(new Item_null()))
{
- res = -1;
+ res= -1;
break;
}
- tables->grant.want_privilege=(SELECT_ACL & ~tables->grant.privilege);
thd->proc_info="init";
if ((res=open_and_lock_tables(thd,tables)))
break;
/* Fix tables-to-be-deleted-from list to point at opened tables */
for (auxi=(TABLE_LIST*) aux_tables ; auxi ; auxi=auxi->next)
- auxi->table= ((TABLE_LIST*) auxi->table)->table;
+ auxi->table= auxi->table_list->table;
if (!thd->fatal_error && (result= new multi_delete(thd,aux_tables,
lex->lock_option,
table_count)))
@@ -2005,7 +2046,7 @@ mysql_execute_command(void)
(ORDER *)NULL,
select_lex->options | thd->options |
SELECT_NO_JOIN_CACHE,
- result);
+ result, unit);
delete result;
}
else
@@ -2052,6 +2093,15 @@ mysql_execute_command(void)
mysqld_list_processes(thd,thd->master_access & PROCESS_ACL ? NullS :
thd->priv_user,lex->verbose);
break;
+ case SQLCOM_SHOW_TABLE_TYPES:
+ res= mysqld_show_table_types(thd);
+ break;
+ case SQLCOM_SHOW_PRIVILEGES:
+ res= mysqld_show_privileges(thd);
+ break;
+ case SQLCOM_SHOW_COLUMN_TYPES:
+ res= mysqld_show_column_types(thd);
+ break;
case SQLCOM_SHOW_STATUS:
res= mysqld_show(thd,(lex->wild ? lex->wild->ptr() : NullS),status_vars,
OPT_GLOBAL);
@@ -2061,10 +2111,17 @@ mysql_execute_command(void)
init_vars, lex->option_type);
break;
case SQLCOM_SHOW_LOGS:
- {
- res= mysqld_show_logs(thd);
- break;
- }
+#ifdef DONT_ALLOW_SHOW_COMMANDS
+ send_error(&thd->net,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
+ DBUG_VOID_RETURN;
+#else
+ {
+ if (grant_option && check_access(thd, FILE_ACL, any_db))
+ goto error;
+ res= mysqld_show_logs(thd);
+ break;
+ }
+#endif
case SQLCOM_SHOW_TABLES:
/* FALL THROUGH */
#ifdef DONT_ALLOW_SHOW_COMMANDS
@@ -2099,6 +2156,9 @@ mysql_execute_command(void)
case SQLCOM_SHOW_OPEN_TABLES:
res= mysqld_show_open_tables(thd,(lex->wild ? lex->wild->ptr() : NullS));
break;
+ case SQLCOM_SHOW_CHARSETS:
+ res= mysqld_show_charsets(thd,(lex->wild ? lex->wild->ptr() : NullS));
+ break;
case SQLCOM_SHOW_FIELDS:
#ifdef DONT_ALLOW_SHOW_COMMANDS
send_error(&thd->net,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
@@ -2233,7 +2293,7 @@ mysql_execute_command(void)
casedn_str(lex->name);
if (check_access(thd,CREATE_ACL,lex->name,0,1))
break;
- res=mysql_create_db(thd,lex->name,lex->create_info.options,0);
+ res=mysql_create_db(thd,lex->name,&lex->create_info,0);
break;
}
case SQLCOM_DROP_DB:
@@ -2255,6 +2315,40 @@ mysql_execute_command(void)
res=mysql_rm_db(thd,lex->name,lex->drop_if_exists,0);
break;
}
+ case SQLCOM_ALTER_DB:
+ {
+ if (!strip_sp(lex->name) || check_db_name(lex->name))
+ {
+ net_printf(&thd->net,ER_WRONG_DB_NAME, lex->name);
+ break;
+ }
+ if (check_access(thd,ALTER_ACL,lex->name,0,1))
+ break;
+ if (thd->locked_tables || thd->active_transaction())
+ {
+ send_error(&thd->net,ER_LOCK_OR_ACTIVE_TRANSACTION);
+ goto error;
+ }
+ res=mysql_alter_db(thd,lex->name,&lex->create_info,0);
+ break;
+ }
+ case SQLCOM_SHOW_CREATE_DB:
+ {
+ if (!strip_sp(lex->name) || check_db_name(lex->name))
+ {
+ net_printf(&thd->net,ER_WRONG_DB_NAME, lex->name);
+ break;
+ }
+ if (check_access(thd,DROP_ACL,lex->name,0,1))
+ break;
+ if (thd->locked_tables || thd->active_transaction())
+ {
+ send_error(&thd->net,ER_LOCK_OR_ACTIVE_TRANSACTION);
+ goto error;
+ }
+ res=mysqld_show_create_db(thd,lex->name);
+ break;
+ }
case SQLCOM_CREATE_FUNCTION:
if (check_access(thd,INSERT_ACL,"mysql",0,1))
break;
@@ -2298,7 +2392,8 @@ mysql_execute_command(void)
if (user->password.str &&
(strcmp(thd->user,user->user.str) ||
user->host.str &&
- my_strcasecmp(user->host.str, thd->host_or_ip)))
+ my_strcasecmp(system_charset_info,
+ user->host.str, thd->host_or_ip)))
{
if (check_access(thd, UPDATE_ACL, "mysql",0,1))
goto error;
@@ -2686,81 +2781,89 @@ bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, int *yystacksize)
Initialize global thd variables needed for query
****************************************************************************/
-static void
+void
mysql_init_query(THD *thd)
{
DBUG_ENTER("mysql_init_query");
- thd->lex.select_lex.item_list.empty();
+ thd->lex.unit.init_query();
+ thd->lex.unit.init_select();
+ thd->lex.select_lex.init_query();
+ thd->lex.unit.slave= &thd->lex.select_lex;
+ thd->lex.unit.global_parameters= &thd->lex.select_lex; //Global limit & order
+ thd->lex.select_lex.master= &thd->lex.unit;
+ thd->lex.select_lex.prev= &thd->lex.unit.slave;
thd->lex.value_list.empty();
- thd->lex.select_lex.table_list.elements=0;
- thd->free_list=0; thd->lex.union_option=0;
- thd->lex.select = &thd->lex.select_lex;
- thd->lex.select_lex.table_list.first=0;
- thd->lex.select_lex.table_list.next= (byte**) &thd->lex.select_lex.table_list.first;
- thd->lex.select_lex.next=0;
+ thd->free_list= 0;
+ thd->lex.union_option= 0;
+ thd->lex.select= &thd->lex.select_lex;
thd->lex.olap=0;
thd->lex.select->olap= UNSPECIFIED_OLAP_TYPE;
- thd->fatal_error=0; // Safety
- thd->last_insert_id_used=thd->query_start_used=thd->insert_id_used=0;
- thd->sent_row_count=thd->examined_row_count=0;
- thd->safe_to_cache_query=1;
+ thd->fatal_error= 0; // Safety
+ thd->last_insert_id_used= thd->query_start_used= thd->insert_id_used=0;
+ thd->sent_row_count= thd->examined_row_count= 0;
+ thd->safe_to_cache_query= 1;
+ thd->param_count=0;
+ thd->prepare_command=false;
+ thd->lex.param_list.empty();
DBUG_VOID_RETURN;
}
void
mysql_init_select(LEX *lex)
{
- SELECT_LEX *select_lex = lex->select;
- select_lex->where=select_lex->having=0;
- select_lex->select_limit= lex->thd->variables.select_limit;
- select_lex->offset_limit=0;
- select_lex->options=0;
- select_lex->linkage=UNSPECIFIED_TYPE;
+ SELECT_LEX *select_lex= lex->select;
+ select_lex->init_select();
+ select_lex->master_unit()->select_limit= select_lex->select_limit=
+ lex->thd->variables.select_limit;
select_lex->olap= UNSPECIFIED_OLAP_TYPE;
- lex->exchange = 0;
- lex->proc_list.first=0;
- select_lex->order_list.elements=select_lex->group_list.elements=0;
- select_lex->order_list.first=0;
- select_lex->order_list.next= (byte**) &select_lex->order_list.first;
- select_lex->group_list.first=0;
- select_lex->group_list.next= (byte**) &select_lex->group_list.first;
- select_lex->next = (SELECT_LEX *)NULL;
+ lex->exchange= 0;
+ lex->proc_list.first= 0;
}
bool
-mysql_new_select(LEX *lex)
+mysql_new_select(LEX *lex, bool move_down)
{
SELECT_LEX *select_lex = (SELECT_LEX *) lex->thd->calloc(sizeof(SELECT_LEX));
if (!select_lex)
return 1;
- lex->select->next=select_lex;
- lex->select=select_lex;
- select_lex->table_list.next= (byte**) &select_lex->table_list.first;
- select_lex->item_list.empty();
- select_lex->when_list.empty();
- select_lex->expr_list.empty();
- select_lex->interval_list.empty();
- select_lex->use_index.empty();
- select_lex->ftfunc_list.empty();
+ select_lex->init_query();
+ select_lex->init_select();
+ if (move_down)
+ {
+ /* first select_lex of subselect or derived table */
+ SELECT_LEX_UNIT *unit=
+ (SELECT_LEX_UNIT *) lex->thd->calloc(sizeof(SELECT_LEX_UNIT));
+ if (!unit)
+ return 1;
+ unit->init_query();
+ unit->init_select();
+ unit->include_down(lex->select);
+ select_lex->include_down(unit);
+ }
+ else
+ select_lex->include_neighbour(lex->select);
+
+ select_lex->master_unit()->global_parameters= select_lex;
+ select_lex->include_global(lex->select->next_select_in_list_addr());
+ lex->select= select_lex;
return 0;
}
void mysql_init_multi_delete(LEX *lex)
{
- lex->sql_command = SQLCOM_DELETE_MULTI;
+ lex->sql_command= SQLCOM_DELETE_MULTI;
mysql_init_select(lex);
- lex->select->select_limit=lex->thd->select_limit=HA_POS_ERROR;
- lex->auxilliary_table_list=lex->select_lex.table_list;
- lex->select->table_list.elements=0;
- lex->select->table_list.first=0;
- lex->select->table_list.next= (byte**) &(lex->select->table_list.first);
+ lex->select->select_limit= lex->select->master_unit()->select_limit_cnt=
+ HA_POS_ERROR;
+ lex->auxilliary_table_list= lex->select_lex.table_list;
+ lex->select->init_query();
}
void
-mysql_parse(THD *thd,char *inBuf,uint length)
+mysql_parse(THD *thd, char *inBuf, uint length)
{
DBUG_ENTER("mysql_parse");
@@ -2813,8 +2916,9 @@ link_in_list(SQL_LIST *list,byte *element,byte **next)
bool add_field_to_list(char *field_name, enum_field_types type,
char *length, char *decimals,
- uint type_modifier, Item *default_value,char *change,
- TYPELIB *interval)
+ uint type_modifier,
+ Item *default_value, Item *comment,
+ char *change, TYPELIB *interval, CHARSET_INFO *cs)
{
register create_field *new_field;
THD *thd=current_thd;
@@ -2830,14 +2934,14 @@ bool add_field_to_list(char *field_name, enum_field_types type,
if (type_modifier & PRI_KEY_FLAG)
{
lex->col_list.push_back(new key_part_spec(field_name,0));
- lex->key_list.push_back(new Key(Key::PRIMARY,NullS,
+ lex->key_list.push_back(new Key(Key::PRIMARY, NullS, HA_KEY_ALG_UNDEF,
lex->col_list));
lex->col_list.empty();
}
if (type_modifier & (UNIQUE_FLAG | UNIQUE_KEY_FLAG))
{
lex->col_list.push_back(new key_part_spec(field_name,0));
- lex->key_list.push_back(new Key(Key::UNIQUE,NullS,
+ lex->key_list.push_back(new Key(Key::UNIQUE, NullS, HA_KEY_ALG_UNDEF,
lex->col_list));
lex->col_list.empty();
}
@@ -2867,6 +2971,19 @@ bool add_field_to_list(char *field_name, enum_field_types type,
new_field->change=change;
new_field->interval=0;
new_field->pack_length=0;
+ new_field->charset=cs;
+
+ if (!comment)
+ {
+ new_field->comment.str=0;
+ new_field->comment.length=0;
+ }
+ else
+ {
+ /* In this case comment is always of type Item_string */
+ new_field->comment.str= (char*) comment->str_value.ptr();
+ new_field->comment.length=comment->str_value.length();
+ }
if (length)
if (!(new_field->length= (uint) atoi(length)))
length=0; /* purecov: inspected */
@@ -3111,8 +3228,8 @@ static void remove_escape(char *name)
#ifdef USE_MB
int l;
/* if ((l = ismbchar(name, name+MBMAXLEN))) { Wei He: I think it's wrong */
- if (use_mb(default_charset_info) &&
- (l = my_ismbchar(default_charset_info, name, strend)))
+ if (use_mb(system_charset_info) &&
+ (l = my_ismbchar(system_charset_info, name, strend)))
{
while (l--)
*to++ = *name++;
@@ -3166,7 +3283,7 @@ TABLE_LIST *add_table_to_list(Table_ident *table, LEX_STRING *alias,
DBUG_RETURN(0); // End of memory
alias_str= alias ? alias->str : table->table.str;
if (table->table.length > NAME_LEN ||
- check_table_name(table->table.str,table->table.length) ||
+ (table->table.length && check_table_name(table->table.str,table->table.length)) ||
table->db.str && check_db_name(table->db.str))
{
net_printf(&thd->net,ER_WRONG_TABLE_NAME,table->table.str);
@@ -3198,13 +3315,14 @@ TABLE_LIST *add_table_to_list(Table_ident *table, LEX_STRING *alias,
ptr->name=alias_str;
if (lower_case_table_names)
{
- casedn_str(ptr->db);
- casedn_str(table->table.str);
+ my_casedn_str(system_charset_info,ptr->db);
+ my_casedn_str(system_charset_info,table->table.str);
}
ptr->real_name=table->table.str;
ptr->real_name_length=table->table.length;
ptr->lock_type=flags;
ptr->updating=updating;
+ ptr->derived= (SELECT_LEX_UNIT *) table->sel;
if (use_index)
ptr->use_index=(List<String> *) thd->memdup((gptr) use_index,
sizeof(*use_index));
@@ -3231,69 +3349,6 @@ TABLE_LIST *add_table_to_list(Table_ident *table, LEX_STRING *alias,
}
-/*
-** This is used for UNION to create a new table list of all used tables
-** The table_list->table entry in all used tables are set to point
-** to the entries in this list.
-*/
-
-static bool create_total_list(THD *thd, LEX *lex, TABLE_LIST **result)
-{
- /* Handle the case when we are not using union */
- if (!lex->select_lex.next)
- {
- *result= (TABLE_LIST*) lex->select_lex.table_list.first;
- return 0;
- }
-
- SELECT_LEX *sl;
- TABLE_LIST **new_table_list= result, *aux;
-
- *new_table_list=0; // end result list
- for (sl= &lex->select_lex; sl; sl=sl->next)
- {
- if (sl->order_list.first && sl->next && !sl->braces)
- {
- net_printf(&thd->net,ER_WRONG_USAGE,"UNION","ORDER BY");
- return 1;
- }
- if ((aux= (TABLE_LIST*) sl->table_list.first))
- {
- TABLE_LIST *next;
- for (; aux; aux=next)
- {
- TABLE_LIST *cursor;
- aux->do_redirect=true;
- next= aux->next;
- for (cursor= *result; cursor; cursor=cursor->next)
- if (!strcmp(cursor->db,aux->db) &&
- !strcmp(cursor->real_name,aux->real_name) &&
- !strcmp(cursor->name, aux->name))
- break;
- if (!cursor)
- {
- /* Add not used table to the total table list */
- aux->lock_type= lex->lock_option;
- if (!(cursor = (TABLE_LIST *) thd->memdup((char*) aux,
- sizeof(*aux))))
- {
- send_error(&thd->net,0);
- return 1;
- }
- *new_table_list= cursor;
- new_table_list= &cursor->next;
- *new_table_list=0; // end result list
- }
- else
- aux->shared=1; // Mark that it's used twice
- aux->table=(TABLE *) cursor;
- }
- }
- }
- return 0;
-}
-
-
void add_join_on(TABLE_LIST *b,Item *expr)
{
if (!b->on_expr)
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
new file mode 100644
index 00000000000..d41aca21fb8
--- /dev/null
+++ b/sql/sql_prepare.cc
@@ -0,0 +1,709 @@
+/* Copyright (C) 1995-2002 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/**********************************************************************
+This file contains the implementation of prepare and executes.
+
+Prepare:
+
+ - Server gets the query from client with command 'COM_PREPARE'
+ - Parse the query and recognize any parameter markers '?' and
+ store its information list lex->param_list
+ - Without executing the query, return back to client the total
+ number of parameters along with result-set metadata information
+ (if any )
+
+Prepare-execute:
+
+ - Server gets the command 'COM_EXECUTE' to execute the
+ previously prepared query.
+ - If there is are any parameters, then replace the markers with the
+ data supplied by client with the following format:
+ [types_specified(0/1)][type][length][data] .. [type][length]..
+ - Execute the query without re-parsing and send back the results
+ to client
+
+Long data handling:
+
+ - Server gets the long data in pieces with command type 'COM_LONG_DATA'.
+ - The packet recieved will have the format as:
+ [type_spec_exists][type][length][data]
+ - Checks if the type is specified by client, and if yes reads the type,
+ and stores the data in that format.
+ - If length == MYSQL_END_OF_DATA, then server sets up the data read ended.
+***********************************************************************/
+
+#include "mysql_priv.h"
+#include "sql_acl.h"
+#include <assert.h> // for DEBUG_ASSERT()
+#include <ctype.h> // for isspace()
+
+/**************************************************************************/
+extern int yyparse(void);
+static ulong get_param_length(uchar **packet);
+static uint get_buffer_type(uchar **packet);
+static bool param_is_null(uchar **packet);
+static bool setup_param_fields(THD *thd,List<Item> &params);
+static uchar* setup_param_field(Item_param *item_param, uchar *pos, uint buffer_type);
+static void setup_longdata_field(Item_param *item_param, uchar *pos);
+static bool setup_longdata(THD *thd,List<Item> &params);
+static void send_prepare_results(THD *thd);
+static void mysql_parse_prepare_query(THD *thd,char *packet,uint length);
+static bool mysql_send_insert_fields(THD *thd,TABLE_LIST *table_list,
+ List<Item> &fields,
+ List<List_item> &values_list,thr_lock_type lock_type);
+static bool mysql_test_insert_fields(THD *thd,TABLE_LIST *table_list,
+ List<Item> &fields,
+ List<List_item> &values_list,thr_lock_type lock_type);
+static bool mysql_test_upd_fields(THD *thd,TABLE_LIST *table_list,
+ List<Item> &fields, List<Item> &values,
+ COND *conds,thr_lock_type lock_type);
+static bool mysql_test_select_fields(THD *thd, TABLE_LIST *tables,
+ List<Item> &fields, List<Item> &values,
+ COND *conds, ORDER *order, ORDER *group,
+ Item *having,thr_lock_type lock_type);
+extern const char *any_db;
+/**************************************************************************/
+
+/*
+ Read the buffer type, this happens only first time
+*/
+
+static uint get_buffer_type(uchar **packet)
+{
+ reg1 uchar *pos= *packet;
+ (*packet)+= 2;
+ return (uint) uint2korr(pos);
+}
+
+/*
+ Check for NULL param data
+*/
+
+static bool param_is_null(uchar **packet)
+{
+ reg1 uchar *pos= *packet;
+ if (*pos == 251)
+ {
+ (*packet)++;
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ Read the length of the parameter data and retun back to
+ caller by positing the pointer to param data
+*/
+
+static ulong get_param_length(uchar **packet)
+{
+ reg1 uchar *pos= *packet;
+ if (*pos < 251)
+ {
+ (*packet)++;
+ return (ulong) *pos;
+ }
+ if (*pos == 252)
+ {
+ (*packet)+=3;
+ return (ulong) uint2korr(pos+1);
+ }
+ if (*pos == 253)
+ {
+ (*packet)+=4;
+ return (ulong) uint3korr(pos+1);
+ }
+ (*packet)+=9; // Must be 254 when here
+ return (ulong) uint4korr(pos+1);
+}
+
+/*
+ Read and return the data for parameters supplied by client
+*/
+
+static uchar* setup_param_field(Item_param *item_param,
+ uchar *pos, uint buffer_type)
+{
+ if (param_is_null(&pos))
+ {
+ item_param->set_null();
+ return(pos);
+ }
+ switch (buffer_type)
+ {
+ case FIELD_TYPE_TINY:
+ item_param->set_int((longlong)(*pos));
+ pos += 1;
+ break;
+ case FIELD_TYPE_SHORT:
+ item_param->set_int((longlong)sint2korr(pos));
+ pos += 2;
+ break;
+ case FIELD_TYPE_INT24:
+ item_param->set_int((longlong)sint4korr(pos));
+ pos += 3;
+ break;
+ case FIELD_TYPE_LONG:
+ item_param->set_int((longlong)sint4korr(pos));
+ pos += 4;
+ break;
+ case FIELD_TYPE_LONGLONG:
+ item_param->set_int((longlong)sint8korr(pos));
+ pos += 8;
+ break;
+ case FIELD_TYPE_FLOAT:
+ float data;
+ float4get(data,pos);
+ item_param->set_double(data);
+ pos += 4;
+ break;
+ case FIELD_TYPE_DOUBLE:
+ double j;
+ float8get(j,pos)
+ item_param->set_double(j);
+ pos += 8;
+ break;
+ default:
+ {
+ ulong len=get_param_length(&pos);
+ item_param->set_value((const char*)pos,len);
+ pos+=len;
+ }
+ }
+ return(pos);
+}
+
+/*
+ Update the parameter markers by reading the data
+ from client ..
+*/
+
+static bool setup_param_fields(THD *thd, List<Item> &params)
+{
+ reg2 Item_param *item_param;
+ List_iterator<Item> it(params);
+ NET *net = &thd->net;
+ DBUG_ENTER("setup_param_fields");
+
+ ulong param_count=0;
+ uchar *pos=(uchar*)net->read_pos+1;// skip command type
+
+ if(*pos++) // No types supplied, read only param data
+ {
+ while ((item_param=(Item_param *)it++) &&
+ (param_count++ < thd->param_count))
+ {
+ if (item_param->long_data_supplied)
+ continue;
+
+ if (!(pos=setup_param_field(item_param,pos,item_param->buffer_type)))
+ DBUG_RETURN(1);
+ }
+ }
+ else // Types supplied, read and store it along with param data
+ {
+ while ((item_param=(Item_param *)it++) &&
+ (param_count++ < thd->param_count))
+ {
+ if (item_param->long_data_supplied)
+ continue;
+
+ if (!(pos=setup_param_field(item_param,pos,
+ item_param->buffer_type=(enum_field_types)get_buffer_type(&pos))))
+ DBUG_RETURN(1);
+ }
+ }
+ DBUG_RETURN(0);
+}
+
+/*
+ Buffer the long data and update the flags
+*/
+
+static void setup_longdata_field(Item_param *item_param, uchar *pos)
+{
+ ulong len;
+
+ if (!*pos++)
+ item_param->buffer_type=(enum_field_types)get_buffer_type(&pos);
+
+ if (*pos == MYSQL_LONG_DATA_END)
+ item_param->set_long_end();
+
+ else
+ {
+ len = get_param_length(&pos);
+ item_param->set_longdata((const char *)pos, len);
+ }
+}
+
+/*
+ Store the long data from client in pieces
+*/
+
+static bool setup_longdata(THD *thd, List<Item> &params)
+{
+ NET *net=&thd->net;
+ List_iterator<Item> it(params);
+ DBUG_ENTER("setup_longdata");
+
+ uchar *pos=(uchar*)net->read_pos+1;// skip command type at first position
+ ulong param_number = get_param_length(&pos);
+ Item_param *item_param = thd->current_param;
+
+ if (thd->current_param_number != param_number)
+ {
+ thd->current_param_number = param_number;
+ while (param_number--) /* TODO:
+ Change this loop by either having operator '+'
+ overloaded to point to desired 'item' or
+ add another memeber in list as 'goto' with
+ location count as parameter number, but what
+ is the best way to traverse ?
+ */
+ {
+ it++;
+ }
+ thd->current_param = item_param = (Item_param *)it++;
+ }
+ setup_longdata_field(item_param,pos);
+ DBUG_RETURN(0);
+}
+
+
+
+/*
+ Validates insert fields
+*/
+
+static int check_prepare_fields(THD *thd,TABLE *table, List<Item> &fields,
+ List<Item> &values, ulong counter)
+{
+ if (fields.elements == 0 && values.elements != 0)
+ {
+ if (values.elements != table->fields)
+ {
+ my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW,
+ ER(ER_WRONG_VALUE_COUNT_ON_ROW),
+ MYF(0),counter);
+ return -1;
+ }
+ }
+ else
+ {
+ if (fields.elements != values.elements)
+ {
+ my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW,
+ ER(ER_WRONG_VALUE_COUNT_ON_ROW),
+ MYF(0),counter);
+ return -1;
+ }
+ TABLE_LIST table_list;
+ bzero((char*) &table_list,sizeof(table_list));
+ table_list.name=table->table_name;
+ table_list.table=table;
+ table_list.grant=table->grant;
+
+ thd->dupp_field=0;
+ if (setup_tables(&table_list) ||
+ setup_fields(thd,&table_list,fields,1,0,0))
+ return -1;
+ if (thd->dupp_field)
+ {
+ my_error(ER_FIELD_SPECIFIED_TWICE,MYF(0), thd->dupp_field->field_name);
+ return -1;
+ }
+ }
+ return 0;
+}
+
+
+/*
+ Validate the following information for INSERT statement:
+ - field existance
+ - fields count
+
+ If there is no column list spec exists, then update the field_list
+ with all columns from the table, and send fields info back to client
+*/
+
+static bool mysql_test_insert_fields(THD *thd, TABLE_LIST *table_list,
+ List<Item> &fields,
+ List<List_item> &values_list,
+ thr_lock_type lock_type)
+{
+ TABLE *table;
+ List_iterator_fast<List_item> its(values_list);
+ List_item *values;
+ DBUG_ENTER("mysql_test_insert_fields");
+
+ if (!(table = open_ltable(thd,table_list,lock_type)))
+ DBUG_RETURN(1);
+
+ if ((values= its++))
+ {
+ uint value_count;
+ ulong counter=0;
+
+ if (check_insert_fields(thd,table,fields,*values,1))
+ DBUG_RETURN(1);
+
+ value_count= values->elements;
+ its.rewind();
+
+ while ((values = its++))
+ {
+ counter++;
+ if (values->elements != value_count)
+ {
+ my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW,
+ ER(ER_WRONG_VALUE_COUNT_ON_ROW),
+ MYF(0),counter);
+ DBUG_RETURN(1);
+ }
+ }
+ if (fields.elements == 0)
+ {
+ /* No field listing, so setup all fields */
+ List<Item> all_fields;
+ Field **ptr,*field;
+ for (ptr=table->field; (field= *ptr) ; ptr++)
+ {
+ all_fields.push_back(new Item_field(table->table_cache_key,
+ table->real_name,
+ field->field_name));
+ }
+ if ((setup_fields(thd,table_list,all_fields,1,0,0) ||
+ send_fields(thd,all_fields,1)))
+ DBUG_RETURN(1);
+ }
+ else if (send_fields(thd,fields,1))
+ DBUG_RETURN(1);
+ }
+ DBUG_RETURN(0);
+}
+
+
+/*
+ Validate the following information
+ UPDATE - set and where clause DELETE - where clause
+
+ And send update-set cluase column list fields info
+ back to client. For DELETE, just validate where cluase
+ and return no fields information back to client.
+*/
+
+static bool mysql_test_upd_fields(THD *thd, TABLE_LIST *table_list,
+ List<Item> &fields, List<Item> &values,
+ COND *conds, thr_lock_type lock_type)
+{
+ TABLE *table;
+ DBUG_ENTER("mysql_test_upd_fields");
+
+ if (!(table = open_ltable(thd,table_list,lock_type)))
+ DBUG_RETURN(1);
+
+ if (setup_tables(table_list) || setup_fields(thd,table_list,fields,1,0,0) ||
+ setup_conds(thd,table_list,&conds))
+ DBUG_RETURN(1);
+
+ /*
+ Currently return only column list info only, and we are not
+ sending any info on where clause.
+ */
+ if (fields.elements && send_fields(thd,fields,1))
+ DBUG_RETURN(1);
+
+ DBUG_RETURN(0);
+}
+
+/*
+ Validate the following information:
+
+ SELECT - column list
+ - where clause
+ - orderr clause
+ - having clause
+ - group by clause
+ - if no column spec i.e. '*', then setup all fields
+
+ And send column list fields info back to client.
+*/
+
+static bool mysql_test_select_fields(THD *thd, TABLE_LIST *tables,
+ List<Item> &fields, List<Item> &values,
+ COND *conds, ORDER *order, ORDER *group,
+ Item *having, thr_lock_type lock_type)
+{
+ TABLE *table;
+ bool hidden_group_fields;
+ List<Item> all_fields(fields);
+ DBUG_ENTER("mysql_test_select_fields");
+
+ if (!(table = open_ltable(thd,tables,lock_type)))
+ DBUG_RETURN(1);
+
+ thd->used_tables=0; // Updated by setup_fields
+ if (setup_tables(tables) ||
+ setup_fields(thd,tables,fields,1,&all_fields,1) ||
+ setup_conds(thd,tables,&conds) ||
+ setup_order(thd,tables,fields,all_fields,order) ||
+ setup_group(thd,tables,fields,all_fields,group,&hidden_group_fields))
+ DBUG_RETURN(1);
+
+ if (having)
+ {
+ thd->where="having clause";
+ thd->allow_sum_func=1;
+ if (having->fix_fields(thd, tables, &having) || thd->fatal_error)
+ DBUG_RETURN(1);
+ if (having->with_sum_func)
+ having->split_sum_func(all_fields);
+ }
+ if (setup_ftfuncs(thd))
+ DBUG_RETURN(1);
+
+ /*
+ Currently return only column list info only, and we are not
+ sending any info on where clause.
+ */
+ if (fields.elements && send_fields(thd,fields,1))
+ DBUG_RETURN(1);
+ DBUG_RETURN(0);
+}
+
+/*
+ Check the access privileges
+*/
+
+static bool check_prepare_access(THD *thd, TABLE_LIST *tables,
+ uint type)
+{
+ if (check_access(thd,type,tables->db,&tables->grant.privilege))
+ return 1;
+ if (grant_option && check_grant(thd,type,tables))
+ return 1;
+ return 0;
+}
+
+/*
+ Send the prepare query results back to client
+*/
+
+static void send_prepare_results(THD *thd)
+{
+ DBUG_ENTER("send_prepare_results");
+ enum enum_sql_command sql_command = thd->lex.sql_command;
+
+ DBUG_PRINT("enter",("command :%d, param_count :%ld",
+ sql_command,thd->param_count));
+
+ LEX *lex=&thd->lex;
+ SELECT_LEX *select_lex = lex->select;
+ TABLE_LIST *tables=(TABLE_LIST*) select_lex->table_list.first;
+
+ switch(sql_command) {
+
+ case SQLCOM_INSERT:
+ if (mysql_test_insert_fields(thd,tables, lex->field_list,
+ lex->many_values, lex->lock_option))
+ goto abort;
+ break;
+
+ case SQLCOM_UPDATE:
+ if (mysql_test_upd_fields(thd,tables, select_lex->item_list,
+ lex->value_list, select_lex->where,
+ lex->lock_option))
+ goto abort;
+ break;
+
+ case SQLCOM_DELETE:
+ if (mysql_test_upd_fields(thd,tables, select_lex->item_list,
+ lex->value_list, select_lex->where,
+ lex->lock_option))
+ goto abort;
+ break;
+
+ case SQLCOM_SELECT:
+ if (mysql_test_select_fields(thd,tables, select_lex->item_list,
+ lex->value_list, select_lex->where,
+ (ORDER*) select_lex->order_list.first,
+ (ORDER*) select_lex->group_list.first,
+ select_lex->having, lex->lock_option))
+ goto abort;
+ break;
+
+ default:
+ {
+ /*
+ Rest fall through to default category, no parsing
+ for non-DML statements
+ */
+ }
+ }
+ send_ok(&thd->net,thd->param_count,0);
+ DBUG_VOID_RETURN;
+
+abort:
+ send_error(&thd->net,thd->killed ? ER_SERVER_SHUTDOWN : 0);
+ DBUG_VOID_RETURN;
+}
+
+/*
+ Parse the prepare query
+*/
+
+static void mysql_parse_prepare_query(THD *thd, char *packet, uint length)
+{
+ DBUG_ENTER("mysql_parse_prepare_query");
+
+ mysql_log.write(thd,COM_PREPARE,"%s",packet);
+ mysql_init_query(thd);
+ thd->prepare_command=true;
+
+ if (query_cache.send_result_to_client(thd, packet, length) <= 0)
+ {
+ LEX *lex=lex_start(thd, (uchar*)packet, length);
+
+ if (!yyparse() && !thd->fatal_error)
+ {
+ send_prepare_results(thd);
+ query_cache_end_of_result(&thd->net);
+ }
+ else
+ query_cache_abort(&thd->net);
+ lex_end(lex);
+ }
+ DBUG_VOID_RETURN;
+}
+
+/*
+ Parse the query and send the total number of parameters
+ and resultset metadata information back to client (if any),
+ without executing the query i.e. with out any log/disk
+ writes. This will allow the queries to be re-executed
+ without re-parsing during execute.
+
+ If parameter markers are found in the query, then store
+ the information using Item_param along with maintaining a
+ list in lex->param_list, so that a fast and direct
+ retrieveal can be made without going through all field
+ items.
+*/
+
+void mysql_com_prepare(THD *thd, char *packet, uint packet_length)
+{
+ MEM_ROOT thd_root = thd->mem_root;
+ DBUG_ENTER("mysql_com_prepare");
+
+ packet_length--;
+
+ while (isspace(packet[0]) && packet_length > 0)
+ {
+ packet++;
+ packet_length--;
+ }
+ char *pos=packet+packet_length;
+ while (packet_length > 0 && (pos[-1] == ';' || isspace(pos[-1])))
+ {
+ pos--;
+ packet_length--;
+ }
+ /*
+ Have the prepare items to have a connection level scope or
+ till next prepare statement by doing all allocations using
+ connection level memory allocator 'con_root' from THD.
+ */
+ free_root(&thd->con_root,MYF(0));
+ init_sql_alloc(&thd->con_root,8192,8192);
+ thd->mem_root = thd->con_root;
+
+ if (!(thd->query= (char*) thd->memdup_w_gap((gptr) (packet),
+ packet_length,
+ thd->db_length+2)))
+ DBUG_VOID_RETURN;
+ thd->query[packet_length]=0;
+ thd->packet.shrink(net_buffer_length);
+ thd->query_length = packet_length;
+
+ if (!(specialflag & SPECIAL_NO_PRIOR))
+ my_pthread_setprio(pthread_self(),QUERY_PRIOR);
+
+ mysql_parse_prepare_query(thd,thd->query,packet_length);
+
+ if (!(specialflag & SPECIAL_NO_PRIOR))
+ my_pthread_setprio(pthread_self(),WAIT_PRIOR);
+
+ thd->mem_root = thd_root; // restore main mem_root
+ DBUG_PRINT("exit",("prepare query ready"));
+ DBUG_VOID_RETURN;
+}
+
+
+/*
+ Executes previously prepared query
+
+ If there is any parameters(thd->param_count), then replace
+ markers with the data supplied from client, and then
+ execute the query
+*/
+
+void mysql_com_execute(THD *thd)
+{
+ MEM_ROOT thd_root=thd->mem_root;
+ DBUG_ENTER("mysql_com_execute");
+ DBUG_PRINT("enter", ("parameters : %ld", thd->param_count));
+
+ thd->mem_root = thd->con_root;
+ if (thd->param_count && setup_param_fields(thd, thd->lex.param_list))
+ DBUG_VOID_RETURN;
+
+ if (!(specialflag & SPECIAL_NO_PRIOR))
+ my_pthread_setprio(pthread_self(),QUERY_PRIOR);
+
+ /* TODO:
+ Also, have checks on basic executions such as mysql_insert(),
+ mysql_delete(), mysql_update() and mysql_select() to not to
+ have re-check on setup_* and other things ..
+ */
+ mysql_execute_command();
+
+ if (!(specialflag & SPECIAL_NO_PRIOR))
+ my_pthread_setprio(pthread_self(),WAIT_PRIOR);
+
+ thd->mem_root = (MEM_ROOT )thd_root;
+ DBUG_PRINT("exit",("prepare-execute done!"));
+ DBUG_VOID_RETURN;
+}
+
+/*
+ Long data in pieces from client
+*/
+
+void mysql_com_longdata(THD *thd)
+{
+ DBUG_ENTER("mysql_com_execute");
+
+ if(thd->param_count && setup_longdata(thd,thd->lex.param_list))
+ DBUG_VOID_RETURN;
+
+ send_ok(&thd->net,0,0);// ok status to client
+ DBUG_PRINT("exit",("longdata-buffering done!"));
+ DBUG_VOID_RETURN;
+}
+
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 11b89722017..8a64fbf968c 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -65,7 +65,8 @@ static ORDER *remove_const(JOIN *join,ORDER *first_order,COND *cond,
static int return_zero_rows(JOIN *join, select_result *res,TABLE_LIST *tables,
List<Item> &fields, bool send_row,
uint select_options, const char *info,
- Item *having, Procedure *proc);
+ Item *having, Procedure *proc,
+ SELECT_LEX_UNIT *unit);
static COND *optimize_cond(COND *conds,Item::cond_result *cond_value);
static COND *remove_eq_conds(COND *cond,Item::cond_result *cond_value);
static bool const_expression_in_where(COND *conds,Item *item, Item **comp_item);
@@ -125,8 +126,6 @@ static bool store_record_in_cache(JOIN_CACHE *cache);
static void reset_cache(JOIN_CACHE *cache);
static void read_cached_record(JOIN_TAB *tab);
static bool cmp_buffer_with_ref(JOIN_TAB *tab);
-static int setup_group(THD *thd,TABLE_LIST *tables,List<Item> &fields,
- List<Item> &all_fields, ORDER *order, bool *hidden);
static bool setup_new_fields(THD *thd,TABLE_LIST *tables,List<Item> &fields,
List<Item> &all_fields,ORDER *new_order);
static ORDER *create_distinct_group(ORDER *order, List<Item> &fields);
@@ -155,6 +154,25 @@ int handle_select(THD *thd, LEX *lex, select_result *result)
{
int res;
register SELECT_LEX *select_lex = &lex->select_lex;
+ if (select_lex->next_select_in_list())
+ {
+ /* Fix tables 'to-be-unioned-from' list to point at opened tables */
+ for (SELECT_LEX *sl= select_lex;
+ sl;
+ sl= sl->next_select_in_list())
+ {
+ for (TABLE_LIST *cursor= (TABLE_LIST *)sl->table_list.first;
+ cursor;
+ cursor=cursor->next)
+ {
+ if (cursor->do_redirect) // False if CUBE/ROLLUP
+ {
+ cursor->do_redirect=false;
+ cursor->table= ((TABLE_LIST*) cursor->table)->table;
+ }
+ }
+ }
+ }
#ifdef DISABLED_UNTIL_REWRITTEN_IN_4_1
if (lex->olap)
@@ -174,7 +192,8 @@ int handle_select(THD *thd, LEX *lex, select_result *result)
lex->select = select_lex;
}
#endif /* DISABLED_UNTIL_REWRITTEN_IN_4_1 */
- if (select_lex->next)
+
+ if (select_lex->next_select())
res=mysql_union(thd,lex,result);
else
res=mysql_select(thd,(TABLE_LIST*) select_lex->table_list.first,
@@ -185,7 +204,7 @@ int handle_select(THD *thd, LEX *lex, select_result *result)
select_lex->having,
(ORDER*) lex->proc_list.first,
select_lex->options | thd->options,
- result);
+ result, &(lex->unit));
if (res && result)
result->abort();
delete result;
@@ -198,47 +217,47 @@ int handle_select(THD *thd, LEX *lex, select_result *result)
mysql_select assumes that all tables are already opened
*****************************************************************************/
+/*
+ Prepare of whole select (including subselect in future).
+ return -1 on error
+ 0 on success
+*/
int
-mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
- ORDER *order, ORDER *group,Item *having,ORDER *proc_param,
- ulong select_options,select_result *result)
+JOIN::prepare(TABLE_LIST *tables_init,
+ COND *conds_init, ORDER *order_init, ORDER *group_init,
+ Item *having_init,
+ ORDER *proc_param_init, SELECT_LEX *select_lex,
+ SELECT_LEX_UNIT *unit)
{
- TABLE *tmp_table;
- int error, tmp_error;
- bool need_tmp,hidden_group_fields;
- bool simple_order,simple_group,no_order, skip_sort_order;
- Item::cond_result cond_value;
- SQL_SELECT *select;
- DYNAMIC_ARRAY keyuse;
- JOIN join;
- Procedure *procedure;
- List<Item> all_fields(fields);
- bool select_distinct;
- SELECT_LEX *cur_sel = thd->lex.select;
- DBUG_ENTER("mysql_select");
-
+ DBUG_ENTER("JOIN::prepare");
+
+ conds= conds_init;
+ order= order_init;
+ group_list= group_init;
+ having= having_init;
+ proc_param= proc_param_init;
+ tables_list= tables_init;
+ select->join= this;
+ union_part= (unit->first_select()->next_select() != 0);
+
/* Check that all tables, fields, conds and order are ok */
- select_distinct=test(select_options & SELECT_DISTINCT);
- tmp_table=0;
- select=0;
- no_order=skip_sort_order=0;
- bzero((char*) &keyuse,sizeof(keyuse));
- thd->proc_info="init";
- thd->used_tables=0; // Updated by setup_fields
-
- if (setup_tables(tables) ||
- setup_fields(thd,tables,fields,1,&all_fields,1) ||
- setup_conds(thd,tables,&conds) ||
- setup_order(thd,tables,fields,all_fields,order) ||
- setup_group(thd,tables,fields,all_fields,group,&hidden_group_fields))
+ if (setup_tables(tables_list) ||
+ setup_fields(thd,tables_list,fields_list,1,&all_fields,1) ||
+ setup_conds(thd,tables_list,&conds) ||
+ setup_order(thd,tables_list,fields_list,all_fields,order) ||
+ setup_group(thd,tables_list,fields_list,all_fields,group_list,
+ &hidden_group_fields))
DBUG_RETURN(-1); /* purecov: inspected */
if (having)
{
thd->where="having clause";
thd->allow_sum_func=1;
- if (having->fix_fields(thd,tables) || thd->fatal_error)
+ select_lex->having_fix_field= 1;
+ bool having_fix_rc= having->fix_fields(thd, tables_list, &having);
+ select_lex->having_fix_field= 0;
+ if (having_fix_rc || thd->fatal_error)
DBUG_RETURN(-1); /* purecov: inspected */
if (having->with_sum_func)
having->split_sum_func(all_fields);
@@ -251,13 +270,11 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
TODO: Add check of calculation of GROUP functions and fields:
SELECT COUNT(*)+table.col1 from table1;
*/
- join.table=0;
- join.tables=0;
{
- if (!group)
+ if (!group_list)
{
uint flag=0;
- List_iterator_fast<Item> it(fields);
+ List_iterator_fast<Item> it(fields_list);
Item *item;
while ((item= it++))
{
@@ -273,22 +290,23 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
}
}
TABLE_LIST *table;
- for (table=tables ; table ; table=table->next)
- join.tables++;
+ for (table=tables_list ; table ; table=table->next)
+ tables++;
}
- procedure=setup_procedure(thd,proc_param,result,fields,&error);
+ procedure=setup_procedure(thd,proc_param,result,fields_list,&error);
if (error)
DBUG_RETURN(-1); /* purecov: inspected */
if (procedure)
{
- if (setup_new_fields(thd,tables,fields,all_fields,procedure->param_fields))
+ if (setup_new_fields(thd, tables_list, fields_list, all_fields,
+ procedure->param_fields))
{ /* purecov: inspected */
delete procedure; /* purecov: inspected */
DBUG_RETURN(-1); /* purecov: inspected */
}
if (procedure->group)
{
- if (!test_if_subpart(procedure->group,group))
+ if (!test_if_subpart(procedure->group,group_list))
{ /* purecov: inspected */
my_message(0,"Can't handle procedures with differents groups yet",
MYF(0)); /* purecov: inspected */
@@ -297,7 +315,7 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
}
}
#ifdef NOT_NEEDED
- else if (!group && procedure->flags & PROC_GROUP)
+ else if (!group_list && procedure->flags & PROC_GROUP)
{
my_message(0,"Select must have a group with this procedure",MYF(0));
delete procedure;
@@ -313,51 +331,53 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
}
/* Init join struct */
- join.thd=thd;
- join.lock=thd->lock;
- join.join_tab=0;
- join.tmp_table_param.copy_field=0;
- join.sum_funcs=0;
- join.send_records=join.found_records=join.examined_rows=0;
- join.tmp_table_param.end_write_records= HA_POS_ERROR;
- join.first_record=join.sort_and_group=0;
- join.select_options=select_options;
- join.result=result;
- count_field_types(&join.tmp_table_param,all_fields,0);
- join.const_tables=0;
- join.having=0;
- join.do_send_rows = 1;
- join.group= group != 0;
- join.row_limit= ((select_distinct || order || group) ? HA_POS_ERROR :
- thd->select_limit);
+ count_field_types(&tmp_table_param, all_fields, 0);
+ this->group= group_list != 0;
+ row_limit= ((select_distinct || order || group_list) ? HA_POS_ERROR :
+ unit->select_limit_cnt);
+ this->unit= unit;
#ifdef RESTRICTED_GROUP
- if (join.sum_func_count && !group && (join.func_count || join.field_count))
+ if (sum_func_count && !group_list && (func_count || field_count))
{
my_message(ER_WRONG_SUM_SELECT,ER(ER_WRONG_SUM_SELECT),MYF(0));
delete procedure;
DBUG_RETURN(-1);
}
#endif
- if (!procedure && result->prepare(fields))
+ if (!procedure && result->prepare(fields_list, unit))
{ /* purecov: inspected */
DBUG_RETURN(-1); /* purecov: inspected */
}
+ DBUG_RETURN(0); // All OK
+}
+
+/*
+ global select optimisation.
+ return 0 - success
+ 1 - go out
+ -1 - go out with cleaning
+ error code saved in field 'error'
+*/
+int
+JOIN::optimize()
+{
+ DBUG_ENTER("JOIN::optimize");
#ifdef HAVE_REF_TO_FIELDS // Not done yet
/* Add HAVING to WHERE if possible */
- if (having && !group && ! join.sum_func_count)
+ if (having && !group_list && ! sum_func_count)
{
if (!conds)
{
- conds=having;
- having=0;
+ conds= having;
+ having= 0;
}
else if ((conds=new Item_cond_and(conds,having)))
{
- conds->fix_fields(thd,tables);
- conds->change_ref_to_fields(thd,tables);
- having=0;
+ conds->fix_fields(thd, tables_list, &conds);
+ conds->change_ref_to_fields(thd, tables_list);
+ having= 0;
}
}
#endif
@@ -366,96 +386,83 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
if (thd->fatal_error) // Out of memory
{
delete procedure;
- DBUG_RETURN(0);
+ error = 0;
+ DBUG_RETURN(1);
}
- if (cond_value == Item::COND_FALSE || !thd->select_limit)
+ if (cond_value == Item::COND_FALSE || !unit->select_limit_cnt)
{ /* Impossible cond */
- error=return_zero_rows(&join, result, tables, fields,
- join.tmp_table_param.sum_func_count != 0 && !group,
- select_options,"Impossible WHERE",having,
- procedure);
- delete procedure;
- DBUG_RETURN(error);
+ zero_result_cause= "Impossible WHERE";
+ DBUG_RETURN(0);
}
/* Optimize count(*), min() and max() */
- if (tables && join.tmp_table_param.sum_func_count && ! group)
+ if (tables_list && tmp_table_param.sum_func_count && ! group_list)
{
int res;
- if ((res=opt_sum_query(tables, all_fields, conds)))
+ if ((res=opt_sum_query(tables_list, all_fields, conds)))
{
if (res < 0)
{
- error=return_zero_rows(&join, result, tables, fields, !group,
- select_options,"No matching min/max row",
- having,procedure);
- delete procedure;
- DBUG_RETURN(error);
+ zero_result_cause= "No matching min/max row";
+ DBUG_RETURN(0);
}
if (select_options & SELECT_DESCRIBE)
{
- describe_info(&join, "Select tables optimized away");
+ describe_info(this, "Select tables optimized away");
delete procedure;
- DBUG_RETURN(error);
+ DBUG_RETURN(1);
}
- tables=0; // All tables resolved
+ tables_list= 0; // All tables resolved
}
}
- if (!tables)
- { // Only test of functions
- error=0;
- if (select_options & SELECT_DESCRIBE)
- describe_info(&join, "No tables used");
- else
- {
- result->send_fields(fields,1);
- if (!having || having->val_int())
- {
- if (join.do_send_rows && result->send_data(fields))
- {
- result->send_error(0,NullS); /* purecov: inspected */
- error=1;
- }
- else
- error=(int) result->send_eof();
- }
- else
- error=(int) result->send_eof();
- }
- delete procedure;
- DBUG_RETURN(error);
+
+ if (!tables_list)
+ {
+ test_function_query= 1;
+ DBUG_RETURN(0);
}
- error = -1;
- join.sort_by_table=get_sort_by_table(order,group,tables);
+ error= -1;
+ sort_by_table= get_sort_by_table(order, group_list, tables_list);
/* Calculate how to do the join */
- thd->proc_info="statistics";
- if (make_join_statistics(&join,tables,conds,&keyuse) || thd->fatal_error)
- goto err;
- thd->proc_info="preparing";
- result->initialize_tables(&join);
- if (join.const_table_map != join.found_const_table_map &&
+ thd->proc_info= "statistics";
+ if (make_join_statistics(this, tables_list, conds, &keyuse) ||
+ thd->fatal_error)
+ DBUG_RETURN(-1);
+
+ if (select_lex->depended)
+ {
+ /*
+ Just remove all const-table optimization in case of depended query
+ TODO: optimize
+ */
+ const_table_map= 0;
+ const_tables= 0;
+ found_const_table_map= 0;
+ }
+ thd->proc_info= "preparing";
+ result->initialize_tables(this);
+ if (const_table_map != found_const_table_map &&
!(select_options & SELECT_DESCRIBE))
{
- error=return_zero_rows(&join,result,tables,fields,
- join.tmp_table_param.sum_func_count != 0 &&
- !group,0,"",having,procedure);
- goto err;
+ zero_result_cause= "";
+ select_options= 0; //TODO why option in return_zero_rows was droped
+ DBUG_RETURN(0);
}
if (!(thd->options & OPTION_BIG_SELECTS) &&
- join.best_read > (double) thd->variables.max_join_size &&
+ best_read > (double) thd->variables.max_join_size &&
!(select_options & SELECT_DESCRIBE))
{ /* purecov: inspected */
result->send_error(ER_TOO_BIG_SELECT,ER(ER_TOO_BIG_SELECT)); /* purecov: inspected */
error= 1; /* purecov: inspected */
- goto err; /* purecov: inspected */
+ DBUG_RETURN(-1);
}
- if (join.const_tables && !thd->locked_tables &&
+ if (const_tables && !thd->locked_tables &&
!(select_options & SELECT_NO_UNLOCK))
{
TABLE **table, **end;
- for (table=join.table, end=table + join.const_tables ;
+ for (table=this->table, end=table + const_tables ;
table != end;
table++)
{
@@ -467,80 +474,79 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
}
(*table)->file->index_end();
}
- mysql_unlock_some_tables(thd, join.table,join.const_tables);
+ mysql_unlock_some_tables(thd, this->table, const_tables);
}
- if (!conds && join.outer_join)
+ if (!conds && outer_join)
{
/* Handle the case where we have an OUTER JOIN without a WHERE */
conds=new Item_int((longlong) 1,1); // Always true
}
- select=make_select(*join.table, join.const_table_map,
- join.const_table_map,conds,&error);
+ select=make_select(*table, const_table_map,
+ const_table_map, conds, &error);
if (error)
{ /* purecov: inspected */
error= -1; /* purecov: inspected */
- goto err; /* purecov: inspected */
+ DBUG_RETURN(-1);
}
- if (make_join_select(&join,select,conds))
+ if (make_join_select(this, select, conds))
{
- error=return_zero_rows(&join, result, tables, fields,
- join.tmp_table_param.sum_func_count != 0 && !group,
- select_options,
- "Impossible WHERE noticed after reading const tables",
- having,procedure);
- goto err;
+ zero_result_cause=
+ "Impossible WHERE noticed after reading const tables";
+ DBUG_RETURN(0);
}
error= -1; /* if goto err */
/* Optimize distinct away if possible */
- order=remove_const(&join,order,conds,&simple_order);
- if (group || join.tmp_table_param.sum_func_count)
+ order= remove_const(this, order, conds, &simple_order);
+ if (group_list || tmp_table_param.sum_func_count)
{
if (! hidden_group_fields)
select_distinct=0;
}
- else if (select_distinct && join.tables - join.const_tables == 1 &&
- (thd->select_limit == HA_POS_ERROR ||
- (join.select_options & OPTION_FOUND_ROWS) ||
+ else if (select_distinct && tables - const_tables == 1 &&
+ (unit->select_limit_cnt == HA_POS_ERROR ||
+ (select_options & OPTION_FOUND_ROWS) ||
order &&
!(skip_sort_order=
- test_if_skip_sort_order(&join.join_tab[join.const_tables],
- order, thd->select_limit,1))))
+ test_if_skip_sort_order(&join_tab[const_tables],
+ order,
+ unit->select_limit_cnt,
+ 1))))
{
- if ((group=create_distinct_group(order,fields)))
+ if ((group_list= create_distinct_group(order, fields_list)))
{
- select_distinct=0;
+ select_distinct= 0;
no_order= !order;
- join.group=1; // For end_write_group
+ group= 1; // For end_write_group
}
else if (thd->fatal_error) // End of memory
- goto err;
+ DBUG_RETURN(-1);
}
- group=remove_const(&join,group,conds,&simple_group);
- if (!group && join.group)
+ group_list= remove_const(this, group_list, conds, &simple_group);
+ if (!group_list && group)
{
order=0; // The output has only one row
simple_order=1;
}
- calc_group_buffer(&join,group);
- join.send_group_parts=join.tmp_table_param.group_parts; /* Save org parts */
+ calc_group_buffer(this, group_list);
+ send_group_parts= tmp_table_param.group_parts; /* Save org parts */
if (procedure && procedure->group)
{
- group=procedure->group=remove_const(&join,procedure->group,conds,
- &simple_group);
- calc_group_buffer(&join,group);
+ group_list= procedure->group= remove_const(this, procedure->group, conds,
+ &simple_group);
+ calc_group_buffer(this, group_list);
}
- if (test_if_subpart(group,order) ||
- (!group && join.tmp_table_param.sum_func_count))
+ if (test_if_subpart(group_list, order) ||
+ (!group_list && tmp_table_param.sum_func_count))
order=0;
// Can't use sort on head table if using row cache
- if (join.full_join)
+ if (full_join)
{
- if (group)
+ if (group_list)
simple_group=0;
if (order)
simple_order=0;
@@ -555,17 +561,18 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
- We are using different ORDER BY and GROUP BY orders
- The user wants us to buffer the result.
*/
- need_tmp= (join.const_tables != join.tables &&
+ need_tmp= (const_tables != tables &&
((select_distinct || !simple_order || !simple_group) ||
- (group && order) ||
+ (group_list && order) ||
test(select_options & OPTION_BUFFER_RESULT)));
// No cache for MATCH
- make_join_readinfo(&join,
+ make_join_readinfo(this,
(select_options & (SELECT_DESCRIBE |
SELECT_NO_JOIN_CACHE)) |
- (cur_sel->ftfunc_list.elements ? SELECT_NO_JOIN_CACHE :
- 0));
+ (thd->lex.select->ftfunc_list.elements ?
+ SELECT_NO_JOIN_CACHE : 0));
+
/*
Need to tell Innobase that to play it safe, it should fetch all
columns of the tables: this is because MySQL may build row
@@ -575,60 +582,151 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
*/
#ifdef HAVE_INNOBASE_DB
- if (need_tmp || select_distinct || group || order)
+ if (need_tmp || select_distinct || group_list || order)
{
- for (uint i_h = join.const_tables; i_h < join.tables; i_h++)
+ for (uint i_h = const_tables; i_h < tables; i_h++)
{
- TABLE* table_h = join.join_tab[i_h].table;
+ TABLE* table_h = join_tab[i_h].table;
if (table_h->db_type == DB_TYPE_INNODB)
table_h->file->extra(HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE);
}
}
#endif
- DBUG_EXECUTE("info",TEST_join(&join););
+ DBUG_EXECUTE("info",TEST_join(this););
/*
Because filesort always does a full table scan or a quick range scan
we must add the removed reference to the select for the table.
We only need to do this when we have a simple_order or simple_group
as in other cases the join is done before the sort.
*/
- if ((order || group) && join.join_tab[join.const_tables].type != JT_ALL &&
- join.join_tab[join.const_tables].type != JT_FT &&
- (order && simple_order || group && simple_group))
+ if ((order || group_list) && join_tab[const_tables].type != JT_ALL &&
+ join_tab[const_tables].type != JT_FT &&
+ (order && simple_order || group_list && simple_group))
{
- if (add_ref_to_table_cond(thd,&join.join_tab[join.const_tables]))
- goto err;
+ if (add_ref_to_table_cond(thd,&join_tab[const_tables]))
+ DBUG_RETURN(-1);
}
if (!(select_options & SELECT_BIG_RESULT) &&
- ((group && join.const_tables != join.tables &&
+ ((group_list && const_tables != tables &&
(!simple_group ||
- !test_if_skip_sort_order(&join.join_tab[join.const_tables], group,
- thd->select_limit,0))) ||
+ !test_if_skip_sort_order(&join_tab[const_tables], group_list,
+ unit->select_limit_cnt,
+ 0))) ||
select_distinct) &&
- join.tmp_table_param.quick_group && !procedure)
+ tmp_table_param.quick_group && !procedure)
{
need_tmp=1; simple_order=simple_group=0; // Force tmp table without sort
}
+ DBUG_RETURN(0);
+}
+
+/*
+ Global optimization (with subselect) must be here (TODO)
+*/
+
+int
+JOIN::global_optimize()
+{
+ return 0;
+}
+
+int
+JOIN::reinit()
+{
+ DBUG_ENTER("JOIN::reinit");
+ //TODO move to unit reinit
+ unit->offset_limit_cnt =select_lex->offset_limit;
+ unit->select_limit_cnt =select_lex->select_limit+select_lex->offset_limit;
+ if (unit->select_limit_cnt < select_lex->select_limit)
+ unit->select_limit_cnt= HA_POS_ERROR; // no limit
+ if (unit->select_limit_cnt == HA_POS_ERROR)
+ select_lex->options&= ~OPTION_FOUND_ROWS;
+
+ if (setup_tables(tables_list))
+ DBUG_RETURN(1);
+
+ // Reset of sum functions
+ first_record= 0;
+ if (sum_funcs)
+ {
+ Item_sum *func, **func_ptr= sum_funcs;
+ while ((func= *(func_ptr++)))
+ func->null_value= 1;
+ }
+
+ DBUG_RETURN(0);
+}
+
+/*
+ Exec select
+*/
+void
+JOIN::exec()
+{
+ int tmp_error;
+
+ DBUG_ENTER("JOIN::exec");
+
+ if (test_function_query)
+ { // Only test of functions
+ error=0;
+ if (select_options & SELECT_DESCRIBE)
+ describe_info(this, "No tables used");
+ else
+ {
+ result->send_fields(fields_list,1);
+ if (!having || having->val_int())
+ {
+ if (do_send_rows && result->send_data(fields_list))
+ {
+ result->send_error(0,NullS); /* purecov: inspected */
+ error=1;
+ }
+ else
+ error=(int) result->send_eof();
+ }
+ else
+ error=(int) result->send_eof();
+ }
+ delete procedure;
+ DBUG_VOID_RETURN;
+ }
+
+ if (zero_result_cause)
+ {
+ (void) return_zero_rows(this, result, tables_list, fields_list,
+ tmp_table_param.sum_func_count != 0 &&
+ !group_list,
+ select_options,
+ zero_result_cause,
+ having,procedure,
+ unit);
+ DBUG_VOID_RETURN;
+ }
+
+ Item *having_list = having;
+ having = 0;
if (select_options & SELECT_DESCRIBE)
{
if (!order && !no_order)
- order=group;
+ order=group_list;
if (order &&
- (join.const_tables == join.tables ||
+ (const_tables == tables ||
(simple_order &&
- test_if_skip_sort_order(&join.join_tab[join.const_tables], order,
- (join.const_tables != join.tables - 1 ||
- (join.select_options & OPTION_FOUND_ROWS)) ?
- HA_POS_ERROR : thd->select_limit,0))))
+ test_if_skip_sort_order(&join_tab[const_tables], order,
+ (const_tables != tables - 1 ||
+ (select_options & OPTION_FOUND_ROWS)) ?
+ HA_POS_ERROR : unit->select_limit_cnt,
+ 0))))
order=0;
- select_describe(&join,need_tmp,
+ select_describe(this, need_tmp,
order != 0 && !skip_sort_order,
select_distinct);
error=0;
- goto err;
+ DBUG_VOID_RETURN;
}
/* Perform FULLTEXT search before all regular searches */
@@ -640,46 +738,47 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
DBUG_PRINT("info",("Creating tmp table"));
thd->proc_info="Creating tmp table";
- join.tmp_table_param.hidden_field_count=(all_fields.elements-
- fields.elements);
- if (!(tmp_table =
- create_tmp_table(thd,&join.tmp_table_param,all_fields,
+ tmp_table_param.hidden_field_count= (all_fields.elements-
+ fields.elements);
+ if (!(exec_tmp_table =
+ create_tmp_table(thd, &tmp_table_param, all_fields,
((!simple_group && !procedure &&
!(test_flags & TEST_NO_KEY_GROUP)) ?
- group : (ORDER*) 0),
- group ? 0 : select_distinct,
- group && simple_group,
+ group_list : (ORDER*) 0),
+ group_list ? 0 : select_distinct,
+ group_list && simple_group,
(order == 0 || skip_sort_order) &&
- !(join.select_options & OPTION_FOUND_ROWS),
- join.select_options)))
- goto err; /* purecov: inspected */
+ !(select_options & OPTION_FOUND_ROWS),
+ select_options, unit)))
+ DBUG_VOID_RETURN;
- if (having && (join.sort_and_group || (tmp_table->distinct && !group)))
- join.having=having;
+ if (having_list &&
+ (sort_and_group || (exec_tmp_table->distinct && !group_list)))
+ having=having_list;
/* if group or order on first table, sort first */
- if (group && simple_group)
+ if (group_list && simple_group)
{
DBUG_PRINT("info",("Sorting for group"));
thd->proc_info="Sorting for group";
- if (create_sort_index(&join.join_tab[join.const_tables],group,
+ if (create_sort_index(&join_tab[const_tables], group_list,
HA_POS_ERROR) ||
- make_sum_func_list(&join,all_fields) ||
- alloc_group_fields(&join,group))
- goto err;
- group=0;
+ make_sum_func_list(this, all_fields) ||
+ alloc_group_fields(this, group_list))
+ DBUG_VOID_RETURN;
+ group_list=0;
}
else
{
- if (make_sum_func_list(&join,all_fields))
- goto err;
- if (!group && ! tmp_table->distinct && order && simple_order)
+ if (make_sum_func_list(this, all_fields))
+ DBUG_VOID_RETURN;
+ if (!group_list && ! exec_tmp_table->distinct && order && simple_order)
{
DBUG_PRINT("info",("Sorting for order"));
thd->proc_info="Sorting for order";
- if (create_sort_index(&join.join_tab[join.const_tables],order,
- HA_POS_ERROR))
- goto err; /* purecov: inspected */
+ if (create_sort_index(&join_tab[const_tables], order,
+ HA_POS_ERROR))
+ DBUG_VOID_RETURN;
order=0;
}
}
@@ -690,58 +789,58 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
In this case we can stop scanning t2 when we have found one t1.a
*/
- if (tmp_table->distinct)
+ if (exec_tmp_table->distinct)
{
table_map used_tables= thd->used_tables;
- JOIN_TAB *join_tab=join.join_tab+join.tables-1;
+ JOIN_TAB *join_tab= this->join_tab+tables-1;
do
{
if (used_tables & join_tab->table->map)
break;
join_tab->not_used_in_distinct=1;
- } while (join_tab-- != join.join_tab);
+ } while (join_tab-- != this->join_tab);
/* Optimize "select distinct b from t1 order by key_part_1 limit #" */
if (order && skip_sort_order)
{
- (void) test_if_skip_sort_order(&join.join_tab[join.const_tables],
- order, thd->select_limit,0);
+ (void) test_if_skip_sort_order(&this->join_tab[const_tables],
+ order, unit->select_limit_cnt, 0);
order=0;
}
}
/* Copy data to the temporary table */
- thd->proc_info="Copying to tmp table";
- if ((tmp_error=do_select(&join,(List<Item> *) 0,tmp_table,0)))
+ thd->proc_info= "Copying to tmp table";
+ if ((tmp_error= do_select(this, (List<Item> *) 0, exec_tmp_table, 0)))
{
- error=tmp_error;
- goto err; /* purecov: inspected */
+ error= tmp_error;
+ DBUG_VOID_RETURN;
}
- if (join.having)
- join.having=having=0; // Allready done
+ if (having)
+ having= having_list= 0; // Allready done
/* Change sum_fields reference to calculated fields in tmp_table */
- if (join.sort_and_group || tmp_table->group)
+ if (sort_and_group || exec_tmp_table->group)
{
if (change_to_use_tmp_fields(all_fields))
- goto err;
- join.tmp_table_param.field_count+=join.tmp_table_param.sum_func_count+
- join.tmp_table_param.func_count;
- join.tmp_table_param.sum_func_count=join.tmp_table_param.func_count=0;
+ DBUG_VOID_RETURN;
+ tmp_table_param.field_count+= tmp_table_param.sum_func_count+
+ tmp_table_param.func_count;
+ tmp_table_param.sum_func_count= tmp_table_param.func_count= 0;
}
else
{
if (change_refs_to_tmp_fields(thd,all_fields))
- goto err;
- join.tmp_table_param.field_count+=join.tmp_table_param.func_count;
- join.tmp_table_param.func_count=0;
+ DBUG_VOID_RETURN;
+ tmp_table_param.field_count+= tmp_table_param.func_count;
+ tmp_table_param.func_count= 0;
}
if (procedure)
procedure->update_refs();
- if (tmp_table->group)
+ if (exec_tmp_table->group)
{ // Already grouped
if (!order && !no_order)
- order=group; /* order by group */
- group=0;
+ order= group_list; /* order by group */
+ group_list= 0;
}
/*
@@ -752,153 +851,210 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
like SEC_TO_TIME(SUM(...)).
*/
- if (group && (!test_if_subpart(group,order) || select_distinct) ||
+ if (group_list && (!test_if_subpart(group_list,order) ||
+ select_distinct) ||
(select_distinct &&
- join.tmp_table_param.using_indirect_summary_function))
+ tmp_table_param.using_indirect_summary_function))
{ /* Must copy to another table */
TABLE *tmp_table2;
DBUG_PRINT("info",("Creating group table"));
/* Free first data from old join */
- join_free(&join);
- if (make_simple_join(&join,tmp_table))
- goto err;
- calc_group_buffer(&join,group);
- count_field_types(&join.tmp_table_param,all_fields,
- select_distinct && !group);
- join.tmp_table_param.hidden_field_count=(all_fields.elements-
- fields.elements);
+ join_free(this);
+ if (make_simple_join(this, exec_tmp_table))
+ DBUG_VOID_RETURN;
+ calc_group_buffer(this, group_list);
+ count_field_types(&tmp_table_param, all_fields,
+ select_distinct && !group_list);
+ tmp_table_param.hidden_field_count= (all_fields.elements-
+ fields_list.elements);
/* group data to new table */
- if (!(tmp_table2 = create_tmp_table(thd,&join.tmp_table_param,all_fields,
+ if (!(tmp_table2 = create_tmp_table(thd, &tmp_table_param, all_fields,
(ORDER*) 0,
- select_distinct && !group,
+ select_distinct && !group_list,
1, 0,
- join.select_options)))
- goto err; /* purecov: inspected */
- if (group)
+ select_options, unit)))
+ DBUG_VOID_RETURN;
+ if (group_list)
{
thd->proc_info="Creating sort index";
- if (create_sort_index(join.join_tab,group,HA_POS_ERROR) ||
- alloc_group_fields(&join,group))
+ if (create_sort_index(join_tab, group_list, HA_POS_ERROR) ||
+ alloc_group_fields(this, group_list))
{
free_tmp_table(thd,tmp_table2); /* purecov: inspected */
- goto err; /* purecov: inspected */
+ DBUG_VOID_RETURN;
}
- group=0;
+ group_list= 0;
}
thd->proc_info="Copying to group table";
tmp_error= -1;
- if (make_sum_func_list(&join,all_fields) ||
- (tmp_error=do_select(&join,(List<Item> *) 0,tmp_table2,0)))
+ if (make_sum_func_list(this, all_fields) ||
+ (tmp_error=do_select(this, (List<Item> *) 0,tmp_table2,0)))
{
error=tmp_error;
free_tmp_table(thd,tmp_table2);
- goto err; /* purecov: inspected */
+ DBUG_VOID_RETURN;
}
- end_read_record(&join.join_tab->read_record);
- free_tmp_table(thd,tmp_table);
- join.const_tables=join.tables; // Mark free for join_free()
- tmp_table=tmp_table2;
- join.join_tab[0].table=0; // Table is freed
+ end_read_record(&join_tab->read_record);
+ free_tmp_table(thd,exec_tmp_table);
+ const_tables= tables; // Mark free for join_free()
+ exec_tmp_table= tmp_table2;
+ join_tab[0].table= 0; // Table is freed
if (change_to_use_tmp_fields(all_fields)) // No sum funcs anymore
- goto err;
- join.tmp_table_param.field_count+=join.tmp_table_param.sum_func_count;
- join.tmp_table_param.sum_func_count=0;
+ DBUG_VOID_RETURN;
+ tmp_table_param.field_count+= tmp_table_param.sum_func_count;
+ tmp_table_param.sum_func_count= 0;
}
- if (tmp_table->distinct)
+ if (exec_tmp_table->distinct)
select_distinct=0; /* Each row is unique */
- join_free(&join); /* Free quick selects */
- if (select_distinct && ! group)
+ join_free(this); /* Free quick selects */
+ if (select_distinct && ! group_list)
{
thd->proc_info="Removing duplicates";
- if (having)
- having->update_used_tables();
- if (remove_duplicates(&join,tmp_table,fields, having))
- goto err; /* purecov: inspected */
- having=0;
+ if (having_list)
+ having_list->update_used_tables();
+ if (remove_duplicates(this, exec_tmp_table, fields_list, having_list))
+ DBUG_VOID_RETURN;
+ having_list=0;
select_distinct=0;
}
- tmp_table->reginfo.lock_type=TL_UNLOCK;
- if (make_simple_join(&join,tmp_table))
- goto err;
- calc_group_buffer(&join,group);
- count_field_types(&join.tmp_table_param,all_fields,0);
+ exec_tmp_table->reginfo.lock_type=TL_UNLOCK;
+ if (make_simple_join(this, exec_tmp_table))
+ DBUG_VOID_RETURN;
+ calc_group_buffer(this, group_list);
+ count_field_types(&tmp_table_param, all_fields, 0);
}
if (procedure)
{
- if (procedure->change_columns(fields) ||
- result->prepare(fields))
- goto err;
- count_field_types(&join.tmp_table_param,all_fields,0);
+ if (procedure->change_columns(fields_list) ||
+ result->prepare(fields_list, unit))
+ DBUG_VOID_RETURN;
+ count_field_types(&tmp_table_param, all_fields, 0);
}
- if (join.group || join.tmp_table_param.sum_func_count ||
+ if (group || tmp_table_param.sum_func_count ||
(procedure && (procedure->flags & PROC_GROUP)))
{
- alloc_group_fields(&join,group);
- setup_copy_fields(thd, &join.tmp_table_param,all_fields);
- if (make_sum_func_list(&join,all_fields) || thd->fatal_error)
- goto err; /* purecov: inspected */
+ alloc_group_fields(this, group_list);
+ setup_copy_fields(thd, &tmp_table_param,all_fields);
+ if (make_sum_func_list(this, all_fields) || thd->fatal_error)
+ DBUG_VOID_RETURN;
}
- if (group || order)
+ if (group_list || order)
{
DBUG_PRINT("info",("Sorting for send_fields"));
thd->proc_info="Sorting result";
/* If we have already done the group, add HAVING to sorted table */
- if (having && ! group && ! join.sort_and_group)
+ if (having_list && ! group_list && ! sort_and_group)
{
- having->update_used_tables(); // Some tables may have been const
- JOIN_TAB *table=&join.join_tab[join.const_tables];
- table_map used_tables= join.const_table_map | table->table->map;
+ having_list->update_used_tables(); // Some tables may have been const
+ JOIN_TAB *table= &join_tab[const_tables];
+ table_map used_tables= const_table_map | table->table->map;
- Item* sort_table_cond=make_cond_for_table(having,used_tables,used_tables);
+ Item* sort_table_cond= make_cond_for_table(having_list, used_tables,
+ used_tables);
if (sort_table_cond)
{
if (!table->select)
if (!(table->select=new SQL_SELECT))
- goto err;
+ DBUG_VOID_RETURN;
if (!table->select->cond)
table->select->cond=sort_table_cond;
else // This should never happen
if (!(table->select->cond=new Item_cond_and(table->select->cond,
sort_table_cond)))
- goto err;
+ DBUG_VOID_RETURN;
table->select_cond=table->select->cond;
DBUG_EXECUTE("where",print_where(table->select->cond,
"select and having"););
- having=make_cond_for_table(having,~ (table_map) 0,~used_tables);
+ having_list= make_cond_for_table(having_list, ~ (table_map) 0,
+ ~used_tables);
DBUG_EXECUTE("where",print_where(conds,"having after sort"););
}
}
- if (create_sort_index(&join.join_tab[join.const_tables],
- group ? group : order,
- (having || group ||
- join.const_tables != join.tables - 1 ||
- (join.select_options & OPTION_FOUND_ROWS)) ?
- HA_POS_ERROR : thd->select_limit))
- goto err; /* purecov: inspected */
+ if (create_sort_index(&join_tab[const_tables],
+ group_list ? group_list : order,
+ (having_list || group_list ||
+ const_tables != tables - 1 ||
+ (select_options & OPTION_FOUND_ROWS)) ?
+ HA_POS_ERROR : unit->select_limit_cnt))
+ DBUG_VOID_RETURN;
}
- join.having=having; // Actually a parameter
+ having=having_list; // Actually a parameter
thd->proc_info="Sending data";
- error=do_select(&join,&fields,NULL,procedure);
+ error=do_select(this, &fields_list, NULL, procedure);
+ DBUG_VOID_RETURN;
+}
-err:
- thd->limit_found_rows = join.send_records;
- thd->examined_row_count = join.examined_rows;
- thd->proc_info="end";
- join.lock=0; // It's faster to unlock later
- join_free(&join);
- thd->proc_info="end2"; // QQ
- if (tmp_table)
- free_tmp_table(thd,tmp_table);
- thd->proc_info="end3"; // QQ
+/*
+ Clean up join. Return error that hold JOIN.
+*/
+
+int
+JOIN::cleanup(THD *thd)
+{
+ lock=0; // It's faster to unlock later
+ join_free(this);
+ if (exec_tmp_table)
+ free_tmp_table(thd, exec_tmp_table);
delete select;
delete_dynamic(&keyuse);
delete procedure;
- thd->proc_info="end4"; // QQ
+ for (SELECT_LEX_UNIT *unit= select_lex->first_inner_unit();
+ unit != 0;
+ unit= unit->next_unit())
+ for (SELECT_LEX *sl= unit->first_select();
+ sl != 0;
+ sl= sl->next_select())
+ {
+ if (sl->join)
+ {
+ int err= sl->join->cleanup(thd);
+ if (err)
+ error= err;
+ sl->join= 0;
+ }
+ }
+ return error;
+}
+
+int
+mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds,
+ ORDER *order, ORDER *group,Item *having, ORDER *proc_param,
+ ulong select_options, select_result *result, SELECT_LEX_UNIT *unit)
+{
+ JOIN *join = new JOIN(thd, fields, select_options, result);
+
+ DBUG_ENTER("mysql_select");
+ thd->proc_info="init";
+ thd->used_tables=0; // Updated by setup_fields
+
+ if (join->prepare(tables, conds, order, group, having, proc_param,
+ &(thd->lex.select_lex), unit))
+ {
+ DBUG_RETURN(-1);
+ }
+ switch (join->optimize()) {
+ case 1:
+ DBUG_RETURN(join->error);
+ case -1:
+ goto err;
+ }
+
+ if(join->global_optimize())
+ goto err;
+
+ join->exec();
+
+err:
+ thd->limit_found_rows = join->send_records;
+ thd->examined_row_count = join->examined_rows;
+ thd->proc_info="end";
+ int error= join->cleanup(thd);
+ delete join;
DBUG_RETURN(error);
}
@@ -1731,7 +1887,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
{
ulong rec;
double tmp;
- THD *thd= current_thd;
+ THD *thd= join->thd;
if (!rest_tables)
{
@@ -2352,7 +2508,7 @@ store_val_in_field(Field *field,Item *item)
THD *thd=current_thd;
ulong cuted_fields=thd->cuted_fields;
thd->count_cuted_fields=1;
- item->save_in_field(field);
+ (void) item->save_in_field(field);
thd->count_cuted_fields=0;
return cuted_fields != thd->cuted_fields;
}
@@ -2380,7 +2536,7 @@ make_simple_join(JOIN *join,TABLE *tmp_table)
join->send_records=(ha_rows) 0;
join->group=0;
join->do_send_rows = 1;
- join->row_limit=join->thd->select_limit;
+ join->row_limit=join->unit->select_limit_cnt;
join_tab->cache.buff=0; /* No cacheing */
join_tab->table=tmp_table;
@@ -2497,7 +2653,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
if ((tab->keys & ~ tab->const_keys && i > 0) ||
(tab->const_keys && i == join->const_tables &&
- join->thd->select_limit < join->best_positions[i].records_read &&
+ join->unit->select_limit_cnt <
+ join->best_positions[i].records_read &&
!(join->select_options & OPTION_FOUND_ROWS)))
{
/* Join with outer join condition */
@@ -2508,7 +2665,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
(join->select_options &
OPTION_FOUND_ROWS ?
HA_POS_ERROR :
- join->thd->select_limit)) < 0)
+ join->unit->select_limit_cnt)) < 0)
DBUG_RETURN(1); // Impossible range
sel->cond=orig_cond;
}
@@ -2550,7 +2707,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
static void
-make_join_readinfo(JOIN *join,uint options)
+make_join_readinfo(JOIN *join, uint options)
{
uint i;
SELECT_LEX *select_lex = &(join->thd->lex.select_lex);
@@ -2730,7 +2887,9 @@ join_free(JOIN *join)
}
end_read_record(&tab->read_record);
}
- join->table=0;
+ //TODO: is enough join_free at the end of mysql_select?
+ if (!join->select_lex->depended)
+ join->table=0;
}
/*
We are not using tables anymore
@@ -2949,18 +3108,19 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond, bool *simple_order)
static int
return_zero_rows(JOIN *join, select_result *result,TABLE_LIST *tables,
List<Item> &fields, bool send_row, uint select_options,
- const char *info, Item *having, Procedure *procedure)
+ const char *info, Item *having, Procedure *procedure,
+ SELECT_LEX_UNIT *unit)
{
DBUG_ENTER("return_zero_rows");
if (select_options & SELECT_DESCRIBE)
- {
+ {
describe_info(join, info);
DBUG_RETURN(0);
}
if (procedure)
{
- if (result->prepare(fields)) // This hasn't been done yet
+ if (result->prepare(fields, unit)) // This hasn't been done yet
DBUG_RETURN(-1);
}
if (send_row)
@@ -3279,7 +3439,7 @@ remove_eq_conds(COND *cond,Item::cond_result *cond_value)
21))))
{
cond=new_cond;
- cond->fix_fields(thd,0);
+ cond->fix_fields(thd, 0, &cond);
}
thd->insert_id(0); // Clear for next request
}
@@ -3293,7 +3453,7 @@ remove_eq_conds(COND *cond,Item::cond_result *cond_value)
if ((new_cond= new Item_func_eq(args[0],new Item_int("0", 0, 2))))
{
cond=new_cond;
- cond->fix_fields(thd,0);
+ cond->fix_fields(thd, 0, &cond);
}
}
}
@@ -3397,14 +3557,14 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
case Item_sum::AVG_FUNC: /* Place for sum & count */
if (group)
return new Field_string(sizeof(double)+sizeof(longlong),
- maybe_null, item->name,table,1);
+ maybe_null, item->name,table,1,default_charset_info);
else
return new Field_double(item_sum->max_length,maybe_null,
item->name, table, item_sum->decimals);
case Item_sum::STD_FUNC: /* Place for sum & count */
if (group)
return new Field_string(sizeof(double)*2+sizeof(longlong),
- maybe_null, item->name,table,1);
+ maybe_null, item->name,table,1,default_charset_info);
else
return new Field_double(item_sum->max_length, maybe_null,
item->name,table,item_sum->decimals);
@@ -3421,9 +3581,9 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
case STRING_RESULT:
if (item_sum->max_length > 255)
return new Field_blob(item_sum->max_length,maybe_null,
- item->name,table,item->binary);
+ item->name,table,item->binary,default_charset_info);
return new Field_string(item_sum->max_length,maybe_null,
- item->name,table,item->binary);
+ item->name,table,item->binary,default_charset_info);
}
}
thd->fatal_error=1;
@@ -3474,10 +3634,12 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
case STRING_RESULT:
if (item->max_length > 255)
new_field= new Field_blob(item->max_length,maybe_null,
- item->name,table,item->binary);
+ item->name,table,item->binary,
+ item->str_value.charset());
else
new_field= new Field_string(item->max_length,maybe_null,
- item->name,table,item->binary);
+ item->name,table,item->binary,
+ item->str_value.charset());
break;
}
if (copy_func)
@@ -3495,7 +3657,8 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
TABLE *
create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
ORDER *group, bool distinct, bool save_sum_fields,
- bool allow_distinct_limit, ulong select_options)
+ bool allow_distinct_limit, ulong select_options,
+ SELECT_LEX_UNIT *unit)
{
TABLE *table;
uint i,field_count,reclength,null_count,null_pack_length,
@@ -3870,8 +4033,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
test(null_pack_length));
if (allow_distinct_limit)
{
- set_if_smaller(table->max_rows,thd->select_limit);
- param->end_write_records=thd->select_limit;
+ set_if_smaller(table->max_rows, unit->select_limit_cnt);
+ param->end_write_records= unit->select_limit_cnt;
}
else
param->end_write_records= HA_POS_ERROR;
@@ -3900,7 +4063,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
(uchar*) 0,
(uint) 0,
Field::NONE,
- NullS, table, (bool) 1);
+ NullS, table, (bool) 1, default_charset_info);
key_part_info->key_type=FIELDFLAG_BINARY;
key_part_info->type= HA_KEYTYPE_BINARY;
key_part_info++;
@@ -3966,7 +4129,7 @@ static bool create_myisam_tmp_table(TABLE *table,TMP_TABLE_PARAM *param,
if (table->keys)
{ // Get keys for ni_create
bool using_unique_constraint=0;
- MI_KEYSEG *seg= (MI_KEYSEG*) sql_calloc(sizeof(*seg) *
+ HA_KEYSEG *seg= (HA_KEYSEG*) sql_calloc(sizeof(*seg) *
keyinfo->key_parts);
if (!seg)
goto err;
@@ -4003,7 +4166,9 @@ static bool create_myisam_tmp_table(TABLE *table,TMP_TABLE_PARAM *param,
{
Field *field=keyinfo->key_part[i].field;
seg->flag= 0;
- seg->language= MY_CHARSET_CURRENT;
+ seg->language= field->binary() ? MY_CHARSET_CURRENT :
+ ((Field_str*)field)->charset()->number;
+
seg->length= keyinfo->key_part[i].length;
seg->start= keyinfo->key_part[i].offset;
if (field->flags & BLOB_FLAG)
@@ -4042,6 +4207,7 @@ static bool create_myisam_tmp_table(TABLE *table,TMP_TABLE_PARAM *param,
}
MI_CREATE_INFO create_info;
bzero((char*) &create_info,sizeof(create_info));
+
if ((options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) ==
OPTION_BIG_TABLES)
create_info.data_file_length= ~(ulonglong) 0;
@@ -4916,7 +5082,7 @@ end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
error=join->result->send_data(*join->fields);
if (error)
DBUG_RETURN(-1); /* purecov: inspected */
- if (++join->send_records >= join->thd->select_limit &&
+ if (++join->send_records >= join->unit->select_limit_cnt &&
join->do_send_rows)
{
if (join->select_options & OPTION_FOUND_ROWS)
@@ -4945,8 +5111,8 @@ end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
}
else
{
- join->do_send_rows=0;
- join->thd->select_limit = HA_POS_ERROR;
+ join->do_send_rows= 0;
+ join->unit->select_limit= HA_POS_ERROR;
DBUG_RETURN(0);
}
}
@@ -5009,14 +5175,13 @@ end_send_group(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
join->send_records++;
DBUG_RETURN(0);
}
- if (!error &&
- ++join->send_records >= join->thd->select_limit &&
+ if (!error && ++join->send_records >= join->unit->select_limit_cnt &&
join->do_send_rows)
{
if (!(join->select_options & OPTION_FOUND_ROWS))
DBUG_RETURN(-3); // Abort nicely
join->do_send_rows=0;
- join->thd->select_limit = HA_POS_ERROR;
+ join->unit->select_limit_cnt = HA_POS_ERROR;
}
}
}
@@ -5097,7 +5262,7 @@ end_write(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
if (!(join->select_options & OPTION_FOUND_ROWS))
DBUG_RETURN(-3);
join->do_send_rows=0;
- join->thd->select_limit = HA_POS_ERROR;
+ join->unit->select_limit_cnt = HA_POS_ERROR;
DBUG_RETURN(0);
}
}
@@ -5799,7 +5964,7 @@ remove_duplicates(JOIN *join, TABLE *entry,List<Item> &fields, Item *having)
if (!field_count)
{ // only const items
- join->thd->select_limit=1; // Only send first row
+ join->unit->select_limit_cnt= 1; // Only send first row
DBUG_RETURN(0);
}
Field **first_field=entry->field+entry->fields - field_count;
@@ -5936,8 +6101,10 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table,
(uint) (field_count*sizeof(*field_lengths)),
NullS))
DBUG_RETURN(1);
- if (hash_init(&hash, (uint) file->records, 0, key_length,
- (hash_get_key) 0, 0, 0))
+
+ // BAR TODO: this must be fixed to use charset from "table" argument
+ if (hash_init(&hash, default_charset_info, (uint) file->records, 0,
+ key_length,(hash_get_key) 0, 0, 0))
{
my_free((char*) key_buffer,MYF(0));
DBUG_RETURN(1);
@@ -6341,7 +6508,7 @@ find_order_in_list(THD *thd,TABLE_LIST *tables,ORDER *order,List<Item> &fields,
return 0;
}
order->in_field_list=0;
- if ((*order->item)->fix_fields(thd,tables) || thd->fatal_error)
+ if ((*order->item)->fix_fields(thd, tables, order->item) || thd->fatal_error)
return 1; // Wrong field
all_fields.push_front(*order->item); // Add new field to field list
order->item=(Item**) all_fields.head_ref();
@@ -6367,7 +6534,7 @@ int setup_order(THD *thd,TABLE_LIST *tables,List<Item> &fields,
}
-static int
+int
setup_group(THD *thd,TABLE_LIST *tables,List<Item> &fields,
List<Item> &all_fields, ORDER *order, bool *hidden_group_fields)
{
@@ -6439,7 +6606,7 @@ setup_new_fields(THD *thd,TABLE_LIST *tables,List<Item> &fields,
else
{
thd->where="procedure list";
- if ((*new_field->item)->fix_fields(thd,tables))
+ if ((*new_field->item)->fix_fields(thd, tables, new_field->item))
DBUG_RETURN(1); /* purecov: inspected */
thd->where=0;
all_fields.push_front(*new_field->item);
@@ -6832,7 +6999,7 @@ change_to_use_tmp_fields(List<Item> &items)
if (_db_on_ && !item_field->name)
{
char buff[256];
- String str(buff,sizeof(buff));
+ String str(buff,sizeof(buff),default_charset_info);
str.length(0);
item->print(&str);
item_field->name=sql_strmake(str.ptr(),str.length());
@@ -7004,7 +7171,7 @@ static bool add_ref_to_table_cond(THD *thd, JOIN_TAB *join_tab)
Here we pass 0 as the first argument to fix_fields that don't need
to do any stack checking (This is already done in the initial fix_fields).
*/
- cond->fix_fields((THD *) 0,(TABLE_LIST *) 0);
+ cond->fix_fields((THD *) 0,(TABLE_LIST *) 0, (Item**)&cond);
if (join_tab->select)
{
error=(int) cond->add(join_tab->select->cond);
@@ -7035,7 +7202,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
/* Don't log this into the slow query log */
select_lex->options&= ~(QUERY_NO_INDEX_USED | QUERY_NO_GOOD_INDEX_USED);
- thd->offset_limit=0;
+ join->unit->offset_limit_cnt= 0;
if (thd->lex.select == select_lex)
{
field_list.push_back(new Item_empty_string("table",NAME_LEN));
@@ -7061,7 +7228,8 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
Item *empty= new Item_empty_string("",0);
for (uint i=0 ; i < 7; i++)
item_list.push_back(empty);
- item_list.push_back(new Item_string(message,strlen(message)));
+ item_list.push_back(new Item_string(message,strlen(message),
+ default_charset_info));
if (result->send_data(item_list))
result->send_error(0,NullS);
}
@@ -7074,8 +7242,8 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
TABLE *table=tab->table;
char buff[512],*buff_ptr=buff;
char buff1[512], buff2[512], buff3[512];
- String tmp1(buff1,sizeof(buff1));
- String tmp2(buff2,sizeof(buff2));
+ String tmp1(buff1,sizeof(buff1),default_charset_info);
+ String tmp2(buff2,sizeof(buff2),default_charset_info);
tmp1.length(0);
tmp2.length(0);
item_list.empty();
@@ -7083,9 +7251,11 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
if (tab->type == JT_ALL && tab->select && tab->select->quick)
tab->type= JT_RANGE;
item_list.push_back(new Item_string(table->table_name,
- strlen(table->table_name)));
+ strlen(table->table_name),
+ default_charset_info));
item_list.push_back(new Item_string(join_type_str[tab->type],
- strlen(join_type_str[tab->type])));
+ strlen(join_type_str[tab->type]),
+ default_charset_info));
key_map bits;
uint j;
for (j=0,bits=tab->keys ; bits ; j++,bits>>=1)
@@ -7098,9 +7268,10 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
}
}
if (tmp1.length())
- item_list.push_back(new Item_string(tmp1.ptr(),tmp1.length()));
+ item_list.push_back(new Item_string(tmp1.ptr(),tmp1.length(),
+ default_charset_info));
else
- item_list.push_back(item_null);
+ item_list.push_back(item_null);
if (tab->ref.key_parts)
{
KEY *key_info=table->key_info+ tab->ref.key;
@@ -7113,13 +7284,15 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
tmp2.append(',');
tmp2.append((*ref)->name());
}
- item_list.push_back(new Item_string(tmp2.ptr(),tmp2.length()));
+ item_list.push_back(new Item_string(tmp2.ptr(),tmp2.length(),
+ default_charset_info));
}
else if (tab->type == JT_NEXT)
{
KEY *key_info=table->key_info+ tab->index;
item_list.push_back(new Item_string(key_info->name,
- strlen(key_info->name)));
+ strlen(key_info->name),
+ default_charset_info));
item_list.push_back(new Item_int((int32) key_info->key_length));
item_list.push_back(item_null);
}
@@ -7127,8 +7300,10 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
{
KEY *key_info=table->key_info+ tab->select->quick->index;
item_list.push_back(new Item_string(key_info->name,
- strlen(key_info->name)));
- item_list.push_back(new Item_int((int32) tab->select->quick->max_used_key_length));
+ strlen(key_info->name),
+ default_charset_info));
+ item_list.push_back(new Item_int((int32) tab->select->quick->
+ max_used_key_length));
item_list.push_back(item_null);
}
else
@@ -7138,14 +7313,16 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
item_list.push_back(item_null);
}
sprintf(buff3,"%.0f",join->best_positions[i].records_read);
- item_list.push_back(new Item_string(buff3,strlen(buff3)));
+ item_list.push_back(new Item_string(buff3,strlen(buff3),
+ default_charset_info));
my_bool key_read=table->key_read;
if (tab->type == JT_NEXT &&
((table->used_keys & ((key_map) 1 << tab->index))))
key_read=1;
if (tab->info)
- item_list.push_back(new Item_string(tab->info,strlen(tab->info)));
+ item_list.push_back(new Item_string(tab->info,strlen(tab->info),
+ default_charset_info));
else if (tab->select)
{
if (tab->use_quick == 2)
@@ -7199,14 +7376,15 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
}
buff_ptr=strmov(buff_ptr,"Distinct");
}
- item_list.push_back(new Item_string(buff,(uint) (buff_ptr - buff)));
+ item_list.push_back(new Item_string(buff,(uint) (buff_ptr - buff),
+ default_charset_info));
// For next iteration
used_tables|=table->map;
if (result->send_data(item_list))
result->send_error(0,NullS);
}
}
- if (!thd->lex.select->next) // Not union
+ if (!thd->lex.select->next_select())
{
save_lock=thd->lock;
thd->lock=(MYSQL_LOCK *)0;
@@ -7221,7 +7399,7 @@ static void describe_info(JOIN *join, const char *info)
{
THD *thd= join->thd;
- if (thd->lex.select_lex.next) /* If in UNION */
+ if (thd->lex.select->next_select()) /* If in UNION */
{
select_describe(join,FALSE,FALSE,FALSE,info);
return;
diff --git a/sql/sql_select.h b/sql/sql_select.h
index befa1efde53..f651f069c13 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -149,8 +149,7 @@ class TMP_TABLE_PARAM {
}
};
-
-class JOIN {
+class JOIN :public Sql_alloc{
public:
JOIN_TAB *join_tab,**best_ref,**map2table;
TABLE **table,**all_tables,*sort_by_table;
@@ -173,6 +172,75 @@ class JOIN {
select_result *result;
TMP_TABLE_PARAM tmp_table_param;
MYSQL_LOCK *lock;
+ // unit structure (with global parameters) for this select
+ SELECT_LEX_UNIT *unit;
+ // select that processed
+ SELECT_LEX *select_lex;
+
+ bool select_distinct, //Is select distinct?
+ no_order, simple_order, simple_group,
+ skip_sort_order, need_tmp,
+ hidden_group_fields,
+ buffer_result;
+ DYNAMIC_ARRAY keyuse;
+ Item::cond_result cond_value;
+ List<Item> all_fields;
+ List<Item> & fields_list; // hold field list passed to mysql_select
+ int error;
+
+ ORDER *order, *group_list, *proc_param; //hold parameters of mysql_select
+ COND *conds; // ---"---
+ TABLE_LIST *tables_list; //hold 'tables' parameter of mysql_selec
+ SQL_SELECT *select; //created in optimisation phase
+ TABLE *exec_tmp_table; //used in 'exec' to hold temporary
+
+ my_bool test_function_query; // need to return select items 1 row
+ const char *zero_result_cause; // not 0 if exec must return zero result
+
+ my_bool union_part; // this subselect is part of union
+
+ JOIN(THD *thd, List<Item> &fields,
+ ulong select_options, select_result *result):
+ join_tab(0),
+ table(0),
+ tables(0), const_tables(0),
+ sort_and_group(0), first_record(0),
+ do_send_rows(1),
+ send_records(0), found_records(0), examined_rows(0),
+ thd(thd),
+ sum_funcs(0),
+ having(0),
+ select_options(select_options),
+ result(result),
+ lock(thd->lock),
+ select_lex(0), //for safety
+ select_distinct(test(select_options & SELECT_DISTINCT)),
+ no_order(0), simple_order(0), simple_group(0), skip_sort_order(0),
+ need_tmp(0),
+ hidden_group_fields (0), /*safety*/
+ buffer_result(test(select_options & OPTION_BUFFER_RESULT) &&
+ !test(select_options & OPTION_FOUND_ROWS)),
+ all_fields(fields),
+ fields_list(fields),
+ select(0),
+ exec_tmp_table(0),
+ test_function_query(0),
+ zero_result_cause(0)
+ {
+ fields_list = fields;
+ bzero((char*) &keyuse,sizeof(keyuse));
+ tmp_table_param.copy_field=0;
+ tmp_table_param.end_write_records= HA_POS_ERROR;
+ }
+
+ int prepare(TABLE_LIST *tables,
+ COND *conds, ORDER *order, ORDER *group, Item *having,
+ ORDER *proc_param, SELECT_LEX *select, SELECT_LEX_UNIT *unit);
+ int optimize();
+ int global_optimize();
+ int reinit();
+ void exec();
+ int cleanup(THD *thd);
};
@@ -187,7 +255,8 @@ void TEST_join(JOIN *join);
bool store_val_in_field(Field *field,Item *val);
TABLE *create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
ORDER *group, bool distinct, bool save_sum_fields,
- bool allow_distinct_limit, ulong select_options);
+ bool allow_distinct_limit, ulong select_options,
+ SELECT_LEX_UNIT *unit);
void free_tmp_table(THD *thd, TABLE *entry);
void count_field_types(TMP_TABLE_PARAM *param, List<Item> &fields,
bool reset_with_sum_func);
@@ -217,7 +286,7 @@ class store_key :public Sql_alloc
if (field_arg->type() == FIELD_TYPE_BLOB)
to_field=new Field_varstring(ptr, length, (uchar*) null, 1,
Field::NONE, field_arg->field_name,
- field_arg->table, field_arg->binary());
+ field_arg->table, field_arg->binary(), default_charset_info);
else
{
to_field=field_arg->new_field(&thd->mem_root,field_arg->table);
@@ -269,7 +338,7 @@ public:
{}
bool copy()
{
- item->save_in_field(to_field);
+ (void) item->save_in_field(to_field);
return err != 0;
}
const char *name() const { return "func"; }
@@ -293,7 +362,7 @@ public:
if (!inited)
{
inited=1;
- item->save_in_field(to_field);
+ (void)item->save_in_field(to_field);
}
return err != 0;
}
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index bf9abaaa32d..5899fe86024 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -57,7 +57,7 @@ extern struct st_VioSSLAcceptorFd * ssl_acceptor_fd;
int
mysqld_show_dbs(THD *thd,const char *wild)
{
- Item_string *field=new Item_string("",0);
+ Item_string *field=new Item_string("",0,default_charset_info);
List<Item> field_list;
char *end;
List<char> files;
@@ -140,7 +140,7 @@ int mysqld_show_open_tables(THD *thd,const char *wild)
int mysqld_show_tables(THD *thd,const char *db,const char *wild)
{
- Item_string *field=new Item_string("",0);
+ Item_string *field=new Item_string("",0,default_charset_info);
List<Item> field_list;
char path[FN_LEN],*end;
List<char> files;
@@ -171,6 +171,201 @@ int mysqld_show_tables(THD *thd,const char *db,const char *wild)
DBUG_RETURN(0);
}
+/***************************************************************************
+** List all table types supported
+***************************************************************************/
+
+static struct show_table_type_st sys_table_types[]= {
+ {"MyISAM", (char *)"YES", "Default type from 3.23 with great performance"},
+ {"HEAP" , (char *)"YES", "Hash based, stored in memory, useful for temporary tables"},
+ {"MERGE", (char *)"YES", "Collection of identical MyISAM tables"},
+ {"ISAM", (char*) &have_isam,"Obsolete table type"},
+ {"InnoDB", (char*) &have_innodb,"Supports transactions, row-level locking and foreign keys"},
+ {"BDB", (char*) &have_berkeley_db, "Supports transactions and page-level locking"},
+};
+
+int mysqld_show_table_types(THD *thd)
+{
+ List<Item> field_list;
+ DBUG_ENTER("mysqld_show_table_types");
+
+ field_list.push_back(new Item_empty_string("Type",10));
+ field_list.push_back(new Item_empty_string("Support",10));
+ field_list.push_back(new Item_empty_string("Comment",NAME_LEN));
+
+ if (send_fields(thd,field_list,1))
+ DBUG_RETURN(1);
+
+ const char *default_type_name=ha_table_typelib.type_names[default_table_type-1];
+ show_table_type_st *types = sys_table_types;
+
+ uint i;
+ for (i = 0; i < 3; i++)
+ {
+ thd->packet.length(0);
+ net_store_data(&thd->packet,types[i].type);
+ if (!strcasecmp(default_type_name,types[i].type))
+ net_store_data(&thd->packet,"DEFAULT");
+ else
+ net_store_data(&thd->packet,types[i].value);
+ net_store_data(&thd->packet,types[i].comment);
+ if (my_net_write(&thd->net,(char*) thd->packet.ptr(),thd->packet.length()))
+ DBUG_RETURN(-1);
+ }
+
+ for (; i < sizeof(sys_table_types)/sizeof(sys_table_types[0]); i++)
+ {
+ thd->packet.length(0);
+ net_store_data(&thd->packet,types[i].type);
+ SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) types[i].value;
+
+ if (tmp == SHOW_OPTION_NO)
+ net_store_data(&thd->packet,"NO");
+ else
+ {
+ if (tmp == SHOW_OPTION_YES)
+ {
+ if (!strcasecmp(default_type_name,types[i].type))
+ net_store_data(&thd->packet,"DEFAULT");
+ else
+ net_store_data(&thd->packet,"YES");
+ }
+ else net_store_data(&thd->packet,"DISABLED");
+ }
+ net_store_data(&thd->packet,types[i].comment);
+ if (my_net_write(&thd->net,(char*) thd->packet.ptr(),thd->packet.length()))
+ DBUG_RETURN(-1);
+ }
+ send_eof(&thd->net);
+ DBUG_RETURN(0);
+}
+
+/***************************************************************************
+** List all privileges supported
+***************************************************************************/
+
+static struct show_table_type_st sys_privileges[]= {
+ {"Select", (char *)"Tables", "To retrieve rows from table"},
+ {"Insert", (char *)"Tables", "To insert data into tables"},
+ {"Update", (char *)"Tables", "To update existing rows "},
+ {"Delete", (char *)"Tables", "To delete existing rows"},
+ {"Index", (char *)"Tables", "To create or drop indexes"},
+ {"Alter", (char *)"Tables", "To alter the table"},
+ {"Create", (char *)"Databases,Tables,Indexes", "To create new databases and tables"},
+ {"Drop", (char *)"Databases,Tables", "To drop databases and tables"},
+ {"Grant", (char *)"Databases,Tables", "To give to other users those privileges you possesed"},
+ {"References", (char *)"Databases,Tables", "To have references on tables"},
+ {"Reload", (char *)"Server Admin", "To reload or refresh tables, logs and privileges"},
+ {"Shutdown",(char *)"Server Admin", "To shutdown the server"},
+ {"Process", (char *)"Server Admin", "To view the plain text of currently executing queries"},
+ {"File", (char *)"File access on server", "To read and write files on the server"},
+};
+
+int mysqld_show_privileges(THD *thd)
+{
+ List<Item> field_list;
+ DBUG_ENTER("mysqld_show_privileges");
+
+ field_list.push_back(new Item_empty_string("Privilege",10));
+ field_list.push_back(new Item_empty_string("Context",15));
+ field_list.push_back(new Item_empty_string("Comment",NAME_LEN));
+
+ if (send_fields(thd,field_list,1))
+ DBUG_RETURN(1);
+
+ for (uint i=0; i < sizeof(sys_privileges)/sizeof(sys_privileges[0]); i++)
+ {
+ thd->packet.length(0);
+ net_store_data(&thd->packet,sys_privileges[i].type);
+ net_store_data(&thd->packet,sys_privileges[i].value);
+ net_store_data(&thd->packet,sys_privileges[i].comment);
+ if (my_net_write(&thd->net,(char*) thd->packet.ptr(),thd->packet.length()))
+ DBUG_RETURN(-1);
+ }
+ send_eof(&thd->net);
+ DBUG_RETURN(0);
+}
+
+
+/***************************************************************************
+** List all column types
+***************************************************************************/
+
+#if 0
+struct show_column_type_st {
+ const char *type;
+ uint size;
+ char *min_value;
+ char *max_value;
+ uint precision,
+ uint scale,
+ char *nullable;
+ char *auto_increment;
+ char *unsigned_attr;
+ char *zerofill;
+ char *searchable;
+ char *case_sensitivity;
+ char *default_value;
+ char *comment;
+};
+#endif
+static struct show_column_type_st sys_column_types[]= {
+ {"tinyint",
+ 1, "-128", "127", 0, 0, "YES", "YES",
+ "NO", "YES", "YES", "NO", "NULL,0",
+ "A very small integer"},
+ {"tinyint unsigned",
+ 1, "0" , "255", 0, 0, "YES", "YES",
+ "YES", "YES", "YES", "NO", "NULL,0",
+ "A very small integer"},
+};
+
+int mysqld_show_column_types(THD *thd)
+{
+ List<Item> field_list;
+ DBUG_ENTER("mysqld_show_column_types");
+
+ field_list.push_back(new Item_empty_string("Type",30));
+ field_list.push_back(new Item_int("Size",(longlong) 1,21));
+ field_list.push_back(new Item_empty_string("Min_Value",20));
+ field_list.push_back(new Item_empty_string("Max_Value",20));
+ field_list.push_back(new Item_int("Prec", 0,4));
+ field_list.push_back(new Item_int("Scale", 0,4));
+ field_list.push_back(new Item_empty_string("Nullable",4));
+ field_list.push_back(new Item_empty_string("Auto_Increment",4));
+ field_list.push_back(new Item_empty_string("Unsigned",4));
+ field_list.push_back(new Item_empty_string("Zerofill",4));
+ field_list.push_back(new Item_empty_string("Searchable",4));
+ field_list.push_back(new Item_empty_string("Case_Sensitive",4));
+ field_list.push_back(new Item_empty_string("Default",NAME_LEN));
+ field_list.push_back(new Item_empty_string("Comment",NAME_LEN));
+
+ if (send_fields(thd,field_list,1))
+ DBUG_RETURN(1);
+
+ for (uint i=0; i < sizeof(sys_column_types)/sizeof(sys_column_types[0]); i++)
+ {
+ thd->packet.length(0);
+ net_store_data(&thd->packet,sys_column_types[i].type);
+ net_store_data(&thd->packet,(longlong)sys_column_types[i].size);
+ net_store_data(&thd->packet,sys_column_types[i].min_value);
+ net_store_data(&thd->packet,sys_column_types[i].max_value);
+ net_store_data(&thd->packet,(uint32)sys_column_types[i].precision);
+ net_store_data(&thd->packet,(uint32)sys_column_types[i].scale);
+ net_store_data(&thd->packet,sys_column_types[i].nullable);
+ net_store_data(&thd->packet,sys_column_types[i].auto_increment);
+ net_store_data(&thd->packet,sys_column_types[i].unsigned_attr);
+ net_store_data(&thd->packet,sys_column_types[i].zerofill);
+ net_store_data(&thd->packet,sys_column_types[i].searchable);
+ net_store_data(&thd->packet,sys_column_types[i].case_sensitivity);
+ net_store_data(&thd->packet,sys_column_types[i].default_value);
+ net_store_data(&thd->packet,sys_column_types[i].comment);
+ if (my_net_write(&thd->net,(char*) thd->packet.ptr(),thd->packet.length()))
+ DBUG_RETURN(-1);
+ }
+ send_eof(&thd->net);
+ DBUG_RETURN(0);
+}
static int
mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
@@ -211,7 +406,7 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
else
{
// Return only .frm files which aren't temp files.
- if (my_strcasecmp(ext=fn_ext(file->name),reg_ext) ||
+ if (my_strcasecmp(system_charset_info, ext=fn_ext(file->name),reg_ext) ||
is_prefix(file->name,tmp_file_prefix))
continue;
*ext=0;
@@ -219,7 +414,7 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
{
if (lower_case_table_names)
{
- if (wild_case_compare(file->name,wild))
+ if (wild_case_compare(system_charset_info,file->name,wild))
continue;
}
else if (wild_compare(file->name,wild))
@@ -264,7 +459,7 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild)
(void) sprintf(path,"%s/%s",mysql_data_home,db);
(void) unpack_dirname(path,path);
-
+//,default_charset_info
field_list.push_back(item=new Item_empty_string("Name",NAME_LEN));
item->maybe_null=1;
field_list.push_back(item=new Item_empty_string("Type",10));
@@ -458,8 +653,10 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
item->maybe_null=1;
field_list.push_back(new Item_empty_string("Extra",20));
if (verbose)
+ {
field_list.push_back(new Item_empty_string("Privileges",80));
-
+ field_list.push_back(new Item_empty_string("Comment",255));
+ }
// Send first number of fields and records
{
char *pos;
@@ -476,7 +673,8 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
String *packet= &thd->packet;
for (ptr=table->field; (field= *ptr) ; ptr++)
{
- if (!wild || !wild[0] || !wild_case_compare(field->field_name,wild))
+ if (!wild || !wild[0] ||
+ !wild_case_compare(system_charset_info, field->field_name,wild))
{
#ifdef NOT_USED
if (thd->col_access & TABLE_ACLS ||
@@ -486,7 +684,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
{
byte *pos;
uint flags=field->flags;
- String type(tmp,sizeof(tmp));
+ String type(tmp,sizeof(tmp),default_charset_info);
uint col_access;
bool null_default_value=0;
@@ -509,7 +707,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
null_default_value=1;
if (!null_default_value && !field->is_null())
{ // Not null by default
- type.set(tmp,sizeof(tmp));
+ type.set(tmp,sizeof(tmp),default_charset_info);
field->val_str(&type,&type);
net_store_data(packet,convert,type.ptr(),type.length());
}
@@ -525,7 +723,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
if (verbose)
{
- /* Add grant options */
+ /* Add grant options & comments */
col_access= get_column_grant(thd,table_list,field) & COL_ACLS;
end=tmp;
for (uint bitnr=0; col_access ; col_access>>=1,bitnr++)
@@ -537,6 +735,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
}
}
net_store_data(packet,convert, tmp+1,end == tmp ? 0 : (uint) (end-tmp-1));
+ net_store_data(packet, field->comment.str,field->comment.length);
}
if (my_net_write(&thd->net,(char*) packet->ptr(),packet->length()))
DBUG_RETURN(1);
@@ -584,6 +783,10 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
if (store_create_info(thd, table, packet))
DBUG_RETURN(-1);
ulong create_len = packet->length() - store_len_offset - 4;
+ /*
+ Just in case somebody manages to create a table
+ with *that* much stuff in the definition
+ */
if (create_len > 0x00ffffff) // better readable in HEX ...
{
/*
@@ -757,7 +960,8 @@ mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
Field **ptr,*field;
for (ptr=table->field ; (field= *ptr); ptr++)
{
- if (!wild || !wild[0] || !wild_case_compare(field->field_name,wild))
+ if (!wild || !wild[0] ||
+ !wild_case_compare(system_charset_info, field->field_name,wild))
field_list.push_back(new Item_field(field));
}
restore_record(table,2); // Get empty record
@@ -821,7 +1025,7 @@ store_create_info(THD *thd, TABLE *table, String *packet)
List<Item> field_list;
char tmp[MAX_FIELD_WIDTH];
- String type(tmp, sizeof(tmp));
+ String type(tmp, sizeof(tmp),default_charset_info);
if (table->tmp_table)
packet->append("CREATE TEMPORARY TABLE ", 23);
else
@@ -841,7 +1045,7 @@ store_create_info(THD *thd, TABLE *table, String *packet)
packet->append(' ');
// check for surprises from the previous call to Field::sql_type()
if (type.ptr() != tmp)
- type.set(tmp, sizeof(tmp));
+ type.set(tmp, sizeof(tmp),default_charset_info);
field->sql_type(type);
packet->append(type.ptr(),type.length());
@@ -857,12 +1061,12 @@ store_create_info(THD *thd, TABLE *table, String *packet)
packet->append(" default ", 9);
if (!field->is_null())
{ // Not null by default
- type.set(tmp,sizeof(tmp));
+ type.set(tmp,sizeof(tmp),default_charset_info);
field->val_str(&type,&type);
- packet->append('\'');
if (type.length())
- append_unescaped(packet, type.c_ptr());
- packet->append('\'');
+ append_unescaped(packet, type.ptr(), type.length());
+ else
+ packet->append("''",2);
}
else if (field->maybe_null())
packet->append("NULL", 4); // Null as default
@@ -871,7 +1075,13 @@ store_create_info(THD *thd, TABLE *table, String *packet)
}
if (field->unireg_check == Field::NEXT_NUMBER)
- packet->append(" auto_increment", 15 );
+ packet->append(" auto_increment", 15 );
+
+ if (field->comment.length)
+ {
+ packet->append(" COMMENT ",9);
+ append_unescaped(packet, field->comment.str, field->comment.length);
+ }
}
KEY *key_info=table->key_info;
@@ -893,11 +1103,18 @@ store_create_info(THD *thd, TABLE *table, String *packet)
packet->append("UNIQUE ", 7);
else if (key_info->flags & HA_FULLTEXT)
packet->append("FULLTEXT ", 9);
+ else if (key_info->flags & HA_SPATIAL)
+ packet->append("SPATIAL ", 8);
packet->append("KEY ", 4);
if (!found_primary)
append_identifier(thd,packet,key_info->name);
+ // +BAR: send USING only in non-default case: non-spatial rtree
+ if((key_info->algorithm == HA_KEY_ALG_RTREE) &&
+ !(key_info->flags & HA_SPATIAL))
+ packet->append(" USING RTREE",12);
+
packet->append(" (", 2);
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
@@ -941,6 +1158,12 @@ store_create_info(THD *thd, TABLE *table, String *packet)
char buff[128];
char* p;
+ if (table->table_charset)
+ {
+ packet->append(" CHARSET=");
+ packet->append(table->table_charset->name);
+ }
+
if (table->min_rows)
{
packet->append(" MIN_ROWS=");
@@ -977,9 +1200,8 @@ store_create_info(THD *thd, TABLE *table, String *packet)
table->file->append_create_info(packet);
if (table->comment && table->comment[0])
{
- packet->append(" COMMENT='", 10);
- append_unescaped(packet, table->comment);
- packet->append('\'');
+ packet->append(" COMMENT=", 9);
+ append_unescaped(packet, table->comment, strlen(table->comment));
}
if (file->raid_type)
{
@@ -1141,19 +1363,61 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
/*****************************************************************************
-** Status functions
+ Status functions
*****************************************************************************/
+int mysqld_show_charsets(THD *thd, const char *wild)
+{
+ uint i;
+ char buff[8192];
+ String packet2(buff,sizeof(buff),default_charset_info);
+ List<Item> field_list;
+ CONVERT *convert=thd->convert_set;
+ CHARSET_INFO *cs;
+ DBUG_ENTER("mysqld_show_charsets");
+
+ field_list.push_back(new Item_empty_string("Name",30));
+ field_list.push_back(new Item_int("Id",0,7));
+ field_list.push_back(new Item_int("strx_maxlen",0,7));
+ field_list.push_back(new Item_int("mb_maxlen",0,7));
+
+ if (send_fields(thd,field_list,1))
+ DBUG_RETURN(1);
+
+ for (cs=all_charsets ; cs < all_charsets+255 ; cs++ )
+ {
+ if (!cs->name)
+ continue;
+ if (!(wild && wild[0] &&
+ wild_case_compare(system_charset_info,cs->name,wild)))
+ {
+ packet2.length(0);
+ net_store_data(&packet2,convert,cs->name);
+ net_store_data(&packet2,(uint32) cs->number);
+ net_store_data(&packet2,(uint32) cs->strxfrm_multiply);
+ net_store_data(&packet2,(uint32) cs->mbmaxlen);
+
+ if (my_net_write(&thd->net, (char*) packet2.ptr(),packet2.length()))
+ goto err;
+ }
+ }
+ send_eof(&thd->net);
+ DBUG_RETURN(0);
+err:
+ DBUG_RETURN(1);
+}
+
+
int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
enum enum_var_type value_type)
{
char buff[8192];
- String packet2(buff,sizeof(buff));
+ String packet2(buff,sizeof(buff), system_charset_info);
List<Item> field_list;
CONVERT *convert=thd->variables.convert_set;
-
DBUG_ENTER("mysqld_show");
+
field_list.push_back(new Item_empty_string("Variable_name",30));
field_list.push_back(new Item_empty_string("Value",256));
if (send_fields(thd,field_list,1))
@@ -1163,7 +1427,8 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
pthread_mutex_lock(&LOCK_status);
for (; variables->name; variables++)
{
- if (!(wild && wild[0] && wild_case_compare(variables->name,wild)))
+ if (!(wild && wild[0] && wild_case_compare(system_charset_info,
+ variables[i].name,wild)))
{
packet2.length(0);
net_store_data(&packet2,convert,variables->name);
diff --git a/sql/sql_string.cc b/sql/sql_string.cc
index 2dcda2d40c2..6a42078cbcd 100644
--- a/sql/sql_string.cc
+++ b/sql/sql_string.cc
@@ -120,7 +120,7 @@ bool String::set(double num,uint decimals)
char *pos,*to;
VOID(fconvert(num,(int) decimals,&decpt,&sign,buff+1));
- if (!isdigit(buff[1]))
+ if (!my_isdigit(system_charset_info, buff[1]))
{ // Nan or Inf
pos=buff+1;
if (sign)
@@ -200,6 +200,7 @@ bool String::copy(const String &str)
str_length=str.str_length;
bmove(Ptr,str.Ptr,str_length); // May be overlapping
Ptr[str_length]=0;
+ str_charset=str.str_charset;
return FALSE;
}
@@ -231,7 +232,7 @@ bool String::fill(uint32 max_length,char fill_char)
void String::strip_sp()
{
- while (str_length && isspace(Ptr[str_length-1]))
+ while (str_length && my_isspace(str_charset,Ptr[str_length-1]))
str_length--;
}
@@ -293,10 +294,10 @@ uint32 String::numchars()
register uint32 n=0,mblen;
register const char *mbstr=Ptr;
register const char *end=mbstr+str_length;
- if (use_mb(default_charset_info))
+ if (use_mb(str_charset))
{
while (mbstr < end) {
- if ((mblen=my_ismbchar(default_charset_info, mbstr,end))) mbstr+=mblen;
+ if ((mblen=my_ismbchar(str_charset, mbstr,end))) mbstr+=mblen;
else ++mbstr;
++n;
}
@@ -313,11 +314,11 @@ int String::charpos(int i,uint32 offset)
register uint32 mblen;
register const char *mbstr=Ptr+offset;
register const char *end=Ptr+str_length;
- if (use_mb(default_charset_info))
+ if (use_mb(str_charset))
{
if (i<=0) return i;
while (i && mbstr < end) {
- if ((mblen=my_ismbchar(default_charset_info, mbstr,end))) mbstr+=mblen;
+ if ((mblen=my_ismbchar(str_charset, mbstr,end))) mbstr+=mblen;
else ++mbstr;
--i;
}
@@ -377,12 +378,14 @@ int String::strstr_case(const String &s,uint32 offset)
skipp:
while (str != end)
{
- if (my_sort_order[*str++] == my_sort_order[*search])
+ if (str_charset->sort_order[*str++] == str_charset->sort_order[*search])
{
register char *i,*j;
i=(char*) str; j=(char*) search+1;
while (j != search_end)
- if (my_sort_order[*i++] != my_sort_order[*j++]) goto skipp;
+ if (str_charset->sort_order[*i++] !=
+ str_charset->sort_order[*j++])
+ goto skipp;
return (int) (str-Ptr) -1;
}
}
@@ -456,6 +459,44 @@ bool String::replace(uint32 offset,uint32 arg_length,const String &to)
return FALSE;
}
+// added by Holyfoot for "geometry" needs
+int String::reserve(uint32 space_needed, uint32 grow_by)
+{
+ if (Alloced_length < str_length + space_needed)
+ {
+ if (realloc(Alloced_length + max(space_needed, grow_by) - 1))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void String::qs_append(const char *str)
+{
+ int len = strlen(str);
+ memcpy(Ptr + str_length, str, len + 1);
+ str_length += len;
+}
+
+void String::qs_append(double d)
+{
+ char *buff = Ptr + str_length;
+ sprintf(buff,"%.14g", d);
+ str_length += strlen(buff);
+}
+
+void String::qs_append(double *d)
+{
+ double ld;
+ float8get(ld, (char*) d);
+ qs_append(ld);
+}
+
+void String::qs_append(const char &c)
+{
+ Ptr[str_length] = c;
+ str_length += sizeof(c);
+}
+
int sortcmp(const String *x,const String *y)
{
@@ -464,15 +505,15 @@ int sortcmp(const String *x,const String *y)
uint32 x_len=x->length(),y_len=y->length(),len=min(x_len,y_len);
#ifdef USE_STRCOLL
- if (use_strcoll(default_charset_info))
+ if (use_strcoll(x->str_charset))
{
#ifndef CMP_ENDSPACE
- while (x_len && isspace(s[x_len-1]))
+ while (x_len && my_isspace(x->str_charset,s[x_len-1]))
x_len--;
- while (y_len && isspace(t[y_len-1]))
+ while (y_len && my_isspace(x->str_charset,t[y_len-1]))
y_len--;
#endif
- return my_strnncoll(default_charset_info,
+ return my_strnncoll(x->str_charset,
(unsigned char *)s,x_len,(unsigned char *)t,y_len);
}
else
@@ -482,9 +523,10 @@ int sortcmp(const String *x,const String *y)
y_len-=len;
while (len--)
{
- if (my_sort_order[(uchar) *s++] != my_sort_order[(uchar) *t++])
- return ((int) my_sort_order[(uchar) s[-1]] -
- (int) my_sort_order[(uchar) t[-1]]);
+ if (x->str_charset->sort_order[(uchar) *s++] !=
+ x->str_charset->sort_order[(uchar) *t++])
+ return ((int) x->str_charset->sort_order[(uchar) s[-1]] -
+ (int) x->str_charset->sort_order[(uchar) t[-1]]);
}
#ifndef CMP_ENDSPACE
/* Don't compare end space in strings */
@@ -493,14 +535,14 @@ int sortcmp(const String *x,const String *y)
{
const char *end=t+y_len;
for (; t != end ; t++)
- if (!isspace(*t))
+ if (!my_isspace(x->str_charset,*t))
return -1;
}
else
{
const char *end=s+x_len;
for (; s != end ; s++)
- if (!isspace(*s))
+ if (!my_isspace(x->str_charset,*s))
return 1;
}
return 0;
@@ -542,17 +584,17 @@ String *copy_if_not_alloced(String *to,String *from,uint32 from_length)
return from; // Actually an error
if ((to->str_length=min(from->str_length,from_length)))
memcpy(to->Ptr,from->Ptr,to->str_length);
+ to->str_charset=from->str_charset;
return to;
}
/* Make it easier to handle different charactersets */
#ifdef USE_MB
-#define INC_PTR(A,B) A+=((use_mb_flag && \
- my_ismbchar(default_charset_info,A,B)) ? \
- my_ismbchar(default_charset_info,A,B) : 1)
+#define INC_PTR(cs,A,B) A+=((use_mb_flag && \
+ my_ismbchar(cs,A,B)) ? my_ismbchar(cs,A,B) : 1)
#else
-#define INC_PTR(A,B) A++
+#define INC_PTR(cs,A,B) A++
#endif
/*
@@ -563,18 +605,18 @@ String *copy_if_not_alloced(String *to,String *from,uint32 from_length)
*/
#ifdef LIKE_CMP_TOUPPER
-#define likeconv(A) (uchar) toupper(A)
+#define likeconv(s,A) (uchar) my_toupper(s,A)
#else
-#define likeconv(A) (uchar) my_sort_order[(uchar) (A)]
+#define likeconv(s,A) (uchar) (s)->sort_order[(uchar) (A)]
#endif
-int wild_case_compare(const char *str,const char *str_end,
+int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *str_end,
const char *wildstr,const char *wildend,
char escape)
{
int result= -1; // Not found, using wildcards
#ifdef USE_MB
- bool use_mb_flag=use_mb(default_charset_info);
+ bool use_mb_flag=use_mb(cs);
#endif
while (wildstr != wildend)
{
@@ -585,7 +627,7 @@ int wild_case_compare(const char *str,const char *str_end,
#ifdef USE_MB
int l;
if (use_mb_flag &&
- (l = my_ismbchar(default_charset_info, wildstr, wildend)))
+ (l = my_ismbchar(cs, wildstr, wildend)))
{
if (str+l > str_end || memcmp(str, wildstr, l) != 0)
return 1;
@@ -594,7 +636,7 @@ int wild_case_compare(const char *str,const char *str_end,
}
else
#endif
- if (str == str_end || likeconv(*wildstr++) != likeconv(*str++))
+ if (str == str_end || likeconv(cs,*wildstr++) != likeconv(cs,*str++))
return(1); // No match
if (wildstr == wildend)
return (str != str_end); // Match if both are at end
@@ -606,7 +648,7 @@ int wild_case_compare(const char *str,const char *str_end,
{
if (str == str_end) // Skip one char if possible
return (result);
- INC_PTR(str,str_end);
+ INC_PTR(cs,str,str_end);
} while (++wildstr < wildend && *wildstr == wild_one);
if (wildstr == wildend)
break;
@@ -623,7 +665,7 @@ int wild_case_compare(const char *str,const char *str_end,
{
if (str == str_end)
return (-1);
- INC_PTR(str,str_end);
+ INC_PTR(cs,str,str_end);
continue;
}
break; // Not a wild character
@@ -641,10 +683,10 @@ int wild_case_compare(const char *str,const char *str_end,
int mblen;
LINT_INIT(mblen);
if (use_mb_flag)
- mblen = my_ismbchar(default_charset_info, wildstr, wildend);
+ mblen = my_ismbchar(cs, wildstr, wildend);
#endif
- INC_PTR(wildstr,wildend); // This is compared trough cmp
- cmp=likeconv(cmp);
+ INC_PTR(cs,wildstr,wildend); // This is compared trough cmp
+ cmp=likeconv(cs,cmp);
do
{
#ifdef USE_MB
@@ -662,26 +704,26 @@ int wild_case_compare(const char *str,const char *str_end,
break;
}
}
- else if (!my_ismbchar(default_charset_info, str, str_end) &&
- likeconv(*str) == cmp)
+ else if (!my_ismbchar(cs, str, str_end) &&
+ likeconv(cs,*str) == cmp)
{
str++;
break;
}
- INC_PTR(str, str_end);
+ INC_PTR(cs,str, str_end);
}
}
else
{
#endif /* USE_MB */
- while (str != str_end && likeconv(*str) != cmp)
+ while (str != str_end && likeconv(cs,*str) != cmp)
str++;
if (str++ == str_end) return (-1);
#ifdef USE_MB
}
#endif
{
- int tmp=wild_case_compare(str,str_end,wildstr,wildend,escape);
+ int tmp=wild_case_compare(cs,str,str_end,wildstr,wildend,escape);
if (tmp <= 0)
return (tmp);
}
@@ -698,7 +740,7 @@ int wild_case_compare(String &match,String &wild, char escape)
DBUG_ENTER("wild_case_compare");
DBUG_PRINT("enter",("match='%s', wild='%s', escape='%c'"
,match.ptr(),wild.ptr(),escape));
- DBUG_RETURN(wild_case_compare(match.ptr(),match.ptr()+match.length(),
+ DBUG_RETURN(wild_case_compare(match.str_charset,match.ptr(),match.ptr()+match.length(),
wild.ptr(), wild.ptr()+wild.length(),escape));
}
@@ -802,3 +844,5 @@ int wild_compare(String &match,String &wild, char escape)
DBUG_RETURN(wild_compare(match.ptr(),match.ptr()+match.length(),
wild.ptr(), wild.ptr()+wild.length(),escape));
}
+
+
diff --git a/sql/sql_string.h b/sql/sql_string.h
index ad7455ecbf1..e94981d22c3 100644
--- a/sql/sql_string.h
+++ b/sql/sql_string.h
@@ -36,26 +36,46 @@ class String
char *Ptr;
uint32 str_length,Alloced_length;
bool alloced;
+ CHARSET_INFO *str_charset;
public:
String()
- { Ptr=0; str_length=Alloced_length=0; alloced=0; }
+ {
+ Ptr=0; str_length=Alloced_length=0; alloced=0;
+ str_charset=default_charset_info;
+ }
String(uint32 length_arg)
- { alloced=0; Alloced_length=0; (void) real_alloc(length_arg); }
- String(const char *str)
- { Ptr=(char*) str; str_length=(uint) strlen(str); Alloced_length=0; alloced=0;}
- String(const char *str,uint32 len)
- { Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;}
- String(char *str,uint32 len)
- { Ptr=(char*) str; Alloced_length=str_length=len; alloced=0;}
+ {
+ alloced=0; Alloced_length=0; (void) real_alloc(length_arg);
+ str_charset=default_charset_info;
+ }
+ String(const char *str, CHARSET_INFO *cs)
+ {
+ Ptr=(char*) str; str_length=(uint) strlen(str); Alloced_length=0; alloced=0;
+ str_charset=cs;
+ }
+ String(const char *str,uint32 len, CHARSET_INFO *cs)
+ {
+ Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;
+ str_charset=cs;
+ }
+ String(char *str,uint32 len, CHARSET_INFO *cs)
+ {
+ Ptr=(char*) str; Alloced_length=str_length=len; alloced=0;
+ str_charset=cs;
+ }
String(const String &str)
- { Ptr=str.Ptr ; str_length=str.str_length ;
- Alloced_length=str.Alloced_length; alloced=0; }
-
+ {
+ Ptr=str.Ptr ; str_length=str.str_length ;
+ Alloced_length=str.Alloced_length; alloced=0;
+ str_charset=str.str_charset;
+ }
static void *operator new(size_t size) { return (void*) sql_alloc((uint) size); }
static void operator delete(void *ptr_arg,size_t size) /*lint -e715 */
{ sql_element_free(ptr_arg); }
~String() { free(); }
+ inline void set_charset(CHARSET_INFO *charset) { str_charset=charset; }
+ inline CHARSET_INFO *charset() const { return str_charset; }
inline uint32 length() const { return str_length;}
inline uint32 alloced_length() const { return Alloced_length;}
inline char& operator [] (uint32 i) const { return Ptr[i]; }
@@ -83,23 +103,27 @@ public:
Alloced_length=str.Alloced_length-offset;
else
Alloced_length=0;
+ str_charset=str.str_charset;
}
- inline void set(char *str,uint32 arg_length)
+ inline void set(char *str,uint32 arg_length, CHARSET_INFO *cs)
{
free();
Ptr=(char*) str; str_length=Alloced_length=arg_length ; alloced=0;
+ str_charset=cs;
}
- inline void set(const char *str,uint32 arg_length)
+ inline void set(const char *str,uint32 arg_length, CHARSET_INFO *cs)
{
free();
Ptr=(char*) str; str_length=arg_length; Alloced_length=0 ; alloced=0;
+ str_charset=cs;
}
- inline void set_quick(char *str,uint32 arg_length)
+ inline void set_quick(char *str,uint32 arg_length, CHARSET_INFO *cs)
{
if (!alloced)
{
Ptr=(char*) str; str_length=Alloced_length=arg_length;
}
+ str_charset=cs;
}
bool set(longlong num);
/* bool set(long num); */
@@ -179,8 +203,8 @@ public:
}
bool fill(uint32 max_length,char fill);
void strip_sp();
- inline void caseup() { ::caseup(Ptr,str_length); }
- inline void casedn() { ::casedn(Ptr,str_length); }
+ inline void caseup() { my_caseup(str_charset,Ptr,str_length); }
+ inline void casedn() { my_casedn(str_charset,Ptr,str_length); }
friend int sortcmp(const String *a,const String *b);
friend int stringcmp(const String *a,const String *b);
friend String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);
@@ -188,4 +212,50 @@ public:
friend int wild_compare(String &match,String &wild,char escape);
uint32 numchars();
int charpos(int i,uint32 offset=0);
+
+ int reserve(uint32 space_needed)
+ {
+ return realloc(str_length + space_needed);
+ }
+ int reserve(uint32 space_needed, uint32 grow_by);
+
+ /*
+ The following append operations do NOT check alloced memory
+ q_*** methods writes values of parameters itself
+ qs_*** methods writes string representation of value
+ */
+ void q_append(const char &c)
+ {
+ Ptr[str_length++] = c;
+ }
+ void q_append(const uint32 &n)
+ {
+ int4store(Ptr + str_length, n);
+ str_length += 4;
+ }
+ void q_append(double d)
+ {
+ float8store(Ptr + str_length, d);
+ str_length += 8;
+ }
+ void q_append(double *d)
+ {
+ float8store(Ptr + str_length, *d);
+ str_length += 8;
+ }
+ void q_append(const char *data, uint32 data_len)
+ {
+ memcpy(Ptr + str_length, data, data_len);
+ str_length += data_len;
+ }
+
+ void WriteAtPosition(int position, uint32 value)
+ {
+ int4store(Ptr + position,value);
+ }
+
+ void qs_append(const char *str);
+ void qs_append(double d);
+ void qs_append(double *d);
+ void qs_append(const char &c);
};
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index f58201ae429..6b24999763b 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -71,7 +71,7 @@ int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists)
}
error=mysql_rm_table_part2(thd,tables,if_exists,0);
- err:
+ err:
pthread_mutex_unlock(&LOCK_open);
VOID(pthread_cond_broadcast(&COND_refresh)); // Signal to refresh
@@ -171,7 +171,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
{
if (wrong_tables.length())
wrong_tables.append(',');
- wrong_tables.append(String(table->real_name));
+ wrong_tables.append(String(table->real_name,default_charset_info));
}
}
if (some_tables_deleted)
@@ -224,7 +224,6 @@ int quick_rm_table(enum db_type base,const char *db,
PRIMARY keys are prioritized.
*/
-
static int sort_keys(KEY *a, KEY *b)
{
if (a->flags & HA_NOSAME)
@@ -266,7 +265,8 @@ static int sort_keys(KEY *a, KEY *b)
int mysql_create_table(THD *thd,const char *db, const char *table_name,
HA_CREATE_INFO *create_info,
List<create_field> &fields,
- List<Key> &keys,bool tmp_table,bool no_log)
+ List<Key> &keys,bool tmp_table,bool no_log,
+ uint select_field_count)
{
char path[FN_REFLEN];
const char *key_name;
@@ -274,14 +274,15 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
int error= -1;
uint db_options,field,null_fields,blob_columns;
ulong pos;
- KEY *key_info,*key_info_buffer;
+ KEY *key_info,*key_info_buffer;
KEY_PART_INFO *key_part_info;
int auto_increment=0;
handler *file;
+ int field_no,dup_no;
DBUG_ENTER("mysql_create_table");
/*
- ** Check for duplicate fields and check type of table to create
+ Check for duplicate fields and check type of table to create
*/
if (!fields.elements)
@@ -290,6 +291,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
DBUG_RETURN(-1);
}
List_iterator<create_field> it(fields),it2(fields);
+ int select_field_pos=fields.elements - select_field_count;
null_fields=blob_columns=0;
db_options=create_info->table_options;
if (create_info->row_type == ROW_TYPE_DYNAMIC)
@@ -303,10 +305,10 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
DBUG_RETURN(-1);
}
- /* Don't pack keys in old tables if the user has requested this */
- while ((sql_field=it++))
+ for(field_no=0; (sql_field=it++) ; field_no++)
{
+ /* Don't pack keys in old tables if the user has requested this */
if ((sql_field->flags & BLOB_FLAG) ||
sql_field->sql_type == FIELD_TYPE_VAR_STRING &&
create_info->row_type != ROW_TYPE_FIXED)
@@ -315,12 +317,29 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
}
if (!(sql_field->flags & NOT_NULL_FLAG))
null_fields++;
- while ((dup_field=it2++) != sql_field)
+ for(dup_no=0; (dup_field=it2++) != sql_field; dup_no++)
{
- if (my_strcasecmp(sql_field->field_name, dup_field->field_name) == 0)
+ if (my_strcasecmp(system_charset_info,
+ sql_field->field_name,
+ dup_field->field_name) == 0)
{
- my_error(ER_DUP_FIELDNAME,MYF(0),sql_field->field_name);
- DBUG_RETURN(-1);
+ if (field_no<select_field_pos || dup_no>=select_field_pos)
+ {
+ my_error(ER_DUP_FIELDNAME,MYF(0),sql_field->field_name);
+ DBUG_RETURN(-1);
+ }
+ else
+ {
+ sql_field->length=dup_field->length;
+ sql_field->decimals=dup_field->decimals;
+ sql_field->flags=dup_field->flags;
+ sql_field->pack_length=dup_field->pack_length;
+ sql_field->unireg_check=dup_field->unireg_check;
+ sql_field->sql_type=dup_field->sql_type;
+ it2.remove();
+ select_field_pos--;
+ break;
+ }
}
}
it2.rewind();
@@ -388,6 +407,11 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
sql_field->offset= pos;
if (MTYP_TYPENR(sql_field->unireg_check) == Field::NEXT_NUMBER)
auto_increment++;
+ if(!sql_field->charset)
+ sql_field->charset = create_info->table_charset ?
+ create_info->table_charset :
+ thd->db_charset? thd->db_charset :
+ default_charset_info;
pos+=sql_field->pack_length;
}
if (auto_increment > 1)
@@ -411,35 +435,50 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
/* Create keys */
List_iterator<Key> key_iterator(keys);
- uint key_parts=0,key_count=keys.elements;
+ uint key_parts=0, key_count=0, fk_key_count=0;
List<Key> keys_in_order; // Add new keys here
bool primary_key=0,unique_key=0;
Key *key;
uint tmp, key_number;
- tmp=min(file->max_keys(), MAX_KEY);
- if (key_count > tmp)
- {
- my_error(ER_TOO_MANY_KEYS,MYF(0),tmp);
- DBUG_RETURN(-1);
- }
/* Calculate number of key segements */
while ((key=key_iterator++))
{
+ if (key->type == Key::FOREIGN_KEY)
+ {
+ fk_key_count++;
+ foreign_key *fk_key= (foreign_key*) key;
+ if (fk_key->ref_columns.elements &&
+ fk_key->ref_columns.elements != fk_key->columns.elements)
+ {
+ my_error(ER_WRONG_FK_DEF, MYF(0), fk_key->name ? fk_key->name :
+ "foreign key without name",
+ ER(ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
+ DBUG_RETURN(-1);
+ }
+ continue;
+ }
+ key_count++;
tmp=max(file->max_key_parts(),MAX_REF_PARTS);
if (key->columns.elements > tmp)
{
my_error(ER_TOO_MANY_KEY_PARTS,MYF(0),tmp);
DBUG_RETURN(-1);
}
- if (key->name() && strlen(key->name()) > NAME_LEN)
+ if (key->name && strlen(key->name) > NAME_LEN)
{
- my_error(ER_TOO_LONG_IDENT, MYF(0), key->name());
+ my_error(ER_TOO_LONG_IDENT, MYF(0), key->name);
DBUG_RETURN(-1);
}
key_parts+=key->columns.elements;
}
+ tmp=min(file->max_keys(), MAX_KEY);
+ if (key_count > tmp)
+ {
+ my_error(ER_TOO_MANY_KEYS,MYF(0),tmp);
+ DBUG_RETURN(-1);
+ }
key_info_buffer=key_info=(KEY*) sql_calloc(sizeof(KEY)*key_count);
key_part_info=(KEY_PART_INFO*) sql_calloc(sizeof(KEY_PART_INFO)*key_parts);
@@ -453,8 +492,23 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
uint key_length=0;
key_part_spec *column;
- key_info->flags= (key->type == Key::MULTIPLE) ? 0 :
- (key->type == Key::FULLTEXT) ? HA_FULLTEXT : HA_NOSAME;
+ switch(key->type){
+ case Key::MULTIPLE:
+ key_info->flags = 0;
+ break;
+ case Key::FULLTEXT:
+ key_info->flags = HA_FULLTEXT;
+ break;
+ case Key::SPATIAL:
+ key_info->flags = HA_SPATIAL;
+ break;
+ case Key::FOREIGN_KEY:
+ key_number--; // Skip this key
+ continue;
+ default:
+ key_info->flags = HA_NOSAME;
+ }
+
key_info->key_parts=(uint8) key->columns.elements;
key_info->key_part=key_part_info;
key_info->usable_key_parts= key_number;
@@ -469,14 +523,42 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
DBUG_RETURN(-1);
}
}
-
+ /*
+ Make SPATIAL to be RTREE by default
+ SPATIAL only on BLOB or at least BINARY, this
+ actually should be replaced by special GEOM type
+ in near future when new frm file is ready
+ checking for proper key parts number:
+ */
+
+ if (key_info->flags == HA_SPATIAL)
+ {
+ if (key_info->key_parts != 1)
+ {
+ my_printf_error(ER_WRONG_ARGUMENTS,
+ ER(ER_WRONG_ARGUMENTS),MYF(0),"SPATIAL INDEX");
+ DBUG_RETURN(-1);
+ }
+ }
+ else if (key_info->algorithm == HA_KEY_ALG_RTREE)
+ {
+ if ((key_info->key_parts & 1) == 1)
+ {
+ my_printf_error(ER_WRONG_ARGUMENTS,
+ ER(ER_WRONG_ARGUMENTS),MYF(0),"RTREE INDEX");
+ DBUG_RETURN(-1);
+ }
+ }
+
List_iterator<key_part_spec> cols(key->columns);
for (uint column_nr=0 ; (column=cols++) ; column_nr++)
{
it.rewind();
field=0;
while ((sql_field=it++) &&
- my_strcasecmp(column->field_name,sql_field->field_name))
+ my_strcasecmp(system_charset_info,
+ column->field_name,
+ sql_field->field_name))
field++;
if (!sql_field)
{
@@ -497,6 +579,14 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
{
if (key->type == Key::FULLTEXT)
column->length=1; /* ft-code ignores it anyway :-) */
+ else if (key->type == Key::SPATIAL)
+ {
+ /*
+ BAR: 4 is: (Xmin,Xmax,Ymin,Ymax), this is for 2D case
+ Lately we'll extend this code to support more dimensions
+ */
+ column->length=4*sizeof(double);
+ }
else
{
my_printf_error(ER_BLOB_KEY_WITHOUT_LENGTH,
@@ -588,7 +678,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
key_name=primary_key_name;
primary_key=1;
}
- else if (!(key_name = key->name()))
+ else if (!(key_name = key->name))
key_name=make_unique_key_name(sql_field->field_name,
key_info_buffer,key_info);
if (check_if_keyname_exists(key_name,key_info_buffer,key_info))
@@ -699,7 +789,7 @@ static bool
check_if_keyname_exists(const char *name, KEY *start, KEY *end)
{
for (KEY *key=start ; key != end ; key++)
- if (!my_strcasecmp(name,key->name))
+ if (!my_strcasecmp(system_charset_info,name,key->name))
return 1;
return 0;
}
@@ -735,6 +825,7 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
TABLE tmp_table; // Used during 'create_field()'
TABLE *table;
tmp_table.table_name=0;
+ uint select_field_count=0;
DBUG_ENTER("create_table_from_items");
/* Add selected items to field list */
@@ -768,11 +859,12 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
(Field*) 0))))
DBUG_RETURN(0);
extra_fields->push_back(cr_field);
+ select_field_count++;
}
/* create and lock table */
/* QQ: This should be done atomic ! */
if (mysql_create_table(thd,db,name,create_info,*extra_fields,
- *keys,0,1)) // no logging
+ *keys,0,1,select_field_count)) // no logging
DBUG_RETURN(0);
if (!(table=open_table(thd,db,name,name,(bool*) 0)))
{
@@ -1298,9 +1390,9 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
strmov(new_name_buff,new_name);
fn_same(new_name_buff,table_name,3);
if (lower_case_table_names)
- casedn_str(new_name);
+ my_casedn_str(system_charset_info,new_name);
if ((lower_case_table_names &&
- !my_strcasecmp(new_name_buff,table_name)) ||
+ !my_strcasecmp(system_charset_info, new_name_buff,table_name)) ||
(!lower_case_table_names &&
!strcmp(new_name_buff,table_name)))
new_name=table_name; // No. Make later check easier
@@ -1398,7 +1490,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
List<Key> key_list; // Add new keys here
/*
- ** First collect all fields from table which isn't in drop_list
+ First collect all fields from table which isn't in drop_list
*/
create_field *def;
@@ -1411,7 +1503,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
while ((drop=drop_it++))
{
if (drop->type == Alter_drop::COLUMN &&
- !my_strcasecmp(field->field_name, drop->name))
+ !my_strcasecmp(system_charset_info,field->field_name, drop->name))
{
/* Reset auto_increment value if it was dropped */
if (MTYP_TYPENR(field->unireg_check) == Field::NEXT_NUMBER &&
@@ -1432,7 +1524,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
def_it.rewind();
while ((def=def_it++))
{
- if (def->change && !my_strcasecmp(field->field_name, def->change))
+ if (def->change &&
+ !my_strcasecmp(system_charset_info,field->field_name, def->change))
break;
}
if (def)
@@ -1456,7 +1549,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
Alter_column *alter;
while ((alter=alter_it++))
{
- if (!my_strcasecmp(field->field_name, alter->name))
+ if (!my_strcasecmp(system_charset_info,field->field_name, alter->name))
break;
}
if (alter)
@@ -1490,7 +1583,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
find_it.rewind();
while ((find=find_it++)) // Add new columns
{
- if (!my_strcasecmp(def->after, find->field_name))
+ if (!my_strcasecmp(system_charset_info,def->after, find->field_name))
break;
}
if (!find)
@@ -1513,8 +1606,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
}
/*
- ** Collect all keys which isn't in drop list. Add only those
- ** for which some fields exists.
+ Collect all keys which isn't in drop list. Add only those
+ for which some fields exists.
*/
List_iterator<Key> key_it(keys);
@@ -1536,7 +1629,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
while ((drop=drop_it++))
{
if (drop->type == Alter_drop::KEY &&
- !my_strcasecmp(key_name, drop->name))
+ !my_strcasecmp(system_charset_info,key_name, drop->name))
break;
}
if (drop)
@@ -1558,11 +1651,13 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
{
if (cfield->change)
{
- if (!my_strcasecmp(key_part_name, cfield->change))
+ if (!my_strcasecmp(system_charset_info, key_part_name,
+ cfield->change))
break;
}
- else if (!my_strcasecmp(key_part_name, cfield->field_name))
- break;
+ else if (!my_strcasecmp(system_charset_info,
+ key_part_name, cfield->field_name))
+ break;
}
if (!cfield)
continue; // Field is removed
@@ -1579,18 +1674,24 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
key_part_length));
}
if (key_parts.elements)
- key_list.push_back(new Key(key_info->flags & HA_NOSAME ?
- (!my_strcasecmp(key_name, "PRIMARY") ?
+ key_list.push_back(new Key(key_info->flags & HA_SPATIAL ? Key::SPATIAL :
+ (key_info->flags & HA_NOSAME ?
+ (!my_strcasecmp(system_charset_info,
+ key_name, "PRIMARY") ?
Key::PRIMARY : Key::UNIQUE) :
- (key_info->flags & HA_FULLTEXT ?
- Key::FULLTEXT : Key::MULTIPLE),
- key_name,key_parts));
+ (key_info->flags & HA_FULLTEXT ?
+ Key::FULLTEXT : Key::MULTIPLE)),
+ key_name,
+ key_info->algorithm,
+ key_parts));
}
- key_it.rewind();
{
Key *key;
while ((key=key_it++)) // Add new keys
- key_list.push_back(key);
+ {
+ if (key->type != Key::FOREIGN_KEY)
+ key_list.push_back(key);
+ }
}
if (drop_list.elements)
@@ -1618,6 +1719,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
create_info->max_rows=table->max_rows;
if (!(used_fields & HA_CREATE_USED_AVG_ROW_LENGTH))
create_info->avg_row_length=table->avg_row_length;
+ if (!(used_fields & HA_CREATE_USED_CHARSET))
+ create_info->table_charset=table->table_charset;
table->file->update_create_info(create_info);
if ((create_info->table_options &
@@ -1685,7 +1788,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
if ((error=mysql_create_table(thd, new_db, tmp_name,
create_info,
- create_list,key_list,1,1))) // no logging
+ create_list,key_list,1,1,0))) // no logging
DBUG_RETURN(error);
if (table->tmp_table)
@@ -1762,9 +1865,9 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
goto err;
}
/*
- ** Data is copied. Now we rename the old table to a temp name,
- ** rename the new one to the old name, remove all entries from the old table
- ** from the cash, free all locks, close the old table and remove it.
+ Data is copied. Now we rename the old table to a temp name,
+ rename the new one to the old name, remove all entries from the old table
+ from the cash, free all locks, close the old table and remove it.
*/
thd->proc_info="rename result table";
diff --git a/sql/sql_test.cc b/sql/sql_test.cc
index b226bc1300a..ef26a1f45fe 100644
--- a/sql/sql_test.cc
+++ b/sql/sql_test.cc
@@ -34,7 +34,7 @@ print_where(COND *cond,const char *info)
if (cond)
{
char buff[256];
- String str(buff,(uint32) sizeof(buff));
+ String str(buff,(uint32) sizeof(buff), default_charset_info);
str.length(0);
cond->print(&str);
str.append('\0');
@@ -100,7 +100,8 @@ void print_cached_tables(void)
void TEST_filesort(SORT_FIELD *sortorder,uint s_length, ha_rows special)
{
char buff[256],buff2[256];
- String str(buff,sizeof(buff)),out(buff2,sizeof(buff2));
+ String str(buff,sizeof(buff),default_charset_info);
+ String out(buff2,sizeof(buff2),default_charset_info);
const char *sep;
DBUG_ENTER("TEST_filesort");
diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc
index 9493f969802..225c0ea26a4 100644
--- a/sql/sql_udf.cc
+++ b/sql/sql_udf.cc
@@ -127,7 +127,8 @@ void udf_init()
init_sql_alloc(&mem, 1024,0);
THD *new_thd = new THD;
if (!new_thd ||
- hash_init(&udf_hash,32,0,0,get_hash_key, NULL, HASH_CASE_INSENSITIVE))
+ hash_init(&udf_hash,system_charset_info,
+ 32,0,0,get_hash_key, NULL, HASH_CASE_INSENSITIVE))
{
sql_print_error("Can't allocate memory for udf structures");
hash_free(&udf_hash);
@@ -411,9 +412,9 @@ int mysql_create_function(THD *thd,udf_func *udf)
goto err;
restore_record(table,2); // Get default values for fields
- table->field[0]->store(u_d->name, u_d->name_length);
+ table->field[0]->store(u_d->name, u_d->name_length, default_charset_info);
table->field[1]->store((longlong) u_d->returns);
- table->field[2]->store(u_d->dl,(uint) strlen(u_d->dl));
+ table->field[2]->store(u_d->dl,(uint) strlen(u_d->dl), default_charset_info);
if (table->fields >= 4) // If not old func format
table->field[3]->store((longlong) u_d->type);
error = table->file->write_row(table->record[0]);
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index aeedfeb148b..51f278536de 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -27,63 +27,26 @@
int mysql_union(THD *thd, LEX *lex,select_result *result)
{
- SELECT_LEX *sl, *last_sl, *lex_sl;
- ORDER *order;
+ SELECT_LEX *sl;
+ SELECT_LEX_UNIT *unit= &(lex->unit);
List<Item> item_list;
TABLE *table;
int describe=(lex->select_lex.options & SELECT_DESCRIBE) ? 1 : 0;
int res;
bool found_rows_for_union=false;
TABLE_LIST result_table_list;
- TABLE_LIST *first_table=(TABLE_LIST *)lex->select_lex.table_list.first;
TMP_TABLE_PARAM tmp_table_param;
select_union *union_result;
DBUG_ENTER("mysql_union");
+ st_select_lex_node * global;
- /* Fix tables 'to-be-unioned-from' list to point at opened tables */
- last_sl= &lex->select_lex;
- for (sl= last_sl;
- sl && sl->linkage != NOT_A_SELECT;
- last_sl=sl, sl=sl->next)
+ /* Global option */
+ if (((void*)(global= unit->global_parameters)) == ((void*)unit))
{
- for (TABLE_LIST *cursor= (TABLE_LIST *)sl->table_list.first;
- cursor;
- cursor=cursor->next)
- {
- if (cursor->do_redirect) // False if CUBE/ROLLUP
- {
- cursor->table= ((TABLE_LIST*) cursor->table)->table;
- cursor->do_redirect=false;
- }
- }
- }
-
- /* last_sel now points at the last select where the ORDER BY is stored */
- if (sl)
- {
- /*
- The found SL is an extra SELECT_LEX argument that contains
- the ORDER BY and LIMIT parameter for the whole UNION
- */
- lex_sl= sl;
- order= (ORDER *) lex_sl->order_list.first;
- found_rows_for_union = (lex->select_lex.options & OPTION_FOUND_ROWS &&
- !describe && sl->select_limit);
+ found_rows_for_union= (lex->select_lex.options & OPTION_FOUND_ROWS &&
+ !describe && global->select_limit);
if (found_rows_for_union)
lex->select_lex.options ^= OPTION_FOUND_ROWS;
- // This is done to eliminate unnecessary slowing down of the first query
- if (!order || !describe)
- last_sl->next=0; // Remove this extra element
- }
- else if (!last_sl->braces)
- {
- lex_sl= last_sl; // ORDER BY is here
- order= (ORDER *) lex_sl->order_list.first;
- }
- else
- {
- lex_sl=0;
- order=0;
}
if (describe)
@@ -120,11 +83,12 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
bzero((char*) &tmp_table_param,sizeof(tmp_table_param));
tmp_table_param.field_count=item_list.elements;
- if (!(table=create_tmp_table(thd, &tmp_table_param, item_list,
- (ORDER*) 0, !describe & !lex->union_option,
- 1, 0,
- (lex->select_lex.options | thd->options |
- TMP_TABLE_ALL_COLUMNS))))
+ if (!(table= create_tmp_table(thd, &tmp_table_param, item_list,
+ (ORDER*) 0, !describe & !lex->union_option,
+ 1, 0,
+ (lex->select_lex.options | thd->options |
+ TMP_TABLE_ALL_COLUMNS),
+ unit)))
DBUG_RETURN(-1);
table->file->extra(HA_EXTRA_WRITE_CACHE);
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
@@ -140,25 +104,28 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
}
union_result->save_time_stamp=!describe;
union_result->tmp_table_param=&tmp_table_param;
- for (sl= &lex->select_lex; sl; sl=sl->next)
+ for (sl= &lex->select_lex; sl; sl= sl->next_select())
{
lex->select=sl;
- thd->offset_limit=sl->offset_limit;
- thd->select_limit=sl->select_limit+sl->offset_limit;
- if (thd->select_limit < sl->select_limit)
- thd->select_limit= HA_POS_ERROR; // no limit
- if (thd->select_limit == HA_POS_ERROR)
+ unit->offset_limit_cnt= sl->offset_limit;
+ unit->select_limit_cnt= sl->select_limit+sl->offset_limit;
+ if (unit->select_limit_cnt < sl->select_limit)
+ unit->select_limit_cnt= HA_POS_ERROR; // no limit
+ if (unit->select_limit_cnt == HA_POS_ERROR)
sl->options&= ~OPTION_FOUND_ROWS;
- res=mysql_select(thd, (describe && sl->linkage==NOT_A_SELECT) ? first_table : (TABLE_LIST*) sl->table_list.first,
- sl->item_list,
- sl->where,
- (sl->braces) ? (ORDER *)sl->order_list.first : (ORDER *) 0,
- (ORDER*) sl->group_list.first,
- sl->having,
- (ORDER*) NULL,
- sl->options | thd->options | SELECT_NO_UNLOCK | ((describe) ? SELECT_DESCRIBE : 0),
- union_result);
+ res= mysql_select(thd,
+ (TABLE_LIST*) sl->table_list.first,
+ sl->item_list,
+ sl->where,
+ (sl->braces) ?
+ (ORDER *)sl->order_list.first : (ORDER *) 0,
+ (ORDER*) sl->group_list.first,
+ sl->having,
+ (ORDER*) NULL,
+ sl->options | thd->options |
+ SELECT_NO_UNLOCK | ((describe) ? SELECT_DESCRIBE : 0),
+ union_result, unit);
if (res)
goto exit;
}
@@ -190,26 +157,20 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
}
if (!thd->fatal_error) // Check if EOM
{
- if (lex_sl)
- {
- thd->offset_limit=lex_sl->offset_limit;
- thd->select_limit=lex_sl->select_limit+lex_sl->offset_limit;
- if (thd->select_limit < lex_sl->select_limit)
- thd->select_limit= HA_POS_ERROR; // no limit
- if (thd->select_limit == HA_POS_ERROR)
- thd->options&= ~OPTION_FOUND_ROWS;
- }
- else
- {
- thd->offset_limit= 0;
- thd->select_limit= thd->variables.select_limit;
- }
+ st_select_lex_node * global= unit->global_parameters;
+ unit->offset_limit_cnt= global->offset_limit;
+ unit->select_limit_cnt= global->select_limit+global->offset_limit;
+ if (unit->select_limit_cnt < global->select_limit)
+ unit->select_limit_cnt= HA_POS_ERROR; // no limit
+ if (unit->select_limit_cnt == HA_POS_ERROR)
+ thd->options&= ~OPTION_FOUND_ROWS;
if (describe)
- thd->select_limit= HA_POS_ERROR; // no limit
- res=mysql_select(thd,&result_table_list,
- item_list, NULL, (describe) ? 0 : order,
- (ORDER*) NULL, NULL, (ORDER*) NULL,
- thd->options, result);
+ unit->select_limit_cnt= HA_POS_ERROR; // no limit
+ res= mysql_select(thd,&result_table_list,
+ item_list, NULL,
+ (describe) ? 0 : (ORDER*)global->order_list.first,
+ (ORDER*) NULL, NULL, (ORDER*) NULL,
+ thd->options, result, unit);
if (found_rows_for_union && !res)
thd->limit_found_rows = (ulonglong)table->file->records;
}
@@ -233,7 +194,7 @@ select_union::select_union(TABLE *table_par)
We can always use DUP_IGNORE because the temporary table will only
contain a unique key if we are using not using UNION ALL
*/
- info.handle_duplicates=DUP_IGNORE;
+ info.handle_duplicates= DUP_IGNORE;
}
select_union::~select_union()
@@ -241,8 +202,9 @@ select_union::~select_union()
}
-int select_union::prepare(List<Item> &list)
+int select_union::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
{
+ unit= u;
if (save_time_stamp && list.elements != table->fields)
{
my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT,
@@ -254,9 +216,9 @@ int select_union::prepare(List<Item> &list)
bool select_union::send_data(List<Item> &values)
{
- if (thd->offset_limit)
+ if (unit->offset_limit_cnt)
{ // using limit offset,count
- thd->offset_limit--;
+ unit->offset_limit_cnt--;
return 0;
}
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index b5df0e03823..f0ca5ad6c7b 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -380,9 +380,10 @@ multi_update::multi_update(THD *thd_arg, TABLE_LIST *ut, List<Item> &fs,
}
int
-multi_update::prepare(List<Item> &values)
+multi_update::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
{
DBUG_ENTER("multi_update::prepare");
+ unit= u;
do_update = true;
thd->count_cuted_fields=1;
thd->cuted_fields=0L;
@@ -480,9 +481,12 @@ multi_update::prepare(List<Item> &values)
}
if (counter)
{
- Field_string offset(table_ref->table->file->ref_length,false,"offset",table_ref->table,true);
+ Field_string offset(table_ref->table->file->ref_length, false,
+ "offset", table_ref->table, true,
+ default_charset_info);
temp_fields->push_front(new Item_field(((Field *)&offset)));
- // Here I make tmp tables
+
+ // Make a temporary table
int cnt=counter-1;
TMP_TABLE_PARAM tmp_table_param;
bzero((char*) &tmp_table_param,sizeof(tmp_table_param));
@@ -490,7 +494,8 @@ multi_update::prepare(List<Item> &values)
if (!(tmp_tables[cnt]=create_tmp_table(thd, &tmp_table_param,
*temp_fields,
(ORDER*) 0, 1, 0, 0,
- TMP_TABLE_ALL_COLUMNS)))
+ TMP_TABLE_ALL_COLUMNS,
+ unit)))
{
error = 1; // A proper error message is due here
DBUG_RETURN(1);
@@ -638,7 +643,8 @@ bool multi_update::send_data(List<Item> &values)
{
// Here we insert into each temporary table
values_by_table.push_front(new Item_string((char*) table->file->ref,
- table->file->ref_length));
+ table->file->ref_length,
+ system_charset_info));
fill_record(tmp_tables[secure_counter]->field,values_by_table);
error= write_record(tmp_tables[secure_counter],
&(infos[secure_counter]));
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 0b8b6337998..8571cb9af6d 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -60,6 +60,7 @@ inline Item *or_or_concat(Item* A, Item* B)
LEX_USER *lex_user;
sys_var *variable;
Key::Keytype key_type;
+ enum ha_key_alg key_alg;
enum db_type db_type;
enum row_type row_type;
enum ha_rkey_function ha_rkey_mode;
@@ -161,14 +162,17 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token BOOL_SYM
%token BOOLEAN_SYM
%token BOTH
+%token BTREE_SYM
%token BY
%token CACHE_SYM
%token CASCADE
%token CAST_SYM
+%token CHARSET
%token CHECKSUM_SYM
%token CHECK_SYM
%token CIPHER
%token COMMITTED_SYM
+%token COLLATE_SYM
%token COLUMNS
%token COLUMN_SYM
%token CONCURRENT
@@ -206,6 +210,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token GREATEST_SYM
%token GROUP
%token HAVING
+%token HASH_SYM
%token HEAP_SYM
%token HEX_NUM
%token HIGH_PRIORITY
@@ -304,11 +309,14 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token ROWS_SYM
%token ROW_FORMAT_SYM
%token ROW_SYM
+%token RTREE_SYM
%token SET
%token SERIALIZABLE_SYM
%token SESSION_SYM
+%token SIMPLE_SYM
%token SHUTDOWN
-%token SSL_SYM
+%token SPATIAL_SYM
+%token SSL_SYM
%token STARTING
%token STATUS_SYM
%token STRAIGHT_JOIN
@@ -322,6 +330,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token TRAILING
%token TRANSACTION_SYM
%token TYPE_SYM
+%token TYPES_SYM
%token FUNC_ARG0
%token FUNC_ARG1
%token FUNC_ARG2
@@ -330,6 +339,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token UDF_SONAME_SYM
%token UDF_SYM
%token UNCOMMITTED_SYM
+%token UNDERSCORE_CHARSET
%token UNION_SYM
%token UNIQUE_SYM
%token USAGE
@@ -342,9 +352,14 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token WITH
%token WRITE_SYM
%token X509_SYM
-%token XOR
+%token XOR
%token COMPRESSED_SYM
+%token ERRORS
+%token SQL_ERROR_COUNT
+%token WARNINGS
+%token SQL_WARNING_COUNT
+
%token BIGINT
%token BLOB_SYM
%token CHAR_SYM
@@ -357,6 +372,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token ENUM
%token FAST_SYM
%token FLOAT_SYM
+%token GEOMETRY_SYM
%token INT_SYM
%token LIMIT
%token LONGBLOB
@@ -414,6 +430,9 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token FORMAT_SYM
%token FOR_SYM
%token FROM_UNIXTIME
+%token GEOMCOLLFROMTEXT
+%token GEOMFROMTEXT
+%token GEOMETRYCOLLECTION
%token GROUP_UNIQUE_USERS
%token HOUR_MINUTE_SYM
%token HOUR_SECOND_SYM
@@ -424,6 +443,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token INTERVAL_SYM
%token LAST_INSERT_ID
%token LEFT
+%token LINEFROMTEXT
+%token LINESTRING
%token LOCATE
%token MAKE_SET_SYM
%token MINUTE_SECOND_SYM
@@ -431,8 +452,17 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token MODE_SYM
%token MODIFY_SYM
%token MONTH_SYM
+%token MLINEFROMTEXT
+%token MPOINTFROMTEXT
+%token MPOLYFROMTEXT
+%token MULTILINESTRING
+%token MULTIPOINT
+%token MULTIPOLYGON
%token NOW_SYM
%token PASSWORD
+%token POINTFROMTEXT
+%token POLYFROMTEXT
+%token POLYGON
%token POSITION_SYM
%token PROCEDURE
%token RAND
@@ -488,17 +518,17 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%left XOR
%left '^'
%right NOT
-%right BINARY
+%right BINARY COLLATE_SYM
%type <lex_str>
IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME
- ULONGLONG_NUM field_ident select_alias ident ident_or_text
+ ULONGLONG_NUM field_ident select_alias ident ident_or_text UNDERSCORE_CHARSET
%type <lex_str_ptr>
opt_table_alias
%type <table>
- table_ident
+ table_ident references
%type <simple_string>
remember_name remember_end opt_len opt_ident opt_db text_or_password
@@ -511,6 +541,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
type int_type real_type order_dir opt_field_spec lock_option
udf_type if_exists opt_local opt_table_options table_options
table_option opt_if_not_exists opt_var_type opt_var_ident_type
+ delete_option
%type <ulong_num>
ULONG_NUM raid_types merge_insert_types
@@ -523,6 +554,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
table_wild opt_pad no_in_expr expr_expr simple_expr no_and_expr
using_list expr_or_default set_expr_or_default
+ param_marker singleval_subselect singleval_subselect_init
+ exists_subselect exists_subselect_init
%type <item_list>
expr_list udf_expr_list when_list ident_list ident_list_arg
@@ -530,6 +563,9 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%type <key_type>
key_type opt_unique_or_fulltext
+%type <key_alg>
+ key_alg opt_btree_or_rtree
+
%type <string_list>
key_usage_list
@@ -577,7 +613,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
opt_precision opt_ignore opt_column opt_restrict
grant revoke set lock unlock string_list field_options field_option
field_opt_list opt_binary table_lock_list table_lock varchar
- references opt_on_delete opt_on_delete_list opt_on_delete_item use
+ ref_list opt_on_delete opt_on_delete_list opt_on_delete_item use
opt_delete_options opt_delete_option
opt_outer table_list table_name opt_option opt_place opt_low_priority
opt_attribute opt_attribute_list attribute column_list column_list_id
@@ -589,7 +625,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
table_to_table_list table_to_table opt_table_list opt_as
handler_rkey_function handler_read_or_scan
single_multi table_wild_list table_wild_one opt_wild union union_list
- precision union_option
+ precision union_option opt_on_delete_item subselect_start
+ subselect_end
END_OF_INPUT
%type <NONE>
@@ -732,32 +769,35 @@ create:
bzero((char*) &lex->create_info,sizeof(lex->create_info));
lex->create_info.options=$2 | $4;
lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type;
+ lex->create_info.table_charset=NULL;
}
create2
- | CREATE opt_unique_or_fulltext INDEX ident ON table_ident
+ | CREATE opt_unique_or_fulltext INDEX ident key_alg ON table_ident
{
LEX *lex=Lex;
lex->sql_command= SQLCOM_CREATE_INDEX;
- if (!add_table_to_list($6,NULL,1))
+ if (!add_table_to_list($7,NULL,1))
YYABORT;
lex->create_list.empty();
lex->key_list.empty();
lex->col_list.empty();
lex->change=NullS;
}
- '(' key_list ')'
+ '(' key_list ')'
{
LEX *lex=Lex;
- lex->key_list.push_back(new Key($2,$4.str,lex->col_list));
+
+ lex->key_list.push_back(new Key($2,$4.str, $5, lex->col_list));
lex->col_list.empty();
}
- | CREATE DATABASE opt_if_not_exists ident
+ | CREATE DATABASE opt_if_not_exists ident default_charset
{
LEX *lex=Lex;
lex->sql_command=SQLCOM_CREATE_DB;
lex->name=$4.str;
lex->create_info.options=$3;
+ lex->create_info.table_charset=lex->charset;
}
| CREATE udf_func_type UDF_SYM ident
{
@@ -844,6 +884,11 @@ create_table_option:
table_list->next=0;
lex->create_info.used_fields|= HA_CREATE_USED_UNION;
}
+ | CHARSET EQ charset_or_nocharset
+ {
+ Lex->create_info.table_charset=Lex->charset;
+ Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
+ }
| INSERT_METHOD EQ merge_insert_types { Lex->create_info.merge_insert_method= $3; Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;}
| DATA_SYM DIRECTORY_SYM EQ TEXT_STRING { Lex->create_info.data_file_name= $4.str; }
| INDEX DIRECTORY_SYM EQ TEXT_STRING { Lex->create_info.index_file_name= $4.str; };
@@ -896,15 +941,22 @@ field_list_item:
{
Lex->col_list.empty(); /* Alloced by sql_alloc */
}
- | key_type opt_ident '(' key_list ')'
+ | key_type opt_ident key_alg '(' key_list ')'
{
LEX *lex=Lex;
- lex->key_list.push_back(new Key($1,$2,lex->col_list));
+ lex->key_list.push_back(new Key($1,$2, $3, lex->col_list));
lex->col_list.empty(); /* Alloced by sql_alloc */
}
| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
{
- Lex->col_list.empty(); /* Alloced by sql_alloc */
+ LEX *lex=Lex;
+ lex->key_list.push_back(new foreign_key($4, lex->col_list,
+ $8,
+ lex->ref_list,
+ lex->fk_delete_opt,
+ lex->fk_update_opt,
+ lex->fk_match_option));
+ lex->col_list.empty(); /* Alloced by sql_alloc */
}
| opt_constraint CHECK_SYM '(' expr ')'
{
@@ -920,7 +972,8 @@ field_spec:
{
LEX *lex=Lex;
lex->length=lex->dec=0; lex->type=0; lex->interval=0;
- lex->default_value=0;
+ lex->default_value=lex->comment=0;
+ lex->charset=NULL;
}
type opt_attribute
{
@@ -928,8 +981,8 @@ field_spec:
if (add_field_to_list($1.str,
(enum enum_field_types) $3,
lex->length,lex->dec,lex->type,
- lex->default_value,lex->change,
- lex->interval))
+ lex->default_value, lex->comment,
+ lex->change,lex->interval,lex->charset))
YYABORT;
};
@@ -964,17 +1017,19 @@ type:
$$=FIELD_TYPE_TINY_BLOB; }
| BLOB_SYM { Lex->type|=BINARY_FLAG;
$$=FIELD_TYPE_BLOB; }
+ | GEOMETRY_SYM { Lex->type|=BINARY_FLAG;
+ $$=FIELD_TYPE_GEOMETRY; }
| MEDIUMBLOB { Lex->type|=BINARY_FLAG;
$$=FIELD_TYPE_MEDIUM_BLOB; }
| LONGBLOB { Lex->type|=BINARY_FLAG;
$$=FIELD_TYPE_LONG_BLOB; }
| LONG_SYM VARBINARY { Lex->type|=BINARY_FLAG;
$$=FIELD_TYPE_MEDIUM_BLOB; }
- | LONG_SYM varchar { $$=FIELD_TYPE_MEDIUM_BLOB; }
- | TINYTEXT { $$=FIELD_TYPE_TINY_BLOB; }
- | TEXT_SYM { $$=FIELD_TYPE_BLOB; }
- | MEDIUMTEXT { $$=FIELD_TYPE_MEDIUM_BLOB; }
- | LONGTEXT { $$=FIELD_TYPE_LONG_BLOB; }
+ | LONG_SYM varchar opt_binary { $$=FIELD_TYPE_MEDIUM_BLOB; }
+ | TINYTEXT opt_binary { $$=FIELD_TYPE_TINY_BLOB; }
+ | TEXT_SYM opt_binary { $$=FIELD_TYPE_BLOB; }
+ | MEDIUMTEXT opt_binary { $$=FIELD_TYPE_MEDIUM_BLOB; }
+ | LONGTEXT opt_binary { $$=FIELD_TYPE_LONG_BLOB; }
| DECIMAL_SYM float_options field_options
{ $$=FIELD_TYPE_DECIMAL;}
| NUMERIC_SYM float_options field_options
@@ -1066,18 +1121,51 @@ attribute:
| PRIMARY_SYM KEY_SYM { Lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG; }
| UNIQUE_SYM { Lex->type|= UNIQUE_FLAG; }
| UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
- | COMMENT_SYM text_literal {};
+ | COMMENT_SYM text_literal { Lex->comment= $2; };
+
+charset:
+ ident
+ {
+ if (!(Lex->charset=get_charset_by_name($1.str,MYF(0))))
+ {
+ net_printf(&current_thd->net,ER_UNKNOWN_CHARACTER_SET,$1.str);
+ YYABORT;
+ }
+ };
+
+charset_or_nocharset:
+ charset
+ | DEFAULT {Lex->charset=NULL; }
opt_binary:
- /* empty */ {}
- | BINARY { Lex->type|=BINARY_FLAG; };
+ /* empty */ { Lex->charset=NULL; }
+ | BINARY { Lex->type|=BINARY_FLAG; Lex->charset=NULL; }
+ | CHAR_SYM SET charset {/* charset is already in Lex->charset */} ;
+
+default_charset:
+ /* empty */ { Lex->charset=NULL; }
+ | DEFAULT CHAR_SYM SET charset_or_nocharset ;
references:
- REFERENCES table_ident opt_on_delete {}
- | REFERENCES table_ident '(' key_list ')' opt_on_delete
- {
- Lex->col_list.empty(); /* Alloced by sql_alloc */
- };
+ REFERENCES table_ident
+ {
+ LEX *lex=Lex;
+ lex->fk_delete_opt= lex->fk_update_opt= lex->fk_match_option= 0;
+ lex->ref_list.empty();
+ }
+ opt_ref_list
+ {
+ $$=$2;
+ };
+
+opt_ref_list:
+ /* empty */ opt_on_delete {}
+ | '(' ref_list ')' opt_on_delete {};
+
+ref_list:
+ ref_list ',' ident { Lex->ref_list.push_back(new key_part_spec($3.str)); }
+ | ident { Lex->ref_list.push_back(new key_part_spec($1.str)); };
+
opt_on_delete:
/* empty */ {}
@@ -1087,25 +1175,27 @@ opt_on_delete_list:
opt_on_delete_list opt_on_delete_item {}
| opt_on_delete_item {};
-
opt_on_delete_item:
- ON DELETE_SYM delete_option {}
- | ON UPDATE_SYM delete_option {}
- | MATCH FULL {}
- | MATCH PARTIAL {};
+ ON DELETE_SYM delete_option { Lex->fk_delete_opt= $3; }
+ | ON UPDATE_SYM delete_option { Lex->fk_update_opt= $3; }
+ | MATCH FULL { Lex->fk_match_option= foreign_key::FK_MATCH_FULL; }
+ | MATCH PARTIAL { Lex->fk_match_option= foreign_key::FK_MATCH_PARTIAL; }
+ | MATCH SIMPLE_SYM { Lex->fk_match_option= foreign_key::FK_MATCH_SIMPLE; };
delete_option:
- RESTRICT {}
- | CASCADE {}
- | SET NULL_SYM {}
- | NO_SYM ACTION {}
- | SET DEFAULT {};
+ RESTRICT { $$= (int) foreign_key::FK_OPTION_RESTRICT; }
+ | CASCADE { $$= (int) foreign_key::FK_OPTION_CASCADE; }
+ | SET NULL_SYM { $$= (int) foreign_key::FK_OPTION_SET_NULL; }
+ | NO_SYM ACTION { $$= (int) foreign_key::FK_OPTION_NO_ACTION; }
+ | SET DEFAULT { $$= (int) foreign_key::FK_OPTION_DEFAULT; };
key_type:
opt_constraint PRIMARY_SYM KEY_SYM { $$= Key::PRIMARY; }
| key_or_index { $$= Key::MULTIPLE; }
| FULLTEXT_SYM { $$= Key::FULLTEXT; }
| FULLTEXT_SYM key_or_index { $$= Key::FULLTEXT; }
+ | SPATIAL_SYM { $$= Key::SPATIAL; }
+ | SPATIAL_SYM key_or_index { $$= Key::SPATIAL; }
| opt_constraint UNIQUE_SYM { $$= Key::UNIQUE; }
| opt_constraint UNIQUE_SYM key_or_index { $$= Key::UNIQUE; };
@@ -1121,7 +1211,16 @@ keys_or_index:
opt_unique_or_fulltext:
/* empty */ { $$= Key::MULTIPLE; }
| UNIQUE_SYM { $$= Key::UNIQUE; }
- | FULLTEXT_SYM { $$= Key::FULLTEXT; };
+ | SPATIAL_SYM { $$= Key::SPATIAL; };
+
+key_alg:
+ /* empty */ { $$= HA_KEY_ALG_UNDEF; }
+ | USING opt_btree_or_rtree { $$= $2; };
+
+opt_btree_or_rtree:
+ BTREE_SYM { $$= HA_KEY_ALG_BTREE; }
+ | RTREE_SYM { $$= HA_KEY_ALG_RTREE; }
+ | HASH_SYM { $$= HA_KEY_ALG_HASH; };
key_list:
key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
@@ -1164,11 +1263,21 @@ alter:
bzero((char*) &lex->create_info,sizeof(lex->create_info));
lex->create_info.db_type= DB_TYPE_DEFAULT;
lex->create_info.row_type= ROW_TYPE_NOT_USED;
+ lex->create_info.table_charset=NULL;
lex->alter_keys_onoff=LEAVE_AS_IS;
lex->simple_alter=1;
}
alter_list;
-
+
+ | ALTER DATABASE ident default_charset
+ {
+ LEX *lex=Lex;
+ lex->sql_command=SQLCOM_ALTER_DB;
+ lex->name=$3.str;
+ lex->create_info.table_charset=lex->charset;
+ }
+
+
alter_list:
| alter_list_item
| alter_list ',' alter_list_item;
@@ -1185,24 +1294,24 @@ alter_list_item:
lex->change= $3.str; lex->simple_alter=0;
}
field_spec opt_place
- | MODIFY_SYM opt_column field_ident
- {
- LEX *lex=Lex;
- lex->length=lex->dec=0; lex->type=0; lex->interval=0;
- lex->default_value=0;
+ | MODIFY_SYM opt_column field_ident
+ {
+ LEX *lex=Lex;
+ lex->length=lex->dec=0; lex->type=0; lex->interval=0;
+ lex->default_value=lex->comment=0;
lex->simple_alter=0;
- }
- type opt_attribute
- {
- LEX *lex=Lex;
- if (add_field_to_list($3.str,
- (enum enum_field_types) $5,
- lex->length,lex->dec,lex->type,
- lex->default_value, $3.str,
- lex->interval))
- YYABORT;
- }
- opt_place
+ }
+ type opt_attribute
+ {
+ LEX *lex=Lex;
+ if (add_field_to_list($3.str,
+ (enum enum_field_types) $5,
+ lex->length,lex->dec,lex->type,
+ lex->default_value, lex->comment,
+ $3.str, lex->interval, lex->charset))
+ YYABORT;
+ }
+ opt_place
| DROP opt_column field_ident opt_restrict
{
LEX *lex=Lex;
@@ -1407,8 +1516,14 @@ select:
select_init:
SELECT_SYM select_part2 { Select->braces=false; } union
|
- '(' SELECT_SYM select_part2 ')' { Select->braces=true;} union_opt;
-
+ '(' SELECT_SYM select_part2 ')'
+ {
+ SELECT_LEX * sel=Select;
+ sel->braces=true;
+ /* select in braces, can't contain global parameters */
+ sel->master_unit()->global_parameters=
+ sel->master_unit();
+ } union_opt;
select_part2:
{
@@ -1527,8 +1642,8 @@ optional_braces:
| '(' ')' {};
/* all possible expressions */
-expr: expr_expr {$$ = $1; }
- | simple_expr {$$ = $1; };
+expr: expr_expr { $$= $1; }
+ | simple_expr { $$= $1; };
/* expressions that begin with 'expr' */
expr_expr:
@@ -1570,7 +1685,16 @@ expr_expr:
| expr '+' INTERVAL_SYM expr interval
{ $$= new Item_date_add_interval($1,$4,$5,0); }
| expr '-' INTERVAL_SYM expr interval
- { $$= new Item_date_add_interval($1,$4,$5,1); };
+ { $$= new Item_date_add_interval($1,$4,$5,1); }
+ | expr COLLATE_SYM ident
+ {
+ if (!(Lex->charset=get_charset_by_name($3.str,MYF(0))))
+ {
+ net_printf(&current_thd->net,ER_UNKNOWN_CHARACTER_SET,$3.str);
+ YYABORT;
+ }
+ $$= new Item_func_set_collation($1,Lex->charset);
+ };
/* expressions that begin with 'expr' that do NOT follow IN_SYM */
no_in_expr:
@@ -1656,6 +1780,7 @@ no_and_expr:
simple_expr:
simple_ident
| literal
+ | param_marker
| '@' ident_or_text SET_VAR expr
{
$$= new Item_func_set_user_var($2,$4);
@@ -1677,6 +1802,8 @@ simple_expr:
| NOT expr %prec NEG { $$= new Item_func_not($2); }
| '!' expr %prec NEG { $$= new Item_func_not($2); }
| '(' expr ')' { $$= $2; }
+ | EXISTS exists_subselect { $$= $2; }
+ | singleval_subselect { $$= $1; }
| '{' ident expr '}' { $$= $3; }
| MATCH ident_list_arg AGAINST '(' expr ')'
{ Select->ftfunc_list.push_back((Item_func_match *)
@@ -1689,6 +1816,12 @@ simple_expr:
| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
{ $$= new Item_func_case(* $4, $2, $5 ); }
| CONVERT_SYM '(' expr ',' cast_type ')' { $$= create_func_cast($3, $5); }
+ | CONVERT_SYM '(' expr USING charset ')'
+ { $$= new Item_func_conv_charset($3,Lex->charset); }
+ | CONVERT_SYM '(' expr ',' expr ',' expr ')'
+ {
+ $$= new Item_func_conv_charset3($3,$7,$5);
+ }
| FUNC_ARG0 '(' ')'
{ $$= ((Item*(*)(void))($1.symbol->create_func))();}
| FUNC_ARG1 '(' expr ')'
@@ -1703,6 +1836,8 @@ simple_expr:
{ $$= new Item_func_atan($3,$5); }
| CHAR_SYM '(' expr_list ')'
{ $$= new Item_func_char(*$3); }
+ | CHARSET '(' expr ')'
+ { $$= new Item_func_charset($3); }
| COALESCE '(' expr_list ')'
{ $$= new Item_func_coalesce(* $3); }
| CONCAT '(' expr_list ')'
@@ -1765,6 +1900,14 @@ simple_expr:
}
| FIELD_FUNC '(' expr ',' expr_list ')'
{ $$= new Item_func_field($3, *$5); }
+ | GEOMFROMTEXT '(' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | GEOMFROMTEXT '(' expr ',' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | GEOMETRYCOLLECTION '(' expr_list ')'
+ { $$= new Item_func_spatial_collection(* $3,
+ Geometry::wkbGeometryCollection,
+ Geometry::wkbPoint); }
| HOUR_SYM '(' expr ')'
{ $$= new Item_func_hour($3); }
| IF '(' expr ',' expr ',' expr ')'
@@ -1789,22 +1932,54 @@ simple_expr:
}
| LEFT '(' expr ',' expr ')'
{ $$= new Item_func_left($3,$5); }
+ | LINESTRING '(' expr_list ')'
+ { $$= new Item_func_spatial_collection(* $3,
+ Geometry::wkbLineString, Geometry::wkbPoint); }
| LOCATE '(' expr ',' expr ')'
{ $$= new Item_func_locate($5,$3); }
| LOCATE '(' expr ',' expr ',' expr ')'
{ $$= new Item_func_locate($5,$3,$7); }
- | GREATEST_SYM '(' expr ',' expr_list ')'
+ | GEOMCOLLFROMTEXT '(' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | GEOMCOLLFROMTEXT '(' expr ',' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | GREATEST_SYM '(' expr ',' expr_list ')'
{ $5->push_front($3); $$= new Item_func_max(*$5); }
| LEAST_SYM '(' expr ',' expr_list ')'
{ $5->push_front($3); $$= new Item_func_min(*$5); }
| LOG_SYM '(' expr ')'
- { $$= new Item_func_log($3); }
+ { $$= new Item_func_log($3); }
| LOG_SYM '(' expr ',' expr ')'
- { $$= new Item_func_log($3, $5); }
+ { $$= new Item_func_log($3, $5); }
+ | LINEFROMTEXT '(' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | LINEFROMTEXT '(' expr ',' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
| MINUTE_SYM '(' expr ')'
{ $$= new Item_func_minute($3); }
| MONTH_SYM '(' expr ')'
{ $$= new Item_func_month($3); }
+ | MULTILINESTRING '(' expr_list ')'
+ { $$= new Item_func_spatial_collection(* $3,
+ Geometry::wkbMultiLineString, Geometry::wkbLineString); }
+ | MLINEFROMTEXT '(' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | MLINEFROMTEXT '(' expr ',' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | MPOINTFROMTEXT '(' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | MPOINTFROMTEXT '(' expr ',' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | MPOLYFROMTEXT '(' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | MPOLYFROMTEXT '(' expr ',' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | MULTIPOINT '(' expr_list ')'
+ { $$= new Item_func_spatial_collection(* $3,
+ Geometry::wkbMultiPoint, Geometry::wkbPoint); }
+ | MULTIPOLYGON '(' expr_list ')'
+ { $$= new Item_func_spatial_collection(* $3,
+ Geometry::wkbMultiPolygon, Geometry::wkbPolygon ); }
| NOW_SYM optional_braces
{ $$= new Item_func_now(); current_thd->safe_to_cache_query=0;}
| NOW_SYM '(' expr ')'
@@ -1813,6 +1988,17 @@ simple_expr:
{
$$= new Item_func_password($3);
}
+ | POINTFROMTEXT '(' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | POINTFROMTEXT '(' expr ',' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | POLYFROMTEXT '(' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | POLYFROMTEXT '(' expr ',' expr ')'
+ { $$= new Item_func_geometry_from_text($3); }
+ | POLYGON '(' expr_list ')'
+ { $$= new Item_func_spatial_collection(* $3,
+ Geometry::wkbPolygon, Geometry::wkbLineString); }
| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
{ $$ = new Item_func_locate($5,$3); }
| RAND '(' expr ')'
@@ -1839,7 +2025,7 @@ simple_expr:
| SUBSTRING_INDEX '(' expr ',' expr ',' expr ')'
{ $$= new Item_func_substr_index($3,$5,$7); }
| TRIM '(' expr ')'
- { $$= new Item_func_trim($3,new Item_string(" ",1)); }
+ { $$= new Item_func_trim($3,new Item_string(" ",1,default_charset_info)); }
| TRIM '(' LEADING opt_pad FROM expr ')'
{ $$= new Item_func_ltrim($6,$4); }
| TRIM '(' TRAILING opt_pad FROM expr ')'
@@ -2024,7 +2210,7 @@ when_list2:
};
opt_pad:
- /* empty */ { $$=new Item_string(" ",1); }
+ /* empty */ { $$=new Item_string(" ",1,default_charset_info); }
| expr { $$=$1; };
join_table_list:
@@ -2087,7 +2273,32 @@ join_table:
YYABORT;
}
| '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
- { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; };
+ { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; }
+ | '(' SELECT_SYM select_part3 ')' opt_table_alias
+ {
+ LEX *lex=Lex;
+ SELECT_LEX_UNIT *unit= lex->select->master_unit();
+ lex->select= unit->outer_select();
+ if (!($$= add_table_to_list(new Table_ident(unit),
+ $5,0,TL_UNLOCK)))
+ YYABORT;
+ };
+
+select_part3:
+ {
+ LEX *lex= Lex;
+ lex->derived_tables= true;
+ if (lex->select->linkage == GLOBAL_OPTIONS_TYPE ||
+ mysql_new_select(lex, 1))
+ YYABORT;
+ mysql_init_select(lex);
+ lex->select->linkage= DERIVED_TABLE_TYPE;
+ }
+ select_options select_item_list select_intoto
+
+select_intoto:
+ limit_clause {}
+ | select_from
opt_outer:
/* empty */ {}
@@ -2114,11 +2325,11 @@ key_usage_list:
key_usage_list2:
key_usage_list2 ',' ident
- { Select->interval_list.push_back(new String((const char*) $3.str,$3.length)); }
+ { Select->interval_list.push_back(new String((const char*) $3.str,$3.length,default_charset_info)); }
| ident
- { Select->interval_list.push_back(new String((const char*) $1.str,$1.length)); }
+ { Select->interval_list.push_back(new String((const char*) $1.str,$1.length,default_charset_info)); }
| PRIMARY_SYM
- { Select->interval_list.push_back(new String("PRIMARY",7)); };
+ { Select->interval_list.push_back(new String("PRIMARY",7,default_charset_info)); };
using_list:
ident
@@ -2235,7 +2446,6 @@ order_clause:
"ORDER BY");
YYABORT;
}
- lex->select->sort_default=1;
} order_list;
order_list:
@@ -2709,6 +2919,29 @@ show_param:
if (!add_table_to_list($3,NULL,0))
YYABORT;
}
+ | COLUMN_SYM TYPES_SYM
+ {
+ LEX *lex=Lex;
+ lex->sql_command= SQLCOM_SHOW_COLUMN_TYPES;
+ }
+ | TABLE_SYM TYPES_SYM
+ {
+ LEX *lex=Lex;
+ lex->sql_command= SQLCOM_SHOW_TABLE_TYPES;
+ }
+ | PRIVILEGES
+ {
+ LEX *lex=Lex;
+ lex->sql_command= SQLCOM_SHOW_PRIVILEGES;
+ }
+ | COUNT_SYM '(' '*' ')' WARNINGS
+ { Lex->sql_command = SQLCOM_SHOW_WARNS_COUNT;}
+ | COUNT_SYM '(' '*' ')' ERRORS
+ { Lex->sql_command = SQLCOM_SHOW_ERRORS_COUNT;}
+ | WARNINGS {Select->offset_limit=0L;} limit_clause
+ { Lex->sql_command = SQLCOM_SHOW_WARNS;}
+ | ERRORS {Select->offset_limit=0L;} limit_clause
+ { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
| STATUS_SYM wild
{ Lex->sql_command= SQLCOM_SHOW_STATUS; }
| INNOBASE_SYM STATUS_SYM
@@ -2716,11 +2949,13 @@ show_param:
| opt_full PROCESSLIST_SYM
{ Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
| opt_var_type VARIABLES wild
- {
+ {
THD *thd= current_thd;
thd->lex.sql_command= SQLCOM_SHOW_VARIABLES;
thd->lex.option_type= (enum_var_type) $1;
}
+ | CHAR_SYM SET wild
+ { Lex->sql_command= SQLCOM_SHOW_CHARSETS; }
| LOGS_SYM
{ Lex->sql_command= SQLCOM_SHOW_LOGS; }
| GRANTS FOR_SYM user
@@ -2730,6 +2965,11 @@ show_param:
lex->grant_user=$3;
lex->grant_user->password.str=NullS;
}
+ | CREATE DATABASE ident
+ {
+ Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
+ Lex->name=$3.str;
+ }
| CREATE TABLE_SYM table_ident
{
Lex->sql_command = SQLCOM_SHOW_CREATE;
@@ -2794,7 +3034,7 @@ opt_describe_column:
/* empty */ {}
| text_string { Lex->wild= $1; }
| ident
- { Lex->wild= new String((const char*) $1.str,$1.length); };
+ { Lex->wild= new String((const char*) $1.str,$1.length,default_charset_info); };
/* flush things */
@@ -2861,7 +3101,7 @@ kill:
KILL_SYM expr
{
LEX *lex=Lex;
- if ($2->fix_fields(lex->thd,0))
+ if ($2->fix_fields(lex->thd, 0, &$2))
{
send_error(&lex->thd->net, ER_SET_CONSTANTS_ONLY);
YYABORT;
@@ -2963,18 +3203,32 @@ opt_ignore_lines:
/* Common definitions */
text_literal:
- TEXT_STRING { $$ = new Item_string($1.str,$1.length); }
+ TEXT_STRING { $$ = new Item_string($1.str,$1.length,default_charset_info); }
+ | UNDERSCORE_CHARSET TEXT_STRING { $$ = new Item_string($2.str,$2.length,Lex->charset); }
| text_literal TEXT_STRING
{ ((Item_string*) $1)->append($2.str,$2.length); };
text_string:
- TEXT_STRING { $$= new String($1.str,$1.length); }
+ TEXT_STRING { $$= new String($1.str,$1.length,default_charset_info); }
| HEX_NUM
{
- Item *tmp = new Item_varbinary($1.str,$1.length);
+ Item *tmp = new Item_varbinary($1.str,$1.length,default_charset_info);
$$= tmp ? tmp->val_str((String*) 0) : (String*) 0;
};
-
+param_marker:
+ '?'
+ {
+ if(current_thd->prepare_command)
+ {
+ Lex->param_list.push_back($$=new Item_param());
+ current_thd->param_count++;
+ }
+ else
+ {
+ yyerror("You have an error in your SQL syntax");
+ YYABORT;
+ }
+ }
literal:
text_literal { $$ = $1; }
| NUM { $$ = new Item_int($1.str, (longlong) atol($1.str),$1.length); }
@@ -2984,7 +3238,7 @@ literal:
| FLOAT_NUM { $$ = new Item_float($1.str, $1.length); }
| NULL_SYM { $$ = new Item_null();
Lex->next_state=STATE_OPERATOR_OR_IDENT;}
- | HEX_NUM { $$ = new Item_varbinary($1.str,$1.length);}
+ | HEX_NUM { $$ = new Item_varbinary($1.str,$1.length,default_charset_info);}
| DATE_SYM text_literal { $$ = $2; }
| TIME_SYM text_literal { $$ = $2; }
| TIMESTAMP text_literal { $$ = $2; };
@@ -3117,14 +3371,14 @@ keyword:
| EXECUTE_SYM {}
| EXTENDED_SYM {}
| FAST_SYM {}
- | DISABLE_SYM {}
- | ENABLE_SYM {}
+ | DISABLE_SYM {}
+ | ENABLE_SYM {}
| FULL {}
| FILE_SYM {}
| FIRST_SYM {}
| FIXED_SYM {}
| FLUSH_SYM {}
- | GRANTS {}
+ | GRANTS {}
| GLOBAL_SYM {}
| HEAP_SYM {}
| HANDLER_SYM {}
@@ -3137,7 +3391,7 @@ keyword:
| ISSUER_SYM {}
| INNOBASE_SYM {}
| INSERT_METHOD {}
- | IO_THREAD {}
+ | IO_THREAD {}
| LAST_SYM {}
| LEVEL_SYM {}
| LOCAL_SYM {}
@@ -3152,9 +3406,9 @@ keyword:
| MASTER_USER_SYM {}
| MASTER_PASSWORD_SYM {}
| MASTER_CONNECT_RETRY_SYM {}
- | MAX_CONNECTIONS_PER_HOUR {}
- | MAX_QUERIES_PER_HOUR {}
- | MAX_UPDATES_PER_HOUR {}
+ | MAX_CONNECTIONS_PER_HOUR {}
+ | MAX_QUERIES_PER_HOUR {}
+ | MAX_UPDATES_PER_HOUR {}
| MEDIUM_SYM {}
| MERGE_SYM {}
| MINUTE_SYM {}
@@ -3170,19 +3424,20 @@ keyword:
| NO_SYM {}
| OPEN_SYM {}
| PACK_KEYS_SYM {}
+ | PARTIAL {}
| PASSWORD {}
| PREV_SYM {}
| PROCESS {}
| PROCESSLIST_SYM {}
| QUERY_SYM {}
| QUICK {}
- | RAID_0_SYM {}
+ | RAID_0_SYM {}
| RAID_CHUNKS {}
| RAID_CHUNKSIZE {}
- | RAID_STRIPED_SYM {}
+ | RAID_STRIPED_SYM {}
| RAID_TYPE {}
- | RELAY_LOG_FILE_SYM {}
- | RELAY_LOG_POS_SYM {}
+ | RELAY_LOG_FILE_SYM {}
+ | RELAY_LOG_POS_SYM {}
| RELOAD {}
| REPAIR {}
| REPEATABLE_SYM {}
@@ -3199,13 +3454,14 @@ keyword:
| SERIALIZABLE_SYM {}
| SESSION_SYM {}
| SIGNED_SYM {}
+ | SIMPLE_SYM {}
| SHARE_SYM {}
| SHUTDOWN {}
- | SLAVE {}
+ | SLAVE {}
| SQL_CACHE_SYM {}
| SQL_BUFFER_RESULT {}
| SQL_NO_CACHE_SYM {}
- | SQL_THREAD {}
+ | SQL_THREAD {}
| START_SYM {}
| STATUS_SYM {}
| STOP_SYM {}
@@ -3224,7 +3480,8 @@ keyword:
| USE_FRM {}
| VARIABLES {}
| WORK_SYM {}
- | YEAR_SYM {};
+ | YEAR_SYM {}
+ ;
/* Option functions */
@@ -3255,16 +3512,16 @@ option_type:
opt_var_type:
/* empty */ { $$=OPT_SESSION; }
+ | GLOBAL_SYM { $$=OPT_GLOBAL; }
| LOCAL_SYM { $$=OPT_SESSION; }
| SESSION_SYM { $$=OPT_SESSION; }
- | GLOBAL_SYM { $$=OPT_GLOBAL; }
;
opt_var_ident_type:
/* empty */ { $$=OPT_DEFAULT; }
+ | GLOBAL_SYM '.' { $$=OPT_GLOBAL; }
| LOCAL_SYM '.' { $$=OPT_SESSION; }
| SESSION_SYM '.' { $$=OPT_SESSION; }
- | GLOBAL_SYM '.' { $$=OPT_GLOBAL; }
;
option_value:
@@ -3326,7 +3583,7 @@ isolation_types:
| REPEATABLE_SYM READ_SYM { $$= ISO_REPEATABLE_READ; }
| SERIALIZABLE_SYM { $$= ISO_SERIALIZABLE; }
;
-
+
text_or_password:
TEXT_STRING { $$=$1.str;}
| PASSWORD '(' TEXT_STRING ')'
@@ -3632,13 +3889,14 @@ column_list:
column_list_id:
ident
{
- String *new_str = new String((const char*) $1.str,$1.length);
+ String *new_str = new String((const char*) $1.str,$1.length,default_charset_info);
List_iterator <LEX_COLUMN> iter(Lex->columns);
class LEX_COLUMN *point;
LEX *lex=Lex;
while ((point=iter++))
{
- if (!my_strcasecmp(point->column.ptr(),new_str->ptr()))
+ if (!my_strcasecmp(system_charset_info,
+ point->column.ptr(), new_str->ptr()))
break;
}
lex->grant_tot_col|= lex->which_columns;
@@ -3704,7 +3962,7 @@ rollback:
/*
-** UNIONS : glue selects together
+ UNIONS : glue selects together
*/
@@ -3713,16 +3971,16 @@ union:
| union_list;
union_list:
- UNION_SYM union_option
+ UNION_SYM union_option
{
LEX *lex=Lex;
if (lex->exchange)
{
/* Only the last SELECT can have INTO...... */
- net_printf(&lex->thd->net, ER_WRONG_USAGE,"UNION","INTO");
+ net_printf(&lex->thd->net, ER_WRONG_USAGE, "UNION", "INTO");
YYABORT;
- }
- if (lex->select->linkage == NOT_A_SELECT)
+ }
+ if (lex->select->linkage == GLOBAL_OPTIONS_TYPE)
{
send_error(&lex->thd->net, ER_SYNTAX_ERROR);
YYABORT;
@@ -3730,7 +3988,7 @@ union_list:
if (mysql_new_select(lex))
YYABORT;
lex->select->linkage=UNION_TYPE;
- }
+ }
select_init
;
@@ -3742,22 +4000,64 @@ optional_order_or_limit:
/* empty */ {}
|
{
- LEX *lex=Lex;
+ LEX *lex=Lex;
if (!lex->select->braces)
{
send_error(&lex->thd->net, ER_SYNTAX_ERROR);
YYABORT;
}
- if (mysql_new_select(lex))
- YYABORT;
- mysql_init_select(lex);
- lex->select->linkage=NOT_A_SELECT;
- lex->select->select_limit=lex->thd->variables.select_limit;
- }
- opt_order_clause limit_clause
+ lex->select->master_unit()->global_parameters=
+ lex->select->master_unit();
+ /*
+ Following type conversion looks like hack, but all that need
+ SELECT_LEX fields always check linkage type.
+ */
+ lex->select= (SELECT_LEX*)lex->select->master_unit();
+ lex->select->select_limit=lex->thd->default_select_limit;
+ }
+ opt_order_clause limit_clause
;
union_option:
/* empty */ {}
- | ALL { Lex->union_option=1; }
- ;
+ | ALL {Lex->union_option=1;};
+
+singleval_subselect:
+ subselect_start singleval_subselect_init
+ subselect_end
+ {
+ $$= $2;
+ };
+
+singleval_subselect_init:
+ select_init
+ {
+ $$= new Item_singleval_subselect(current_thd, Lex->select);
+ };
+
+exists_subselect:
+ subselect_start exists_subselect_init
+ subselect_end
+ {
+ $$= $2;
+ };
+
+exists_subselect_init:
+ select_init
+ {
+ $$= new Item_exists_subselect(current_thd, Lex->select);
+ };
+
+subselect_start:
+ '('
+ {
+ if (mysql_new_select(Lex, 1))
+ YYABORT;
+ };
+
+subselect_end:
+ ')'
+ {
+ LEX *lex=Lex;
+ lex->select = lex->select->outer_select();
+ };
diff --git a/sql/structs.h b/sql/structs.h
index bd058a08e46..c2ad4ef527e 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -156,6 +156,29 @@ typedef struct show_var_st {
SHOW_TYPE type;
} SHOW_VAR;
+struct show_table_type_st {
+ const char *type;
+ char *value;
+ const char *comment;
+};
+
+struct show_column_type_st {
+ const char *type;
+ uint size;
+ const char *min_value;
+ const char *max_value;
+ uint precision;
+ uint scale;
+ const char *nullable;
+ const char *auto_increment;
+ const char *unsigned_attr;
+ const char *zerofill;
+ const char *searchable;
+ const char *case_sensitivity;
+ const char *default_value;
+ const char *comment;
+};
+
typedef struct lex_string {
char *str;
uint length;
diff --git a/sql/table.cc b/sql/table.cc
index cc5666ff5fb..3e41da73109 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -47,19 +47,19 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
int j,error;
uint rec_buff_length,n_length,int_length,records,key_parts,keys,
interval_count,interval_parts,read_length,db_create_options;
- uint key_info_length;
+ uint key_info_length, com_length;
ulong pos;
- char index_file[FN_REFLEN], *names,*keynames;
+ char index_file[FN_REFLEN], *names, *keynames, *comment_pos;
uchar head[288],*disk_buff,new_field_pack_flag;
my_string record;
const char **int_array;
- bool new_frm_ver,use_hash, null_field_first;
+ bool use_hash, null_field_first;
File file;
Field **field_ptr,*reg_field;
KEY *keyinfo;
KEY_PART_INFO *key_part;
uchar *null_pos;
- uint null_bit;
+ uint null_bit, new_frm_ver, field_pack_length;
SQL_CRYPT *crypted=0;
DBUG_ENTER("openfrm");
DBUG_PRINT("enter",("name: '%s' form: %lx",name,outparam));
@@ -95,10 +95,11 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
if (my_read(file,(byte*) head,64,MYF(MY_NABP))) goto err_not_open;
if (head[0] != (uchar) 254 || head[1] != 1 ||
- (head[2] != FRM_VER && head[2] != FRM_VER+1))
+ (head[2] < FRM_VER && head[2] > FRM_VER+2))
goto err_not_open; /* purecov: inspected */
new_field_pack_flag=head[27];
- new_frm_ver= (head[2] == FRM_VER+1);
+ new_frm_ver= (head[2] - FRM_VER);
+ field_pack_length= new_frm_ver < 2 ? 11 : 15;
error=3;
if (!(pos=get_form_pos(file,head,(TYPELIB*) 0)))
@@ -116,6 +117,8 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
outparam->raid_type= head[41];
outparam->raid_chunks= head[42];
outparam->raid_chunksize= uint4korr(head+43);
+ if (!(outparam->table_charset=get_charset((uint) head[38],MYF(0))))
+ outparam->table_charset=NULL; // QQ display error message?
null_field_first=1;
}
outparam->db_record_offset=1;
@@ -153,9 +156,23 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
for (i=0 ; i < keys ; i++, keyinfo++)
{
- keyinfo->flags= ((uint) strpos[0]) ^ HA_NOSAME;
- keyinfo->key_length= (uint) uint2korr(strpos+1);
- keyinfo->key_parts= (uint) strpos[3]; strpos+=4;
+ if (new_frm_ver == 2)
+ {
+ keyinfo->flags= (uint) uint2korr(strpos) ^ HA_NOSAME;
+ keyinfo->key_length= (uint) uint2korr(strpos+2);
+ keyinfo->key_parts= (uint) strpos[4];
+ keyinfo->algorithm= (enum ha_key_alg) strpos[5];
+ strpos+=8;
+ }
+ else
+ {
+ keyinfo->flags= ((uint) strpos[0]) ^ HA_NOSAME;
+ keyinfo->key_length= (uint) uint2korr(strpos+1);
+ keyinfo->key_parts= (uint) strpos[3];
+ keyinfo->algorithm= HA_KEY_ALG_UNDEF;
+ strpos+=4;
+ }
+
keyinfo->key_part= key_part;
keyinfo->rec_per_key= rec_per_key;
for (j=keyinfo->key_parts ; j-- ; key_part++)
@@ -165,7 +182,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
key_part->offset= (uint) uint2korr(strpos+2)-1;
key_part->key_type= (uint) uint2korr(strpos+5);
// key_part->field= (Field*) 0; // Will be fixed later
- if (new_frm_ver)
+ if (new_frm_ver >= 1)
{
key_part->key_part_flag= *(strpos+4);
key_part->length= (uint) uint2korr(strpos+7);
@@ -191,15 +208,6 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
}
keynames=(char*) key_part;
strpos+= (strmov(keynames, (char *) strpos) - keynames)+1;
- /* Test if new 4.0 format */
- if ((uint) (strpos - disk_buff) < key_info_length)
- {
- /* Read key types */
- keyinfo=outparam->key_info;
- for (i=0 ; i < keys ; i++, keyinfo++)
- keyinfo->algorithm= (enum ha_key_alg) *(strpos++);
- }
-
outparam->reclength = uint2korr((head+16));
if (*(head+26) == 1)
outparam->system=1; /* one-record-database */
@@ -267,10 +275,11 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
interval_parts=uint2korr(head+272);
int_length=uint2korr(head+274);
outparam->null_fields=uint2korr(head+282);
+ com_length=uint2korr(head+284);
outparam->comment=strdup_root(&outparam->mem_root,
(char*) head+47);
- DBUG_PRINT("info",("i_count: %d i_parts: %d index: %d n_length: %d int_length: %d", interval_count,interval_parts, outparam->keys,n_length,int_length));
+ DBUG_PRINT("info",("i_count: %d i_parts: %d index: %d n_length: %d int_length: %d com_length: %d", interval_count,interval_parts, outparam->keys,n_length,int_length, com_length));
if (!(field_ptr = (Field **)
alloc_root(&outparam->mem_root,
@@ -278,12 +287,12 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
interval_count*sizeof(TYPELIB)+
(outparam->fields+interval_parts+
keys+3)*sizeof(my_string)+
- (n_length+int_length)))))
+ (n_length+int_length+com_length)))))
goto err_not_open; /* purecov: inspected */
outparam->field=field_ptr;
- read_length=((uint) (outparam->fields*11)+pos+
- (uint) (n_length+int_length));
+ read_length=(uint) (outparam->fields * field_pack_length +
+ pos+ (uint) (n_length+int_length+com_length));
if (read_string(file,(gptr*) &disk_buff,read_length))
goto err_not_open; /* purecov: inspected */
if (crypted)
@@ -299,8 +308,10 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
names= (char*) (int_array+outparam->fields+interval_parts+keys+3);
if (!interval_count)
outparam->intervals=0; // For better debugging
- memcpy((char*) names, strpos+(outparam->fields*11),
+ memcpy((char*) names, strpos+(outparam->fields*field_pack_length),
(uint) (n_length+int_length));
+ comment_pos=names+(n_length+int_length);
+ memcpy(comment_pos, disk_buff+read_length-com_length, com_length);
fix_type_pointers(&int_array,&outparam->fieldnames,1,&names);
fix_type_pointers(&int_array,outparam->intervals,interval_count,
@@ -328,26 +339,60 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
use_hash= outparam->fields >= MAX_FIELDS_BEFORE_HASH;
if (use_hash)
use_hash= !hash_init(&outparam->name_hash,
+ system_charset_info,
outparam->fields,0,0,
(hash_get_key) get_field_name,0,
HASH_CASE_INSENSITIVE);
- for (i=0 ; i < outparam->fields; i++, strpos+= 11, field_ptr++)
+ for (i=0 ; i < outparam->fields; i++, strpos+=field_pack_length, field_ptr++)
{
uint pack_flag= uint2korr(strpos+6);
uint interval_nr= (uint) strpos[10];
+ enum_field_types field_type;
+ CHARSET_INFO *charset;
+ LEX_STRING comment;
+ if (new_frm_ver == 2)
+ {
+ /* new frm file in 4.1 */
+ uint comment_length=uint2korr(strpos+13);
+ field_type=(enum_field_types) (uint) strpos[11];
+ if (!(charset=get_charset((uint) strpos[12], MYF(0))))
+ charset=outparam->table_charset?outparam->table_charset:default_charset_info;
+ if (!comment_length)
+ {
+ comment.str= (char*) "";
+ comment.length=0;
+ }
+ else
+ {
+ comment.str= (char*) comment_pos;
+ comment.length= comment_length;
+ comment_pos+= comment_length;
+ }
+ }
+ else
+ {
+ /* old frm file */
+ field_type= (enum_field_types) f_packtype(pack_flag);
+ charset=outparam->table_charset?outparam->table_charset:default_charset_info;
+ bzero((char*) &comment, sizeof(comment));
+ }
*field_ptr=reg_field=
make_field(record+uint2korr(strpos+4),
(uint32) strpos[3], // field_length
null_pos,null_bit,
pack_flag,
+ field_type,
(Field::utype) MTYP_TYPENR((uint) strpos[8]),
(interval_nr ?
outparam->intervals+interval_nr-1 :
(TYPELIB*) 0),
outparam->fieldnames.type_names[i],
outparam);
+ reg_field->comment=comment;
+ if (!reg_field->binary())
+ ((Field_str*) reg_field)->set_charset(charset);
if (!(reg_field->flags & NOT_NULL_FLAG))
{
if ((null_bit<<=1) == 256)
@@ -445,13 +490,13 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
keyinfo->key_length ? UNIQUE_KEY_FLAG : MULTIPLE_KEY_FLAG);
if (i == 0)
field->key_start|= ((key_map) 1 << key);
- if ((index_flags & HA_KEY_READ_ONLY) &&
- field->key_length() == key_part->length &&
+ if (field->key_length() == key_part->length &&
field->type() != FIELD_TYPE_BLOB)
{
- if (field->key_type() != HA_KEYTYPE_TEXT ||
- (!(ha_option & HA_KEY_READ_WRONG_STR) &&
- !(keyinfo->flags & HA_FULLTEXT)))
+ if ((index_flags & HA_HAVE_KEY_READ_ONLY) &&
+ (field->key_type() != HA_KEYTYPE_TEXT ||
+ (!(ha_option & HA_KEY_READ_WRONG_STR) &&
+ !(keyinfo->flags & HA_FULLTEXT))))
field->part_of_key|= ((key_map) 1 << key);
if ((field->key_type() != HA_KEYTYPE_TEXT ||
!(keyinfo->flags & HA_FULLTEXT)) &&
@@ -934,9 +979,14 @@ ulong next_io_size(register ulong pos)
} /* next_io_size */
-void append_unescaped(String *res,const char *pos)
+ /* Store in String an SQL quoted string */
+
+void append_unescaped(String *res,const char *pos, uint length)
{
- for (; *pos ; pos++)
+ const char *end= pos+length;
+ res->append('\'');
+
+ for (; pos != end ; pos++)
{
switch (*pos) {
case 0: /* Must be escaped for 'mysql' */
@@ -964,6 +1014,7 @@ void append_unescaped(String *res,const char *pos)
break;
}
}
+ res->append('\'');
}
/* Create a .frm file */
@@ -987,7 +1038,7 @@ File create_frm(register my_string name, uint reclength, uchar *fileinfo,
if ((file=my_create(name,CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
{
bzero((char*) fileinfo,64);
- fileinfo[0]=(uchar) 254; fileinfo[1]= 1; fileinfo[2]= FRM_VER+1; // Header
+ fileinfo[0]=(uchar) 254; fileinfo[1]= 1; fileinfo[2]= FRM_VER+2; // Header
fileinfo[3]= (uchar) ha_checktype(create_info->db_type);
fileinfo[4]=1;
int2store(fileinfo+6,IO_SIZE); /* Next block starts here */
@@ -1003,6 +1054,7 @@ File create_frm(register my_string name, uint reclength, uchar *fileinfo,
int2store(fileinfo+30,create_info->table_options);
fileinfo[32]=0; // No filename anymore
int4store(fileinfo+34,create_info->avg_row_length);
+ fileinfo[38]= create_info->table_charset?create_info->table_charset->number:0;
fileinfo[40]= (uchar) create_info->row_type;
fileinfo[41]= (uchar) create_info->raid_type;
fileinfo[42]= (uchar) create_info->raid_chunks;
@@ -1033,6 +1085,7 @@ void update_create_info_from_table(HA_CREATE_INFO *create_info, TABLE *table)
create_info->raid_type=table->raid_type;
create_info->raid_chunks=table->raid_chunks;
create_info->raid_chunksize=table->raid_chunksize;
+ create_info->table_charset=table->table_charset;
DBUG_VOID_RETURN;
}
@@ -1055,7 +1108,7 @@ char *get_field(MEM_ROOT *mem, TABLE *table, uint fieldnr)
{
Field *field=table->field[fieldnr];
char buff[MAX_FIELD_WIDTH];
- String str(buff,sizeof(buff));
+ String str(buff,sizeof(buff),default_charset_info);
field->val_str(&str,&str);
uint length=str.length();
if (!length)
@@ -1072,9 +1125,10 @@ bool check_db_name(const char *name)
while (*name)
{
#if defined(USE_MB) && defined(USE_MB_IDENT)
- if (use_mb(default_charset_info))
+ if (use_mb(system_charset_info))
{
- int len=my_ismbchar(default_charset_info, name, name+MBMAXLEN);
+ int len=my_ismbchar(system_charset_info, name,
+ name+system_charset_info->mbmaxlen);
if (len)
{
name += len;
@@ -1105,9 +1159,9 @@ bool check_table_name(const char *name, uint length)
while (name != end)
{
#if defined(USE_MB) && defined(USE_MB_IDENT)
- if (use_mb(default_charset_info))
+ if (use_mb(system_charset_info))
{
- int len=my_ismbchar(default_charset_info, name, end);
+ int len=my_ismbchar(system_charset_info, name, end);
if (len)
{
name += len;
@@ -1127,9 +1181,10 @@ bool check_column_name(const char *name)
while (*name)
{
#if defined(USE_MB) && defined(USE_MB_IDENT)
- if (use_mb(default_charset_info))
+ if (use_mb(system_charset_info))
{
- int len=my_ismbchar(default_charset_info, name, name+MBMAXLEN);
+ int len=my_ismbchar(system_charset_info, name,
+ name+system_charset_info->mbmaxlen);
if (len)
{
name += len;
@@ -1161,7 +1216,7 @@ db_type get_table_type(const char *name)
error=my_read(file,(byte*) head,4,MYF(MY_NABP));
my_close(file,MYF(0));
if (error || head[0] != (uchar) 254 || head[1] != 1 ||
- (head[2] != FRM_VER && head[2] != FRM_VER+1))
+ (head[2] < FRM_VER && head[2] > FRM_VER+2))
DBUG_RETURN(DB_TYPE_UNKNOWN);
DBUG_RETURN(ha_checktype((enum db_type) (uint) *(head+3)));
}
diff --git a/sql/table.h b/sql/table.h
index 229d41a2df7..02abb090426 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -105,6 +105,7 @@ struct st_table {
*rowid_field;
Field_timestamp *timestamp_field;
my_string comment; /* Comment about table */
+ CHARSET_INFO *table_charset; /* Default charset of string fields */
REGINFO reginfo; /* field connections */
MEM_ROOT mem_root;
GRANT_INFO grant;
@@ -140,21 +141,29 @@ typedef struct st_table_list
struct st_table_list *next;
char *db,*name,*real_name;
uint32 db_length, real_name_length;
- Item *on_expr; /* Used with outer join */
- struct st_table_list *natural_join; /* natural join on this table*/
+ Item *on_expr; /* Used with outer join */
+ struct st_table_list *natural_join; /* natural join on this table*/
/* ... join ... USE INDEX ... IGNORE INDEX */
- List<String> *use_index,*ignore_index;
- TABLE *table;
+ List<String> *use_index, *ignore_index;
+ /*
+ Usually hold reference on opened table, but may hold reference
+ to node of complete list of tables used in UNION & subselect.
+ */
+ union
+ {
+ TABLE *table; /* opened table */
+ st_table_list *table_list; /* pointer to node of list of all tables */
+ };
GRANT_INFO grant;
thr_lock_type lock_type;
- uint outer_join; /* Which join type */
- bool straight; /* optimize with prev table */
- bool updating; /* for replicate-do/ignore table */
- bool shared; /* Used twice in union */
- bool do_redirect; /* To get the struct in UNION's */
+ uint outer_join; /* Which join type */
+ bool straight; /* optimize with prev table */
+ bool updating; /* for replicate-do/ignore table */
+ bool shared; /* Used twice in union */
+ bool do_redirect; /* If *table has to be fixed in UNION */
+ void *derived; /* SELECT_LEX_UNIT of derived table */
} TABLE_LIST;
-
typedef struct st_changed_table_list
{
struct st_changed_table_list *next;
@@ -162,7 +171,6 @@ typedef struct st_changed_table_list
uint32 key_length;
} CHANGED_TABLE_LIST;
-
typedef struct st_open_table_list
{
struct st_open_table_list *next;
diff --git a/sql/time.cc b/sql/time.cc
index 1597368908d..aadc32964ff 100644
--- a/sql/time.cc
+++ b/sql/time.cc
@@ -268,13 +268,13 @@ void find_date(string pos,uint *vek,uint flag)
DBUG_PRINT("enter",("pos: '%s' flag: %d",pos,flag));
bzero((char*) vek,sizeof(int)*4);
- while (*pos && !isdigit(*pos))
+ while (*pos && !my_isdigit(system_charset_info,*pos))
pos++;
length=(uint) strlen(pos);
for (uint i=0 ; i< 3; i++)
{
start=pos; value=0;
- while (isdigit(pos[0]) &&
+ while (my_isdigit(system_charset_info,pos[0]) &&
((pos-start) < 2 || ((pos-start) < 4 && length >= 8 &&
!(flag & 3))))
{
@@ -282,7 +282,8 @@ void find_date(string pos,uint *vek,uint flag)
pos++;
}
vek[flag & 3]=value; flag>>=2;
- while (*pos && (ispunct(*pos) || isspace(*pos)))
+ while (*pos && (my_ispunct(system_charset_info,*pos) ||
+ my_isspace(system_charset_info,*pos)))
pos++;
}
DBUG_PRINT("exit",("year: %d month: %d day: %d",vek[0],vek[1],vek[2]));
@@ -434,7 +435,8 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date)
DBUG_ENTER("str_to_TIME");
DBUG_PRINT("enter",("str: %.*s",length,str));
- for (; str != end && !isdigit(*str) ; str++) ; // Skip garbage
+ // Skip garbage
+ for (; str != end && !my_isdigit(system_charset_info, *str) ; str++) ;
if (str == end)
DBUG_RETURN(TIMESTAMP_NONE);
/*
@@ -442,14 +444,14 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date)
** If length= 8 or >= 14 then year is of format YYYY.
(YYYY-MM-DD, YYYYMMDD, YYYYYMMDDHHMMSS)
*/
- for (pos=str; pos != end && isdigit(*pos) ; pos++) ;
+ for (pos=str; pos != end && my_isdigit(system_charset_info,*pos) ; pos++) ;
digits= (uint) (pos-str);
year_length= (digits == 4 || digits == 8 || digits >= 14) ? 4 : 2;
field_length=year_length-1;
- for (i=0 ; i < 6 && str != end && isdigit(*str) ; i++)
+ for (i=0 ; i < 6 && str != end && my_isdigit(system_charset_info,*str) ; i++)
{
uint tmp_value=(uint) (uchar) (*str++ - '0');
- while (str != end && isdigit(str[0]) && field_length--)
+ while (str != end && my_isdigit(system_charset_info,str[0]) && field_length--)
{
tmp_value=tmp_value*10 + (uint) (uchar) (*str - '0');
str++;
@@ -459,10 +461,12 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date)
str++; // ISO8601: CCYYMMDDThhmmss
else if ( i != 5 ) // Skip inter-field delimiters
{
- while (str != end && (ispunct(*str) || isspace(*str)))
+ while (str != end &&
+ (my_ispunct(system_charset_info,*str) ||
+ my_isspace(system_charset_info,*str)))
{
// Only allow space between days and hours
- if (isspace(*str) && i != 2)
+ if (my_isspace(system_charset_info,*str) && i != 2)
DBUG_RETURN(TIMESTAMP_NONE);
str++;
}
@@ -470,12 +474,13 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date)
field_length=1; // Rest fields can only be 2
}
/* Handle second fractions */
- if (i == 6 && (uint) (end-str) >= 2 && *str == '.' && isdigit(str[1]))
+ if (i == 6 && (uint) (end-str) >= 2 && *str == '.' &&
+ my_isdigit(system_charset_info,str[1]))
{
str++;
uint tmp_value=(uint) (uchar) (*str - '0');
field_length=3;
- while (str++ != end && isdigit(str[0]) && field_length--)
+ while (str++ != end && my_isdigit(system_charset_info,str[0]) && field_length--)
tmp_value=tmp_value*10 + (uint) (uchar) (*str - '0');
date[6]=tmp_value;
}
@@ -498,7 +503,7 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date)
{
for (; str != end ; str++)
{
- if (!isspace(*str))
+ if (!my_isspace(system_charset_info,*str))
{
current_thd->cuted_fields++;
break;
@@ -559,7 +564,8 @@ bool str_to_time(const char *str,uint length,TIME *l_time)
uint state;
l_time->neg=0;
- for (; str != end && !isdigit(*str) && *str != '-' ; str++)
+ for (; str != end &&
+ !my_isdigit(system_charset_info,*str) && *str != '-' ; str++)
length--;
if (str != end && *str == '-')
{
@@ -578,7 +584,7 @@ bool str_to_time(const char *str,uint length,TIME *l_time)
}
/* Not a timestamp. Try to get this as a DAYS_TO_SECOND string */
- for (value=0; str != end && isdigit(*str) ; str++)
+ for (value=0; str != end && my_isdigit(system_charset_info,*str) ; str++)
value=value*10L + (long) (*str - '0');
if (*str == ' ')
@@ -589,14 +595,16 @@ bool str_to_time(const char *str,uint length,TIME *l_time)
LINT_INIT(state);
found_days=found_hours=0;
- if ((uint) (end-str) > 1 && (*str == ' ' && isdigit(str[1])))
+ if ((uint) (end-str) > 1 && (*str == ' ' &&
+ my_isdigit(system_charset_info,str[1])))
{ // days !
date[0]=value;
state=1; // Assume next is hours
found_days=1;
str++; // Skip space;
}
- else if ((end-str) > 1 && *str == ':' && isdigit(str[1]))
+ else if ((end-str) > 1 && *str == ':' &&
+ my_isdigit(system_charset_info,str[1]))
{
date[0]=0; // Assume we found hours
date[1]=value;
@@ -618,10 +626,11 @@ bool str_to_time(const char *str,uint length,TIME *l_time)
/* Read hours, minutes and seconds */
for (;;)
{
- for (value=0; str != end && isdigit(*str) ; str++)
+ for (value=0; str != end && my_isdigit(system_charset_info,*str) ; str++)
value=value*10L + (long) (*str - '0');
date[state++]=value;
- if (state == 4 || (end-str) < 2 || *str != ':' || !isdigit(str[1]))
+ if (state == 4 || (end-str) < 2 || *str != ':' ||
+ !my_isdigit(system_charset_info,str[1]))
break;
str++; // Skip ':'
}
@@ -641,11 +650,13 @@ bool str_to_time(const char *str,uint length,TIME *l_time)
fractional:
/* Get fractional second part */
- if ((end-str) >= 2 && *str == '.' && isdigit(str[1]))
+ if ((end-str) >= 2 && *str == '.' && my_isdigit(system_charset_info,str[1]))
{
uint field_length=3;
str++; value=(uint) (uchar) (*str - '0');
- while (++str != end && isdigit(str[0]) && field_length--)
+ while (++str != end &&
+ my_isdigit(system_charset_info,str[0]) &&
+ field_length--)
value=value*10 + (uint) (uchar) (*str - '0');
date[4]=value;
}
@@ -670,7 +681,7 @@ bool str_to_time(const char *str,uint length,TIME *l_time)
{
do
{
- if (!isspace(*str))
+ if (!my_isspace(system_charset_info,*str))
{
current_thd->cuted_fields++;
break;
diff --git a/sql/unireg.cc b/sql/unireg.cc
index 7d0201f75ae..8db9b871a39 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -28,7 +28,7 @@
#include "mysql_priv.h"
#include <m_ctype.h>
-#define FCOMP 11 /* Byte per packat f{lt */
+#define FCOMP 15 /* Bytes for a packed field */
static uchar * pack_screens(List<create_field> &create_fields,
uint *info_length, uint *screens, bool small_file);
@@ -246,7 +246,7 @@ static uchar * pack_screens(List<create_field> &create_fields,
static uint pack_keys(uchar *keybuff,uint key_count,KEY *keyinfo)
{
uint key_parts,length;
- uchar *pos, *keyname_pos, *key_alg_pos;
+ uchar *pos, *keyname_pos;
KEY *key,*end;
KEY_PART_INFO *key_part,*key_part_end;
DBUG_ENTER("pack_keys");
@@ -255,10 +255,12 @@ static uint pack_keys(uchar *keybuff,uint key_count,KEY *keyinfo)
key_parts=0;
for (key=keyinfo,end=keyinfo+key_count ; key != end ; key++)
{
- pos[0]=(uchar) (key->flags ^ HA_NOSAME);
- int2store(pos+1,key->key_length);
- pos[3]=key->key_parts;
- pos+=4;
+ int2store(pos, (key->flags ^ HA_NOSAME));
+ int2store(pos+2,key->key_length);
+ pos[4]= (uchar) key->key_parts;
+ pos[5]= (uchar) key->algorithm;
+ pos[6]=pos[7]=0; // For the future
+ pos+=8;
key_parts+=key->key_parts;
DBUG_PRINT("loop",("flags: %d key_parts: %d at %lx",
key->flags,key->key_parts,
@@ -290,18 +292,11 @@ static uint pack_keys(uchar *keybuff,uint key_count,KEY *keyinfo)
}
*(pos++)=0;
- /* For MySQL 4.0; Store key algoritms last */
- key_alg_pos= pos;
- for (key=keyinfo ; key != end ; key++)
- {
- *(pos++)= (uchar) key->algorithm;
- }
-
keybuff[0]=(uchar) key_count;
keybuff[1]=(uchar) key_parts;
length=(uint) (keyname_pos-keybuff);
int2store(keybuff+2,length);
- length=(uint) (key_alg_pos-keyname_pos);
+ length=(uint) (pos-keyname_pos);
int2store(keybuff+4,length);
DBUG_RETURN((uint) (pos-keybuff));
} /* pack_keys */
@@ -314,9 +309,9 @@ static bool pack_header(uchar *forminfo, enum db_type table_type,
uint info_length, uint screens,uint table_options,
handler *file)
{
- uint length,int_count,int_length,no_empty, int_parts,
- time_stamp_pos,null_fields;
- ulong reclength,totlength,n_length;
+ uint length,int_count,int_length,no_empty, int_parts;
+ uint time_stamp_pos,null_fields;
+ ulong reclength, totlength, n_length, com_length;
DBUG_ENTER("pack_header");
if (create_fields.elements > MAX_FIELDS)
@@ -326,7 +321,8 @@ static bool pack_header(uchar *forminfo, enum db_type table_type,
}
totlength=reclength=0L;
- no_empty=int_count=int_parts=int_length=time_stamp_pos=null_fields=0;
+ no_empty=int_count=int_parts=int_length=time_stamp_pos=null_fields=
+ com_length=0;
n_length=2L;
/* Check fields */
@@ -336,6 +332,7 @@ static bool pack_header(uchar *forminfo, enum db_type table_type,
while ((field=it++))
{
totlength+= field->length;
+ com_length+= field->comment.length;
if (MTYP_TYPENR(field->unireg_check) == Field::NOEMPTY ||
field->unireg_check & MTYP_NOEMPTY_BIT)
{
@@ -378,14 +375,15 @@ static bool pack_header(uchar *forminfo, enum db_type table_type,
/* Hack to avoid bugs with small static rows in MySQL */
reclength=max(file->min_record_length(table_options),reclength);
if (info_length+(ulong) create_fields.elements*FCOMP+288+
- n_length+int_length > 65535L || int_count > 255)
+ n_length+int_length+com_length > 65535L || int_count > 255)
{
my_error(ER_TOO_MANY_FIELDS,MYF(0));
DBUG_RETURN(1);
}
bzero((char*)forminfo,288);
- length=info_length+create_fields.elements*FCOMP+288+n_length+int_length;
+ length=(info_length+create_fields.elements*FCOMP+288+n_length+int_length+
+ com_length);
int2store(forminfo,length);
forminfo[256] = (uint8) screens;
int2store(forminfo+258,create_fields.elements);
@@ -401,6 +399,7 @@ static bool pack_header(uchar *forminfo, enum db_type table_type,
int2store(forminfo+278,80); /* Columns needed */
int2store(forminfo+280,22); /* Rows needed */
int2store(forminfo+282,null_fields);
+ int2store(forminfo+284,com_length);
DBUG_RETURN(0);
} /* pack_header */
@@ -438,7 +437,7 @@ static uint get_interval_id(uint *int_count,List<create_field> &create_fields,
static bool pack_fields(File file,List<create_field> &create_fields)
{
reg2 uint i;
- uint int_count;
+ uint int_count, comment_length=0;
uchar buff[MAX_FIELD_WIDTH];
create_field *field;
DBUG_ENTER("pack_fields");
@@ -459,6 +458,10 @@ static bool pack_fields(File file,List<create_field> &create_fields)
int2store(buff+6,field->pack_flag);
int2store(buff+8,field->unireg_check);
buff[10]= (uchar) field->interval_id;
+ buff[11]= (uchar) field->sql_type;
+ buff[12]= (uchar) field->charset->number;
+ int2store(buff+13, field->comment.length);
+ comment_length+= field->comment.length;
set_if_bigger(int_count,field->interval_id);
if (my_write(file,(byte*) buff,FCOMP,MYF_RW))
DBUG_RETURN(1);
@@ -484,7 +487,7 @@ static bool pack_fields(File file,List<create_field> &create_fields)
/* Write intervals */
if (int_count)
{
- String tmp((char*) buff,sizeof(buff));
+ String tmp((char*) buff,sizeof(buff), default_charset_info);
tmp.length(0);
it.rewind();
int_count=0;
@@ -505,6 +508,18 @@ static bool pack_fields(File file,List<create_field> &create_fields)
if (my_write(file,(byte*) tmp.ptr(),tmp.length(),MYF_RW))
DBUG_RETURN(1);
}
+ if (comment_length)
+ {
+ it.rewind();
+ int_count=0;
+ while ((field=it++))
+ {
+ if (field->comment.length)
+ if (my_write(file, (byte*) field->comment.str, field->comment.length,
+ MYF_RW))
+ DBUG_RETURN(1);
+ }
+ }
DBUG_RETURN(0);
}
@@ -557,10 +572,12 @@ static bool make_empty_rec(File file,enum db_type table_type,
null_pos+null_count/8,
1 << (null_count & 7),
field->pack_flag,
+ field->sql_type,
field->unireg_check,
field->interval,
field->field_name,
&table);
+
if (!(field->flags & NOT_NULL_FLAG))
null_count++;
@@ -573,7 +590,7 @@ static bool make_empty_rec(File file,enum db_type table_type,
if (field->def &&
(regfield->real_type() != FIELD_TYPE_YEAR ||
field->def->val_int() != 0))
- field->def->save_in_field(regfield);
+ (void) field->def->save_in_field(regfield);
else if (regfield->real_type() == FIELD_TYPE_ENUM &&
(field->flags & NOT_NULL_FLAG))
{
@@ -581,9 +598,9 @@ static bool make_empty_rec(File file,enum db_type table_type,
regfield->store((longlong) 1);
}
else if (type == Field::YES) // Old unireg type
- regfield->store(ER(ER_YES),(uint) strlen(ER(ER_YES)));
+ regfield->store(ER(ER_YES),(uint) strlen(ER(ER_YES)),default_charset_info);
else if (type == Field::NO) // Old unireg type
- regfield->store(ER(ER_NO), (uint) strlen(ER(ER_NO)));
+ regfield->store(ER(ER_NO), (uint) strlen(ER(ER_NO)),default_charset_info);
else
regfield->reset();
delete regfield;