mirror of
https://github.com/MariaDB/server.git
synced 2025-01-30 10:31:54 +01:00
10e22c346a
Some changes to the prepared statement protocol to make it easier to use and faster. Makefile.am: Fix to make dist to work with cmd-line-utils client/mysql.cc: Portability fixes client/mysqlbinlog.cc: Portabiliy fixes and remove usafe of FILE configure.in: Fix to make dist to work with cmd-line-utils heap/_check.c: Portability fixes include/config-win.h: Portability fixes include/m_ctype.h: Indentation cleanup include/my_list.h: Portability fixes include/mysql.h: Cleanup of BIND structure include/violite.h: Portability fixes innobase/dict/dict0dict.c: Portability fixes innobase/dict/dict0load.c: Portability fixes innobase/include/os0proc.h: Portability fixes (Heikki, please check) innobase/os/os0proc.c: Portability fixes (Heikki, please check) innobase/ut/ut0ut.c: Portability fixes isam/pack_isam.c: Portability fixes libmysql/libmysql.c: Portability fixes Remove obscure usage of the length parameter for prepared statements. libmysql/libmysql.def: Remove not existing functions libmysqld/lib_sql.cc: Remove compiler warning mysql-test/r/explain.result: Fix after merge mysql-test/r/join.result: Fix after merge mysys/my_once.c: Portability fix mysys/tree.c: Portability fixes sql/field.cc: Portability fixes sql/filesort.cc: move assert.h to mysql_priv.h sql/ha_berkeley.cc: move assert.h to mysql_priv.h sql/ha_innodb.cc: move assert.h to mysql_priv.h sql/item.cc: move assert.h to mysql_priv.h Fixed syntax error sql/item_cmpfunc.cc: move assert.h to mysql_priv.h sql/item_func.cc: move assert.h to mysql_priv.h sql/item_row.cc: move assert.h to mysql_priv.h sql/item_strfunc.cc: Portability fix sql/item_subselect.cc: Portability fix sql/item_sum.cc: move assert.h to mysql_priv.h sql/lex.h: Portability fix sql/lock.cc: move assert.h to mysql_priv.h sql/log.cc: move assert.h to mysql_priv.h sql/log_event.cc: Portability fix sql/mf_iocache.cc: move assert.h to mysql_priv.h sql/mysql_priv.h: move assert.h to mysql_priv.h sql/mysqld.cc: move assert.h to mysql_priv.h sql/opt_range.cc: move assert.h to mysql_priv.h sql/password.c: Portability fix sql/protocol.cc: move assert.h to mysql_priv.h sql/set_var.cc: Portability fix sql/slave.cc: move assert.h to mysql_priv.h sql/spatial.cc: Portability fix sql/sql_acl.cc: move assert.h to mysql_priv.h sql/sql_base.cc: move assert.h to mysql_priv.h sql/sql_cache.cc: move assert.h to mysql_priv.h sql/sql_class.cc: move assert.h to mysql_priv.h sql/sql_handler.cc: move assert.h to mysql_priv.h sql/sql_help.cc: Removed compiler warning sql/sql_lex.cc: Portability fix sql/sql_lex.h: Portability fix sql/sql_parse.cc: move assert.h to mysql_priv.h sql/sql_prepare.cc: move assert.h to mysql_priv.h sql/sql_repl.cc: move assert.h to mysql_priv.h sql/sql_select.cc: move assert.h to mysql_priv.h sql/sql_string.cc: Portability fix sql/sql_string.h: Portability fix sql/sql_table.cc: move assert.h to mysql_priv.h sql/sql_yacc.yy: Portability fix Remove not accessed code strings/ctype-bin.c: Portability fix strings/ctype-mb.c: Portability fix strings/ctype.c: Portability fix tests/client_test.c: A
280 lines
6.2 KiB
C
280 lines
6.2 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 */
|
|
|
|
#include <my_global.h>
|
|
#include "m_ctype.h"
|
|
#include "m_string.h"
|
|
|
|
#ifdef USE_MB
|
|
|
|
|
|
void my_caseup_str_mb(CHARSET_INFO * cs, char *str)
|
|
{
|
|
register uint32 l;
|
|
register char *end=str+strlen(str); /* BAR TODO: remove strlen() call */
|
|
register uchar *map=cs->to_upper;
|
|
|
|
while (*str)
|
|
{
|
|
if ((l=my_ismbchar(cs, str,end)))
|
|
str+=l;
|
|
else
|
|
{
|
|
*str=(char) map[(uchar)*str];
|
|
str++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void my_casedn_str_mb(CHARSET_INFO * cs, char *str)
|
|
{
|
|
register uint32 l;
|
|
register char *end=str+strlen(str);
|
|
register uchar *map=cs->to_lower;
|
|
|
|
while (*str)
|
|
{
|
|
if ((l=my_ismbchar(cs, str,end)))
|
|
str+=l;
|
|
else
|
|
{
|
|
*str=(char) map[(uchar)*str];
|
|
str++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void my_caseup_mb(CHARSET_INFO * cs, char *str, uint length)
|
|
{
|
|
register uint32 l;
|
|
register char *end=str+length;
|
|
register uchar *map=cs->to_upper;
|
|
|
|
while (str<end)
|
|
{
|
|
if ((l=my_ismbchar(cs, str,end)))
|
|
str+=l;
|
|
else
|
|
{
|
|
*str=(char) map[(uchar)*str];
|
|
str++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void my_casedn_mb(CHARSET_INFO * cs, char *str, uint length)
|
|
{
|
|
register uint32 l;
|
|
register char *end=str+length;
|
|
register uchar *map=cs->to_lower;
|
|
|
|
while (str<end)
|
|
{
|
|
if ((l=my_ismbchar(cs, str,end)))
|
|
str+=l;
|
|
else
|
|
{
|
|
*str=(char) map[(uchar)*str];
|
|
str++;
|
|
}
|
|
}
|
|
}
|
|
|
|
int my_strcasecmp_mb(CHARSET_INFO * cs,const char *s, const char *t)
|
|
{
|
|
register uint32 l;
|
|
register const char *end=s+strlen(s);
|
|
register uchar *map=cs->to_upper;
|
|
|
|
while (s<end)
|
|
{
|
|
if ((l=my_ismbchar(cs, s,end)))
|
|
{
|
|
while (l--)
|
|
if (*s++ != *t++)
|
|
return 1;
|
|
}
|
|
else if (my_ismbhead(cs, *t))
|
|
return 1;
|
|
else if (map[(uchar) *s++] != map[(uchar) *t++])
|
|
return 1;
|
|
}
|
|
return *t;
|
|
}
|
|
|
|
|
|
int my_strncasecmp_mb(CHARSET_INFO * cs,
|
|
const char *s, const char *t, uint len)
|
|
{
|
|
register uint32 l;
|
|
register const char *end=s+len;
|
|
register uchar *map=cs->to_upper;
|
|
|
|
while (s<end)
|
|
{
|
|
if ((l=my_ismbchar(cs, s,end)))
|
|
{
|
|
while (l--)
|
|
if (*s++ != *t++)
|
|
return 1;
|
|
}
|
|
else if (my_ismbhead(cs, *t))
|
|
return 1;
|
|
else if (map[(uchar) *s++] != map[(uchar) *t++])
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
/*
|
|
** Compare string against string with wildcard
|
|
** 0 if matched
|
|
** -1 if not matched with wildcard
|
|
** 1 if matched with wildcard
|
|
*/
|
|
|
|
#define INC_PTR(cs,A,B) A+=((use_mb_flag && \
|
|
my_ismbchar(cs,A,B)) ? my_ismbchar(cs,A,B) : 1)
|
|
|
|
#ifdef LIKE_CMP_TOUPPER
|
|
#define likeconv(s,A) (uchar) my_toupper(s,A)
|
|
#else
|
|
#define likeconv(s,A) (uchar) (s)->sort_order[(uchar) (A)]
|
|
#endif
|
|
|
|
int my_wildcmp_mb(CHARSET_INFO *cs,
|
|
const char *str,const char *str_end,
|
|
const char *wildstr,const char *wildend,
|
|
int escape, int w_one, int w_many)
|
|
{
|
|
int result= -1; // Not found, using wildcards
|
|
|
|
bool use_mb_flag=use_mb(cs);
|
|
|
|
while (wildstr != wildend)
|
|
{
|
|
while (*wildstr != w_many && *wildstr != w_one)
|
|
{
|
|
int l;
|
|
if (*wildstr == escape && wildstr+1 != wildend)
|
|
wildstr++;
|
|
if (use_mb_flag &&
|
|
(l = my_ismbchar(cs, wildstr, wildend)))
|
|
{
|
|
if (str+l > str_end || memcmp(str, wildstr, l) != 0)
|
|
return 1;
|
|
str += l;
|
|
wildstr += l;
|
|
}
|
|
else
|
|
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
|
|
result=1; // Found an anchor char
|
|
}
|
|
if (*wildstr == w_one)
|
|
{
|
|
do
|
|
{
|
|
if (str == str_end) // Skip one char if possible
|
|
return (result);
|
|
INC_PTR(cs,str,str_end);
|
|
} while (++wildstr < wildend && *wildstr == w_one);
|
|
if (wildstr == wildend)
|
|
break;
|
|
}
|
|
if (*wildstr == w_many)
|
|
{ // Found w_many
|
|
uchar cmp;
|
|
const char* mb = wildstr;
|
|
int mblen=0;
|
|
|
|
wildstr++;
|
|
/* Remove any '%' and '_' from the wild search string */
|
|
for (; wildstr != wildend ; wildstr++)
|
|
{
|
|
if (*wildstr == w_many)
|
|
continue;
|
|
if (*wildstr == w_one)
|
|
{
|
|
if (str == str_end)
|
|
return (-1);
|
|
INC_PTR(cs,str,str_end);
|
|
continue;
|
|
}
|
|
break; // Not a wild character
|
|
}
|
|
if (wildstr == wildend)
|
|
return(0); // Ok if w_many is last
|
|
if (str == str_end)
|
|
return -1;
|
|
|
|
if ((cmp= *wildstr) == escape && wildstr+1 != wildend)
|
|
cmp= *++wildstr;
|
|
|
|
mb=wildstr;
|
|
LINT_INIT(mblen);
|
|
if (use_mb_flag)
|
|
mblen = my_ismbchar(cs, wildstr, wildend);
|
|
INC_PTR(cs,wildstr,wildend); // This is compared trough cmp
|
|
cmp=likeconv(cs,cmp);
|
|
do
|
|
{
|
|
if (use_mb_flag)
|
|
{
|
|
for (;;)
|
|
{
|
|
if (str >= str_end)
|
|
return -1;
|
|
if (mblen)
|
|
{
|
|
if (str+mblen <= str_end && memcmp(str, mb, mblen) == 0)
|
|
{
|
|
str += mblen;
|
|
break;
|
|
}
|
|
}
|
|
else if (!my_ismbchar(cs, str, str_end) &&
|
|
likeconv(cs,*str) == cmp)
|
|
{
|
|
str++;
|
|
break;
|
|
}
|
|
INC_PTR(cs,str, str_end);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
while (str != str_end && likeconv(cs,*str) != cmp)
|
|
str++;
|
|
if (str++ == str_end) return (-1);
|
|
}
|
|
{
|
|
int tmp=my_wildcmp_mb(cs,str,str_end,wildstr,wildend,escape,w_one,w_many);
|
|
if (tmp <= 0)
|
|
return (tmp);
|
|
}
|
|
} while (str != str_end && wildstr[0] != w_many);
|
|
return(-1);
|
|
}
|
|
}
|
|
return (str != str_end ? 1 : 0);
|
|
}
|
|
|
|
|
|
#endif
|