Review of all code pushed since last review

Simple optimzations and cleanups
Removed compiler warnings and fixed portability issues
Added client functions 'mysql_embedded()' to allow client to check if we are using embedded server
Fixes for purify
This commit is contained in:
monty@mishka.local 2004-10-20 01:28:42 +03:00
parent 57a85986ac
commit 04c23808a8
28 changed files with 191 additions and 134 deletions

View File

@ -264,7 +264,6 @@ static int write_to_table(char *filename, MYSQL *sock)
{ {
char tablename[FN_REFLEN], hard_path[FN_REFLEN], char tablename[FN_REFLEN], hard_path[FN_REFLEN],
sql_statement[FN_REFLEN*16+256], *end; sql_statement[FN_REFLEN*16+256], *end;
my_bool local_file;
DBUG_ENTER("write_to_table"); DBUG_ENTER("write_to_table");
DBUG_PRINT("enter",("filename: %s",filename)); DBUG_PRINT("enter",("filename: %s",filename));

View File

@ -58,13 +58,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <violite.h> #include <violite.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifndef MAXPATHLEN
#define MAXPATHLEN 256
#endif
#define MAX_QUERY 131072 #define MAX_QUERY 131072
#define MAX_VAR_NAME 256 #define MAX_VAR_NAME 256
@ -2105,10 +2098,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
embedded_server_arg_count=1; embedded_server_arg_count=1;
embedded_server_args[0]= (char*) ""; embedded_server_args[0]= (char*) "";
} }
embedded_server_args[embedded_server_arg_count++]= if (embedded_server_arg_count == MAX_SERVER_ARGS-1 ||
my_strdup(argument, MYF(MY_FAE)); !(embedded_server_args[embedded_server_arg_count++]=
if (embedded_server_arg_count == MAX_SERVER_ARGS || my_strdup(argument, MYF(MY_FAE))))
!embedded_server_args[embedded_server_arg_count-1])
{ {
die("Can't use server argument"); die("Can't use server argument");
} }
@ -2166,7 +2158,7 @@ char* safe_str_append(char* buf, const char* str, int size)
void str_to_file(const char* fname, char* str, int size) void str_to_file(const char* fname, char* str, int size)
{ {
int fd; int fd;
char buff[MAXPATHLEN]; char buff[FN_REFLEN];
if (!test_if_hard_path(fname)) if (!test_if_hard_path(fname))
{ {
strxmov(buff, opt_basedir, fname, NullS); strxmov(buff, opt_basedir, fname, NullS);
@ -2979,10 +2971,10 @@ static void timer_output(void)
{ {
if (timer_file) if (timer_file)
{ {
char buf[1024]; char buf[32], *end;
ulonglong timer= timer_now() - timer_start; ulonglong timer= timer_now() - timer_start;
sprintf(buf,"%llu",timer); end= longlong2str(timer, buf, 10);
str_to_file(timer_file,buf,strlen(buf)); str_to_file(timer_file,buf, (int) (end-buf));
} }
} }

View File

@ -506,6 +506,7 @@ char * STDCALL mysql_odbc_escape_string(MYSQL *mysql,
unsigned long *length)); unsigned long *length));
void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name); void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
unsigned int STDCALL mysql_thread_safe(void); unsigned int STDCALL mysql_thread_safe(void);
my_bool STDCALL mysql_embedded(void);
MYSQL_MANAGER* STDCALL mysql_manager_init(MYSQL_MANAGER* con); MYSQL_MANAGER* STDCALL mysql_manager_init(MYSQL_MANAGER* con);
MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con, MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con,
const char* host, const char* host,

View File

@ -95,6 +95,19 @@ static char* srv_monitor_file_name;
#define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD #define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD
#define SRV_MAX_N_PENDING_SYNC_IOS 100 #define SRV_MAX_N_PENDING_SYNC_IOS 100
/* Avoid warnings when using purify */
#ifdef HAVE_purify
static int inno_bcmp(register const char *s1, register const char *s2,
register uint len)
{
while (len-- != 0 && *s1++ == *s2++) ;
return len+1;
}
#define memcmp(A,B,C) inno_bcmp((A),(B),(C))
#endif
/************************************************************************* /*************************************************************************
Reads the data files and their sizes from a character string given in Reads the data files and their sizes from a character string given in
the .cnf file. */ the .cnf file. */

