Skip to content

Commit c4e3a62

Browse files
author
hf@deer.(none)
committed
SCRUM
client capabilities included into libmysqld some API methods became "virtual" lots of duplicated code removed IMHO all the above made library's code way more pleasant to look at, didn't it?
1 parent f5bd641 commit c4e3a62

19 files changed

Lines changed: 217 additions & 1568 deletions

.bzrignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,7 @@ vio/test-ssl
622622
vio/test-sslclient
623623
vio/test-sslserver
624624
vio/viotest-ssl
625+
libmysqld/client.c
626+
libmysqld/client_settings.h
627+
libmysqld/libmysql.c
628+
libmysqld/pack.c

client/mysqltest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static uint out_length;
319319
static int eval_result = 0;
320320

321321
/* Disable functions that only exist in MySQL 4.0 */
322-
#if MYSQL_VERSION_ID < 40000 || defined(EMBEDDED_LIBRARY)
322+
#if MYSQL_VERSION_ID < 40000
323323
void mysql_enable_rpl_parse(MYSQL* mysql __attribute__((unused))) {}
324324
void mysql_disable_rpl_parse(MYSQL* mysql __attribute__((unused))) {}
325325
int mysql_rpl_parse_enabled(MYSQL* mysql __attribute__((unused))) { return 1; }

include/mysql.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ enum mysql_rpl_type
201201
MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, MYSQL_RPL_ADMIN
202202
};
203203

204+
struct st_mysql_methods;
204205

205206
#if !defined(CHECK_EMBEDDED_DIFFERENCES) || !defined(EMBEDDED_LIBRARY)
206207

@@ -247,11 +248,13 @@ typedef struct st_mysql
247248
struct st_mysql* last_used_con;
248249

249250
LIST *stmts; /* list of all statements */
251+
const struct st_mysql_methods *methods;
250252
#if !defined(CHECK_EMBEDDED_DIFFERENCES)
251253
struct st_mysql_res *result;
252254
void *thd;
253255
unsigned int last_errno;
254256
char *last_error;
257+
char sqlstate[SQLSTATE_LENGTH+1]; /* Used by embedded server */
255258
#endif
256259
} MYSQL;
257260

@@ -378,12 +381,10 @@ MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
378381
unsigned int port,
379382
const char *unix_socket,
380383
unsigned long clientflag);
381-
void STDCALL mysql_close(MYSQL *sock);
382384
int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
383385
int STDCALL mysql_query(MYSQL *mysql, const char *q);
384386
int STDCALL mysql_send_query(MYSQL *mysql, const char *q,
385387
unsigned long length);
386-
my_bool STDCALL mysql_read_query_result(MYSQL *mysql);
387388
int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
388389
unsigned long length);
389390
/* perform query on master */
@@ -444,8 +445,6 @@ MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
444445
MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
445446
const char *wild);
446447
MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
447-
MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
448-
MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
449448
int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
450449
const char *arg);
451450
void STDCALL mysql_free_result(MYSQL_RES *result);
@@ -566,6 +565,25 @@ typedef struct st_mysql_stmt
566565
} MYSQL_STMT;
567566

568567

568+
#define mysql_close(sock) (*(sock)->methods->close)(sock)
569+
#define mysql_read_query_result(mysql) (*(mysql)->methods->read_query_result)(mysql)
570+
#define mysql_store_result(mysql) (*(mysql)->methods->store_result)(mysql)
571+
#define mysql_use_result(mysql) (*(mysql)->methods->use_result)(mysql)
572+
573+
typedef struct st_mysql_methods
574+
{
575+
void STDCALL (*close)(MYSQL *sock);
576+
my_bool STDCALL (*read_query_result)(MYSQL *mysql);
577+
my_bool STDCALL (*advanced_command)(MYSQL *mysql,
578+
enum enum_server_command command,
579+
const char *header,
580+
ulong header_length,
581+
const char *arg,
582+
ulong arg_length, my_bool skip_check);
583+
MYSQL_RES * STDCALL (*store_result)(MYSQL *mysql);
584+
MYSQL_RES * STDCALL (*use_result)(MYSQL *mysql);
585+
} MYSQL_METHODS;
586+
569587
MYSQL_STMT * STDCALL mysql_prepare(MYSQL * mysql, const char *query,
570588
unsigned long length);
571589
int STDCALL mysql_execute(MYSQL_STMT * stmt);

