mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 05:22:25 +01:00
a07e48eca0
Added more DBUG statements Ensure that we are comparing end space with BINARY strings Use 'any_db' instead of '' to mean any database. (For HANDLER command) Only strip ' ' when comparing CHAR, not other space-like characters (like \t) BitKeeper/deleted/.del-ctype_tis620.result-old~3578ceb0b8284685: Delete: mysql-test/r/ctype_tis620.result-old BitKeeper/deleted/.del-ctype_tis620.test-old~ffb1bbd2935d1aba: Delete: mysql-test/t/ctype_tis620.test-old client/mysqlbinlog.cc: Added DBUG statements Added call of my_end() to free all used memory on exit heap/hp_info.c: After merge fixes heap/hp_open.c: After merge fixes include/heap.h: After merge fixes include/m_ctype.h: Use pchar instead of 'int' for character parameters. Added 'my_binary_compare()' include/m_string.h: Fixed wrong define innobase/ibuf/ibuf0ibuf.c: After merge fixes innobase/srv/srv0start.c: After merge fixes mysql-test/r/alter_table.result: Fixed results after merge mysql-test/r/auto_increment.result: Fixed results after merge mysql-test/r/bdb.result: Fixed results after merge mysql-test/r/binary.result: Fixed results after merge mysql-test/r/create.result: Fixed results after merge mysql-test/r/ctype_mb.result: Fixed results after merge mysql-test/r/ctype_tis620.result: Fixed results after merge mysql-test/r/ctype_utf8.result: Fixed results after merge mysql-test/r/delete.result: Fixed results after merge mysql-test/r/func_compress.result: Fixed results after merge mysql-test/r/func_gconcat.result: Fixed results after merge mysql-test/r/func_group.result: Fixed results after merge mysql-test/r/func_str.result: Fixed results after merge mysql-test/r/innodb.result: Fixed results after merge mysql-test/r/insert.result: Fixed results after merge mysql-test/r/insert_select.result: Fixed results after merge mysql-test/r/key.result: Fixed results after merge mysql-test/r/loaddata.result: Fixed results after merge mysql-test/r/lock.result: Fixed results after merge mysql-test/r/myisam.result: Fixed results after merge mysql-test/r/null.result: Fixed results after merge mysql-test/r/null_key.result: Fixed results after merge mysql-test/r/order_by.result: Fixed results after merge mysql-test/r/query_cache.result: Fixed results after merge mysql-test/r/range.result: Fixed results after merge mysql-test/r/rpl_multi_delete.result: Fixed results after merge mysql-test/r/rpl_until.result: Fixed results after merge mysql-test/r/subselect.result: Fixed results after merge mysql-test/r/subselect_innodb.result: Fixed results after merge mysql-test/r/type_blob.result: Fixed results after merge mysql-test/r/type_datetime.result: Fixed results after merge mysql-test/r/type_decimal.result: Fixed results after merge mysql-test/r/type_enum.result: Fixed results after merge mysql-test/r/type_float.result: Fixed results after merge mysql-test/r/type_ranges.result: Fixed results after merge mysql-test/r/type_time.result: Fixed results after merge mysql-test/r/type_timestamp.result: Fixed results after merge mysql-test/r/type_uint.result: Fixed results after merge mysql-test/r/type_year.result: Fixed results after merge mysql-test/r/variables.result: Fixed results after merge mysql-test/r/warnings.result: Fixed results after merge mysql-test/t/case.test: Fixed shifted error messages mysql-test/t/create.test: Fixed shifted error messages mysql-test/t/ctype_collate.test: Fixed shifted error messages mysql-test/t/ctype_tis620.test: Merge with 4.0 ctype_tis620 test mysql-test/t/delete.test: Fixed shifted error messages mysql-test/t/derived.test: Fixed shifted error messages mysql-test/t/fulltext.test: Fixed shifted error messages mysql-test/t/func_in.test: Fixed shifted error messages mysql-test/t/func_str.test: Fixed shifted error messages mysql-test/t/func_test.test: Fixed shifted error messages mysql-test/t/grant.test: Fixed shifted error messages mysql-test/t/innodb.test: Change to 4.1 syntax mysql-test/t/key_cache.test: Fixed shifted error messages mysql-test/t/myisam.test: New test of blob and end space mysql-test/t/row.test: Fixed shifted error messages mysql-test/t/rpl_until.test: Fixed shifted error messages mysql-test/t/subselect.test: Fixed shifted error messages mysql-test/t/subselect_innodb.test: Fix test to take into account foreign key constraints mysql-test/t/union.test: Fixed shifted error messages mysql-test/t/user_var.test: Fixed shifted error messages mysql-test/t/variables.test: Fixed shifted error messages mysys/my_handler.c: Merge with 4.0 code sql/ha_heap.cc: After merge fixes sql/handler.cc: After merge fixes sql/item.cc: After merge fixes sql/item_cmpfunc.cc: Ensure that we are comparing end space with BINARY strings sql/item_cmpfunc.h: Ensure that we are comparing end space with BINARY strings sql/log_event.cc: More DBUG statements Ensure that we use all options to LOAD DATA in replication sql/opt_range.cc: After merge fixes sql/sql_db.cc: After merge fixes sql/sql_handler.cc: After merge fixes Use 'any_db' instead of '' to mean 'no database comparison' sql/sql_parse.cc: After merge fixes sql/sql_select.cc: After merge fixes Added function comment for setup_group() sql/sql_string.cc: Added stringcmp() for binary comparison. Added function comments for sortcmp() and stringcmp() sql/sql_string.h: Added stringcmp() sql/sql_table.cc: After merge fixes sql/sql_update.cc: After merge fixes sql/sql_yacc.yy: Use 'any_db' instead of '' to mean any database. Using "" causes a 'wrong db name' error. strings/ctype-big5.c: Strip only end space, not other space characters. strings/ctype-bin.c: Removed some not needed functions. Added function comments Don't remove end space in comparisons Change my_wildcmp_bin() to be 'identical' with other similar code strings/ctype-czech.c: Strip only end space, not other space characters. strings/ctype-gbk.c: Strip only end space, not other space characters. strings/ctype-latin1.c: Strip only end space, not other space characters. strings/ctype-mb.c: Strip only end space, not other space characters. strings/ctype-simple.c: Strip only end space, not other space characters. strings/ctype-sjis.c: Strip only end space, not other space characters. strings/ctype-tis620.c: Added usage of my_instr_simple. This needs to be cleaned up! strings/ctype-utf8.c: Strip only end space, not other space characters. strings/ctype-win1250ch.c: Strip only end space, not other space characters. Fixed indentation strings/strto.c: Code cleanup
300 lines
8.8 KiB
C++
300 lines
8.8 KiB
C++
/* 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 */
|
|
|
|
/* This file is originally from the mysql distribution. Coded by monty */
|
|
|
|
#ifdef __GNUC__
|
|
#pragma interface /* gcc class implementation */
|
|
#endif
|
|
|
|
#ifndef NOT_FIXED_DEC
|
|
#define NOT_FIXED_DEC 31
|
|
#endif
|
|
|
|
class String;
|
|
int sortcmp(const String *a,const String *b, CHARSET_INFO *cs);
|
|
String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);
|
|
uint32 copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs,
|
|
const char *from, uint32 from_length,
|
|
CHARSET_INFO *from_cs);
|
|
|
|
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;
|
|
str_charset= &my_charset_bin;
|
|
}
|
|
String(uint32 length_arg)
|
|
{
|
|
alloced=0; Alloced_length=0; (void) real_alloc(length_arg);
|
|
str_charset= &my_charset_bin;
|
|
}
|
|
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;
|
|
str_charset=str.str_charset;
|
|
}
|
|
static void *operator new(size_t size)
|
|
{ return (void*) sql_alloc((uint) size); }
|
|
static void *operator new(size_t size, MEM_ROOT *mem_root)
|
|
{ return (void*) alloc_root(mem_root, (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]; }
|
|
inline void length(uint32 len) { str_length=len ; }
|
|
inline bool is_empty() { return (str_length == 0); }
|
|
inline const char *ptr() const { return Ptr; }
|
|
inline char *c_ptr()
|
|
{
|
|
if (!Ptr || Ptr[str_length]) /* Should be safe */
|
|
(void) realloc(str_length);
|
|
return Ptr;
|
|
}
|
|
inline char *c_ptr_quick()
|
|
{
|
|
if (Ptr && str_length < Alloced_length)
|
|
Ptr[str_length]=0;
|
|
return Ptr;
|
|
}
|
|
|
|
void set(String &str,uint32 offset,uint32 arg_length)
|
|
{
|
|
free();
|
|
Ptr=(char*) str.ptr()+offset; str_length=arg_length; alloced=0;
|
|
if (str.Alloced_length)
|
|
Alloced_length=str.Alloced_length-offset;
|
|
else
|
|
Alloced_length=0;
|
|
str_charset=str.str_charset;
|
|
}
|
|
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, CHARSET_INFO *cs)
|
|
{
|
|
free();
|
|
Ptr=(char*) str; str_length=arg_length; Alloced_length=0 ; alloced=0;
|
|
str_charset=cs;
|
|
}
|
|
bool set_ascii(const 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, CHARSET_INFO *cs);
|
|
bool set(ulonglong num, CHARSET_INFO *cs);
|
|
bool set(double num,uint decimals, CHARSET_INFO *cs);
|
|
inline void free()
|
|
{
|
|
if (alloced)
|
|
{
|
|
alloced=0;
|
|
Alloced_length=0;
|
|
my_free(Ptr,MYF(0));
|
|
Ptr=0;
|
|
str_length=0; /* Safety */
|
|
}
|
|
}
|
|
inline bool alloc(uint32 arg_length)
|
|
{
|
|
if (arg_length < Alloced_length)
|
|
return 0;
|
|
return real_alloc(arg_length);
|
|
}
|
|
bool real_alloc(uint32 arg_length); // Empties old string
|
|
bool realloc(uint32 arg_length);
|
|
inline void shrink(uint32 arg_length) // Shrink buffer
|
|
{
|
|
if (arg_length < Alloced_length)
|
|
{
|
|
char *new_ptr;
|
|
if (!(new_ptr=(char*) my_realloc(Ptr,arg_length,MYF(0))))
|
|
{
|
|
Alloced_length = 0;
|
|
real_alloc(arg_length);
|
|
}
|
|
else
|
|
{
|
|
Ptr=new_ptr;
|
|
Alloced_length=arg_length;
|
|
}
|
|
}
|
|
}
|
|
bool is_alloced() { return alloced; }
|
|
inline String& operator = (const String &s)
|
|
{
|
|
if (&s != this)
|
|
{
|
|
free();
|
|
Ptr=s.Ptr ; str_length=s.str_length ; Alloced_length=s.Alloced_length;
|
|
alloced=0;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
bool copy(); // Alloc string if not alloced
|
|
bool copy(const String &s); // Allocate new string
|
|
bool copy(const char *s,uint32 arg_length, CHARSET_INFO *cs); // Allocate new string
|
|
static bool needs_conversion(uint32 arg_length,
|
|
CHARSET_INFO *cs_from, CHARSET_INFO *cs_to,
|
|
uint32 *offset);
|
|
bool copy_aligned(const char *s, uint32 arg_length, uint32 offset,
|
|
CHARSET_INFO *cs);
|
|
bool set_or_copy_aligned(const char *s, uint32 arg_length, CHARSET_INFO *cs);
|
|
bool copy(const char*s,uint32 arg_length, CHARSET_INFO *csfrom,
|
|
CHARSET_INFO *csto);
|
|
bool append(const String &s);
|
|
bool append(const char *s,uint32 arg_length=0);
|
|
bool append(const char *s,uint32 arg_length, CHARSET_INFO *cs);
|
|
bool append(IO_CACHE* file, uint32 arg_length);
|
|
bool append_with_prefill(const char *s, uint32 arg_length,
|
|
uint32 full_length, char fill_char);
|
|
int strstr(const String &search,uint32 offset=0); // Returns offset to substring or -1
|
|
int strstr_case(const String &s,uint32 offset=0);
|
|
int strrstr(const String &search,uint32 offset=0); // Returns offset to substring or -1
|
|
bool replace(uint32 offset,uint32 arg_length,const char *to,uint32 length);
|
|
bool replace(uint32 offset,uint32 arg_length,const String &to);
|
|
inline bool append(char chr)
|
|
{
|
|
if (str_length < Alloced_length)
|
|
{
|
|
Ptr[str_length++]=chr;
|
|
}
|
|
else
|
|
{
|
|
if (realloc(str_length+1))
|
|
return 1;
|
|
Ptr[str_length++]=chr;
|
|
}
|
|
return 0;
|
|
}
|
|
bool fill(uint32 max_length,char fill);
|
|
void strip_sp();
|
|
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, CHARSET_INFO *cs);
|
|
friend int stringcmp(const String *a,const String *b);
|
|
friend String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);
|
|
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);
|
|
|
|
/* Inline (general) functions used by the protocol functions */
|
|
|
|
inline char *prep_append(uint32 arg_length, uint32 step_alloc)
|
|
{
|
|
uint32 new_length= arg_length + str_length;
|
|
if (new_length > Alloced_length)
|
|
{
|
|
if (realloc(new_length + step_alloc))
|
|
return 0;
|
|
}
|
|
uint32 old_length= str_length;
|
|
str_length+= arg_length;
|
|
return Ptr+ old_length; /* Area to use */
|
|
}
|
|
|
|
inline bool append(const char *s, uint32 arg_length, uint32 step_alloc)
|
|
{
|
|
uint32 new_length= arg_length + str_length;
|
|
if (new_length > Alloced_length && realloc(new_length + step_alloc))
|
|
return TRUE;
|
|
memcpy(Ptr+str_length, s, arg_length);
|
|
str_length+= arg_length;
|
|
return FALSE;
|
|
}
|
|
void print(String *print);
|
|
};
|