mariadb/sql/sql_list.h
unknown 5a28c2caca Fixes and code cleanups after merge with 4.0.3
Warning handling and initial prepared statement handling (last not complete yet)
Changed a lot of functions that returned 0/1 to my_bool type.
GRANT handling now uses read/write locks instead of mutex
Change basic net functions to use THD instead of NET
(needed for 4.1 protocol)
Use my_sprintf instead of sprintf() + strlen()
Added alloc_query() to be able to chare query initialization code with
prepared statements.
Cleanup handling of SHOW COUNT(*) WARNINGS and SELECT LAST_INSERT_ID()

Note that the following test fails (will be fixed ASAP):
sub_select, union, rpl_rotate_logs and rpl_mystery22


BitKeeper/deleted/.del-README~3449730baf983117:
  Delete: mysql-test/t/README
BitKeeper/deleted/.del-sql_error.cc~2f1caca8d2485dbe:
  Delete: libmysqld/sql_error.cc
BitKeeper/deleted/.del-sql_prepare.cc~f703729793935ed6:
  Delete: libmysqld/sql_prepare.cc
Docs/manual.texi:
  Updated variable list
client/mysql.cc:
  Show warning count to user.
client/mysqltest.c:
  Add warnings to test results
configure.in:
  New shared library version number
include/errmsg.h:
  Indentation cleanup
include/mysql.h:
  Removed MYSQL_ERROR
  Indentaion cleanups
include/mysql_com.h:
  Changed functions to returns true/false to my_bool.
include/mysqld_error.h:
  New error messages
isam/pack_isam.c:
  Indentation change
libmysql/Makefile.am:
  Fix of wrong merge
libmysql/Makefile.shared:
  Indentation cleanup
libmysql/errmsg.c:
  Removed not used errors
libmysql/libmysql.c:
  Change functions to return 1 on error (not -1)
  Change type of functions that returns 0/1 to my_bool
  Lot of code optimizations.
  Lot of changes for prepared statements. This now handles sending of binary data to server.
  Receving of binary data is not yet done (will have to wait until server code for this is ready)
  mysql_warning_count and mysql_warnings() implemented.
libmysql/libmysql.def:
  Added mysql_warnings and mysql_warning_count
libmysql/manager.c:
  Fixed wrong testing of result from my_connect()
libmysqld/lib_sql.cc:
  Removed global variable THR_NET
  Change basic net functions to use THD instead of NET
  GRANT handling now uses read/write locks instead of mutex
libmysqld/libmysqld.c:
  Changed functions to be my_bool
myisam/ft_boolean_search.c:
  Trivial code cleanup
myisam/ft_stopwords.c:
  Trivial code cleanup
myisam/mi_check.c:
  Update to 4.1 structures
myisam/myisampack.c:
  Trivial code cleanup
myisam/rt_key.c:
  Code cleanup
myisam/rt_test.c:
  Code cleanup
  Removed compiler warnings
myisam/sp_key.c:
  Indentation changes
myisam/sp_test.c:
  Removed compiler warnings
mysql-test/README:
  Updated to reflect the new --external flag.
mysql-test/mysql-test-run.sh:
  --local (start new server) is now default.
  Use --external to test against external server.
mysql-test/r/rollback.result:
  Updated for 4.1 warnings
mysql-test/r/rpl_log.result:
  Update for 4.1
mysql-test/t/rollback.test:
  Updated for 4.1 warnings
mysql-test/t/rpl_log_pos.test:
  Portability fix
mysys/hash.c:
  Indentation change
mysys/my_error.c:
  Indentation change
mysys/tree.c:
  Updated file description
sql/field.cc:
  Fixed bugs introduced by merge
  Use my_sprintf instead of sprintf() + strlen()
sql/field.h:
  Add CHARSET_INFO to field structure
sql/gstream.h:
  Indentation changes.
  Added GPL copyright header
sql/ha_innodb.cc:
  Updated parameters for net functions.
sql/item.cc:
  Updates of Item_param
  Indentation changes
sql/item.h:
  Removed size_of() function from item.
sql/item_func.cc:
  Update function usage for 4.1
  Added get_system_var()
sql/item_func.h:
  Indentation change
sql/item_strfunc.cc:
  Removed not needed inclusion of gstream.h
  Update to use system variables (from 4.0)
sql/item_sum.h:
  Removed size_of() functions from item.
sql/item_timefunc.cc:
  Change sprintf() + strlen() -> my_sprintf()
  Added length parameter to ->append()
sql/item_timefunc.h:
  Removed size_of() functions from item.