include/mysql_com.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ void my_net_local_init(NET *net);
232232
void net_end(NET *net);
233233
void net_clear(NET *net);
234234
my_bool net_realloc(NET *net, unsigned long length);
235+
236+
/*HFTODO - should remove it
237+
*/
235238
#ifndef EMBEDDED_LIBRARY
236239
my_bool net_flush(NET *net);
237240
#else

include/mysql_embed.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
#ifdef EMBEDDED_LIBRARY
2020

2121
/* Things we don't need in the embedded version of MySQL */
22+
/*HFTODO
23+
#undef HAVE_VIO - if we don't want client in embedded library
24+
*/
2225

2326
#undef HAVE_PSTACK /* No stacktrace */
2427
#undef HAVE_DLOPEN /* No udf functions */
2528
#undef HAVE_OPENSSL
26-
#undef HAVE_VIO
2729
#undef HAVE_ISAM
2830
#undef HAVE_SMEM /* No shared memory */
2931

include/sql_common.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ my_ulonglong net_field_length_ll(uchar **packet);
2727

2828
MYSQL_FIELD *unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
2929
my_bool default_value, uint server_capabilities);
30-
my_bool advanced_command(MYSQL *mysql, enum enum_server_command command,
31-
const char *header, ulong header_length,
32-
const char *arg, ulong arg_length, my_bool skip_check);
3330
void free_rows(MYSQL_DATA *cur);
3431
MYSQL_DATA *read_rows (MYSQL *mysql,MYSQL_FIELD *fields,
3532
uint field_count);
@@ -38,6 +35,8 @@ void fetch_lengths(ulong *to, MYSQL_ROW column, uint field_count);
3835
void free_old_query(MYSQL *mysql);
3936
void end_server(MYSQL *mysql);
4037
my_bool mysql_reconnect(MYSQL *mysql);
38+
void mysql_read_default_options(struct st_mysql_options *options,
39+
const char *filename,const char *group);
4140
#ifdef __cplusplus
4241
}
4342
#endif

include/violite.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ enum SSL_type
220220
};
221221

222222

223-
#ifndef EMBEDDED_LIBRARY
223+
/* HFTODO - hide this if we don't want client in embedded server
224+
*/
224225
/* This structure is for every connection on both sides */
225226
struct st_vio
226227
{
@@ -263,5 +264,4 @@ struct st_vio
263264
#endif /* HAVE_SMEM */
264265
#endif /* HAVE_VIO */
265266
};
266-
#endif /* EMBEDDED_LIBRARY */
267267
#endif /* vio_violite_h_ */

libmysql/client_settings.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
1616

1717

18-
static my_bool mysql_client_init=0;
1918
extern uint mysql_port;
2019
extern my_string mysql_unix_port;
2120

@@ -35,7 +34,7 @@ char *shared_memory_base_name=0;
3534
const char *def_shared_memory_base_name=default_shared_memory_base_name;
3635
#endif
3736

38-
static my_bool org_my_init_done=0;
37+
extern my_bool org_my_init_done;
3938

4039
sig_handler pipe_sig_handler(int sig __attribute__((unused)));
4140
my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list);
@@ -56,3 +55,8 @@ my_bool send_file_to_server(MYSQL *mysql, const char *filename);
5655
#define set_sigpipe(mysql)
5756
#define reset_sigpipe(mysql)
5857
#endif
58+
59+
#define CLI_MYSQL_USE_RESULT cli_mysql_use_result
60+
61+
MYSQL_RES * STDCALL cli_mysql_use_result(MYSQL *mysql);
62+