View File

@ -1516,6 +1516,16 @@ uint STDCALL mysql_thread_safe(void)
#endif #endif
} }
my_bool STDCALL mysql_embedded(void)
{
#ifdef EMBEDDED_LIBRARY
return 1;
#else
return 0;
#endif
}
/**************************************************************************** /****************************************************************************
Some support functions Some support functions
****************************************************************************/ ****************************************************************************/

View File

@ -144,3 +144,4 @@ EXPORTS
mysql_rpl_probe mysql_rpl_probe
mysql_rpl_query_type mysql_rpl_query_type
mysql_slave_query mysql_slave_query
mysql_embedded

View File

@ -68,7 +68,7 @@ int main(int argc,char *argv[])
struct { MI_INFO *info; } aio0, *aio=&aio0; /* for GWS_IN_USE */ struct { MI_INFO *info; } aio0, *aio=&aio0; /* for GWS_IN_USE */
MY_INIT(argv[0]); MY_INIT(argv[0]);
if (error=handle_options(&argc, &argv, my_long_options, get_one_option)) if ((error= handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(error); exit(error);
if (count || dump) if (count || dump)
verbose=0; verbose=0;

View File

@ -1695,7 +1695,7 @@ err:
static my_bool not_killed= 0; static my_bool not_killed= 0;
volatile my_bool *killed_ptr(MI_CHECK *param) volatile my_bool *killed_ptr(MI_CHECK *param __attribute__((unused)))
{ {
return &not_killed; /* always NULL */ return &not_killed; /* always NULL */
} }

View File

@ -425,6 +425,7 @@ static void create_record1(char *record,uint rownr)
} }
} }
#ifdef NOT_USED
static void create_record0(char *record,uint rownr) static void create_record0(char *record,uint rownr)
{ {
@ -447,6 +448,8 @@ static void create_record0(char *record,uint rownr)
} }
} }
#endif
static void create_record(char *record,uint rownr) static void create_record(char *record,uint rownr)
{ {
int i; int i;

View File

@ -83,7 +83,7 @@ _hash_init(HASH *hash,CHARSET_INFO *charset,
Sets records to 0 Sets records to 0
*/ */
static void inline hash_free_elements(HASH *hash) static inline void hash_free_elements(HASH *hash)
{ {
if (hash->free) if (hash->free)
{ {

View File

@ -107,7 +107,7 @@ my_bool my_gethwaddr(uchar *to __attribute__((unused)))
} }
#endif #endif
#else MAIN #else /* MAIN */
int main(int argc __attribute__((unused)),char **argv) int main(int argc __attribute__((unused)),char **argv)
{ {
uchar mac[6]; uchar mac[6];

View File

@ -491,6 +491,7 @@ static
const const
int NbClassification = sizeof(StatusClassificationMapping)/sizeof(ErrorStatusClassification); int NbClassification = sizeof(StatusClassificationMapping)/sizeof(ErrorStatusClassification);
#ifdef NOT_USED
/** /**
* Complete all fields of an NdbError given the error code * Complete all fields of an NdbError given the error code
* and details * and details
@ -506,7 +507,7 @@ set(ndberror_struct * error, int code, const char * details, ...){
va_end(ap); va_end(ap);
} }
} }
#endif
void void
ndberror_update(ndberror_struct * error){ ndberror_update(ndberror_struct * error){

View File

@ -1183,6 +1183,7 @@ register cset *cs;
return(n); return(n);
} }
#ifdef USE_ORIG_REGEX_CODE
/* /*
- mcadd - add a collating element to a cset - mcadd - add a collating element to a cset
== static void mcadd(register struct parse *p, register cset *cs, \ == static void mcadd(register struct parse *p, register cset *cs, \
@ -1209,6 +1210,7 @@ register char *cp;
(void) strcpy(cs->multis + oldend - 1, cp); (void) strcpy(cs->multis + oldend - 1, cp);
cs->multis[cs->smultis - 1] = '\0'; cs->multis[cs->smultis - 1] = '\0';
} }
#endif
#ifdef NOT_USED #ifdef NOT_USED
/* /*

View File

@ -27,7 +27,9 @@ static void freeset(register struct parse *p, register cset *cs);
static int freezeset(register struct parse *p, register cset *cs); static int freezeset(register struct parse *p, register cset *cs);
static int firstch(register struct parse *p, register cset *cs); static int firstch(register struct parse *p, register cset *cs);
static int nch(register struct parse *p, register cset *cs); static int nch(register struct parse *p, register cset *cs);
#ifdef USE_ORIG_REGEX_CODE
static void mcadd(register struct parse *p, register cset *cs, register char *cp); static void mcadd(register struct parse *p, register cset *cs, register char *cp);
#endif
#ifdef NOT_USED #ifdef NOT_USED
static void mcsub(register cset *cs, register char *cp); static void mcsub(register cset *cs, register char *cp);
static int mcin(register cset *cs, register char *cp); static int mcin(register cset *cs, register char *cp);

View File

@ -2249,7 +2249,7 @@ static void mysql_close_free(MYSQL *mysql)
stmt_list pointer to mysql->stmts stmt_list pointer to mysql->stmts
*/ */
void mysql_detach_stmt_list(LIST **stmt_list) void mysql_detach_stmt_list(LIST **stmt_list __attribute__((unused)))
{ {
#ifdef MYSQL_CLIENT #ifdef MYSQL_CLIENT
/* Reset connection handle in all prepared statements. */ /* Reset connection handle in all prepared statements. */

View File

@ -304,14 +304,11 @@ bool Field::field_cast_compatible(Field::field_cast_enum type)
{ {
DBUG_ASSERT(type != FIELD_CAST_STOP); DBUG_ASSERT(type != FIELD_CAST_STOP);
Field::field_cast_enum *array= field_cast_array[field_cast_type()]; Field::field_cast_enum *array= field_cast_array[field_cast_type()];
uint i= 0; while (*array != FIELD_CAST_STOP)
Field::field_cast_enum tp;
do
{ {
tp= array[i++]; if (*(array++) == type)
if (tp == type)
return 1; return 1;
} while (tp != FIELD_CAST_STOP); }
return 0; return 0;
} }
@ -4438,13 +4435,9 @@ char *Field_string::pack(char *to, const char *from, uint max_length)
while (end > from && end[-1] == ' ') while (end > from && end[-1] == ' ')
end--; end--;
length= (end-from); length= (end-from);
if (field_length > 255)
{
int2store(to, length);
to+= 2;
}
else
*to++= (char) (uchar) length; *to++= (char) (uchar) length;
if (field_length > 255)
*to++= (char) (uchar) (length >> 8);
memcpy(to, from, (int) length); memcpy(to, from, (int) length);
return to+length; return to+length;
} }
@ -4459,13 +4452,9 @@ char *Field_string::pack_key(char *to, const char *from, uint max_length)
set_if_smaller(length, char_length); set_if_smaller(length, char_length);
while (length && from[length-1] == ' ') while (length && from[length-1] == ' ')
length--; length--;
if (field_length > 255)
{
int2store(to, length);
to+= 2;
}
else
*to++= (char) (uchar) length; *to++= (char) (uchar) length;
if (field_length > 255)
*to++= (char) (uchar) (length >> 8);
memcpy(to, from, length); memcpy(to, from, length);
return to+length; return to+length;
} }

View File

@ -855,7 +855,7 @@ innobase_init(void)
Note that when using the embedded server, the datadirectory is not Note that when using the embedded server, the datadirectory is not
necessarily the current directory of this program. */ necessarily the current directory of this program. */
if (mysql_embedded) { if (mysqld_embedded) {
default_path = mysql_real_data_home; default_path = mysql_real_data_home;
fil_path_to_mysql_datadir = mysql_real_data_home; fil_path_to_mysql_datadir = mysql_real_data_home;
} else { } else {
@ -993,7 +993,7 @@ innobase_init(void)
srv_max_n_open_files = (ulint) innobase_open_files; srv_max_n_open_files = (ulint) innobase_open_files;
srv_innodb_status = (ibool) innobase_create_status_file; srv_innodb_status = (ibool) innobase_create_status_file;
srv_print_verbose_log = mysql_embedded ? 0 : 1; srv_print_verbose_log = mysqld_embedded ? 0 : 1;
/* Store the default charset-collation number of this MySQL /* Store the default charset-collation number of this MySQL
installation */ installation */

View File

@ -1196,7 +1196,7 @@ bool Item_ref_null_helper::get_date(TIME *ltime, uint fuzzydate)
static void mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current, static void mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
Item_ident *item) Item_ident *item)
{ {
// store pointer on SELECT_LEX from wich item is dependent // store pointer on SELECT_LEX from which item is dependent
item->depended_from= last; item->depended_from= last;
current->mark_as_dependent(last); current->mark_as_dependent(last);
if (thd->lex->describe & DESCRIBE_EXTENDED) if (thd->lex->describe & DESCRIBE_EXTENDED)
@ -1872,10 +1872,11 @@ bool Item_field::send(Protocol *protocol, String *buffer)
return protocol->store(result_field); return protocol->store(result_field);
} }
/* /*
This is used for HAVING clause This is used for HAVING clause
Find field in select list having the same name Find field in select list having the same name
*/ */
bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
{ {
@ -1904,8 +1905,9 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
REPORT_ALL_ERRORS ), &not_used)) == REPORT_ALL_ERRORS ), &not_used)) ==
(Item **)not_found_item) (Item **)not_found_item)
{ {
upward_lookup= 1;
Field *tmp= (Field*) not_found_field; Field *tmp= (Field*) not_found_field;
SELECT_LEX *last= 0;
upward_lookup= 1;
/* /*
We can't find table field in select list of current select, We can't find table field in select list of current select,
consequently we have to find it in outer subselect(s). consequently we have to find it in outer subselect(s).
@ -1915,7 +1917,6 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
mention of table name, but if we join tables in one list it will mention of table name, but if we join tables in one list it will
cause error ER_NON_UNIQ_ERROR in find_item_in_list. cause error ER_NON_UNIQ_ERROR in find_item_in_list.
*/ */
SELECT_LEX *last=0;
for ( ; sl ; sl= (prev_unit= sl->master_unit())->outer_select()) for ( ; sl ; sl= (prev_unit= sl->master_unit())->outer_select())
{ {
last= sl; last= sl;
@ -1967,9 +1968,9 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
if (!ref) if (!ref)
return 1; return 1;
else if (!tmp) if (!tmp)
return -1; return -1;
else if (ref == (Item **)not_found_item && tmp == not_found_field) if (ref == (Item **)not_found_item && tmp == not_found_field)
{ {
if (upward_lookup) if (upward_lookup)
{ {
@ -1984,21 +1985,24 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
*(thd->lex->current_select->get_item_list()), *(thd->lex->current_select->get_item_list()),
&counter, REPORT_ALL_ERRORS, &not_used); &counter, REPORT_ALL_ERRORS, &not_used);
} }
ref= 0; ref= 0; // Safety
return 1; return 1;
} }
else if (tmp != not_found_field) if (tmp != not_found_field)
{ {
ref= 0; // To prevent "delete *ref;" on ~Item_ref() of this item Item_field* fld;
Item_field* fld= new Item_field(tmp); /*
if (!fld) Set ref to 0 as we are replacing this item with the found item
and this will ensure we get an error if this item would be
used elsewhere
*/
ref= 0; // Safety
if (!(fld= new Item_field(tmp)))
return 1; return 1;
thd->change_item_tree(reference, fld); thd->change_item_tree(reference, fld);
mark_as_dependent(thd, last, thd->lex->current_select, fld); mark_as_dependent(thd, last, thd->lex->current_select, fld);
return 0; return 0;
} }
else
{
if (!(*ref)->fixed) if (!(*ref)->fixed)
{ {
my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, my_error(ER_ILLEGAL_REFERENCE, MYF(0), name,
@ -2009,7 +2013,6 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
this); this);
ref= last->ref_pointer_array + counter; ref= last->ref_pointer_array + counter;
} }
}
else if (!ref) else if (!ref)
return 1; return 1;
else else
@ -2523,12 +2526,13 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
uint32 new_length= real_length(item); uint32 new_length= real_length(item);
bool use_new_field= 0, use_expression_type= 0; bool use_new_field= 0, use_expression_type= 0;
Item_result new_result_type= type_convertor[item_type][item->result_type()]; Item_result new_result_type= type_convertor[item_type][item->result_type()];
bool item_is_a_field= item->type() == Item::FIELD_ITEM;
/* /*
Check if both items point to fields: in this case we Check if both items point to fields: in this case we
can adjust column types of result table in the union smartly. can adjust column types of result table in the union smartly.
*/ */
if (field_example && item->type() == Item::FIELD_ITEM) if (field_example && item_is_a_field)
{ {
Field *field= ((Item_field *)item)->field; Field *field= ((Item_field *)item)->field;
/* Can 'field_example' field store data of the column? */ /* Can 'field_example' field store data of the column? */
@ -2545,23 +2549,25 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
!is_attr_compatible(this, item)); !is_attr_compatible(this, item));
} }
} }
else if (field_example || item->type() == Item::FIELD_ITEM) else if (field_example || item_is_a_field)
{ {
/* /*
Expression types can't be mixed with field types, we have to use Expression types can't be mixed with field types, we have to use
expression types. expression types.
*/ */
use_new_field= 1; // make next if test easier
use_expression_type= 1; use_expression_type= 1;
} }
/* Check whether size/type of the result item should be changed */ /* Check whether size/type of the result item should be changed */
if (use_new_field || use_expression_type || if (use_new_field ||
(new_result_type != item_type) || (new_length > max_length) || (new_result_type != item_type) || (new_length > max_length) ||
(!maybe_null && item->maybe_null) || (!maybe_null && item->maybe_null) ||
(item_type == STRING_RESULT && (item_type == STRING_RESULT &&
!my_charset_same(collation.collation, item->collation.collation))) !my_charset_same(collation.collation, item->collation.collation)))
{ {
if (use_expression_type || item->type() != Item::FIELD_ITEM) const char *old_cs,*old_derivation;
if (use_expression_type || !item_is_a_field)
field_example= 0; field_example= 0;
else else
{ {
@ -2572,8 +2578,8 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
field_example= ((Item_field*) item)->field; field_example= ((Item_field*) item)->field;
} }
const char *old_cs= collation.collation->name, old_cs= collation.collation->name;
*old_derivation= collation.derivation_name(); old_derivation= collation.derivation_name();
if (item_type == STRING_RESULT && collation.aggregate(item->collation)) if (item_type == STRING_RESULT && collation.aggregate(item->collation))
{ {
my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0), my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0),
@ -2593,12 +2599,12 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
return 0; return 0;
} }
uint32 Item_type_holder::real_length(Item *item) uint32 Item_type_holder::real_length(Item *item)
{ {
if (item->type() == Item::FIELD_ITEM) if (item->type() == Item::FIELD_ITEM)
{
return ((Item_field *)item)->max_disp_length(); return ((Item_field *)item)->max_disp_length();
}
switch (item->result_type()) switch (item->result_type())
{ {
case STRING_RESULT: case STRING_RESULT:

View File

@ -859,6 +859,10 @@ void Item_func_between::fix_length_and_dec()
Field *field=((Item_field*) args[0])->field; Field *field=((Item_field*) args[0])->field;
if (field->can_be_compared_as_longlong()) if (field->can_be_compared_as_longlong())
{ {
/*
The following can't be recoded with || as convert_constant_item
changes the argument
*/
if (convert_constant_item(thd, field,&args[1])) if (convert_constant_item(thd, field,&args[1]))
cmp_type=INT_RESULT; // Works for all types. cmp_type=INT_RESULT; // Works for all types.
if (convert_constant_item(thd, field,&args[2])) if (convert_constant_item(thd, field,&args[2]))

View File

@ -897,7 +897,7 @@ extern uint test_flags,select_errors,ha_open_options;
extern uint protocol_version, mysqld_port, dropping_tables; extern uint protocol_version, mysqld_port, dropping_tables;
extern uint delay_key_write_options, lower_case_table_names; extern uint delay_key_write_options, lower_case_table_names;
extern bool opt_endinfo, using_udf_functions, locked_in_memory; extern bool opt_endinfo, using_udf_functions, locked_in_memory;
extern bool opt_using_transactions, mysql_embedded; extern bool opt_using_transactions, mysqld_embedded;
extern bool using_update_log, opt_large_files, server_id_supplied; extern bool using_update_log, opt_large_files, server_id_supplied;
extern bool opt_log, opt_update_log, opt_bin_log, opt_slow_log, opt_error_log; extern bool opt_log, opt_update_log, opt_bin_log, opt_slow_log, opt_error_log;
extern bool opt_disable_networking, opt_skip_show_db; extern bool opt_disable_networking, opt_skip_show_db;

View File

@ -449,9 +449,9 @@ pthread_cond_t eventShutdown;
#endif #endif
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
bool mysql_embedded=0; bool mysqld_embedded=0;
#else #else
bool mysql_embedded=1; bool mysqld_embedded=1;
#endif #endif
#ifndef DBUG_OFF #ifndef DBUG_OFF

View File

@ -2398,7 +2398,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
table_list->db, table_list->db,
table_list->real_name, table_list->real_name,
rights, column_priv, revoke_grant)) rights, column_priv, revoke_grant))
{ // Crashend table ?? {
/* Should only happen if table is crashed */
result= -1; /* purecov: deadcode */ result= -1; /* purecov: deadcode */
} }
else if (tables[2].table) else if (tables[2].table)
@ -3636,12 +3637,17 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list)
if (!strcmp(lex_user->user.str,user) && if (!strcmp(lex_user->user.str,user) &&
!my_strcasecmp(system_charset_info, lex_user->host.str, host)) !my_strcasecmp(system_charset_info, lex_user->host.str, host))
{ {
if (replace_db_table(tables[1].table, acl_db->db, *lex_user, ~0, 1)) if (!replace_db_table(tables[1].table, acl_db->db, *lex_user, ~0, 1))
result= -1; {
else /*
Don't increment counter as replace_db_table deleted the
current element in acl_db's and shifted the higher elements down
*/
continue; continue;
} }
++counter; result= -1; // Something went wrong
}
counter++;
} }
/* Remove column access */ /* Remove column access */
@ -3664,11 +3670,12 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list)
~0, 0, 1)) ~0, 0, 1))
{ {
result= -1; result= -1;
continue;
} }
else else
{ {
if (grant_table->cols) if (!grant_table->cols)
{ continue;
List<LEX_COLUMN> columns; List<LEX_COLUMN> columns;
if (replace_column_table(grant_table,tables[3].table, *lex_user, if (replace_column_table(grant_table,tables[3].table, *lex_user,
columns, columns,
@ -3676,14 +3683,14 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list)
grant_table->tname, grant_table->tname,
~0, 1)) ~0, 1))
result= -1; result= -1;
else /*
continue; Safer to do continue here as replace_table_table changed
} column_priv_hash and we want to test the current element
else */
continue; continue;
} }
} }
++counter; counter++;
} }
} }