sql/item_uniq.h:
  Removed size_of() functions from item.
sql/lex.h:
  Removed SQL_ERROR_COUNT variable
sql/log.cc:
  Change sprintf() + strlen() -> my_sprintf()
sql/log_event.cc:
  Change sprintf() + strlen() -> my_sprintf()
sql/mini_client.cc:
  Added check that one always specifies a length to mc_mysql_query()
sql/mysql_priv.h:
  New prototypes
  Change of NET -> THD parameter for net functions.
sql/mysqld.cc:
  New startup options:  'max_prepared_statements', 'max_error_count'
  Updated usage of net functions.
sql/net_pkg.cc:
  Change basic net functions to use THD instead of NET
  (needed to be able to handle 4.0 and 4.1 protocols)
  Lots of function comments
sql/net_serv.cc:
  Change int return values -> my_bool
  Updated net_write_command() to take an extra header block to be added to the packet.
  (This made the prepared statement code much nicer and more efficient)
sql/repl_failsafe.cc:
  Update net functions to use THD instead of NET
sql/set_var.cc:
  Added @@error_count and @@warning_count variables.
  Updated to 4.1 function usage
sql/set_var.h:
  Added @@error_count and @@warning_count variables.
sql/share/czech/errmsg.txt:
  Removed Warning: from warning error messages.
sql/share/english/errmsg.txt:
  Removed Warning: from warning error messages.
sql/share/greek/errmsg.txt:
  Removed Warning: from warning error messages.
sql/share/hungarian/errmsg.txt:
  Removed Warning: from warning error messages.
sql/share/japanese/errmsg.txt:
  Removed Warning: from warning error messages.
sql/share/korean/errmsg.txt:
  Removed Warning: from warning error messages.
sql/share/norwegian-ny/errmsg.txt:
  Removed Warning: from warning error messages.
sql/share/norwegian/errmsg.txt:
  Removed Warning: from warning error messages.
sql/share/polish/errmsg.txt:
  Removed Warning: from warning error messages.
sql/share/romanian/errmsg.txt:
  Removed Warning: from warning error messages.
sql/share/slovak/errmsg.txt:
  Removed Warning: from warning error messages.
sql/share/swedish/errmsg.txt:
  Removed Warning: from warning error messages.
sql/slave.cc:
  Change basic net functions to use THD instead of NET
  skip_load_data_file recoded to fit new client/server protocol
sql/spatial.h:
  Added copyright header
  Indentation cleanups
sql/sql_acl.cc:
  Change basic net functions to use THD instead of NET
  GRANT handling now uses read/write locks instead of mutex
sql/sql_analyse.cc:
  Change basic net functions to use THD instead of NET
  sprintf() + strlen() -> my_sprintf()
sql/sql_base.cc:
  More DBUG statements
sql/sql_class.cc:
  Change basic net functions to use THD instead of NET
  warning and prepared statement handling
sql/sql_class.h:
  Change basic net functions to use THD instead of NET
  warning and prepared statement handling
sql/sql_db.cc:
  Code cleanup & optimization.
sql/sql_delete.cc:
  Change basic net functions to use THD instead of NET
sql/sql_derived.cc:
  Change basic net functions to use THD instead of NET
sql/sql_do.cc:
  Change basic net functions to use THD instead of NET
sql/sql_error.cc:
  Big rewrite of error handling.
sql/sql_handler.cc:
  Change basic net functions to use THD instead of NET
sql/sql_insert.cc:
  Change basic net functions to use THD instead of NET
sql/sql_lex.cc:
  Change basic net functions to use THD instead of NET
sql/sql_lex.h:
  Added param_count to st_select_lex_node
sql/sql_list.h:
  Removed not needed error list.
sql/sql_load.cc:
  Change basic net functions to use THD instead of NET
sql/sql_parse.cc:
  Change basic net functions to use THD instead of NET
  Added alloc_query() to be able to chare query initialization code with
  prepared statements.
  Update of warning handling.
  Added create_select_for_variable() (for SHOW COUNT(*) WARNINGS)
sql/sql_prepare.cc:
  Initial prepared statement handling
sql/sql_rename.cc:
  Change basic net functions to use THD instead of NET
sql/sql_repl.cc:
  Change basic net functions to use THD instead of NET
sql/sql_select.cc:
  Small code cleanups
  Added missing initialization of error that caused some queries that returned an empty result set to fail
sql/sql_select.h:
  Ensure that JOIN.error is properly initialized
sql/sql_show.cc:
  Change basic net functions to use THD instead of NET
  A lot of optimization