libmysql/libmysql.c

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,20 @@
5858
#endif
5959

6060
#include <sql_common.h>
61+
#include "client_settings.h"
62+
63+
#ifdef EMBEDDED_LIBRARY
64+
#ifdef net_flush
65+
#undef net_flush
66+
#endif
67+
68+
my_bool net_flush(NET *net);
69+
70+
#endif
71+
6172

6273
uint mysql_port=0;
6374
my_string mysql_unix_port=0;
64-
ulong net_buffer_length=8192;
65-
ulong max_allowed_packet= 1024L*1024L*1024L;
66-
ulong net_read_timeout= NET_READ_TIMEOUT;
67-
ulong net_write_timeout= NET_WRITE_TIMEOUT;
6875

6976
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG \
7077
| CLIENT_LOCAL_FILES | CLIENT_TRANSACTIONS \
@@ -101,8 +108,9 @@ sig_handler pipe_sig_handler(int sig);
101108
static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to,
102109
const char *from, ulong length);
103110
my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list);
104-
static my_bool org_my_init_done=0;
111+
my_bool org_my_init_done=0;
105112

113+
#ifndef EMBEDDED_LIBRARY
106114
int STDCALL mysql_server_init(int argc __attribute__((unused)),
107115
char **argv __attribute__((unused)),
108116
char **groups __attribute__((unused)))
@@ -119,6 +127,7 @@ void STDCALL mysql_server_end()
119127
else
120128
mysql_thread_end();
121129
}
130+
#endif /*EMBEDDED_LIBRARY*/
122131