View File

@ -6911,10 +6911,23 @@ part_of_refkey(TABLE *table,Field *field)
/***************************************************************************** /*****************************************************************************
Test if one can use the key to resolve ORDER BY Test if one can use the key to resolve ORDER BY
Returns: 1 if key is ok.
0 if key can't be used SYNOPSIS
-1 if reverse key can be used test_if_order_by_key()
used_key_parts is set to key parts used if length != 0 order Sort order
table Table to sort
idx Index to check
used_key_parts Return value for used key parts.
NOTES
used_key_parts is set to correct key parts used if return value != 0
(On other cases, used_key_part may be changed)
RETURN
1 key is ok.
0 Key can't be used
-1 Reverse key can be used
*****************************************************************************/ *****************************************************************************/
static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx, static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
@ -6943,16 +6956,17 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
DBUG_RETURN(0); DBUG_RETURN(0);
/* set flag to 1 if we can use read-next on key, else to -1 */ /* set flag to 1 if we can use read-next on key, else to -1 */
flag= ((order->asc == !(key_part->key_part_flag & HA_REVERSE_SORT)) ? 1 : -1); flag= ((order->asc == !(key_part->key_part_flag & HA_REVERSE_SORT)) ?
1 : -1);
if (reverse && flag != reverse) if (reverse && flag != reverse)
DBUG_RETURN(0); DBUG_RETURN(0);
reverse=flag; // Remember if reverse reverse=flag; // Remember if reverse
key_part++; key_part++;
} }
uint tmp= (uint) (key_part - table->key_info[idx].key_part); *used_key_parts= (uint) (key_part - table->key_info[idx].key_part);
if (reverse == -1 && !(table->file->index_flags(idx,tmp-1, 1) & HA_READ_PREV)) if (reverse == -1 && !(table->file->index_flags(idx, *used_key_parts-1, 1) &
DBUG_RETURN(0); HA_READ_PREV))
*used_key_parts= tmp; reverse= 0; // Index can't be used
DBUG_RETURN(reverse); DBUG_RETURN(reverse);
} }

