summaryrefslogtreecommitdiff
path: root/sql-common
diff options
context:
space:
mode:
authorunknown <hf@deer.(none)>2003-06-17 21:32:31 +0500
committerunknown <hf@deer.(none)>2003-06-17 21:32:31 +0500
commitef726bbff367ab6c5aa735655d8ff6c3fdccdb7d (patch)
tree6f68559f6a79f53926e1432aa904b9520399b6a8 /sql-common
parent5551e0df2a5208ead3ca7d024083e572e21f8845 (diff)
downloadmariadb-git-ef726bbff367ab6c5aa735655d8ff6c3fdccdb7d.tar.gz
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? BitKeeper/deleted/.del-lib_vio.c~d779731a1e391220: Delete: libmysqld/lib_vio.c BitKeeper/etc/ignore: Added libmysqld/client.c libmysqld/client_settings.h libmysqld/libmysql.c libmysqld/pack.c to the ignore list client/mysqltest.c: we don't need this now include/mysql.h: MYSQL and related structures unified four methods made "virtual" relative wrappers added include/mysql_com.h: todo added include/mysql_embed.h: now we include implementations of Vio structure in libmysqld include/sql_common.h: declarations changed include/violite.h: implementation of Vio included in libmysqld libmysql/client_settings.h: changes to make this working with both client and embedded libmysql/libmysql.c: global variables and my_net_local_init moved to sql-common/pack.c libmysqld/Makefile.am: libmysql.c, client.c, pack.c symlinked and added to sources lib_vio.c removed libmysqld/examples/Makefile.am: now we need CLIENT_LIBS here libmysqld/lib_sql.cc: code duplications removed emb_advanced_command was made from simple_command libmysqld/libmysqld.c: duplicated code removed sql-common/client.c: code trimmed with new model of calling sql-common/pack.c: some code moved here from libmysql.c and protocol.cc sql/client_settings.h: we don't need mysql_use_result for mini_client sql/net_serv.cc: file included in embedded server sql/protocol.cc: code moved to sql-common/pack.c
Diffstat (limited to 'sql-common')
-rw-r--r--sql-common/client.c68
-rw-r--r--sql-common/pack.c34
2 files changed, 88 insertions, 14 deletions
diff --git a/sql-common/client.c b/sql-common/client.c
index 3c025d18bd6..207744a773f 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -40,6 +40,32 @@
#if defined(MYSQL_SERVER) || defined(HAVE_EXTERNAL_CLIENT)
#include "mysql.h"
+
+#ifdef EMBEDDED_LIBRARY
+
+#ifdef MYSQL_SERVER
+#undef MYSQL_SERVER
+#endif
+
+#ifndef MYSQL_CLIENT
+#define MYSQL_CLIENT
+#endif
+
+#define CLI_MYSQL_REAL_CONNECT cli_mysql_real_connect
+
+#ifdef net_flush
+#undef net_flush
+#endif
+my_bool net_flush(NET *net);
+
+#else /*EMBEDDED_LIBRARY*/
+#define CLI_MYSQL_REAL_CONNECT mysql_real_connect
+#endif /*EMBEDDED_LIBRARY*/
+
+#ifdef MYSQL_CLIENT
+static my_bool mysql_client_init=0;
+#endif
+
#if !defined(MYSQL_SERVER) && defined(__WIN__) || defined(_WIN32) || defined(_WIN64)
#include <winsock.h>
#include <odbcinst.h>
@@ -563,8 +589,8 @@ void free_rows(MYSQL_DATA *cur)
}
}
-my_bool
-advanced_command(MYSQL *mysql, enum enum_server_command command,
+static my_bool
+cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
const char *header, ulong header_length,
const char *arg, ulong arg_length, my_bool skip_check)
{
@@ -632,7 +658,9 @@ my_bool
simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
ulong length, my_bool skip_check)
{
- return advanced_command(mysql, command, NullS, 0, arg, length, skip_check);
+ return
+ (*mysql->methods->advanced_command)(mysql, command,
+ NullS, 0, arg, length, skip_check);
}
void free_old_query(MYSQL *mysql)
@@ -747,8 +775,8 @@ static int add_init_command(struct st_mysql_options *options, const char *cmd)
return 0;
}
-static void mysql_read_default_options(struct st_mysql_options *options,
- const char *filename,const char *group)
+void mysql_read_default_options(struct st_mysql_options *options,
+ const char *filename,const char *group)
{
int argc;
char *argv_buff[1],**argv;
@@ -1428,10 +1456,23 @@ error:
before calling mysql_real_connect !
*/
-MYSQL * STDCALL
-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)
+static void STDCALL cli_mysql_close(MYSQL *mysql);
+static my_bool STDCALL cli_mysql_read_query_result(MYSQL *mysql);
+static MYSQL_RES * STDCALL cli_mysql_store_result(MYSQL *mysql);
+
+static MYSQL_METHODS client_methods=
+{
+ cli_mysql_close,
+ cli_mysql_read_query_result,
+ cli_advanced_command,
+ cli_mysql_store_result,
+ CLI_MYSQL_USE_RESULT
+};
+
+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 MYSQL_CLIENT
char *charset_name;
@@ -1466,6 +1507,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
user ? user : "(Null)"));
/* Don't give sigpipe errors if the client doesn't want them */
+ mysql->methods= &client_methods;
set_sigpipe(mysql);
net->vio = 0; /* If something goes wrong */
mysql->client_flag=0; /* For handshake */
@@ -2176,8 +2218,7 @@ mysql_ssl_free(MYSQL *mysql __attribute__((unused)))
If handle is alloced by mysql connect free it.
*************************************************************************/
-void STDCALL
-mysql_close(MYSQL *mysql)
+static void STDCALL cli_mysql_close(MYSQL *mysql)
{
DBUG_ENTER("mysql_close");
if (mysql) /* Some simple safety */
@@ -2259,7 +2300,7 @@ mysql_close(MYSQL *mysql)
DBUG_VOID_RETURN;
}
-my_bool STDCALL mysql_read_query_result(MYSQL *mysql)
+static my_bool STDCALL cli_mysql_read_query_result(MYSQL *mysql)
{
uchar *pos;
ulong field_count;
@@ -2378,8 +2419,7 @@ mysql_real_query(MYSQL *mysql, const char *query, ulong length)
mysql_data_seek may be used.
**************************************************************************/
-MYSQL_RES * STDCALL
-mysql_store_result(MYSQL *mysql)
+static MYSQL_RES * STDCALL cli_mysql_store_result(MYSQL *mysql)
{
MYSQL_RES *result;
DBUG_ENTER("mysql_store_result");
diff --git a/sql-common/pack.c b/sql-common/pack.c
index e363d600e20..16cc13eddbd 100644
--- a/sql-common/pack.c
+++ b/sql-common/pack.c
@@ -1,7 +1,28 @@
+/* Copyright (C) 2000-2003 MySQL 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 */
+
#include <my_global.h>
#include <mysql_com.h>
#include <mysql.h>
+ulong net_buffer_length=8192;
+ulong max_allowed_packet= 1024L*1024L*1024L;
+ulong net_read_timeout= NET_READ_TIMEOUT;
+ulong net_write_timeout= NET_WRITE_TIMEOUT;
+
/* Get the length of next field. Change parameter to point at fieldstart */
ulong STDCALL net_field_length(uchar **packet)
{
@@ -62,3 +83,16 @@ my_ulonglong net_field_length_ll(uchar **packet)
#endif
}
+/*
+ Functions called my my_net_init() to set some application specific variables
+*/
+
+void my_net_local_init(NET *net)
+{
+ net->max_packet= (uint) net_buffer_length;
+ net->read_timeout= (uint) net_read_timeout;
+ net->write_timeout=(uint) net_write_timeout;
+ net->retry_count= 1;
+ net->max_packet_size= max(net_buffer_length, max_allowed_packet);
+}
+