123132
my_bool STDCALL mysql_thread_init()
124133
{
@@ -140,17 +149,6 @@ void STDCALL mysql_thread_end()
140149
Let the user specify that we don't want SIGPIPE; This doesn't however work
141150
with threaded applications as we can have multiple read in progress.
142151
*/
143-
144-
#if !defined(__WIN__) && defined(SIGPIPE) && !defined(THREAD)
145-
#define init_sigpipe_variables sig_return old_signal_handler=(sig_return) 0
146-
#define set_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) old_signal_handler=signal(SIGPIPE,pipe_sig_handler)
147-
#define reset_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) signal(SIGPIPE,old_signal_handler);
148-
#else
149-
#define init_sigpipe_variables
150-
#define set_sigpipe(mysql)
151-
#define reset_sigpipe(mysql)
152-
#endif
153-
154152
static MYSQL* spawn_init(MYSQL* parent, const char* host,
155153
unsigned int port,
156154
const char* user,
@@ -846,8 +844,7 @@ STDCALL mysql_add_slave(MYSQL* mysql, const char* host,
846844
have to wait for the client (and will not wait more than 30 sec/packet).
847845
**************************************************************************/
848846

849-
MYSQL_RES * STDCALL
850-
mysql_use_result(MYSQL *mysql)
847+
MYSQL_RES * STDCALL CLI_MYSQL_USE_RESULT(MYSQL *mysql)
851848
{
852849
MYSQL_RES *result;
853850
DBUG_ENTER("mysql_use_result");
@@ -1253,19 +1250,6 @@ uint STDCALL mysql_thread_safe(void)
12531250
Some support functions
12541251
****************************************************************************/
12551252

1256-
/*
1257-
Functions called my my_net_init() to set some application specific variables
1258-
*/
1259-
1260-
void my_net_local_init(NET *net)
1261-
{
1262-
net->max_packet= (uint) net_buffer_length;
1263-
net->read_timeout= (uint) net_read_timeout;
1264-
net->write_timeout=(uint) net_write_timeout;
1265-
net->retry_count= 1;
1266-
net->max_packet_size= max(net_buffer_length, max_allowed_packet);
1267-
}
1268-
12691253
/*
12701254
Add escape characters to a string (blob?) to make it suitable for a insert
12711255
to should at least have place for length*2+1 chars
@@ -1999,8 +1983,9 @@ static my_bool execute(MYSQL_STMT * stmt, char *packet, ulong length)
19991983

20001984
mysql->last_used_con= mysql;
20011985
int4store(buff, stmt->stmt_id); /* Send stmt id to server */
2002-
if (advanced_command(mysql, COM_EXECUTE, buff, MYSQL_STMT_HEADER, packet,
2003-
length, 1) ||
1986+
if ((*mysql->methods->advanced_command)(mysql, COM_EXECUTE, buff,
1987+
MYSQL_STMT_HEADER, packet,
1988+
length, 1) ||
20041989
mysql_read_query_result(mysql))
20051990
{
20061991
set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
@@ -2292,8 +2277,9 @@ mysql_send_long_data(MYSQL_STMT *stmt, uint param_number,
22922277
Note that we don't get any ok packet from the server in this case
22932278
This is intentional to save bandwidth.
22942279
*/
2295-
if (advanced_command(mysql, COM_LONG_DATA, extra_data,
2296-
MYSQL_LONG_DATA_HEADER, data, length, 1))
2280+
if ((*mysql->methods->advanced_command)(mysql, COM_LONG_DATA, extra_data,
2281+
MYSQL_LONG_DATA_HEADER, data,
2282+
length, 1))
22972283
{
22982284
set_stmt_errmsg(stmt, mysql->net.last_error,
22992285
mysql->net.last_errno, mysql->net.sqlstate);

libmysqld/Makefile.am

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ noinst_LIBRARIES = libmysqld_int.a
3232
pkglib_LIBRARIES = libmysqld.a
3333
SUBDIRS = . examples
3434
libmysqld_sources= libmysqld.c lib_sql.cc
35-
libmysqlsources = errmsg.c get_password.c
35+
libmysqlsources = errmsg.c get_password.c libmysql.c client.c pack.c
3636

3737
noinst_HEADERS = embedded_priv.h
3838

@@ -57,8 +57,6 @@ sqlsources = derror.cc field.cc field_conv.cc filesort.cc \
5757
unireg.cc uniques.cc stacktrace.c sql_union.cc hash_filo.cc \
5858
spatial.cc gstream.cc sql_help.cc
5959

60-
EXTRA_DIST = lib_vio.c
61-
6260
libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources)
6361
libmysqld_a_SOURCES=
6462

@@ -74,7 +72,8 @@ INC_LIB= $(top_builddir)/regex/libregex.a \
7472
$(top_builddir)/mysys/libmysys.a \
7573
$(top_builddir)/strings/libmystrings.a \
7674
$(top_builddir)/dbug/libdbug.a \
77-
$(top_builddir)/regex/libregex.a
75+
$(top_builddir)/regex/libregex.a \
76+
$(top_builddir)/vio/libvio.a
7877

7978
#
8079
# To make it easy for the end user to use the embedded library we
@@ -115,11 +114,14 @@ link_sources:
115114
for f in $(libmysqlsources); do \
116115
rm -f $(srcdir)/$$f; \
117116
@LN_CP_F@ $(srcdir)/../libmysql/$$f $(srcdir)/$$f; \
118-
done
117+
done; \
118+
@LN_CP_F@ $(srcdir)/../libmysql/client_settings.h $(srcdir)/client_settings.h;
119+
119120

120121
clean-local:
121122
rm -f `echo $(sqlsources) $(libmysqlsources) | sed "s;\.lo;.c;g"` \
122-
$(top_srcdir)/linked_libmysqld_sources
123+
$(top_srcdir)/linked_libmysqld_sources; \
124+
rm -f client_settings.h
123125

124126
# Don't update the files from bitkeeper
125127
%::SCCS/s.%

0 commit comments

Comments
 (0)