sql/sql_table.cc:
  Change basic net functions to use THD instead of NET
  Indentaion cleanup
sql/sql_udf.cc:
  Change basic net functions to use THD instead of NET
sql/sql_union.cc:
  Change basic net functions to use THD instead of NET
sql/sql_update.cc:
  Change basic net functions to use THD instead of NET
sql/sql_yacc.yy:
  Change basic net functions to use THD instead of NET
  Cleanup handling of SHOW COUNT(*) WARNINGS and SELECT LAST_INSERT_ID()
sql/structs.h:
  Moved structures to files where they was used
sql/table.cc:
  Don't accept empty database names
sql/uniques.cc:
  Indentation cleanup
sql/unireg.cc:
  Change basic net functions to use THD instead of NET
sql/unireg.h:
  Added defaults for warnings and prepared statements
strings/ctype-simple.c:
  optimization
tests/client_test.c:
  Fixed wrong paramaters to printf()
2002-10-02 13:33:08 +03:00

364 lines
9 KiB
C++

/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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 */
/* mysql standard open memoryallocator */
#ifdef __GNUC__
#pragma interface /* gcc class implementation */
#endif
class Sql_alloc
{
public:
static void *operator new(size_t size) {return (void*) sql_alloc((uint) size); }
static void operator delete(void *ptr, size_t size) {} /*lint -e715 */
#ifdef HAVE_purify
bool dummy;
inline Sql_alloc() :dummy(0) {}
inline ~Sql_alloc() {}
#else
inline Sql_alloc() {}
inline ~Sql_alloc() {}
#endif
};
/*
** basic single linked list
** Used for item and item_buffs.
** All list ends with a pointer to the 'end_of_list' element, which
** data pointer is a null pointer and the next pointer points to itself.
** This makes it very fast to traverse lists as we don't have to
** test for a specialend condition for list that can't contain a null
** pointer.
*/
class list_node :public Sql_alloc
{
public:
list_node *next;
void *info;
list_node(void *info_par,list_node *next_par)
:next(next_par),info(info_par)
{}
list_node() /* For end_of_list */
{
info=0;
next= this;
}
friend class base_list;
friend class base_list_iterator;
};
extern list_node end_of_list;
class base_list :public Sql_alloc {
protected:
list_node *first,**last;
public:
uint elements;
inline void empty() { elements=0; first= &end_of_list; last=&first;}
inline base_list() { empty(); }
inline base_list(const base_list &tmp) :Sql_alloc()
{
elements=tmp.elements;
first=tmp.first;
last=tmp.last;
}
inline base_list(bool error) { }
inline bool push_back(void *info)
{
if (((*last)=new list_node(info, &end_of_list)))
{
last= &(*last)->next;
elements++;
return 0;
}
return 1;
}
inline bool push_front(void *info)
{
list_node *node=new list_node(info,first);
if (node)
{
if (last == &first)
last= &node->next;
first=node;
elements++;
return 0;
}
return 1;
}
void remove(list_node **prev)
{
list_node *node=(*prev)->next;
delete *prev;
*prev=node;
if (!--elements)
last= &first;
}
inline void *pop(void)
{
if (first == &end_of_list) return 0;
list_node *tmp=first;
first=first->next;
if (!--elements)
last= &first;
return tmp->info;
}
inline list_node* last_node() { return *last; }
inline list_node* first_node() { return first;}
inline void *head() { return first->info; }
inline void **head_ref() { return first != &end_of_list ? &first->info : 0; }
inline bool is_empty() { return first == &end_of_list ; }
inline list_node *last_ref() { return &end_of_list; }
friend class base_list_iterator;
friend class error_list;
friend class error_list_iterator;
protected:
void after(void *info,list_node *node)
{
list_node *new_node=new list_node(info,node->next);
node->next=new_node;
elements++;
if (last == &(node->next))
last= &new_node->next;
}
};
class base_list_iterator
{
base_list *list;
list_node **el,**prev,*current;
public:
base_list_iterator(base_list &list_par) :list(&list_par),el(&list_par.first),
prev(0),current(0)
{}
inline void *next(void)
{
prev=el;
current= *el;
el= &current->next;
return current->info;
}
inline void *next_fast(void)
{
list_node *tmp;
tmp= *el;
el= &tmp->next;
return tmp->info;
}
inline void rewind(void)
{
el= &list->first;
}
inline void *replace(void *element)
{ // Return old element
void *tmp=current->info;
current->info=element;
return tmp;
}
void *replace(base_list &new_list)
{
void *ret_value=current->info;
if (!new_list.is_empty())
{
*new_list.last=current->next;
current->info=new_list.first->info;
current->next=new_list.first->next;
list->elements+=new_list.elements-1;
}
return ret_value; // return old element
}
inline void remove(void) // Remove current
{
list->remove(prev);
el=prev;
current=0; // Safeguard
}
void after(void *element) // Insert element after current
{
list->after(element,current);
current=current->next;
el= &current->next;
}
inline void **ref(void) // Get reference pointer
{
return &current->info;
}
inline bool is_last(void)
{
return el == &list->last_ref()->next;
}
friend class error_list_iterator;
};
template <class T> class List :public base_list
{
public:
inline List() :base_list() {}
inline List(const List<T> &tmp) :base_list(tmp) {}
inline bool push_back(T *a) { return base_list::push_back(a); }
inline bool push_front(T *a) { return base_list::push_front(a); }
inline T* head() {return (T*) base_list::head(); }
inline T** head_ref() {return (T**) base_list::head_ref(); }
inline T* pop() {return (T*) base_list::pop(); }
void delete_elements(void)
{
list_node *element,*next;
for (element=first; element != &end_of_list; element=next)
{
next=element->next;
delete (T*) element->info;
}
empty();
}
};
template <class T> class List_iterator :public base_list_iterator
{
public:
List_iterator(List<T> &a) : base_list_iterator(a) {}
inline T* operator++(int) { return (T*) base_list_iterator::next(); }
inline T *replace(T *a) { return (T*) base_list_iterator::replace(a); }
inline T *replace(List<T> &a) { return (T*) base_list_iterator::replace(a); }
inline void after(T *a) { base_list_iterator::after(a); }
inline T** ref(void) { return (T**) base_list_iterator::ref(); }
};
template <class T> class List_iterator_fast :public base_list_iterator
{
protected:
inline T *replace(T *a) { return (T*) 0; }
inline T *replace(List<T> &a) { return (T*) 0; }
inline void remove(void) { }
inline void after(T *a) { }
inline T** ref(void) { return (T**) 0; }
public:
List_iterator_fast(List<T> &a) : base_list_iterator(a) {}
inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); }
inline void rewind(void) { base_list_iterator::rewind(); }
};
/*
** A simple intrusive list which automaticly removes element from list
** on delete (for THD element)
*/
struct ilink {
struct ilink **prev,*next;
static void *operator new(size_t size)
{
return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE));
}
static void operator delete(void* ptr_arg, size_t size)
{
my_free((gptr)ptr_arg, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
}
inline ilink()
{
prev=0; next=0;
}
inline void unlink()
{
/* Extra tests because element doesn't have to be linked */
if (prev) *prev= next;
if (next) next->prev=prev;
prev=0 ; next=0;
}
virtual ~ilink() { unlink(); } /*lint -e1740 */
};
template <class T> class I_List_iterator;
class base_ilist {
public:
struct ilink *first,last;
base_ilist() { first= &last; last.prev= &first; }
inline bool is_empty() { return first == &last; }
inline void append(ilink *a)
{
first->prev= &a->next;
a->next=first; a->prev= &first; first=a;
}
inline void push_back(ilink *a)
{
*last.prev= a;
a->next= &last;
a->prev= last.prev;
last.prev= &a->next;
}
inline struct ilink *get()
{
struct ilink *first_link=first;
if (first_link == &last)
return 0;
first_link->unlink(); // Unlink from list
return first_link;
}
friend class base_list_iterator;
};
class base_ilist_iterator
{
base_ilist *list;
struct ilink **el,*current;
public:
base_ilist_iterator(base_ilist &list_par) :list(&list_par),
el(&list_par.first),current(0) {}
void *next(void)
{
/* This is coded to allow push_back() while iterating */
current= *el;
if (current == &list->last) return 0;
el= &current->next;
return current;
}
};
template <class T>
class I_List :private base_ilist {
public:
I_List() :base_ilist() {}
inline bool is_empty() { return base_ilist::is_empty(); }
inline void append(T* a) { base_ilist::append(a); }
inline void push_back(T* a) { base_ilist::push_back(a); }
inline T* get() { return (T*) base_ilist::get(); }
#ifndef _lint
friend class I_List_iterator<T>;
#endif
};
template <class T> class I_List_iterator :public base_ilist_iterator
{
public:
I_List_iterator(I_List<T> &a) : base_ilist_iterator(a) {}
inline T* operator++(int) { return (T*) base_ilist_iterator::next(); }
};