summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/Makefile.am10
-rw-r--r--client/client_priv.h2
-rw-r--r--client/completion_hash.cc2
-rw-r--r--client/errmsg.c24
-rw-r--r--client/get_password.c2
-rw-r--r--client/insert_test.c8
-rw-r--r--client/mysql.cc138
-rw-r--r--client/mysqldump.c27
-rw-r--r--client/mysqlshow.c2
-rw-r--r--client/mysqltest.c59
-rw-r--r--client/password.c2
-rw-r--r--client/readline.cc2
-rw-r--r--client/sql_string.cc2
-rw-r--r--client/thimble.cc2
-rw-r--r--client/thread_test.c4
-rw-r--r--client/violite.c394
16 files changed, 220 insertions, 460 deletions
diff --git a/client/Makefile.am b/client/Makefile.am
index 380c9f2acbe..d5b80ac5f4c 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -16,7 +16,7 @@
# This file is public domain and comes with NO WARRANTY of any kind
-INCLUDES = -I$(srcdir)/../include \
+INCLUDES = -I$(srcdir)/../include $(openssl_includes) \
-I../include -I$(srcdir)/.. -I$(top_srcdir) \
-I..
noinst_HEADERS = client_priv.h
@@ -36,14 +36,14 @@ mysqldump_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
mysqlimport_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
insert_test_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
select_test_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
-mysqltest_SOURCES= mysqltest.c
+mysqltest_SOURCES= mysqltest.c
mysqltest_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
-mysqlbinlog_SOURCES = mysqlbinlog.cc
+mysqlbinlog_SOURCES = mysqlbinlog.cc
mysqlbinlog_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
-sql_src=log_event.h log_event.cc
+sql_src= log_event.h log_event.cc
# Fix for mit-threads
-DEFS = -DUNDEF_THREADS_HACK
+DEFS= -DUNDEF_THREADS_HACK
link_sources:
for f in $(sql_src) ; do \
diff --git a/client/client_priv.h b/client/client_priv.h
index 7bee03a8ab5..64ded3ed7f3 100644
--- a/client/client_priv.h
+++ b/client/client_priv.h
@@ -16,7 +16,7 @@
/* Common defines for all clients */
-#include <global.h>
+#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include <mysql.h>
diff --git a/client/completion_hash.cc b/client/completion_hash.cc
index 006427f0295..74ff3083197 100644
--- a/client/completion_hash.cc
+++ b/client/completion_hash.cc
@@ -22,7 +22,7 @@
* Small portability changes by Monty. Changed also to use my_malloc/my_free
*/
-#include <global.h>
+#include <my_global.h>
#include <m_string.h>
#undef SAFEMALLOC // Speed things up
#include <my_sys.h>
diff --git a/client/errmsg.c b/client/errmsg.c
index 67cfe874f77..012158a6e30 100644
--- a/client/errmsg.c
+++ b/client/errmsg.c
@@ -18,7 +18,7 @@
/* Error messages for MySQL clients */
/* error messages for the demon is in share/language/errmsg.sys */
-#include <global.h>
+#include <my_global.h>
#include <my_sys.h>
#include "errmsg.h"
@@ -45,7 +45,13 @@ const char *client_errors[]=
"Kann Named Pipe nicht oeffnen. Host: %-.64s pipe: %-.32s (%lu)",
"Kann den Status der Named Pipe nicht setzen. Host: %-.64s pipe: %-.32s (%lu)",
"Can't initialize character set %-.64s (path: %-.64s)",
- "Got packet bigger than 'max_allowed_packet'"
+ "Got packet bigger than 'max_allowed_packet'",
+ "Embedded server",
+ "Error on SHOW SLAVE STATUS:",
+ "Error on SHOW SLAVE HOSTS:",
+ "Error connecting to slave:",
+ "Error connecting to master:"
+
};
/* Start of code added by Roberto M. Serqueira - martinsc@uol.com.br - 05.24.2001 */
@@ -73,7 +79,12 @@ const char *client_errors[]=
"Não pode abrir 'named pipe' para o 'host' %-.64s - 'pipe' %-.32s (%lu)",
"Não pode estabelecer o estado do 'named pipe' para o 'host' %-.64s - 'pipe' %-.32s (%lu)",
"Não pode inicializar conjunto de caracteres %-.64s (caminho %-.64s)",
- "Obteve pacote maior do que 'max_allowed_packet'"
+ "Obteve pacote maior do que 'max_allowed_packet'",
+ "Embedded server",
+ "Error on SHOW SLAVE STATUS:",
+ "Error on SHOW SLAVE HOSTS:",
+ "Error connecting to slave:",
+ "Error connecting to master:"
};
#else /* ENGLISH */
@@ -99,7 +110,12 @@ const char *client_errors[]=
"Can't open named pipe to host: %-.64s pipe: %-.32s (%lu)",
"Can't set state of named pipe to host: %-.64s pipe: %-.32s (%lu)",
"Can't initialize character set %-.64s (path: %-.64s)",
- "Got packet bigger than 'max_allowed_packet'"
+ "Got packet bigger than 'max_allowed_packet'",
+ "Embedded server",
+ "Error on SHOW SLAVE STATUS:",
+ "Error on SHOW SLAVE HOSTS:",
+ "Error connecting to slave:",
+ "Error connecting to master:"
};
#endif
diff --git a/client/get_password.c b/client/get_password.c
index 25069a14b75..e47cf7b3783 100644
--- a/client/get_password.c
+++ b/client/get_password.c
@@ -19,7 +19,7 @@
** Ask for a password from tty
** This is an own file to avoid conflicts with curses
*/
-#include <global.h>
+#include <my_global.h>
#include <my_sys.h>
#include "mysql.h"
#include <m_string.h>
diff --git a/client/insert_test.c b/client/insert_test.c
index 640935d63b2..82609f68e4e 100644
--- a/client/insert_test.c
+++ b/client/insert_test.c
@@ -34,19 +34,13 @@ int main(int argc, char **argv)
exit(1);
}
- if (!(sock = mysql_connect(&mysql,NULL,0,0)))
+ if (!(sock = mysql_real_connect(&mysql,NULL,NULL,NULL,argv[1],0,NULL,0)))
{
fprintf(stderr,"Couldn't connect to engine!\n%s\n",mysql_error(&mysql));
perror("");
exit(1);
}
- if (mysql_select_db(sock,argv[1]))
- {
- fprintf(stderr,"Couldn't select database %s!\n%s\n",argv[1],
- mysql_error(sock));
- }
-
num = atoi(argv[2]);
count = 0;
while (count < num)
diff --git a/client/mysql.cc b/client/mysql.cc
index 96536c9d5f0..6c947d90d76 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -19,9 +19,11 @@
*
* Written by:
* Michael 'Monty' Widenius
- * Andi Gutmans <andi@zend.com>
+ * Andi Gutmans <andi@zend.com>
* Zeev Suraski <zeev@zend.com>
* Jani Tolonen <jani@mysql.com>
+ * Matt Wagner <mwagner@mysql.com>
+ * Jeremy Cole <jcole@mysql.com>
*
**/
@@ -33,8 +35,9 @@
#endif
#include "my_readline.h"
#include <signal.h>
+#include <violite.h>
-const char *VER="11.15";
+const char *VER="11.16";
/* Don't try to make a nice table if the data is too big */
#define MAX_COLUMN_LENGTH 1024
@@ -115,7 +118,7 @@ static bool info_flag=0,ignore_errors=0,wait_flag=0,quick=0,
no_rehash=0,skip_updates=0,safe_updates=0,one_database=0,
opt_compress=0,
vertical=0,skip_line_numbers=0,skip_column_names=0,opt_html=0,
- opt_nopager=1, opt_outfile=0, no_named_cmds=1;
+ opt_xml=0,opt_nopager=1, opt_outfile=0, no_named_cmds=1;
static uint verbose=0,opt_silent=0,opt_mysql_port=0;
static my_string opt_mysql_unix_port=0;
static int connect_flag=CLIENT_INTERACTIVE;
@@ -126,6 +129,11 @@ static String glob_buffer,old_buffer;
static int wait_time = 5;
static STATUS status;
static ulong select_limit,max_join_size,opt_connect_timeout=0;
+static const char *xmlmeta[] = {
+ "&", "&amp;",
+ "<", "&lt;",
+ 0, 0
+};
static char default_pager[FN_REFLEN];
char pager[FN_REFLEN], outfile[FN_REFLEN];
FILE *PAGER, *OUTFILE;
@@ -161,6 +169,9 @@ static int sql_connect(char *host,char *database,char *user,char *password,
uint silent);
static int put_info(const char *str,INFO_TYPE info,uint error=0);
static void safe_put_field(const char *pos,ulong length);
+static const char *array_value(const char **array, char *key);
+static void xmlencode(char *dest, char *src);
+static void my_chomp(char *end);
static void init_pager();
static void end_pager();
static void init_tee();
@@ -232,6 +243,7 @@ static COMMANDS commands[] = {
};
static const char *load_default_groups[]= { "mysql","client",0 };
+static const char *server_default_groups[]= { "server", "mysql_SERVER", 0 };
#ifdef HAVE_READLINE
extern "C" void add_history(char *command); /* From readline directory */
@@ -245,6 +257,7 @@ static bool add_line(String &buffer,char *line,char *in_string);
static void remove_cntrl(String &buffer);
static void print_table_data(MYSQL_RES *result);
static void print_table_data_html(MYSQL_RES *result);
+static void print_table_data_xml(MYSQL_RES *result);
static void print_tab_data(MYSQL_RES *result);
static void print_table_data_vertically(MYSQL_RES *result);
static ulong start_timer(void);
@@ -258,6 +271,7 @@ int main(int argc,char *argv[])
{
char buff[80];
+ mysql_server_init(0, NULL, server_default_groups);
MY_INIT(argv[0]);
DBUG_ENTER("main");
DBUG_PROCESS(argv[0]);
@@ -311,9 +325,19 @@ int main(int argc,char *argv[])
mysql_thread_id(&mysql),mysql_get_server_info(&mysql));
put_info((char*) glob_buffer.ptr(),INFO_INFO);
+#ifdef HAVE_OPENSSL
+ if(mysql.net.vio->ssl_ && SSL_get_cipher(mysql.net.vio->ssl_)) {
+ sprintf((char*) glob_buffer.ptr(),
+ "SSL cipher in use is %s\n", SSL_get_cipher(mysql.net.vio->ssl_));
+ put_info((char*) glob_buffer.ptr(),INFO_INFO);
+ } else
+ put_info("SSL is not in use\n",INFO_INFO);
+#endif /* HAVE_OPENSSL */
+
+
#ifdef HAVE_READLINE
initialize_readline(my_progname);
- if (!status.batch && !quick && !opt_html)
+ if (!status.batch && !quick && !opt_html && !opt_xml)
{
/*read-history from file, default ~/.mysql_history*/
if (getenv("MYSQL_HISTFILE"))
@@ -341,6 +365,7 @@ int main(int argc,char *argv[])
if (opt_outfile)
end_tee();
mysql_end(0);
+ mysql_server_end();
#ifndef _lint
DBUG_RETURN(0); // Keep compiler happy
#endif
@@ -350,8 +375,13 @@ sig_handler mysql_end(int sig)
{
if (connected)
mysql_close(&mysql);
+#ifdef HAVE_OPENSSL
+ else
+ mysql_ssl_clear(&mysql); /* SSL data structres should be freed
+ even if connection was not made */
+#endif
#ifdef HAVE_READLINE
- if (!status.batch && !quick && ! opt_html)
+ if (!status.batch && !quick && !opt_html && !opt_xml)
{
/* write-history */
if (verbose)
@@ -392,6 +422,7 @@ static struct option long_options[] =
{"force", no_argument, 0, 'f'},
{"help", no_argument, 0, '?'},
{"html", no_argument, 0, 'H'},
+ {"xml", no_argument, 0, 'X'},
{"host", required_argument, 0, 'h'},
{"ignore-spaces", no_argument, 0, 'i'},
{"no-auto-rehash",no_argument, 0, 'A'},
@@ -486,6 +517,7 @@ static void usage(int version)
-i, --ignore-space Ignore space after function names.\n\
-h, --host=... Connect to host.\n\
-H, --html Produce HTML output.\n\
+ -X, --xml Produce XML output.\n\
-L, --skip-line-numbers\n\
Don't write line number for errors.\n");
#ifndef __WIN__
@@ -560,7 +592,7 @@ static int get_options(int argc, char **argv)
set_all_changeable_vars(changeable_vars);
while ((c=getopt_long(argc,argv,
- (char*) "?ABCD:LfgGHinNoqrstTU::vVw::WEe:h:O:P:S:u:#::p::",
+ (char*) "?ABCD:LfgGHXinNoqrstTU::vVw::WEe:h:O:P:S:u:#::p::",
long_options, &option_index)) != EOF)
{
switch(c) {
@@ -681,6 +713,7 @@ static int get_options(int argc, char **argv)
case 'G': no_named_cmds=0; break;
case 'g': no_named_cmds=1; break;
case 'H': opt_html=1; break;
+ case 'X': opt_xml=1; break;
case 'i': connect_flag|= CLIENT_IGNORE_SPACE; break;
case 'B':
if (!status.batch)
@@ -1448,6 +1481,8 @@ com_go(String *buffer,char *line __attribute__((unused)))
init_pager();
if (opt_html)
print_table_data_html(result);
+ else if (opt_xml)
+ print_table_data_xml(result);
else if (vertical)
print_table_data_vertically(result);
else if (opt_silent && verbose <= 2 && !output_tables)
@@ -1650,6 +1685,49 @@ print_table_data_html(MYSQL_RES *result)
}
+static void
+print_table_data_xml(MYSQL_RES *result)
+{
+ MYSQL_ROW cur;
+ MYSQL_FIELD *fields;
+
+ mysql_field_seek(result,0);
+
+ char *statement;
+ statement=(char*) my_malloc(strlen(glob_buffer.ptr())*5+1, MYF(MY_WME));
+ xmlencode(statement, (char*) glob_buffer.ptr());
+
+ (void) my_chomp(strend(statement));
+
+ tee_fprintf(PAGER,"<?xml version=\"1.0\"?>\n\n<resultset statement=\"%s\">", statement);
+
+ my_free(statement,MYF(MY_ALLOW_ZERO_PTR));
+
+ fields = mysql_fetch_fields(result);
+
+ while ((cur = mysql_fetch_row(result)))
+ {
+ (void) tee_fputs("\n <row>\n", PAGER);
+ for (uint i=0; i < mysql_num_fields(result); i++)
+ {
+ char *data;
+ ulong *lengths=mysql_fetch_lengths(result);
+ data=(char*) my_malloc(lengths[i]*5+1, MYF(MY_WME));
+ tee_fprintf(PAGER, "\t<%s>", (fields[i].name ?
+ (fields[i].name[0] ? fields[i].name :
+ " &nbsp; ") : "NULL"));
+ xmlencode(data, cur[i]);
+ safe_put_field(data, strlen(data));
+ tee_fprintf(PAGER, "</%s>\n", (fields[i].name ?
+ (fields[i].name[0] ? fields[i].name :
+ " &nbsp; ") : "NULL"));
+ my_free(data,MYF(MY_ALLOW_ZERO_PTR));
+ }
+ (void) tee_fputs(" </row>\n", PAGER);
+ }
+ (void) tee_fputs("</resultset>\n", PAGER);
+}
+
static void
print_table_data_vertically(MYSQL_RES *result)
@@ -1681,6 +1759,45 @@ print_table_data_vertically(MYSQL_RES *result)
}
}
+static const char
+*array_value(const char **array, char *key) {
+ int x;
+ for(x=0; array[x]; x+=2)
+ if(!strcmp(array[x], key))
+ return array[x+1];
+ return 0;
+}
+
+static void
+xmlencode(char *dest, char *src)
+{
+ char *p = src;
+ const char *t;
+ char s[2] = { 0, 0 };
+ *dest = 0;
+
+ do
+ {
+ s[0] = *p;
+ if (!(t=array_value(xmlmeta, s)))
+ t = s;
+ dest=strmov(dest, t);
+ } while(*p++);
+}
+
+static void
+my_chomp(char *end) {
+ char *mend;
+ mend = end;
+
+ do {
+ if (isspace(*mend)) {
+ *mend = '\0';
+ } else
+ mend--;
+ } while (mend && *mend);
+}
+
static void
safe_put_field(const char *pos,ulong length)
@@ -1711,7 +1828,7 @@ safe_put_field(const char *pos,ulong length)
tee_fputs("\\n", PAGER); // This too
else if (*pos == '\\')
tee_fputs("\\\\", PAGER);
- else
+ else
tee_putc(*pos, PAGER);
}
}
@@ -2096,6 +2213,11 @@ sql_real_connect(char *host,char *database,char *user,char *password,
mysql_close(&mysql);
connected= 0;
}
+#ifdef HAVE_OPENSSL
+ else
+ mysql_ssl_clear(&mysql); /* SSL data structres should be freed
+ even if connection was not made */
+#endif
mysql_init(&mysql);
if (opt_connect_timeout)
{
@@ -2447,6 +2569,7 @@ static void mysql_end_timer(ulong start_time,char *buff)
strmov(strend(buff),")");
}
+#ifndef EMBEDDED_SERVER
/* Keep sql_string library happy */
gptr sql_alloc(unsigned int Size)
@@ -2458,3 +2581,4 @@ void sql_element_free(void *ptr)
{
my_free((gptr) ptr,MYF(0));
}
+#endif /* EMBEDDED_SERVER */
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 597a1393f69..9d80fd9a6c9 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -39,7 +39,7 @@
#define DUMP_VERSION "8.16"
-#include <global.h>
+#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include <m_ctype.h>
@@ -274,12 +274,12 @@ puts("\
static void write_heder(FILE *sql_file, char *db_name)
{
- fprintf(sql_file, "# MySQL dump %s\n#\n", DUMP_VERSION);
- fprintf(sql_file, "# Host: %s Database: %s\n",
+ fprintf(sql_file, "-- MySQL dump %s\n#\n", DUMP_VERSION);
+ fprintf(sql_file, "-- Host: %s Database: %s\n",
current_host ? current_host : "localhost", db_name ? db_name : "");
- fputs("#--------------------------------------------------------\n",
+ fputs("---------------------------------------------------------\n",
sql_file);
- fprintf(sql_file, "# Server version\t%s\n",
+ fprintf(sql_file, "-- Server version\t%s\n",
mysql_get_server_info(&mysql_connection));
return;
} /* write_heder */
@@ -515,7 +515,7 @@ static int dbConnect(char *host, char *user,char *passwd)
DBUG_ENTER("dbConnect");
if (verbose)
{
- fprintf(stderr, "# Connecting to %s...\n", host ? host : "localhost");
+ fprintf(stderr, "-- Connecting to %s...\n", host ? host : "localhost");
}
mysql_init(&mysql_connection);
if (opt_compress)
@@ -542,7 +542,7 @@ static int dbConnect(char *host, char *user,char *passwd)
static void dbDisconnect(char *host)
{
if (verbose)
- fprintf(stderr, "# Disconnecting from %s...\n", host ? host : "localhost");
+ fprintf(stderr, "-- Disconnecting from %s...\n", host ? host : "localhost");
mysql_close(sock);
} /* dbDisconnect */
@@ -608,7 +608,7 @@ static uint getTableStructure(char *table, char* db)
delayed= opt_delayed ? " DELAYED " : "";
if (verbose)
- fprintf(stderr, "# Retrieving table structure for table %s...\n", table);
+ fprintf(stderr, "-- Retrieving table structure for table %s...\n", table);
sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d", opt_quoted);
table_name=quote_name(table,table_buff);
@@ -837,7 +837,7 @@ static uint getTableStructure(char *table, char* db)
{ /* If old MySQL version */
if (verbose)
fprintf(stderr,
- "# Warning: Couldn't get status information for table '%s' (%s)\n",
+ "-- Warning: Couldn't get status information for table '%s' (%s)\n",
table,mysql_error(sock));
}
}
@@ -934,7 +934,7 @@ static void dumpTable(uint numFields, char *table)
ulong rownr, row_break, total_length, init_length;
if (verbose)
- fprintf(stderr, "# Sending SELECT query...\n");
+ fprintf(stderr, "-- Sending SELECT query...\n");
if (path)
{
char filename[FN_REFLEN], tmp_path[FN_REFLEN];
@@ -977,11 +977,10 @@ static void dumpTable(uint numFields, char *table)
sprintf(query, "SELECT * FROM %s", quote_name(table,table_buff));
if (where)
{
- fprintf(md_result_file,"# WHERE: %s\n",where);
+ fprintf(md_result_file,"-- WHERE: %s\n",where);
strxmov(strend(query), " WHERE ",where,NullS);
}
- fputs("#\n\n", md_result_file);
-
+ fputs("\n\n", md_result_file);
if (mysql_query(sock, query))
{
DBerror(sock, "when retrieving data from server");
@@ -997,7 +996,7 @@ static void dumpTable(uint numFields, char *table)
return;
}
if (verbose)
- fprintf(stderr, "# Retrieving rows...\n");
+ fprintf(stderr, "-- Retrieving rows...\n");
if (mysql_num_fields(res) != numFields)
{
fprintf(stderr,"%s: Error in field count for table: '%s' ! Aborting.\n",
diff --git a/client/mysqlshow.c b/client/mysqlshow.c
index 199318abc2f..8bce1203df8 100644
--- a/client/mysqlshow.c
+++ b/client/mysqlshow.c
@@ -18,7 +18,7 @@
#define SHOW_VERSION "8.3"
-#include <global.h>
+#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include "mysql.h"
diff --git a/client/mysqltest.c b/client/mysqltest.c
index 4288b5d7871..1361dc843ed 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -45,7 +45,7 @@
#define MTEST_VERSION "1.10"
-#include <global.h>
+#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include <mysql.h>
@@ -257,7 +257,6 @@ static int mysql_rpl_parse_enabled(MYSQL* mysql __attribute__((unused))) { retur
static int mysql_rpl_probe(MYSQL *mysql __attribute__((unused))) { return 1; }
#endif
-
static void do_eval(DYNAMIC_STRING* query_eval, const char* query)
{
const char* p;
@@ -1112,6 +1111,25 @@ char* safe_get_param(char* str, char** arg, const char* msg)
DBUG_RETURN(str);
}
+int safe_connect(MYSQL* con, const char* host, const char* user,
+ const char* pass,
+ const char* db, int port, const char* sock)
+{
+ int con_error = 1;
+ int i;
+ for (i = 0; i < MAX_CON_TRIES; ++i)
+ {
+ if(mysql_real_connect(con, host,user, pass,
+ db, port, sock, 0))
+ {
+ con_error = 0;
+ break;
+ }
+ sleep(CON_RETRY_SLEEP);
+ }
+ return con_error;
+}
+
int do_connect(struct st_query* q)
{
@@ -1120,7 +1138,7 @@ int do_connect(struct st_query* q)
char* p=q->first_argument;
char buff[FN_REFLEN];
int con_port;
- int i, con_error;
+ int con_error;
DBUG_ENTER("do_connect");
DBUG_PRINT("enter",("connect: %s",p));
@@ -1153,20 +1171,9 @@ int do_connect(struct st_query* q)
con_sock=fn_format(buff, con_sock, TMPDIR, "",0);
if (!con_db[0])
con_db=db;
- con_error = 1;
- for (i = 0; i < MAX_CON_TRIES; ++i)
- {
- if(mysql_real_connect(&next_con->mysql, con_host,
+ if((con_error = safe_connect(&next_con->mysql, con_host,
con_user, con_pass,
- con_db, con_port, con_sock, 0))
- {
- con_error = 0;
- break;
- }
- sleep(CON_RETRY_SLEEP);
- }
-
- if(con_error)
+ con_db, con_port, con_sock)))
die("Could not open connection '%s': %s", con_name,
mysql_error(&next_con->mysql));
@@ -1928,12 +1935,26 @@ static void init_var_hash()
var_from_env("BIG_TEST", opt_big_test ? "1" : "0");
}
+static const char *embedded_server_args[] = {
+ "", /* XXX: argv[0] is program name - we should fix the API */
+ "--datadir=.",
+ "--language=/usr/local/mysql/share/mysql/english",
+ "--skip-innodb",
+ NullS
+};
+static const char *embedded_server_groups[] = {
+ "mysql-test-server",
+ NullS
+};
+
int main(int argc, char** argv)
{
int error = 0;
struct st_query* q;
my_bool require_file=0, q_send_flag=0;
char save_file[FN_REFLEN];
+ mysql_server_init(sizeof(embedded_server_args) / sizeof(char *) - 1,
+ embedded_server_args, embedded_server_groups);
MY_INIT(argv[0]);
save_file[0]=0;
@@ -1970,9 +1991,8 @@ int main(int argc, char** argv)
if (!cur_con->name)
die("Out of memory");
- if (!mysql_real_connect(&cur_con->mysql, host,
- user, pass, db, port, unix_sock,
- 0))
+ if (safe_connect(&cur_con->mysql, host,
+ user, pass, db, port, unix_sock))
die("Failed in mysql_real_connect(): %s", mysql_error(&cur_con->mysql));
while (!read_query(&q))
@@ -2098,6 +2118,7 @@ int main(int argc, char** argv)
printf("ok\n");
}
+ mysql_server_end();
free_used_memory();
exit(error ? 1 : 0);
return error ? 1 : 0; /* Keep compiler happy */
diff --git a/client/password.c b/client/password.c
index 0fd5861873a..cb658f32022 100644
--- a/client/password.c
+++ b/client/password.c
@@ -35,7 +35,7 @@
This saves a hashed number as a string in the password field.
*****************************************************************************/
-#include <global.h>
+#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include "mysql.h"
diff --git a/client/readline.cc b/client/readline.cc
index f0312b089e5..f390be466ab 100644
--- a/client/readline.cc
+++ b/client/readline.cc
@@ -17,7 +17,7 @@
/* readline for batch mode */
-#include <global.h>
+#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include "my_readline.h"
diff --git a/client/sql_string.cc b/client/sql_string.cc
index 4b9ebef21f1..d749dbee978 100644
--- a/client/sql_string.cc
+++ b/client/sql_string.cc
@@ -21,7 +21,7 @@
#pragma implementation // gcc: Class implementation
#endif
-#include <global.h>
+#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include <m_ctype.h>
diff --git a/client/thimble.cc b/client/thimble.cc
index 6d1e8a85559..4a4227b3c71 100644
--- a/client/thimble.cc
+++ b/client/thimble.cc
@@ -2,7 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include "my_global.h"
+#include "my_my_global.h"
static void spawn_stern_thread(pthread_t *t);
static int act_goofy(void);
diff --git a/client/thread_test.c b/client/thread_test.c
index dbe2acee8db..06c6424de66 100644
--- a/client/thread_test.c
+++ b/client/thread_test.c
@@ -15,11 +15,11 @@
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA */
-#include <global.h>
+#include <my_global.h>
#ifndef THREAD
-int main(void)
+int main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
{
printf("This test must be compiled with multithread support to work\n");
exit(1);
diff --git a/client/violite.c b/client/violite.c
deleted file mode 100644
index 224ba051d82..00000000000
--- a/client/violite.c
+++ /dev/null
@@ -1,394 +0,0 @@
-/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA */
-
-#include <global.h>
-
-#ifndef HAVE_VIO /* is Vio suppored by the Vio lib ? */
-
-#include <errno.h>
-#include <assert.h>
-#include <violite.h>
-#include <my_sys.h>
-#include <my_net.h>
-#include <m_string.h>
-
-#if defined(__EMX__)
-#include <sys/ioctl.h>
-#define ioctlsocket(A,B,C) ioctl((A),(B),(void *)(C),sizeof(*(C)))
-#undef HAVE_FCNTL
-#endif /* defined(__EMX__) */
-
-#if defined(MSDOS) || defined(__WIN__)
-#ifdef __WIN__
-#undef errno
-#undef EINTR
-#undef EAGAIN
-#define errno WSAGetLastError()
-#define EINTR WSAEINTR
-#define EAGAIN WSAEINPROGRESS
-#endif /* __WIN__ */
-#define O_NONBLOCK 1 /* For emulation of fcntl() */
-#endif
-#ifndef EWOULDBLOCK
-#define EWOULDBLOCK EAGAIN
-#endif
-
-#ifndef __WIN__
-#define HANDLE void *
-#endif
-
-struct st_vio
-{
- my_socket sd; /* my_socket - real or imaginary */
- HANDLE hPipe;
- my_bool localhost; /* Are we from localhost? */
- int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
- my_bool fcntl_set; /* Have we done any fcntl yet?*/
- struct sockaddr_in local; /* Local internet address */
- struct sockaddr_in remote; /* Remote internet address */
- enum enum_vio_type type; /* Type of connection */
- char desc[30]; /* String description */
-};
-
-typedef void *vio_ptr;
-typedef char *vio_cstring;
-
-/*
- * Helper to fill most of the Vio* with defaults.
- */
-
-static void vio_reset(Vio* vio, enum enum_vio_type type,
- my_socket sd, HANDLE hPipe,
- my_bool localhost)
-{
- bzero((char*) vio, sizeof(*vio));
- vio->type = type;
- vio->sd = sd;
- vio->hPipe = hPipe;
- vio->localhost= localhost;
-}
-
-Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost)
-{
- Vio *vio;
- DBUG_ENTER("vio_new");
- DBUG_PRINT("enter", ("sd=%d", sd));
- if ((vio = (Vio*) my_malloc(sizeof(*vio),MYF(MY_WME))))
- {
- vio_reset(vio, type, sd, 0, localhost);
- sprintf(vio->desc, "socket (%d)", vio->sd);
- }
- DBUG_RETURN(vio);
-}
-
-
-#ifdef __WIN__
-
-Vio *vio_new_win32pipe(HANDLE hPipe)
-{
- Vio *vio;
- DBUG_ENTER("vio_new_handle");
- if ((vio = (Vio*) my_malloc(sizeof(Vio),MYF(MY_WME))))
- {
- vio_reset(vio, VIO_TYPE_NAMEDPIPE, 0, hPipe, TRUE);
- strmov(vio->desc, "named pipe");
- }
- DBUG_RETURN(vio);
-}
-
-#endif
-
-void vio_delete(Vio * vio)
-{
- /* It must be safe to delete null pointers. */
- /* This matches the semantics of C++'s delete operator. */
- if (vio)
- {
- vio_close(vio);
- my_free((gptr) vio,MYF(0));
- }
-}
-
-int vio_errno(Vio *vio)
-{
- return errno; /* On Win32 this mapped to WSAGetLastError() */
-}
-
-
-int vio_read(Vio * vio, gptr buf, int size)
-{
- int r;
- DBUG_ENTER("vio_read");
- DBUG_PRINT("enter", ("sd=%d, buf=%p, size=%d", vio->sd, buf, size));
- assert(vio->sd >= 0);
-#ifdef __WIN__
- if (vio->type == VIO_TYPE_NAMEDPIPE)
- {
- DWORD length;
- if (!ReadFile(vio->hPipe, buf, size, &length, NULL))
- DBUG_RETURN(-1);
- DBUG_RETURN(length);
- }
- r = recv(vio->sd, buf, size,0);
-#else
- errno=0; /* For linux */
- r = read(vio->sd, buf, size);
-#endif /* __WIN__ */
-#ifndef DBUG_OFF
- if (r < 0)
- {
- DBUG_PRINT("error", ("Got error %d during read",errno));
- }
-#endif /* DBUG_OFF */
- DBUG_PRINT("exit", ("%d", r));
- DBUG_RETURN(r);
-}
-
-
-int vio_write(Vio * vio, const gptr buf, int size)
-{
- int r;
- DBUG_ENTER("vio_write");
- DBUG_PRINT("enter", ("sd=%d, buf=%p, size=%d", vio->sd, buf, size));
- assert(vio->sd >= 0);
-#ifdef __WIN__
- if ( vio->type == VIO_TYPE_NAMEDPIPE)
- {
- DWORD length;
- if (!WriteFile(vio->hPipe, (char*) buf, size, &length, NULL))
- DBUG_RETURN(-1);
- DBUG_RETURN(length);
- }
- r = send(vio->sd, buf, size,0);
-#else
- r = write(vio->sd, buf, size);
-#endif /* __WIN__ */
-#ifndef DBUG_OFF
- if (r < 0)
- {
- DBUG_PRINT("error", ("Got error on write: %d",errno));
- }
-#endif /* DBUG_OFF */
- DBUG_PRINT("exit", ("%d", r));
- DBUG_RETURN(r);
-}
-
-
-int vio_blocking(Vio * vio, my_bool set_blocking_mode)
-{
- int r=0;
- DBUG_ENTER("vio_blocking");
- DBUG_PRINT("enter", ("set_blocking_mode: %d", (int) set_blocking_mode));
-
-#if !defined(___WIN__) && !defined(__EMX__)
-#if !defined(NO_FCNTL_NONBLOCK)
-
- if (vio->sd >= 0)
- {
- int old_fcntl=vio->fcntl_mode;
- if (!vio->fcntl_set)
- {
- vio->fcntl_set = TRUE;
- old_fcntl=vio->fcntl_mode = fcntl(vio->sd, F_GETFL);
- }
- if (set_blocking_mode)
- vio->fcntl_mode &= ~O_NONBLOCK; /*clear bit */
- else
- vio->fcntl_mode |= O_NONBLOCK; /*set bit */
- if (old_fcntl != vio->fcntl_mode)
- r = fcntl(vio->sd, F_SETFL, vio->fcntl_mode);
- }
-#endif /* !defined(NO_FCNTL_NONBLOCK) */
-#else /* !defined(__WIN__) && !defined(__EMX__) */
-#ifndef __EMX__
- if (vio->type != VIO_TYPE_NAMEDPIPE)
-#endif
- {
- ulong arg;
- int old_fcntl=vio->fcntl_mode;
- if (!vio->fcntl_set)
- {
- vio->fcntl_set = TRUE;
- old_fnctl=vio->fcntl_mode=0;
- }
- if (set_blocking_mode)
- {
- arg = 0;
- vio->fcntl_mode &= ~O_NONBLOCK; /*clear bit */
- }
- else
- {
- arg = 1;
- vio->fcntl_mode |= O_NONBLOCK; /*set bit */
- }
- if (old_fcntl != vio->fcntl_mode)
- r = ioctlsocket(vio->sd,FIONBIO,(void*) &arg, sizeof(arg));
- }
-#endif /* !defined(__WIN__) && !defined(__EMX__) */
- DBUG_RETURN(r);
-}
-
-my_bool
-vio_is_blocking(Vio * vio)
-{
- my_bool r;
- DBUG_ENTER("vio_is_blocking");
- r = !(vio->fcntl_mode & O_NONBLOCK);
- DBUG_PRINT("exit", ("%d", (int) r));
- DBUG_RETURN(r);
-}
-
-
-int vio_fastsend(Vio * vio, my_bool onoff)
-{
- int r=0;
- DBUG_ENTER("vio_fastsend");
- DBUG_PRINT("enter", ("onoff:%d", (int) onoff));
- assert(vio->sd >= 0);
-
-#ifdef IPTOS_THROUGHPUT
- {
-#ifndef __EMX__
- int tos = IPTOS_THROUGHPUT;
- if (!setsockopt(vio->sd, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof(tos)))
-#endif /* !__EMX__ */
- {
- int nodelay = 1;
- if (setsockopt(vio->sd, IPPROTO_TCP, TCP_NODELAY, (void *) &nodelay,
- sizeof(nodelay))) {
- DBUG_PRINT("warning",
- ("Couldn't set socket option for fast send"));
- r= -1;
- }
- }
- }
-#endif /* IPTOS_THROUGHPUT */
- DBUG_PRINT("exit", ("%d", r));
- DBUG_RETURN(r);
-}
-
-int vio_keepalive(Vio* vio, my_bool set_keep_alive)
-{
- int r=0;
- uint opt = 0;
- DBUG_ENTER("vio_keepalive");
- DBUG_PRINT("enter", ("sd=%d, set_keep_alive=%d", vio->sd, (int)
- set_keep_alive));
- if (vio->type != VIO_TYPE_NAMEDPIPE)
- {
- assert(vio->sd >= 0);
- if (set_keep_alive)
- opt = 1;
- r = setsockopt(vio->sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt,
- sizeof(opt));
- }
- DBUG_RETURN(r);
-}
-
-
-my_bool
-vio_should_retry(Vio * vio)
-{
- int en = errno;
- return en == EAGAIN || en == EINTR || en == EWOULDBLOCK;
-}
-
-
-int vio_close(Vio * vio)
-{
- int r;
- DBUG_ENTER("vio_close");
- assert(vio->sd >= 0); /* Vill also work on PIPE:s */
-#ifdef __WIN__
- if (vio->type == VIO_TYPE_NAMEDPIPE)
- {
-#if defined(__NT__) && defined(MYSQL_SERVER)
- CancelIO(vio->hPipe);
- DisconnectNamedPipe(vio->hPipe);
-#endif
- r=CloseHandle(vio->hPipe);
- }
- else
-#endif /* __WIN__ */
- {
- r=0;
- if (shutdown(vio->sd,2))
- r= -1;
- if (closesocket(vio->sd))
- r= -1;
- }
- if (r)
- {
- DBUG_PRINT("error", ("close() failed, error: %d",errno));
- /* FIXME: error handling (not critical for MySQL) */
- }
- vio_reset(vio,VIO_CLOSED,-1,0,TRUE); /* For debugging */
- DBUG_RETURN(r);
-}
-
-
-const char *vio_description(Vio * vio)
-{
- return vio->desc;
-}
-
-enum enum_vio_type vio_type(Vio* vio)
-{
- return vio->type;
-}
-
-my_socket vio_fd(Vio* vio)
-{
- return vio->sd;
-}
-
-
-my_bool vio_peer_addr(Vio * vio, char *buf)
-{
- DBUG_ENTER("vio_peer_addr");
- DBUG_PRINT("enter", ("sd=%d", vio->sd));
- if (vio->localhost)
- {
- strmov(buf,"127.0.0.1");
- }
- else
- {
- size_socket addrLen = sizeof(struct sockaddr);
- if (getpeername(vio->sd, (struct sockaddr *) (& (vio->remote)),
- &addrLen) != 0)
- {
- DBUG_PRINT("exit", ("getpeername, error: %d", errno));
- DBUG_RETURN(1);
- }
- my_inet_ntoa(vio->remote.sin_addr,buf);
- }
- DBUG_PRINT("exit", ("addr=%s", buf));
- DBUG_RETURN(0);
-}
-
-
-void vio_in_addr(Vio *vio, struct in_addr *in)
-{
- DBUG_ENTER("vio_in_addr");
- if (vio->localhost)
- bzero((char*) in, sizeof(*in)); /* This should never be executed */
- else
- *in=vio->remote.sin_addr;
- DBUG_VOID_RETURN;
-}
-
-#endif /* HAVE_VIO */