View File

@ -1136,7 +1136,7 @@ static const char *require_quotes(const char *name, uint name_length)
for ( ; name < end ; name++) for ( ; name < end ; name++)
{ {
uchar chr= (uchar) *name; uchar chr= (uchar) *name;
length= my_mbcharlen(system_charset_info, (uchar) chr); length= my_mbcharlen(system_charset_info, chr);
if (length == 1 && !system_charset_info->ident_map[chr]) if (length == 1 && !system_charset_info->ident_map[chr])
return name; return name;
} }
@ -1148,25 +1148,29 @@ void
append_identifier(THD *thd, String *packet, const char *name, uint length) append_identifier(THD *thd, String *packet, const char *name, uint length)
{ {
const char *name_end; const char *name_end;
char quote_char;
int q= get_quote_char_for_identifier(thd, name, length); int q= get_quote_char_for_identifier(thd, name, length);
if (q == EOF) { if (q == EOF)
{
packet->append(name, length, system_charset_info); packet->append(name, length, system_charset_info);
return; return;
} }
char quote_char= q; /*
The identifier must be quoted as it includes a quote character or
/* The identifier must be quoted as it includes a quote character */ it's a keyword
*/
packet->reserve(length*2 + 2); packet->reserve(length*2 + 2);
quote_char= (char) q;
packet->append(&quote_char, 1, system_charset_info); packet->append(&quote_char, 1, system_charset_info);
for (name_end= name+length ; name < name_end ; name+= length) for (name_end= name+length ; name < name_end ; name+= length)
{ {
char chr= *name; uchar chr= (uchar) *name;
length= my_mbcharlen(system_charset_info, (uchar) chr); length= my_mbcharlen(system_charset_info, chr);
if (length == 1 && chr == quote_char) if (length == 1 && chr == (uchar) quote_char)
packet->append(&quote_char, 1, system_charset_info); packet->append(&quote_char, 1, system_charset_info);
packet->append(name, length, packet->charset()); packet->append(name, length, packet->charset());
} }
@ -1174,8 +1178,25 @@ append_identifier(THD *thd, String *packet, const char *name, uint length)
} }
/* Get the quote character for displaying an identifier. /*
If no quote character is needed, return EOF. */ Get the quote character for displaying an identifier.
SYNOPSIS
get_quote_char_for_identifier()
thd Thread handler
name name to quote
length length of name
IMPLEMENTATION
If name is a keyword or includes a special character, then force
quoting.
Otherwise identifier is quoted only if the option OPTION_QUOTE_SHOW_CREATE
is set.
RETURN
EOF No quote character is needed
# Quote character
*/
int get_quote_char_for_identifier(THD *thd, const char *name, uint length) int get_quote_char_for_identifier(THD *thd, const char *name, uint length)
{ {
@ -1183,9 +1204,8 @@ int get_quote_char_for_identifier(THD *thd, const char *name, uint length)
!require_quotes(name, length) && !require_quotes(name, length) &&
!(thd->options & OPTION_QUOTE_SHOW_CREATE)) !(thd->options & OPTION_QUOTE_SHOW_CREATE))
return EOF; return EOF;
else if (thd->variables.sql_mode & MODE_ANSI_QUOTES) if (thd->variables.sql_mode & MODE_ANSI_QUOTES)
return '"'; return '"';
else
return '`'; return '`';
} }
@ -1195,10 +1215,9 @@ int get_quote_char_for_identifier(THD *thd, const char *name, uint length)
static void append_directory(THD *thd, String *packet, const char *dir_type, static void append_directory(THD *thd, String *packet, const char *dir_type,
const char *filename) const char *filename)
{ {
uint length;
if (filename && !(thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE)) if (filename && !(thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE))
{ {
length= dirname_length(filename); uint length= dirname_length(filename);
packet->append(' '); packet->append(' ');
packet->append(dir_type); packet->append(dir_type);
packet->append(" DIRECTORY='", 12); packet->append(" DIRECTORY='", 12);

View File

@ -537,7 +537,8 @@ uint32 String::numchars()
int String::charpos(int i,uint32 offset) int String::charpos(int i,uint32 offset)
{ {
if (i<0) return i; if (i <= 0)
return i;
return str_charset->cset->charpos(str_charset,Ptr+offset,Ptr+str_length,i); return str_charset->cset->charpos(str_charset,Ptr+offset,Ptr+str_length,i);
} }

View File

@ -57,7 +57,7 @@ EXTRA_DIST = ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-win1250ch.c \
t_ctype.h t_ctype.h
libmystrings_a_LIBADD= libmystrings_a_LIBADD=
conf_to_src_SOURCES = conf_to_src.c xml.c ctype.c conf_to_src_SOURCES = conf_to_src.c xml.c ctype.c bcmp.c
conf_to_src_LDADD= conf_to_src_LDADD=
#force static linking of conf_to_src - essential when linking against #force static linking of conf_to_src - essential when linking against
#custom installation of libc #custom installation of libc

View File

@ -81,10 +81,11 @@ static int my_xml_scan(MY_XML_PARSER *p,MY_XML_ATTR *a)
a->beg=p->cur; a->beg=p->cur;
a->end=p->cur; a->end=p->cur;
if (!memcmp(p->cur,"<!--",4)) if (!bcmp(p->cur,"<!--",4))
{ {
for( ; (p->cur < p->end) && memcmp(p->cur, "-->", 3); p->cur++); for( ; (p->cur < p->end) && bcmp(p->cur, "-->", 3); p->cur++)
if(!memcmp(p->cur, "-->", 3)) {}
if (!bcmp(p->cur, "-->", 3))
p->cur+=3; p->cur+=3;
a->end=p->cur; a->end=p->cur;
lex=MY_XML_COMMENT; lex=MY_XML_COMMENT;

View File

@ -26,14 +26,6 @@
#include <mysql.h> #include <mysql.h>
#include <my_getopt.h> #include <my_getopt.h>
#include <m_string.h> #include <m_string.h>
#ifdef HAVE_SYS_PARAM_H
/* Include to get MAXPATHLEN */
#include <sys/param.h>
#endif
#ifndef MAXPATHLEN
#define MAXPATHLEN 256
#endif
#define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */ #define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */
@ -6652,8 +6644,8 @@ static void test_frm_bug()
MYSQL_RES *result; MYSQL_RES *result;
MYSQL_ROW row; MYSQL_ROW row;
FILE *test_file; FILE *test_file;
char data_dir[MAXPATHLEN]; char data_dir[FN_REFLEN];
char test_frm[MAXPATHLEN]; char test_frm[FN_REFLEN];
int rc; int rc;
myheader("test_frm_bug"); myheader("test_frm_bug");
@ -6674,7 +6666,7 @@ static void test_frm_bug()
bind[0].buffer_type= MYSQL_TYPE_STRING; bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= data_dir; bind[0].buffer= data_dir;
bind[0].buffer_length= MAXPATHLEN; bind[0].buffer_length= FN_REFLEN;
bind[0].is_null= 0; bind[0].is_null= 0;
bind[0].length= 0; bind[0].length= 0;
bind[1]= bind[0]; bind[1]= bind[0];