summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <serg@serg.mylan>2004-08-26 15:19:46 +0200
committerunknown <serg@serg.mylan>2004-08-26 15:19:46 +0200
commite949b47fe42c98f435631556e7206b48a7a65232 (patch)
tree9299076637e9019c66560b2d68fe6b4bc6456487 /sql
parentaba96f8307ff337118e8050c51cafaaef2a0a02e (diff)
parentf45d80766783a1f6930b1eee0667022ce9f7f8ec (diff)
downloadmariadb-git-e949b47fe42c98f435631556e7206b48a7a65232.tar.gz
merged
BitKeeper/etc/logging_ok: auto-union VC++Files/sql/mysqld.dsp: Auto merged client/mysql.cc: Auto merged client/mysqladmin.c: Auto merged BitKeeper/deleted/.del-mysql_install.c~8c089740d79a92: Auto merged client/mysqlbinlog.cc: Auto merged client/mysqlcheck.c: Auto merged client/mysqldump.c: Auto merged client/mysqlimport.c: Auto merged client/mysqlmanager-pwgen.c: Auto merged client/mysqlshow.c: Auto merged client/mysqltest.c: Auto merged extra/my_print_defaults.c: Auto merged extra/perror.c: Auto merged extra/resolve_stack_dump.c: Auto merged extra/resolveip.c: Auto merged include/my_getopt.h: Auto merged innobase/buf/buf0rea.c: Auto merged isam/isamchk.c: Auto merged isam/pack_isam.c: Auto merged libmysqld/Makefile.am: Auto merged myisam/mi_test1.c: Auto merged myisam/myisamchk.c: Auto merged myisam/myisampack.c: Auto merged mysql-test/mysql-test-run.sh: Auto merged sql/gen_lex_hash.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_parse.cc: Auto merged tools/mysqlmanager.c: Auto merged
Diffstat (limited to 'sql')
-rw-r--r--sql/gen_lex_hash.cc2
-rw-r--r--sql/log.cc194
-rw-r--r--sql/mysql_priv.h12
-rw-r--r--sql/mysqld.cc11
-rw-r--r--sql/sql_base.cc11
-rw-r--r--sql/sql_parse.cc2
6 files changed, 203 insertions, 29 deletions
diff --git a/sql/gen_lex_hash.cc b/sql/gen_lex_hash.cc
index 7a445ed8c4d..cb97febea32 100644
--- a/sql/gen_lex_hash.cc
+++ b/sql/gen_lex_hash.cc
@@ -362,7 +362,7 @@ static int get_options(int argc, char **argv)
{
int ho_error;
- if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, 0)))
exit(ho_error);
if (argc >= 1)
diff --git a/sql/log.cc b/sql/log.cc
index 240965fdca3..870242eac31 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -31,12 +31,51 @@
#include <stdarg.h>
#include <m_ctype.h> // For test_if_number
+#ifdef __NT__
+#include "message.h"
+#endif
+
MYSQL_LOG mysql_log,mysql_update_log,mysql_slow_log,mysql_bin_log;
ulong sync_binlog_counter= 0;
static bool test_if_number(const char *str,
long *res, bool allow_wildcards);
+#ifdef __NT__
+static int eventSource = 0;
+void setupWindowsEventSource()
+{
+ if (eventSource) return;
+
+ eventSource = 1;
+ HKEY hRegKey = NULL;
+ DWORD dwError = 0;
+ TCHAR szPath[ MAX_PATH ];
+
+ // Create the event source registry key
+ dwError = RegCreateKey(HKEY_LOCAL_MACHINE,
+ "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\MySQL",
+ &hRegKey);
+
+ // Name of the PE module that contains the message resource
+ GetModuleFileName(NULL, szPath, MAX_PATH);
+
+ // Register EventMessageFile
+ dwError = RegSetValueEx(hRegKey, "EventMessageFile", 0, REG_EXPAND_SZ,
+ (PBYTE) szPath, strlen(szPath)+1);
+
+
+ // Register supported event types
+ DWORD dwTypes = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
+ dwError = RegSetValueEx(hRegKey, "TypesSupported", 0, REG_DWORD,
+ (LPBYTE) &dwTypes, sizeof dwTypes);
+
+ RegCloseKey(hRegKey);
+}
+
+#endif
+
+
/****************************************************************************
** Find a uniq filename for 'filename.#'.
** Set # to a number as low as possible
@@ -230,7 +269,7 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg,
"started with:\nTcp port: %d Unix socket: %s\n",
my_progname,server_version,mysqld_port,mysqld_unix_port
#endif
- );
+ );
end=strnmov(buff+len,"Time Id Command Argument\n",
sizeof(buff)-len);
if (my_b_write(&log_file, (byte*) buff,(uint) (end-buff)) ||
@@ -1940,41 +1979,33 @@ static bool test_if_number(register const char *str,
} /* test_if_number */
-void sql_print_error(const char *format,...)
+void print_buffer_to_file(enum loglevel level, const char *buffer)
{
- va_list args;
time_t skr;
struct tm tm_tmp;
struct tm *start;
- va_start(args,format);
- DBUG_ENTER("sql_print_error");
+
+ DBUG_ENTER("print_buffer_to_log");
VOID(pthread_mutex_lock(&LOCK_error_log));
-#ifndef DBUG_OFF
- {
- char buff[1024];
- my_vsnprintf(buff,sizeof(buff)-1,format,args);
- DBUG_PRINT("error",("%s",buff));
- va_end(args);
- va_start(args,format);
- }
-#endif
+
skr=time(NULL);
- localtime_r(&skr,&tm_tmp);
+ localtime_r(&skr, &tm_tmp);
start=&tm_tmp;
- fprintf(stderr,"%02d%02d%02d %2d:%02d:%02d ",
- start->tm_year % 100,
- start->tm_mon+1,
+ fprintf(stderr, "%02d%02d%02d %2d:%02d:%02d [%s] %s\n",
+ start->tm_year % 100,
+ start->tm_mon+1,
start->tm_mday,
start->tm_hour,
start->tm_min,
- start->tm_sec);
- (void) vfprintf(stderr,format,args);
- (void) fputc('\n',stderr);
+ start->tm_sec,
+ level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ? "WARNING" : "INFORMATION",
+ buffer);
+
fflush(stderr);
- va_end(args);
VOID(pthread_mutex_unlock(&LOCK_error_log));
+
DBUG_VOID_RETURN;
}
@@ -2169,5 +2200,124 @@ void MYSQL_LOG::report_pos_in_innodb()
my_b_tell(&log_file));
}
#endif
+
+#ifdef __NT__
+void print_buffer_to_nt_eventlog(enum loglevel level, char *buff, int buffLen)
+{
+ HANDLE event;
+ char *buffptr;
+ LPCSTR *buffmsgptr;
+
+ DBUG_ENTER("print_buffer_to_nt_eventlog");
+
+ buffptr = buff;
+ if (strlen(buff) > (uint)(buffLen-4))
+ {
+ char *newBuff = new char[ strlen(buff) + 4 ];
+ strcpy(newBuff, buff);
+ buffptr = newBuff;
+ }
+ strcat(buffptr, "\r\n\r\n");
+ buffmsgptr = (LPCSTR*)&buffptr;
+
+ setupWindowsEventSource();
+ if (event = RegisterEventSource(NULL,"MySQL"))
+ {
+ switch (level){
+ case ERROR_LEVEL:
+ ReportEvent(event, EVENTLOG_ERROR_TYPE, 0, MSG_DEFAULT, NULL, 1, 0, buffmsgptr, NULL);
+ break;
+ case WARNING_LEVEL:
+ ReportEvent(event, EVENTLOG_WARNING_TYPE, 0, MSG_DEFAULT, NULL, 1, 0, buffmsgptr, NULL);
+ break;
+ case INFORMATION_LEVEL:
+ ReportEvent(event, EVENTLOG_INFORMATION_TYPE, 0, MSG_DEFAULT, NULL, 1, 0, buffmsgptr, NULL);
+ break;
+ }
+ DeregisterEventSource(event);
+ }
+
+ // if we created a string buffer, then delete it
+ if (buffptr != buff)
+ delete[] buffptr;
+
+
+ DBUG_VOID_RETURN;
+}
+#endif
+
+/*
+ Prints a printf style message to the error log and, under NT, to the Windows event log.
+
+ SYNOPSIS
+ vprint_msg_to_log()
+ event_type Type of event to write (Error, Warning, or Info)
+ format Printf style format of message
+ args va_list list of arguments for the message
+
+ NOTE
+
+ IMPLEMENTATION
+ This function prints the message into a buffer and then sends that buffer to other
+ functions to write that message to other logging sources.
+
+ RETURN VALUES
+ void
+*/
+void vprint_msg_to_log(enum loglevel level, const char *format, va_list args)
+{
+ char buff[1024];
+
+ DBUG_ENTER("vprint_msg_to_log");
+
+ my_vsnprintf(buff, sizeof(buff)-5, format, args);
+
+ print_buffer_to_file(level, buff);
+
+#ifndef DBUG_OFF
+ DBUG_PRINT("error",("%s",buff));
+#endif
+
+#ifdef __NT__
+ print_buffer_to_nt_eventlog(level, buff, sizeof(buff));
+#endif
+
+ DBUG_VOID_RETURN;
+}
+
+
+void sql_print_error(const char *format, ...)
+{
+ DBUG_ENTER("sql_print_error");
+
+ va_list args;
+ va_start(args, format);
+ vprint_msg_to_log(ERROR_LEVEL, format, args);
+ va_end(args);
+
+ DBUG_VOID_RETURN;
+}
+
+void sql_print_warning(const char *format, ...)
+{
+ DBUG_ENTER("sql_print_warning");
+
+ va_list args;
+ va_start(args, format);
+ vprint_msg_to_log(WARNING_LEVEL, format, args);
+ va_end(args);
+
+ DBUG_VOID_RETURN;
+}
+
+void sql_print_information(const char *format, ...)
+{
+ DBUG_ENTER("sql_print_information");
+
+ va_list args;
+ va_start(args, format);
+ vprint_msg_to_log(INFORMATION_LEVEL, format, args);
+ va_end(args);
+
DBUG_VOID_RETURN;
}
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 2037cf48616..1949ecf26dc 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -576,7 +576,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
int mysql_delete(THD *thd, TABLE_LIST *table, COND *conds, SQL_LIST *order,
ha_rows rows, ulong options);
-int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok=0);
+int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok);
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update);
TABLE *open_table(THD *thd,const char *db,const char *table,const char *alias,
bool *refresh);
@@ -782,8 +782,14 @@ int key_cmp(KEY_PART_INFO *key_part, const byte *key, uint key_length);
bool init_errmessage(void);
void sql_perror(const char *message);
-void sql_print_error(const char *format,...)
- __attribute__ ((format (printf, 1, 2)));
+
+void vprint_msg_to_log( enum loglevel level, const char *format, va_list args );
+void sql_print_error( const char *format, ... );
+void sql_print_warning( const char *format, ...);
+void sql_print_information( const char *format, ...);
+
+
+
bool fn_format_relative_to_data_home(my_string to, const char *name,
const char *dir, const char *extension);
bool open_log(MYSQL_LOG *log, const char *hostname,
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 4ef41e62f32..74f130e6784 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -6078,7 +6078,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
}
return 0;
}
-
+ /* Initiates DEBUG - but no debugging here ! */
extern "C" gptr *
mysql_getopt_value(const char *keyname, uint key_length,
@@ -6108,6 +6108,13 @@ mysql_getopt_value(const char *keyname, uint key_length,
return option->value;
}
+void option_error_reporter( enum loglevel level, const char *format, ... )
+{
+ va_list args;
+ va_start( args, format );
+ vprint_msg_to_log( level, format, args );
+ va_end( args );
+}
static void get_options(int argc,char **argv)
{
@@ -6116,7 +6123,7 @@ static void get_options(int argc,char **argv)
my_getopt_register_get_addr(mysql_getopt_value);
strmake(def_ft_boolean_syntax, ft_boolean_syntax,
sizeof(ft_boolean_syntax)-1);
- if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)) != 0)
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, option_error_reporter)))
exit(ho_error);
if (argc > 0)
{
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index dede280325d..255f04d853b 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -2441,9 +2441,20 @@ bool
insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name,
const char *table_name, List_iterator<Item> *it)
{
+ char name_buff[NAME_LEN+1];
uint found;
DBUG_ENTER("insert_fields");
+
+ if (db_name && lower_case_table_names)
+ {
+ /* convert database to lower case for comparison */
+ strmake( name_buff, db_name, sizeof(name_buff)-1 );
+ casedn_str( name_buff );
+ db_name = name_buff;
+ }
+
+
found=0;
for (; tables ; tables=tables->next)
{
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index f9e979d1fdf..3cb356d42c8 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2740,7 +2740,7 @@ unsent_create_error:
send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION,NullS);
goto error;
}
- res=mysql_truncate(thd,tables);
+ res=mysql_truncate(thd, tables, 0);
break;
case SQLCOM_DELETE:
{