diff options
author | Sergei Golubchik <sergii@pisem.net> | 2014-06-06 00:07:27 +0200 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2014-06-06 00:07:27 +0200 |
commit | e27c338634739ef56a6888e7948e04c0fa0ba677 (patch) | |
tree | ad63ccae614f3dd77509825d1905fd815ef322cb /sql/sql_load.cc | |
parent | 2a5905141a3c509a7c34c3d370fb146dbc1c965f (diff) | |
parent | 6d75570e99fbf070cdbeefdfbcfc94d1c7b3ad1f (diff) | |
download | mariadb-git-e27c338634739ef56a6888e7948e04c0fa0ba677.tar.gz |
5.5.38 merge
Diffstat (limited to 'sql/sql_load.cc')
-rw-r--r-- | sql/sql_load.cc | 64 |
1 files changed, 40 insertions, 24 deletions
diff --git a/sql/sql_load.cc b/sql/sql_load.cc index bdf26ec0292..534a8fa5484 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -1,6 +1,6 @@ /* - Copyright (c) 2000, 2013, Oracle and/or its affiliates. - Copyright (c) 2010, 2013, Monty Progrm Ab + Copyright (c) 2000, 2014, Oracle and/or its affiliates. + Copyright (c) 2010, 2014, SkySQL 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 @@ -58,13 +58,17 @@ XML_TAG::XML_TAG(int l, String f, String v) } +#define GET (stack_pos != stack ? *--stack_pos : my_b_get(&cache)) +#define PUSH(A) *(stack_pos++)=(A) + class READ_INFO { File file; uchar *buffer, /* Buffer for read text */ *end_of_buff; /* Data in bufferts ends here */ uint buff_length, /* Length of buffert */ max_length; /* Max length of row */ - char *field_term_ptr,*line_term_ptr,*line_start_ptr,*line_start_end; + const uchar *field_term_ptr,*line_term_ptr; + const char *line_start_ptr,*line_start_end; uint field_term_length,line_term_length,enclosed_length; int field_term_char,line_term_char,enclosed_char,escape_char; int *stack,*stack_pos; @@ -88,7 +92,7 @@ public: int read_fixed_length(void); int next_line(void); char unescape(char chr); - int terminator(char *ptr,uint length); + int terminator(const uchar *ptr, uint length); bool find_start_of_fields(); /* load xml */ List<XML_TAG> taglist; @@ -114,6 +118,15 @@ public: either the table or THD value */ void set_io_cache_arg(void* arg) { cache.arg = arg; } + + /** + skip all data till the eof. + */ + void skip_data_till_eof() + { + while (GET != my_b_EOF) + ; + } }; static int read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, @@ -531,8 +544,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, if (error) { if (read_file_from_client) - while (!read_info.next_line()) - ; + read_info.skip_data_till_eof(); #ifndef EMBEDDED_LIBRARY if (mysql_bin_log.is_open()) @@ -1337,10 +1349,18 @@ READ_INFO::READ_INFO(File file_par, uint tot_length, CHARSET_INFO *cs, found_end_of_line(false), eof(false), need_end_io_cache(false), error(false), line_cuted(false), found_null(false), read_charset(cs) { - field_term_ptr=(char*) field_term.ptr(); + /* + Field and line terminators must be interpreted as sequence of unsigned char. + Otherwise, non-ascii terminators will be negative on some platforms, + and positive on others (depending on the implementation of char). + */ + field_term_ptr= + static_cast<const uchar*>(static_cast<const void*>(field_term.ptr())); field_term_length= field_term.length(); - line_term_ptr=(char*) line_term.ptr(); + line_term_ptr= + static_cast<const uchar*>(static_cast<const void*>(line_term.ptr())); line_term_length= line_term.length(); + level= 0; /* for load xml */ if (line_start.length() == 0) { @@ -1349,7 +1369,7 @@ READ_INFO::READ_INFO(File file_par, uint tot_length, CHARSET_INFO *cs, } else { - line_start_ptr=(char*) line_start.ptr(); + line_start_ptr= line_start.ptr(); line_start_end=line_start_ptr+line_start.length(); start_of_line= 1; } @@ -1358,12 +1378,12 @@ READ_INFO::READ_INFO(File file_par, uint tot_length, CHARSET_INFO *cs, !memcmp(field_term_ptr,line_term_ptr,field_term_length)) { line_term_length=0; - line_term_ptr=(char*) ""; + line_term_ptr= NULL; } enclosed_char= (enclosed_length=enclosed_par.length()) ? (uchar) enclosed_par[0] : INT_MAX; - field_term_char= field_term_length ? (uchar) field_term_ptr[0] : INT_MAX; - line_term_char= line_term_length ? (uchar) line_term_ptr[0] : INT_MAX; + field_term_char= field_term_length ? field_term_ptr[0] : INT_MAX; + line_term_char= line_term_length ? line_term_ptr[0] : INT_MAX; /* Set of a stack for unget if long terminators */ uint length= MY_MAX(cs->mbmaxlen, MY_MAX(field_term_length, line_term_length)) + 1; @@ -1418,11 +1438,7 @@ READ_INFO::~READ_INFO() } -#define GET (stack_pos != stack ? *--stack_pos : my_b_get(&cache)) -#define PUSH(A) *(stack_pos++)=(A) - - -inline int READ_INFO::terminator(char *ptr,uint length) +inline int READ_INFO::terminator(const uchar *ptr,uint length) { int chr=0; // Keep gcc happy uint i; @@ -1437,7 +1453,7 @@ inline int READ_INFO::terminator(char *ptr,uint length) return 1; PUSH(chr); while (i-- > 1) - PUSH((uchar) *--ptr); + PUSH(*--ptr); return 0; } @@ -1569,7 +1585,7 @@ int READ_INFO::read_field() if (my_mbcharlen(read_charset, chr) > 1 && to + my_mbcharlen(read_charset, chr) <= end_of_buff) { - uchar* p= (uchar*) to; + uchar* p= to; int ml, i; *to++ = chr; @@ -1594,7 +1610,7 @@ int READ_INFO::read_field() (const char *)to)) continue; for (i= 0; i < ml; i++) - PUSH((uchar) *--to); + PUSH(*--to); chr= GET; } #endif @@ -1743,7 +1759,7 @@ bool READ_INFO::find_start_of_fields() return 1; } } while ((char) chr != line_start_ptr[0]); - for (char *ptr=line_start_ptr+1 ; ptr != line_start_end ; ptr++) + for (const char *ptr=line_start_ptr+1 ; ptr != line_start_end ; ptr++) { chr=GET; // Eof will be checked later if ((char) chr != *ptr) @@ -1751,7 +1767,7 @@ bool READ_INFO::find_start_of_fields() PUSH(chr); while (--ptr != line_start_ptr) { // Restart with next char - PUSH((uchar) *ptr); + PUSH( *ptr); } goto try_again; } @@ -1947,7 +1963,7 @@ int READ_INFO::read_xml() // row tag should be in ROWS IDENTIFIED BY '<row>' - stored in line_term if((tag.length() == line_term_length -2) && - (strncmp(tag.c_ptr_safe(), line_term_ptr + 1, tag.length()) == 0)) + (memcmp(tag.ptr(), line_term_ptr + 1, tag.length()) == 0)) { DBUG_PRINT("read_xml", ("start-of-row: %i %s %s", level,tag.c_ptr_safe(), line_term_ptr)); @@ -2009,7 +2025,7 @@ int READ_INFO::read_xml() } if((tag.length() == line_term_length -2) && - (strncmp(tag.c_ptr_safe(), line_term_ptr + 1, tag.length()) == 0)) + (memcmp(tag.ptr(), line_term_ptr + 1, tag.length()) == 0)) { DBUG_PRINT("read_xml", ("found end-of-row %i %s", level, tag.c_ptr_safe())); |