diff options
author | unknown <hf@deer.(none)> | 2003-06-18 15:58:57 +0500 |
---|---|---|
committer | unknown <hf@deer.(none)> | 2003-06-18 15:58:57 +0500 |
commit | 13e8bf67fc63280f76023fab73c373f33e363bfc (patch) | |
tree | f2de81966600f6bb3e831afc62a7ed1d9babbf42 | |
parent | 4c7431dc906cd5e5dba8515ec63107b590708898 (diff) | |
download | mariadb-git-13e8bf67fc63280f76023fab73c373f33e363bfc.tar.gz |
SCRUM
including client code into embedded server
code to guess what library to use added
net_field_length moved to pack.c
include/mysql.h:
typedefinitions moved for suitability
mysql_option.methods_to_use added
include/mysql_com.h:
net_store_length declaration
libmysql/libmysql.c:
net_store_length moved to sql-common/pack.c
libmysqld/libmysqld.c:
added code to guess whether to use remote or embedded connection
sql-common/client.c:
options checking added
sql-common/pack.c:
net_store_length implementation moved here
sql/protocol.cc:
net_store_length moved to sql-common/pack.c
-rw-r--r-- | include/mysql.h | 21 | ||||
-rw-r--r-- | include/mysql_com.h | 1 | ||||
-rw-r--r-- | libmysql/libmysql.c | 33 | ||||
-rw-r--r-- | libmysqld/libmysqld.c | 14 | ||||
-rw-r--r-- | sql-common/client.c | 5 | ||||
-rw-r--r-- | sql-common/pack.c | 27 | ||||
-rw-r--r-- | sql/protocol.cc | 34 |
7 files changed, 58 insertions, 77 deletions
diff --git a/include/mysql.h b/include/mysql.h index 81e50525614..a6bdb39e5ec 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -134,6 +134,17 @@ typedef struct st_mysql_data { #endif } MYSQL_DATA; +enum mysql_option +{ + MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE, + MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, + MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE, + MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT, + MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT, + MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, + MYSQL_OPT_GUESS_CONNECTION +}; + struct st_mysql_options { unsigned int connect_timeout, read_timeout, write_timeout; unsigned int port, protocol; @@ -168,15 +179,7 @@ struct st_mysql_options { #if !defined(CHECK_EMBEDDED_DIFFERENCES) || defined(EMBEDDED_LIBRARY) my_bool separate_thread; #endif -}; - -enum mysql_option -{ - MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE, - MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, - MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE, - MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT, - MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT + enum mysql_option methods_to_use; }; enum mysql_status diff --git a/include/mysql_com.h b/include/mysql_com.h index c480273f3e9..a89569c451e 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -341,6 +341,7 @@ void my_thread_end(void); #ifdef _global_h ulong STDCALL net_field_length(uchar **packet); my_ulonglong net_field_length_ll(uchar **packet); +char *net_store_length(char *pkg, ulonglong length); #endif #ifdef __cplusplus diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 495647bf302..1a5e91045ae 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -1730,39 +1730,6 @@ static void store_param_type(NET *net, uint type) net->write_pos+=2; } -/* - Store the length of parameter data - (Same function as in sql/net_pkg.cc) -*/ - -char * -net_store_length(char *pkg, ulong length) -{ - uchar *packet=(uchar*) pkg; - if (length < 251) - { - *packet=(uchar) length; - return (char*) packet+1; - } - /* 251 is reserved for NULL */ - if (length < 65536L) - { - *packet++=252; - int2store(packet,(uint) length); - return (char*) packet+2; - } - if (length < 16777216L) - { - *packet++=253; - int3store(packet,(ulong) length); - return (char*) packet+3; - } - *packet++=254; - int8store(packet, (ulonglong) length); - return (char*) packet+9; -} - - /**************************************************************************** Functions to store parameter data from a prepared statement. diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c index efc3ee353e8..5b738f7f95b 100644 --- a/libmysqld/libmysqld.c +++ b/libmysqld/libmysqld.c @@ -68,6 +68,10 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, */ void mysql_read_default_options(struct st_mysql_options *options, const char *filename,const char *group); +MYSQL * STDCALL +cli_mysql_real_connect(MYSQL *mysql,const char *host, const char *user, + const char *passwd, const char *db, + uint port, const char *unix_socket,ulong client_flag); #ifdef HAVE_GETPWUID struct passwd *getpwuid(uid_t); @@ -179,7 +183,7 @@ static MYSQL_METHODS embedded_methods= MYSQL * STDCALL mysql_real_connect(MYSQL *mysql,const char *host, const char *user, - const char *passwd __attribute__((unused)), const char *db, + const char *passwd, const char *db, uint port, const char *unix_socket,ulong client_flag) { char *db_name; @@ -189,6 +193,14 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, db ? db : "(Null)", user ? user : "(Null)")); + if (mysql->options.methods_to_use == MYSQL_OPT_USE_REMOTE_CONNECTION) + cli_mysql_real_connect(mysql, host, user, + passwd, db, port, unix_socket, client_flag); + if ((mysql->options.methods_to_use == MYSQL_OPT_GUESS_CONNECTION) && + host && strcmp(host,LOCAL_HOST)) + cli_mysql_real_connect(mysql, host, user, + passwd, db, port, unix_socket, client_flag); + mysql->methods= &embedded_methods; /* use default options */ diff --git a/sql-common/client.c b/sql-common/client.c index 7d82ff0d209..8a6f3ed1e3d 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1303,6 +1303,7 @@ mysql_init(MYSQL *mysql) #ifdef HAVE_SMEM mysql->options.shared_memory_base_name= (char*) def_shared_memory_base_name; #endif + mysql->options.methods_to_use= MYSQL_OPT_GUESS_CONNECTION; return mysql; } @@ -2512,6 +2513,10 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg) my_free(mysql->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR)); mysql->options.shared_memory_base_name=my_strdup(arg,MYF(MY_WME)); #endif + case MYSQL_OPT_USE_REMOTE_CONNECTION: + case MYSQL_OPT_USE_EMBEDDED_CONNECTION: + case MYSQL_OPT_GUESS_CONNECTION: + mysql->options.methods_to_use= option; break; default: DBUG_RETURN(1); diff --git a/sql-common/pack.c b/sql-common/pack.c index 16cc13eddbd..43e0098bf29 100644 --- a/sql-common/pack.c +++ b/sql-common/pack.c @@ -96,3 +96,30 @@ void my_net_local_init(NET *net) net->max_packet_size= max(net_buffer_length, max_allowed_packet); } +char * +net_store_length(char *pkg, ulonglong length) +{ + uchar *packet=(uchar*) pkg; + if (length < LL(251)) + { + *packet=(uchar) length; + return (char*) packet+1; + } + /* 251 is reserved for NULL */ + if (length < LL(65536)) + { + *packet++=252; + int2store(packet,(uint) length); + return (char*) packet+2; + } + if (length < LL(16777216)) + { + *packet++=253; + int3store(packet,(ulong) length); + return (char*) packet+3; + } + *packet++=254; + int8store(packet,length); + return (char*) packet+8; +} + diff --git a/sql/protocol.cc b/sql/protocol.cc index da363a478fd..3933cd08d40 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -349,40 +349,6 @@ send_eof(THD *thd, bool no_flush) } #endif /* EMBEDDED_LIBRARY */ - -/**************************************************************************** - Store a field length in logical packet - This is used to code the string length for normal protocol -****************************************************************************/ - -char * -net_store_length(char *pkg, ulonglong length) -{ - uchar *packet=(uchar*) pkg; - if (length < LL(251)) - { - *packet=(uchar) length; - return (char*) packet+1; - } - /* 251 is reserved for NULL */ - if (length < LL(65536)) - { - *packet++=252; - int2store(packet,(uint) length); - return (char*) packet+2; - } - if (length < LL(16777216)) - { - *packet++=253; - int3store(packet,(ulong) length); - return (char*) packet+3; - } - *packet++=254; - int8store(packet,length); - return (char*) packet+8; -} - - /* Faster net_store_length when we know length is a 32 bit integer */ |