diff options
-rw-r--r-- | client/mysqlimport.c | 1 | ||||
-rw-r--r-- | client/mysqltest.c | 22 | ||||
-rw-r--r-- | include/mysql.h | 1 | ||||
-rw-r--r-- | innobase/srv/srv0start.c | 13 | ||||
-rw-r--r-- | libmysql/libmysql.c | 10 | ||||
-rw-r--r-- | libmysql/libmysql.def | 1 | ||||
-rw-r--r-- | myisam/myisam_ftdump.c | 2 | ||||
-rw-r--r-- | myisam/myisamchk.c | 2 | ||||
-rw-r--r-- | myisam/rt_test.c | 3 | ||||
-rw-r--r-- | mysys/hash.c | 2 | ||||
-rw-r--r-- | mysys/my_gethwaddr.c | 2 | ||||
-rw-r--r-- | ndb/src/ndbapi/ndberror.c | 3 | ||||
-rw-r--r-- | regex/regcomp.c | 2 | ||||
-rw-r--r-- | regex/regcomp.ih | 2 | ||||
-rw-r--r-- | sql-common/client.c | 2 | ||||
-rw-r--r-- | sql/field.cc | 25 | ||||
-rw-r--r-- | sql/ha_innodb.cc | 4 | ||||
-rw-r--r-- | sql/item.cc | 64 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 4 | ||||
-rw-r--r-- | sql/mysql_priv.h | 2 | ||||
-rw-r--r-- | sql/mysqld.cc | 4 | ||||
-rw-r--r-- | sql/sql_acl.cc | 47 | ||||
-rw-r--r-- | sql/sql_select.cc | 32 | ||||
-rw-r--r-- | sql/sql_show.cc | 49 | ||||
-rw-r--r-- | sql/sql_string.cc | 3 | ||||
-rw-r--r-- | strings/Makefile.am | 2 | ||||
-rw-r--r-- | strings/xml.c | 7 | ||||
-rw-r--r-- | tests/client_test.c | 14 |
28 files changed, 191 insertions, 134 deletions
diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 447410fa947..fae84be610a 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -264,7 +264,6 @@ static int write_to_table(char *filename, MYSQL *sock) { char tablename[FN_REFLEN], hard_path[FN_REFLEN], sql_statement[FN_REFLEN*16+256], *end; - my_bool local_file; DBUG_ENTER("write_to_table"); DBUG_PRINT("enter",("filename: %s",filename)); diff --git a/client/mysqltest.c b/client/mysqltest.c index d2d110c7954..deaaa4dca16 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -58,13 +58,6 @@ #include <stdarg.h> #include <sys/stat.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_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_args[0]= (char*) ""; } - embedded_server_args[embedded_server_arg_count++]= - my_strdup(argument, MYF(MY_FAE)); - if (embedded_server_arg_count == MAX_SERVER_ARGS || - !embedded_server_args[embedded_server_arg_count-1]) + if (embedded_server_arg_count == MAX_SERVER_ARGS-1 || + !(embedded_server_args[embedded_server_arg_count++]= + my_strdup(argument, MYF(MY_FAE)))) { 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) { int fd; - char buff[MAXPATHLEN]; + char buff[FN_REFLEN]; if (!test_if_hard_path(fname)) { strxmov(buff, opt_basedir, fname, NullS); @@ -2979,10 +2971,10 @@ static void timer_output(void) { if (timer_file) { - char buf[1024]; + char buf[32], *end; ulonglong timer= timer_now() - timer_start; - sprintf(buf,"%llu",timer); - str_to_file(timer_file,buf,strlen(buf)); + end= longlong2str(timer, buf, 10); + str_to_file(timer_file,buf, (int) (end-buf)); } } diff --git a/include/mysql.h b/include/mysql.h index cf5af6ce189..1c886020fdb 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -506,6 +506,7 @@ char * STDCALL mysql_odbc_escape_string(MYSQL *mysql, unsigned long *length)); void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name); 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_connect(MYSQL_MANAGER* con, const char* host, diff --git a/innobase/srv/srv0start.c b/innobase/srv/srv0start.c index 8e48034e09c..9709f5235de 100644 --- a/innobase/srv/srv0start.c +++ b/innobase/srv/srv0start.c @@ -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_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 the .cnf file. */ diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 2ad6771cc69..1bf3ac5e9af 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -1516,6 +1516,16 @@ uint STDCALL mysql_thread_safe(void) #endif } + +my_bool STDCALL mysql_embedded(void) +{ +#ifdef EMBEDDED_LIBRARY + return 1; +#else + return 0; +#endif +} + /**************************************************************************** Some support functions ****************************************************************************/ diff --git a/libmysql/libmysql.def b/libmysql/libmysql.def index 38ac9505e4b..bc91e90a41c 100644 --- a/libmysql/libmysql.def +++ b/libmysql/libmysql.def @@ -144,3 +144,4 @@ EXPORTS mysql_rpl_probe mysql_rpl_query_type mysql_slave_query + mysql_embedded diff --git a/myisam/myisam_ftdump.c b/myisam/myisam_ftdump.c index 8219c19848a..54b2cc77965 100644 --- a/myisam/myisam_ftdump.c +++ b/myisam/myisam_ftdump.c @@ -68,7 +68,7 @@ int main(int argc,char *argv[]) struct { MI_INFO *info; } aio0, *aio=&aio0; /* for GWS_IN_USE */ 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); if (count || dump) verbose=0; diff --git a/myisam/myisamchk.c b/myisam/myisamchk.c index 98cbc838d31..6c0c30b7056 100644 --- a/myisam/myisamchk.c +++ b/myisam/myisamchk.c @@ -1695,7 +1695,7 @@ err: 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 ¬_killed; /* always NULL */ } diff --git a/myisam/rt_test.c b/myisam/rt_test.c index 5e883e223b3..4f04aa11fce 100644 --- a/myisam/rt_test.c +++ b/myisam/rt_test.c @@ -425,6 +425,7 @@ static void create_record1(char *record,uint rownr) } } +#ifdef NOT_USED 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) { int i; diff --git a/mysys/hash.c b/mysys/hash.c index 1296a9289e9..cf0f1d2dde6 100644 --- a/mysys/hash.c +++ b/mysys/hash.c @@ -83,7 +83,7 @@ _hash_init(HASH *hash,CHARSET_INFO *charset, Sets records to 0 */ -static void inline hash_free_elements(HASH *hash) +static inline void hash_free_elements(HASH *hash) { if (hash->free) { diff --git a/mysys/my_gethwaddr.c b/mysys/my_gethwaddr.c index 72f1cb975c4..222abe81933 100644 --- a/mysys/my_gethwaddr.c +++ b/mysys/my_gethwaddr.c @@ -107,7 +107,7 @@ my_bool my_gethwaddr(uchar *to __attribute__((unused))) } #endif -#else MAIN +#else /* MAIN */ int main(int argc __attribute__((unused)),char **argv) { uchar mac[6]; diff --git a/ndb/src/ndbapi/ndberror.c b/ndb/src/ndbapi/ndberror.c index fdfd8a15fb0..141aa1c6b60 100644 --- a/ndb/src/ndbapi/ndberror.c +++ b/ndb/src/ndbapi/ndberror.c @@ -491,6 +491,7 @@ static const int NbClassification = sizeof(StatusClassificationMapping)/sizeof(ErrorStatusClassification); +#ifdef NOT_USED /** * Complete all fields of an NdbError given the error code * and details @@ -506,7 +507,7 @@ set(ndberror_struct * error, int code, const char * details, ...){ va_end(ap); } } - +#endif void ndberror_update(ndberror_struct * error){ diff --git a/regex/regcomp.c b/regex/regcomp.c index 31899609e3c..5f0351c32aa 100644 --- a/regex/regcomp.c +++ b/regex/regcomp.c @@ -1183,6 +1183,7 @@ register cset *cs; return(n); } +#ifdef USE_ORIG_REGEX_CODE /* - mcadd - add a collating element to a cset == static void mcadd(register struct parse *p, register cset *cs, \ @@ -1209,6 +1210,7 @@ register char *cp; (void) strcpy(cs->multis + oldend - 1, cp); cs->multis[cs->smultis - 1] = '\0'; } +#endif #ifdef NOT_USED /* diff --git a/regex/regcomp.ih b/regex/regcomp.ih index 32f1f6e89eb..5deba89217a 100644 --- a/regex/regcomp.ih +++ b/regex/regcomp.ih @@ -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 firstch(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); +#endif #ifdef NOT_USED static void mcsub(register cset *cs, register char *cp); static int mcin(register cset *cs, register char *cp); diff --git a/sql-common/client.c b/sql-common/client.c index 43e116eb0b6..9fca38f3857 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -2249,7 +2249,7 @@ static void mysql_close_free(MYSQL *mysql) 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 /* Reset connection handle in all prepared statements. */ diff --git a/sql/field.cc b/sql/field.cc index 3dc1375dff3..e7e8ec736ef 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -304,14 +304,11 @@ bool Field::field_cast_compatible(Field::field_cast_enum type) { DBUG_ASSERT(type != FIELD_CAST_STOP); Field::field_cast_enum *array= field_cast_array[field_cast_type()]; - uint i= 0; - Field::field_cast_enum tp; - do + while (*array != FIELD_CAST_STOP) { - tp= array[i++]; - if (tp == type) + if (*(array++) == type) return 1; - } while (tp != FIELD_CAST_STOP); + } return 0; } @@ -4438,13 +4435,9 @@ char *Field_string::pack(char *to, const char *from, uint max_length) while (end > from && end[-1] == ' ') end--; length= (end-from); + *to++= (char) (uchar) length; if (field_length > 255) - { - int2store(to, length); - to+= 2; - } - else - *to++= (char) (uchar) length; + *to++= (char) (uchar) (length >> 8); memcpy(to, from, (int) 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); while (length && from[length-1] == ' ') length--; + *to++= (char) (uchar) length; if (field_length > 255) - { - int2store(to, length); - to+= 2; - } - else - *to++= (char) (uchar) length; + *to++= (char) (uchar) (length >> 8); memcpy(to, from, length); return to+length; } diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index d748c005d02..fbf46dd0a50 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -855,7 +855,7 @@ innobase_init(void) Note that when using the embedded server, the datadirectory is not necessarily the current directory of this program. */ - if (mysql_embedded) { + if (mysqld_embedded) { default_path = mysql_real_data_home; fil_path_to_mysql_datadir = mysql_real_data_home; } else { @@ -993,7 +993,7 @@ innobase_init(void) srv_max_n_open_files = (ulint) innobase_open_files; 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 installation */ diff --git a/sql/item.cc b/sql/item.cc index 0366ea29485..3bc65ca1062 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -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, 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; current->mark_as_dependent(last); if (thd->lex->describe & DESCRIBE_EXTENDED) @@ -1872,10 +1872,11 @@ bool Item_field::send(Protocol *protocol, String *buffer) return protocol->store(result_field); } + /* This is used for HAVING clause Find field in select list having the same name - */ +*/ 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 ), ¬_used)) == (Item **)not_found_item) { - upward_lookup= 1; 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, 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 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()) { last= sl; @@ -1967,9 +1968,9 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) if (!ref) return 1; - else if (!tmp) + if (!tmp) 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) { @@ -1984,31 +1985,33 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) *(thd->lex->current_select->get_item_list()), &counter, REPORT_ALL_ERRORS, ¬_used); } - ref= 0; + ref= 0; // Safety 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= new Item_field(tmp); - if (!fld) + Item_field* 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; thd->change_item_tree(reference, fld); mark_as_dependent(thd, last, thd->lex->current_select, fld); return 0; } - else + if (!(*ref)->fixed) { - if (!(*ref)->fixed) - { - my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, - "forward reference in item list"); - return -1; - } - mark_as_dependent(thd, last, thd->lex->current_select, - this); - ref= last->ref_pointer_array + counter; + my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, + "forward reference in item list"); + return -1; } + mark_as_dependent(thd, last, thd->lex->current_select, + this); + ref= last->ref_pointer_array + counter; } else if (!ref) return 1; @@ -2523,12 +2526,13 @@ bool Item_type_holder::join_types(THD *thd, Item *item) uint32 new_length= real_length(item); bool use_new_field= 0, use_expression_type= 0; 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 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; /* 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)); } } - 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. */ + use_new_field= 1; // make next if test easier use_expression_type= 1; } /* 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) || (!maybe_null && item->maybe_null) || (item_type == STRING_RESULT && !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; else { @@ -2572,8 +2578,8 @@ bool Item_type_holder::join_types(THD *thd, Item *item) field_example= ((Item_field*) item)->field; } - const char *old_cs= collation.collation->name, - *old_derivation= collation.derivation_name(); + old_cs= collation.collation->name; + old_derivation= collation.derivation_name(); if (item_type == STRING_RESULT && collation.aggregate(item->collation)) { my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0), @@ -2593,12 +2599,12 @@ bool Item_type_holder::join_types(THD *thd, Item *item) return 0; } + uint32 Item_type_holder::real_length(Item *item) { if (item->type() == Item::FIELD_ITEM) - { return ((Item_field *)item)->max_disp_length(); - } + switch (item->result_type()) { case STRING_RESULT: diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 248b56fe064..f6730c84979 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -859,6 +859,10 @@ void Item_func_between::fix_length_and_dec() Field *field=((Item_field*) args[0])->field; 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])) cmp_type=INT_RESULT; // Works for all types. if (convert_constant_item(thd, field,&args[2])) diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 1a0879c6347..e94d436b135 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -897,7 +897,7 @@ extern uint test_flags,select_errors,ha_open_options; extern uint protocol_version, mysqld_port, dropping_tables; extern uint delay_key_write_options, lower_case_table_names; 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 opt_log, opt_update_log, opt_bin_log, opt_slow_log, opt_error_log; extern bool opt_disable_networking, opt_skip_show_db; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index d7d0f637ec2..878b7bf7e92 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -449,9 +449,9 @@ pthread_cond_t eventShutdown; #endif #ifndef EMBEDDED_LIBRARY -bool mysql_embedded=0; +bool mysqld_embedded=0; #else -bool mysql_embedded=1; +bool mysqld_embedded=1; #endif #ifndef DBUG_OFF diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index fc252c1f5ac..b7eecac4e48 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -2398,7 +2398,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, table_list->db, table_list->real_name, rights, column_priv, revoke_grant)) - { // Crashend table ?? + { + /* Should only happen if table is crashed */ result= -1; /* purecov: deadcode */ } 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) && !my_strcasecmp(system_charset_info, lex_user->host.str, host)) { - if (replace_db_table(tables[1].table, acl_db->db, *lex_user, ~0, 1)) - result= -1; - else + if (!replace_db_table(tables[1].table, acl_db->db, *lex_user, ~0, 1)) + { + /* + Don't increment counter as replace_db_table deleted the + current element in acl_db's and shifted the higher elements down + */ continue; + } + result= -1; // Something went wrong } - ++counter; + counter++; } /* Remove column access */ @@ -3664,26 +3670,27 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list) ~0, 0, 1)) { result= -1; + continue; } else { - if (grant_table->cols) - { - List<LEX_COLUMN> columns; - if (replace_column_table(grant_table,tables[3].table, *lex_user, - columns, - grant_table->db, - grant_table->tname, - ~0, 1)) - result= -1; - else - continue; - } - else - continue; + if (!grant_table->cols) + continue; + List<LEX_COLUMN> columns; + if (replace_column_table(grant_table,tables[3].table, *lex_user, + columns, + grant_table->db, + grant_table->tname, + ~0, 1)) + result= -1; + /* + Safer to do continue here as replace_table_table changed + column_priv_hash and we want to test the current element + */ + continue; } } - ++counter; + counter++; } } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 638ed229a70..df74a946b5c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -6911,10 +6911,23 @@ part_of_refkey(TABLE *table,Field *field) /***************************************************************************** Test if one can use the key to resolve ORDER BY - Returns: 1 if key is ok. - 0 if key can't be used - -1 if reverse key can be used - used_key_parts is set to key parts used if length != 0 + + SYNOPSIS + test_if_order_by_key() + 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, @@ -6943,16 +6956,17 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx, DBUG_RETURN(0); /* 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) DBUG_RETURN(0); reverse=flag; // Remember if reverse key_part++; } - uint tmp= (uint) (key_part - table->key_info[idx].key_part); - if (reverse == -1 && !(table->file->index_flags(idx,tmp-1, 1) & HA_READ_PREV)) - DBUG_RETURN(0); - *used_key_parts= tmp; + *used_key_parts= (uint) (key_part - table->key_info[idx].key_part); + if (reverse == -1 && !(table->file->index_flags(idx, *used_key_parts-1, 1) & + HA_READ_PREV)) + reverse= 0; // Index can't be used DBUG_RETURN(reverse); } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index c5cd2860e03..e030db2caf7 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1136,7 +1136,7 @@ static const char *require_quotes(const char *name, uint name_length) for ( ; name < end ; 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]) return name; } @@ -1148,25 +1148,29 @@ void append_identifier(THD *thd, String *packet, const char *name, uint length) { const char *name_end; + char quote_char; int q= get_quote_char_for_identifier(thd, name, length); - if (q == EOF) { + if (q == EOF) + { packet->append(name, length, system_charset_info); return; } - char quote_char= q; - - /* The identifier must be quoted as it includes a quote character */ + /* + The identifier must be quoted as it includes a quote character or + it's a keyword + */ packet->reserve(length*2 + 2); + quote_char= (char) q; packet->append("e_char, 1, system_charset_info); for (name_end= name+length ; name < name_end ; name+= length) { - char chr= *name; - length= my_mbcharlen(system_charset_info, (uchar) chr); - if (length == 1 && chr == quote_char) + uchar chr= (uchar) *name; + length= my_mbcharlen(system_charset_info, chr); + if (length == 1 && chr == (uchar) quote_char) packet->append("e_char, 1, system_charset_info); 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) { @@ -1183,10 +1204,9 @@ int get_quote_char_for_identifier(THD *thd, const char *name, uint length) !require_quotes(name, length) && !(thd->options & OPTION_QUOTE_SHOW_CREATE)) return EOF; - else if (thd->variables.sql_mode & MODE_ANSI_QUOTES) + if (thd->variables.sql_mode & MODE_ANSI_QUOTES) 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, const char *filename) { - uint length; if (filename && !(thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE)) { - length= dirname_length(filename); + uint length= dirname_length(filename); packet->append(' '); packet->append(dir_type); packet->append(" DIRECTORY='", 12); diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 1ec0faafa8f..1044dc4e58e 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -537,7 +537,8 @@ uint32 String::numchars() 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); } diff --git a/strings/Makefile.am b/strings/Makefile.am index be51e48ef8d..d17a4f598a6 100644 --- a/strings/Makefile.am +++ b/strings/Makefile.am @@ -57,7 +57,7 @@ EXTRA_DIST = ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-win1250ch.c \ t_ctype.h 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= #force static linking of conf_to_src - essential when linking against #custom installation of libc diff --git a/strings/xml.c b/strings/xml.c index 7d7839e1603..6ba52ea41a8 100644 --- a/strings/xml.c +++ b/strings/xml.c @@ -81,10 +81,11 @@ static int my_xml_scan(MY_XML_PARSER *p,MY_XML_ATTR *a) a->beg=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++); - if(!memcmp(p->cur, "-->", 3)) + for( ; (p->cur < p->end) && bcmp(p->cur, "-->", 3); p->cur++) + {} + if (!bcmp(p->cur, "-->", 3)) p->cur+=3; a->end=p->cur; lex=MY_XML_COMMENT; diff --git a/tests/client_test.c b/tests/client_test.c index 0b30cc3386d..eb97c0ce949 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -26,14 +26,6 @@ #include <mysql.h> #include <my_getopt.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 */ @@ -6652,8 +6644,8 @@ static void test_frm_bug() MYSQL_RES *result; MYSQL_ROW row; FILE *test_file; - char data_dir[MAXPATHLEN]; - char test_frm[MAXPATHLEN]; + char data_dir[FN_REFLEN]; + char test_frm[FN_REFLEN]; int rc; myheader("test_frm_bug"); @@ -6674,7 +6666,7 @@ static void test_frm_bug() bind[0].buffer_type= MYSQL_TYPE_STRING; bind[0].buffer= data_dir; - bind[0].buffer_length= MAXPATHLEN; + bind[0].buffer_length= FN_REFLEN; bind[0].is_null= 0; bind[0].length= 0; bind[1]= bind[0]; |