diff options
author | unknown <monty@mashka.mysql.fi> | 2002-06-11 11:20:31 +0300 |
---|---|---|
committer | unknown <monty@mashka.mysql.fi> | 2002-06-11 11:20:31 +0300 |
commit | 70aa7424c41c45a8fb171bbdd9e24d74b70a7765 (patch) | |
tree | 8fcaabe013fff43cf466235067f2c47f0cd66531 /libmysql | |
parent | 30d5eb22877d0546fb4bd93ead7e8602285d449b (diff) | |
download | mariadb-git-70aa7424c41c45a8fb171bbdd9e24d74b70a7765.tar.gz |
Big code cleanup/review before 4.0.2 release.
(All commit emails since 4.0.1 checked)
This had to be done now, before the 4.1 tree changes to much, to make it easy to propagate bug fixes to the 4.1 tree.
BUILD/SETUP.sh:
Added -DPEDANTIC_SAFEMALLOC as standard debug option
Docs/manual.texi:
Changes for new version.
client/mysql.cc:
Fixed default value for rehash
cleanup
client/mysqladmin.c:
Cleanup
client/mysqlbinlog.cc:
cleanup
client/mysqldump.c:
Cleanup
client/mysqlmanager-pwgen.c:
Cleanup
client/mysqlmanagerc.c:
Cleanup
client/mysqltest.c:
Cleanup
dbug/dbug.c:
Cleanup
extra/resolve_stack_dump.c:
Cleanup & Simple optimizations
include/ft_global.h:
Cleanup
include/my_alloc.h:
Cleanup
include/my_global.h:
Cleanup
include/my_sys.h:
Cleanup
include/myisam.h:
Cleanup
libmysql/libmysql.c:
Cleanup
libmysql/manager.c:
Cleanup
myisam/ft_boolean_search.c:
Cleanup
myisam/ft_dump.c:
Change strcpy -> strmov
myisam/ft_eval.c:
Cleanup
myisam/ft_nlq_search.c:
Cleanup
myisam/ft_test1.c:
strncpy -> strnmov
myisam/ft_update.c:
Cleanup
myisam/mi_static.c:
Cleanup
myisam/mi_test2.c:
Cleanup
myisam/mi_write.c:
Cleanup
mysys/mf_fn_ext.c:
Cleanup
mysys/mf_iocache.c:
Cleanup
mysys/mf_iocache2.c:
Cleanup
mysys/my_getopt.c:
Cleanup
mysys/my_read.c:
Cleanup
mysys/my_thr_init.c:
Cleanup
mysys/queues.c:
Cleanup
mysys/safemalloc.c:
Cleanup
sql/field.cc:
Indentation cleanups
sql/ha_berkeley.cc:
Indentation cleanups
sql/ha_myisam.cc:
Cleanup
sql/item.h:
Indentation cleanups
sql/item_cmpfunc.cc:
Indentation cleanups
sql/item_create.cc:
cleanup
sql/item_func.cc:
Cleanup
sql/item_func.h:
Indentation cleanups
sql/item_strfunc.cc:
Indentation cleanups
sql/item_sum.cc:
Indentation cleanups
sql/item_timefunc.cc:
Indentation cleanups
sql/lock.cc:
Indentation cleanups
sql/log.cc:
Cleanup
strnmov -> strmake
sql/log_event.cc:
Cleanup + optimizations
Fixed memory leak
Added missing pthread_mutex_unlock() (On error condition)
sql/log_event.h:
Indentation and comment cleanup
Merged #ifdef's into common blocks for better readability
sql/mini_client.cc:
Indentation cleanup
sql/mysql_priv.h:
Cleanup
Changed int function to bool
sql/mysqld.cc:
Indentation and comment cleanup
sql/net_pkg.cc:
Indentation cleanup
sql/net_serv.cc:
Changed int function -> bool
sql/nt_servc.cc:
Cleanup
sql/opt_range.cc:
Indentation cleanup
sql/repl_failsafe.cc:
Cleanup + simple optimization
strnmov -> strmake
sql/slave.cc:
strnmov -> strmake
Cleanups
sql/slave.h:
Cleanup
sql/sql_acl.cc:
Indentation and DBUG_PRINT cleanup
Changed WITH MAX... to not use =
sql/sql_base.cc:
Indentation cleanup
sql/sql_cache.cc:
Indentation cleanup
sql/sql_class.cc:
Indentation cleanup
sql/sql_class.h:
Renamed some struct slots
sql/sql_delete.cc:
Indentation cleanup
sql/sql_handler.cc:
Indentation cleanup
sql/sql_insert.cc:
Use new slot names.
sql/sql_lex.cc:
Indentation cleanup
sql/sql_lex.h:
Indentation cleanup
sql/sql_load.cc:
Indentation cleanup
sql/sql_parse.cc:
Indentation cleanup
Removed not used check from LOCK TABLES
sql/sql_repl.cc:
strnmov -> strmake
sql/sql_repl.h:
Removed test if file is included (We want to know if it's included twice to avoid this)
sql/sql_select.cc:
Indentation cleanup
sql/sql_show.cc:
Indentation cleanup
sql/sql_string.cc:
Indentation cleanup
sql/sql_table.cc:
Indentation cleanup
sql/sql_union.cc:
Use renamed struct slot
sql/sql_update.cc:
Indentation cleanup
sql/sql_yacc.yy:
Removed = after GRANT ... MAX_ to make the syntax uniform
sql/table.cc:
Indentation cleanup
sql/table.h:
Indentation cleanup
sql/time.cc:
Indentation cleanup
sql/udf_example.cc:
Indentation cleanup
sql/unireg.cc:
strnmov -> strmake
tests/grant.pl:
Added test for LOCK TABLES
tools/mysqlmanager.c:
Cleanup
fopen() -> my_fopen()
vio/viosocket.c:
DBUG_PRINT cleanups
vio/viosslfactories.c:
Indentation cleanup
Checking of results from malloc()
Fixed possible memory leak
BitKeeper/etc/ignore:
Added scripts/mysql_secure_installation to the ignore list
BitKeeper/etc/logging_ok:
Logging to logging@openlogging.org accepted
Diffstat (limited to 'libmysql')
-rw-r--r-- | libmysql/libmysql.c | 275 | ||||
-rw-r--r-- | libmysql/manager.c | 25 |
2 files changed, 160 insertions, 140 deletions
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 73fc1feb472..646c165d512 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -144,12 +144,12 @@ static MYSQL* spawn_init(MYSQL* parent, const char* host, /**************************************************************************** -* A modified version of connect(). connect2() allows you to specify -* a timeout value, in seconds, that we should wait until we -* derermine we can't connect to a particular host. If timeout is 0, -* my_connect() will behave exactly like connect(). -* -* Base version coded by Steve Bernacki, Jr. <steve@navinet.net> + A modified version of connect(). connect2() allows you to specify + a timeout value, in seconds, that we should wait until we + derermine we can't connect to a particular host. If timeout is 0, + my_connect() will behave exactly like connect(). + + Base version coded by Steve Bernacki, Jr. <steve@navinet.net> *****************************************************************************/ int my_connect(my_socket s, const struct sockaddr *name, uint namelen, @@ -249,7 +249,7 @@ int my_connect(my_socket s, const struct sockaddr *name, uint namelen, } /* -** Create a named pipe connection + Create a named pipe connection */ #ifdef __WIN__ @@ -322,8 +322,8 @@ HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host, /***************************************************************************** -** read a packet from server. Give error message if socket was down -** or packet is an error message + read a packet from server. Give error message if socket was down + or packet is an error message *****************************************************************************/ ulong @@ -569,7 +569,7 @@ static my_bool is_NT(void) #endif /* -** Expand wildcard to a sql string + Expand wildcard to a sql string */ static void @@ -595,7 +595,7 @@ append_wild(char *to, char *end, const char *wild) /************************************************************************** -** Init debugging if MYSQL_DEBUG environment variable is found + Init debugging if MYSQL_DEBUG environment variable is found **************************************************************************/ void STDCALL @@ -632,7 +632,7 @@ mysql_debug(const char *debug __attribute__((unused))) /************************************************************************** -** Close the server connection if we get a SIGPIPE + Close the server connection if we get a SIGPIPE ARGSUSED **************************************************************************/ @@ -647,7 +647,7 @@ pipe_sig_handler(int sig __attribute__((unused))) /************************************************************************** -** Shut down connection + Shut down connection **************************************************************************/ static void @@ -701,7 +701,7 @@ mysql_free_result(MYSQL_RES *result) /**************************************************************************** -** Get options from my.cnf + Get options from my.cnf ****************************************************************************/ static const char *default_options[]= @@ -879,7 +879,7 @@ static void mysql_read_default_options(struct st_mysql_options *options, /*************************************************************************** -** Change field rows to field structs + Change field rows to field structs ***************************************************************************/ static MYSQL_FIELD * @@ -1004,8 +1004,8 @@ static MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, /* -** Read one row. Uses packet buffer as storage for fields. -** When next packet is read, the previous field values are destroyed + Read one row. Uses packet buffer as storage for fields. + When next packet is read, the previous field values are destroyed */ @@ -1146,9 +1146,11 @@ static inline void expand_error(MYSQL* mysql, int error) mysql->net.last_errno = error; } -/* This function assumes we have just called SHOW SLAVE STATUS and have - read the given result and row +/* + This function assumes we have just called SHOW SLAVE STATUS and have + read the given result and row */ + static inline int get_master(MYSQL* mysql, MYSQL_RES* res, MYSQL_ROW row) { MYSQL* master; @@ -1162,9 +1164,12 @@ static inline int get_master(MYSQL* mysql, MYSQL_RES* res, MYSQL_ROW row) return 0; } -/* assuming we already know that mysql points to a master connection, - retrieve all the slaves + +/* + Assuming we already know that mysql points to a master connection, + retrieve all the slaves */ + static inline int get_slaves_from_master(MYSQL* mysql) { MYSQL_RES* res = 0; @@ -1180,14 +1185,13 @@ static inline int get_slaves_from_master(MYSQL* mysql) } if (mysql_query(mysql, "SHOW SLAVE HOSTS") || - !(res = mysql_store_result(mysql))) + !(res = mysql_store_result(mysql))) { expand_error(mysql, CR_PROBE_SLAVE_HOSTS); return 1; } - switch (mysql_num_fields(res)) - { + switch (mysql_num_fields(res)) { case 5: has_auth_info = 0; port_ind=2; @@ -1236,15 +1240,16 @@ int STDCALL mysql_rpl_probe(MYSQL* mysql) MYSQL_RES* res = 0; MYSQL_ROW row; int error = 1; - /* first determine the replication role of the server we connected to - the most reliable way to do this is to run SHOW SLAVE STATUS and see - if we have a non-empty master host. This is still not fool-proof - - it is not a sin to have a master that has a dormant slave thread with - a non-empty master host. However, it is more reliable to check - for empty master than whether the slave thread is actually running + /* + First determine the replication role of the server we connected to + the most reliable way to do this is to run SHOW SLAVE STATUS and see + if we have a non-empty master host. This is still not fool-proof - + it is not a sin to have a master that has a dormant slave thread with + a non-empty master host. However, it is more reliable to check + for empty master than whether the slave thread is actually running */ if (mysql_query(mysql, "SHOW SLAVE STATUS") || - !(res = mysql_store_result(mysql))) + !(res = mysql_store_result(mysql))) { expand_error(mysql, CR_PROBE_SLAVE_STATUS); return 1; @@ -1275,51 +1280,54 @@ err: } -/* make a not so fool-proof decision on where the query should go, to - the master or the slave. Ideally the user should always make this - decision himself with mysql_master_query() or mysql_slave_query(). - However, to be able to more easily port the old code, we support the - option of an educated guess - this should work for most applications, - however, it may make the wrong decision in some particular cases. If - that happens, the user would have to change the code to call - mysql_master_query() or mysql_slave_query() explicitly in the place - where we have made the wrong decision +/* + Make a not so fool-proof decision on where the query should go, to + the master or the slave. Ideally the user should always make this + decision himself with mysql_master_query() or mysql_slave_query(). + However, to be able to more easily port the old code, we support the + option of an educated guess - this should work for most applications, + however, it may make the wrong decision in some particular cases. If + that happens, the user would have to change the code to call + mysql_master_query() or mysql_slave_query() explicitly in the place + where we have made the wrong decision */ + enum mysql_rpl_type STDCALL mysql_rpl_query_type(const char* q, int len) { const char* q_end; q_end = (len) ? q + len : strend(q); - for(; q < q_end; ++q) + for (; q < q_end; ++q) { char c; if (isalpha(c=*q)) - switch(tolower(c)) - { - case 'i': /* insert */ - case 'u': /* update or unlock tables */ - case 'l': /* lock tables or load data infile */ - case 'd': /* drop or delete */ - case 'a': /* alter */ - return MYSQL_RPL_MASTER; - case 'c': /* create or check */ - return tolower(q[1]) == 'h' ? MYSQL_RPL_ADMIN : MYSQL_RPL_MASTER ; - case 's': /* select or show */ - return tolower(q[1]) == 'h' ? MYSQL_RPL_ADMIN : MYSQL_RPL_SLAVE; - case 'f': /* flush */ - case 'r': /* repair */ - case 'g': /* grant */ - return MYSQL_RPL_ADMIN; - default: - return MYSQL_RPL_SLAVE; - } + { + switch(tolower(c)) { + case 'i': /* insert */ + case 'u': /* update or unlock tables */ + case 'l': /* lock tables or load data infile */ + case 'd': /* drop or delete */ + case 'a': /* alter */ + return MYSQL_RPL_MASTER; + case 'c': /* create or check */ + return tolower(q[1]) == 'h' ? MYSQL_RPL_ADMIN : MYSQL_RPL_MASTER ; + case 's': /* select or show */ + return tolower(q[1]) == 'h' ? MYSQL_RPL_ADMIN : MYSQL_RPL_SLAVE; + case 'f': /* flush */ + case 'r': /* repair */ + case 'g': /* grant */ + return MYSQL_RPL_ADMIN; + default: + return MYSQL_RPL_SLAVE; + } + } } return MYSQL_RPL_MASTER; /* By default, send to master */ } /**************************************************************************** -** Init MySQL structure or allocate one + Init MySQL structure or allocate one ****************************************************************************/ MYSQL * STDCALL @@ -1338,8 +1346,9 @@ mysql_init(MYSQL *mysql) mysql->options.connect_timeout=CONNECT_TIMEOUT; mysql->last_used_con = mysql->next_slave = mysql->master = mysql; mysql->last_used_slave = 0; - /* By default, we are a replication pivot. The caller must reset it - after we return if this is not the case. + /* + By default, we are a replication pivot. The caller must reset it + after we return if this is not the case. */ mysql->rpl_pivot = 1; #if defined(SIGPIPE) && defined(THREAD) && !defined(__WIN__) @@ -1403,37 +1412,42 @@ static void mysql_once_init() } /************************************************************************** -** Fill in SSL part of MYSQL structure and set 'use_ssl' flag. -** NB! Errors are not reported until you do mysql_real_connect. + Fill in SSL part of MYSQL structure and set 'use_ssl' flag. + NB! Errors are not reported until you do mysql_real_connect. **************************************************************************/ +#define strdup_if_not_null(A) (A) == 0 ? 0 : my_strdup((A),MYF(MY_WME)) + int STDCALL mysql_ssl_set(MYSQL *mysql __attribute__((unused)) , - const char *key __attribute__((unused)), - const char *cert __attribute__((unused)), - const char *ca __attribute__((unused)), - const char *capath __attribute__((unused)), - const char *cipher __attribute__((unused))) + const char *key __attribute__((unused)), + const char *cert __attribute__((unused)), + const char *ca __attribute__((unused)), + const char *capath __attribute__((unused)), + const char *cipher __attribute__((unused))) { #ifdef HAVE_OPENSSL - mysql->options.ssl_key = key==0 ? 0 : my_strdup(key,MYF(0)); - mysql->options.ssl_cert = cert==0 ? 0 : my_strdup(cert,MYF(0)); - mysql->options.ssl_ca = ca==0 ? 0 : my_strdup(ca,MYF(0)); - mysql->options.ssl_capath = capath==0 ? 0 : my_strdup(capath,MYF(0)); - mysql->options.ssl_cipher = cipher==0 ? 0 : my_strdup(cipher,MYF(0)); - mysql->options.use_ssl = TRUE; - mysql->connector_fd = (gptr)new_VioSSLConnectorFd(key, cert, ca, capath, cipher); - DBUG_PRINT("info",("mysql_ssl_set, context: %p",((struct st_VioSSLConnectorFd *)(mysql->connector_fd))->ssl_context_)); + mysql->options.ssl_key= strdup_if_not_null(key); + mysql->options.ssl_cert= strdup_if_not_null(cert); + mysql->options.ssl_ca= strdup_if_not_null(ca); + mysql->options.ssl_capath= strdup_if_not_null(capath); + mysql->options.ssl_cipher= strdup_if_not_null(cipher); + mysql->options.use_ssl= TRUE; + mysql->connector_fd = (gptr) new_VioSSLConnectorFd(key, cert, ca, capath, + cipher); + DBUG_PRINT("info",("mysql_ssl_set, context: %p", + ((struct st_VioSSLConnectorFd *) (mysql->connector_fd))-> + ssl_context_)); #endif return 0; } -/* -*************************************************************************** -** Free strings in the SSL structure and clear 'use_ssl' flag. -** NB! Errors are not reported until you do mysql_real_connect. -************************************************************************** -*/ + +/************************************************************************** + Free strings in the SSL structure and clear 'use_ssl' flag. + NB! Errors are not reported until you do mysql_real_connect. +**************************************************************************/ + int STDCALL mysql_ssl_clear(MYSQL *mysql __attribute__((unused))) { @@ -1443,21 +1457,21 @@ mysql_ssl_clear(MYSQL *mysql __attribute__((unused))) my_free(mysql->options.ssl_ca, MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->options.ssl_capath, MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->options.ssl_cipher, MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->connector_fd,MYF(MY_ALLOW_ZERO_PTR)); mysql->options.ssl_key = 0; mysql->options.ssl_cert = 0; mysql->options.ssl_ca = 0; mysql->options.ssl_capath = 0; mysql->options.ssl_cipher= 0; mysql->options.use_ssl = FALSE; - my_free(mysql->connector_fd,MYF(MY_ALLOW_ZERO_PTR)); mysql->connector_fd = 0; #endif /* HAVE_OPENSSL */ return 0; } /************************************************************************** -** Connect to sql server -** If host == 0 then use localhost + Connect to sql server + If host == 0 then use localhost **************************************************************************/ #ifdef USE_OLD_FUNCTIONS @@ -1481,8 +1495,8 @@ mysql_connect(MYSQL *mysql,const char *host, /* -** Note that the mysql argument must be initialized with mysql_init() -** before calling mysql_real_connect ! + Note that the mysql argument must be initialized with mysql_init() + before calling mysql_real_connect ! */ MYSQL * STDCALL @@ -1824,8 +1838,10 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, mysql->client_flag=client_flag; #ifdef HAVE_OPENSSL - /* Oops.. are we careful enough to not send ANY information */ - /* without encryption? */ + /* + Oops.. are we careful enough to not send ANY information without + encryption? + */ if (client_flag & CLIENT_SSL) { if (my_net_write(net,buff,(uint) (2)) || net_flush(net)) @@ -1897,7 +1913,9 @@ error: DBUG_RETURN(0); } + /* needed when we move MYSQL structure to a different address */ + static void mysql_fix_pointers(MYSQL* mysql, MYSQL* old_mysql) { MYSQL *tmp, *tmp_prev; @@ -1915,6 +1933,7 @@ static void mysql_fix_pointers(MYSQL* mysql, MYSQL* old_mysql) tmp_prev->next_slave = mysql; } + static my_bool mysql_reconnect(MYSQL *mysql) { MYSQL tmp_mysql; @@ -1947,7 +1966,7 @@ static my_bool mysql_reconnect(MYSQL *mysql) /************************************************************************** -** Change user and database + Change user and database **************************************************************************/ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, @@ -1980,7 +1999,7 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, /************************************************************************** -** Set current database + Set current database **************************************************************************/ int STDCALL @@ -1999,8 +2018,8 @@ mysql_select_db(MYSQL *mysql, const char *db) /************************************************************************* -** Send a QUIT to the server and close the connection -** If handle is alloced by mysql connect free it. + Send a QUIT to the server and close the connection + If handle is alloced by mysql connect free it. *************************************************************************/ void STDCALL @@ -2062,8 +2081,8 @@ mysql_close(MYSQL *mysql) /************************************************************************** -** Do a query. If query returned rows, free old rows. -** Read data by mysql_store_result or by repeat call of mysql_fetch_row + Do a query. If query returned rows, free old rows. + Read data by mysql_store_result or by repeat call of mysql_fetch_row **************************************************************************/ int STDCALL @@ -2287,8 +2306,8 @@ err: /************************************************************************** -** Alloc result struct for buffered results. All rows are read to buffer. -** mysql_data_seek may be used. + Alloc result struct for buffered results. All rows are read to buffer. + mysql_data_seek may be used. **************************************************************************/ MYSQL_RES * STDCALL @@ -2338,13 +2357,13 @@ mysql_store_result(MYSQL *mysql) /************************************************************************** -** Alloc struct for use with unbuffered reads. Data is fetched by domand -** when calling to mysql_fetch_row. -** mysql_data_seek is a noop. -** -** No other queries may be specified with the same MYSQL handle. -** There shouldn't be much processing per row because mysql server shouldn't -** have to wait for the client (and will not wait more than 30 sec/packet). + Alloc struct for use with unbuffered reads. Data is fetched by domand + when calling to mysql_fetch_row. + mysql_data_seek is a noop. + + No other queries may be specified with the same MYSQL handle. + There shouldn't be much processing per row because mysql server shouldn't + have to wait for the client (and will not wait more than 30 sec/packet). **************************************************************************/ MYSQL_RES * STDCALL @@ -2388,7 +2407,7 @@ mysql_use_result(MYSQL *mysql) /************************************************************************** -** Return next field of the query results + Return next field of the query results **************************************************************************/ MYSQL_FIELD * STDCALL @@ -2401,7 +2420,7 @@ mysql_fetch_field(MYSQL_RES *result) /************************************************************************** -** Return next row of the query results + Return next row of the query results **************************************************************************/ MYSQL_ROW STDCALL @@ -2442,9 +2461,9 @@ mysql_fetch_row(MYSQL_RES *res) } /************************************************************************** -** Get column lengths of the current row -** If one uses mysql_use_result, res->lengths contains the length information, -** else the lengths are calculated from the offset between pointers. + Get column lengths of the current row + If one uses mysql_use_result, res->lengths contains the length information, + else the lengths are calculated from the offset between pointers. **************************************************************************/ ulong * STDCALL @@ -2478,7 +2497,7 @@ mysql_fetch_lengths(MYSQL_RES *res) } /************************************************************************** -** Move to a specific row and column + Move to a specific row and column **************************************************************************/ void STDCALL @@ -2493,9 +2512,9 @@ mysql_data_seek(MYSQL_RES *result, my_ulonglong row) } /************************************************************************* -** put the row or field cursor one a position one got from mysql_row_tell() -** This doesn't restore any data. The next mysql_fetch_row or -** mysql_fetch_field will return the next row or field after the last used + put the row or field cursor one a position one got from mysql_row_tell() + This doesn't restore any data. The next mysql_fetch_row or + mysql_fetch_field will return the next row or field after the last used *************************************************************************/ MYSQL_ROW_OFFSET STDCALL @@ -2517,7 +2536,7 @@ mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET field_offset) } /***************************************************************************** -** List all databases + List all databases *****************************************************************************/ MYSQL_RES * STDCALL @@ -2534,8 +2553,8 @@ mysql_list_dbs(MYSQL *mysql, const char *wild) /***************************************************************************** -** List all tables in a database -** If wild is given then only the tables matching wild is returned + List all tables in a database + If wild is given then only the tables matching wild is returned *****************************************************************************/ MYSQL_RES * STDCALL @@ -2552,10 +2571,10 @@ mysql_list_tables(MYSQL *mysql, const char *wild) /************************************************************************** -** List all fields in a table -** If wild is given then only the fields matching wild is returned -** Instead of this use query: -** show fields in 'table' like "wild" + List all fields in a table + If wild is given then only the fields matching wild is returned + Instead of this use query: + show fields in 'table' like "wild" **************************************************************************/ MYSQL_RES * STDCALL @@ -2774,8 +2793,8 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg) } /**************************************************************************** -** Functions to get information from the MySQL structure -** These are functions to make shared libraries more usable. + Functions to get information from the MySQL structure + These are functions to make shared libraries more usable. ****************************************************************************/ /* MYSQL_RES */ @@ -2867,13 +2886,13 @@ uint STDCALL mysql_thread_safe(void) } /**************************************************************************** -** Some support functions + Some support functions ****************************************************************************/ /* -** Add escape characters to a string (blob?) to make it suitable for a insert -** to should at least have place for length*2+1 chars -** Returns the length of the to string + Add escape characters to a string (blob?) to make it suitable for a insert + to should at least have place for length*2+1 chars + Returns the length of the to string */ ulong STDCALL diff --git a/libmysql/manager.c b/libmysql/manager.c index 330c070777c..a38c7fe1cd7 100644 --- a/libmysql/manager.c +++ b/libmysql/manager.c @@ -54,9 +54,6 @@ #endif #define RES_BUF_SHIFT 5 -#ifndef __WIN__ -#define SOCKET_ERROR -1 -#endif #define NET_BUF_SIZE 2048 MYSQL_MANAGER* STDCALL mysql_manager_init(MYSQL_MANAGER* con) @@ -101,7 +98,7 @@ MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con, if (!passwd) passwd=""; - if ((sock=(my_socket)socket(AF_INET,SOCK_STREAM,0)) == SOCKET_ERROR) + if ((sock=(my_socket)socket(AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET) { con->last_errno=errno; strmov(con->last_error,"Cannot create socket"); @@ -185,6 +182,7 @@ MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con, strmov(con->user,user); strmov(con->passwd,passwd); return con; + err: { my_bool free_me=con->free_me; @@ -195,18 +193,20 @@ err: return 0; } -void STDCALL mysql_manager_close(MYSQL_MANAGER* con) +void STDCALL mysql_manager_close(MYSQL_MANAGER* con) { - my_free((gptr)con->host,MYF(MY_ALLOW_ZERO_PTR)); - /* no need to free con->user and con->passwd, because they were - allocated in my_multimalloc() along with con->host, freeing - con->hosts frees the whole block + /* + No need to free con->user and con->passwd, because they were + allocated in my_multimalloc() along with con->host, freeing + con->hosts frees the whole block */ + my_free((gptr)con->host,MYF(MY_ALLOW_ZERO_PTR)); net_end(&con->net); if (con->free_me) my_free((gptr)con,MYF(0)); } + int STDCALL mysql_manager_command(MYSQL_MANAGER* con,const char* cmd, int cmd_len) { @@ -222,8 +222,9 @@ int STDCALL mysql_manager_command(MYSQL_MANAGER* con,const char* cmd, return 0; } -int STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con, char* res_buf, - int res_buf_size) + +int STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con, char* res_buf, + int res_buf_size) { char* res_buf_end=res_buf+res_buf_size; char* net_buf=(char*) con->net.read_pos, *net_buf_end; @@ -252,7 +253,7 @@ int STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con, char* res_buf, res_buf_end[-1]=0; for (;net_buf<net_buf_end && res_buf < res_buf_end;res_buf++,net_buf++) { - if((*res_buf=*net_buf) == '\r') + if ((*res_buf=*net_buf) == '\r') { *res_buf=0; break; |