Skip to content

Commit 7e1ce53

Browse files
author
hf@deer.(none)
committed
SCRUM
including client code into embedded server code to guess what library to use added net_field_length moved to pack.c
1 parent 66ecacb commit 7e1ce53

7 files changed

Lines changed: 58 additions & 77 deletions

File tree

include/mysql.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ typedef struct st_mysql_data {
134134
#endif
135135
} MYSQL_DATA;
136136

137+
enum mysql_option
138+
{
139+
MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
140+
MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
141+
MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
142+
MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
143+
MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
144+
MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
145+
MYSQL_OPT_GUESS_CONNECTION
146+
};
147+
137148
struct st_mysql_options {
138149
unsigned int connect_timeout, read_timeout, write_timeout;
139150
unsigned int port, protocol;
@@ -168,15 +179,7 @@ struct st_mysql_options {
168179
#if !defined(CHECK_EMBEDDED_DIFFERENCES) || defined(EMBEDDED_LIBRARY)
169180
my_bool separate_thread;
170181
#endif
171-
};
172-
173-
enum mysql_option
174-
{
175-
MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
176-
MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
177-
MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
178-
MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
179-
MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT
182+
enum mysql_option methods_to_use;
180183
};
181184

182185
enum mysql_status

include/mysql_com.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ void my_thread_end(void);
341341
#ifdef _global_h
342342
ulong STDCALL net_field_length(uchar **packet);
343343
my_ulonglong net_field_length_ll(uchar **packet);
344+
char *net_store_length(char *pkg, ulonglong length);
344345
#endif
345346

346347
#ifdef __cplusplus

libmysql/libmysql.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,39 +1730,6 @@ static void store_param_type(NET *net, uint type)
17301730
net->write_pos+=2;
17311731
}
17321732

1733-
/*
1734-
Store the length of parameter data
1735-
(Same function as in sql/net_pkg.cc)
1736-
*/
1737-
1738-
char *
1739-
net_store_length(char *pkg, ulong length)
1740-
{
1741-
uchar *packet=(uchar*) pkg;
1742-
if (length < 251)
1743-
{
1744-
*packet=(uchar) length;
1745-
return (char*) packet+1;
1746-
}
1747-
/* 251 is reserved for NULL */
1748-
if (length < 65536L)
1749-
{
1750-
*packet++=252;
1751-
int2store(packet,(uint) length);
1752-
return (char*) packet+2;
1753-
}
1754-
if (length < 16777216L)
1755-
{
1756-
*packet++=253;
1757-
int3store(packet,(ulong) length);
1758-
return (char*) packet+3;
1759-
}
1760-
*packet++=254;
1761-
int8store(packet, (ulonglong) length);
1762-
return (char*) packet+9;
1763-
}
1764-
1765-
17661733
/****************************************************************************
17671734
Functions to store parameter data from a prepared statement.
17681735

libmysqld/libmysqld.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command,
6868
*/
6969
void mysql_read_default_options(struct st_mysql_options *options,
7070
const char *filename,const char *group);
71+
MYSQL * STDCALL
72+
cli_mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
73+
const char *passwd, const char *db,
74+
uint port, const char *unix_socket,ulong client_flag);
7175

7276
#ifdef HAVE_GETPWUID
7377
struct passwd *getpwuid(uid_t);
@@ -179,7 +183,7 @@ static MYSQL_METHODS embedded_methods=
179183

180184
MYSQL * STDCALL
181185
mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
182-
const char *passwd __attribute__((unused)), const char *db,
186+
const char *passwd, const char *db,
183187
uint port, const char *unix_socket,ulong client_flag)
184188
{
185189
char *db_name;
@@ -189,6 +193,14 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
189193
db ? db : "(Null)",
190194
user ? user : "(Null)"));
191195

196+
if (mysql->options.methods_to_use == MYSQL_OPT_USE_REMOTE_CONNECTION)
197+
cli_mysql_real_connect(mysql, host, user,
198+
passwd, db, port, unix_socket, client_flag);
199+
if ((mysql->options.methods_to_use == MYSQL_OPT_GUESS_CONNECTION) &&
200+
host && strcmp(host,LOCAL_HOST))
201+
cli_mysql_real_connect(mysql, host, user,
202+
passwd, db, port, unix_socket, client_flag);
203+
192204
mysql->methods= &embedded_methods;
193205

194206
/* use default options */

sql-common/client.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,7 @@ mysql_init(MYSQL *mysql)
13031303
#ifdef HAVE_SMEM
13041304
mysql->options.shared_memory_base_name= (char*) def_shared_memory_base_name;
13051305
#endif
1306+
mysql->options.methods_to_use= MYSQL_OPT_GUESS_CONNECTION;
13061307
return mysql;
13071308
}
13081309

@@ -2512,6 +2513,10 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg)
25122513
my_free(mysql->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
25132514
mysql->options.shared_memory_base_name=my_strdup(arg,MYF(MY_WME));
25142515
#endif
2516+
case MYSQL_OPT_USE_REMOTE_CONNECTION:
2517+
case MYSQL_OPT_USE_EMBEDDED_CONNECTION:
2518+
case MYSQL_OPT_GUESS_CONNECTION:
2519+
mysql->options.methods_to_use= option;
25152520
break;
25162521
default:
25172522
DBUG_RETURN(1);

sql-common/pack.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,30 @@ void my_net_local_init(NET *net)
9696
net->max_packet_size= max(net_buffer_length, max_allowed_packet);
9797
}
9898

99+
char *
100+
net_store_length(char *pkg, ulonglong length)
101+
{
102+
uchar *packet=(uchar*) pkg;
103+
if (length < LL(251))
104+
{
105+
*packet=(uchar) length;
106+
return (char*) packet+1;
107+
}
108+
/* 251 is reserved for NULL */
109+
if (length < LL(65536))
110+
{
111+
*packet++=252;
112+
int2store(packet,(uint) length);
113+
return (char*) packet+2;
114+
}
115+
if (length < LL(16777216))
116+
{
117+
*packet++=253;
118+
int3store(packet,(ulong) length);
119+
return (char*) packet+3;
120+
}
121+
*packet++=254;
122+
int8store(packet,length);
123+
return (char*) packet+8;
124+
}
125+

sql/protocol.cc

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -349,40 +349,6 @@ send_eof(THD *thd, bool no_flush)
349349
}
350350
#endif /* EMBEDDED_LIBRARY */
351351

352-
353-
/****************************************************************************
354-
Store a field length in logical packet
355-
This is used to code the string length for normal protocol
356-
****************************************************************************/
357-
358-
char *
359-
net_store_length(char *pkg, ulonglong length)
360-
{
361-
uchar *packet=(uchar*) pkg;
362-
if (length < LL(251))
363-
{
364-
*packet=(uchar) length;
365-
return (char*) packet+1;
366-
}
367-
/* 251 is reserved for NULL */
368-
if (length < LL(65536))
369-
{
370-
*packet++=252;
371-
int2store(packet,(uint) length);
372-
return (char*) packet+2;
373-
}
374-
if (length < LL(16777216))
375-
{
376-
*packet++=253;
377-
int3store(packet,(ulong) length);
378-
return (char*) packet+3;
379-
}
380-
*packet++=254;
381-
int8store(packet,length);
382-
return (char*) packet+8;
383-
}
384-
385-
386352
/*
387353
Faster net_store_length when we know length is a 32 bit integer
388354
*/

0 commit comments

Comments
 (0)