diff --git a/client/mysql.cc b/client/mysql.cc index be157f52d08ced52149012dc15f95f607d8a8cc3..65512e695b8ef724bb79af45b5287d7e19680a3c 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -2270,8 +2270,10 @@ extern "C" char **new_mysql_completion (const char *text, int start, int end); if not. */ -#if defined(USE_NEW_READLINE_INTERFACE) || defined(USE_LIBEDIT_INTERFACE) +#if defined(USE_NEW_READLINE_INTERFACE) extern "C" char *no_completion(const char*,int) +#elif defined(USE_LIBEDIT_INTERFACE) +extern "C" int no_completion(const char*,int) #else extern "C" char *no_completion() #endif diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 89b9c78a049a8037632dbeed3b531bd8ecee9081..e9e462b8d3f497ea8c76bf4705a48fd8047a17cc 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -4647,6 +4647,10 @@ void safe_connect(MYSQL* mysql, const char *name, const char *host, int failed_attempts= 0; DBUG_ENTER("safe_connect"); + + verbose_msg("Connecting to server %s:%d (socket %s) as '%s'" + ", connection '%s', attempt %d ...", + host, port, sock, user, name, failed_attempts); while(!mysql_real_connect(mysql, host,user, pass, db, port, sock, CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS)) { @@ -4678,6 +4682,7 @@ void safe_connect(MYSQL* mysql, const char *name, const char *host, } failed_attempts++; } + verbose_msg("... Connected."); DBUG_VOID_RETURN; } @@ -7511,8 +7516,12 @@ int main(int argc, char **argv) parse_args(argc, argv); log_file.open(opt_logdir, result_file_name, ".log"); + verbose_msg("Logging to '%s'.", log_file.file_name()); if (opt_mark_progress) + { progress_file.open(opt_logdir, result_file_name, ".progress"); + verbose_msg("Tracing progress in '%s'.", progress_file.file_name()); + } var_set_int("$PS_PROTOCOL", ps_protocol); var_set_int("$SP_PROTOCOL", sp_protocol); @@ -7521,6 +7530,8 @@ int main(int argc, char **argv) DBUG_PRINT("info",("result_file: '%s'", result_file_name ? result_file_name : "")); + verbose_msg("Results saved in '%s'.", + result_file_name ? result_file_name : ""); if (mysql_server_init(embedded_server_arg_count, embedded_server_args, (char**) embedded_server_groups)) @@ -7591,6 +7602,7 @@ int main(int argc, char **argv) open_file(opt_include); } + verbose_msg("Start processing test commands from '%s' ...", cur_file->file_name); while (!read_command(&command) && !abort_flag) { int current_line_inc = 1, processed = 0; @@ -7908,6 +7920,7 @@ int main(int argc, char **argv) log_file.close(); start_lineno= 0; + verbose_msg("... Done processing test commands."); if (parsing_disabled) die("Test ended with parsing disabled"); @@ -7958,6 +7971,7 @@ int main(int argc, char **argv) if (!command_executed && result_file_name) die("No queries executed but result file found!"); + verbose_msg("Test has succeeded!"); timer_output(); /* Yes, if we got this far the test has suceeded! Sakila smiles */ cleanup_and_exit(0); diff --git a/client/sql_string.cc b/client/sql_string.cc index c41463999aa8db76a23dd2d2b89b54eab539c048..5a922b9361c4617b4f6ad6d8589fdba9130eb2d0 100644 --- a/client/sql_string.cc +++ b/client/sql_string.cc @@ -71,25 +71,22 @@ bool String::realloc(uint32 alloc_length) char *new_ptr; if (alloced) { - if ((new_ptr= (char*) my_realloc(Ptr,len,MYF(MY_WME)))) - { - Ptr=new_ptr; - Alloced_length=len; - } - else - return TRUE; // Signal error + if (!(new_ptr= (char*) my_realloc(Ptr,len,MYF(MY_WME)))) + return TRUE; // Signal error } else if ((new_ptr= (char*) my_malloc(len,MYF(MY_WME)))) { + if (str_length > len - 1) + str_length= 0; if (str_length) // Avoid bugs in memcpy on AIX memcpy(new_ptr,Ptr,str_length); new_ptr[str_length]=0; - Ptr=new_ptr; - Alloced_length=len; alloced=1; } else return TRUE; // Signal error + Ptr= new_ptr; + Alloced_length= len; } Ptr[alloc_length]=0; // This make other funcs shorter return FALSE; @@ -125,7 +122,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs) str_charset=cs; if (decimals >= NOT_FIXED_DEC) { - uint32 len= my_sprintf(buff,(buff, "%.14g",num));// Enough for a DATETIME + uint32 len= my_sprintf(buff,(buff, "%.15g",num));// Enough for a DATETIME return copy(buff, len, &my_charset_latin1, cs, &dummy_errors); } #ifdef HAVE_FCONVERT @@ -677,7 +674,7 @@ void String::qs_append(const char *str, uint32 len) void String::qs_append(double d) { char *buff = Ptr + str_length; - str_length+= my_sprintf(buff, (buff, "%.14g", d)); + str_length+= my_sprintf(buff, (buff, "%.15g", d)); } void String::qs_append(double *d) diff --git a/cmd-line-utils/libedit/Makefile.am b/cmd-line-utils/libedit/Makefile.am index 23ee20894ecbfa60a35ca1fca5ffacd73678e4ba..ddafa4aab444768f1da713d72b9f4efabdd3e43e 100644 --- a/cmd-line-utils/libedit/Makefile.am +++ b/cmd-line-utils/libedit/Makefile.am @@ -1,6 +1,4 @@ ## Process this file with automake to create Makefile.in -# Makefile for the GNU readline library. -# Copyright (C) 1994,1996,1997 Free Software Foundation, Inc. ASRC = $(srcdir)/vi.c $(srcdir)/emacs.c $(srcdir)/common.c AHDR = vi.h emacs.h common.h @@ -12,32 +10,22 @@ noinst_LIBRARIES = libedit.a libedit_a_SOURCES = chared.c el.c history.c map.c prompt.c readline.c \ search.c tokenizer.c vi.c common.c emacs.c \ hist.c key.c parse.c read.c refresh.c sig.c term.c \ - tty.c help.c fcns.c - -EXTRA_libedit_a_SOURCES = np/unvis.c np/strlcpy.c np/vis.c np/strlcat.c \ - np/fgetln.c + tty.c help.c fcns.c filecomplete.c \ + np/unvis.c np/strlcpy.c np/vis.c np/strlcat.c \ + np/fgetln.c libedit_a_LIBADD = @LIBEDIT_LOBJECTS@ libedit_a_DEPENDENCIES = @LIBEDIT_LOBJECTS@ -noinst_HEADERS = readline/readline.h \ -\ - chared.h el.h el_term.h histedit.h key.h parse.h refresh.h sig.h \ - sys.h tokenizer.h config.h hist.h map.h prompt.h read.h \ - search.h tty.h libedit_term.h vis.h +pkginclude_HEADERS = readline/readline.h -EXTRA_DIST = makelist.sh np/unvis.c np/strlcpy.c np/vis.c np/vis.h np/strlcat.c np/fgetln.c +noinst_HEADERS = chared.h el.h el_term.h histedit.h key.h parse.h refresh.h sig.h \ + sys.h config.h hist.h map.h prompt.h read.h \ + search.h tty.h filecomplete.h np/vis.h -CLEANFILES = makelist common.h emacs.h vi.h fcns.h help.h fcns.c help.c +EXTRA_DIST = makelist.sh -# Make sure to include stuff from this directory first, to get right "config.h" -# Automake puts into DEFAULT_INCLUDES this source and corresponding -# build directory together with ../../include to let all make files -# find the central "config.h". This variable is used before INCLUDES -# above. But in automake 1.10 the order of these are changed. Put the -# includes of this directory into DEFS to always be sure it is first -# before DEFAULT_INCLUDES on the compile line. -DEFS = -DUNDEF_THREADS_HACK -DHAVE_CONFIG_H -DNO_KILL_INTR -I. -I$(srcdir) +CLEANFILES = makelist common.h emacs.h vi.h fcns.h help.h fcns.c help.c SUFFIXES = .sh @@ -101,6 +89,4 @@ term.o: vi.h emacs.h common.h help.h fcns.h tty.o: vi.h emacs.h common.h help.h fcns.h help.o: vi.h emacs.h common.h help.h fcns.h fcns.o: vi.h emacs.h common.h help.h fcns.h - -# Don't update the files from bitkeeper -%::SCCS/s.% +filecomplete.o: vi.h emacs.h common.h help.h fcns.h diff --git a/cmd-line-utils/libedit/README b/cmd-line-utils/libedit/README new file mode 100644 index 0000000000000000000000000000000000000000..0b698a6150d8d71f9bb49622f390334a750050d6 --- /dev/null +++ b/cmd-line-utils/libedit/README @@ -0,0 +1,50 @@ +An approximate method to merge from upstream is: + + # Fetch latest from upstream (we also include some compat stuff) + $ CVS_RSH=ssh; export CVS_RSH + $ CVSROOT="anoncvs@stripped:/cvsroot" + $ cvs co -d libedit -P src/lib/libedit + $ mkdir libedit/np + $ for f in src/common/lib/libc/string/strlcat.c \ + > src/common/lib/libc/string/strlcpy.c \ + > src/include/vis.h \ + > src/lib/libc/gen/unvis.c \ + > src/lib/libc/gen/vis.c \ + > src/tools/compat/fgetln.c + > do + > cvs co -P ${f} + > mv ${f} libedit/np + > done + $ rm -rf src + $ cd libedit + + # Remove files we don't need/use + $ rm -rf CVS TEST Makefile shlib_version *.[0-9] + $ (cd readline; rm -rf CVS Makefile) + + # Rename files to match our naming + $ mv makelist makelist.sh + $ mv term.h el_term.h + + # Remove NetBSD-specific bits + $ for file in $(find . -type f) + > do + > cp ${file} ${file}.orig + > sed -e 's/#include "term.h"/#include "el_term.h"/g' \ + > -e 's/sig_handler/el_sig_handler/g' \ + > -e 's/isprint/el_isprint/g' \ + > -e '/^__RCSID/d' \ + > ${file}.orig >${file} + > rm ${file}.orig + > done + +then merge remaining bits by hand. All MySQL-specific changes should be +marked with XXXMYSQL to make them easier to identify and merge. To generate +a 'clean' diff against upstream you can use the above commands but use + + cvs co -D "2009/02/06 20:09:00" [..] + +to fetch the baseline of most recent merge. + +Please feed any fixes to Jonathan Perkin <jperkin@stripped> who will endeavour +to merge them upstream and keep diffs minimal. diff --git a/cmd-line-utils/libedit/TEST/test.c b/cmd-line-utils/libedit/TEST/test.c deleted file mode 100644 index 605341eac62504a8585f8c6218285c6042b31444..0000000000000000000000000000000000000000 --- a/cmd-line-utils/libedit/TEST/test.c +++ /dev/null @@ -1,269 +0,0 @@ -/* $NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $ */ - -/*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Christos Zoulas of Cornell University. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -#include "compat.h" -#ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\ - The Regents of the University of California. All rights reserved.\n"); -#endif /* not lint */ - -#if !defined(lint) && !defined(SCCSID) -#if 0 -static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $"); -#endif -#endif /* not lint && not SCCSID */ - -/* - * test.c: A little test program - */ -#include "sys.h" -#include <stdio.h> -#include <string.h> -#include <signal.h> -#include <sys/wait.h> -#include <ctype.h> -#include <stdlib.h> -#include <unistd.h> -#include <dirent.h> - -#include "histedit.h" -#include "tokenizer.h" - -static int continuation = 0; -static EditLine *el = NULL; - -static u_char complete(EditLine *, int); - int main(int, char **); -static char *prompt(EditLine *); -static void sig(int); - -static char * -prompt(EditLine *el) -{ - static char a[] = "Edit$"; - static char b[] = "Edit>"; - - return (continuation ? b : a); -} - -static void -sig(int i) -{ - - (void) fprintf(stderr, "Got signal %d.\n", i); - el_reset(el); -} - -static unsigned char -complete(EditLine *el, int ch) -{ - DIR *dd = opendir("."); - struct dirent *dp; - const char* ptr; - const LineInfo *lf = el_line(el); - int len; - - /* - * Find the last word - */ - for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--) - continue; - len = lf->cursor - ++ptr; - - for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) { - if (len > strlen(dp->d_name)) - continue; - if (strncmp(dp->d_name, ptr, len) == 0) { - closedir(dd); - if (el_insertstr(el, &dp->d_name[len]) == -1) - return (CC_ERROR); - else - return (CC_REFRESH); - } - } - - closedir(dd); - return (CC_ERROR); -} - -int -main(int argc, char *argv[]) -{ - int num; - const char *buf; - Tokenizer *tok; - int lastevent = 0, ncontinuation; - History *hist; - HistEvent ev; - - (void) signal(SIGINT, sig); - (void) signal(SIGQUIT, sig); - (void) signal(SIGHUP, sig); - (void) signal(SIGTERM, sig); - - hist = history_init(); /* Init the builtin history */ - /* Remember 100 events */ - history(hist, &ev, H_SETSIZE, 100); - - tok = tok_init(NULL); /* Initialize the tokenizer */ - - /* Initialize editline */ - el = el_init(*argv, stdin, stdout, stderr); - - el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */ - el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */ - el_set(el, EL_PROMPT, prompt); /* Set the prompt function */ - - /* Tell editline to use this history interface */ - el_set(el, EL_HIST, history, hist); - - /* Add a user-defined function */ - el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete); - - /* Bind tab to it */ - el_set(el, EL_BIND, "^I", "ed-complete", NULL); - - /* - * Bind j, k in vi command mode to previous and next line, instead - * of previous and next history. - */ - el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL); - el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL); - - /* - * Source the user's defaults file. - */ - el_source(el, NULL); - - while ((buf = el_gets(el, &num)) != NULL && num != 0) { - int ac; - char **av; -#ifdef DEBUG - (void) fprintf(stderr, "got %d %s", num, buf); -#endif - if (!continuation && num == 1) - continue; - - if (tok_line(tok, buf, &ac, &av) > 0) - ncontinuation = 1; - -#if 0 - if (continuation) { - /* - * Append to the right event in case the user - * moved around in history. - */ - if (history(hist, &ev, H_SET, lastevent) == -1) - err(1, "%d: %s\n", lastevent, ev.str); - history(hist, &ev, H_ADD , buf); - } else { - history(hist, &ev, H_ENTER, buf); - lastevent = ev.num; - } -#else - /* Simpler */ - history(hist, &ev, continuation ? H_APPEND : H_ENTER, buf); -#endif - - continuation = ncontinuation; - ncontinuation = 0; - - if (strcmp(av[0], "history") == 0) { - int rv; - - switch (ac) { - case 1: - for (rv = history(hist, &ev, H_LAST); rv != -1; - rv = history(hist, &ev, H_PREV)) - (void) fprintf(stdout, "%4d %s", - ev.num, ev.str); - break; - - case 2: - if (strcmp(av[1], "clear") == 0) - history(hist, &ev, H_CLEAR); - else - goto badhist; - break; - - case 3: - if (strcmp(av[1], "load") == 0) - history(hist, &ev, H_LOAD, av[2]); - else if (strcmp(av[1], "save") == 0) - history(hist, &ev, H_SAVE, av[2]); - break; - - badhist: - default: - (void) fprintf(stderr, - "Bad history arguments\n"); - break; - } - } else if (el_parse(el, ac, av) == -1) { - switch (fork()) { - case 0: - execvp(av[0], av); - perror(av[0]); - _exit(1); - /*NOTREACHED*/ - break; - - case -1: - perror("fork"); - break; - - default: - if (wait(&num) == -1) - perror("wait"); - (void) fprintf(stderr, "Exit %x\n", num); - break; - } - } - - tok_reset(tok); - } - - el_end(el); - tok_end(tok); - history_end(hist); - - return (0); -} diff --git a/cmd-line-utils/libedit/chared.c b/cmd-line-utils/libedit/chared.c index 4cb6e00d26e42082c5fbf366416233ea0996ac3d..e4823db71473d9397c26ad6328eabde09fc4f069 100644 --- a/cmd-line-utils/libedit/chared.c +++ b/cmd-line-utils/libedit/chared.c @@ -1,4 +1,4 @@ -/* $NetBSD: chared.c,v 1.22 2004/08/13 12:10:38 mycroft Exp $ */ +/* $NetBSD: chared.c,v 1.26 2009/02/06 12:45:25 sketch Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * chared.c: Character editor utilities @@ -40,6 +46,8 @@ #include <stdlib.h> #include "el.h" +private void ch__clearmacro (EditLine *); + /* value to leave unused in line buffer */ #define EL_LEAVE 2 @@ -51,13 +59,13 @@ cv_undo(EditLine *el) { c_undo_t *vu = &el->el_chared.c_undo; c_redo_t *r = &el->el_chared.c_redo; - int size; + unsigned int size; /* Save entire line for undo */ size = el->el_line.lastchar - el->el_line.buffer; vu->len = size; vu->cursor = el->el_line.cursor - el->el_line.buffer; - memcpy(vu->buf, el->el_line.buffer, (size_t)size); + memcpy(vu->buf, el->el_line.buffer, size); /* save command info for redo */ r->count = el->el_state.doingarg ? el->el_state.argument : 0; @@ -439,6 +447,8 @@ cv__endword(char *p, char *high, int n, int (*wtest)(int)) protected int ch_init(EditLine *el) { + c_macro_t *ma = &el->el_chared.c_macro; + el->el_line.buffer = (char *) el_malloc(EL_BUFSIZ); if (el->el_line.buffer == NULL) return (-1); @@ -479,11 +489,10 @@ ch_init(EditLine *el) el->el_state.argument = 1; el->el_state.lastcmd = ED_UNASSIGNED; - el->el_chared.c_macro.level = -1; - el->el_chared.c_macro.offset = 0; - el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO * - sizeof(char *)); - if (el->el_chared.c_macro.macro == NULL) + ma->level = -1; + ma->offset = 0; + ma->macro = (char **) el_malloc(EL_MAXMACRO * sizeof(char *)); + if (ma->macro == NULL) return (-1); return (0); } @@ -492,7 +501,7 @@ ch_init(EditLine *el) * Reset the character editor */ protected void -ch_reset(EditLine *el) +ch_reset(EditLine *el, int mclear) { el->el_line.cursor = el->el_line.buffer; el->el_line.lastchar = el->el_line.buffer; @@ -513,9 +522,19 @@ ch_reset(EditLine *el) el->el_state.argument = 1; el->el_state.lastcmd = ED_UNASSIGNED; - el->el_chared.c_macro.level = -1; - el->el_history.eventno = 0; + + if (mclear) + ch__clearmacro(el); +} + +private void +ch__clearmacro(el) + EditLine *el; +{ + c_macro_t *ma = &el->el_chared.c_macro; + while (ma->level >= 0) + el_free((ptr_t)ma->macro[ma->level--]); } /* ch_enlargebufs(): @@ -623,9 +642,9 @@ ch_end(EditLine *el) el->el_chared.c_redo.cmd = ED_UNASSIGNED; el_free((ptr_t) el->el_chared.c_kill.buf); el->el_chared.c_kill.buf = NULL; + ch_reset(el, 1); el_free((ptr_t) el->el_chared.c_macro.macro); el->el_chared.c_macro.macro = NULL; - ch_reset(el); } diff --git a/cmd-line-utils/libedit/chared.h b/cmd-line-utils/libedit/chared.h index 2dd0a5795c73ca28512fbe1c8ad727052da99558..fa8f5a58d830407fc323be19d2f20d4300c20631 100644 --- a/cmd-line-utils/libedit/chared.h +++ b/cmd-line-utils/libedit/chared.h @@ -1,4 +1,4 @@ -/* $NetBSD: chared.h,v 1.14 2004/08/13 12:10:39 mycroft Exp $ */ +/* $NetBSD: chared.h,v 1.17 2006/03/06 21:11:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -48,7 +48,7 @@ #define EL_MAXMACRO 10 /* - * This is a issue of basic "vi" look-and-feel. Defining VI_MOVE works + * This is an issue of basic "vi" look-and-feel. Defining VI_MOVE works * like real vi: i.e. the transition from command<->insert modes moves * the cursor. * @@ -116,11 +116,10 @@ typedef struct el_chared_t { } el_chared_t; -#define STReof "^D\b\b" #define STRQQ "\"\"" #define isglob(a) (strchr("*[]?", (a)) != NULL) -#define isword(a) (isprint(a)) +#define isword(a) (el_isprint(a)) #define NOP 0x00 #define DELETE 0x01 @@ -161,7 +160,7 @@ protected int c_gets(EditLine *, char *, const char *); protected int c_hpos(EditLine *); protected int ch_init(EditLine *); -protected void ch_reset(EditLine *); +protected void ch_reset(EditLine *, int); protected int ch_enlargebufs(EditLine *, size_t); protected void ch_end(EditLine *); diff --git a/cmd-line-utils/libedit/common.c b/cmd-line-utils/libedit/common.c index 81bf9bf29ffb7c8864183d8293f2e6b7b721b884..d4d024eae10722b93c446565efbcce3e05752c6a 100644 --- a/cmd-line-utils/libedit/common.c +++ b/cmd-line-utils/libedit/common.c @@ -1,4 +1,4 @@ -/* $NetBSD: common.c,v 1.16 2003/08/07 16:44:30 agc Exp $ */ +/* $NetBSD: common.c,v 1.21 2008/09/30 08:37:42 aymeric Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * common.c: Common Editor functions @@ -130,7 +136,7 @@ ed_delete_prev_word(EditLine *el, int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_delete_next_char(EditLine *el, int c __attribute__((__unused__))) +ed_delete_next_char(EditLine *el, int c) { #ifdef notdef /* XXX */ #define EL el->el_line @@ -147,9 +153,8 @@ ed_delete_next_char(EditLine *el, int c __attribute__((__unused__))) #ifdef KSHVI return (CC_ERROR); #else - term_overwrite(el, STReof, 4); - /* then do a EOF */ - term__flush(); + /* then do an EOF */ + term_writechar(el, c); return (CC_EOF); #endif } else { @@ -207,13 +212,13 @@ ed_move_to_end(EditLine *el, int c __attribute__((__unused__))) el->el_line.cursor = el->el_line.lastchar; if (el->el_map.type == MAP_VI) { -#ifdef VI_MOVE - el->el_line.cursor--; -#endif if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } +#ifdef VI_MOVE + el->el_line.cursor--; +#endif } return (CC_CURSOR); } @@ -609,7 +614,7 @@ protected el_action_t ed_start_over(EditLine *el, int c __attribute__((__unused__))) { - ch_reset(el); + ch_reset(el, 0); return (CC_REFRESH); } @@ -904,7 +909,7 @@ ed_command(EditLine *el, int c __attribute__((__unused__))) int tmplen; tmplen = c_gets(el, tmpbuf, "\n: "); - term__putc('\n'); + term__putc(el, '\n'); if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1) term_beep(el); diff --git a/cmd-line-utils/libedit/compat.h b/cmd-line-utils/libedit/compat.h deleted file mode 100644 index 3693a2db809e8fae271e811322217a3bab360366..0000000000000000000000000000000000000000 --- a/cmd-line-utils/libedit/compat.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef __LIBEDIT_COMPATH_H -#define __LIBEDIT_COMPATH_H - -#define __RCSID(x) -#define __COPYRIGHT(x) - -#include "compat_conf.h" - -#ifndef HAVE_VIS_H -/* string visual representation - may want to reimplement */ -#define strvis(d,s,m) strcpy(d,s) -#define strunvis(d,s) strcpy(d,s) -#endif - -#ifndef HAVE_FGETLN -#include "fgetln.h" -#endif - -#ifndef HAVE_ISSETUGID -#define issetugid() (getuid()!=geteuid() || getegid()!=getgid()) -#endif - -#ifndef HAVE_STRLCPY -#include "strlcpy.h" -#endif - -#if HAVE_SYS_CDEFS_H -#include <sys/cdefs.h> -#endif - -#ifndef __P -#ifdef __STDC__ -#define __P(x) x -#else -#define __P(x) () -#endif -#endif - -#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8) -#define __attribute__(A) -#endif - -#endif diff --git a/cmd-line-utils/libedit/compat_conf.h b/cmd-line-utils/libedit/compat_conf.h deleted file mode 100644 index e2b9557f5b1b517b9c915827a0e47f64a667d9da..0000000000000000000000000000000000000000 --- a/cmd-line-utils/libedit/compat_conf.h +++ /dev/null @@ -1,2 +0,0 @@ - -#include "my_config.h" diff --git a/cmd-line-utils/libedit/config.h b/cmd-line-utils/libedit/config.h index 642123d1ddcf7d89051c7d80c1f16da9e4d74b30..2c3989ee31647fe840ec5839939c7e1cc53d993e 100644 --- a/cmd-line-utils/libedit/config.h +++ b/cmd-line-utils/libedit/config.h @@ -1,16 +1,2 @@ - #include "my_config.h" #include "sys.h" - -#if defined(LIBC_SCCS) && !defined(lint) -#define __RCSID(x) -#define __COPYRIGHT(x) -#endif -#define __RENAME(x) -#define _DIAGASSERT(x) - -#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8) -#define __attribute__(A) -#endif - - diff --git a/cmd-line-utils/libedit/editline.3 b/cmd-line-utils/libedit/editline.3 deleted file mode 100644 index 1b812ebcc79fbee2131de55f3b0f5c025b36c308..0000000000000000000000000000000000000000 --- a/cmd-line-utils/libedit/editline.3 +++ /dev/null @@ -1,619 +0,0 @@ -.\" $NetBSD: editline.3,v 1.21 2001/04/02 18:29:49 wiz Exp $ -.\" -.\" Copyright (c) 1997-1999 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" -.\" This file was contributed to The NetBSD Foundation by Luke Mewburn. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the NetBSD -.\" Foundation, Inc. and its contributors. -.\" 4. Neither the name of The NetBSD Foundation nor the names of its -.\" contributors may be used to endorse or promote products derived -.\" from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS -.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS -.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd November 12, 1999 -.Os -.Dt EDITLINE 3 -.Sh NAME -.Nm editline , -.Nm el_init , -.Nm el_end , -.Nm el_reset , -.Nm el_gets , -.Nm el_getc , -.Nm el_push , -.Nm el_parse , -.Nm el_set , -.Nm el_source , -.Nm el_resize , -.Nm el_line , -.Nm el_insertstr , -.Nm el_deletestr , -.Nm history_init , -.Nm history_end , -.Nm history -.Nd line editor and history functions -.Sh LIBRARY -.Lb libedit -.Sh SYNOPSIS -.Fd #include <histedit.h> -.Ft EditLine * -.Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr" -.Ft void -.Fn el_end "EditLine *e" -.Ft void -.Fn el_reset "EditLine *e" -.Ft const char * -.Fn el_gets "EditLine *e" "int *count" -.Ft int -.Fn el_getc "EditLine *e" "char *ch" -.Ft void -.Fn el_push "EditLine *e" "const char *str" -.Ft int -.Fn el_parse "EditLine *e" "int argc" "char *argv[]" -.Ft int -.Fn el_set "EditLine *e" "int op" "..." -.Ft int -.Fn el_get "EditLine *e" "int op" "void *result" -.Ft int -.Fn el_source "EditLine *e" "const char *file" -.Ft void -.Fn el_resize "EditLine *e" -.Ft const LineInfo * -.Fn el_line "EditLine *e" -.Ft int -.Fn el_insertstr "EditLine *e" "const char *str" -.Ft void -.Fn el_deletestr "EditLine *e" "int count" -.Ft History * -.Fn history_init -.Ft void -.Fn history_end "History *h" -.Ft int -.Fn history "History *h" "HistEvent *ev" "int op" "..." -.Sh DESCRIPTION -The -.Nm -library provides generic line editing and history functions, -similar to those found in -.Xr sh 1 . -.Pp -These functions are available in the -.Nm libedit -library (which needs the -.Nm libtermcap -library). -Programs should be linked with -.Fl ledit ltermcap . -.Sh LINE EDITING FUNCTIONS -The line editing functions use a common data structure, -.Fa EditLine , -which is created by -.Fn el_init -and freed by -.Fn el_end . -.Pp -The following functions are available: -.Bl -tag -width 4n -.It Fn el_init -Initialise the line editor, and return a data structure -to be used by all other line editing functions. -.Fa prog -is the name of the invoking program, used when reading the -.Xr editrc 5 -file to determine which settings to use. -.Fa fin , -.Fa fout -and -.Fa ferr -are the input, output, and error streams (respectively) to use. -In this documentation, references to -.Dq the tty -are actually to this input/output stream combination. -.It Fn el_end -Clean up and finish with -.Fa e , -assumed to have been created with -.Fn el_init . -.It Fn el_reset -Reset the tty and the parser. -This should be called after an error which may have upset the tty's -state. -.It Fn el_gets -Read a line from the tty. -.Fa count -is modified to contain the number of characters read. -Returns the line read if successful, or -.Dv NULL -if no characters were read or if an error occurred. -.It Fn el_getc -Read a character from the tty. -.Fa ch -is modified to contain the character read. -Returns the number of characters read if successful, -1 otherwise. -.It Fn el_push -Pushes -.Fa str -back onto the input stream. -This is used by the macro expansion mechanism. -Refer to the description of -.Ic bind -.Fl s -in -.Xr editrc 5 -for more information. -.It Fn el_parse -Parses the -.Fa argv -array (which is -.Fa argc -elements in size) -to execute builtin -.Nm -commands. -If the command is prefixed with -.Dq prog: -then -.Fn el_parse -will only execute the command if -.Dq prog -matches the -.Fa prog -argument supplied to -.Fn el_init . -The return value is --1 if the command is unknown, -0 if there was no error or -.Dq prog -didn't match, or -1 if the command returned an error. -Refer to -.Xr editrc 5 -for more information. -.It Fn el_set -Set -.Nm -parameters. -.Fa op -determines which parameter to set, and each operation has its -own parameter list. -.Pp -The following values for -.Fa op -are supported, along with the required argument list: -.Bl -tag -width 4n -.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)" -Define prompt printing function as -.Fa f , -which is to return a string that contains the prompt. -.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)" -Define right side prompt printing function as -.Fa f , -which is to return a string that contains the prompt. -.It Dv EL_TERMINAL , Fa "const char *type" -Define terminal type of the tty to be -.Fa type , -or to -.Ev TERM -if -.Fa type -is -.Dv NULL . -.It Dv EL_EDITOR , Fa "const char *mode" -Set editing mode to -.Fa mode , -which must be one of -.Dq emacs -or -.Dq vi . -.It Dv EL_SIGNAL , Fa "int flag" -If -.Fa flag -is non-zero, -.Nm -will install its own signal handler for the following signals when -reading command input: -.Dv SIGCONT , -.Dv SIGHUP , -.Dv SIGINT , -.Dv SIGQUIT , -.Dv SIGSTOP , -.Dv SIGTERM , -.Dv SIGTSTP , -and -.Dv SIGWINCH . -Otherwise, the current signal handlers will be used. -.It Dv EL_BIND , Xo -.Fa "const char *" , -.Fa "..." , -.Dv NULL -.Xc -Perform the -.Ic bind -builtin command. -Refer to -.Xr editrc 5 -for more information. -.It Dv EL_ECHOTC , Xo -.Fa "const char *" , -.Fa "..." , -.Dv NULL -.Xc -Perform the -.Ic echotc -builtin command. -Refer to -.Xr editrc 5 -for more information. -.It Dv EL_SETTC , Xo -.Fa "const char *" , -.Fa "..." , -.Dv NULL -.Xc -Perform the -.Ic settc -builtin command. -Refer to -.Xr editrc 5 -for more information. -.It Dv EL_SETTY , Xo -.Fa "const char *" , -.Fa "..." , -.Dv NULL -.Xc -Perform the -.Ic setty -builtin command. -Refer to -.Xr editrc 5 -for more information. -.It Dv EL_TELLTC , Xo -.Fa "const char *" , -.Fa "..." , -.Dv NULL -.Xc -Perform the -.Ic telltc -builtin command. -Refer to -.Xr editrc 5 -for more information. -.It Dv EL_ADDFN , Xo -.Fa "const char *name" , -.Fa "const char *help" , -.Fa "unsigned char (*func)(EditLine *e, int ch) -.Xc -Add a user defined function, -.Fn func , -referred to as -.Fa name -which is invoked when a key which is bound to -.Fa name -is entered. -.Fa help -is a description of -.Fa name . -At invocation time, -.Fa ch -is the key which caused the invocation. -The return value of -.Fn func -should be one of: -.Bl -tag -width "CC_REDISPLAY" -.It Dv CC_NORM -Add a normal character. -.It Dv CC_NEWLINE -End of line was entered. -.It Dv CC_EOF -EOF was entered. -.It Dv CC_ARGHACK -Expecting further command input as arguments, do nothing visually. -.It Dv CC_REFRESH -Refresh display. -.It Dv CC_REFRESH_BEEP -Refresh display, and beep. -.It Dv CC_CURSOR -Cursor moved, so update and perform -.Dv CC_REFRESH. -.It Dv CC_REDISPLAY -Redisplay entire input line. -This is useful if a key binding outputs extra information. -.It Dv CC_ERROR -An error occurred. -Beep, and flush tty. -.It Dv CC_FATAL -Fatal error, reset tty to known state. -.El -.It Dv EL_HIST , Xo -.Fa "History *(*func)(History *, int op, ...)" , -.Fa "const char *ptr" -.Xc -Defines which history function to use, which is usually -.Fn history . -.Fa ptr -should be the value returned by -.Fn history_init . -.It Dv EL_EDITMODE , Fa "int flag" -If -.Fa flag -is non-zero, -editing is enabled (the default). -Note that this is only an indication, and does not -affect the operation of -.Nm "" . -At this time, it is the caller's responsibility to -check this -(using -.Fn el_get ) -to determine if editing should be enabled or not. -.El -.It Fn el_get -Get -.Nm -parameters. -.Fa op -determines which parameter to retrieve into -.Fa result . -.Pp -The following values for -.Fa op -are supported, along with actual type of -.Fa result : -.Bl -tag -width 4n -.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)" -Return a pointer to the function that displays the prompt. -.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)" -Return a pointer to the function that displays the rightside prompt. -.It Dv EL_EDITOR , Fa "const char *" -Return the name of the editor, which will be one of -.Dq emacs -or -.Dq vi . -.It Dv EL_SIGNAL , Fa "int *" -Return non-zero if -.Nm -has installed private signal handlers (see -.Fn el_get -above). -.It Dv EL_EDITMODE, Fa "int *" -Return non-zero if editing is enabled. -.El -.It Fn el_source -Initialise -.Nm -by reading the contents of -.Fa file . -.Fn el_parse -is called for each line in -.Fa file . -If -.Fa file -is -.Dv NULL , -try -.Pa $PWD/.editrc -then -.Pa $HOME/.editrc . -Refer to -.Xr editrc 5 -for details on the format of -.Fa file . -.It Fn el_resize -Must be called if the terminal size changes. -If -.Dv EL_SIGNAL -has been set with -.Fn el_set , -then this is done automatically. -Otherwise, it's the responsibility of the application to call -.Fn el_resize -on the appropriate occasions. -.It Fn el_line -Return the editing information for the current line in a -.Fa LineInfo -structure, which is defined as follows: -.Bd -literal -typedef struct lineinfo { - const char *buffer; /* address of buffer */ - const char *cursor; /* address of cursor */ - const char *lastchar; /* address of last character */ -} LineInfo; -.Ed -.It Fn el_insertstr -Insert -.Fa str -into the line at the cursor. -Returns -1 if -.Fa str -is empty or won't fit, and 0 otherwise. -.It Fn el_deletestr -Delete -.Fa num -characters before the cursor. -.El -.Sh HISTORY LIST FUNCTIONS -The history functions use a common data structure, -.Fa History , -which is created by -.Fn history_init -and freed by -.Fn history_end . -.Pp -The following functions are available: -.Bl -tag -width 4n -.It Fn history_init -Initialise the history list, and return a data structure -to be used by all other history list functions. -.It Fn history_end -Clean up and finish with -.Fa h , -assumed to have been created with -.Fn history_init . -.It Fn history -Perform operation -.Fa op -on the history list, with optional arguments as needed by the -operation. -.Fa ev -is changed accordingly to operation. -The following values for -.Fa op -are supported, along with the required argument list: -.Bl -tag -width 4n -.It Dv H_SETSIZE , Fa "int size" -Set size of history to -.Fa size -elements. -.It Dv H_GETSIZE -Get number of events currently in history. -.It Dv H_END -Cleans up and finishes with -.Fa h , -assumed to be created with -.Fn history_init . -.It Dv H_CLEAR -Clear the history. -.It Dv H_FUNC , Xo -.Fa "void *ptr" , -.Fa "history_gfun_t first" , -.Fa "history_gfun_t next" , -.Fa "history_gfun_t last" , -.Fa "history_gfun_t prev" , -.Fa "history_gfun_t curr" , -.Fa "history_sfun_t set" , -.Fa "history_vfun_t clear" , -.Fa "history_efun_t enter" , -.Fa "history_efun_t add" -.Xc -Define functions to perform various history operations. -.Fa ptr -is the argument given to a function when it's invoked. -.It Dv H_FIRST -Return the first element in the history. -.It Dv H_LAST -Return the last element in the history. -.It Dv H_PREV -Return the previous element in the history. -.It Dv H_NEXT -Return the next element in the history. -.It Dv H_CURR -Return the current element in the history. -.It Dv H_SET -Set the cursor to point to the requested element. -.It Dv H_ADD , Fa "const char *str" -Append -.Fa str -to the current element of the history, or create an element with -.It Dv H_APPEND , Fa "const char *str" -Append -.Fa str -to the last new element of the history. -.It Dv H_ENTER , Fa "const char *str" -Add -.Fa str -as a new element to the history, and, if necessary, -removing the oldest entry to keep the list to the created size. -.It Dv H_PREV_STR , Fa "const char *str" -Return the closest previous event that starts with -.Fa str . -.It Dv H_NEXT_STR , Fa "const char *str" -Return the closest next event that starts with -.Fa str . -.It Dv H_PREV_EVENT , Fa "int e" -Return the previous event numbered -.Fa e . -.It Dv H_NEXT_EVENT , Fa "int e" -Return the next event numbered -.Fa e . -.It Dv H_LOAD , Fa "const char *file" -Load the history list stored in -.Fa file . -.It Dv H_SAVE , Fa "const char *file" -Save the history list to -.Fa file . -.El -.Pp -.Fn history -returns 0 if the operation -.Fa op -succeeds. Otherwise, -1 is returned and -.Fa ev -is updated to contain more details about the error. -.El -.\"XXX.Sh EXAMPLES -.\"XXX: provide some examples -.Sh SEE ALSO -.Xr editrc 5 , -.Xr sh 1 , -.Xr signal 3 , -.Xr termcap 3 -.Sh HISTORY -The -.Nm -library first appeared in -.Bx 4.4 . -.Dv CC_REDISPLAY -appeared in -.Nx 1.3 . -.Dv CC_REFRESH_BEEP , -.Dv EL_EDITMODE -and the readline emulation appeared in -.Nx 1.4 . -.Dv EL_RPROMPT -appeared in -.Nx 1.5 . -.Sh AUTHORS -The -.Nm -library was written by Christos Zoulas. -Luke Mewburn wrote this manual and implemented -.Dv CC_REDISPLAY , -.Dv CC_REFRESH_BEEP , -.Dv EL_EDITMODE , -and -.Dv EL_RPROMPT . -Jaromir Dolecek implemented the readline emulation. -.Sh BUGS -The tokenization functions are not publically defined in -.Fd <histedit.h>. -.Pp -At this time, it is the responsibility of the caller to -check the result of the -.Dv EL_EDITMODE -operation of -.Fn el_get -(after an -.Fn el_source -or -.Fn el_parse ) -to determine if -.Nm -should be used for further input. -I.e., -.Dv EL_EDITMODE -is purely an indication of the result of the most recent -.Xr editrc 5 -.Ic edit -command. diff --git a/cmd-line-utils/libedit/editrc.5 b/cmd-line-utils/libedit/editrc.5 deleted file mode 100644 index b1122618939891228c3a47ebd411352e22245dfe..0000000000000000000000000000000000000000 --- a/cmd-line-utils/libedit/editrc.5 +++ /dev/null @@ -1,491 +0,0 @@ -.\" $NetBSD: editrc.5,v 1.11 2001/06/19 13:42:09 wiz Exp $ -.\" -.\" Copyright (c) 1997-2000 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" -.\" This file was contributed to The NetBSD Foundation by Luke Mewburn. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the NetBSD -.\" Foundation, Inc. and its contributors. -.\" 4. Neither the name of The NetBSD Foundation nor the names of its -.\" contributors may be used to endorse or promote products derived -.\" from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS -.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS -.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd November 8, 2000 -.Os -.Dt EDITRC 5 -.Sh NAME -.Nm editrc -.Nd configuration file for editline library -.Sh SYNOPSIS -.Nm -.Sh DESCRIPTION -The -.Nm -file defines various settings to be used by the -.Xr editline 3 -library. -.Pp -The format of each line is: -.Dl [prog:]command [arg [...]] -.Pp -.Ar command -is one of the -.Xr editline 3 -builtin commands. -Refer to -.Sx BUILTIN COMMANDS -for more information. -.Pp -.Ar prog -is the program name string that a program defines when it calls -.Xr el_init 3 -to setup -.Xr editline 3 , -which is usually -.Va argv[0] . -.Ar command -will be executed for any program which matches -.Ar prog . -.Pp -.Ar prog -may also be a -.Xr regex 3 -style -regular expression, in which case -.Ar command -will be executed for any program that matches the regular expression. -.Pp -If -.Ar prog -is absent, -.Ar command -is executed for all programs. -.Sh BUILTIN COMMANDS -The -.Nm editline -library has some builtin commands, which affect the way -that the line editing and history functions operate. -These are based on similar named builtins present in the -.Xr tcsh 1 -shell. -.Pp -The following builtin commands are available: -.Bl -tag -width 4n -.It Ic bind Xo -.Op Fl a -.Op Fl e -.Op Fl k -.Op Fl l -.Op Fl r -.Op Fl s -.Op Fl v -.Op Ar key Op Ar command -.Xc -Without options, list all bound keys, and the editor command to which -each is bound. -If -.Ar key -is supplied, show the bindings for -.Ar key . -If -.Ar key command -is supplied, bind -.Ar command -to -.Ar key . -Options include: -.Bl -tag -width 4n -.It Fl e -Bind all keys to the standard GNU Emacs-like bindings. -.It Fl v -Bind all keys to the standard -.Xr vi 1 -like -bindings. -.It Fl a -List or change key bindings in the -.Xr vi 1 -mode alternate (command mode) key map. -.It Fl k -.Ar key -is interpreted as a symbolic arrow key name, which may be one of -.Sq up , -.Sq down , -.Sq left -or -.Sq right . -.It Fl l -List all editor commands and a short description of each. -.It Fl r -Remove a key's binding. -.It Fl s -.Ar command -is taken as a literal string and treated as terminal input when -.Ar key -is typed. -Bound keys in -.Ar command -are themselves reinterpreted, and this continues for ten levels of -interpretation. -.El -.Pp -.Ar command -may be one of the commands documented in -.Sx "EDITOR COMMANDS" -below, or another key. -.Pp -.Ar key -and -.Ar command -can contain control characters of the form -.Sm off -.Sq No ^ Ar character -.Sm on -.Po -e.g. -.Sq ^A -.Pc , -and the following backslashed escape sequences: -.Pp -.Bl -tag -compact -offset indent -width 4n -.It Ic \ea -Bell -.It Ic \eb -Backspace -.It Ic \ee -Escape -.It Ic \ef -Formfeed -.It Ic \en -Newline -.It Ic \er -Carriage return -.It Ic \et -Horizontal tab -.It Ic \ev -Vertical tab -.Sm off -.It Sy \e Ar nnn -.Sm on -The ASCII character corresponding to the octal number -.Ar nnn . -.El -.Pp -.Sq \e -nullifies the special meaning of the following character, -if it has any, notably -.Sq \e -and -.Sq ^ . -.It Ic echotc Xo -.Op Fl sv -.Ar arg -.Ar ... -.Xc -Exercise terminal capabilities given in -.Ar arg Ar ... . -If -.Ar arg -is -.Sq baud , -.Sq cols , -.Sq lines , -.Sq rows , -.Sq meta or -.Sq tabs , -the value of that capability is printed, with -.Dq yes -or -.Dq no -indicating that the terminal does or does not have that capability. -.Pp -.Fl s -returns an emptry string for non-existent capabilities, rather than -causing an error. -.Fl v -causes messages to be verbose. -.It Ic edit Op Li on | Li off -Enable or disable the -.Nm editline -functionality in a program. -.It Ic history -List the history. -.It Ic telltc -List the values of all the terminal capabilities (see -.Xr termcap 5 ). -.It Ic settc Ar cap Ar val -Set the terminal capability -.Ar cap -to -.Ar val , -as defined in -.Xr termcap 5 . -No sanity checking is done. -.It Ic setty Xo -.Op Fl a -.Op Fl d -.Op Fl q -.Op Fl x -.Op Ar +mode -.Op Ar -mode -.Op Ar mode -.Xc -Control which tty modes that -.Nm -won't allow the user to change. -.Fl d , -.Fl q -or -.Fl x -tells -.Ic setty -to act on the -.Sq edit , -.Sq quote -or -.Sq execute -set of tty modes respectively; defaulting to -.Fl x . -.Pp -Without other arguments, -.Ic setty -lists the modes in the chosen set which are fixed on -.Po -.Sq +mode -.Pc -or off -.Po -.Sq -mode -.Pc . -.Fl a -lists all tty modes in the chosen set regardless of the setting. -With -.Ar +mode , -.Ar -mode -or -.Ar mode , -fixes -.Ar mode -on or off or removes control of -.Ar mode -in the chosen set. -.El -.Sh EDITOR COMMANDS -The following editor commands are available for use in key bindings: -.\" Section automatically generated with makelist -.Bl -tag -width 4n -.It Ic vi-paste-next -Vi paste previous deletion to the right of the cursor. -.It Ic vi-paste-prev -Vi paste previous deletion to the left of the cursor. -.It Ic vi-prev-space-word -Vi move to the previous space delimited word. -.It Ic vi-prev-word -Vi move to the previous word. -.It Ic vi-next-space-word -Vi move to the next space delimited word. -.It Ic vi-next-word -Vi move to the next word. -.It Ic vi-change-case -Vi change case of character under the cursor and advance one character. -.It Ic vi-change-meta -Vi change prefix command. -.It Ic vi-insert-at-bol -Vi enter insert mode at the beginning of line. -.It Ic vi-replace-char -Vi replace character under the cursor with the next character typed. -.It Ic vi-replace-mode -Vi enter replace mode. -.It Ic vi-substitute-char -Vi replace character under the cursor and enter insert mode. -.It Ic vi-substitute-line -Vi substitute entire line. -.It Ic vi-change-to-eol -Vi change to end of line. -.It Ic vi-insert -Vi enter insert mode. -.It Ic vi-add -Vi enter insert mode after the cursor. -.It Ic vi-add-at-eol -Vi enter insert mode at end of line. -.It Ic vi-delete-meta -Vi delete prefix command. -.It Ic vi-end-word -Vi move to the end of the current space delimited word. -.It Ic vi-to-end-word -Vi move to the end of the current word. -.It Ic vi-undo -Vi undo last change. -.It Ic vi-command-mode -Vi enter command mode (use alternative key bindings). -.It Ic vi-zero -Vi move to the beginning of line. -.It Ic vi-delete-prev-char -Vi move to previous character (backspace). -.It Ic vi-list-or-eof -Vi list choices for completion or indicate end of file if empty line. -.It Ic vi-kill-line-prev -Vi cut from beginning of line to cursor. -.It Ic vi-search-prev -Vi search history previous. -.It Ic vi-search-next -Vi search history next. -.It Ic vi-repeat-search-next -Vi repeat current search in the same search direction. -.It Ic vi-repeat-search-prev -Vi repeat current search in the opposite search direction. -.It Ic vi-next-char -Vi move to the character specified next. -.It Ic vi-prev-char -Vi move to the character specified previous. -.It Ic vi-to-next-char -Vi move up to the character specified next. -.It Ic vi-to-prev-char -Vi move up to the character specified previous. -.It Ic vi-repeat-next-char -Vi repeat current character search in the same search direction. -.It Ic vi-repeat-prev-char -Vi repeat current character search in the opposite search direction. -.It Ic em-delete-or-list -Delete character under cursor or list completions if at end of line. -.It Ic em-delete-next-word -Cut from cursor to end of current word. -.It Ic em-yank -Paste cut buffer at cursor position. -.It Ic em-kill-line -Cut the entire line and save in cut buffer. -.It Ic em-kill-region -Cut area between mark and cursor and save in cut buffer. -.It Ic em-copy-region -Copy area between mark and cursor to cut buffer. -.It Ic em-gosmacs-traspose -Exchange the two characters before the cursor. -.It Ic em-next-word -Move next to end of current word. -.It Ic em-upper-case -Uppercase the characters from cursor to end of current word. -.It Ic em-capitol-case -Capitalize the characters from cursor to end of current word. -.It Ic em-lower-case -Lowercase the characters from cursor to end of current word. -.It Ic em-set-mark -Set the mark at cursor. -.It Ic em-exchange-mark -Exchange the cursor and mark. -.It Ic em-universal-argument -Universal argument (argument times 4). -.It Ic em-meta-next -Add 8th bit to next character typed. -.It Ic em-toggle-overwrite -Switch from insert to overwrite mode or vice versa. -.It Ic em-copy-prev-word -Copy current word to cursor. -.It Ic em-inc-search-next -Emacs incremental next search. -.It Ic em-inc-search-prev -Emacs incremental reverse search. -.It Ic ed-end-of-file -Indicate end of file. -.It Ic ed-insert -Add character to the line. -.It Ic ed-delete-prev-word -Delete from beginning of current word to cursor. -.It Ic ed-delete-next-char -Delete character under cursor. -.It Ic ed-kill-line -Cut to the end of line. -.It Ic ed-move-to-end -Move cursor to the end of line. -.It Ic ed-move-to-beg -Move cursor to the beginning of line. -.It Ic ed-transpose-chars -Exchange the character to the left of the cursor with the one under it. -.It Ic ed-next-char -Move to the right one character. -.It Ic ed-prev-word -Move to the beginning of the current word. -.It Ic ed-prev-char -Move to the left one character. -.It Ic ed-quoted-insert -Add the next character typed verbatim. -.It Ic ed-digit -Adds to argument or enters a digit. -.It Ic ed-argument-digit -Digit that starts argument. -.It Ic ed-unassigned -Indicates unbound character. -.It Ic ed-tty-sigint -Tty interrupt character. -.It Ic ed-tty-dsusp -Tty delayed suspend character. -.It Ic ed-tty-flush-output -Tty flush output characters. -.It Ic ed-tty-sigquit -Tty quit character. -.It Ic ed-tty-sigtstp -Tty suspend character. -.It Ic ed-tty-stop-output -Tty disallow output characters. -.It Ic ed-tty-start-output -Tty allow output characters. -.It Ic ed-newline -Execute command. -.It Ic ed-delete-prev-char -Delete the character to the left of the cursor. -.It Ic ed-clear-screen -Clear screen leaving current line at the top. -.It Ic ed-redisplay -Redisplay everything. -.It Ic ed-start-over -Erase current line and start from scratch. -.It Ic ed-sequence-lead-in -First character in a bound sequence. -.It Ic ed-prev-history -Move to the previous history line. -.It Ic ed-next-history -Move to the next history line. -.It Ic ed-search-prev-history -Search previous in history for a line matching the current. -.It Ic ed-search-next-history -Search next in history for a line matching the current. -.It Ic ed-prev-line -Move up one line. -.It Ic ed-next-line -Move down one line. -.It Ic ed-command -Editline extended command. -.El -.\" End of section automatically generated with makelist -.Sh SEE ALSO -.Xr editline 3 , -.Xr regex 3 , -.Xr termcap 5 -.Sh AUTHORS -The -.Nm editline -library was written by Christos Zoulas, -and this manual was written by Luke Mewburn, -with some sections inspired by -.Xr tcsh 1 . diff --git a/cmd-line-utils/libedit/el.c b/cmd-line-utils/libedit/el.c index c32a01b215153eacb321326c2f99cdd7c0efd936..d99946eb68f6fb3e70e5d35cc683669d41797bf4 100644 --- a/cmd-line-utils/libedit/el.c +++ b/cmd-line-utils/libedit/el.c @@ -1,4 +1,4 @@ -/* $NetBSD: el.c,v 1.39 2004/07/08 00:51:36 christos Exp $ */ +/* $NetBSD: el.c,v 1.47 2009/01/18 12:17:24 lukem Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * el.c: EditLine interface functions @@ -58,9 +64,12 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr) memset(el, 0, sizeof(EditLine)); - el->el_infd = fileno(fin); + el->el_infile = fin; el->el_outfile = fout; el->el_errfile = ferr; + + el->el_infd = fileno(fin); + if ((el->el_prog = el_strdup(prog)) == NULL) { el_free(el); return NULL; @@ -126,7 +135,7 @@ el_reset(EditLine *el) { tty_cookedmode(el); - ch_reset(el); /* XXX: Do we want that? */ + ch_reset(el, 0); /* XXX: Do we want that? */ } @@ -136,29 +145,29 @@ el_reset(EditLine *el) public int el_set(EditLine *el, int op, ...) { - va_list va; + va_list ap; int rv = 0; if (el == NULL) return (-1); - va_start(va, op); + va_start(ap, op); switch (op) { case EL_PROMPT: case EL_RPROMPT: - rv = prompt_set(el, va_arg(va, el_pfunc_t), op); + rv = prompt_set(el, va_arg(ap, el_pfunc_t), op); break; case EL_TERMINAL: - rv = term_set(el, va_arg(va, char *)); + rv = term_set(el, va_arg(ap, char *)); break; case EL_EDITOR: - rv = map_set_editor(el, va_arg(va, char *)); + rv = map_set_editor(el, va_arg(ap, char *)); break; case EL_SIGNAL: - if (va_arg(va, int)) + if (va_arg(ap, int)) el->el_flags |= HANDLE_SIGNALS; else el->el_flags &= ~HANDLE_SIGNALS; @@ -167,6 +176,7 @@ el_set(EditLine *el, int op, ...) case EL_BIND: case EL_TELLTC: case EL_SETTC: + case EL_GETTC: case EL_ECHOTC: case EL_SETTY: { @@ -174,7 +184,7 @@ el_set(EditLine *el, int op, ...) int i; for (i = 1; i < 20; i++) - if ((argv[i] = va_arg(va, char *)) == NULL) + if ((argv[i] = va_arg(ap, char *)) == NULL) break; switch (op) { @@ -213,9 +223,9 @@ el_set(EditLine *el, int op, ...) case EL_ADDFN: { - char *name = va_arg(va, char *); - char *help = va_arg(va, char *); - el_func_t func = va_arg(va, el_func_t); + char *name = va_arg(ap, char *); + char *help = va_arg(ap, char *); + el_func_t func = va_arg(ap, el_func_t); rv = map_addfunc(el, name, help, func); break; @@ -223,15 +233,15 @@ el_set(EditLine *el, int op, ...) case EL_HIST: { - hist_fun_t func = va_arg(va, hist_fun_t); - ptr_t ptr = va_arg(va, char *); + hist_fun_t func = va_arg(ap, hist_fun_t); + ptr_t ptr = va_arg(ap, char *); rv = hist_set(el, func, ptr); break; } case EL_EDITMODE: - if (va_arg(va, int)) + if (va_arg(ap, int)) el->el_flags &= ~EDIT_DISABLED; else el->el_flags |= EDIT_DISABLED; @@ -240,17 +250,17 @@ el_set(EditLine *el, int op, ...) case EL_GETCFN: { - el_rfunc_t rc = va_arg(va, el_rfunc_t); + el_rfunc_t rc = va_arg(ap, el_rfunc_t); rv = el_read_setfn(el, rc); break; } case EL_CLIENTDATA: - el->el_data = va_arg(va, void *); + el->el_data = va_arg(ap, void *); break; case EL_UNBUFFERED: - rv = va_arg(va, int); + rv = va_arg(ap, int); if (rv && !(el->el_flags & UNBUFFERED)) { el->el_flags |= UNBUFFERED; read_prepare(el); @@ -262,7 +272,7 @@ el_set(EditLine *el, int op, ...) break; case EL_PREP_TERM: - rv = va_arg(va, int); + rv = va_arg(ap, int); if (rv) (void) tty_rawmode(el); else @@ -270,12 +280,45 @@ el_set(EditLine *el, int op, ...) rv = 0; break; + case EL_SETFP: + { + FILE *fp; + int what; + + what = va_arg(ap, int); + fp = va_arg(ap, FILE *); + + rv = 0; + switch (what) { + case 0: + el->el_infile = fp; + el->el_infd = fileno(fp); + break; + case 1: + el->el_outfile = fp; + break; + case 2: + el->el_errfile = fp; + break; + default: + rv = -1; + break; + } + break; + } + + case EL_REFRESH: + re_clear_display(el); + re_refresh(el); + term__flush(el); + break; + default: rv = -1; break; } - va_end(va); + va_end(ap); return (rv); } @@ -284,90 +327,71 @@ el_set(EditLine *el, int op, ...) * retrieve the editline parameters */ public int -el_get(EditLine *el, int op, void *ret) +el_get(EditLine *el, int op, ...) { + va_list ap; int rv; - if (el == NULL || ret == NULL) - return (-1); + if (el == NULL) + return -1; + + va_start(ap, op); + switch (op) { case EL_PROMPT: case EL_RPROMPT: - rv = prompt_get(el, (void *) &ret, op); + rv = prompt_get(el, va_arg(ap, el_pfunc_t *), op); break; case EL_EDITOR: - rv = map_get_editor(el, (void *) &ret); + rv = map_get_editor(el, va_arg(ap, const char **)); break; case EL_SIGNAL: - *((int *) ret) = (el->el_flags & HANDLE_SIGNALS); + *va_arg(ap, int *) = (el->el_flags & HANDLE_SIGNALS); rv = 0; break; case EL_EDITMODE: - *((int *) ret) = (!(el->el_flags & EDIT_DISABLED)); + *va_arg(ap, int *) = !(el->el_flags & EDIT_DISABLED); rv = 0; break; case EL_TERMINAL: - term_get(el, (const char **)ret); + term_get(el, va_arg(ap, const char **)); rv = 0; break; -#if 0 /* XXX */ - case EL_BIND: - case EL_TELLTC: - case EL_SETTC: - case EL_ECHOTC: - case EL_SETTY: + case EL_GETTC: { - const char *argv[20]; + static char name[] = "gettc"; + char *argv[20]; int i; - for (i = 1; i < sizeof(argv) / sizeof(argv[0]); i++) - if ((argv[i] = va_arg(va, char *)) == NULL) + for (i = 1; i < (int)(sizeof(argv) / sizeof(argv[0])); i++) + if ((argv[i] = va_arg(ap, char *)) == NULL) break; switch (op) { - case EL_BIND: - argv[0] = "bind"; - rv = map_bind(el, i, argv); - break; - - case EL_TELLTC: - argv[0] = "telltc"; - rv = term_telltc(el, i, argv); - break; - - case EL_SETTC: - argv[0] = "settc"; - rv = term_settc(el, i, argv); - break; - - case EL_ECHOTC: - argv[0] = "echotc"; - rv = term_echotc(el, i, argv); - break; - - case EL_SETTY: - argv[0] = "setty"; - rv = tty_stty(el, i, argv); + case EL_GETTC: + argv[0] = name; + rv = term_gettc(el, i, argv); break; default: rv = -1; - EL_ABORT((el->errfile, "Bad op %d\n", op)); + EL_ABORT((el->el_errfile, "Bad op %d\n", op)); break; } break; } +#if 0 /* XXX */ case EL_ADDFN: { - char *name = va_arg(va, char *); - char *help = va_arg(va, char *); - el_func_t func = va_arg(va, el_func_t); + char *name = va_arg(ap, char *); + char *help = va_arg(ap, char *); + el_func_t func = va_arg(ap, el_func_t); rv = map_addfunc(el, name, help, func); break; @@ -375,31 +399,57 @@ el_get(EditLine *el, int op, void *ret) case EL_HIST: { - hist_fun_t func = va_arg(va, hist_fun_t); - ptr_t ptr = va_arg(va, char *); + hist_fun_t func = va_arg(ap, hist_fun_t); + ptr_t ptr = va_arg(ap, char *); rv = hist_set(el, func, ptr); } break; #endif /* XXX */ case EL_GETCFN: - *((el_rfunc_t *)ret) = el_read_getfn(el); + *va_arg(ap, el_rfunc_t *) = el_read_getfn(el); rv = 0; break; case EL_CLIENTDATA: - *((void **)ret) = el->el_data; + *va_arg(ap, void **) = el->el_data; rv = 0; break; case EL_UNBUFFERED: - *((int *) ret) = (!(el->el_flags & UNBUFFERED)); + *va_arg(ap, int *) = (!(el->el_flags & UNBUFFERED)); rv = 0; break; + case EL_GETFP: + { + int what; + FILE **fpp; + + what = va_arg(ap, int); + fpp = va_arg(ap, FILE **); + rv = 0; + switch (what) { + case 0: + *fpp = el->el_infile; + break; + case 1: + *fpp = el->el_outfile; + break; + case 2: + *fpp = el->el_errfile; + break; + default: + rv = -1; + break; + } + break; + } default: rv = -1; + break; } + va_end(ap); return (rv); } @@ -428,17 +478,17 @@ el_source(EditLine *el, const char *fname) fp = NULL; if (fname == NULL) { +#ifdef HAVE_ISSETUGID static const char elpath[] = "/.editrc"; +/* XXXMYSQL: Portability fix (for which platforms?) */ #ifdef MAXPATHLEN char path[MAXPATHLEN]; #else char path[4096]; #endif -#ifdef HAVE_ISSETUGID if (issetugid()) return (-1); -#endif if ((ptr = getenv("HOME")) == NULL) return (-1); if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path)) @@ -446,6 +496,14 @@ el_source(EditLine *el, const char *fname) if (strlcat(path, elpath, sizeof(path)) >= sizeof(path)) return (-1); fname = path; +#else + /* + * If issetugid() is missing, always return an error, in order + * to keep from inadvertently opening up the user to a security + * hole. + */ + return (-1); +#endif } if (fp == NULL) fp = fopen(fname, "r"); diff --git a/cmd-line-utils/libedit/el.h b/cmd-line-utils/libedit/el.h index d9379d7c8aaf1df5ba740005da68e3a5ed4c3294..05d88ad88bafb06ebf4eb9e45819ebbba342c293 100644 --- a/cmd-line-utils/libedit/el.h +++ b/cmd-line-utils/libedit/el.h @@ -1,4 +1,4 @@ -/* $NetBSD: el.h,v 1.16 2003/10/18 23:48:42 christos Exp $ */ +/* $NetBSD: el.h,v 1.17 2006/12/15 22:13:33 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -110,6 +110,7 @@ typedef struct el_state_t { struct editline { char *el_prog; /* the program name */ + FILE *el_infile; /* Stdio stuff */ FILE *el_outfile; /* Stdio stuff */ FILE *el_errfile; /* Stdio stuff */ int el_infd; /* Input file descriptor */ @@ -136,7 +137,8 @@ struct editline { protected int el_editmode(EditLine *, int, const char **); -#define el_isprint(x) ((unsigned char) (x) < 0x80 ? isprint(x) : 1) +/* XXXMYSQL: Bug#23097 mysql can't insert korean on mysql prompt. */ +#define el_isprint(x) ((unsigned char) (x) < 0x80 ? isprint(x) : 1) #ifdef DEBUG #define EL_ABORT(a) do { \ diff --git a/cmd-line-utils/libedit/el_term.h b/cmd-line-utils/libedit/el_term.h index 00ca48e38e23dea4cf394a723d191fee1c43ff01..0e7ddd555f4d2db25a873447bc812a61348ddf2e 100644 --- a/cmd-line-utils/libedit/el_term.h +++ b/cmd-line-utils/libedit/el_term.h @@ -1,4 +1,4 @@ -/* $NetBSD: term.h,v 1.15 2003/09/14 21:48:55 christos Exp $ */ +/* $NetBSD: term.h,v 1.19 2008/09/10 15:45:37 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -81,25 +81,6 @@ typedef struct { #define A_K_EN 5 #define A_K_NKEYS 6 -#ifdef _SUNOS -extern int tgetent(char *, const char *); -extern int tgetflag(char *); -extern int tgetnum(char *); -extern int tputs(const char *, int, int (*)(int)); -extern char* tgoto(const char*, int, int); -extern char* tgetstr(char*, char**); -#endif - - -#if !HAVE_DECL_TGOTO -/* - 'tgoto' is not declared in the system header files, this causes - problems on 64-bit systems. The function returns a 64 bit pointer - but caller see it as "int" and it's thus truncated to 32-bit -*/ -extern char* tgoto(const char*, int, int); -#endif - protected void term_move_to_line(EditLine *, int); protected void term_move_to_char(EditLine *, int); protected void term_clear_EOL(EditLine *, int); @@ -119,10 +100,12 @@ protected void term_end(EditLine *); protected void term_get(EditLine *, const char **); protected int term_set(EditLine *, const char *); protected int term_settc(EditLine *, int, const char **); +protected int term_gettc(EditLine *, int, char **); protected int term_telltc(EditLine *, int, const char **); protected int term_echotc(EditLine *, int, const char **); -protected int term__putc(int); -protected void term__flush(void); +protected void term_writec(EditLine *, int); +protected int term__putc(EditLine *, int); +protected void term__flush(EditLine *); /* * Easy access macros @@ -134,6 +117,7 @@ protected void term__flush(void); #define EL_CAN_CEOL (EL_FLAGS & TERM_CAN_CEOL) #define EL_CAN_TAB (EL_FLAGS & TERM_CAN_TAB) #define EL_CAN_ME (EL_FLAGS & TERM_CAN_ME) +#define EL_CAN_UP (EL_FLAGS & TERM_CAN_UP) #define EL_HAS_META (EL_FLAGS & TERM_HAS_META) #define EL_HAS_AUTO_MARGINS (EL_FLAGS & TERM_HAS_AUTO_MARGINS) #define EL_HAS_MAGIC_MARGINS (EL_FLAGS & TERM_HAS_MAGIC_MARGINS) diff --git a/cmd-line-utils/libedit/emacs.c b/cmd-line-utils/libedit/emacs.c index 79f2bf0c8180f517dc31d7ba92dd42ec357a5580..135bd75f566d1c3afa06e3b67c633095ba6b8260 100644 --- a/cmd-line-utils/libedit/emacs.c +++ b/cmd-line-utils/libedit/emacs.c @@ -1,4 +1,4 @@ -/* $NetBSD: emacs.c,v 1.19 2004/10/28 21:14:52 dsl Exp $ */ +/* $NetBSD: emacs.c,v 1.21 2006/03/06 21:11:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * emacs.c: Emacs functions @@ -45,15 +51,14 @@ */ protected el_action_t /*ARGSUSED*/ -em_delete_or_list(EditLine *el, int c __attribute__((__unused__))) +em_delete_or_list(EditLine *el, int c) { if (el->el_line.cursor == el->el_line.lastchar) { /* if I'm at the end */ if (el->el_line.cursor == el->el_line.buffer) { /* and the beginning */ - term_overwrite(el, STReof, 4); /* then do a EOF */ - term__flush(); + term_writec(el, c); /* then do an EOF */ return (CC_EOF); } else { /* diff --git a/cmd-line-utils/libedit/fgetln.h b/cmd-line-utils/libedit/fgetln.h deleted file mode 100644 index b2ddce01da98798d30b527c3ac9a491d37c77df0..0000000000000000000000000000000000000000 --- a/cmd-line-utils/libedit/fgetln.h +++ /dev/null @@ -1,3 +0,0 @@ -#include <stdio.h> - -char *fgetln(FILE *stream, size_t *len); diff --git a/cmd-line-utils/libedit/filecomplete.c b/cmd-line-utils/libedit/filecomplete.c new file mode 100644 index 0000000000000000000000000000000000000000..4c63f57bc450da34e6234fb153cfc44a7d006e95 --- /dev/null +++ b/cmd-line-utils/libedit/filecomplete.c @@ -0,0 +1,558 @@ +/* $NetBSD: filecomplete.c,v 1.13 2009/01/26 17:32:41 apb Exp $ */ + +/*- + * Copyright (c) 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jaromir Dolecek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* AIX requires this to be the first thing in the file. */ +#if defined (_AIX) && !defined (__GNUC__) + #pragma alloca +#endif + +#include "config.h" + +/* XXXMYSQL */ +#ifdef __GNUC__ +# undef alloca +# define alloca(n) __builtin_alloca (n) +#else +# ifdef HAVE_ALLOCA_H +# include <alloca.h> +# else +# ifndef _AIX +extern char *alloca (); +# endif +# endif +#endif + +#if !defined(lint) && !defined(SCCSID) +#endif /* not lint && not SCCSID */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <stdio.h> +#include <dirent.h> +#include <string.h> +#include <pwd.h> +#include <ctype.h> +#include <stdlib.h> +#include <unistd.h> +#include <limits.h> +#include <errno.h> +#include <fcntl.h> +#ifdef HAVE_VIS_H +#include <vis.h> +#else +#include "np/vis.h" +#endif +#ifdef HAVE_ALLOCA_H +#include <alloca.h> +#endif +#include "el.h" +#include "fcns.h" /* for EL_NUM_FCNS */ +#include "histedit.h" +#include "filecomplete.h" + +static char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@', '$', + '>', '<', '=', ';', '|', '&', '{', '(', '\0' }; + + +/********************************/ +/* completion functions */ + +/* + * does tilde expansion of strings of type ``~user/foo'' + * if ``user'' isn't valid user name or ``txt'' doesn't start + * w/ '~', returns pointer to strdup()ed copy of ``txt'' + * + * it's callers's responsibility to free() returned string + */ +char * +fn_tilde_expand(const char *txt) +{ + struct passwd pwres, *pass; + char *temp; + size_t len = 0; + char pwbuf[1024]; + + if (txt[0] != '~') + return (strdup(txt)); + + temp = strchr(txt + 1, '/'); + if (temp == NULL) { + temp = strdup(txt + 1); + if (temp == NULL) + return NULL; + } else { + len = temp - txt + 1; /* text until string after slash */ + temp = malloc(len); + if (temp == NULL) + return NULL; + (void)strncpy(temp, txt + 1, len - 2); + temp[len - 2] = '\0'; + } + /* XXXMYSQL: use non-_r functions for now */ + if (temp[0] == 0) { + pass = getpwuid(getuid()); + } else { + pass = getpwnam(temp); + } + free(temp); /* value no more needed */ + if (pass == NULL) + return (strdup(txt)); + + /* update pointer txt to point at string immedially following */ + /* first slash */ + txt += len; + + temp = malloc(strlen(pass->pw_dir) + 1 + strlen(txt) + 1); + if (temp == NULL) + return NULL; + (void)sprintf(temp, "%s/%s", pass->pw_dir, txt); + + return (temp); +} + + +/* + * return first found file name starting by the ``text'' or NULL if no + * such file can be found + * value of ``state'' is ignored + * + * it's caller's responsibility to free returned string + */ +char * +fn_filename_completion_function(const char *text, int state) +{ + static DIR *dir = NULL; + static char *filename = NULL, *dirname = NULL, *dirpath = NULL; + static size_t filename_len = 0; + struct dirent *entry; + char *temp; + size_t len; + + if (state == 0 || dir == NULL) { + temp = strrchr(text, '/'); + if (temp) { + char *nptr; + temp++; + nptr = realloc(filename, strlen(temp) + 1); + if (nptr == NULL) { + free(filename); + return NULL; + } + filename = nptr; + (void)strcpy(filename, temp); + len = temp - text; /* including last slash */ + nptr = realloc(dirname, len + 1); + if (nptr == NULL) { + free(filename); + return NULL; + } + dirname = nptr; + (void)strncpy(dirname, text, len); + dirname[len] = '\0'; + } else { + if (*text == 0) + filename = NULL; + else { + filename = strdup(text); + if (filename == NULL) + return NULL; + } + dirname = NULL; + } + + if (dir != NULL) { + (void)closedir(dir); + dir = NULL; + } + + /* support for ``~user'' syntax */ + free(dirpath); + + if (dirname == NULL && (dirname = strdup("./")) == NULL) + return NULL; + + if (*dirname == '~') + dirpath = fn_tilde_expand(dirname); + else + dirpath = strdup(dirname); + + if (dirpath == NULL) + return NULL; + + dir = opendir(dirpath); + if (!dir) + return (NULL); /* cannot open the directory */ + + /* will be used in cycle */ + filename_len = filename ? strlen(filename) : 0; + } + + /* find the match */ + while ((entry = readdir(dir)) != NULL) { + /* skip . and .. */ + if (entry->d_name[0] == '.' && (!entry->d_name[1] + || (entry->d_name[1] == '.' && !entry->d_name[2]))) + continue; + if (filename_len == 0) + break; + /* otherwise, get first entry where first */ + /* filename_len characters are equal */ + if (entry->d_name[0] == filename[0] +#if HAVE_STRUCT_DIRENT_D_NAMLEN + && entry->d_namlen >= filename_len +#else + && strlen(entry->d_name) >= filename_len +#endif + && strncmp(entry->d_name, filename, + filename_len) == 0) + break; + } + + if (entry) { /* match found */ + +#if HAVE_STRUCT_DIRENT_D_NAMLEN + len = entry->d_namlen; +#else + len = strlen(entry->d_name); +#endif + + temp = malloc(strlen(dirname) + len + 1); + if (temp == NULL) + return NULL; + (void)sprintf(temp, "%s%s", dirname, entry->d_name); + } else { + (void)closedir(dir); + dir = NULL; + temp = NULL; + } + + return (temp); +} + + +static const char * +append_char_function(const char *name) +{ + struct stat stbuf; + char *expname = *name == '~' ? fn_tilde_expand(name) : NULL; + const char *rs = " "; + + if (stat(expname ? expname : name, &stbuf) == -1) + goto out; + if (S_ISDIR(stbuf.st_mode)) + rs = "/"; +out: + if (expname) + free(expname); + return rs; +} +/* + * returns list of completions for text given + * non-static for readline. + */ +char ** completion_matches(const char *, char *(*)(const char *, int)); +char ** +completion_matches(const char *text, char *(*genfunc)(const char *, int)) +{ + char **match_list = NULL, *retstr, *prevstr; + size_t match_list_len, max_equal, which, i; + size_t matches; + + matches = 0; + match_list_len = 1; + while ((retstr = (*genfunc) (text, (int)matches)) != NULL) { + /* allow for list terminator here */ + if (matches + 3 >= match_list_len) { + char **nmatch_list; + while (matches + 3 >= match_list_len) + match_list_len <<= 1; + nmatch_list = realloc(match_list, + match_list_len * sizeof(char *)); + if (nmatch_list == NULL) { + free(match_list); + return NULL; + } + match_list = nmatch_list; + + } + match_list[++matches] = retstr; + } + + if (!match_list) + return NULL; /* nothing found */ + + /* find least denominator and insert it to match_list[0] */ + which = 2; + prevstr = match_list[1]; + max_equal = strlen(prevstr); + for (; which <= matches; which++) { + for (i = 0; i < max_equal && + prevstr[i] == match_list[which][i]; i++) + continue; + max_equal = i; + } + + retstr = malloc(max_equal + 1); + if (retstr == NULL) { + free(match_list); + return NULL; + } + (void)strncpy(retstr, match_list[1], max_equal); + retstr[max_equal] = '\0'; + match_list[0] = retstr; + + /* add NULL as last pointer to the array */ + match_list[matches + 1] = (char *) NULL; + + return (match_list); +} + +/* + * Sort function for qsort(). Just wrapper around strcasecmp(). + */ +static int +_fn_qsort_string_compare(const void *i1, const void *i2) +{ + const char *s1 = ((const char * const *)i1)[0]; + const char *s2 = ((const char * const *)i2)[0]; + + return strcasecmp(s1, s2); +} + +/* + * Display list of strings in columnar format on readline's output stream. + * 'matches' is list of strings, 'len' is number of strings in 'matches', + * 'max' is maximum length of string in 'matches'. + */ +void +fn_display_match_list (EditLine *el, char **matches, int len, int max) +{ + int i, idx, limit, count; + int screenwidth = el->el_term.t_size.h; + + /* + * Find out how many entries can be put on one line, count + * with two spaces between strings. + */ + limit = screenwidth / (max + 2); + if (limit == 0) + limit = 1; + + /* how many lines of output */ + count = len / limit; + if (count * limit < len) + count++; + + /* Sort the items if they are not already sorted. */ + qsort(&matches[1], (size_t)(len - 1), sizeof(char *), + _fn_qsort_string_compare); + + idx = 1; + for(; count > 0; count--) { + for(i = 0; i < limit && matches[idx]; i++, idx++) + (void)fprintf(el->el_outfile, "%-*s ", max, + matches[idx]); + (void)fprintf(el->el_outfile, "\n"); + } +} + +/* + * Complete the word at or before point, + * 'what_to_do' says what to do with the completion. + * \t means do standard completion. + * `?' means list the possible completions. + * `*' means insert all of the possible completions. + * `!' means to do standard completion, and list all possible completions if + * there is more than one. + * + * Note: '*' support is not implemented + * '!' could never be invoked + */ +int +fn_complete(EditLine *el, + char *(*complet_func)(const char *, int), + char **(*attempted_completion_function)(const char *, int, int), + const char *word_break, const char *special_prefixes, + const char *(*app_func)(const char *), int query_items, + int *completion_type, int *over, int *point, int *end) +{ + const LineInfo *li; + char *temp, **matches; + const char *ctemp; + size_t len; + int what_to_do = '\t'; + int retval = CC_NORM; + + if (el->el_state.lastcmd == el->el_state.thiscmd) + what_to_do = '?'; + + /* readline's rl_complete() has to be told what we did... */ + if (completion_type != NULL) + *completion_type = what_to_do; + + if (!complet_func) + complet_func = fn_filename_completion_function; + if (!app_func) + app_func = append_char_function; + + /* We now look backwards for the start of a filename/variable word */ + li = el_line(el); + ctemp = (const char *) li->cursor; + while (ctemp > li->buffer + && !strchr(word_break, ctemp[-1]) + && (!special_prefixes || !strchr(special_prefixes, ctemp[-1]) ) ) + ctemp--; + + len = li->cursor - ctemp; +#if defined(__SSP__) || defined(__SSP_ALL__) + temp = malloc(len + 1); +#else + temp = alloca(len + 1); +#endif + (void)strncpy(temp, ctemp, len); + temp[len] = '\0'; + + /* these can be used by function called in completion_matches() */ + /* or (*attempted_completion_function)() */ + if (point != 0) + *point = li->cursor - li->buffer; + if (end != NULL) + *end = li->lastchar - li->buffer; + + if (attempted_completion_function) { + int cur_off = li->cursor - li->buffer; + matches = (*attempted_completion_function) (temp, + (int)(cur_off - len), cur_off); + } else + matches = 0; + if (!attempted_completion_function || + (over != NULL && !*over && !matches)) + matches = completion_matches(temp, complet_func); + + if (over != NULL) + *over = 0; + + if (matches) { + int i; + int matches_num, maxlen, match_len, match_display=1; + + retval = CC_REFRESH; + /* + * Only replace the completed string with common part of + * possible matches if there is possible completion. + */ + if (matches[0][0] != '\0') { + el_deletestr(el, (int) len); + el_insertstr(el, matches[0]); + } + + if (what_to_do == '?') + goto display_matches; + + if (matches[2] == NULL && strcmp(matches[0], matches[1]) == 0) { + /* + * We found exact match. Add a space after + * it, unless we do filename completion and the + * object is a directory. + */ + el_insertstr(el, (*app_func)(matches[0])); + } else if (what_to_do == '!') { + display_matches: + /* + * More than one match and requested to list possible + * matches. + */ + + for(i=1, maxlen=0; matches[i]; i++) { + match_len = strlen(matches[i]); + if (match_len > maxlen) + maxlen = match_len; + } + matches_num = i - 1; + + /* newline to get on next line from command line */ + (void)fprintf(el->el_outfile, "\n"); + + /* + * If there are too many items, ask user for display + * confirmation. + */ + if (matches_num > query_items) { + (void)fprintf(el->el_outfile, + "Display all %d possibilities? (y or n) ", + matches_num); + (void)fflush(el->el_outfile); + if (getc(stdin) != 'y') + match_display = 0; + (void)fprintf(el->el_outfile, "\n"); + } + + if (match_display) + fn_display_match_list(el, matches, matches_num, + maxlen); + retval = CC_REDISPLAY; + } else if (matches[0][0]) { + /* + * There was some common match, but the name was + * not complete enough. Next tab will print possible + * completions. + */ + el_beep(el); + } else { + /* lcd is not a valid object - further specification */ + /* is needed */ + el_beep(el); + retval = CC_NORM; + } + + /* free elements of array and the array itself */ + for (i = 0; matches[i]; i++) + free(matches[i]); + free(matches); + matches = NULL; + } +#if defined(__SSP__) || defined(__SSP_ALL__) + free(temp); +#endif + return retval; +} + +/* + * el-compatible wrapper around rl_complete; needed for key binding + */ +/* ARGSUSED */ +unsigned char +_el_fn_complete(EditLine *el, int ch __attribute__((__unused__))) +{ + return (unsigned char)fn_complete(el, NULL, NULL, + break_chars, NULL, NULL, 100, + NULL, NULL, NULL, NULL); +} diff --git a/cmd-line-utils/libedit/fgetln.c b/cmd-line-utils/libedit/filecomplete.h similarity index 50% rename from cmd-line-utils/libedit/fgetln.c rename to cmd-line-utils/libedit/filecomplete.h index 5b95b2f6584cd7d13e034f122661a7a9e3782b06..12e0c6f14b037db1f8c44ef1609c268c7881738f 100644 --- a/cmd-line-utils/libedit/fgetln.c +++ b/cmd-line-utils/libedit/filecomplete.h @@ -1,11 +1,11 @@ -/* $NetBSD: fgetln.c,v 1.2 2003/12/10 01:30:27 lukem Exp $ */ +/* $NetBSD: filecomplete.h,v 1.6 2008/04/29 06:53:01 martin Exp $ */ /*- - * Copyright (c) 1998 The NetBSD Foundation, Inc. + * Copyright (c) 1997 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Christos Zoulas. + * by Jaromir Dolecek. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,13 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -35,54 +28,17 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#ifndef _FILECOMPLETE_H_ +#define _FILECOMPLETE_H_ -#include <config.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <errno.h> -#include <string.h> +int fn_complete(EditLine *, + char *(*)(const char *, int), + char **(*)(const char *, int, int), + const char *, const char *, const char *(*)(const char *), int, + int *, int *, int *, int *); +void fn_display_match_list(EditLine *, char **, int, int); +char *fn_tilde_expand(const char *); +char *fn_filename_completion_function(const char *, int); -char * -fgetln(FILE *fp, size_t *len) -{ - static char *buf = NULL; - static size_t bufsiz = 0; - char *ptr; - - - if (buf == NULL) { - bufsiz = BUFSIZ; - if ((buf = malloc(bufsiz)) == NULL) - return NULL; - } - - if (fgets(buf, bufsiz, fp) == NULL) - return NULL; - *len = 0; - - while ((ptr = strchr(&buf[*len], '\n')) == NULL) { - size_t nbufsiz = bufsiz + BUFSIZ; - char *nbuf = realloc(buf, nbufsiz); - - if (nbuf == NULL) { - int oerrno = errno; - free(buf); - errno = oerrno; - buf = NULL; - return NULL; - } else - buf = nbuf; - - *len = bufsiz; - if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL) - return buf; - - bufsiz = nbufsiz; - } - - *len = (ptr - buf) + 1; - return buf; -} - +#endif diff --git a/cmd-line-utils/libedit/hist.c b/cmd-line-utils/libedit/hist.c index e8f5c0f39bad0ac00929cb09b94a3b010bd9cc59..c0b23ee664170278e04f3a4b2d13134334406d69 100644 --- a/cmd-line-utils/libedit/hist.c +++ b/cmd-line-utils/libedit/hist.c @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * hist.c: History access functions diff --git a/cmd-line-utils/libedit/histedit.h b/cmd-line-utils/libedit/histedit.h index c58eb62dcfab3df062394bd024c639fa2a7d1583..37823141c064602911bf2f80c483e53a15b6de21 100644 --- a/cmd-line-utils/libedit/histedit.h +++ b/cmd-line-utils/libedit/histedit.h @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.h,v 1.25 2003/12/05 13:37:48 lukem Exp $ */ +/* $NetBSD: histedit.h,v 1.35 2009/02/05 19:15:44 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,11 +41,15 @@ #define _HISTEDIT_H_ #define LIBEDIT_MAJOR 2 -#define LIBEDIT_MINOR 9 +#define LIBEDIT_MINOR 11 #include <sys/types.h> #include <stdio.h> +#ifdef __cplusplus +extern "C" { +#endif + /* * ==== Editing ==== */ @@ -88,7 +92,7 @@ void el_reset(EditLine *); */ const char *el_gets(EditLine *, int *); int el_getc(EditLine *, char *); -void el_push(EditLine *, char *); +void el_push(EditLine *, const char *); /* * Beep! @@ -105,7 +109,8 @@ int el_parse(EditLine *, int, const char **); * Low level editline access functions */ int el_set(EditLine *, int, ...); -int el_get(EditLine *, int, void *); +int el_get(EditLine *, int, ...); +unsigned char _el_fn_complete(EditLine *, int); /* * el_set/el_get parameters @@ -128,8 +133,12 @@ int el_get(EditLine *, int, void *); #define EL_CLIENTDATA 14 /* , void *); */ #define EL_UNBUFFERED 15 /* , int); */ #define EL_PREP_TERM 16 /* , int); */ +#define EL_GETTC 17 /* , const char *, ..., NULL); */ +#define EL_GETFP 18 /* , int, FILE **); */ +#define EL_SETFP 19 /* , int, FILE *); */ +#define EL_REFRESH 20 /* , void); */ -#define EL_BUILTIN_GETCFN (NULL) +#define EL_BUILTIN_GETCFN (NULL) /* * Source named file or $PWD/.editrc or $HOME/.editrc @@ -192,6 +201,7 @@ int history(History *, HistEvent *, int, ...); #define H_CLEAR 19 /* , void); */ #define H_SETUNIQUE 20 /* , int); */ #define H_GETUNIQUE 21 /* , void); */ +#define H_DEL 22 /* , int); */ /* @@ -211,4 +221,8 @@ int tok_line(Tokenizer *, const LineInfo *, int tok_str(Tokenizer *, const char *, int *, const char ***); +#ifdef __cplusplus +} +#endif + #endif /* _HISTEDIT_H_ */ diff --git a/cmd-line-utils/libedit/history.c b/cmd-line-utils/libedit/history.c index c0fa7cc717dd0a79dbd64530681d0a654ba2be95..3080dd231f6269e94f8748ff9481821408d545d0 100644 --- a/cmd-line-utils/libedit/history.c +++ b/cmd-line-utils/libedit/history.c @@ -1,4 +1,4 @@ -/* $NetBSD: history.c,v 1.28 2004/11/27 18:31:45 christos Exp $ */ +/* $NetBSD: history.c,v 1.33 2009/02/06 14:40:32 sketch Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * hist.c: History access functions @@ -40,7 +46,11 @@ #include <string.h> #include <stdlib.h> #include <stdarg.h> +#ifdef HAVE_VIS_H #include <vis.h> +#else +#include "np/vis.h" +#endif #include <sys/stat.h> static const char hist_cookie[] = "_HiStOrY_V2_\n"; @@ -61,6 +71,7 @@ struct history { history_gfun_t h_prev; /* Get the previous element */ history_gfun_t h_curr; /* Get the current element */ history_sfun_t h_set; /* Set the current element */ + history_sfun_t h_del; /* Set the given element */ history_vfun_t h_clear; /* Clear the history list */ history_efun_t h_enter; /* Add an element */ history_efun_t h_add; /* Append to an element */ @@ -75,6 +86,7 @@ struct history { #define HCLEAR(h, ev) (*(h)->h_clear)((h)->h_ref, ev) #define HENTER(h, ev, str) (*(h)->h_enter)((h)->h_ref, ev, str) #define HADD(h, ev, str) (*(h)->h_add)((h)->h_ref, ev, str) +#define HDEL(h, ev, n) (*(h)->h_del)((h)->h_ref, ev, n) #define h_strdup(a) strdup(a) #define h_malloc(a) malloc(a) @@ -122,16 +134,18 @@ typedef struct history_t { #define H_UNIQUE 1 /* Store only unique elements */ } history_t; -private int history_def_first(ptr_t, HistEvent *); -private int history_def_last(ptr_t, HistEvent *); private int history_def_next(ptr_t, HistEvent *); +private int history_def_first(ptr_t, HistEvent *); private int history_def_prev(ptr_t, HistEvent *); +private int history_def_last(ptr_t, HistEvent *); private int history_def_curr(ptr_t, HistEvent *); -private int history_def_set(ptr_t, HistEvent *, const int n); +private int history_def_set(ptr_t, HistEvent *, const int); +private void history_def_clear(ptr_t, HistEvent *); private int history_def_enter(ptr_t, HistEvent *, const char *); private int history_def_add(ptr_t, HistEvent *, const char *); +private int history_def_del(ptr_t, HistEvent *, const int); + private int history_def_init(ptr_t *, HistEvent *, int); -private void history_def_clear(ptr_t, HistEvent *); private int history_def_insert(history_t *, HistEvent *, const char *); private void history_def_delete(history_t *, HistEvent *, hentry_t *); @@ -353,6 +367,24 @@ history_def_add(ptr_t p, HistEvent *ev, const char *str) } +/* history_def_del(): + * Delete element hp of the h list + */ +/* ARGSUSED */ +private int +history_def_del(ptr_t p, HistEvent *ev __attribute__((__unused__)), + const int num) +{ + history_t *h = (history_t *) p; + if (history_def_set(h, ev, num) != 0) + return (-1); + ev->str = strdup(h->cursor->ev.str); + ev->num = h->cursor->ev.num; + history_def_delete(h, ev, h->cursor); + return (0); +} + + /* history_def_delete(): * Delete element hp of the h list */ @@ -364,6 +396,8 @@ history_def_delete(history_t *h, HistEventPrivate *evp = (void *)&hp->ev; if (hp == &h->list) abort(); + if (h->cursor == hp) + h->cursor = hp->prev; hp->prev->next = hp->next; hp->next->prev = hp->prev; h_free((ptr_t) evp->str); @@ -497,6 +531,7 @@ history_init(void) h->h_clear = history_def_clear; h->h_enter = history_def_enter; h->h_add = history_def_add; + h->h_del = history_def_del; return (h); } @@ -512,6 +547,8 @@ history_end(History *h) if (h->h_next == history_def_next) history_def_clear(h->h_ref, &ev); + h_free(h->h_ref); + h_free(h); } @@ -597,7 +634,7 @@ history_set_fun(History *h, History *nh) if (nh->h_first == NULL || nh->h_next == NULL || nh->h_last == NULL || nh->h_prev == NULL || nh->h_curr == NULL || nh->h_set == NULL || nh->h_enter == NULL || nh->h_add == NULL || nh->h_clear == NULL || - nh->h_ref == NULL) { + nh->h_del == NULL || nh->h_ref == NULL) { if (h->h_next != history_def_next) { history_def_init(&h->h_ref, &ev, 0); h->h_first = history_def_first; @@ -609,6 +646,7 @@ history_set_fun(History *h, History *nh) h->h_clear = history_def_clear; h->h_enter = history_def_enter; h->h_add = history_def_add; + h->h_del = history_def_del; } return (-1); } @@ -625,6 +663,7 @@ history_set_fun(History *h, History *nh) h->h_clear = nh->h_clear; h->h_enter = nh->h_enter; h->h_add = nh->h_add; + h->h_del = nh->h_del; return (0); } @@ -676,8 +715,8 @@ history_load(History *h, const char *fname) (void) strunvis(ptr, line); line[sz] = c; if (HENTER(h, &ev, ptr) == -1) { - i = -1; - goto oomem; + i = -1; + goto oomem; } } oomem: @@ -841,6 +880,10 @@ history(History *h, HistEvent *ev, int fun, ...) retval = HADD(h, ev, str); break; + case H_DEL: + retval = HDEL(h, ev, va_arg(va, const int)); + break; + case H_ENTER: str = va_arg(va, const char *); if ((retval = HENTER(h, ev, str)) != -1) @@ -925,6 +968,7 @@ history(History *h, HistEvent *ev, int fun, ...) hf.h_clear = va_arg(va, history_vfun_t); hf.h_enter = va_arg(va, history_efun_t); hf.h_add = va_arg(va, history_efun_t); + hf.h_del = va_arg(va, history_sfun_t); if ((retval = history_set_fun(h, &hf)) == -1) he_seterrev(ev, _HE_PARAM_MISSING); diff --git a/cmd-line-utils/libedit/key.c b/cmd-line-utils/libedit/key.c index 35fcf0651b2d029770b495011089a0469e0908b7..cda028168611931e8282ba0cdf14a4e1ce5fc756 100644 --- a/cmd-line-utils/libedit/key.c +++ b/cmd-line-utils/libedit/key.c @@ -1,4 +1,4 @@ -/* $NetBSD: key.c,v 1.15 2003/10/18 23:48:42 christos Exp $ */ +/* $NetBSD: key.c,v 1.19 2006/03/23 20:22:51 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,14 +32,20 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * key.c: This module contains the procedures for maintaining * the extended-key map. * * An extended-key (key) is a sequence of keystrokes introduced - * with an sequence introducer and consisting of an arbitrary + * with a sequence introducer and consisting of an arbitrary * number of characters. This module maintains a map (the el->el_key.map) * to convert these extended-key sequences into input strs * (XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE). @@ -78,12 +84,12 @@ private int node_trav(EditLine *, key_node_t *, char *, private int node__try(EditLine *, key_node_t *, const char *, key_value_t *, int); private key_node_t *node__get(int); +private void node__free(key_node_t *); private void node__put(EditLine *, key_node_t *); private int node__delete(EditLine *, key_node_t **, const char *); private int node_lookup(EditLine *, const char *, key_node_t *, int); private int node_enum(EditLine *, key_node_t *, int); -private int key__decode_char(char *, int, int); #define KEY_BUFSIZ EL_BUFSIZ @@ -103,7 +109,6 @@ key_init(EditLine *el) return (0); } - /* key_end(): * Free the key maps */ @@ -113,8 +118,7 @@ key_end(EditLine *el) el_free((ptr_t) el->el_key.buf); el->el_key.buf = NULL; - /* XXX: provide a function to clear the keys */ - el->el_key.map = NULL; + node__free(el->el_key.map); } @@ -443,7 +447,7 @@ node__put(EditLine *el, key_node_t *ptr) /* node__get(): - * Returns pointer to an key_node_t for ch. + * Returns pointer to a key_node_t for ch. */ private key_node_t * node__get(int ch) @@ -461,7 +465,15 @@ node__get(int ch) return (ptr); } - +private void +node__free(key_node_t *k) +{ + if (k == NULL) + return; + node__free(k->sibling); + node__free(k->next); + el_free((ptr_t) k); +} /* node_lookup(): * look for the str starting at node ptr. @@ -483,7 +495,7 @@ node_lookup(EditLine *el, const char *str, key_node_t *ptr, int cnt) /* If match put this char into el->el_key.buf. Recurse */ if (ptr->ch == *str) { /* match found */ - ncnt = key__decode_char(el->el_key.buf, cnt, + ncnt = key__decode_char(el->el_key.buf, KEY_BUFSIZ, cnt, (unsigned char) ptr->ch); if (ptr->next != NULL) /* not yet at leaf */ @@ -537,7 +549,8 @@ node_enum(EditLine *el, key_node_t *ptr, int cnt) return (-1); } /* put this char at end of str */ - ncnt = key__decode_char(el->el_key.buf, cnt, (unsigned char) ptr->ch); + ncnt = key__decode_char(el->el_key.buf, KEY_BUFSIZ, cnt, + (unsigned char)ptr->ch); if (ptr->next == NULL) { /* print this key and function */ el->el_key.buf[ncnt + 1] = '"'; @@ -568,9 +581,10 @@ key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype) switch (ntype) { case XK_STR: case XK_EXE: - (void) fprintf(el->el_outfile, fmt, key, - key__decode_str(val->str, unparsbuf, - ntype == XK_STR ? "\"\"" : "[]")); + (void) key__decode_str(val->str, unparsbuf, + sizeof(unparsbuf), + ntype == XK_STR ? "\"\"" : "[]"); + (void) fprintf(el->el_outfile, fmt, key, unparsbuf); break; case XK_CMD: for (fp = el->el_map.help; fp->name; fp++) @@ -595,83 +609,97 @@ key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype) } +#define ADDC(c) \ + if (b < eb) \ + *b++ = c; \ + else \ + b++ /* key__decode_char(): * Put a printable form of char in buf. */ -private int -key__decode_char(char *buf, int cnt, int ch) +protected int +key__decode_char(char *buf, int cnt, int off, int ch) { + char *sb = buf + off; + char *eb = buf + cnt; + char *b = sb; if (ch == 0) { - buf[cnt++] = '^'; - buf[cnt] = '@'; - return (cnt); + ADDC('^'); + ADDC('@'); + return b - sb; } if (iscntrl(ch)) { - buf[cnt++] = '^'; + ADDC('^'); if (ch == '\177') - buf[cnt] = '?'; + ADDC('?'); else - buf[cnt] = ch | 0100; + ADDC(ch | 0100); } else if (ch == '^') { - buf[cnt++] = '\\'; - buf[cnt] = '^'; + ADDC('\\'); + ADDC('^'); } else if (ch == '\\') { - buf[cnt++] = '\\'; - buf[cnt] = '\\'; + ADDC('\\'); + ADDC('\\'); } else if (ch == ' ' || (el_isprint(ch) && !isspace(ch))) { - buf[cnt] = ch; + ADDC(ch); } else { - buf[cnt++] = '\\'; - buf[cnt++] = (((unsigned int) ch >> 6) & 7) + '0'; - buf[cnt++] = (((unsigned int) ch >> 3) & 7) + '0'; - buf[cnt] = (ch & 7) + '0'; + ADDC('\\'); + ADDC((((unsigned int) ch >> 6) & 7) + '0'); + ADDC((((unsigned int) ch >> 3) & 7) + '0'); + ADDC((ch & 7) + '0'); } - return (cnt); + return b - sb; } /* key__decode_str(): * Make a printable version of the ey */ -protected char * -key__decode_str(const char *str, char *buf, const char *sep) +protected int +key__decode_str(const char *str, char *buf, int len, const char *sep) { - char *b; + char *b = buf, *eb = b + len; const char *p; b = buf; - if (sep[0] != '\0') - *b++ = sep[0]; - if (*str == 0) { - *b++ = '^'; - *b++ = '@'; - if (sep[0] != '\0' && sep[1] != '\0') - *b++ = sep[1]; - *b++ = 0; - return (buf); + if (sep[0] != '\0') { + ADDC(sep[0]); + } + if (*str == '\0') { + ADDC('^'); + ADDC('@'); + if (sep[0] != '\0' && sep[1] != '\0') { + ADDC(sep[1]); + } + goto done; } for (p = str; *p != 0; p++) { if (iscntrl((unsigned char) *p)) { - *b++ = '^'; - if (*p == '\177') - *b++ = '?'; - else - *b++ = *p | 0100; + ADDC('^'); + if (*p == '\177') { + ADDC('?'); + } else { + ADDC(*p | 0100); + } } else if (*p == '^' || *p == '\\') { - *b++ = '\\'; - *b++ = *p; + ADDC('\\'); + ADDC(*p); } else if (*p == ' ' || (el_isprint((unsigned char) *p) && !isspace((unsigned char) *p))) { - *b++ = *p; + ADDC(*p); } else { - *b++ = '\\'; - *b++ = (((unsigned int) *p >> 6) & 7) + '0'; - *b++ = (((unsigned int) *p >> 3) & 7) + '0'; - *b++ = (*p & 7) + '0'; + ADDC('\\'); + ADDC((((unsigned int) *p >> 6) & 7) + '0'); + ADDC((((unsigned int) *p >> 3) & 7) + '0'); + ADDC((*p & 7) + '0'); } } - if (sep[0] != '\0' && sep[1] != '\0') - *b++ = sep[1]; - *b++ = 0; - return (buf); /* should check for overflow */ + if (sep[0] != '\0' && sep[1] != '\0') { + ADDC(sep[1]); + } +done: + ADDC('\0'); + if (b - buf >= len) + buf[len - 1] = '\0'; + return b - buf; } diff --git a/cmd-line-utils/libedit/key.h b/cmd-line-utils/libedit/key.h index 39a075c504e1eb8245d9f9a71d2f82846c3db72e..9c6844e6d993bef893599cfc676ec488cebf3335 100644 --- a/cmd-line-utils/libedit/key.h +++ b/cmd-line-utils/libedit/key.h @@ -1,4 +1,4 @@ -/* $NetBSD: key.h,v 1.8 2003/08/07 16:44:32 agc Exp $ */ +/* $NetBSD: key.h,v 1.10 2006/03/23 20:22:51 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -74,6 +74,8 @@ protected int key_delete(EditLine *, const char *); protected void key_print(EditLine *, const char *); protected void key_kprint(EditLine *, const char *, key_value_t *, int); -protected char *key__decode_str(const char *, char *, const char *); +protected int key__decode_str(const char *, char *, int, + const char *); +protected int key__decode_char(char *, int, int, int); #endif /* _h_el_key */ diff --git a/cmd-line-utils/libedit/libedit_term.h b/cmd-line-utils/libedit/libedit_term.h deleted file mode 100644 index 9f03c5495152bca83920f6213ed6c5657e47a501..0000000000000000000000000000000000000000 --- a/cmd-line-utils/libedit/libedit_term.h +++ /dev/null @@ -1,124 +0,0 @@ -/* $NetBSD: term.h,v 1.12 2001/01/04 15:56:32 christos Exp $ */ - -/*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Christos Zoulas of Cornell University. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)term.h 8.1 (Berkeley) 6/4/93 - */ - -/* - * el.term.h: Termcap header - */ -#ifndef _h_el_term -#define _h_el_term - -#include "histedit.h" - -typedef struct { /* Symbolic function key bindings */ - const char *name; /* name of the key */ - int key; /* Index in termcap table */ - key_value_t fun; /* Function bound to it */ - int type; /* Type of function */ -} fkey_t; - -typedef struct { - coord_t t_size; /* # lines and cols */ - int t_flags; -#define TERM_CAN_INSERT 0x001 /* Has insert cap */ -#define TERM_CAN_DELETE 0x002 /* Has delete cap */ -#define TERM_CAN_CEOL 0x004 /* Has CEOL cap */ -#define TERM_CAN_TAB 0x008 /* Can use tabs */ -#define TERM_CAN_ME 0x010 /* Can turn all attrs. */ -#define TERM_CAN_UP 0x020 /* Can move up */ -#define TERM_HAS_META 0x040 /* Has a meta key */ -#define TERM_HAS_AUTO_MARGINS 0x080 /* Has auto margins */ -#define TERM_HAS_MAGIC_MARGINS 0x100 /* Has magic margins */ - char *t_buf; /* Termcap buffer */ - int t_loc; /* location used */ - char **t_str; /* termcap strings */ - int *t_val; /* termcap values */ - char *t_cap; /* Termcap buffer */ - fkey_t *t_fkey; /* Array of keys */ -} el_term_t; - -/* - * fKey indexes - */ -#define A_K_DN 0 -#define A_K_UP 1 -#define A_K_LT 2 -#define A_K_RT 3 -#define A_K_HO 4 -#define A_K_EN 5 -#define A_K_NKEYS 6 - -protected void term_move_to_line(EditLine *, int); -protected void term_move_to_char(EditLine *, int); -protected void term_clear_EOL(EditLine *, int); -protected void term_overwrite(EditLine *, const char *, int); -protected void term_insertwrite(EditLine *, char *, int); -protected void term_deletechars(EditLine *, int); -protected void term_clear_screen(EditLine *); -protected void term_beep(EditLine *); -protected int term_change_size(EditLine *, int, int); -protected int term_get_size(EditLine *, int *, int *); -protected int term_init(EditLine *); -protected void term_bind_arrow(EditLine *); -protected void term_print_arrow(EditLine *, const char *); -protected int term_clear_arrow(EditLine *, const char *); -protected int term_set_arrow(EditLine *, const char *, key_value_t *, int); -protected void term_end(EditLine *); -protected int term_set(EditLine *, const char *); -protected int term_settc(EditLine *, int, const char **); -protected int term_telltc(EditLine *, int, const char **); -protected int term_echotc(EditLine *, int, const char **); -protected int term__putc(int); -protected void term__flush(void); - -/* - * Easy access macros - */ -#define EL_FLAGS (el)->el_term.t_flags - -#define EL_CAN_INSERT (EL_FLAGS & TERM_CAN_INSERT) -#define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE) -#define EL_CAN_CEOL (EL_FLAGS & TERM_CAN_CEOL) -#define EL_CAN_TAB (EL_FLAGS & TERM_CAN_TAB) -#define EL_CAN_ME (EL_FLAGS & TERM_CAN_ME) -#define EL_HAS_META (EL_FLAGS & TERM_HAS_META) -#define EL_HAS_AUTO_MARGINS (EL_FLAGS & TERM_HAS_AUTO_MARGINS) -#define EL_HAS_MAGIC_MARGINS (EL_FLAGS & TERM_HAS_MAGIC_MARGINS) - -#endif /* _h_el_term */ diff --git a/cmd-line-utils/libedit/makelist.sh b/cmd-line-utils/libedit/makelist.sh index f15b3d1eb9feaac3454d9f517e442b084580998c..fdd3f934e150b0b61ce216b32ed176368f339d05 100644 --- a/cmd-line-utils/libedit/makelist.sh +++ b/cmd-line-utils/libedit/makelist.sh @@ -1,5 +1,5 @@ #!/bin/sh - -# $NetBSD: makelist,v 1.8 2003/03/10 21:21:10 christos Exp $ +# $NetBSD: makelist,v 1.11 2005/10/22 16:45:03 christos Exp $ # # Copyright (c) 1992, 1993 # The Regents of the University of California. All rights reserved. @@ -15,11 +15,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # @@ -68,6 +64,7 @@ case $FLAG in /\(\):/ { pr = substr($2, 1, 2); if (pr == "vi" || pr == "em" || pr == "ed") { + # XXXMYSQL: support CRLF name = substr($2, 1, index($2,"(") - 1); # # XXX: need a space between name and prototype so that -fc and -fh @@ -87,7 +84,7 @@ case $FLAG in cat $FILES | $AWK ' BEGIN { printf("/* Automatically generated file, do not edit */\n"); - printf("#include \"config.h\"\n#include \"el.h\"\n"); + printf("#include \"sys.h\"\n#include \"el.h\"\n"); printf("private const struct el_bindings_t el_func_help[] = {\n"); low = "abcdefghijklmnopqrstuvwxyz_"; high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; @@ -97,6 +94,7 @@ case $FLAG in /\(\):/ { pr = substr($2, 1, 2); if (pr == "vi" || pr == "em" || pr == "ed") { + # XXXMYSQL: support CRLF name = substr($2, 1, index($2,"(") - 1); uname = ""; fname = ""; @@ -117,13 +115,13 @@ case $FLAG in printf(" \""); for (i = 2; i < NF; i++) printf("%s ", $i); - sub("\r", "", $i); + # XXXMYSQL: support CRLF + sub("\r", "", $i); printf("%s\" },\n", $i); ok = 0; } } END { - printf(" { NULL, 0, NULL }\n"); printf("};\n"); printf("\nprotected const el_bindings_t* help__get()"); printf("{ return el_func_help; }\n"); @@ -144,6 +142,7 @@ case $FLAG in # generate fcns.h from various .h files # +# XXXMYSQL: use portable tr syntax -fh) cat $FILES | $AWK '/el_action_t/ { print $3 }' | \ sort | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | $AWK ' @@ -170,7 +169,7 @@ case $FLAG in cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK ' BEGIN { printf("/* Automatically generated file, do not edit */\n"); - printf("#include \"config.h\"\n#include \"el.h\"\n"); + printf("#include \"sys.h\"\n#include \"el.h\"\n"); printf("private const el_func_t el_func[] = {"); maxlen = 80; needn = 1; @@ -220,6 +219,7 @@ case $FLAG in /\(\):/ { pr = substr($2, 1, 2); if (pr == "vi" || pr == "em" || pr == "ed") { + # XXXMYSQL: support CRLF name = substr($2, 1, index($2, "(") - 1); fname = ""; for (i = 1; i <= length(name); i++) { diff --git a/cmd-line-utils/libedit/map.c b/cmd-line-utils/libedit/map.c index 6be9279b5e5f7c59d95d7e2a7d45c65dbd98c470..693b56c82baaf5b0544fd8ecd2b9e8054d6b84c6 100644 --- a/cmd-line-utils/libedit/map.c +++ b/cmd-line-utils/libedit/map.c @@ -1,4 +1,4 @@ -/* $NetBSD: map.c,v 1.20 2004/08/13 12:10:39 mycroft Exp $ */ +/* $NetBSD: map.c,v 1.24 2006/04/09 01:36:51 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * map.c: Editor function definitions @@ -1118,11 +1124,12 @@ private void map_print_key(EditLine *el, el_action_t *map, const char *in) { char outbuf[EL_BUFSIZ]; - el_bindings_t *bp; + el_bindings_t *bp, *ep; if (in[0] == '\0' || in[1] == '\0') { - (void) key__decode_str(in, outbuf, ""); - for (bp = el->el_map.help; bp->name != NULL; bp++) + (void) key__decode_str(in, outbuf, sizeof(outbuf), ""); + ep = &el->el_map.help[el->el_map.nfunc]; + for (bp = el->el_map.help; bp < ep; bp++) if (bp->func == map[(unsigned char) *in]) { (void) fprintf(el->el_outfile, "%s\t->\t%s\n", outbuf, bp->name); @@ -1139,7 +1146,7 @@ map_print_key(EditLine *el, el_action_t *map, const char *in) private void map_print_some_keys(EditLine *el, el_action_t *map, int first, int last) { - el_bindings_t *bp; + el_bindings_t *bp, *ep; char firstbuf[2], lastbuf[2]; char unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ]; @@ -1148,39 +1155,47 @@ map_print_some_keys(EditLine *el, el_action_t *map, int first, int last) lastbuf[0] = last; lastbuf[1] = 0; if (map[first] == ED_UNASSIGNED) { - if (first == last) + if (first == last) { + (void) key__decode_str(firstbuf, unparsbuf, + sizeof(unparsbuf), STRQQ); (void) fprintf(el->el_outfile, - "%-15s-> is undefined\n", - key__decode_str(firstbuf, unparsbuf, STRQQ)); + "%-15s-> is undefined\n", unparsbuf); + } return; } - for (bp = el->el_map.help; bp->name != NULL; bp++) { + ep = &el->el_map.help[el->el_map.nfunc]; + for (bp = el->el_map.help; bp < ep; bp++) { if (bp->func == map[first]) { if (first == last) { + (void) key__decode_str(firstbuf, unparsbuf, + sizeof(unparsbuf), STRQQ); (void) fprintf(el->el_outfile, "%-15s-> %s\n", - key__decode_str(firstbuf, unparsbuf, STRQQ), - bp->name); + unparsbuf, bp->name); } else { + (void) key__decode_str(firstbuf, unparsbuf, + sizeof(unparsbuf), STRQQ); + (void) key__decode_str(lastbuf, extrabuf, + sizeof(extrabuf), STRQQ); (void) fprintf(el->el_outfile, "%-4s to %-7s-> %s\n", - key__decode_str(firstbuf, unparsbuf, STRQQ), - key__decode_str(lastbuf, extrabuf, STRQQ), - bp->name); + unparsbuf, extrabuf, bp->name); } return; } } #ifdef MAP_DEBUG if (map == el->el_map.key) { + (void) key__decode_str(firstbuf, unparsbuf, + sizeof(unparsbuf), STRQQ); (void) fprintf(el->el_outfile, - "BUG!!! %s isn't bound to anything.\n", - key__decode_str(firstbuf, unparsbuf, STRQQ)); + "BUG!!! %s isn't bound to anything.\n", unparsbuf); (void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n", first, el->el_map.key[first]); } else { + (void) key__decode_str(firstbuf, unparsbuf, + sizeof(unparsbuf), STRQQ); (void) fprintf(el->el_outfile, - "BUG!!! %s isn't bound to anything.\n", - key__decode_str(firstbuf, unparsbuf, STRQQ)); + "BUG!!! %s isn't bound to anything.\n", unparsbuf); (void) fprintf(el->el_outfile, "el->el_map.alt[%d] == %d\n", first, el->el_map.alt[first]); } @@ -1237,7 +1252,7 @@ map_bind(EditLine *el, int argc, const char **argv) char outbuf[EL_BUFSIZ]; const char *in = NULL; char *out = NULL; - el_bindings_t *bp; + el_bindings_t *bp, *ep; int cmd; int key; @@ -1279,8 +1294,8 @@ map_bind(EditLine *el, int argc, const char **argv) return (0); case 'l': - for (bp = el->el_map.help; bp->name != NULL; - bp++) + ep = &el->el_map.help[el->el_map.nfunc]; + for (bp = el->el_map.help; bp < ep; bp++) (void) fprintf(el->el_outfile, "%s\n\t%s\n", bp->name, bp->description); @@ -1367,7 +1382,7 @@ map_bind(EditLine *el, int argc, const char **argv) break; default: - EL_ABORT((el->el_errfile, "Bad XK_ type\n", ntype)); + EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype)); break; } return (0); @@ -1381,7 +1396,7 @@ protected int map_addfunc(EditLine *el, const char *name, const char *help, el_func_t func) { void *p; - int nf = el->el_map.nfunc + 2; + int nf = el->el_map.nfunc + 1; if (name == NULL || help == NULL || func == NULL) return (-1); @@ -1400,7 +1415,6 @@ map_addfunc(EditLine *el, const char *name, const char *help, el_func_t func) el->el_map.help[nf].name = name; el->el_map.help[nf].func = nf; el->el_map.help[nf].description = help; - el->el_map.help[++nf].name = NULL; el->el_map.nfunc++; return (0); diff --git a/cmd-line-utils/libedit/np/fgetln.c b/cmd-line-utils/libedit/np/fgetln.c index 93da9914dc8ff2cd9880a4b0a14affb625a64b2c..898abc758dc2f15662b08da82d243436ece5c05f 100644 --- a/cmd-line-utils/libedit/np/fgetln.c +++ b/cmd-line-utils/libedit/np/fgetln.c @@ -1,4 +1,4 @@ -/* $NetBSD: fgetln.c,v 1.1.1.1 1999/04/12 07:43:21 crooksa Exp $ */ +/* $NetBSD: fgetln.c,v 1.9 2008/04/29 06:53:03 martin Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -15,13 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -36,17 +29,24 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#ifdef HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#else #include "config.h" -#include <stdio.h> +#endif + +#if !HAVE_FGETLN #include <stdlib.h> +#ifndef HAVE_NBTOOL_CONFIG_H +/* These headers are required, but included from nbtool_config.h */ +#include <stdio.h> #include <unistd.h> #include <errno.h> #include <string.h> +#endif char * -fgetln(fp, len) - FILE *fp; - size_t *len; +fgetln(FILE *fp, size_t *len) { static char *buf = NULL; static size_t bufsiz = 0; @@ -61,8 +61,8 @@ fgetln(fp, len) if (fgets(buf, bufsiz, fp) == NULL) return NULL; - *len = 0; + *len = 0; while ((ptr = strchr(&buf[*len], '\n')) == NULL) { size_t nbufsiz = bufsiz + BUFSIZ; char *nbuf = realloc(buf, nbufsiz); @@ -76,13 +76,33 @@ fgetln(fp, len) } else buf = nbuf; - *len = bufsiz; - if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL) + if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL) { + buf[bufsiz] = '\0'; + *len = strlen(buf); return buf; + } + *len = bufsiz; bufsiz = nbufsiz; } *len = (ptr - buf) + 1; return buf; } + +#endif + +#ifdef TEST +int +main(int argc, char *argv[]) +{ + char *p; + size_t len; + + while ((p = fgetln(stdin, &len)) != NULL) { + (void)printf("%zu %s", len, p); + free(p); + } + return 0; +} +#endif diff --git a/cmd-line-utils/libedit/np/strlcat.c b/cmd-line-utils/libedit/np/strlcat.c index 6c9f1e92d797422608f07d8c07f33843904789a8..4e2897d8f356199750c359dbab2714d7e80c4580 100644 --- a/cmd-line-utils/libedit/np/strlcat.c +++ b/cmd-line-utils/libedit/np/strlcat.c @@ -1,59 +1,68 @@ +/* $NetBSD: strlcat.c,v 1.3 2007/06/04 18:19:27 christos Exp $ */ +/* $OpenBSD: strlcat.c,v 1.10 2003/04/12 21:56:39 millert Exp $ */ + /* * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> - * All rights reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE + * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#if !defined(_KERNEL) && !defined(_STANDALONE) +#if HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#else #include "config.h" +#endif + #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $"; #endif /* LIBC_SCCS and not lint */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD: src/lib/libc/string/strlcat.c,v 1.2.4.2 2001/07/09 23:30:06 obrien Exp $"; -#endif +#ifdef _LIBC +#include "namespace.h" +#endif #include <sys/types.h> +#include <assert.h> #include <string.h> +#ifdef _LIBC +# ifdef __weak_alias +__weak_alias(strlcat, _strlcat) +# endif +#endif + +#else +#include <lib/libkern/libkern.h> +#endif /* !_KERNEL && !_STANDALONE */ + +#if !HAVE_STRLCAT /* * Appends src to string dst of size siz (unlike strncat, siz is the * full size of dst, not space left). At most siz-1 characters * will be copied. Always NUL terminates (unless siz <= strlen(dst)). - * Returns strlen(initial dst) + strlen(src); if retval >= siz, - * truncation occurred. + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. */ -size_t strlcat(dst, src, siz) - char *dst; - const char *src; - size_t siz; +size_t +strlcat(char *dst, const char *src, size_t siz) { - register char *d = dst; - register const char *s = src; - register size_t n = siz; + char *d = dst; + const char *s = src; + size_t n = siz; size_t dlen; + _DIAGASSERT(dst != NULL); + _DIAGASSERT(src != NULL); + /* Find the end of dst and adjust bytes left but don't go past end */ while (n-- != 0 && *d != '\0') d++; @@ -73,3 +82,4 @@ size_t strlcat(dst, src, siz) return(dlen + (s - src)); /* count does not include NUL */ } +#endif diff --git a/cmd-line-utils/libedit/np/strlcpy.c b/cmd-line-utils/libedit/np/strlcpy.c index 1f154bcf2ea75d2eb9cb7fdc7b741b6c31e8524f..092a9757c0fd56b855b4d4911d16889d8b85e95f 100644 --- a/cmd-line-utils/libedit/np/strlcpy.c +++ b/cmd-line-utils/libedit/np/strlcpy.c @@ -1,59 +1,63 @@ -/* $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $ */ +/* $NetBSD: strlcpy.c,v 1.3 2007/06/04 18:19:27 christos Exp $ */ +/* $OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $ */ /* * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> - * All rights reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE + * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#if !defined(_KERNEL) && !defined(_STANDALONE) +#if HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#else #include "config.h" -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $"; #endif +#if defined(LIBC_SCCS) && !defined(lint) #endif /* LIBC_SCCS and not lint */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD: src/lib/libc/string/strlcpy.c,v 1.2.4.1 2001/07/09 23:30:06 obrien Exp $"; -#endif +#ifdef _LIBC +#include "namespace.h" +#endif #include <sys/types.h> +#include <assert.h> #include <string.h> +#ifdef _LIBC +# ifdef __weak_alias +__weak_alias(strlcpy, _strlcpy) +# endif +#endif +#else +#include <lib/libkern/libkern.h> +#endif /* !_KERNEL && !_STANDALONE */ + + +#if !HAVE_STRLCPY /* * Copy src to string dst of size siz. At most siz-1 characters * will be copied. Always NUL terminates (unless siz == 0). * Returns strlen(src); if retval >= siz, truncation occurred. */ -size_t strlcpy(dst, src, siz) - char *dst; - const char *src; - size_t siz; +size_t +strlcpy(char *dst, const char *src, size_t siz) { - register char *d = dst; - register const char *s = src; - register size_t n = siz; + char *d = dst; + const char *s = src; + size_t n = siz; + + _DIAGASSERT(dst != NULL); + _DIAGASSERT(src != NULL); /* Copy as many bytes as will fit */ if (n != 0 && --n != 0) { @@ -73,3 +77,4 @@ size_t strlcpy(dst, src, siz) return(s - src - 1); /* count does not include NUL */ } +#endif diff --git a/cmd-line-utils/libedit/np/unvis.c b/cmd-line-utils/libedit/np/unvis.c index 895ff2059aca35faa46dd40d6c76828530c142b8..3c37c231ceb51771c8ec7fd3ec9b14372a005fa2 100644 --- a/cmd-line-utils/libedit/np/unvis.c +++ b/cmd-line-utils/libedit/np/unvis.c @@ -1,4 +1,4 @@ -/* $NetBSD: unvis.c,v 1.22 2002/03/23 17:38:27 christos Exp $ */ +/* $NetBSD: unvis.c,v 1.28 2005/09/13 01:44:09 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -12,11 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -34,34 +30,30 @@ */ #include "config.h" + #if defined(LIBC_SCCS) && !defined(lint) #if 0 static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: unvis.c,v 1.22 2002/03/23 17:38:27 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ -#define __LIBC12_SOURCE__ - #include <sys/types.h> #include <assert.h> #include <ctype.h> #include <stdio.h> +#ifdef HAVE_VIS_H +#include <vis.h> +#else #include "np/vis.h" +#endif #ifdef __weak_alias __weak_alias(strunvis,_strunvis) -__weak_alias(unvis,_unvis) #endif -#ifdef __warn_references -__warn_references(unvis, - "warning: reference to compatibility unvis(); include <vis.h> for correct reference") -#endif - -#if !HAVE_VIS_H +#if !HAVE_VIS /* * decode driven by state machine */ @@ -72,30 +64,22 @@ __warn_references(unvis, #define S_CTRL 4 /* control char started (^) */ #define S_OCTAL2 5 /* octal digit 2 */ #define S_OCTAL3 6 /* octal digit 3 */ -#define S_HEX1 7 /* hex digit */ -#define S_HEX2 8 /* hex digit 2 */ +#define S_HEX1 7 /* hex digit */ +#define S_HEX2 8 /* hex digit 2 */ #define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') #define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10)) -int -unvis(cp, c, astate, flag) - char *cp; - int c; - int *astate, flag; -{ - return __unvis13(cp, (int)c, astate, flag); -} - /* * unvis - decode characters previously encoded by vis */ int -__unvis13(cp, c, astate, flag) +unvis(cp, c, astate, flag) char *cp; int c; int *astate, flag; { + unsigned char uc = (unsigned char)c; _DIAGASSERT(cp != NULL); _DIAGASSERT(astate != NULL); @@ -105,7 +89,7 @@ __unvis13(cp, c, astate, flag) || *astate == S_HEX2) { *astate = S_GROUND; return (UNVIS_VALID); - } + } return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD); } @@ -116,7 +100,7 @@ __unvis13(cp, c, astate, flag) if (c == '\\') { *astate = S_START; return (0); - } + } if ((flag & VIS_HTTPSTYLE) && c == '%') { *astate = S_HEX1; return (0); @@ -193,7 +177,7 @@ __unvis13(cp, c, astate, flag) } *astate = S_GROUND; return (UNVIS_SYNBAD); - + case S_META: if (c == '-') *astate = S_META1; @@ -204,12 +188,12 @@ __unvis13(cp, c, astate, flag) return (UNVIS_SYNBAD); } return (0); - + case S_META1: *astate = S_GROUND; *cp |= c; return (UNVIS_VALID); - + case S_CTRL: if (c == '?') *cp |= 0177; @@ -219,23 +203,23 @@ __unvis13(cp, c, astate, flag) return (UNVIS_VALID); case S_OCTAL2: /* second possible octal digit */ - if (isoctal(c)) { - /* - * yes - and maybe a third + if (isoctal(uc)) { + /* + * yes - and maybe a third */ *cp = (*cp << 3) + (c - '0'); - *astate = S_OCTAL3; + *astate = S_OCTAL3; return (0); - } - /* - * no - done with current sequence, push back passed char + } + /* + * no - done with current sequence, push back passed char */ *astate = S_GROUND; return (UNVIS_VALIDPUSH); case S_OCTAL3: /* third possible octal digit */ *astate = S_GROUND; - if (isoctal(c)) { + if (isoctal(uc)) { *cp = (*cp << 3) + (c - '0'); return (UNVIS_VALID); } @@ -243,27 +227,30 @@ __unvis13(cp, c, astate, flag) * we were done, push back passed char */ return (UNVIS_VALIDPUSH); + case S_HEX1: - if (isxdigit(c)) { - *cp = xtod(c); + if (isxdigit(uc)) { + *cp = xtod(uc); *astate = S_HEX2; return (0); } - /* - * no - done with current sequence, push back passed char + /* + * no - done with current sequence, push back passed char */ *astate = S_GROUND; return (UNVIS_VALIDPUSH); + case S_HEX2: - *astate = S_GROUND; - if (isxdigit(c)) { - *cp = xtod(c) | (*cp << 4); + *astate = S_GROUND; + if (isxdigit(uc)) { + *cp = xtod(uc) | (*cp << 4); return (UNVIS_VALID); } - return (UNVIS_VALIDPUSH); - default: - /* - * decoder in unknown state - (probably uninitialized) + return (UNVIS_VALIDPUSH); + + default: + /* + * decoder in unknown state - (probably uninitialized) */ *astate = S_GROUND; return (UNVIS_SYNBAD); @@ -271,7 +258,7 @@ __unvis13(cp, c, astate, flag) } /* - * strunvis - decode src into dst + * strunvis - decode src into dst * * Number of chars decoded into dst is returned, -1 on error. * Dst is null terminated. @@ -291,8 +278,8 @@ strunvisx(dst, src, flag) _DIAGASSERT(dst != NULL); while ((c = *src++) != '\0') { - again: - switch (__unvis13(dst, c, &state, flag)) { + again: + switch (unvis(dst, c, &state, flag)) { case UNVIS_VALID: dst++; break; @@ -306,7 +293,7 @@ strunvisx(dst, src, flag) return (-1); } } - if (__unvis13(dst, c, &state, UNVIS_END) == UNVIS_VALID) + if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID) dst++; *dst = '\0'; return (dst - start); diff --git a/cmd-line-utils/libedit/np/vis.c b/cmd-line-utils/libedit/np/vis.c index e8f5c195f10fe213958be5982d5f1890ca3c4698..2a74627468196adc27330e8b9d0e7aa3fac6f588 100644 --- a/cmd-line-utils/libedit/np/vis.c +++ b/cmd-line-utils/libedit/np/vis.c @@ -1,7 +1,6 @@ -/* $NetBSD: vis.c,v 1.22 2002/03/23 17:38:27 christos Exp $ */ +/* $NetBSD: vis.c,v 1.38 2008/09/04 09:41:44 lukem Exp $ */ /*- - * Copyright (c) 1999 The NetBSD Foundation, Inc. * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,11 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -34,21 +29,47 @@ * SUCH DAMAGE. */ +/*- + * Copyright (c) 1999, 2005 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + #include "config.h" #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: vis.c,v 1.22 2002/03/23 17:38:27 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> + #include <assert.h> -#ifdef HAVE_ALLOCA_H -#include <alloca.h> +#ifdef HAVE_VIS_H +#include <vis.h> +#else +#include "np/vis.h" #endif #include <stdlib.h> -#include "np/vis.h" - #ifdef __weak_alias __weak_alias(strsvis,_strsvis) __weak_alias(strsvisx,_strsvisx) @@ -58,63 +79,61 @@ __weak_alias(svis,_svis) __weak_alias(vis,_vis) #endif -#if !HAVE_VIS_H +#if !HAVE_VIS || !HAVE_SVIS #include <ctype.h> #include <limits.h> #include <stdio.h> #include <string.h> -#include <assert.h> + +static char *do_svis(char *, int, int, int, const char *); + #undef BELL -#if defined(__STDC__) #define BELL '\a' -#else -#define BELL '\007' -#endif -#define isoctal(c) (((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '7') +#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') #define iswhite(c) (c == ' ' || c == '\t' || c == '\n') #define issafe(c) (c == '\b' || c == BELL || c == '\r') #define xtoa(c) "0123456789abcdef"[c] -#define MAXEXTRAS 5 - - -char *MAKEEXTRALIST(unsigned int flag, const char *orig) -{ - const char *o = orig; - char *e, *extra; - while (*o++) - continue; - extra = (char*) malloc((size_t)((o - orig) + MAXEXTRAS)); - assert(extra); - for (o = orig, e = extra; (*e++ = *o++) != '\0';) - continue; - e--; - if (flag & VIS_SP) *e++ = ' '; - if (flag & VIS_TAB) *e++ = '\t'; - if (flag & VIS_NL) *e++ = '\n'; - if ((flag & VIS_NOSLASH) == 0) *e++ = '\\'; - *e = '\0'; - return extra; -} +#define MAXEXTRAS 5 +#define MAKEEXTRALIST(flag, extra, orig_str) \ +do { \ + const char *orig = orig_str; \ + const char *o = orig; \ + char *e; \ + while (*o++) \ + continue; \ + extra = malloc((size_t)((o - orig) + MAXEXTRAS)); \ + if (!extra) break; \ + for (o = orig, e = extra; (*e++ = *o++) != '\0';) \ + continue; \ + e--; \ + if (flag & VIS_SP) *e++ = ' '; \ + if (flag & VIS_TAB) *e++ = '\t'; \ + if (flag & VIS_NL) *e++ = '\n'; \ + if ((flag & VIS_NOSLASH) == 0) *e++ = '\\'; \ + *e = '\0'; \ +} while (/*CONSTCOND*/0) /* - * This is HVIS, the macro of vis used to HTTP style (RFC 1808) + * This is do_hvis, for HTTP style (RFC 1808) */ -#define HVIS(dst, c, flag, nextc, extra) \ -do \ - if (!isascii(c) || !isalnum(c) || strchr("$-_.+!*'(),", c) != NULL) { \ - *dst++ = '%'; \ - *dst++ = xtoa(((unsigned int)c >> 4) & 0xf); \ - *dst++ = xtoa((unsigned int)c & 0xf); \ - } else { \ - SVIS(dst, c, flag, nextc, extra); \ - } \ -while (/*CONSTCOND*/0) - +static char * +do_hvis(char *dst, int c, int flag, int nextc, const char *extra) +{ + if (!isascii(c) || !isalnum(c) || strchr("$-_.+!*'(),", c) != NULL) { + *dst++ = '%'; + *dst++ = xtoa(((unsigned int)c >> 4) & 0xf); + *dst++ = xtoa((unsigned int)c & 0xf); + } else { + dst = do_svis(dst, c, flag, nextc, extra); + } + return dst; +} + /* - * This is SVIS, the central macro of vis. + * This is do_vis, the central code of vis. * dst: Pointer to the destination buffer * c: Character to encode * flag: Flag word @@ -122,95 +141,103 @@ while (/*CONSTCOND*/0) * extra: Pointer to the list of extra characters to be * backslash-protected. */ -#define SVIS(dst, c, flag, nextc, extra) \ -do { \ - int isextra, isc; \ - isextra = strchr(extra, c) != NULL; \ - if (!isextra && isascii(c) && (isgraph(c) || iswhite(c) || \ - ((flag & VIS_SAFE) && issafe(c)))) { \ - *dst++ = c; \ - break; \ - } \ - isc = 0; \ - if (flag & VIS_CSTYLE) { \ - switch (c) { \ - case '\n': \ - isc = 1; *dst++ = '\\'; *dst++ = 'n'; \ - break; \ - case '\r': \ - isc = 1; *dst++ = '\\'; *dst++ = 'r'; \ - break; \ - case '\b': \ - isc = 1; *dst++ = '\\'; *dst++ = 'b'; \ - break; \ - case BELL: \ - isc = 1; *dst++ = '\\'; *dst++ = 'a'; \ - break; \ - case '\v': \ - isc = 1; *dst++ = '\\'; *dst++ = 'v'; \ - break; \ - case '\t': \ - isc = 1; *dst++ = '\\'; *dst++ = 't'; \ - break; \ - case '\f': \ - isc = 1; *dst++ = '\\'; *dst++ = 'f'; \ - break; \ - case ' ': \ - isc = 1; *dst++ = '\\'; *dst++ = 's'; \ - break; \ - case '\0': \ - isc = 1; *dst++ = '\\'; *dst++ = '0'; \ - if (isoctal(nextc)) { \ - *dst++ = '0'; \ - *dst++ = '0'; \ - } \ - } \ - } \ - if (isc) break; \ - if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) { \ - *dst++ = '\\'; \ - *dst++ = (unsigned char)(((unsigned int)(unsigned char)c >> 6) & 03) + '0'; \ - *dst++ = (unsigned char)(((unsigned int)(unsigned char)c >> 3) & 07) + '0'; \ - *dst++ = (c & 07) + '0'; \ - } else { \ - if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\'; \ - if (c & 0200) { \ - c &= 0177; *dst++ = 'M'; \ - } \ - if (iscntrl(c)) { \ - *dst++ = '^'; \ - if (c == 0177) \ - *dst++ = '?'; \ - else \ - *dst++ = c + '@'; \ - } else { \ - *dst++ = '-'; *dst++ = c; \ - } \ - } \ -} while (/*CONSTCOND*/0) +static char * +do_svis(char *dst, int c, int flag, int nextc, const char *extra) +{ + int isextra; + isextra = strchr(extra, c) != NULL; + if (!isextra && isascii(c) && (isgraph(c) || iswhite(c) || + ((flag & VIS_SAFE) && issafe(c)))) { + *dst++ = c; + return dst; + } + if (flag & VIS_CSTYLE) { + switch (c) { + case '\n': + *dst++ = '\\'; *dst++ = 'n'; + return dst; + case '\r': + *dst++ = '\\'; *dst++ = 'r'; + return dst; + case '\b': + *dst++ = '\\'; *dst++ = 'b'; + return dst; + case BELL: + *dst++ = '\\'; *dst++ = 'a'; + return dst; + case '\v': + *dst++ = '\\'; *dst++ = 'v'; + return dst; + case '\t': + *dst++ = '\\'; *dst++ = 't'; + return dst; + case '\f': + *dst++ = '\\'; *dst++ = 'f'; + return dst; + case ' ': + *dst++ = '\\'; *dst++ = 's'; + return dst; + case '\0': + *dst++ = '\\'; *dst++ = '0'; + if (isoctal(nextc)) { + *dst++ = '0'; + *dst++ = '0'; + } + return dst; + default: + if (isgraph(c)) { + *dst++ = '\\'; *dst++ = c; + return dst; + } + } + } + if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) { + *dst++ = '\\'; + *dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + '0'; + *dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + '0'; + *dst++ = (c & 07) + '0'; + } else { + if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\'; + if (c & 0200) { + c &= 0177; *dst++ = 'M'; + } + if (iscntrl(c)) { + *dst++ = '^'; + if (c == 0177) + *dst++ = '?'; + else + *dst++ = c + '@'; + } else { + *dst++ = '-'; *dst++ = c; + } + } + return dst; +} /* * svis - visually encode characters, also encoding the characters - * pointed to by `extra' + * pointed to by `extra' */ char * -svis(dst, c, flag, nextc, extra) - char *dst; - int c, flag, nextc; - const char *extra; +svis(char *dst, int c, int flag, int nextc, const char *extra) { - char *nextra, *to_be_freed; + char *nextra = NULL; + _DIAGASSERT(dst != NULL); _DIAGASSERT(extra != NULL); - nextra= to_be_freed= MAKEEXTRALIST(flag, extra); + MAKEEXTRALIST(flag, nextra, extra); + if (!nextra) { + *dst = '\0'; /* can't create nextra, return "" */ + return dst; + } if (flag & VIS_HTTPSTYLE) - HVIS(dst, c, flag, nextc, nextra); + dst = do_hvis(dst, c, flag, nextc, nextra); else - SVIS(dst, c, flag, nextc, nextra); + dst = do_svis(dst, c, flag, nextc, nextra); + free(nextra); *dst = '\0'; - free(to_be_freed); - return(dst); + return dst; } @@ -221,140 +248,146 @@ svis(dst, c, flag, nextc, extra) * be encoded, too. These functions are useful e. g. to * encode strings in such a way so that they are not interpreted * by a shell. - * + * * Dst must be 4 times the size of src to account for possible * expansion. The length of dst, not including the trailing NULL, - * is returned. + * is returned. * * Strsvisx encodes exactly len bytes from src into dst. * This is useful for encoding a block of data. */ int -strsvis(dst, src, flag, extra) - char *dst; - const char *src; - int flag; - const char *extra; +strsvis(char *dst, const char *csrc, int flag, const char *extra) { - char c; + int c; char *start; - char *nextra, *to_be_freed; + char *nextra = NULL; + const unsigned char *src = (const unsigned char *)csrc; _DIAGASSERT(dst != NULL); _DIAGASSERT(src != NULL); _DIAGASSERT(extra != NULL); - nextra= to_be_freed= MAKEEXTRALIST(flag, extra); + MAKEEXTRALIST(flag, nextra, extra); + if (!nextra) { + *dst = '\0'; /* can't create nextra, return "" */ + return 0; + } if (flag & VIS_HTTPSTYLE) { for (start = dst; (c = *src++) != '\0'; /* empty */) - HVIS(dst, c, flag, *src, nextra); + dst = do_hvis(dst, c, flag, *src, nextra); } else { for (start = dst; (c = *src++) != '\0'; /* empty */) - SVIS(dst, c, flag, *src, nextra); + dst = do_svis(dst, c, flag, *src, nextra); } + free(nextra); *dst = '\0'; - free(to_be_freed); return (dst - start); } int -strsvisx(dst, src, len, flag, extra) - char *dst; - const char *src; - size_t len; - int flag; - const char *extra; +strsvisx(char *dst, const char *csrc, size_t len, int flag, const char *extra) { - char c; + unsigned char c; char *start; - char *nextra, *to_be_freed; + char *nextra = NULL; + const unsigned char *src = (const unsigned char *)csrc; _DIAGASSERT(dst != NULL); _DIAGASSERT(src != NULL); _DIAGASSERT(extra != NULL); - nextra= to_be_freed= MAKEEXTRALIST(flag, extra); + MAKEEXTRALIST(flag, nextra, extra); + if (! nextra) { + *dst = '\0'; /* can't create nextra, return "" */ + return 0; + } if (flag & VIS_HTTPSTYLE) { for (start = dst; len > 0; len--) { c = *src++; - HVIS(dst, c, flag, len ? *src : '\0', nextra); + dst = do_hvis(dst, c, flag, + len > 1 ? *src : '\0', nextra); } } else { for (start = dst; len > 0; len--) { c = *src++; - SVIS(dst, c, flag, len ? *src : '\0', nextra); + dst = do_svis(dst, c, flag, + len > 1 ? *src : '\0', nextra); } } + free(nextra); *dst = '\0'; - free(to_be_freed); return (dst - start); } +#endif - +#if !HAVE_VIS /* * vis - visually encode characters */ char * -vis(dst, c, flag, nextc) - char *dst; - int c, flag, nextc; - +vis(char *dst, int c, int flag, int nextc) { - char *extra, *to_be_freed; + char *extra = NULL; + unsigned char uc = (unsigned char)c; _DIAGASSERT(dst != NULL); - extra= to_be_freed= MAKEEXTRALIST(flag, ""); - + MAKEEXTRALIST(flag, extra, ""); + if (! extra) { + *dst = '\0'; /* can't create extra, return "" */ + return dst; + } if (flag & VIS_HTTPSTYLE) - HVIS(dst, c, flag, nextc, extra); + dst = do_hvis(dst, uc, flag, nextc, extra); else - SVIS(dst, c, flag, nextc, extra); + dst = do_svis(dst, uc, flag, nextc, extra); + free(extra); *dst = '\0'; - free(to_be_freed); - return (dst); + return dst; } /* * strvis, strvisx - visually encode characters from src into dst - * + * * Dst must be 4 times the size of src to account for possible * expansion. The length of dst, not including the trailing NULL, - * is returned. + * is returned. * * Strvisx encodes exactly len bytes from src into dst. * This is useful for encoding a block of data. */ int -strvis(dst, src, flag) - char *dst; - const char *src; - int flag; +strvis(char *dst, const char *src, int flag) { - char *extra; - int tmp; + char *extra = NULL; + int rv; - extra= MAKEEXTRALIST(flag, ""); - tmp= strsvis(dst, src, flag, extra); + MAKEEXTRALIST(flag, extra, ""); + if (!extra) { + *dst = '\0'; /* can't create extra, return "" */ + return 0; + } + rv = strsvis(dst, src, flag, extra); free(extra); - return tmp; + return rv; } int -strvisx(dst, src, len, flag) - char *dst; - const char *src; - size_t len; - int flag; +strvisx(char *dst, const char *src, size_t len, int flag) { - char *extra; - int tmp; + char *extra = NULL; + int rv; - extra= MAKEEXTRALIST(flag, ""); - tmp= strsvisx(dst, src, len, flag, extra); + MAKEEXTRALIST(flag, extra, ""); + if (!extra) { + *dst = '\0'; /* can't create extra, return "" */ + return 0; + } + rv = strsvisx(dst, src, len, flag, extra); free(extra); - return tmp; + return rv; } #endif diff --git a/cmd-line-utils/libedit/np/vis.h b/cmd-line-utils/libedit/np/vis.h index 1a49c9e3ed23043cb08d165c682edc04c5c368b2..11f5b740e2d6853504060a32439dd8025c13482f 100644 --- a/cmd-line-utils/libedit/np/vis.h +++ b/cmd-line-utils/libedit/np/vis.h @@ -1,4 +1,4 @@ -/* $NetBSD: vis.h,v 1.12 2002/03/23 17:39:05 christos Exp $ */ +/* $NetBSD: vis.h,v 1.16 2005/09/13 01:44:32 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -12,11 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -38,9 +34,7 @@ #ifndef _VIS_H_ #define _VIS_H_ -#ifdef HAVE_SYS_CDEFS_H -#include <sys/cdefs.h> -#endif +#include <sys/types.h> /* * to select alternate encoding format @@ -78,6 +72,7 @@ */ #define UNVIS_END 1 /* no more characters */ +__BEGIN_DECLS char *vis(char *, int, int, int); char *svis(char *, int, int, int, const char *); int strvis(char *, const char *, int); @@ -86,11 +81,7 @@ int strvisx(char *, const char *, size_t, int); int strsvisx(char *, const char *, size_t, int, const char *); int strunvis(char *, const char *); int strunvisx(char *, const char *, int); -#ifdef __LIBC12_SOURCE__ int unvis(char *, int, int *, int); -int __unvis13(char *, int, int *, int); -#else -int unvis(char *, int, int *, int) __RENAME(__unvis13); -#endif +__END_DECLS #endif /* !_VIS_H_ */ diff --git a/cmd-line-utils/libedit/parse.c b/cmd-line-utils/libedit/parse.c index 993cf5b752d215e998507ddc516e77577238e0e7..5bdefb5a0e4869783c28636a743b3718321e299d 100644 --- a/cmd-line-utils/libedit/parse.c +++ b/cmd-line-utils/libedit/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.20 2003/12/05 13:37:48 lukem Exp $ */ +/* $NetBSD: parse.c,v 1.22 2005/05/29 04:58:15 lukem Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * parse.c: parse an editline extended command @@ -129,7 +135,7 @@ el_parse(EditLine *el, int argc, const char *argv[]) * the appropriate character or -1 if the escape is not valid */ protected int -parse__escape(const char **const ptr) +parse__escape(const char **ptr) { const char *p; int c; diff --git a/cmd-line-utils/libedit/parse.h b/cmd-line-utils/libedit/parse.h index 4b796666b8ecef2e9f3fd210bb72a21421f81bd3..58dced1aeaa2fc5c818ce1b2d3c087dc05ad1714 100644 --- a/cmd-line-utils/libedit/parse.h +++ b/cmd-line-utils/libedit/parse.h @@ -1,4 +1,4 @@ -/* $NetBSD: parse.h,v 1.5 2003/08/07 16:44:32 agc Exp $ */ +/* $NetBSD: parse.h,v 1.6 2005/05/29 04:58:15 lukem Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,7 +41,7 @@ #define _h_el_parse protected int parse_line(EditLine *, const char *); -protected int parse__escape(const char ** const); +protected int parse__escape(const char **); protected char *parse__string(char *, const char *); protected int parse_cmd(EditLine *, const char *); diff --git a/cmd-line-utils/libedit/prompt.c b/cmd-line-utils/libedit/prompt.c index 455dd60331b5e2d7fb02575c267be0ccab060a5b..982943afd30c29b757cd424753c52925c6d651d0 100644 --- a/cmd-line-utils/libedit/prompt.c +++ b/cmd-line-utils/libedit/prompt.c @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * prompt.c: Prompt printing functions diff --git a/cmd-line-utils/libedit/read.c b/cmd-line-utils/libedit/read.c index 51848c2038e12ef6642a0b978fc2b34cc1b79d0b..ac768142e79e28cbb9e18605123e87250e59ab20 100644 --- a/cmd-line-utils/libedit/read.c +++ b/cmd-line-utils/libedit/read.c @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.35 2005/03/09 23:55:02 christos Exp $ */ +/* $NetBSD: read.c,v 1.43 2009/02/05 19:15:44 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * read.c: Clean this junk up! This is horrible code. @@ -50,6 +56,7 @@ private int read__fixio(int, int); private int read_preread(EditLine *); private int read_char(EditLine *, char *); private int read_getcmd(EditLine *, el_action_t *, char *); +private void read_pop(c_macro_t *); /* read_init(): * Initialize the read stuff @@ -205,7 +212,7 @@ read_preread(EditLine *el) * Push a macro */ public void -el_push(EditLine *el, char *str) +el_push(EditLine *el, const char *str) { c_macro_t *ma = &el->el_chared.c_macro; @@ -216,7 +223,7 @@ el_push(EditLine *el, char *str) ma->level--; } term_beep(el); - term__flush(); + term__flush(el); } @@ -294,6 +301,19 @@ read_char(EditLine *el, char *cp) return (num_read); } +/* read_pop(): + * Pop a macro from the stack + */ +private void +read_pop(c_macro_t *ma) +{ + int i; + + el_free(ma->macro[0]); + for (i = ma->level--; i > 0; i--) + ma->macro[i - 1] = ma->macro[i]; + ma->offset = 0; +} /* el_getc(): * Read a character @@ -304,26 +324,28 @@ el_getc(EditLine *el, char *cp) int num_read; c_macro_t *ma = &el->el_chared.c_macro; - term__flush(); + term__flush(el); for (;;) { if (ma->level < 0) { if (!read_preread(el)) break; } + if (ma->level < 0) break; - if (ma->macro[ma->level][ma->offset] == '\0') { - el_free(ma->macro[ma->level--]); - ma->offset = 0; + if (ma->macro[0][ma->offset] == '\0') { + read_pop(ma); continue; } - *cp = ma->macro[ma->level][ma->offset++] & 0377; - if (ma->macro[ma->level][ma->offset] == '\0') { + + *cp = ma->macro[0][ma->offset++] & 0377; + + if (ma->macro[0][ma->offset] == '\0') { /* Needed for QuoteMode On */ - el_free(ma->macro[ma->level--]); - ma->offset = 0; + read_pop(ma); } + return (1); } @@ -357,11 +379,11 @@ read_prepare(EditLine *el) we have the wrong size. */ el_resize(el); re_clear_display(el); /* reset the display stuff */ - ch_reset(el); + ch_reset(el, 0); re_refresh(el); /* print the prompt */ if (el->el_flags & UNBUFFERED) - term__flush(); + term__flush(el); } protected void @@ -438,7 +460,7 @@ el_gets(EditLine *el, int *nread) else cp = el->el_line.lastchar; - term__flush(); + term__flush(el); while ((*el->el_read.read_char)(el, cp) == 1) { /* make sure there is space next character */ @@ -478,7 +500,7 @@ el_gets(EditLine *el, int *nread) #endif /* DEBUG_READ */ break; } - if ((unsigned int)cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */ + if ((unsigned int)cmdnum >= (unsigned int)el->el_map.nfunc) { /* BUG CHECK command */ #ifdef DEBUG_EDIT (void) fprintf(el->el_errfile, "ERROR: illegal command from key 0%o\r\n", ch); @@ -570,7 +592,7 @@ el_gets(EditLine *el, int *nread) #endif /* DEBUG_READ */ /* put (real) cursor in a known place */ re_clear_display(el); /* reset the display stuff */ - ch_reset(el); /* reset the input pointers */ + ch_reset(el, 1); /* reset the input pointers */ re_refresh(el); /* print the prompt again */ break; @@ -581,7 +603,7 @@ el_gets(EditLine *el, int *nread) "*** editor ERROR ***\r\n\n"); #endif /* DEBUG_READ */ term_beep(el); - term__flush(); + term__flush(el); break; } el->el_state.argument = 1; @@ -591,7 +613,7 @@ el_gets(EditLine *el, int *nread) break; } - term__flush(); /* flush any buffered output */ + term__flush(el); /* flush any buffered output */ /* make sure the tty is set up correctly */ if ((el->el_flags & UNBUFFERED) == 0) { read_finish(el); diff --git a/cmd-line-utils/libedit/read.h b/cmd-line-utils/libedit/read.h index 1982f47253bc53ce3d7a4878d2a4eb80571126bb..bd8d4c1f5bbf473adb7c8d5771a7c3808a0c345d 100644 --- a/cmd-line-utils/libedit/read.h +++ b/cmd-line-utils/libedit/read.h @@ -1,4 +1,4 @@ -/* $NetBSD: read.h,v 1.4 2004/02/27 14:52:18 christos Exp $ */ +/* $NetBSD: read.h,v 1.6 2008/04/29 06:53:01 martin Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -15,13 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED diff --git a/cmd-line-utils/libedit/readline.c b/cmd-line-utils/libedit/readline.c index 004fcf7d1839729e42ca2ee9596c6b8b9dceee14..ca8796fbd3741892f6e2eb5e3dea0b60919c1979 100644 --- a/cmd-line-utils/libedit/readline.c +++ b/cmd-line-utils/libedit/readline.c @@ -1,4 +1,4 @@ -/* $NetBSD: readline.c,v 1.49 2005/03/10 19:34:46 christos Exp $ */ +/* $NetBSD: readline.c,v 1.78 2009/02/05 19:15:26 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -15,13 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -36,25 +29,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/* AIX requires this to be the first thing in the file. */ -#if defined (_AIX) && !defined (__GNUC__) - #pragma alloca -#endif - -#include <config.h> - -#ifdef __GNUC__ -# undef alloca -# define alloca(n) __builtin_alloca (n) -#else -# ifdef HAVE_ALLOCA_H -# include <alloca.h> -# else -# ifndef _AIX -extern char *alloca (); -# endif -# endif -#endif +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#endif /* not lint && not SCCSID */ #include <sys/types.h> #include <sys/stat.h> @@ -68,12 +45,23 @@ extern char *alloca (); #include <limits.h> #include <errno.h> #include <fcntl.h> +#include <setjmp.h> +#ifdef HAVE_VIS_H #include <vis.h> - -#include "readline/readline.h" +#else +#include "np/vis.h" +#endif +#ifdef HAVE_ALLOCA_H +#include <alloca.h> +#endif #include "el.h" #include "fcns.h" /* for EL_NUM_FCNS */ #include "histedit.h" +#include "readline/readline.h" +#include "filecomplete.h" + +void rl_prep_terminal(int); +void rl_deprep_terminal(void); /* for rl_complete() */ #define TAB '\r' @@ -94,9 +82,12 @@ FILE *rl_outstream = NULL; int rl_point = 0; int rl_end = 0; char *rl_line_buffer = NULL; -VFunction *rl_linefunc = NULL; +VCPFunction *rl_linefunc = NULL; int rl_done = 0; VFunction *rl_event_hook = NULL; +KEYMAP_ENTRY_ARRAY emacs_standard_keymap, + emacs_meta_keymap, + emacs_ctlx_keymap; int history_base = 1; /* probably never subject to change */ int history_length = 0; @@ -112,21 +103,23 @@ int rl_attempted_completion_over = 0; char *rl_basic_word_break_characters = break_chars; char *rl_completer_word_break_characters = NULL; char *rl_completer_quote_characters = NULL; -CPFunction *rl_completion_entry_function = NULL; +Function *rl_completion_entry_function = NULL; CPPFunction *rl_attempted_completion_function = NULL; Function *rl_pre_input_hook = NULL; Function *rl_startup1_hook = NULL; -Function *rl_getc_function = NULL; +int (*rl_getc_function)(FILE *) = NULL; char *rl_terminal_name = NULL; int rl_already_prompted = 0; int rl_filename_completion_desired = 0; int rl_ignore_completion_duplicates = 0; int rl_catch_signals = 1; +int readline_echoing_p = 1; +int _rl_print_completions_horizontally = 0; VFunction *rl_redisplay_function = NULL; Function *rl_startup_hook = NULL; VFunction *rl_completion_display_matches_hook = NULL; -VFunction *rl_prep_term_function = NULL; -VFunction *rl_deprep_term_function = NULL; +VFunction *rl_prep_term_function = (VFunction *)rl_prep_terminal; +VFunction *rl_deprep_term_function = (VFunction *)rl_deprep_terminal; /* * The current prompt string. @@ -150,7 +143,7 @@ int rl_completion_query_items = 100; * in the parsed text when it is passed to the completion function. * Shell uses this to help determine what kind of completing to do. */ -char *rl_special_prefixes = (char *)NULL; +char *rl_special_prefixes = NULL; /* * This is the character appended to the completed words if at the end of @@ -160,25 +153,21 @@ int rl_completion_append_character = ' '; /* stuff below is used internally by libedit for readline emulation */ -/* if not zero, non-unique completions always show list of possible matches */ -static int _rl_complete_show_all = 0; - static History *h = NULL; static EditLine *e = NULL; static Function *map[256]; -static int el_rl_complete_cmdnum = 0; +static jmp_buf topbuf; /* internal functions */ static unsigned char _el_rl_complete(EditLine *, int); static unsigned char _el_rl_tstp(EditLine *, int); static char *_get_prompt(EditLine *); +static int _getc_function(EditLine *, char *); static HIST_ENTRY *_move_history(int); static int _history_expand_command(const char *, size_t, size_t, char **); static char *_rl_compat_sub(const char *, const char *, const char *, int); -static int _rl_complete_internal(int); -static int _rl_qsort_string_compare(const void *, const void *); static int _rl_event_read_char(EditLine *, char *); static void _rl_update_pos(void); @@ -205,16 +194,49 @@ _move_history(int op) return (HIST_ENTRY *) NULL; rl_he.line = ev.str; - rl_he.data = (histdata_t) &(ev.num); + rl_he.data = NULL; return (&rl_he); } +/* + * read one key from user defined input function + */ +static int +/*ARGSUSED*/ +_getc_function(EditLine *el, char *c) +{ + int i; + + i = (*rl_getc_function)(NULL); + if (i == -1) + return 0; + *c = i; + return 1; +} + + /* * READLINE compatibility stuff */ +/* + * Set the prompt + */ +int +rl_set_prompt(const char *prompt) +{ + if (!prompt) + prompt = ""; + if (rl_prompt != NULL && strcmp(rl_prompt, prompt) == 0) + return 0; + if (rl_prompt) + free(rl_prompt); + rl_prompt = strdup(prompt); + return rl_prompt == NULL ? -1 : 0; +} + /* * initialize rl compat stuff */ @@ -223,7 +245,6 @@ rl_initialize(void) { HistEvent ev; const LineInfo *li; - int i; int editmode = 1; struct termios t; @@ -257,9 +278,12 @@ rl_initialize(void) max_input_history = INT_MAX; el_set(e, EL_HIST, history, h); + /* setup getc function if valid */ + if (rl_getc_function) + el_set(e, EL_GETCFN, _getc_function); + /* for proper prompt printing in readline() */ - rl_prompt = strdup(""); - if (rl_prompt == NULL) { + if (rl_set_prompt("") == -1) { history_end(h); el_end(e); return -1; @@ -291,17 +315,6 @@ rl_initialize(void) "ReadLine compatible suspend function", _el_rl_tstp); el_set(e, EL_BIND, "^Z", "rl_tstp", NULL); - - /* - * Find out where the rl_complete function was added; this is - * used later to detect that lastcmd was also rl_complete. - */ - for(i=EL_NUM_FCNS; i < e->el_map.nfunc; i++) { - if (e->el_map.func[i] == _el_rl_complete) { - el_rl_complete_cmdnum = i; - break; - } - } /* read settings from configuration file */ el_source(e, NULL); @@ -327,9 +340,10 @@ rl_initialize(void) * trailing newline (if there is any) */ char * -readline(const char *prompt) +readline(const char *p) { HistEvent ev; + const char * volatile prompt = p; int count; const char *ret; char *buf; @@ -340,15 +354,11 @@ readline(const char *prompt) rl_done = 0; + (void)setjmp(topbuf); + /* update prompt accordingly to what has been passed */ - if (!prompt) - prompt = ""; - if (strcmp(rl_prompt, prompt) != 0) { - free(rl_prompt); - rl_prompt = strdup(prompt); - if (rl_prompt == NULL) - return NULL; - } + if (rl_set_prompt(prompt) == -1) + return NULL; if (rl_pre_input_hook) (*rl_pre_input_hook)(NULL, 0); @@ -446,7 +456,7 @@ _rl_compat_sub(const char *str, const char *what, const char *with, } else *r++ = *s++; } - *r = 0; + *r = '\0'; return(result); } @@ -467,7 +477,7 @@ get_history_event(const char *cmd, int *cindex, int qchar) return(NULL); /* find out which event to take */ - if (cmd[idx] == history_expansion_char || cmd[idx] == 0) { + if (cmd[idx] == history_expansion_char || cmd[idx] == '\0') { if (history(h, &ev, H_FIRST) != 0) return(NULL); *cindex = cmd[idx]? (idx + 1):idx; @@ -689,7 +699,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen, if (aptr) free(aptr); - if (*cmd == 0 || (cmd - (command + offs) >= cmdlen)) { + if (*cmd == '\0' || ((size_t)(cmd - (command + offs)) >= cmdlen)) { *result = tmp; return(1); } @@ -699,7 +709,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen, continue; else if (*cmd == 'h') { /* remove trailing path */ if ((aptr = strrchr(tmp, '/')) != NULL) - *aptr = 0; + *aptr = '\0'; } else if (*cmd == 't') { /* remove leading path */ if ((aptr = strrchr(tmp, '/')) != NULL) { aptr = strdup(aptr + 1); @@ -708,7 +718,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen, } } else if (*cmd == 'r') { /* remove trailing suffix */ if ((aptr = strrchr(tmp, '.')) != NULL) - *aptr = 0; + *aptr = '\0'; } else if (*cmd == 'e') { /* remove all but suffix */ if ((aptr = strrchr(tmp, '.')) != NULL) { aptr = strdup(aptr); @@ -732,6 +742,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen, what = realloc(from, size); if (what == NULL) { free(from); + free(tmp); return 0; } len = 0; @@ -744,6 +755,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen, (size <<= 1)); if (nwhat == NULL) { free(what); + free(tmp); return 0; } what = nwhat; @@ -756,10 +768,13 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen, free(what); if (search) { from = strdup(search); - if (from == NULL) + if (from == NULL) { + free(tmp); return 0; + } } else { from = NULL; + free(tmp); return (-1); } } @@ -771,6 +786,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen, with = realloc(to, size); if (with == NULL) { free(to); + free(tmp); return -1; } len = 0; @@ -782,6 +798,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen, nwith = realloc(with, size); if (nwith == NULL) { free(with); + free(tmp); return -1; } with = nwith; @@ -850,12 +867,14 @@ history_expand(char *str, char **output) return 0; } -#define ADD_STRING(what, len) \ +#define ADD_STRING(what, len, fr) \ { \ if (idx + len + 1 > size) { \ char *nresult = realloc(result, (size += len + 1));\ if (nresult == NULL) { \ free(*output); \ + if (/*CONSTCOND*/fr) \ + free(tmp); \ return 0; \ } \ result = nresult; \ @@ -867,6 +886,7 @@ history_expand(char *str, char **output) result = NULL; size = idx = 0; + tmp = NULL; for (i = 0; str[i];) { int qchar, loop_again; size_t len, start, j; @@ -904,13 +924,11 @@ history_expand(char *str, char **output) goto loop; } len = i - start; - tmp = &str[start]; - ADD_STRING(tmp, len); + ADD_STRING(&str[start], len, 0); if (str[i] == '\0' || str[i] != history_expansion_char) { len = j - i; - tmp = &str[i]; - ADD_STRING(tmp, len); + ADD_STRING(&str[i], len, 0); if (start == 0) ret = 0; else @@ -920,8 +938,11 @@ history_expand(char *str, char **output) ret = _history_expand_command (str, i, (j - i), &tmp); if (ret > 0 && tmp) { len = strlen(tmp); - ADD_STRING(tmp, len); + ADD_STRING(tmp, len, 1); + } + if (tmp) { free(tmp); + tmp = NULL; } i = j; } @@ -973,23 +994,23 @@ history_arg_extract(int start, int end, const char *str) if (start < 0) start = end; - if (start < 0 || end < 0 || start > max || end > max || start > end) + if (start < 0 || end < 0 || (size_t)start > max || (size_t)end > max || start > end) return(NULL); - for (i = start, len = 0; i <= end; i++) + for (i = start, len = 0; i <= (size_t)end; i++) len += strlen(arr[i]) + 1; len++; result = malloc(len); if (result == NULL) return NULL; - for (i = start, len = 0; i <= end; i++) { + for (i = start, len = 0; i <= (size_t)end; i++) { (void)strcpy(result + len, arr[i]); len += strlen(arr[i]); - if (i < end) + if (i < (size_t)end) result[len++] = ' '; } - result[len] = 0; + result[len] = '\0'; for (i = 0; arr[i]; i++) free(arr[i]); @@ -1152,7 +1173,7 @@ history_get(int num) return (NULL); /* error */ /* look backwards for event matching specified offset */ - if (history(h, &ev, H_NEXT_EVENT, num)) + if (history(h, &ev, H_NEXT_EVENT, num + 1)) return (NULL); she.line = ev.str; @@ -1184,6 +1205,31 @@ add_history(const char *line) } +/* + * remove the specified entry from the history list and return it. + */ +HIST_ENTRY * +remove_history(int num) +{ + HIST_ENTRY *she; + HistEvent ev; + + if (h == NULL || e == NULL) + rl_initialize(); + + if (history(h, &ev, H_DEL, num) != 0) + return NULL; + + if ((she = malloc(sizeof(*she))) == NULL) + return NULL; + + she->line = ev.str; + she->data = NULL; + + return she; +} + + /* * clear the history list - delete all entries */ @@ -1377,172 +1423,18 @@ history_search_pos(const char *str, /********************************/ /* completion functions */ -/* - * does tilde expansion of strings of type ``~user/foo'' - * if ``user'' isn't valid user name or ``txt'' doesn't start - * w/ '~', returns pointer to strdup()ed copy of ``txt'' - * - * it's callers's responsibility to free() returned string - */ char * -tilde_expand(char *txt) +tilde_expand(char *name) { - struct passwd *pass; - char *temp; - size_t len = 0; - - if (txt[0] != '~') - return (strdup(txt)); - - temp = strchr(txt + 1, '/'); - if (temp == NULL) { - temp = strdup(txt + 1); - if (temp == NULL) - return NULL; - } else { - len = temp - txt + 1; /* text until string after slash */ - temp = malloc(len); - if (temp == NULL) - return NULL; - (void)strncpy(temp, txt + 1, len - 2); - temp[len - 2] = '\0'; - } - pass = getpwnam(temp); - free(temp); /* value no more needed */ - if (pass == NULL) - return (strdup(txt)); - - /* update pointer txt to point at string immedially following */ - /* first slash */ - txt += len; - - temp = malloc(strlen(pass->pw_dir) + 1 + strlen(txt) + 1); - if (temp == NULL) - return NULL; - (void)sprintf(temp, "%s/%s", pass->pw_dir, txt); - - return (temp); + return fn_tilde_expand(name); } - -/* - * return first found file name starting by the ``text'' or NULL if no - * such file can be found - * value of ``state'' is ignored - * - * it's caller's responsibility to free returned string - */ char * -filename_completion_function(const char *text, int state) +filename_completion_function(const char *name, int state) { - static DIR *dir = NULL; - static char *filename = NULL, *dirname = NULL; - static size_t filename_len = 0; - struct dirent *entry; - char *temp; - size_t len; - - if (state == 0 || dir == NULL) { - temp = strrchr(text, '/'); - if (temp) { - char *nptr; - temp++; - nptr = realloc(filename, strlen(temp) + 1); - if (nptr == NULL) { - free(filename); - return NULL; - } - filename = nptr; - (void)strcpy(filename, temp); - len = temp - text; /* including last slash */ - nptr = realloc(dirname, len + 1); - if (nptr == NULL) { - free(filename); - return NULL; - } - dirname = nptr; - (void)strncpy(dirname, text, len); - dirname[len] = '\0'; - } else { - if (*text == 0) - filename = NULL; - else { - filename = strdup(text); - if (filename == NULL) - return NULL; - } - dirname = NULL; - } - - /* support for ``~user'' syntax */ - if (dirname && *dirname == '~') { - char *nptr; - temp = tilde_expand(dirname); - if (temp == NULL) - return NULL; - nptr = realloc(dirname, strlen(temp) + 1); - if (nptr == NULL) { - free(dirname); - return NULL; - } - dirname = nptr; - (void)strcpy(dirname, temp); /* safe */ - free(temp); /* no longer needed */ - } - /* will be used in cycle */ - filename_len = filename ? strlen(filename) : 0; - - if (dir != NULL) { - (void)closedir(dir); - dir = NULL; - } - dir = opendir(dirname ? dirname : "."); - if (!dir) - return (NULL); /* cannot open the directory */ - } - /* find the match */ - while ((entry = readdir(dir)) != NULL) { - /* skip . and .. */ - if (entry->d_name[0] == '.' && (!entry->d_name[1] - || (entry->d_name[1] == '.' && !entry->d_name[2]))) - continue; - if (filename_len == 0) - break; - /* otherwise, get first entry where first */ - /* filename_len characters are equal */ - if (entry->d_name[0] == filename[0] - /* Some dirents have d_namlen, but it is not portable. */ - && strlen(entry->d_name) >= filename_len - && strncmp(entry->d_name, filename, - filename_len) == 0) - break; - } - - if (entry) { /* match found */ - - struct stat stbuf; - /* Some dirents have d_namlen, but it is not portable. */ - len = strlen(entry->d_name) + - ((dirname) ? strlen(dirname) : 0) + 1 + 1; - temp = malloc(len); - if (temp == NULL) - return NULL; - (void)sprintf(temp, "%s%s", - dirname ? dirname : "", entry->d_name); /* safe */ - - /* test, if it's directory */ - if (stat(temp, &stbuf) == 0 && S_ISDIR(stbuf.st_mode)) - strcat(temp, "/"); /* safe */ - } else { - (void)closedir(dir); - dir = NULL; - temp = NULL; - } - - return (temp); + return fn_filename_completion_function(name, state); } - /* * a completion generator for usernames; returns _first_ username * which starts with supplied text @@ -1564,6 +1456,7 @@ username_completion_function(const char *text, int state) if (state == 0) setpwent(); + /* XXXMYSQL: just use non-_r functions for now */ while ((pwd = getpwent()) && text[0] == pwd->pw_name[0] && strcmp(text, pwd->pw_name) == 0); @@ -1575,16 +1468,6 @@ username_completion_function(const char *text, int state) } -/* - * el-compatible wrapper around rl_complete; needed for key binding - */ -/* ARGSUSED */ -static unsigned char -_el_rl_complete(EditLine *el __attribute__((__unused__)), int ch) -{ - return (unsigned char) rl_complete(0, ch); -} - /* * el-compatible wrapper to send TSTP on ^Z */ @@ -1596,273 +1479,36 @@ _el_rl_tstp(EditLine *el __attribute__((__unused__)), int ch __attribute__((__un return CC_NORM; } -/* - * returns list of completions for text given - */ -char ** -completion_matches(const char *text, CPFunction *genfunc) -{ - char **match_list = NULL, *retstr, *prevstr; - size_t match_list_len, max_equal, which, i; - size_t matches; - - if (h == NULL || e == NULL) - rl_initialize(); - - matches = 0; - match_list_len = 1; - while ((retstr = (*genfunc) (text, (int)matches)) != NULL) { - /* allow for list terminator here */ - if (matches + 3 >= match_list_len) { - char **nmatch_list; - while (matches + 3 >= match_list_len) - match_list_len <<= 1; - nmatch_list = realloc(match_list, - match_list_len * sizeof(char *)); - if (nmatch_list == NULL) { - free(match_list); - return NULL; - } - match_list = nmatch_list; - - } - match_list[++matches] = retstr; - } - - if (!match_list) - return NULL; /* nothing found */ - - /* find least denominator and insert it to match_list[0] */ - which = 2; - prevstr = match_list[1]; - max_equal = strlen(prevstr); - for (; which <= matches; which++) { - for (i = 0; i < max_equal && - prevstr[i] == match_list[which][i]; i++) - continue; - max_equal = i; - } - - retstr = malloc(max_equal + 1); - if (retstr == NULL) { - free(match_list); - return NULL; - } - (void)strncpy(retstr, match_list[1], max_equal); - retstr[max_equal] = '\0'; - match_list[0] = retstr; - - /* add NULL as last pointer to the array */ - match_list[matches + 1] = (char *) NULL; - - return (match_list); -} - -/* - * Sort function for qsort(). Just wrapper around strcasecmp(). - */ -static int -_rl_qsort_string_compare(i1, i2) - const void *i1, *i2; -{ - const char *s1 = ((const char * const *)i1)[0]; - const char *s2 = ((const char * const *)i2)[0]; - - return strcasecmp(s1, s2); -} - /* * Display list of strings in columnar format on readline's output stream. * 'matches' is list of strings, 'len' is number of strings in 'matches', * 'max' is maximum length of string in 'matches'. */ void -rl_display_match_list (matches, len, max) - char **matches; - int len, max; +rl_display_match_list(char **matches, int len, int max) { - int i, idx, limit, count; - int screenwidth = e->el_term.t_size.h; - /* - * Find out how many entries can be put on one line, count - * with two spaces between strings. - */ - limit = screenwidth / (max + 2); - if (limit == 0) - limit = 1; - - /* how many lines of output */ - count = len / limit; - if (count * limit < len) - count++; - - /* Sort the items if they are not already sorted. */ - qsort(&matches[1], (size_t)(len - 1), sizeof(char *), - _rl_qsort_string_compare); - - idx = 1; - for(; count > 0; count--) { - for(i = 0; i < limit && matches[idx]; i++, idx++) - (void)fprintf(e->el_outfile, "%-*s ", max, - matches[idx]); - (void)fprintf(e->el_outfile, "\n"); - } + fn_display_match_list(e, matches, len, max); } -/* - * Complete the word at or before point, called by rl_complete() - * 'what_to_do' says what to do with the completion. - * `?' means list the possible completions. - * TAB means do standard completion. - * `*' means insert all of the possible completions. - * `!' means to do standard completion, and list all possible completions if - * there is more than one. - * - * Note: '*' support is not implemented - */ -static int -_rl_complete_internal(int what_to_do) +static const char * +/*ARGSUSED*/ +_rl_completion_append_character_function(const char *dummy + __attribute__((__unused__))) { - CPFunction *complet_func; - const LineInfo *li; - char *temp, **matches; - const char *ctemp; - size_t len; - - rl_completion_type = what_to_do; - - if (h == NULL || e == NULL) - rl_initialize(); - - complet_func = rl_completion_entry_function; - if (!complet_func) - complet_func = filename_completion_function; - - /* We now look backwards for the start of a filename/variable word */ - li = el_line(e); - ctemp = (const char *) li->cursor; - while (ctemp > li->buffer - && !strchr(rl_basic_word_break_characters, ctemp[-1]) - && (!rl_special_prefixes - || !strchr(rl_special_prefixes, ctemp[-1]) ) ) - ctemp--; - - len = li->cursor - ctemp; - temp = alloca(len + 1); - (void)strncpy(temp, ctemp, len); - temp[len] = '\0'; - - /* these can be used by function called in completion_matches() */ - /* or (*rl_attempted_completion_function)() */ - _rl_update_pos(); - - if (rl_attempted_completion_function) { - int end = li->cursor - li->buffer; - matches = (*rl_attempted_completion_function) (temp, (int) - (end - len), end); - } else - matches = 0; - if (!rl_attempted_completion_function || !matches) - matches = completion_matches(temp, complet_func); - - if (matches) { - int i, retval = CC_REFRESH; - int matches_num, maxlen, match_len, match_display=1; - - /* - * Only replace the completed string with common part of - * possible matches if there is possible completion. - */ - if (matches[0][0] != '\0') { - el_deletestr(e, (int) len); - el_insertstr(e, matches[0]); - } - - if (what_to_do == '?') - goto display_matches; - - if (matches[2] == NULL && strcmp(matches[0], matches[1]) == 0) { - /* - * We found exact match. Add a space after - * it, unless we do filename completion and the - * object is a directory. - */ - size_t alen = strlen(matches[0]); - if ((complet_func != filename_completion_function - || (alen > 0 && (matches[0])[alen - 1] != '/')) - && rl_completion_append_character) { - char buf[2]; - buf[0] = rl_completion_append_character; - buf[1] = '\0'; - el_insertstr(e, buf); - } - } else if (what_to_do == '!') { - display_matches: - /* - * More than one match and requested to list possible - * matches. - */ - - for(i=1, maxlen=0; matches[i]; i++) { - match_len = strlen(matches[i]); - if (match_len > maxlen) - maxlen = match_len; - } - matches_num = i - 1; - - /* newline to get on next line from command line */ - (void)fprintf(e->el_outfile, "\n"); - - /* - * If there are too many items, ask user for display - * confirmation. - */ - if (matches_num > rl_completion_query_items) { - (void)fprintf(e->el_outfile, - "Display all %d possibilities? (y or n) ", - matches_num); - (void)fflush(e->el_outfile); - if (getc(stdin) != 'y') - match_display = 0; - (void)fprintf(e->el_outfile, "\n"); - } - - if (match_display) - rl_display_match_list(matches, matches_num, - maxlen); - retval = CC_REDISPLAY; - } else if (matches[0][0]) { - /* - * There was some common match, but the name was - * not complete enough. Next tab will print possible - * completions. - */ - el_beep(e); - } else { - /* lcd is not a valid object - further specification */ - /* is needed */ - el_beep(e); - retval = CC_NORM; - } - - /* free elements of array and the array itself */ - for (i = 0; matches[i]; i++) - free(matches[i]); - free(matches), matches = NULL; - - return (retval); - } - return (CC_NORM); + static char buf[2]; + buf[0] = rl_completion_append_character; + buf[1] = '\0'; + return buf; } /* * complete word at current point */ +/* ARGSUSED */ int -/*ARGSUSED*/ -rl_complete(int ignore, int invoking_key) +rl_complete(int ignore __attribute__((__unused__)), int invoking_key) { if (h == NULL || e == NULL) rl_initialize(); @@ -1873,15 +1519,26 @@ rl_complete(int ignore, int invoking_key) arr[1] = '\0'; el_insertstr(e, arr); return (CC_REFRESH); - } else if (e->el_state.lastcmd == el_rl_complete_cmdnum) - return _rl_complete_internal('?'); - else if (_rl_complete_show_all) - return _rl_complete_internal('!'); - else - return _rl_complete_internal(TAB); + } + + /* Just look at how many global variables modify this operation! */ + return fn_complete(e, + (CPFunction *)rl_completion_entry_function, + rl_attempted_completion_function, + rl_basic_word_break_characters, rl_special_prefixes, + _rl_completion_append_character_function, rl_completion_query_items, + &rl_completion_type, &rl_attempted_completion_over, + &rl_point, &rl_end); } +/* ARGSUSED */ +static unsigned char +_el_rl_complete(EditLine *el __attribute__((__unused__)), int ch) +{ + return (unsigned char)rl_complete(0, ch); +} + /* * misc other functions */ @@ -1989,7 +1646,7 @@ int rl_add_defun(const char *name, Function *fun, int c) { char dest[8]; - if (c >= sizeof(map) / sizeof(map[0]) || c < 0) + if ((size_t)c >= sizeof(map) / sizeof(map[0]) || c < 0) return -1; map[(unsigned char)c] = fun; el_set(e, EL_ADDFN, name, name, rl_bind_wrapper); @@ -2007,11 +1664,7 @@ rl_callback_read_char() if (buf == NULL || count-- <= 0) return; -#ifdef CTRL2 /* _AIX */ - if (count == 0 && buf[0] == CTRL2('d')) -#else - if (count == 0 && buf[0] == CTRL('d')) -#endif + if (count == 0 && buf[0] == e->el_tty.t_c[TS_IO][C_EOF]) done = 1; if (buf[count] == '\n' || buf[count] == '\r') done = 2; @@ -2029,14 +1682,12 @@ rl_callback_read_char() } void -rl_callback_handler_install (const char *prompt, VFunction *linefunc) +rl_callback_handler_install(const char *prompt, VCPFunction *linefunc) { if (e == NULL) { rl_initialize(); } - if (rl_prompt) - free(rl_prompt); - rl_prompt = prompt ? strdup(strchr(prompt, *prompt)) : NULL; + (void)rl_set_prompt(prompt); rl_linefunc = linefunc; el_set(e, EL_UNBUFFERED, 1); } @@ -2045,17 +1696,14 @@ void rl_callback_handler_remove(void) { el_set(e, EL_UNBUFFERED, 0); + rl_linefunc = NULL; } void rl_redisplay(void) { char a[2]; -#ifdef CTRL2 /* _AIX */ - a[0] = CTRL2('r'); -#else - a[0] = CTRL('r'); -#endif + a[0] = e->el_tty.t_c[TS_IO][C_REPRINT]; a[1] = '\0'; el_push(e, a); } @@ -2079,7 +1727,7 @@ rl_prep_terminal(int meta_flag) } void -rl_deprep_terminal() +rl_deprep_terminal(void) { el_set(e, EL_PREP_TERM, 0); } @@ -2104,6 +1752,16 @@ rl_parse_and_bind(const char *line) return (argc ? 1 : 0); } +int +rl_variable_bind(const char *var, const char *value) +{ + /* + * The proper return value is undocument, but this is what the + * readline source seems to do. + */ + return ((el_set(e, EL_BIND, "", var, value) == -1) ? 1 : 0); +} + void rl_stuff_char(int c) { @@ -2119,7 +1777,7 @@ _rl_event_read_char(EditLine *el, char *cp) { int n, num_read = 0; - *cp = 0; + *cp = '\0'; while (rl_event_hook) { (*rl_event_hook)(); @@ -2164,3 +1822,142 @@ _rl_update_pos(void) rl_point = li->cursor - li->buffer; rl_end = li->lastchar - li->buffer; } + +void +rl_get_screen_size(int *rows, int *cols) +{ + if (rows) + el_get(e, EL_GETTC, "li", rows); + if (cols) + el_get(e, EL_GETTC, "co", cols); +} + +void +rl_set_screen_size(int rows, int cols) +{ + char buf[64]; + (void)snprintf(buf, sizeof(buf), "%d", rows); + el_set(e, EL_SETTC, "li", buf); + (void)snprintf(buf, sizeof(buf), "%d", cols); + el_set(e, EL_SETTC, "co", buf); +} + +char ** +rl_completion_matches(const char *str, rl_compentry_func_t *fun) +{ + size_t len, max, i, j, min; + char **list, *match, *a, *b; + + len = 1; + max = 10; + if ((list = malloc(max * sizeof(*list))) == NULL) + return NULL; + + while ((match = (*fun)(str, (int)(len - 1))) != NULL) { + if (len == max) { + char **nl; + max += 10; + if ((nl = realloc(list, max * sizeof(*nl))) == NULL) + goto out; + list = nl; + } + list[len++] = match; + } + if (len == 1) + goto out; + list[len] = NULL; + if (len == 2) { + if ((list[0] = strdup(list[1])) == NULL) + goto out; + return list; + } + qsort(&list[1], len - 1, sizeof(*list), + (int (*)(const void *, const void *)) strcmp); + min = SIZE_T_MAX; + for (i = 1, a = list[i]; i < len - 1; i++, a = b) { + b = list[i + 1]; + for (j = 0; a[j] && a[j] == b[j]; j++) + continue; + if (min > j) + min = j; + } + if (min == 0 && *str) { + if ((list[0] = strdup(str)) == NULL) + goto out; + } else { + if ((list[0] = malloc(min + 1)) == NULL) + goto out; + (void)memcpy(list[0], list[1], min); + list[0][min] = '\0'; + } + return list; + +out: + free(list); + return NULL; +} + +char * +rl_filename_completion_function (const char *text, int state) +{ + return fn_filename_completion_function(text, state); +} + +void +rl_forced_update_display(void) +{ + el_set(e, EL_REFRESH); +} + +int +_rl_abort_internal(void) +{ + el_beep(e); + longjmp(topbuf, 1); + /*NOTREACHED*/ +} + +int +_rl_qsort_string_compare(char **s1, char **s2) +{ + return strcoll(*s1, *s2); +} + +int +/*ARGSUSED*/ +rl_kill_text(int from, int to) +{ + return 0; +} + +Keymap +rl_make_bare_keymap(void) +{ + return NULL; +} + +Keymap +rl_get_keymap(void) +{ + return NULL; +} + +void +/*ARGSUSED*/ +rl_set_keymap(Keymap k) +{ +} + +int +/*ARGSUSED*/ +rl_generic_bind(int type, const char * keyseq, const char * data, Keymap k) +{ + return 0; +} + +int +/*ARGSUSED*/ +rl_bind_key_in_map(int key, Function *fun, Keymap k) +{ + return 0; +} diff --git a/cmd-line-utils/libedit/readline/readline.h b/cmd-line-utils/libedit/readline/readline.h index 6b1fa1865120d47be3bb5aef92f8c3e25211e443..c4806734bc5798f6c7e5ca97b70943050d5c90fd 100644 --- a/cmd-line-utils/libedit/readline/readline.h +++ b/cmd-line-utils/libedit/readline/readline.h @@ -1,4 +1,4 @@ -/* $NetBSD: readline.h,v 1.12 2004/09/08 18:15:37 christos Exp $ */ +/* $NetBSD: readline.h,v 1.24 2009/02/05 19:15:26 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -15,13 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -45,14 +38,14 @@ /* typedefs */ typedef int Function(const char *, int); typedef void VFunction(void); +typedef void VCPFunction(char *); typedef char *CPFunction(const char *, int); typedef char **CPPFunction(const char *, int, int); - -typedef void *histdata_t; +typedef char *rl_compentry_func_t(const char *, int); typedef struct _hist_entry { const char *line; - histdata_t *data; + const char *data; } HIST_ENTRY; typedef struct _keymap_entry { @@ -73,7 +66,7 @@ typedef KEYMAP_ENTRY *Keymap; #ifndef CTRL #include <sys/ioctl.h> -#if defined(__GLIBC__) || defined(__MWERKS__) +#if !defined(__sun__) && !defined(__hpux__) #include <sys/ttydefaults.h> #endif #ifndef CTRL @@ -102,8 +95,9 @@ extern int max_input_history; extern char *rl_basic_word_break_characters; extern char *rl_completer_word_break_characters; extern char *rl_completer_quote_characters; -extern CPFunction *rl_completion_entry_function; +extern Function *rl_completion_entry_function; extern CPPFunction *rl_attempted_completion_function; +extern int rl_attempted_completion_over; extern int rl_completion_type; extern int rl_completion_query_items; extern char *rl_special_prefixes; @@ -122,11 +116,13 @@ extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap, emacs_ctlx_keymap; extern int rl_filename_completion_desired; extern int rl_ignore_completion_duplicates; -extern Function *rl_getc_function; +extern int (*rl_getc_function)(FILE *); extern VFunction *rl_redisplay_function; extern VFunction *rl_completion_display_matches_hook; extern VFunction *rl_prep_term_function; extern VFunction *rl_deprep_term_function; +extern int readline_echoing_p; +extern int _rl_print_completions_horizontally; /* supported functions */ char *readline(const char *); @@ -141,6 +137,7 @@ int history_is_stifled(void); int where_history(void); HIST_ENTRY *current_history(void); HIST_ENTRY *history_get(int); +HIST_ENTRY *remove_history(int); int history_total_bytes(void); int history_set_pos(int); HIST_ENTRY *previous_history(void); @@ -168,7 +165,7 @@ void rl_reset_terminal(const char *); int rl_bind_key(int, int (*)(int, int)); int rl_newline(int, int); void rl_callback_read_char(void); -void rl_callback_handler_install(const char *, VFunction *); +void rl_callback_handler_install(const char *, VCPFunction *); void rl_callback_handler_remove(void); void rl_redisplay(void); int rl_get_previous_history(int, int); @@ -176,13 +173,24 @@ void rl_prep_terminal(int); void rl_deprep_terminal(void); int rl_read_init_file(const char *); int rl_parse_and_bind(const char *); +int rl_variable_bind(const char *, const char *); void rl_stuff_char(int); int rl_add_defun(const char *, Function *, int); +void rl_get_screen_size(int *, int *); +void rl_set_screen_size(int, int); +char *rl_filename_completion_function (const char *, int); +int _rl_abort_internal(void); +int _rl_qsort_string_compare(char **, char **); +char **rl_completion_matches(const char *, rl_compentry_func_t *); +void rl_forced_update_display(void); +int rl_set_prompt(const char *); /* * The following are not implemented */ +int rl_kill_text(int, int); Keymap rl_get_keymap(void); +void rl_set_keymap(Keymap); Keymap rl_make_bare_keymap(void); int rl_generic_bind(int, const char *, const char *, Keymap); int rl_bind_key_in_map(int, Function *, Keymap); diff --git a/cmd-line-utils/libedit/refresh.c b/cmd-line-utils/libedit/refresh.c index 46aca15ef08628deeed02ce627a2205273df35c4..5edd1fe78fc316fbd55fc8fad6b155de98acef6d 100644 --- a/cmd-line-utils/libedit/refresh.c +++ b/cmd-line-utils/libedit/refresh.c @@ -1,4 +1,4 @@ -/* $NetBSD: refresh.c,v 1.26 2003/08/07 16:44:33 agc Exp $ */ +/* $NetBSD: refresh.c,v 1.28 2008/09/10 15:45:37 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * refresh.c: Lower level screen refreshing functions @@ -49,6 +55,7 @@ private void re_update_line(EditLine *, char *, char *, int); private void re_insert (EditLine *, char *, int, int, char *, int); private void re_delete(EditLine *, char *, int, int, int); private void re_fastputc(EditLine *, int); +private void re_clear_eol(EditLine *, int, int, int); private void re__strncopy(char *, char *, size_t); private void re__copy_and_pad(char *, const char *, size_t); @@ -315,9 +322,9 @@ re_goto_bottom(EditLine *el) { term_move_to_line(el, el->el_refresh.r_oldcv); - term__putc('\n'); + term__putc(el, '\n'); re_clear_display(el); - term__flush(); + term__flush(el); } @@ -340,7 +347,7 @@ re_insert(EditLine *el __attribute__((__unused__)), ELRE_DEBUG(1, (__F, "re_insert() starting: %d at %d max %d, d == \"%s\"\n", num, dat, dlen, d)); - ELRE_DEBUG(1, (__F, "s == \"%s\"n", s)); + ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s)); /* open up the space for num chars */ if (num > 0) { @@ -353,7 +360,7 @@ re_insert(EditLine *el __attribute__((__unused__)), ELRE_DEBUG(1, (__F, "re_insert() after insert: %d at %d max %d, d == \"%s\"\n", num, dat, dlen, d)); - ELRE_DEBUG(1, (__F, "s == \"%s\"n", s)); + ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s)); /* copy the characters */ for (a = d + dat; (a < d + dlen) && (num > 0); num--) @@ -362,7 +369,7 @@ re_insert(EditLine *el __attribute__((__unused__)), ELRE_DEBUG(1, (__F, "re_insert() after copy: %d at %d max %d, %s == \"%s\"\n", num, dat, dlen, d, s)); - ELRE_DEBUG(1, (__F, "s == \"%s\"n", s)); + ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s)); } @@ -411,6 +418,32 @@ re__strncopy(char *a, char *b, size_t n) *a++ = *b++; } +/* re_clear_eol(): + * Find the number of characters we need to clear till the end of line + * in order to make sure that we have cleared the previous contents of + * the line. fx and sx is the number of characters inserted or deleted + * int the first or second diff, diff is the difference between the + * number of characters between the new and old line. + */ +private void +re_clear_eol(EditLine *el, int fx, int sx, int diff) +{ + + ELRE_DEBUG(1, (__F, "re_clear_eol sx %d, fx %d, diff %d\n", + sx, fx, diff)); + + if (fx < 0) + fx = -fx; + if (sx < 0) + sx = -sx; + if (fx > diff) + diff = fx; + if (sx > diff) + diff = sx; + + ELRE_DEBUG(1, (__F, "re_clear_eol %d\n", diff)); + term_clear_EOL(el, diff); +} /***************************************************************** re_update_line() is based on finding the middle difference of each line @@ -626,7 +659,7 @@ re_update_line(EditLine *el, char *old, char *new, int i) fx = (nsb - nfd) - (osb - ofd); sx = (nls - nse) - (ols - ose); - ELRE_DEBUG(1, (__F, "\n")); + ELRE_DEBUG(1, (__F, "fx %d, sx %d\n", fx, sx)); ELRE_DEBUG(1, (__F, "ofd %d, osb %d, ose %d, ols %d, oe %d\n", ofd - old, osb - old, ose - old, ols - old, oe - old)); ELRE_DEBUG(1, (__F, "nfd %d, nsb %d, nse %d, nls %d, ne %d\n", @@ -775,9 +808,7 @@ re_update_line(EditLine *el, char *old, char *new, int i) * write (nsb-nfd) chars of new starting at nfd */ term_overwrite(el, nfd, (nsb - nfd)); - ELRE_DEBUG(1, (__F, - "cleareol %d\n", (oe - old) - (ne - new))); - term_clear_EOL(el, (oe - old) - (ne - new)); + re_clear_eol(el, fx, sx, (oe - old) - (ne - new)); /* * Done */ @@ -818,10 +849,7 @@ re_update_line(EditLine *el, char *old, char *new, int i) ELRE_DEBUG(1, (__F, "but with nothing left to save\r\n")); term_overwrite(el, nse, (nls - nse)); - ELRE_DEBUG(1, (__F, - "cleareol %d\n", (oe - old) - (ne - new))); - if ((oe - old) - (ne - new) != 0) - term_clear_EOL(el, (oe - old) - (ne - new)); + re_clear_eol(el, fx, sx, (oe - old) - (ne - new)); } } /* @@ -982,7 +1010,7 @@ re_refresh_cursor(EditLine *el) /* now go there */ term_move_to_line(el, v); term_move_to_char(el, h); - term__flush(); + term__flush(el); } @@ -993,7 +1021,7 @@ private void re_fastputc(EditLine *el, int c) { - term__putc(c); + term__putc(el, c); el->el_display[el->el_cursor.v][el->el_cursor.h++] = c; if (el->el_cursor.h >= el->el_term.t_size.h) { /* if we must overflow */ @@ -1020,12 +1048,12 @@ re_fastputc(EditLine *el, int c) } if (EL_HAS_AUTO_MARGINS) { if (EL_HAS_MAGIC_MARGINS) { - term__putc(' '); - term__putc('\b'); + term__putc(el, ' '); + term__putc(el, '\b'); } } else { - term__putc('\r'); - term__putc('\n'); + term__putc(el, '\r'); + term__putc(el, '\n'); } } } @@ -1065,7 +1093,7 @@ re_fastaddc(EditLine *el) re_fastputc(el, (int)(((((unsigned int)c) >> 3) & 7) + '0')); re_fastputc(el, (c & 7) + '0'); } - term__flush(); + term__flush(el); } @@ -1104,7 +1132,7 @@ re_clear_lines(EditLine *el) } else { term_move_to_line(el, el->el_refresh.r_oldcv); /* go to last line */ - term__putc('\r'); /* go to BOL */ - term__putc('\n'); /* go to new line */ + term__putc(el, '\r'); /* go to BOL */ + term__putc(el, '\n'); /* go to new line */ } } diff --git a/cmd-line-utils/libedit/search.c b/cmd-line-utils/libedit/search.c index 850c5f271409c4097cf5fbbea1f21a38eae9d629..df50c7e7370514973ff68ea0f75e9ee1ed3376bb 100644 --- a/cmd-line-utils/libedit/search.c +++ b/cmd-line-utils/libedit/search.c @@ -32,12 +32,17 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * search.c: History and character search functions */ -#include <sys/types.h> #include <stdlib.h> #if defined(REGEX) #include <regex.h> diff --git a/cmd-line-utils/libedit/sig.c b/cmd-line-utils/libedit/sig.c index 8e70933d606e2bc0a8ad54fb964df7380d4de320..5307ee6ec6046797076cb96d435f3cb58d089cd3 100644 --- a/cmd-line-utils/libedit/sig.c +++ b/cmd-line-utils/libedit/sig.c @@ -1,4 +1,4 @@ -/* $NetBSD: sig.c,v 1.11 2003/08/07 16:44:33 agc Exp $ */ +/* $NetBSD: sig.c,v 1.12 2008/09/10 15:45:37 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * sig.c: Signal handling stuff. @@ -51,15 +57,15 @@ private const int sighdl[] = { - 1 }; -private void sig_handler(int); +private void el_sig_handler(int); -/* sig_handler(): +/* el_sig_handler(): * This is the handler called for all signals * XXX: we cannot pass any data so we just store the old editline * state in a private variable */ private void -sig_handler(int signo) +el_sig_handler(int signo) { int i; sigset_t nset, oset; @@ -73,7 +79,7 @@ sig_handler(int signo) tty_rawmode(sel); if (ed_redisplay(sel, 0) == CC_REFRESH) re_refresh(sel); - term__flush(); + term__flush(sel); break; case SIGWINCH: @@ -154,7 +160,7 @@ sig_set(EditLine *el) for (i = 0; sighdl[i] != -1; i++) { el_signalhandler_t s; /* This could happen if we get interrupted */ - if ((s = signal(sighdl[i], sig_handler)) != sig_handler) + if ((s = signal(sighdl[i], el_sig_handler)) != el_sig_handler) el->el_signal[i] = s; } sel = el; diff --git a/cmd-line-utils/libedit/sig.h b/cmd-line-utils/libedit/sig.h index 0bf1fc37e39451adb9f04654dedee11f4e9e8693..2bd3c516d466905ba1d201ec4ffda20c02fd4aa6 100644 --- a/cmd-line-utils/libedit/sig.h +++ b/cmd-line-utils/libedit/sig.h @@ -1,4 +1,4 @@ -/* $NetBSD: sig.h,v 1.5 2003/08/07 16:44:33 agc Exp $ */ +/* $NetBSD: sig.h,v 1.6 2008/07/12 15:27:14 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -51,7 +51,6 @@ #define ALLSIGS \ _DO(SIGINT) \ _DO(SIGTSTP) \ - _DO(SIGSTOP) \ _DO(SIGQUIT) \ _DO(SIGHUP) \ _DO(SIGTERM) \ diff --git a/cmd-line-utils/libedit/strlcpy.c b/cmd-line-utils/libedit/strlcpy.c deleted file mode 100644 index e38d6cf1c4b61ded014e43139c25913d1c8c6992..0000000000000000000000000000000000000000 --- a/cmd-line-utils/libedit/strlcpy.c +++ /dev/null @@ -1,73 +0,0 @@ -/* $NetBSD: strlcpy.c,v 1.14 2003/10/27 00:12:42 lukem Exp $ */ -/* $OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE - * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <config.h> - -#include <sys/types.h> -#include <assert.h> -#include <string.h> - -#ifdef _LIBC -# ifdef __weak_alias -__weak_alias(strlcpy, _strlcpy) -# endif -#endif - -#if !HAVE_STRLCPY -/* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. - */ -size_t -#ifdef _LIBC -_strlcpy(dst, src, siz) -#else -strlcpy(dst, src, siz) -#endif - char *dst; - const char *src; - size_t siz; -{ - char *d = dst; - const char *s = src; - size_t n = siz; - - _DIAGASSERT(dst != NULL); - _DIAGASSERT(src != NULL); - - /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) { - do { - if ((*d++ = *s++) == 0) - break; - } while (--n != 0); - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ -} -#endif diff --git a/cmd-line-utils/libedit/strlcpy.h b/cmd-line-utils/libedit/strlcpy.h deleted file mode 100644 index e4d3a7ffa3f262480646c95bdef08fa874943c8a..0000000000000000000000000000000000000000 --- a/cmd-line-utils/libedit/strlcpy.h +++ /dev/null @@ -1,2 +0,0 @@ -size_t strlcpy(char *dst, const char *src, size_t size); -size_t strlcat(char *dst, const char *src, size_t size); diff --git a/cmd-line-utils/libedit/sys.h b/cmd-line-utils/libedit/sys.h index c8a29dbfb05713297bbe76415d940fd0033d8124..a0369affbb04b89b86f06ec4c7b3ef859f770a20 100644 --- a/cmd-line-utils/libedit/sys.h +++ b/cmd-line-utils/libedit/sys.h @@ -48,14 +48,14 @@ # define __attribute__(A) #endif -#ifndef __P -# define __P(x) x -#endif - #ifndef _DIAGASSERT # define _DIAGASSERT(x) #endif +#ifndef SIZE_T_MAX +# define SIZE_T_MAX UINT_MAX +#endif + #ifndef __BEGIN_DECLS # ifdef __cplusplus # define __BEGIN_DECLS extern "C" { @@ -113,6 +113,25 @@ char *fgetln(FILE *fp, size_t *len); #define REGEX /* Use POSIX.2 regular expression functions */ #undef REGEXP /* Use UNIX V8 regular expression functions */ +#ifdef __SunOS +extern int tgetent(char *, const char *); +extern int tgetflag(char *); +extern int tgetnum(char *); +extern int tputs(const char *, int, int (*)(int)); +extern char* tgoto(const char*, int, int); +extern char* tgetstr(char*, char**); +#endif + +/* XXXMYSQL: Bug#10218 Command line recall rolls into segfault */ +#if !HAVE_DECL_TGOTO +/* + 'tgoto' is not declared in the system header files, this causes + problems on 64-bit systems. The function returns a 64 bit pointer + but caller see it as "int" and it's thus truncated to 32-bit +*/ +extern char* tgoto(const char*, int, int); +#endif + #ifdef notdef # undef REGEX # undef REGEXP diff --git a/cmd-line-utils/libedit/term.c b/cmd-line-utils/libedit/term.c index b516d6753c3245e765efec1c35627360d258cf8b..488c760da14c1a43e65e70abf2b8f011b1e33555 100644 --- a/cmd-line-utils/libedit/term.c +++ b/cmd-line-utils/libedit/term.c @@ -1,4 +1,4 @@ -/* $NetBSD: term.c,v 1.40 2004/05/22 23:21:28 christos Exp $ */ +/* $NetBSD: term.c,v 1.48 2009/02/06 20:08:13 sketch Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * term.c: Editor/termcap-curses interface @@ -44,21 +50,28 @@ #include <string.h> #include <stdlib.h> #include <unistd.h> - +#if 0 /* TODO: do we need this */ +#ifdef HAVE_TERMCAP_H +#include <termcap.h> +#endif +#endif #ifdef HAVE_CURSES_H -# include <curses.h> -#elif HAVE_NCURSES_H -# include <ncurses.h> +#include <curses.h> +#endif +#ifdef HAVE_NCURSES_H +#include <ncurses.h> #endif - /* Solaris's term.h does horrid things. */ -#if (defined(HAVE_TERM_H) && !defined(_SUNOS)) -# include <term.h> +#if (defined(HAVE_TERM_H) && !defined(__SunOS)) +#include <term.h> #endif - #include <sys/types.h> #include <sys/ioctl.h> +#ifdef _REENTRANT +#include <pthread.h> +#endif + #include "el.h" /* @@ -263,9 +276,13 @@ private int term_alloc_display(EditLine *); private void term_alloc(EditLine *, const struct termcapstr *, const char *); private void term_init_arrow(EditLine *); private void term_reset_arrow(EditLine *); +private int term_putc(int); +private void term_tputs(EditLine *, const char *, int); - -private FILE *term_outfile = NULL; /* XXX: How do we fix that? */ +#ifdef _REENTRANT +private pthread_mutex_t term_mutex = PTHREAD_MUTEX_INITIALIZER; +#endif +private FILE *term_outfile = NULL; /* term_setflags(): @@ -313,7 +330,6 @@ term_setflags(EditLine *el) #endif /* DEBUG_SCREEN */ } - /* term_init(): * Initialize the terminal stuff */ @@ -339,7 +355,6 @@ term_init(EditLine *el) if (el->el_term.t_val == NULL) return (-1); (void) memset(el->el_term.t_val, 0, T_val * sizeof(int)); - term_outfile = el->el_outfile; (void) term_set(el, NULL); term_init_arrow(el); return (0); @@ -390,7 +405,8 @@ term_alloc(EditLine *el, const struct termcapstr *t, const char *cap) * New string is shorter; no need to allocate space */ if (clen <= tlen) { - (void) strcpy(*str, cap); /* XXX strcpy is safe */ + if (*str) + (void) strcpy(*str, cap); /* XXX strcpy is safe */ return; } /* @@ -464,8 +480,12 @@ term_alloc_display(EditLine *el) return (-1); for (i = 0; i < c->v; i++) { b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1))); - if (b[i] == NULL) + if (b[i] == NULL) { + while (--i >= 0) + el_free((ptr_t) b[i]); + el_free((ptr_t) b); return (-1); + } } b[c->v] = NULL; el->el_display = b; @@ -475,8 +495,12 @@ term_alloc_display(EditLine *el) return (-1); for (i = 0; i < c->v; i++) { b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1))); - if (b[i] == NULL) + if (b[i] == NULL) { + while (--i >= 0) + el_free((ptr_t) b[i]); + el_free((ptr_t) b); return (-1); + } } b[c->v] = NULL; el->el_vdisplay = b; @@ -542,12 +566,12 @@ term_move_to_line(EditLine *el, int where) del--; } else { if ((del > 1) && GoodStr(T_DO)) { - (void) tputs(tgoto(Str(T_DO), del, del), - del, term__putc); + term_tputs(el, tgoto(Str(T_DO), del, + del), del); del = 0; } else { for (; del > 0; del--) - term__putc('\n'); + term__putc(el, '\n'); /* because the \n will become \r\n */ el->el_cursor.h = 0; } @@ -555,12 +579,11 @@ term_move_to_line(EditLine *el, int where) } } else { /* del < 0 */ if (GoodStr(T_UP) && (-del > 1 || !GoodStr(T_up))) - (void) tputs(tgoto(Str(T_UP), -del, -del), -del, - term__putc); + term_tputs(el, tgoto(Str(T_UP), -del, -del), -del); else { if (GoodStr(T_up)) for (; del < 0; del++) - (void) tputs(Str(T_up), 1, term__putc); + term_tputs(el, Str(T_up), 1); } } el->el_cursor.v = where;/* now where is here */ @@ -587,7 +610,7 @@ term_move_to_char(EditLine *el, int where) return; } if (!where) { /* if where is first column */ - term__putc('\r'); /* do a CR */ + term__putc(el, '\r'); /* do a CR */ el->el_cursor.h = 0; return; } @@ -595,12 +618,11 @@ term_move_to_char(EditLine *el, int where) if ((del < -4 || del > 4) && GoodStr(T_ch)) /* go there directly */ - (void) tputs(tgoto(Str(T_ch), where, where), where, term__putc); + term_tputs(el, tgoto(Str(T_ch), where, where), where); else { if (del > 0) { /* moving forward */ if ((del > 4) && GoodStr(T_RI)) - (void) tputs(tgoto(Str(T_RI), del, del), - del, term__putc); + term_tputs(el, tgoto(Str(T_RI), del, del), del); else { /* if I can do tabs, use them */ if (EL_CAN_TAB) { @@ -611,7 +633,7 @@ term_move_to_char(EditLine *el, int where) (el->el_cursor.h & 0370); i < (where & 0370); i += 8) - term__putc('\t'); + term__putc(el, '\t'); /* then tab over */ el->el_cursor.h = where & 0370; } @@ -631,8 +653,8 @@ term_move_to_char(EditLine *el, int where) } } else { /* del < 0 := moving backward */ if ((-del > 4) && GoodStr(T_LE)) - (void) tputs(tgoto(Str(T_LE), -del, -del), - -del, term__putc); + term_tputs(el, tgoto(Str(T_LE), -del, -del), + -del); else { /* can't go directly there */ /* * if the "cost" is greater than the "cost" @@ -643,12 +665,12 @@ term_move_to_char(EditLine *el, int where) (((unsigned int) where >> 3) + (where & 07))) : (-del > where)) { - term__putc('\r'); /* do a CR */ + term__putc(el, '\r'); /* do a CR */ el->el_cursor.h = 0; goto mc_again; /* and try again */ } for (i = 0; i < -del; i++) - term__putc('\b'); + term__putc(el, '\b'); } } } @@ -673,7 +695,7 @@ term_overwrite(EditLine *el, const char *cp, int n) return; } do { - term__putc(*cp++); + term__putc(el, *cp++); el->el_cursor.h++; } while (--n); @@ -689,7 +711,7 @@ term_overwrite(EditLine *el, const char *cp, int n) != '\0') term_overwrite(el, &c, 1); else - term__putc(' '); + term__putc(el, ' '); el->el_cursor.h = 1; } } else /* no wrap, but cursor stays on screen */ @@ -723,19 +745,18 @@ term_deletechars(EditLine *el, int num) if (GoodStr(T_DC)) /* if I have multiple delete */ if ((num > 1) || !GoodStr(T_dc)) { /* if dc would be more * expen. */ - (void) tputs(tgoto(Str(T_DC), num, num), - num, term__putc); + term_tputs(el, tgoto(Str(T_DC), num, num), num); return; } if (GoodStr(T_dm)) /* if I have delete mode */ - (void) tputs(Str(T_dm), 1, term__putc); + term_tputs(el, Str(T_dm), 1); if (GoodStr(T_dc)) /* else do one at a time */ while (num--) - (void) tputs(Str(T_dc), 1, term__putc); + term_tputs(el, Str(T_dc), 1); if (GoodStr(T_ed)) /* if I have delete mode */ - (void) tputs(Str(T_ed), 1, term__putc); + term_tputs(el, Str(T_ed), 1); } @@ -764,37 +785,35 @@ term_insertwrite(EditLine *el, char *cp, int num) if (GoodStr(T_IC)) /* if I have multiple insert */ if ((num > 1) || !GoodStr(T_ic)) { /* if ic would be more expensive */ - (void) tputs(tgoto(Str(T_IC), num, num), - num, term__putc); + term_tputs(el, tgoto(Str(T_IC), num, num), num); term_overwrite(el, cp, num); /* this updates el_cursor.h */ return; } if (GoodStr(T_im) && GoodStr(T_ei)) { /* if I have insert mode */ - (void) tputs(Str(T_im), 1, term__putc); + term_tputs(el, Str(T_im), 1); el->el_cursor.h += num; do - term__putc(*cp++); + term__putc(el, *cp++); while (--num); if (GoodStr(T_ip)) /* have to make num chars insert */ - (void) tputs(Str(T_ip), 1, term__putc); + term_tputs(el, Str(T_ip), 1); - (void) tputs(Str(T_ei), 1, term__putc); + term_tputs(el, Str(T_ei), 1); return; } do { if (GoodStr(T_ic)) /* have to make num chars insert */ - (void) tputs(Str(T_ic), 1, term__putc); - /* insert a char */ + term_tputs(el, Str(T_ic), 1); - term__putc(*cp++); + term__putc(el, *cp++); el->el_cursor.h++; if (GoodStr(T_ip)) /* have to make num chars insert */ - (void) tputs(Str(T_ip), 1, term__putc); + term_tputs(el, Str(T_ip), 1); /* pad the inserted char */ } while (--num); @@ -810,10 +829,10 @@ term_clear_EOL(EditLine *el, int num) int i; if (EL_CAN_CEOL && GoodStr(T_ce)) - (void) tputs(Str(T_ce), 1, term__putc); + term_tputs(el, Str(T_ce), 1); else { for (i = 0; i < num; i++) - term__putc(' '); + term__putc(el, ' '); el->el_cursor.h += num; /* have written num spaces */ } } @@ -828,14 +847,14 @@ term_clear_screen(EditLine *el) if (GoodStr(T_cl)) /* send the clear screen code */ - (void) tputs(Str(T_cl), Val(T_li), term__putc); + term_tputs(el, Str(T_cl), Val(T_li)); else if (GoodStr(T_ho) && GoodStr(T_cd)) { - (void) tputs(Str(T_ho), Val(T_li), term__putc); /* home */ + term_tputs(el, Str(T_ho), Val(T_li)); /* home */ /* clear to bottom of screen */ - (void) tputs(Str(T_cd), Val(T_li), term__putc); + term_tputs(el, Str(T_cd), Val(T_li)); } else { - term__putc('\r'); - term__putc('\n'); + term__putc(el, '\r'); + term__putc(el, '\n'); } } @@ -848,9 +867,9 @@ term_beep(EditLine *el) { if (GoodStr(T_bl)) /* what termcap says we should use */ - (void) tputs(Str(T_bl), 1, term__putc); + term_tputs(el, Str(T_bl), 1); else - term__putc('\007'); /* an ASCII bell; ^G */ + term__putc(el, '\007'); /* an ASCII bell; ^G */ } @@ -862,9 +881,9 @@ protected void term_clear_to_bottom(EditLine *el) { if (GoodStr(T_cd)) - (void) tputs(Str(T_cd), Val(T_li), term__putc); + term_tputs(el, Str(T_cd), Val(T_li)); else if (GoodStr(T_ce)) - (void) tputs(Str(T_ce), Val(T_li), term__putc); + term_tputs(el, Str(T_ce), Val(T_li)); } #endif @@ -936,7 +955,7 @@ term_set(EditLine *el, const char *term) Val(T_co) = tgetnum("co"); Val(T_li) = tgetnum("li"); for (t = tstr; t->name != NULL; t++) { - /* XXX: some systems tgetstr needs non const */ + /* XXX: some systems' tgetstr needs non const */ term_alloc(el, t, tgetstr(strchr(t->name, *t->name), &area)); } @@ -1220,26 +1239,62 @@ term_bind_arrow(EditLine *el) } } +/* term_putc(): + * Add a character + */ +private int +term_putc(int c) +{ + + if (term_outfile == NULL) + return -1; + return fputc(c, term_outfile); +} + +private void +term_tputs(EditLine *el, const char *cap, int affcnt) +{ +#ifdef _REENTRANT + pthread_mutex_lock(&term_mutex); +#endif + term_outfile = el->el_outfile; + (void)tputs(cap, affcnt, term_putc); +#ifdef _REENTRANT + pthread_mutex_unlock(&term_mutex); +#endif +} /* term__putc(): * Add a character */ protected int -term__putc(int c) +term__putc(EditLine *el, int c) { - return (fputc(c, term_outfile)); + return fputc(c, el->el_outfile); } - /* term__flush(): * Flush output */ protected void -term__flush(void) +term__flush(EditLine *el) { - (void) fflush(term_outfile); + (void) fflush(el->el_outfile); +} + +/* term_writec(): + * Write the given character out, in a human readable form + */ +protected void +term_writec(EditLine *el, int c) +{ + char buf[8]; + int cnt = key__decode_char(buf, sizeof(buf), 0, c); + buf[cnt] = '\0'; + term_overwrite(el, buf, cnt); + term__flush(el); } @@ -1269,11 +1324,17 @@ term_telltc(EditLine *el, int argc __attribute__((__unused__)), (void) fprintf(el->el_outfile, "\tIt %s magic margins\n", EL_HAS_MAGIC_MARGINS ? "has" : "does not have"); - for (t = tstr, ts = el->el_term.t_str; t->name != NULL; t++, ts++) + for (t = tstr, ts = el->el_term.t_str; t->name != NULL; t++, ts++) { + const char *ub; + if (*ts && **ts) { + (void) key__decode_str(*ts, upbuf, sizeof(upbuf), ""); + ub = upbuf; + } else { + ub = "(empty)"; + } (void) fprintf(el->el_outfile, "\t%25s (%s) == %s\n", - t->long_name, - t->name, *ts && **ts ? - key__decode_str(*ts, upbuf, "") : "(empty)"); + t->long_name, t->name, ub); + } (void) fputc('\n', el->el_outfile); return (0); } @@ -1292,7 +1353,7 @@ term_settc(EditLine *el, int argc __attribute__((__unused__)), const char *what, *how; if (argv == NULL || argv[1] == NULL || argv[2] == NULL) - return (-1); + return -1; what = argv[1]; how = argv[2]; @@ -1307,7 +1368,7 @@ term_settc(EditLine *el, int argc __attribute__((__unused__)), if (ts->name != NULL) { term_alloc(el, ts, how); term_setflags(el); - return (0); + return 0; } /* * Do the numeric ones second @@ -1316,46 +1377,100 @@ term_settc(EditLine *el, int argc __attribute__((__unused__)), if (strcmp(tv->name, what) == 0) break; - if (tv->name != NULL) { - if (tv == &tval[T_pt] || tv == &tval[T_km] || - tv == &tval[T_am] || tv == &tval[T_xn]) { - if (strcmp(how, "yes") == 0) - el->el_term.t_val[tv - tval] = 1; - else if (strcmp(how, "no") == 0) - el->el_term.t_val[tv - tval] = 0; - else { - (void) fprintf(el->el_errfile, - "settc: Bad value `%s'.\n", how); - return (-1); - } - term_setflags(el); - if (term_change_size(el, Val(T_li), Val(T_co)) == -1) - return (-1); - return (0); - } else { - long i; - char *ep; + if (tv->name != NULL) + return -1; - i = strtol(how, &ep, 10); - if (*ep != '\0') { - (void) fprintf(el->el_errfile, - "settc: Bad value `%s'.\n", how); - return (-1); - } - el->el_term.t_val[tv - tval] = (int) i; - el->el_term.t_size.v = Val(T_co); - el->el_term.t_size.h = Val(T_li); - if (tv == &tval[T_co] || tv == &tval[T_li]) - if (term_change_size(el, Val(T_li), Val(T_co)) - == -1) - return (-1); - return (0); + if (tv == &tval[T_pt] || tv == &tval[T_km] || + tv == &tval[T_am] || tv == &tval[T_xn]) { + if (strcmp(how, "yes") == 0) + el->el_term.t_val[tv - tval] = 1; + else if (strcmp(how, "no") == 0) + el->el_term.t_val[tv - tval] = 0; + else { + (void) fprintf(el->el_errfile, + "%s: Bad value `%s'.\n", argv[0], how); + return -1; + } + term_setflags(el); + if (term_change_size(el, Val(T_li), Val(T_co)) == -1) + return -1; + return 0; + } else { + long i; + char *ep; + + i = strtol(how, &ep, 10); + if (*ep != '\0') { + (void) fprintf(el->el_errfile, + "%s: Bad value `%s'.\n", argv[0], how); + return -1; } + el->el_term.t_val[tv - tval] = (int) i; + el->el_term.t_size.v = Val(T_co); + el->el_term.t_size.h = Val(T_li); + if (tv == &tval[T_co] || tv == &tval[T_li]) + if (term_change_size(el, Val(T_li), Val(T_co)) + == -1) + return -1; + return 0; } - return (-1); } +/* term_gettc(): + * Get the current terminal characteristics + */ +protected int +/*ARGSUSED*/ +term_gettc(EditLine *el, int argc __attribute__((__unused__)), char **argv) +{ + const struct termcapstr *ts; + const struct termcapval *tv; + char *what; + void *how; + + if (argv == NULL || argv[1] == NULL || argv[2] == NULL) + return (-1); + + what = argv[1]; + how = argv[2]; + + /* + * Do the strings first + */ + for (ts = tstr; ts->name != NULL; ts++) + if (strcmp(ts->name, what) == 0) + break; + + if (ts->name != NULL) { + *(char **)how = el->el_term.t_str[ts - tstr]; + return 0; + } + /* + * Do the numeric ones second + */ + for (tv = tval; tv->name != NULL; tv++) + if (strcmp(tv->name, what) == 0) + break; + + if (tv->name == NULL) + return -1; + + if (tv == &tval[T_pt] || tv == &tval[T_km] || + tv == &tval[T_am] || tv == &tval[T_xn]) { + static char yes[] = "yes"; + static char no[] = "no"; + if (el->el_term.t_val[tv - tval]) + *(char **)how = yes; + else + *(char **)how = no; + return 0; + } else { + *(int *)how = el->el_term.t_val[tv - tval]; + return 0; + } +} + /* term_echotc(): * Print the termcap string out with variable substitution */ @@ -1441,7 +1556,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)), break; } if (t->name == NULL) { - /* XXX: some systems tgetstr needs non const */ + /* XXX: some systems' tgetstr needs non const */ scap = tgetstr(strchr(*argv, **argv), &area); } if (!scap || scap[0] == '\0') { @@ -1494,7 +1609,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)), *argv); return (-1); } - (void) tputs(scap, 1, term__putc); + term_tputs(el, scap, 1); break; case 1: argv++; @@ -1522,7 +1637,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)), *argv); return (-1); } - (void) tputs(tgoto(scap, arg_cols, arg_rows), 1, term__putc); + term_tputs(el, tgoto(scap, arg_cols, arg_rows), 1); break; default: /* This is wrong, but I will ignore it... */ @@ -1578,8 +1693,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)), *argv); return (-1); } - (void) tputs(tgoto(scap, arg_cols, arg_rows), arg_rows, - term__putc); + term_tputs(el, tgoto(scap, arg_cols, arg_rows), arg_rows); break; } return (0); diff --git a/cmd-line-utils/libedit/tokenizer.c b/cmd-line-utils/libedit/tokenizer.c index 561b41740f82d1049ba53c8256015b0333367933..5161cdd0a22eb3fa33b1628885f69a17debd2337 100644 --- a/cmd-line-utils/libedit/tokenizer.c +++ b/cmd-line-utils/libedit/tokenizer.c @@ -32,7 +32,13 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * tokenize.c: Bourne shell like tokenizer diff --git a/cmd-line-utils/libedit/tokenizer.h b/cmd-line-utils/libedit/tokenizer.h deleted file mode 100644 index 7cc7a3346e4c7d50539d22b40a5a94182376bb45..0000000000000000000000000000000000000000 --- a/cmd-line-utils/libedit/tokenizer.h +++ /dev/null @@ -1,54 +0,0 @@ -/* $NetBSD: tokenizer.h,v 1.5 2002/03/18 16:01:00 christos Exp $ */ - -/*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Christos Zoulas of Cornell University. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tokenizer.h 8.1 (Berkeley) 6/4/93 - */ - -/* - * tokenizer.h: Header file for tokenizer routines - */ -#ifndef _h_tokenizer -#define _h_tokenizer - -typedef struct tokenizer Tokenizer; - -Tokenizer *tok_init(const char *); -void tok_reset(Tokenizer *); -void tok_end(Tokenizer *); -int tok_line(Tokenizer *, const char *, int *, const char ***); - -#endif /* _h_tokenizer */ diff --git a/cmd-line-utils/libedit/tty.c b/cmd-line-utils/libedit/tty.c index 6f73fb4f9e77e367d45716c17da55ed85670e0d1..3706905fc7931b85fd089cdca3099b8f244c3db7 100644 --- a/cmd-line-utils/libedit/tty.c +++ b/cmd-line-utils/libedit/tty.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty.c,v 1.21 2004/08/13 12:10:39 mycroft Exp $ */ +/* $NetBSD: tty.c,v 1.28 2009/02/06 19:53:23 sketch Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,18 +32,25 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * tty.c: tty interface stuff */ #include <assert.h> +#include <errno.h> #include "tty.h" #include "el.h" typedef struct ttymodes_t { const char *m_name; - u_int m_value; + unsigned int m_value; int m_type; } ttymodes_t; @@ -438,13 +445,12 @@ private const ttymodes_t ttymodes[] = { -#define tty_getty(el, td) tcgetattr((el)->el_infd, (td)) -#define tty_setty(el, td) tcsetattr((el)->el_infd, TCSADRAIN, (td)) - #define tty__gettabs(td) ((((td)->c_oflag & TAB3) == TAB3) ? 0 : 1) #define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8) #define tty__cooked_mode(td) ((td)->c_lflag & ICANON) +private int tty_getty(EditLine *, struct termios *); +private int tty_setty(EditLine *, int, const struct termios *); private int tty__getcharindex(int); private void tty__getchar(struct termios *, unsigned char *); private void tty__setchar(struct termios *, unsigned char *); @@ -453,6 +459,29 @@ private int tty_setup(EditLine *); #define t_qu t_ts +/* tty_getty(): + * Wrapper for tcgetattr to handle EINTR + */ +private int +tty_getty(EditLine *el, struct termios *t) +{ + int rv; + while ((rv = tcgetattr(el->el_infd, t)) == -1 && errno == EINTR) + continue; + return rv; +} + +/* tty_setty(): + * Wrapper for tcsetattr to handle EINTR + */ +private int +tty_setty(EditLine *el, int action, const struct termios *t) +{ + int rv; + while ((rv = tcsetattr(el->el_infd, action, t)) == -1 && errno == EINTR) + continue; + return rv; +} /* tty_setup(): * Get the tty parameters and initialize the editing state @@ -514,7 +543,7 @@ tty_setup(EditLine *el) el->el_tty.t_c[TS_IO][rst]; } tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]); - if (tty_setty(el, &el->el_tty.t_ex) == -1) { + if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) { #ifdef DEBUG_TTY (void) fprintf(el->el_errfile, "tty_setup: tty_setty: %s\n", @@ -522,8 +551,11 @@ tty_setup(EditLine *el) #endif /* DEBUG_TTY */ return (-1); } - } else + } +#ifdef notdef + else tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]); +#endif el->el_tty.t_ed.c_iflag &= ~el->el_tty.t_t[ED_IO][MD_INP].t_clrmask; el->el_tty.t_ed.c_iflag |= el->el_tty.t_t[ED_IO][MD_INP].t_setmask; @@ -1040,7 +1072,7 @@ tty_rawmode(EditLine *el) } } } - if (tty_setty(el, &el->el_tty.t_ed) == -1) { + if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) { #ifdef DEBUG_TTY (void) fprintf(el->el_errfile, "tty_rawmode: tty_setty: %s\n", strerror(errno)); @@ -1065,7 +1097,7 @@ tty_cookedmode(EditLine *el) if (el->el_flags & EDIT_DISABLED) return (0); - if (tty_setty(el, &el->el_tty.t_ex) == -1) { + if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) { #ifdef DEBUG_TTY (void) fprintf(el->el_errfile, "tty_cookedmode: tty_setty: %s\n", @@ -1101,7 +1133,7 @@ tty_quotemode(EditLine *el) el->el_tty.t_qu.c_lflag &= ~el->el_tty.t_t[QU_IO][MD_LIN].t_clrmask; el->el_tty.t_qu.c_lflag |= el->el_tty.t_t[QU_IO][MD_LIN].t_setmask; - if (tty_setty(el, &el->el_tty.t_qu) == -1) { + if (tty_setty(el, TCSADRAIN, &el->el_tty.t_qu) == -1) { #ifdef DEBUG_TTY (void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n", strerror(errno)); @@ -1122,7 +1154,7 @@ tty_noquotemode(EditLine *el) if (el->el_tty.t_mode != QU_IO) return (0); - if (tty_setty(el, &el->el_tty.t_ed) == -1) { + if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) { #ifdef DEBUG_TTY (void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n", strerror(errno)); @@ -1193,10 +1225,14 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const char **argv) st = len = strlen(el->el_tty.t_t[z][m->m_type].t_name); } - x = (el->el_tty.t_t[z][i].t_setmask & m->m_value) - ? '+' : '\0'; - x = (el->el_tty.t_t[z][i].t_clrmask & m->m_value) - ? '-' : x; + if (i != -1) { + x = (el->el_tty.t_t[z][i].t_setmask & m->m_value) + ? '+' : '\0'; + x = (el->el_tty.t_t[z][i].t_clrmask & m->m_value) + ? '-' : x; + } else { + x = '\0'; + } if (x != '\0' || aflag) { @@ -1221,7 +1257,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const char **argv) return (0); } while (argv && (s = *argv++)) { - char *p; + const char *p; switch (*s) { case '+': case '-': @@ -1232,10 +1268,10 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const char **argv) break; } d = s; - if ((p = strchr(s, '=')) != NULL) - *p++ = '\0'; + p = strchr(s, '='); for (m = ttymodes; m->m_name; m++) - if (strcmp(m->m_name, d) == 0 && + if ((p ? strncmp(m->m_name, d, (size_t)(p - d)) : + strcmp(m->m_name, d)) == 0 && (p == NULL || m->m_type == MD_CHAR)) break; @@ -1246,7 +1282,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const char **argv) } if (p) { int c = ffs((int)m->m_value); - int v = *p ? parse__escape((const char **const) &p) : + int v = *++p ? parse__escape((const char **) &p) : el->el_tty.t_vdisable; assert(c-- != 0); c = tty__getcharindex(c); @@ -1269,6 +1305,17 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const char **argv) break; } } + + if (el->el_tty.t_mode == z) { + if (tty_setty(el, TCSADRAIN, tios) == -1) { +#ifdef DEBUG_TTY + (void) fprintf(el->el_errfile, + "tty_stty: tty_setty: %s\n", strerror(errno)); +#endif /* DEBUG_TTY */ + return (-1); + } + } + return (0); } diff --git a/cmd-line-utils/libedit/tty.h b/cmd-line-utils/libedit/tty.h index cc7c4ad8c6676c36aa69934ec6a9a34226017292..10e9b98c953b6dad5a01ba3dcf52647dec2914a5 100644 --- a/cmd-line-utils/libedit/tty.h +++ b/cmd-line-utils/libedit/tty.h @@ -1,4 +1,4 @@ -/* $NetBSD: tty.h,v 1.10 2003/08/07 16:44:34 agc Exp $ */ +/* $NetBSD: tty.h,v 1.11 2005/06/01 11:37:52 lukem Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -450,8 +450,8 @@ typedef struct { const char *t_name; - u_int t_setmask; - u_int t_clrmask; + unsigned int t_setmask; + unsigned int t_clrmask; } ttyperm_t[NN_IO][MD_NN]; typedef unsigned char ttychar_t[NN_IO][C_NCC]; diff --git a/cmd-line-utils/libedit/unvis.c b/cmd-line-utils/libedit/unvis.c deleted file mode 100644 index ffa8ac4251c4d0cee5c805f672e667f3f44f44f0..0000000000000000000000000000000000000000 --- a/cmd-line-utils/libedit/unvis.c +++ /dev/null @@ -1,311 +0,0 @@ -/* $NetBSD: unvis.c,v 1.24 2003/08/07 16:42:59 agc Exp $ */ - -/*- - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <config.h> - -#define __LIBC12_SOURCE__ - -#include <sys/types.h> - -#include <assert.h> -#include <ctype.h> -#include <stdio.h> -#include <vis.h> - -#ifdef __weak_alias -__weak_alias(strunvis,_strunvis) -__weak_alias(unvis,_unvis) -#endif - -#ifdef __warn_references -__warn_references(unvis, - "warning: reference to compatibility unvis(); include <vis.h> for correct reference") -#endif - -#if !HAVE_VIS -/* - * decode driven by state machine - */ -#define S_GROUND 0 /* haven't seen escape char */ -#define S_START 1 /* start decoding special sequence */ -#define S_META 2 /* metachar started (M) */ -#define S_META1 3 /* metachar more, regular char (-) */ -#define S_CTRL 4 /* control char started (^) */ -#define S_OCTAL2 5 /* octal digit 2 */ -#define S_OCTAL3 6 /* octal digit 3 */ -#define S_HEX1 7 /* hex digit */ -#define S_HEX2 8 /* hex digit 2 */ - -#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') -#define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10)) - -int -unvis(cp, c, astate, flag) - char *cp; - int c; - int *astate, flag; -{ - return __unvis13(cp, (int)c, astate, flag); -} - -/* - * unvis - decode characters previously encoded by vis - */ -int -__unvis13(cp, c, astate, flag) - char *cp; - int c; - int *astate, flag; -{ - - _DIAGASSERT(cp != NULL); - _DIAGASSERT(astate != NULL); - - if (flag & UNVIS_END) { - if (*astate == S_OCTAL2 || *astate == S_OCTAL3 - || *astate == S_HEX2) { - *astate = S_GROUND; - return (UNVIS_VALID); - } - return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD); - } - - switch (*astate) { - - case S_GROUND: - *cp = 0; - if (c == '\\') { - *astate = S_START; - return (0); - } - if ((flag & VIS_HTTPSTYLE) && c == '%') { - *astate = S_HEX1; - return (0); - } - *cp = c; - return (UNVIS_VALID); - - case S_START: - switch(c) { - case '\\': - *cp = c; - *astate = S_GROUND; - return (UNVIS_VALID); - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - *cp = (c - '0'); - *astate = S_OCTAL2; - return (0); - case 'M': - *cp = (char)0200; - *astate = S_META; - return (0); - case '^': - *astate = S_CTRL; - return (0); - case 'n': - *cp = '\n'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'r': - *cp = '\r'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'b': - *cp = '\b'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'a': - *cp = '\007'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'v': - *cp = '\v'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 't': - *cp = '\t'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'f': - *cp = '\f'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 's': - *cp = ' '; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'E': - *cp = '\033'; - *astate = S_GROUND; - return (UNVIS_VALID); - case '\n': - /* - * hidden newline - */ - *astate = S_GROUND; - return (UNVIS_NOCHAR); - case '$': - /* - * hidden marker - */ - *astate = S_GROUND; - return (UNVIS_NOCHAR); - } - *astate = S_GROUND; - return (UNVIS_SYNBAD); - - case S_META: - if (c == '-') - *astate = S_META1; - else if (c == '^') - *astate = S_CTRL; - else { - *astate = S_GROUND; - return (UNVIS_SYNBAD); - } - return (0); - - case S_META1: - *astate = S_GROUND; - *cp |= c; - return (UNVIS_VALID); - - case S_CTRL: - if (c == '?') - *cp |= 0177; - else - *cp |= c & 037; - *astate = S_GROUND; - return (UNVIS_VALID); - - case S_OCTAL2: /* second possible octal digit */ - if (isoctal(c)) { - /* - * yes - and maybe a third - */ - *cp = (*cp << 3) + (c - '0'); - *astate = S_OCTAL3; - return (0); - } - /* - * no - done with current sequence, push back passed char - */ - *astate = S_GROUND; - return (UNVIS_VALIDPUSH); - - case S_OCTAL3: /* third possible octal digit */ - *astate = S_GROUND; - if (isoctal(c)) { - *cp = (*cp << 3) + (c - '0'); - return (UNVIS_VALID); - } - /* - * we were done, push back passed char - */ - return (UNVIS_VALIDPUSH); - case S_HEX1: - if (isxdigit(c)) { - *cp = xtod(c); - *astate = S_HEX2; - return (0); - } - /* - * no - done with current sequence, push back passed char - */ - *astate = S_GROUND; - return (UNVIS_VALIDPUSH); - case S_HEX2: - *astate = S_GROUND; - if (isxdigit(c)) { - *cp = xtod(c) | (*cp << 4); - return (UNVIS_VALID); - } - return (UNVIS_VALIDPUSH); - default: - /* - * decoder in unknown state - (probably uninitialized) - */ - *astate = S_GROUND; - return (UNVIS_SYNBAD); - } -} - -/* - * strunvis - decode src into dst - * - * Number of chars decoded into dst is returned, -1 on error. - * Dst is null terminated. - */ - -int -strunvisx(dst, src, flag) - char *dst; - const char *src; - int flag; -{ - char c; - char *start = dst; - int state = 0; - - _DIAGASSERT(src != NULL); - _DIAGASSERT(dst != NULL); - - while ((c = *src++) != '\0') { - again: - switch (__unvis13(dst, c, &state, flag)) { - case UNVIS_VALID: - dst++; - break; - case UNVIS_VALIDPUSH: - dst++; - goto again; - case 0: - case UNVIS_NOCHAR: - break; - default: - return (-1); - } - } - if (__unvis13(dst, c, &state, UNVIS_END) == UNVIS_VALID) - dst++; - *dst = '\0'; - return (dst - start); -} - -int -strunvis(dst, src) - char *dst; - const char *src; -{ - return strunvisx(dst, src, 0); -} -#endif diff --git a/cmd-line-utils/libedit/vi.c b/cmd-line-utils/libedit/vi.c index b977ce716c67a2ebf778afd5a1433b9e799687fa..602383f323168b61971c463dfca393240af32d96 100644 --- a/cmd-line-utils/libedit/vi.c +++ b/cmd-line-utils/libedit/vi.c @@ -1,4 +1,4 @@ -/* $NetBSD: vi.c,v 1.20 2004/08/13 12:10:39 mycroft Exp $ */ +/* $NetBSD: vi.c,v 1.28 2009/02/06 13:14:37 sketch Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -32,11 +32,17 @@ * SUCH DAMAGE. */ -#include <config.h> +#include "config.h" #include <stdlib.h> #include <unistd.h> #include <sys/wait.h> +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93"; +#else +#endif +#endif /* not lint && not SCCSID */ /* * vi.c: Vi mode commands. @@ -64,8 +70,10 @@ cv_action(EditLine *el, int c) el->el_line.lastchar - el->el_line.buffer); el->el_chared.c_vcmd.action = NOP; el->el_chared.c_vcmd.pos = 0; - el->el_line.lastchar = el->el_line.buffer; - el->el_line.cursor = el->el_line.buffer; + if (!(c & YANK)) { + el->el_line.lastchar = el->el_line.buffer; + el->el_line.cursor = el->el_line.buffer; + } if (c & INSERT) el->el_map.current = el->el_map.key; @@ -82,7 +90,6 @@ cv_action(EditLine *el, int c) private el_action_t cv_paste(EditLine *el, int c) { - char *ptr; c_kill_t *k = &el->el_chared.c_kill; int len = k->last - k->buf; @@ -96,12 +103,12 @@ cv_paste(EditLine *el, int c) if (!c && el->el_line.cursor < el->el_line.lastchar) el->el_line.cursor++; - ptr = el->el_line.cursor; c_insert(el, len); if (el->el_line.cursor + len > el->el_line.lastchar) return (CC_ERROR); - (void) memcpy(ptr, k->buf, len +0u); + (void) memcpy(el->el_line.cursor, k->buf, len +0u); + return (CC_REFRESH); } @@ -592,13 +599,12 @@ vi_delete_prev_char(EditLine *el, int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_list_or_eof(EditLine *el, int c __attribute__((__unused__))) +vi_list_or_eof(EditLine *el, int c) { if (el->el_line.cursor == el->el_line.lastchar) { if (el->el_line.cursor == el->el_line.buffer) { - term_overwrite(el, STReof, 4); /* then do a EOF */ - term__flush(); + term_writec(el, c); /* then do a EOF */ return (CC_EOF); } else { /* @@ -888,7 +894,7 @@ vi_yank(EditLine *el, int c) /* vi_comment_out(): * Vi comment out current command - * [c] + * [#] */ protected el_action_t /*ARGSUSED*/ @@ -905,18 +911,19 @@ vi_comment_out(EditLine *el, int c) /* vi_alias(): * Vi include shell alias * [@] - * NB: posix impiles that we should enter insert mode, however + * NB: posix implies that we should enter insert mode, however * this is against historical precedent... */ +#ifdef __weak_reference +extern char *get_alias_text(const char *) __weak_reference(get_alias_text); +#endif protected el_action_t /*ARGSUSED*/ vi_alias(EditLine *el, int c) { -#ifdef __weak_extern +#ifdef __weak_reference char alias_name[3]; char *alias_text; - extern char *get_alias_text(const char *); - __weak_extern(get_alias_text); if (get_alias_text == 0) { return CC_ERROR; @@ -1014,7 +1021,7 @@ vi_histedit(EditLine *el, int c) return CC_ERROR; case 0: close(fd); - execlp("vi", "vi", tempfile, (char *) NULL); + execlp("vi", "vi", tempfile, (char *)NULL); exit(0); /*NOTREACHED*/ default: diff --git a/cmd-line-utils/libedit/vis.c b/cmd-line-utils/libedit/vis.c deleted file mode 100644 index 127d28733a8a5908333be869769d218c0bbfd43a..0000000000000000000000000000000000000000 --- a/cmd-line-utils/libedit/vis.c +++ /dev/null @@ -1,392 +0,0 @@ -/* $NetBSD: vis.c,v 1.27 2004/02/26 23:01:15 enami Exp $ */ - -/*- - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*- - * Copyright (c) 1999 The NetBSD Foundation, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* AIX requires this to be the first thing in the file. */ -#if defined (_AIX) && !defined (__GNUC__) - #pragma alloca -#endif - -#include <config.h> - -#ifdef __GNUC__ -# undef alloca -# define alloca(n) __builtin_alloca (n) -#else -# ifdef HAVE_ALLOCA_H -# include <alloca.h> -# else -# ifndef _AIX -extern char *alloca (); -# endif -# endif -#endif - -#include <sys/types.h> - -#include <assert.h> -#include <vis.h> -#include <stdlib.h> - -#ifdef __weak_alias -__weak_alias(strsvis,_strsvis) -__weak_alias(strsvisx,_strsvisx) -__weak_alias(strvis,_strvis) -__weak_alias(strvisx,_strvisx) -__weak_alias(svis,_svis) -__weak_alias(vis,_vis) -#endif - -#if !HAVE_VIS || !HAVE_SVIS -#include <ctype.h> -#include <limits.h> -#include <stdio.h> -#include <string.h> - -#undef BELL -#define BELL '\a' - -#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') -#define iswhite(c) (c == ' ' || c == '\t' || c == '\n') -#define issafe(c) (c == '\b' || c == BELL || c == '\r') -#define xtoa(c) "0123456789abcdef"[c] - -#define MAXEXTRAS 5 - - -#define MAKEEXTRALIST(flag, extra, orig) \ -do { \ - const char *o = orig; \ - char *e; \ - while (*o++) \ - continue; \ - extra = alloca((size_t)((o - orig) + MAXEXTRAS)); \ - for (o = orig, e = extra; (*e++ = *o++) != '\0';) \ - continue; \ - e--; \ - if (flag & VIS_SP) *e++ = ' '; \ - if (flag & VIS_TAB) *e++ = '\t'; \ - if (flag & VIS_NL) *e++ = '\n'; \ - if ((flag & VIS_NOSLASH) == 0) *e++ = '\\'; \ - *e = '\0'; \ -} while (/*CONSTCOND*/0) - - -/* - * This is HVIS, the macro of vis used to HTTP style (RFC 1808) - */ -#define HVIS(dst, c, flag, nextc, extra) \ -do \ - if (!isascii(c) || !isalnum(c) || strchr("$-_.+!*'(),", c) != NULL) { \ - *dst++ = '%'; \ - *dst++ = xtoa(((unsigned int)c >> 4) & 0xf); \ - *dst++ = xtoa((unsigned int)c & 0xf); \ - } else { \ - SVIS(dst, c, flag, nextc, extra); \ - } \ -while (/*CONSTCOND*/0) - -/* - * This is SVIS, the central macro of vis. - * dst: Pointer to the destination buffer - * c: Character to encode - * flag: Flag word - * nextc: The character following 'c' - * extra: Pointer to the list of extra characters to be - * backslash-protected. - */ -#define SVIS(dst, c, flag, nextc, extra) \ -do { \ - int isextra; \ - isextra = strchr(extra, c) != NULL; \ - if (!isextra && isascii(c) && (isgraph(c) || iswhite(c) || \ - ((flag & VIS_SAFE) && issafe(c)))) { \ - *dst++ = c; \ - break; \ - } \ - if (flag & VIS_CSTYLE) { \ - switch (c) { \ - case '\n': \ - *dst++ = '\\'; *dst++ = 'n'; \ - continue; \ - case '\r': \ - *dst++ = '\\'; *dst++ = 'r'; \ - continue; \ - case '\b': \ - *dst++ = '\\'; *dst++ = 'b'; \ - continue; \ - case BELL: \ - *dst++ = '\\'; *dst++ = 'a'; \ - continue; \ - case '\v': \ - *dst++ = '\\'; *dst++ = 'v'; \ - continue; \ - case '\t': \ - *dst++ = '\\'; *dst++ = 't'; \ - continue; \ - case '\f': \ - *dst++ = '\\'; *dst++ = 'f'; \ - continue; \ - case ' ': \ - *dst++ = '\\'; *dst++ = 's'; \ - continue; \ - case '\0': \ - *dst++ = '\\'; *dst++ = '0'; \ - if (isoctal(nextc)) { \ - *dst++ = '0'; \ - *dst++ = '0'; \ - } \ - continue; \ - default: \ - if (isgraph(c)) { \ - *dst++ = '\\'; *dst++ = c; \ - continue; \ - } \ - } \ - } \ - if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) { \ - *dst++ = '\\'; \ - *dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + '0'; \ - *dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + '0'; \ - *dst++ = (c & 07) + '0'; \ - } else { \ - if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\'; \ - if (c & 0200) { \ - c &= 0177; *dst++ = 'M'; \ - } \ - if (iscntrl(c)) { \ - *dst++ = '^'; \ - if (c == 0177) \ - *dst++ = '?'; \ - else \ - *dst++ = c + '@'; \ - } else { \ - *dst++ = '-'; *dst++ = c; \ - } \ - } \ -} while (/*CONSTCOND*/0) - - -/* - * svis - visually encode characters, also encoding the characters - * pointed to by `extra' - */ -char * -svis(dst, c, flag, nextc, extra) - char *dst; - int c, flag, nextc; - const char *extra; -{ - char *nextra; - _DIAGASSERT(dst != NULL); - _DIAGASSERT(extra != NULL); - MAKEEXTRALIST(flag, nextra, extra); - if (flag & VIS_HTTPSTYLE) - HVIS(dst, c, flag, nextc, nextra); - else - SVIS(dst, c, flag, nextc, nextra); - *dst = '\0'; - return(dst); -} - - -/* - * strsvis, strsvisx - visually encode characters from src into dst - * - * Extra is a pointer to a \0-terminated list of characters to - * be encoded, too. These functions are useful e. g. to - * encode strings in such a way so that they are not interpreted - * by a shell. - * - * Dst must be 4 times the size of src to account for possible - * expansion. The length of dst, not including the trailing NULL, - * is returned. - * - * Strsvisx encodes exactly len bytes from src into dst. - * This is useful for encoding a block of data. - */ -int -strsvis(dst, csrc, flag, extra) - char *dst; - const char *csrc; - int flag; - const char *extra; -{ - int c; - char *start; - char *nextra; - const unsigned char *src = (const unsigned char *)csrc; - - _DIAGASSERT(dst != NULL); - _DIAGASSERT(src != NULL); - _DIAGASSERT(extra != NULL); - MAKEEXTRALIST(flag, nextra, extra); - if (flag & VIS_HTTPSTYLE) { - for (start = dst; (c = *src++) != '\0'; /* empty */) - HVIS(dst, c, flag, *src, nextra); - } else { - for (start = dst; (c = *src++) != '\0'; /* empty */) - SVIS(dst, c, flag, *src, nextra); - } - *dst = '\0'; - return (dst - start); -} - - -int -strsvisx(dst, csrc, len, flag, extra) - char *dst; - const char *csrc; - size_t len; - int flag; - const char *extra; -{ - int c; - char *start; - char *nextra; - const unsigned char *src = (const unsigned char *)csrc; - - _DIAGASSERT(dst != NULL); - _DIAGASSERT(src != NULL); - _DIAGASSERT(extra != NULL); - MAKEEXTRALIST(flag, nextra, extra); - - if (flag & VIS_HTTPSTYLE) { - for (start = dst; len > 0; len--) { - c = *src++; - HVIS(dst, c, flag, len ? *src : '\0', nextra); - } - } else { - for (start = dst; len > 0; len--) { - c = *src++; - SVIS(dst, c, flag, len ? *src : '\0', nextra); - } - } - *dst = '\0'; - return (dst - start); -} -#endif - -#if !HAVE_VIS -/* - * vis - visually encode characters - */ -char * -vis(dst, c, flag, nextc) - char *dst; - int c, flag, nextc; - -{ - char *extra; - - _DIAGASSERT(dst != NULL); - - MAKEEXTRALIST(flag, extra, ""); - if (flag & VIS_HTTPSTYLE) - HVIS(dst, c, flag, nextc, extra); - else - SVIS(dst, c, flag, nextc, extra); - *dst = '\0'; - return (dst); -} - - -/* - * strvis, strvisx - visually encode characters from src into dst - * - * Dst must be 4 times the size of src to account for possible - * expansion. The length of dst, not including the trailing NULL, - * is returned. - * - * Strvisx encodes exactly len bytes from src into dst. - * This is useful for encoding a block of data. - */ -int -strvis(dst, src, flag) - char *dst; - const char *src; - int flag; -{ - char *extra; - - MAKEEXTRALIST(flag, extra, ""); - return (strsvis(dst, src, flag, extra)); -} - - -int -strvisx(dst, src, len, flag) - char *dst; - const char *src; - size_t len; - int flag; -{ - char *extra; - - MAKEEXTRALIST(flag, extra, ""); - return (strsvisx(dst, src, len, flag, extra)); -} -#endif diff --git a/cmd-line-utils/libedit/vis.h b/cmd-line-utils/libedit/vis.h deleted file mode 100644 index 44f6fc7d785b63ef733fec501f13167acf610aff..0000000000000000000000000000000000000000 --- a/cmd-line-utils/libedit/vis.h +++ /dev/null @@ -1,92 +0,0 @@ -/* $NetBSD: vis.h,v 1.15 2005/02/03 04:39:32 perry Exp $ */ - -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)vis.h 8.1 (Berkeley) 6/2/93 - */ - -#ifndef _VIS_H_ -#define _VIS_H_ - -#include <config.h> - -/* - * to select alternate encoding format - */ -#define VIS_OCTAL 0x01 /* use octal \ddd format */ -#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropiate */ - -/* - * to alter set of characters encoded (default is to encode all - * non-graphic except space, tab, and newline). - */ -#define VIS_SP 0x04 /* also encode space */ -#define VIS_TAB 0x08 /* also encode tab */ -#define VIS_NL 0x10 /* also encode newline */ -#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL) -#define VIS_SAFE 0x20 /* only encode "unsafe" characters */ - -/* - * other - */ -#define VIS_NOSLASH 0x40 /* inhibit printing '\' */ -#define VIS_HTTPSTYLE 0x80 /* http-style escape % HEX HEX */ - -/* - * unvis return codes - */ -#define UNVIS_VALID 1 /* character valid */ -#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */ -#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */ -#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */ -#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */ - -/* - * unvis flags - */ -#define UNVIS_END 1 /* no more characters */ - -__BEGIN_DECLS -char *vis(char *, int, int, int); -char *svis(char *, int, int, int, const char *); -int strvis(char *, const char *, int); -int strsvis(char *, const char *, int, const char *); -int strvisx(char *, const char *, size_t, int); -int strsvisx(char *, const char *, size_t, int, const char *); -int strunvis(char *, const char *); -int strunvisx(char *, const char *, int); -#ifdef __LIBC12_SOURCE__ -int unvis(char *, int, int *, int); -int __unvis13(char *, int, int *, int); -#else -int unvis(char *, int, int *, int); -#endif -__END_DECLS - -#endif /* !_VIS_H_ */ diff --git a/include/my_global.h b/include/my_global.h index 4581dd6785c162327b7ab0f3f44bd636d74149cb..8c25cbf802e74a49a3204eb272d9c551842a1dab 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -621,7 +621,6 @@ C_MODE_END */ #define _VARARGS(X) X #define _STATIC_VARARGS(X) X -#define _PC(X) X /* The DBUG_ON flag always takes precedence over default DBUG_OFF */ #if defined(DBUG_ON) && defined(DBUG_OFF) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index ca329eadf0fbe61cb5a3c222717a2356d95a9fc5..e84e79fc89e0bc81beac77e7e70409e5a47f08e7 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -3833,13 +3833,13 @@ static void fetch_float_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, #undef NOT_FIXED_DEC { /* - The 14 below is to ensure that the server and client has the same + DBL_DIG below is to ensure that the server and client has the same precisions. This will ensure that on the same machine you get the same value as a string independent of the protocol you use. */ sprintf(buff, "%-*.*g", (int) min(sizeof(buff)-1, param->buffer_length), - min(14,width), value); + min(DBL_DIG, width), value); end= strcend(buff, ' '); *end= 0; } diff --git a/mysql-test/extra/binlog_tests/binlog_truncate.test b/mysql-test/extra/binlog_tests/binlog_truncate.test new file mode 100644 index 0000000000000000000000000000000000000000..dce33b3cef0e98ce3972ec7ec5a4e7e6c4344d51 --- /dev/null +++ b/mysql-test/extra/binlog_tests/binlog_truncate.test @@ -0,0 +1,27 @@ +# BUG #36763: TRUNCATE TABLE fails to replicate when stmt-based +# binlogging is not supported. + +# This should always be logged as a statement, even when executed as a +# row-by-row deletion. + +# $before_truncate A statement to execute (just) before issuing the +# TRUNCATE TABLE + + +eval CREATE TABLE t1 (a INT) ENGINE=$engine; +eval CREATE TABLE t2 (a INT) ENGINE=$engine; +INSERT INTO t2 VALUES (1),(2),(3); +let $binlog_start = query_get_value("SHOW MASTER STATUS", Position, 1); +if (`select length('$before_truncate') > 0`) { + eval $before_truncate; +} +--echo **** Truncate of empty table shall be logged +TRUNCATE TABLE t1; + +if (`select length('$before_truncate') > 0`) { + eval $before_truncate; +} +TRUNCATE TABLE t2; +source include/show_binlog_events.inc; + +DROP TABLE t1,t2; diff --git a/mysql-test/extra/rpl_tests/rpl_truncate.test b/mysql-test/extra/rpl_tests/rpl_truncate.test index bca533365141d295bd67cc893fefce91d6bf6d8f..7036ab126e10bcec389474720eac5163bba18179 100644 --- a/mysql-test/extra/rpl_tests/rpl_truncate.test +++ b/mysql-test/extra/rpl_tests/rpl_truncate.test @@ -9,27 +9,8 @@ --source include/master-slave.inc -let $format = STATEMENT; -let $stmt = TRUNCATE TABLE; +let $trunc_stmt = TRUNCATE TABLE; --source extra/rpl_tests/rpl_truncate_helper.test -let $format = MIXED; -let $stmt = TRUNCATE TABLE; +let $trunc_stmt = DELETE FROM; --source extra/rpl_tests/rpl_truncate_helper.test - -let $format = ROW; -let $stmt = TRUNCATE TABLE; ---source extra/rpl_tests/rpl_truncate_helper.test - -let $format = STATEMENT; -let $stmt = DELETE FROM; ---source extra/rpl_tests/rpl_truncate_helper.test - -let $format = MIXED; -let $stmt = DELETE FROM; ---source extra/rpl_tests/rpl_truncate_helper.test - -let $format = ROW; -let $stmt = DELETE FROM; ---source extra/rpl_tests/rpl_truncate_helper.test - diff --git a/mysql-test/extra/rpl_tests/rpl_truncate_helper.test b/mysql-test/extra/rpl_tests/rpl_truncate_helper.test index eb0729e4921fbce13ef925661043d28d57ce03f7..cd1ce93177a9db0ffa52388444025e27fb5e6792 100644 --- a/mysql-test/extra/rpl_tests/rpl_truncate_helper.test +++ b/mysql-test/extra/rpl_tests/rpl_truncate_helper.test @@ -1,47 +1,35 @@ -connection slave; -STOP SLAVE; -source include/wait_for_slave_to_stop.inc; -connection master; ---disable_warnings -DROP TABLE IF EXISTS t1; ---enable_warnings -connection slave; ---disable_warnings -DROP TABLE IF EXISTS t1; ---enable_warnings -RESET SLAVE; -START SLAVE; +source include/reset_master_and_slave.inc; --echo **** On Master **** connection master; -SET @old_session_binlog_format= @@session.binlog_format; -SET @old_global_binlog_format= @@global.binlog_format; - -eval SET SESSION BINLOG_FORMAT=$format; -eval SET GLOBAL BINLOG_FORMAT=$format; - eval CREATE TABLE t1 (a INT, b LONG) ENGINE=$engine; INSERT INTO t1 VALUES (1,1), (2,2); -SELECT * FROM t1; ---echo **** On Slave **** sync_slave_with_master; -INSERT INTO t1 VALUE (3,3); -SELECT * FROM t1; --echo **** On Master **** connection master; -eval $stmt t1; -SELECT * FROM t1; ---echo **** On Slave **** +eval $trunc_stmt t1; sync_slave_with_master; -# Should be empty -SELECT * FROM t1; + +let $diff_table_1=master:test.t1; +let $diff_table_2=slave:test.t1; +source include/diff_tables.inc; + +--echo ==== Test using a table with delete triggers ==== --echo **** On Master **** connection master; -DROP TABLE t1; -let $SERVER_VERSION=`select version()`; -source include/show_binlog_events.inc; +SET @count := 1; +eval CREATE TABLE t2 (a INT, b LONG) ENGINE=$engine; +CREATE TRIGGER trg1 BEFORE DELETE ON t1 FOR EACH ROW SET @count := @count + 1; +sync_slave_with_master; +--echo **** On Master **** +connection master; +eval $trunc_stmt t1; +sync_slave_with_master; + +let $diff_table_1=master:test.t2; +let $diff_table_2=slave:test.t2; +source include/diff_tables.inc; connection master; -RESET MASTER; -SET @@session.binlog_format= @old_session_binlog_format; -SET @@global.binlog_format= @old_global_binlog_format; +DROP TABLE t1,t2; +sync_slave_with_master; diff --git a/mysql-test/include/setup_fake_relay_log.inc b/mysql-test/include/setup_fake_relay_log.inc index 79ff7429466b3aa2b34e9051b0b11289bbc8d892..f88806e1079671e887230e3624339d24a9ba9698 100644 --- a/mysql-test/include/setup_fake_relay_log.inc +++ b/mysql-test/include/setup_fake_relay_log.inc @@ -69,9 +69,9 @@ let $_fake_relay_log_purge= `SELECT @@global.relay_log_purge`; # Create relay log file. copy_file $fake_relay_log $_fake_relay_log; # Create relay log index. ---exec echo $_fake_relay_log > $_fake_relay_index +--exec echo $_fake_filename-fake.000001 > $_fake_relay_index # Setup replication from existing relay log. -eval CHANGE MASTER TO MASTER_HOST='dummy.localdomain', RELAY_LOG_FILE='$_fake_relay_log', RELAY_LOG_POS=4; +eval CHANGE MASTER TO MASTER_HOST='dummy.localdomain', RELAY_LOG_FILE='$_fake_filename-fake.000001', RELAY_LOG_POS=4; --enable_query_log diff --git a/mysql-test/include/wait_for_query_to_suceed.inc b/mysql-test/include/wait_for_query_to_succeed.inc similarity index 69% rename from mysql-test/include/wait_for_query_to_suceed.inc rename to mysql-test/include/wait_for_query_to_succeed.inc index 6ac1144620e565ec9eb1ca873058df56ec86dcee..12ba5c4d9b81e9b79b0155e2603b3eb3f47b93a8 100644 --- a/mysql-test/include/wait_for_query_to_suceed.inc +++ b/mysql-test/include/wait_for_query_to_succeed.inc @@ -1,5 +1,5 @@ # -# Run a query over and over until it suceeds ot timeout occurs +# Run a query over and over until it succeeds ot timeout occurs # @@ -17,7 +17,7 @@ while ($mysql_errno) if (!$counter) { - die("Waited too long for query to suceed"); + --die "Waited too long for query to succeed"; } } enable_abort_on_error; diff --git a/mysql-test/include/wait_until_count_sessions.inc b/mysql-test/include/wait_until_count_sessions.inc index 36fa9accafe7a7e91fd595ebd845a60529f8095c..41348bee129a3ed6de762a866fb616384ca612ef 100644 --- a/mysql-test/include/wait_until_count_sessions.inc +++ b/mysql-test/include/wait_until_count_sessions.inc @@ -82,7 +82,7 @@ # Created: 2009-01-14 mleich # -let $wait_counter= 50; +let $wait_counter= 100; if ($wait_timeout) { let $wait_counter= `SELECT $wait_timeout * 10`; @@ -108,5 +108,6 @@ if (!$success) { --echo # Timeout in wait_until_count_sessions.inc --echo # Number of sessions expected: $count_sessions found: $current_sessions + SHOW PROCESSLIST; } diff --git a/mysql-test/lib/My/SafeProcess/safe_process_win.cc b/mysql-test/lib/My/SafeProcess/safe_process_win.cc index 640254875c978b44d90afe2c444547e7225ec8d4..4fb89f098ed43a5f8d4eaa009349525043e8e07e 100755 --- a/mysql-test/lib/My/SafeProcess/safe_process_win.cc +++ b/mysql-test/lib/My/SafeProcess/safe_process_win.cc @@ -77,14 +77,29 @@ static void message(const char* fmt, ...) static void die(const char* fmt, ...) { + DWORD last_err= GetLastError(); va_list args; fprintf(stderr, "%s: FATAL ERROR, ", safe_process_name); va_start(args, fmt); vfprintf(stderr, fmt, args); fprintf(stderr, "\n"); va_end(args); - if (int last_err= GetLastError()) - fprintf(stderr, "error: %d, %s\n", last_err, strerror(last_err)); + if (last_err) + { + char *message_text; + if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER + |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, last_err , 0, (LPSTR)&message_text, + 0, NULL)) + { + fprintf(stderr,"error: %d, %s\n",last_err, message_text); + LocalFree(message_text); + } + else + { + /* FormatMessage failed, print error code only */ + fprintf(stderr,"error:%d\n", last_err); + } + } fflush(stderr); exit(1); } diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 511cd4d07ba652a25086311c7a3b7e8b28f23393..50617428d0f3a0d18fb6f2615a569aa78ad1f739 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -45,8 +45,8 @@ BEGIN { print "=======================================================\n"; print " WARNING: Using mysql-test-run.pl version 1! \n"; print "=======================================================\n"; - require "lib/v1/mysql-test-run.pl"; - exit(1); + # Should use exec() here on *nix but this appears not to work on Windows + exit(system($^X, "lib/v1/mysql-test-run.pl", @ARGV) >> 8); } elsif ( $version == 2 ) { @@ -107,6 +107,17 @@ our $default_vardir; our $opt_vardir; # Path to use for var/ dir my $path_vardir_trace; # unix formatted opt_vardir for trace files my $opt_tmpdir; # Path to use for tmp/ dir +my $opt_tmpdir_pid; + +END { + if (defined $opt_tmpdir_pid and + $opt_tmpdir_pid == $$){ + # Remove the tempdir this process has created + mtr_verbose("Removing tmpdir '$opt_tmpdir"); + rmtree($opt_tmpdir); + } +} + my $path_config_file; # The generated config file, var/my.cnf # Visual Studio produces executables in different sub-directories based on the @@ -1066,8 +1077,11 @@ sub command_line_setup { " creating a shorter one..."); # Create temporary directory in standard location for temporary files - $opt_tmpdir= tempdir( TMPDIR => 1, CLEANUP => 1 ); + $opt_tmpdir= tempdir( TMPDIR => 1, CLEANUP => 0 ); mtr_report(" - using tmpdir: '$opt_tmpdir'\n"); + + # Remember pid that created dir so it's removed by correct process + $opt_tmpdir_pid= $$; } } $opt_tmpdir =~ s,/+$,,; # Remove ending slash if any @@ -2860,9 +2874,6 @@ test case was executed:\n"; $result= 2; } - # Remove the .err file the check generated - unlink($err_file); - # Remove the .result file the check generated unlink("$base_file.result"); @@ -3480,6 +3491,7 @@ sub start_check_warnings ($$) { mtr_add_arg($args, "--skip-safemalloc"); mtr_add_arg($args, "--test-file=%s", "include/check-warnings.test"); + mtr_add_arg($args, "--verbose"); if ( $opt_embedded_server ) { @@ -3569,10 +3581,9 @@ sub check_warnings ($) { if ( $res == 62 ) { # Test case was ok and called "skip" - ; + # Remove the .err file the check generated + unlink($err_file); } - # Remove the .err file the check generated - unlink($err_file); if ( keys(%started) == 0){ # All checks completed @@ -3594,8 +3605,6 @@ sub check_warnings ($) { $result= 2; } - # Remove the .err file the check generated - unlink($err_file); } elsif ( $proc eq $timeout_proc ) { $tinfo->{comment}.= "Timeout $timeout_proc for ". @@ -4479,6 +4488,7 @@ sub start_check_testcase ($$$) { mtr_add_arg($args, "--result-file=%s", "$opt_vardir/tmp/$name.result"); mtr_add_arg($args, "--test-file=%s", "include/check-testcase.test"); + mtr_add_arg($args, "--verbose"); if ( $mode eq "before" ) { @@ -4648,8 +4658,7 @@ sub start_mysqltest ($) { elsif ( $opt_client_debugger ) { debugger_arguments(\$args, \$exe, "client"); - } - + } my $proc= My::SafeProcess->new ( diff --git a/mysql-test/r/archive_gis.result b/mysql-test/r/archive_gis.result index 901f8a9acc2f04e956d28362093706b314aca0b3..178c57169110de50b8823310989d2bc579cb9bbb 100644 --- a/mysql-test/r/archive_gis.result +++ b/mysql-test/r/archive_gis.result @@ -292,7 +292,7 @@ Note 1003 select astext(startpoint(`test`.`gis_line`.`g`)) AS `AsText(StartPoint SELECT fid, AsText(Centroid(g)) FROM gis_polygon ORDER by fid; fid AsText(Centroid(g)) 108 POINT(15 15) -109 POINT(25.416666666667 25.416666666667) +109 POINT(25.4166666666667 25.4166666666667) 110 POINT(20 10) SELECT fid, Area(g) FROM gis_polygon ORDER by fid; fid Area(g) @@ -326,8 +326,8 @@ fid IsClosed(g) 116 0 SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon ORDER by fid; fid AsText(Centroid(g)) -117 POINT(55.588527753042 17.426536064114) -118 POINT(55.588527753042 17.426536064114) +117 POINT(55.5885277530424 17.426536064114) +118 POINT(55.5885277530424 17.426536064114) 119 POINT(2 2) SELECT fid, Area(g) FROM gis_multi_polygon ORDER by fid; fid Area(g) diff --git a/mysql-test/r/commit_1innodb.result b/mysql-test/r/commit_1innodb.result index a31a881051f4458a21a2b14da2240a5216eda8e3..de80dba47c10516650ad2dddec5e4ab7164fbbcf 100644 --- a/mysql-test/r/commit_1innodb.result +++ b/mysql-test/r/commit_1innodb.result @@ -687,8 +687,8 @@ SUCCESS truncate table t2; call p_verify_status_increment(4, 0, 4, 0); -SUCCESS - +ERROR +Expected commit increment: 4 actual: 2 commit; # There is nothing left to commit call p_verify_status_increment(0, 0, 0, 0); @@ -854,8 +854,8 @@ SUCCESS truncate table t3; call p_verify_status_increment(4, 4, 4, 4); -SUCCESS - +ERROR +Expected commit increment: 4 actual: 2 create view v1 as select * from t2; call p_verify_status_increment(1, 0, 1, 0); SUCCESS diff --git a/mysql-test/r/fulltext.result b/mysql-test/r/fulltext.result index 8633bd6168131670c03fedd1bd7df1b300356345..a980c7bfa014d0b7ea0c917a7d882b8335a195b7 100644 --- a/mysql-test/r/fulltext.result +++ b/mysql-test/r/fulltext.result @@ -531,3 +531,7 @@ SELECT MATCH(a) AGAINST('aaa1* aaa14 aaa15 aaa16' IN BOOLEAN MODE) FROM t1; MATCH(a) AGAINST('aaa1* aaa14 aaa15 aaa16' IN BOOLEAN MODE) 2 DROP TABLE t1; +CREATE TABLE t1(a TEXT); +SELECT GROUP_CONCAT(a) AS st FROM t1 HAVING MATCH(st) AGAINST('test' IN BOOLEAN MODE); +ERROR HY000: Incorrect arguments to AGAINST +DROP TABLE t1; diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index e0a6c44eb01e6683ee72cfaaa324582f7ef9e44d..3d989ad17301c844c64b3a069c918ec7aae8b26c 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -61,7 +61,7 @@ grp sum NULL NULL 1 7 2 20.25 -3 45.483163247594 +3 45.4831632475944 create table t2 (grp int, a bigint unsigned, c char(10)); insert into t2 select grp,max(a)+max(grp),max(c) from t1 group by grp; replace into t2 select grp, a, c from t1 limit 2,1; @@ -1186,7 +1186,7 @@ std(s1/s2) 0.21325764 select std(o1/o2) from bug22555; std(o1/o2) -0.21325763586649 +0.213257635866493 select std(e1/e2) from bug22555; std(e1/e2) 0.21325764 @@ -1212,7 +1212,7 @@ round(std(s1/s2), 17) 0.21325763586649341 select std(o1/o2) from bug22555; std(o1/o2) -0.21325763586649 +0.213257635866493 select round(std(e1/e2), 17) from bug22555; round(std(e1/e2), 17) 0.21325763586649341 @@ -1237,7 +1237,7 @@ round(std(s1/s2), 17) 0.21325763586649341 select std(o1/o2) from bug22555; std(o1/o2) -0.21325763586649 +0.213257635866493 select round(std(e1/e2), 17) from bug22555; round(std(e1/e2), 17) 0.21325763586649341 diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index b4a07f185213226869a3bb0e0c71ffa4a3354143..74136816a95282b5e5dcfece765d558d7f948a4f 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -60,7 +60,7 @@ Warnings: Note 1003 select ln(exp(10)) AS `ln(exp(10))`,exp((ln(sqrt(10)) * 2)) AS `exp(ln(sqrt(10))*2)`,ln(-(1)) AS `ln(-1)`,ln(0) AS `ln(0)`,ln(NULL) AS `ln(NULL)` select log2(8),log2(15),log2(-2),log2(0),log2(NULL); log2(8) log2(15) log2(-2) log2(0) log2(NULL) -3 3.9068905956085 NULL NULL NULL +3 3.90689059560852 NULL NULL NULL explain extended select log2(8),log2(15),log2(-2),log2(0),log2(NULL); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used @@ -68,7 +68,7 @@ Warnings: Note 1003 select log2(8) AS `log2(8)`,log2(15) AS `log2(15)`,log2(-(2)) AS `log2(-2)`,log2(0) AS `log2(0)`,log2(NULL) AS `log2(NULL)` select log10(100),log10(18),log10(-4),log10(0),log10(NULL); log10(100) log10(18) log10(-4) log10(0) log10(NULL) -2 1.2552725051033 NULL NULL NULL +2 1.25527250510331 NULL NULL NULL explain extended select log10(100),log10(18),log10(-4),log10(0),log10(NULL); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used @@ -85,7 +85,7 @@ Note 1003 select pow(10,log10(10)) AS `pow(10,log10(10))`,pow(2,4) AS `power(2,4 set @@rand_seed1=10000000,@@rand_seed2=1000000; select rand(999999),rand(); rand(999999) rand() -0.014231365187309 0.028870999839968 +0.0142313651873091 0.028870999839968 explain extended select rand(999999),rand(); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used @@ -101,7 +101,7 @@ Warnings: Note 1003 select pi() AS `pi()`,format(sin((pi() / 2)),6) AS `format(sin(pi()/2),6)`,format(cos((pi() / 2)),6) AS `format(cos(pi()/2),6)`,format(abs(tan(pi())),6) AS `format(abs(tan(pi())),6)`,format((1 / tan(1)),6) AS `format(cot(1),6)`,format(asin(1),6) AS `format(asin(1),6)`,format(acos(0),6) AS `format(acos(0),6)`,format(atan(1),6) AS `format(atan(1),6)` select degrees(pi()),radians(360); degrees(pi()) radians(360) -180 6.2831853071796 +180 6.28318530717959 select format(atan(-2, 2), 6); format(atan(-2, 2), 6) -0.785398 @@ -368,7 +368,7 @@ mod(5, cast(-2 as unsigned)) mod(5, 18446744073709551614) mod(5, -2) 5 5 1 select pow(cast(-2 as unsigned), 5), pow(18446744073709551614, 5), pow(-2, 5); pow(cast(-2 as unsigned), 5) pow(18446744073709551614, 5) pow(-2, 5) -2.1359870359209e+96 2.1359870359209e+96 -32 +2.13598703592091e+96 2.13598703592091e+96 -32 CREATE TABLE t1 (a timestamp, b varchar(20), c bit(1)); INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0); SELECT a DIV 900 y FROM t1 GROUP BY y; diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 0824f13cafcf77bc52f56ef08c12016780569b1f..00c98ad136c71ed348cca24e93e55a3373284a86 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -1351,10 +1351,10 @@ cast(rtrim(ltrim(' 20.06 ')) as decimal(19,2)) 20.06 select conv("18383815659218730760",10,10) + 0; conv("18383815659218730760",10,10) + 0 -1.8383815659219e+19 +1.83838156592187e+19 select "18383815659218730760" + 0; "18383815659218730760" + 0 -1.8383815659219e+19 +1.83838156592187e+19 CREATE TABLE t1 (code varchar(10)); INSERT INTO t1 VALUES ('a12'), ('A12'), ('a13'); SELECT ASCII(code), code FROM t1 WHERE code='A12'; @@ -2519,4 +2519,10 @@ def format(a, 2) 253 49 4 Y 0 31 8 format(a, 2) 1.33 drop table t1; +CREATE TABLE t1 (c DATE, aa VARCHAR(30)); +INSERT INTO t1 VALUES ('2008-12-31','aaaaaa'); +SELECT DATE_FORMAT(c, GET_FORMAT(DATE, 'eur')) h, CONCAT(UPPER(aa),', ', aa) i FROM t1; +h i +31.12.2008 AAAAAA, aaaaaa +DROP TABLE t1; End of 5.0 tests diff --git a/mysql-test/r/gis.result b/mysql-test/r/gis.result index fdcde4e8739e72d33d5728b7d1c87dea38598e44..94a5fd83162a087b7f4525be4b96a994fd2c880d 100644 --- a/mysql-test/r/gis.result +++ b/mysql-test/r/gis.result @@ -284,7 +284,7 @@ Note 1003 select astext(startpoint(`test`.`gis_line`.`g`)) AS `AsText(StartPoint SELECT fid, AsText(Centroid(g)) FROM gis_polygon; fid AsText(Centroid(g)) 108 POINT(15 15) -109 POINT(25.416666666667 25.416666666667) +109 POINT(25.4166666666667 25.4166666666667) 110 POINT(20 10) SELECT fid, Area(g) FROM gis_polygon; fid Area(g) @@ -318,8 +318,8 @@ fid IsClosed(g) 116 0 SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon; fid AsText(Centroid(g)) -117 POINT(55.588527753042 17.426536064114) -118 POINT(55.588527753042 17.426536064114) +117 POINT(55.5885277530424 17.426536064114) +118 POINT(55.5885277530424 17.426536064114) 119 POINT(2 2) SELECT fid, Area(g) FROM gis_multi_polygon; fid Area(g) @@ -651,11 +651,11 @@ insert into t1 values ('85984',GeomFromText('MULTIPOLYGON(((-115.006363 select object_id, geometrytype(geo), ISSIMPLE(GEO), ASTEXT(centroid(geo)) from t1 where object_id=85998; object_id geometrytype(geo) ISSIMPLE(GEO) ASTEXT(centroid(geo)) -85998 MULTIPOLYGON 0 POINT(115.31877315203 -36.237472821022) +85998 MULTIPOLYGON 0 POINT(115.318773152032 -36.2374728210215) select object_id, geometrytype(geo), ISSIMPLE(GEO), ASTEXT(centroid(geo)) from t1 where object_id=85984; object_id geometrytype(geo) ISSIMPLE(GEO) ASTEXT(centroid(geo)) -85984 MULTIPOLYGON 0 POINT(-114.87787186923 36.33101763469) +85984 MULTIPOLYGON 0 POINT(-114.877871869233 36.3310176346905) drop table t1; create table t1 (fl geometry not null); insert into t1 values (1); diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result index 18f11ebcc711a4bbadea1fe772bc2eecd0531e61..e7e5e1e716590d24893c698e0fd0ff021b20cfcc 100644 --- a/mysql-test/r/grant.result +++ b/mysql-test/r/grant.result @@ -164,7 +164,7 @@ Warnings: Warning 1364 Field 'ssl_cipher' doesn't have a default value Warning 1364 Field 'x509_issuer' doesn't have a default value Warning 1364 Field 'x509_subject' doesn't have a default value -insert into mysql.db (host, db, user, select_priv) values +insert into mysql.db (host, db, user, select_priv) values ('localhost', 'a%', 'test11', 'Y'), ('localhost', 'ab%', 'test11', 'Y'); alter table mysql.db order by db asc; flush privileges; @@ -264,7 +264,7 @@ drop user mysqltest_1@localhost; SET NAMES koi8r; CREATE DATABASE ÂÄ; USE ÂÄ; -CREATE TABLE ÔÁ (ËÏÌ int); +CREATE TABLE ÔÁ (ËÏÌ INT); GRANT SELECT ON ÂÄ.* TO ÀÚÅÒ@localhost; SHOW GRANTS FOR ÀÚÅÒ@localhost; Grants for ÀÚÅÒ@localhost @@ -383,21 +383,21 @@ grant update (a) on mysqltest_1.t1 to mysqltest_3@localhost; grant select (b) on mysqltest_1.t2 to mysqltest_3@localhost; grant select (c) on mysqltest_2.t1 to mysqltest_3@localhost; grant update (d) on mysqltest_2.t2 to mysqltest_3@localhost; -SELECT * FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES -WHERE GRANTEE = '''mysqltest_3''@''localhost''' -ORDER BY TABLE_NAME,COLUMN_NAME,PRIVILEGE_TYPE; +SELECT * FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES +WHERE GRANTEE = '''mysqltest_3''@''localhost''' + ORDER BY TABLE_NAME,COLUMN_NAME,PRIVILEGE_TYPE; GRANTEE TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME PRIVILEGE_TYPE IS_GRANTABLE 'mysqltest_3'@'localhost' NULL mysqltest_1 t1 a UPDATE NO 'mysqltest_3'@'localhost' NULL mysqltest_2 t1 c SELECT NO 'mysqltest_3'@'localhost' NULL mysqltest_1 t2 b SELECT NO 'mysqltest_3'@'localhost' NULL mysqltest_2 t2 d UPDATE NO SELECT * FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES -WHERE GRANTEE = '''mysqltest_3''@''localhost''' -ORDER BY TABLE_NAME,PRIVILEGE_TYPE; +WHERE GRANTEE = '''mysqltest_3''@''localhost''' + ORDER BY TABLE_NAME,PRIVILEGE_TYPE; GRANTEE TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PRIVILEGE_TYPE IS_GRANTABLE SELECT * from INFORMATION_SCHEMA.SCHEMA_PRIVILEGES -WHERE GRANTEE = '''mysqltest_3''@''localhost''' -ORDER BY TABLE_SCHEMA,PRIVILEGE_TYPE; +WHERE GRANTEE = '''mysqltest_3''@''localhost''' + ORDER BY TABLE_SCHEMA,PRIVILEGE_TYPE; GRANTEE TABLE_CATALOG TABLE_SCHEMA PRIVILEGE_TYPE IS_GRANTABLE SELECT * from INFORMATION_SCHEMA.USER_PRIVILEGES WHERE GRANTEE = '''mysqltest_3''@''localhost''' @@ -884,11 +884,11 @@ flush privileges; drop table t2; drop table t1; CREATE DATABASE mysqltest3; -use mysqltest3; +USE mysqltest3; CREATE TABLE t_nn (c1 INT); CREATE VIEW v_nn AS SELECT * FROM t_nn; CREATE DATABASE mysqltest2; -use mysqltest2; +USE mysqltest2; CREATE TABLE t_nn (c1 INT); CREATE VIEW v_nn AS SELECT * FROM t_nn; CREATE VIEW v_yn AS SELECT * FROM t_nn; @@ -958,7 +958,7 @@ DROP TABLE mysqltest3.t_nn; DROP DATABASE mysqltest3; REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'mysqltest_1'@'localhost'; DROP USER 'mysqltest_1'@'localhost'; -use test; +USE test; create user mysqltest1_thisisreallytoolong; ERROR HY000: String 'mysqltest1_thisisreallytoolong' is too long for user name (should be no longer than 16) CREATE DATABASE mysqltest1; @@ -1196,16 +1196,16 @@ DROP DATABASE mysqltest1; DROP DATABASE mysqltest2; DROP USER mysqltest_1@localhost; DROP USER mysqltest_2@localhost; -use test; +USE test; CREATE TABLE t1 (f1 int, f2 int); INSERT INTO t1 VALUES(1,1), (2,2); CREATE DATABASE db27878; GRANT UPDATE(f1) ON t1 TO 'mysqltest_1'@'localhost'; GRANT SELECT ON `test`.* TO 'mysqltest_1'@'localhost'; GRANT ALL ON db27878.* TO 'mysqltest_1'@'localhost'; -use db27878; +USE db27878; CREATE SQL SECURITY INVOKER VIEW db27878.v1 AS SELECT * FROM test.t1; -use db27878; +USE db27878; UPDATE v1 SET f2 = 4; ERROR HY000: View 'db27878.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them SELECT * FROM test.t1; @@ -1217,7 +1217,7 @@ REVOKE SELECT ON `test`.* FROM 'mysqltest_1'@'localhost'; REVOKE ALL ON db27878.* FROM 'mysqltest_1'@'localhost'; DROP USER mysqltest_1@localhost; DROP DATABASE db27878; -use test; +USE test; DROP TABLE t1; # # Bug#33275 Server crash when creating temporary table mysql.user @@ -1355,6 +1355,6 @@ Warnings: Warning 1403 There is no such grant defined for user 'userbug33464' on host 'localhost' on routine 'fn2' DROP PROCEDURE sp3; DROP USER 'userbug33464'@'localhost'; -use test; +USE test; DROP DATABASE dbbug33464; SET @@global.log_bin_trust_function_creators= @old_log_bin_trust_function_creators; diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index f8deef158192b0044f52217bf8e3bcfab3dde319..5dd0f1594285a7676c231db8190f80486bbc08e6 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -99,7 +99,7 @@ t2 t3 t5 v1 -select c,table_name from v1 +select c,table_name from v1 inner join information_schema.TABLES v2 on (v1.c=v2.table_name) where v1.c like "t%"; c table_name @@ -118,7 +118,7 @@ t4 t4 t2 t2 t3 t3 t5 t5 -select c,table_name from v1 +select c,table_name from v1 left join information_schema.TABLES v2 on (v1.c=v2.table_name) where v1.c like "t%"; c table_name @@ -197,7 +197,7 @@ a int(11) YES NULL create view mysqltest.v1 (c) as select a from mysqltest.t1; grant select (a) on mysqltest.t1 to mysqltest_2@localhost; grant select on mysqltest.v1 to mysqltest_3; -select table_name, column_name, privileges from information_schema.columns +select table_name, column_name, privileges from information_schema.columns where table_schema = 'mysqltest' and table_name = 't1'; table_name column_name privileges t1 a select @@ -275,7 +275,7 @@ begin select * from t1; select * from t2; end| -select parameter_style, sql_data_access, dtd_identifier +select parameter_style, sql_data_access, dtd_identifier from information_schema.routines where routine_schema='test'; parameter_style sql_data_access dtd_identifier SQL CONTAINS SQL NULL @@ -560,7 +560,7 @@ drop view v1; create table t1(a NUMERIC(5,3), b NUMERIC(5,1), c float(5,2), d NUMERIC(6,4), e float, f DECIMAL(6,3), g int(11), h DOUBLE(10,3), i DOUBLE); -select COLUMN_NAME,COLUMN_TYPE, CHARACTER_MAXIMUM_LENGTH, +select COLUMN_NAME,COLUMN_TYPE, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE from information_schema.columns where table_name= 't1'; COLUMN_NAME COLUMN_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE @@ -621,7 +621,7 @@ TABLE_NAME= "vo"; CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION POSITION_IN_UNIQUE_CONSTRAINT REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME drop view vo; select TABLE_NAME,TABLE_TYPE,ENGINE -from information_schema.tables +from information_schema.tables where table_schema='information_schema' limit 2; TABLE_NAME TABLE_TYPE ENGINE CHARACTER_SETS SYSTEM VIEW MEMORY @@ -726,7 +726,7 @@ where table_schema="information_schema" and table_name="COLUMNS" and column_type varchar(32) varchar(32) -select TABLE_ROWS from information_schema.tables where +select TABLE_ROWS from information_schema.tables where table_schema="information_schema" and table_name="COLUMNS"; TABLE_ROWS NULL @@ -760,7 +760,7 @@ count(*) drop view a2, a1; drop table t_crashme; select table_schema,table_name, column_name from -information_schema.columns +information_schema.columns where data_type = 'longtext'; table_schema table_name column_name information_schema COLUMNS COLUMN_DEFAULT @@ -804,7 +804,7 @@ event last_executed datetime event starts datetime event ends datetime SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES A -WHERE NOT EXISTS +WHERE NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS B WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA AND A.TABLE_NAME = B.TABLE_NAME); @@ -833,7 +833,7 @@ x_float NULL NULL x_double_precision NULL NULL drop table t1; grant select on test.* to mysqltest_4@localhost; -SELECT TABLE_NAME, COLUMN_NAME, PRIVILEGES FROM INFORMATION_SCHEMA.COLUMNS +SELECT TABLE_NAME, COLUMN_NAME, PRIVILEGES FROM INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME='TABLE_NAME'; TABLE_NAME COLUMN_NAME PRIVILEGES COLUMNS TABLE_NAME select @@ -1079,7 +1079,7 @@ BEGIN SELECT 'foo' FROM DUAL; END | ERROR 42000: Unknown database 'information_schema' -select ROUTINE_NAME from routines where ROUTINE_SCHEMA='information_schema'; +select ROUTINE_NAME from routines where ROUTINE_SCHEMA='information_schema'; ROUTINE_NAME grant all on information_schema.* to 'user1'@'localhost'; ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema' @@ -1634,7 +1634,7 @@ show events where Db= 'information_schema'; Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation use test; # -# Bug#34166: Server crash in SHOW OPEN TABLES and prelocking +# Bug#34166 Server crash in SHOW OPEN TABLES and prelocking # drop table if exists t1; drop function if exists f1; diff --git a/mysql-test/r/innodb_gis.result b/mysql-test/r/innodb_gis.result index ef8bdcc5f3e79c34e40a45d0ab3c2cd5e853e813..c6c775afc9fd7327aad9beb0949c71e057f9b038 100644 --- a/mysql-test/r/innodb_gis.result +++ b/mysql-test/r/innodb_gis.result @@ -292,7 +292,7 @@ Note 1003 select astext(startpoint(`test`.`gis_line`.`g`)) AS `AsText(StartPoint SELECT fid, AsText(Centroid(g)) FROM gis_polygon ORDER by fid; fid AsText(Centroid(g)) 108 POINT(15 15) -109 POINT(25.416666666667 25.416666666667) +109 POINT(25.4166666666667 25.4166666666667) 110 POINT(20 10) SELECT fid, Area(g) FROM gis_polygon ORDER by fid; fid Area(g) @@ -326,8 +326,8 @@ fid IsClosed(g) 116 0 SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon ORDER by fid; fid AsText(Centroid(g)) -117 POINT(55.588527753042 17.426536064114) -118 POINT(55.588527753042 17.426536064114) +117 POINT(55.5885277530424 17.426536064114) +118 POINT(55.5885277530424 17.426536064114) 119 POINT(2 2) SELECT fid, Area(g) FROM gis_multi_polygon ORDER by fid; fid Area(g) diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result index 9ab982a6688c79925ea0fe5905400cb76b261fc4..3910536ee5d86c7139b2c2ca4d50a43e86e00bf1 100644 --- a/mysql-test/r/merge.result +++ b/mysql-test/r/merge.result @@ -2025,7 +2025,6 @@ TABLE_SCHEMA = 'test' and TABLE_NAME='tm1'; TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE VERSION ROW_FORMAT TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CREATE_TIME UPDATE_TIME CHECK_TIME TABLE_COLLATION CHECKSUM CREATE_OPTIONS TABLE_COMMENT NULL test tm1 BASE TABLE NULL NULL NULL # # # # # # # # # # NULL # # Unable to open underlying table which is differently defined or of non-MyISAM ty DROP TABLE tm1; -End of 5.1 tests CREATE TABLE t1(C1 INT, C2 INT, KEY C1(C1), KEY C2(C2)) ENGINE=MYISAM; CREATE TABLE t2(C1 INT, C2 INT, KEY C1(C1), KEY C2(C2)) ENGINE=MYISAM; CREATE TABLE t3(C1 INT, C2 INT, KEY C1(C1), KEY C2(C2)) ENGINE=MYISAM; @@ -2041,4 +2040,67 @@ EXPLAIN SELECT COUNT(*) FROM t4; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away DROP TABLE t1, t2, t3, t4; +CREATE TABLE t1(a INT, KEY(a)); +INSERT INTO t1 VALUES(0),(1),(2),(3),(4); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +CREATE TABLE m1(a INT, KEY(a)) ENGINE=MERGE UNION=(t1); +SELECT CARDINALITY FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA='test' AND TABLE_NAME='m1'; +CARDINALITY +5 +SELECT CARDINALITY FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA='test' AND TABLE_NAME='m1'; +CARDINALITY +5 +SELECT CARDINALITY FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA='test' AND TABLE_NAME='m1'; +CARDINALITY +5 +SELECT CARDINALITY FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA='test' AND TABLE_NAME='m1'; +CARDINALITY +5 +DROP TABLE t1, m1; +# +# Bug #40675 MySQL 5.1 crash with index merge algorithm and Merge tables +# +# create MYISAM table t1 and insert values into it +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES(1); +# create MYISAM table t2 and insert values into it +CREATE TABLE t2(a INT, b INT, dummy CHAR(16) DEFAULT '', KEY(a), KEY(b)); +INSERT INTO t2(a,b) VALUES +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(1,2); +# Create the merge table t3 +CREATE TABLE t3(a INT, b INT, dummy CHAR(16) DEFAULT '', KEY(a), KEY(b)) +ENGINE=MERGE UNION=(t2) INSERT_METHOD=FIRST; +# Lock tables t1 and t3 for write +LOCK TABLES t1 WRITE, t3 WRITE; +# Insert values into the merge table t3 +INSERT INTO t3(a,b) VALUES(1,2); +# select from the join of t2 and t3 (The merge table) +SELECT t3.a FROM t1,t3 WHERE t3.b=2 AND t3.a=1; +a +1 +1 +# Unlock the tables +UNLOCK TABLES; +# drop the created tables +DROP TABLE t1, t2, t3; End of 5.1 tests diff --git a/mysql-test/r/multi_update.result b/mysql-test/r/multi_update.result index b8f6aa9e4d4c3286804892846495a6712df6c81d..449333a4ae6a83b859bff93b041372d0b1226c8d 100644 --- a/mysql-test/r/multi_update.result +++ b/mysql-test/r/multi_update.result @@ -375,7 +375,7 @@ update t2, t1 set t2.field=t1.field where t1.id1=t2.id2 and 0=1; delete t1, t2 from t2 inner join t1 on t1.id1=t2.id2 where 0=1; -delete t1, t2 from t2,t1 +delete t1, t2 from t2,t1 where t1.id1=t2.id2 and 0=1; drop table t1,t2; CREATE TABLE t1 ( a int ); @@ -443,12 +443,12 @@ delete t1 from t1,t2 where t1.col1 < (select max(col1) from t1) and t1.col1 = t2 ERROR HY000: You can't specify target table 't1' for update in FROM clause drop table t1,t2; create table t1 ( -aclid bigint not null primary key, -status tinyint(1) not null +aclid bigint not null primary key, +status tinyint(1) not null ) engine = innodb; create table t2 ( -refid bigint not null primary key, -aclid bigint, index idx_acl(aclid) +refid bigint not null primary key, +aclid bigint, index idx_acl(aclid) ) engine = innodb; insert into t2 values(1,null); delete t2, t1 from t2 left join t1 on (t2.aclid=t1.aclid) where t2.refid='1'; diff --git a/mysql-test/r/mysqlbinlog_row_trans.result b/mysql-test/r/mysqlbinlog_row_trans.result index 9c3348a9e7669a22ad7b0312ab49fe575b8a3fcd..d0180e4a7a370380a06754689fa97ff82839a0a0 100644 --- a/mysql-test/r/mysqlbinlog_row_trans.result +++ b/mysql-test/r/mysqlbinlog_row_trans.result @@ -215,30 +215,14 @@ COMMIT/*!*/; # at # #010909 4:46:40 server id 1 end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; -BEGIN -/*!*/; -# at # -#010909 4:46:40 server id 1 end_log_pos # Query thread_id=# exec_time=# error_code=0 -SET TIMESTAMP=1000000000/*!*/; TRUNCATE TABLE t1 /*!*/; # at # -#010909 4:46:40 server id 1 end_log_pos # Xid = # -COMMIT/*!*/; -# at # -#010909 4:46:40 server id 1 end_log_pos # Query thread_id=# exec_time=# error_code=0 -SET TIMESTAMP=1000000000/*!*/; -BEGIN -/*!*/; -# at # #010909 4:46:40 server id 1 end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; TRUNCATE TABLE t1 /*!*/; # at # -#010909 4:46:40 server id 1 end_log_pos # Xid = # -COMMIT/*!*/; -# at # #010909 4:46:40 server id 1 end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; BEGIN @@ -347,17 +331,9 @@ COMMIT/*!*/; # at # #010909 4:46:40 server id 1 end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; -BEGIN -/*!*/; -# at # -#010909 4:46:40 server id 1 end_log_pos # Query thread_id=# exec_time=# error_code=0 -SET TIMESTAMP=1000000000/*!*/; TRUNCATE TABLE t1 /*!*/; # at # -#010909 4:46:40 server id 1 end_log_pos # Xid = # -COMMIT/*!*/; -# at # #010909 4:46:40 server id 1 end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; TRUNCATE TABLE t2 @@ -473,17 +449,9 @@ ROLLBACK # at # #010909 4:46:40 server id 1 end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; -BEGIN -/*!*/; -# at # -#010909 4:46:40 server id 1 end_log_pos # Query thread_id=# exec_time=# error_code=0 -SET TIMESTAMP=1000000000/*!*/; TRUNCATE TABLE t1 /*!*/; # at # -#010909 4:46:40 server id 1 end_log_pos # Xid = # -COMMIT/*!*/; -# at # #010909 4:46:40 server id 1 end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; TRUNCATE TABLE t2 diff --git a/mysql-test/r/packet.result b/mysql-test/r/packet.result index fa2fb33d278013a26ed81c30adf8e28f5c9521ea..ecbb47d4ee08a5d1699250b8399f8d7524a8434a 100644 --- a/mysql-test/r/packet.result +++ b/mysql-test/r/packet.result @@ -1,3 +1,5 @@ +set @max_allowed_packet=@@global.max_allowed_packet; +set @net_buffer_length=@@global.net_buffer_length; set global max_allowed_packet=100; Warnings: Warning 1292 Truncated incorrect max_allowed_packet value: '100' @@ -23,3 +25,5 @@ len select length(repeat('a',2000)); length(repeat('a',2000)) 2000 +set global max_allowed_packet=@max_allowed_packet; +set global net_buffer_length=@net_buffer_length; diff --git a/mysql-test/r/query_cache_notembedded.result b/mysql-test/r/query_cache_notembedded.result index 64bb40f1d1779934f7ce7e9a9a8d83e8f2431d14..d9bf7a6d81468822ddf013d63dd8c868f3855f5b 100644 --- a/mysql-test/r/query_cache_notembedded.result +++ b/mysql-test/r/query_cache_notembedded.result @@ -375,6 +375,7 @@ id show status like 'Qcache_queries_in_cache'; Variable_name Value Qcache_queries_in_cache 1 +USE test; DROP DATABASE bug30269; DROP USER 'bug30269'@'localhost'; set GLOBAL query_cache_type=default; diff --git a/mysql-test/r/read_only.result b/mysql-test/r/read_only.result index cf81566f4e585820383edc9e0a0c81dcbf1ef29c..558e0356c5a5030d278343b4e11e72eb49ce63c0 100644 --- a/mysql-test/r/read_only.result +++ b/mysql-test/r/read_only.result @@ -1,12 +1,18 @@ +set @start_read_only= @@global.read_only; DROP TABLE IF EXISTS t1,t2,t3; grant CREATE, SELECT, DROP on *.* to test@localhost; +connect (con1,localhost,test,,test); +connection default; set global read_only=0; +connection con1; create table t1 (a int); insert into t1 values(1); create table t2 select * from t1; +connection default; set global read_only=1; create table t3 (a int); drop table t3; +connection con1; select @@global.read_only; @@global.read_only 1 @@ -39,13 +45,18 @@ delete t1 from t1,t3 where t1.a=t3.a; drop table t1; insert into t1 values(1); ERROR HY000: The MySQL server is running with the --read-only option so it cannot execute this statement +connection default; set global read_only=0; lock table t1 write; +connection con1; lock table t2 write; +connection default; set global read_only=1; ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction unlock tables ; +send set global read_only=1; set global read_only=1; +connection con1; select @@global.read_only; @@global.read_only 0 @@ -53,13 +64,20 @@ unlock tables ; select @@global.read_only; @@global.read_only 1 +connection default; +reap; +connection default; set global read_only=0; lock table t1 read; +connection con1; lock table t2 read; +connection default; set global read_only=1; ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction unlock tables ; +send set global read_only=1; set global read_only=1; +connection con1; select @@global.read_only; @@global.read_only 0 @@ -67,24 +85,35 @@ unlock tables ; select @@global.read_only; @@global.read_only 1 +connection default; +reap; +connection default; set global read_only=0; BEGIN; +connection con1; BEGIN; +connection default; set global read_only=1; ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction ROLLBACK; set global read_only=1; +connection con1; select @@global.read_only; @@global.read_only 1 ROLLBACK; +connection default; set global read_only=0; flush tables with read lock; set global read_only=1; unlock tables; +connect (root2,localhost,root,,test); +connection default; set global read_only=0; flush tables with read lock; +connection root2; set global read_only=1; +connection default; select @@global.read_only; @@global.read_only 1 @@ -94,6 +123,7 @@ ERROR 42S02: Unknown table 'ttt' drop temporary table if exists ttt; Warnings: Note 1051 Unknown table 'ttt' +connection default; set global read_only=0; drop table t1,t2; drop user test@localhost; @@ -112,16 +142,20 @@ grant all on mysqltest_db2.* to `mysqltest_u1`@`%`; create database mysqltest_db1; grant all on mysqltest_db1.* to `mysqltest_u1`@`%`; flush privileges; +connect (con_bug27440,127.0.0.1,mysqltest_u1,,test,MASTER_MYPORT,); +connection con_bug27440; create database mysqltest_db2; ERROR HY000: The MySQL server is running with the --read-only option so it cannot execute this statement show databases like '%mysqltest_db2%'; Database (%mysqltest_db2%) drop database mysqltest_db1; ERROR HY000: The MySQL server is running with the --read-only option so it cannot execute this statement +disconnect con_bug27440; +connection default; delete from mysql.user where User like 'mysqltest_%'; delete from mysql.db where User like 'mysqltest_%'; delete from mysql.tables_priv where User like 'mysqltest_%'; delete from mysql.columns_priv where User like 'mysqltest_%'; flush privileges; drop database mysqltest_db1; -set global read_only=0; +set global read_only= @start_read_only; diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 0519489b7155980d65806622b198b6be843376b3..621c11906cb6a5a3daba553736921c3237963997 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2784,26 +2784,26 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away select max(key1) from t1 where key1 <= 0.6158; max(key1) -0.61580002307892 +0.615800023078918 select max(key2) from t2 where key2 <= 1.6158; max(key2) -1.6158000230789 +1.61580002307892 select min(key1) from t1 where key1 >= 0.3762; min(key1) -0.37619999051094 +0.376199990510941 select min(key2) from t2 where key2 >= 1.3762; min(key2) -1.3761999607086 +1.37619996070862 select max(key1), min(key2) from t1, t2 where key1 <= 0.6158 and key2 >= 1.3762; max(key1) min(key2) -0.61580002307892 1.3761999607086 +0.615800023078918 1.37619996070862 select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; max(key1) -0.61580002307892 +0.615800023078918 select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; min(key1) -0.37619999051094 +0.376199990510941 DROP TABLE t1,t2; CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL); INSERT INTO t1 VALUES (10); diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 01ddde564503339353e9c43dc4788a22e9c24db6..cf4eac563ad1ec1ea393989a6f6b0f4fc8d8ef02 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -581,7 +581,7 @@ return 2.7182818284590452354| set @e = e()| select e(), @e| e() @e -2.718281828459 2.718281828459 +2.71828182845905 2.71828182845905 drop function if exists inc| create function inc(i int) returns int return i+1| @@ -618,7 +618,7 @@ create function fun(d double, i int, u int unsigned) returns double return mul(inc(i), fac(u)) / e()| select fun(2.3, 3, 5)| fun(2.3, 3, 5) -176.58213176229 +176.582131762292 insert into t2 values (append("xxx", "yyy"), mul(4,3), e())| insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6))| select * from t2 where s = append("a", "b")| @@ -6018,9 +6018,9 @@ CREATE TABLE t3 (f1 INT, f2 FLOAT)| INSERT INTO t3 VALUES (1, 3.4), (1, 2), (1, 0.9), (2, 8), (2, 7)| SELECT SUM(f2), bug25373(f1) FROM t3 GROUP BY bug25373(f1) WITH ROLLUP| SUM(f2) bug25373(f1) -6.3000000715256 1 +6.30000007152557 1 15 2 -21.300000071526 NULL +21.3000000715256 NULL DROP FUNCTION bug25373| DROP TABLE t3| DROP DATABASE IF EXISTS mysqltest1| diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index aff26454b2d902c551bfecaae310d9a08de3de2c..7f6ebb14c3e305a9bba2587cc80de928e94eabb3 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -192,11 +192,11 @@ select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2; (select a from t3 where a<t2.a*4 order by 1 desc limit 1) a 3 1 7 2 -select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from +select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from (select * from t2 where a>1) as tt; (select t3.a from t3 where a<8 order by 1 desc limit 1) a 7 2 -explain extended select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from +explain extended select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from (select * from t2 where a>1) as tt; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY <derived3> system NULL NULL NULL NULL 1 100.00 @@ -2303,20 +2303,20 @@ drop table t1,t2; CREATE TABLE t1 ( a int, b int ); CREATE TABLE t2 ( c int, d int ); INSERT INTO t1 VALUES (1,2), (2,3), (3,4); -SELECT a AS abc, b FROM t1 outr WHERE b = +SELECT a AS abc, b FROM t1 outr WHERE b = (SELECT MIN(b) FROM t1 WHERE a=outr.a); abc b 1 2 2 3 3 4 -INSERT INTO t2 SELECT a AS abc, b FROM t1 outr WHERE b = +INSERT INTO t2 SELECT a AS abc, b FROM t1 outr WHERE b = (SELECT MIN(b) FROM t1 WHERE a=outr.a); select * from t2; c d 1 2 2 3 3 4 -CREATE TABLE t3 SELECT a AS abc, b FROM t1 outr WHERE b = +CREATE TABLE t3 SELECT a AS abc, b FROM t1 outr WHERE b = (SELECT MIN(b) FROM t1 WHERE a=outr.a); select * from t3; abc b @@ -2517,8 +2517,8 @@ INSERT INTO t1 VALUES ('ASM','American Samoa','Oceania','Polynesia',199.00,0,680 INSERT INTO t1 VALUES ('ATF','French Southern territories','Antarctica','Antarctica',7780.00,0,0,NULL,0.00,NULL,'Terres australes françaises','Nonmetropolitan Territory of France','Jacques Chirac',NULL,'TF'); INSERT INTO t1 VALUES ('UMI','United States Minor Outlying Islands','Oceania','Micronesia/Caribbean',16.00,0,0,NULL,0.00,NULL,'United States Minor Outlying Islands','Dependent Territory of the US','George W. Bush',NULL,'UM'); /*!40000 ALTER TABLE t1 ENABLE KEYS */; -SELECT DISTINCT Continent AS c FROM t1 outr WHERE -Code <> SOME ( SELECT Code FROM t1 WHERE Continent = outr.Continent AND +SELECT DISTINCT Continent AS c FROM t1 outr WHERE +Code <> SOME ( SELECT Code FROM t1 WHERE Continent = outr.Continent AND Population < 200); c Oceania @@ -2628,32 +2628,32 @@ select count(distinct t2.userid) pass, groupstuff.*, count(t2.courseid) crse, -t1.categoryid, +t1.categoryid, t2.courseid, date_format(date, '%b%y') as colhead -from t2 -join t1 on t2.courseid=t1.courseid +from t2 +join t1 on t2.courseid=t1.courseid join ( -select -t5.userid, -parentid, -parentgroup, -childid, -groupname, -grouptypeid -from t5 -join +select +t5.userid, +parentid, +parentgroup, +childid, +groupname, +grouptypeid +from t5 +join ( -select t4.id as parentid, -t4.name as parentgroup, -t4.id as childid, -t4.name as groupname, -t4.grouptypeid -from t4 -) as gin on t5.groupid=gin.childid -) as groupstuff on t2.userid = groupstuff.userid -group by +select t4.id as parentid, +t4.name as parentgroup, +t4.id as childid, +t4.name as groupname, +t4.grouptypeid +from t4 +) as gin on t5.groupid=gin.childid +) as groupstuff on t2.userid = groupstuff.userid +group by groupstuff.groupname, colhead , t2.courseid; pass userid parentid parentgroup childid groupname grouptypeid crse categoryid courseid colhead 1 5141 12 group2 12 group2 5 1 5 12 Aug04 @@ -2929,9 +2929,9 @@ INSERT INTO t1 VALUES("0037", "1", "2005-12-06 12:18:56"); INSERT INTO t1 VALUES("0037", "2", "2006-01-06 12:25:53"); INSERT INTO t1 VALUES("0048", "1", "2006-01-06 12:37:50"); INSERT INTO t1 VALUES("0059", "1", "2006-01-06 12:37:50"); -select * from t1 r1 -where (r1.retailerID,(r1.changed)) in -(SELECT r2.retailerId,(max(changed)) from t1 r2 +select * from t1 r1 +where (r1.retailerID,(r1.changed)) in +(SELECT r2.retailerId,(max(changed)) from t1 r2 group by r2.retailerId); retailerID statusID changed 0026 2 2006-01-06 12:25:53 @@ -2943,41 +2943,41 @@ create table t1(a int, primary key (a)); insert into t1 values (10); create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)); insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989'); -explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r -ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' -ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; +explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r +ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' + ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using where -SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r -ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' -ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; +SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r +ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' + ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; a a b 10 3 35989 -explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r -ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' -ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; +explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r +ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' + ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 2 DEPENDENT SUBQUERY t2 range b b 40 NULL 2 Using where -SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r -ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' -ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; +SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r +ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' + ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; a a b 10 1 359 drop table t1,t2; -CREATE TABLE t1 ( -field1 int NOT NULL, -field2 int NOT NULL, -field3 int NOT NULL, -PRIMARY KEY (field1,field2,field3) +CREATE TABLE t1 ( +field1 int NOT NULL, +field2 int NOT NULL, +field3 int NOT NULL, +PRIMARY KEY (field1,field2,field3) ); -CREATE TABLE t2 ( -fieldA int NOT NULL, -fieldB int NOT NULL, -PRIMARY KEY (fieldA,fieldB) +CREATE TABLE t2 ( +fieldA int NOT NULL, +fieldB int NOT NULL, +PRIMARY KEY (fieldA,fieldB) ); INSERT INTO t1 VALUES (1,1,1), (1,1,2), (1,2,1), (1,2,2), (1,2,3), (1,3,1); @@ -2991,14 +2991,14 @@ field1 field2 COUNT(*) SELECT field1, field2 FROM t1 GROUP BY field1, field2 -HAVING COUNT(*) >= ALL (SELECT fieldB +HAVING COUNT(*) >= ALL (SELECT fieldB FROM t2 WHERE fieldA = field1); field1 field2 1 2 SELECT field1, field2 FROM t1 GROUP BY field1, field2 -HAVING COUNT(*) < ANY (SELECT fieldB +HAVING COUNT(*) < ANY (SELECT fieldB FROM t2 WHERE fieldA = field1); field1 field2 1 1 @@ -3021,8 +3021,8 @@ a a IN (SELECT a FROM t1) DROP TABLE t1,t2; CREATE TABLE t1 (a DATETIME); INSERT INTO t1 VALUES ('1998-09-23'), ('2003-03-25'); -CREATE TABLE t2 AS SELECT -(SELECT a FROM t1 WHERE a < '2000-01-01') AS sub_a +CREATE TABLE t2 AS SELECT +(SELECT a FROM t1 WHERE a < '2000-01-01') AS sub_a FROM t1 WHERE a > '2000-01-01'; SHOW CREATE TABLE t2; Table Create Table @@ -3188,7 +3188,7 @@ INSERT INTO t2 VALUES ( 6 ); CREATE TABLE t3 ( c3 integer ); INSERT INTO t3 VALUES ( 7 ); INSERT INTO t3 VALUES ( 8 ); -SELECT c1,c2 FROM t1 LEFT JOIN t2 ON c1 = c2 +SELECT c1,c2 FROM t1 LEFT JOIN t2 ON c1 = c2 WHERE EXISTS (SELECT c3 FROM t3 WHERE c2 IS NULL ); c1 c2 2 NULL @@ -3231,20 +3231,20 @@ E1 DROP TABLE t1,t2; CREATE TABLE t1(select_id BIGINT, values_id BIGINT); INSERT INTO t1 VALUES (1, 1); -CREATE TABLE t2 (select_id BIGINT, values_id BIGINT, +CREATE TABLE t2 (select_id BIGINT, values_id BIGINT, PRIMARY KEY(select_id,values_id)); INSERT INTO t2 VALUES (0, 1), (0, 2), (0, 3), (1, 5); -SELECT values_id FROM t1 +SELECT values_id FROM t1 WHERE values_id IN (SELECT values_id FROM t2 WHERE select_id IN (1, 0)); values_id 1 -SELECT values_id FROM t1 +SELECT values_id FROM t1 WHERE values_id IN (SELECT values_id FROM t2 WHERE select_id BETWEEN 0 AND 1); values_id 1 -SELECT values_id FROM t1 +SELECT values_id FROM t1 WHERE values_id IN (SELECT values_id FROM t2 WHERE select_id = 0 OR select_id = 1); values_id @@ -3259,7 +3259,7 @@ drop table t1; CREATE TABLE t1 (a int, b int); CREATE TABLE t2 (c int, d int); CREATE TABLE t3 (e int); -INSERT INTO t1 VALUES +INSERT INTO t1 VALUES (1,10), (2,10), (1,20), (2,20), (3,20), (2,30), (4,40); INSERT INTO t2 VALUES (2,10), (2,20), (4,10), (5,10), (3,20), (2,40); @@ -3322,7 +3322,7 @@ a 2 SELECT a FROM t1 GROUP BY a HAVING a IN (SELECT c FROM t2 -WHERE MIN(b) < d AND +WHERE MIN(b) < d AND EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d)); a 2 @@ -3373,7 +3373,7 @@ a 4 SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > ALL(SELECT t2.c FROM t2 -WHERE EXISTS(SELECT t3.e FROM t3 +WHERE EXISTS(SELECT t3.e FROM t3 WHERE SUM(t1.a+t2.c) < t3.e/4)); ERROR HY000: Invalid use of group function SELECT t1.a from t1 GROUP BY t1.a HAVING AVG(SUM(t1.b)) > 20; @@ -3486,7 +3486,7 @@ mid bigint(20) unsigned NOT NULL, date date NOT NULL, PRIMARY KEY (id) ); -INSERT INTO t2 VALUES +INSERT INTO t2 VALUES (1, 1, '2006-03-30'), (2, 2, '2006-04-06'), (3, 3, '2006-04-13'), (4, 2, '2006-04-20'), (5, 1, '2006-05-01'); SELECT *, @@ -3524,7 +3524,7 @@ i2 int(11) NOT NULL default '0', t datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (i1,i2,t) ); -INSERT INTO t1 VALUES +INSERT INTO t1 VALUES (24,1,'2005-03-03 16:31:31'),(24,1,'2005-05-27 12:40:07'), (24,1,'2005-05-27 12:40:08'),(24,1,'2005-05-27 12:40:10'), (24,1,'2005-05-27 12:40:25'),(24,1,'2005-05-27 12:40:30'), @@ -3540,7 +3540,7 @@ PRIMARY KEY (i1) INSERT INTO t2 VALUES (24,1,'2006-06-20 12:29:40'); EXPLAIN SELECT * FROM t1,t2 -WHERE t1.t = (SELECT t1.t FROM t1 +WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 ORDER BY t1.t DESC LIMIT 1); id select_type table type possible_keys key key_len ref rows Extra @@ -3548,7 +3548,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index 2 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index SELECT * FROM t1,t2 -WHERE t1.t = (SELECT t1.t FROM t1 +WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 ORDER BY t1.t DESC LIMIT 1); i1 i2 t i1 i2 t @@ -3557,22 +3557,22 @@ DROP TABLE t1, t2; CREATE TABLE t1 (i INT); (SELECT i FROM t1) UNION (SELECT i FROM t1); i -SELECT sql_no_cache * FROM t1 WHERE NOT EXISTS +SELECT sql_no_cache * FROM t1 WHERE NOT EXISTS ( -(SELECT i FROM t1) UNION +(SELECT i FROM t1) UNION (SELECT i FROM t1) ); -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION (SELECT i FROM t1) )' at line 3 -SELECT * FROM t1 +SELECT * FROM t1 WHERE NOT EXISTS (((SELECT i FROM t1) UNION (SELECT i FROM t1))); ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION (SELECT i FROM t1)))' at line 2 explain select ((select t11.i from t1 t11) union (select t12.i from t1 t12)) from t1; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'union (select t12.i from t1 t12)) from t1' at line 1 -explain select * from t1 where not exists +explain select * from t1 where not exists ((select t11.i from t1 t11) union (select t12.i from t1 t12)); ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'union (select t12.i from t1 t12))' at line 2 DROP TABLE t1; @@ -3591,9 +3591,9 @@ insert into t1 (a) select FLOOR(rand() * 100) from t1; insert into t1 (a) select FLOOR(rand() * 100) from t1; insert into t1 (a) select FLOOR(rand() * 100) from t1; insert into t1 (a) select FLOOR(rand() * 100) from t1; -SELECT a, -(SELECT REPEAT(' ',250) FROM t1 i1 -WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a +SELECT a, +(SELECT REPEAT(' ',250) FROM t1 i1 +WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a FROM t1 ORDER BY a LIMIT 5; a a 0 NULL @@ -3622,7 +3622,7 @@ COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b)) 2 2 1 1 1 1 -SELECT COUNT(DISTINCT t1.b), +SELECT COUNT(DISTINCT t1.b), (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) FROM t1 GROUP BY t1.a; COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) @@ -3633,7 +3633,7 @@ SELECT ( SELECT ( SELECT COUNT(DISTINCT t1.b) ) -) +) FROM t1 GROUP BY t1.a; ( SELECT ( @@ -3648,8 +3648,8 @@ SELECT ( SELECT ( SELECT COUNT(DISTINCT t1.b) ) -) -FROM t1 GROUP BY t1.a LIMIT 1) +) +FROM t1 GROUP BY t1.a LIMIT 1) FROM t1 t2 GROUP BY t2.a; ( @@ -3657,7 +3657,7 @@ SELECT ( SELECT ( SELECT COUNT(DISTINCT t1.b) ) -) +) FROM t1 GROUP BY t1.a LIMIT 1) 2 2 @@ -3669,13 +3669,13 @@ PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b)); SET SESSION sort_buffer_size = 32 * 1024; Warnings: Warning 1292 Truncated incorrect sort_buffer_size value: '32768' -SELECT SQL_NO_CACHE COUNT(*) +SELECT SQL_NO_CACHE COUNT(*) FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c FROM t1) t; COUNT(*) 3000 SET SESSION sort_buffer_size = 8 * 1024 * 1024; -SELECT SQL_NO_CACHE COUNT(*) +SELECT SQL_NO_CACHE COUNT(*) FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c FROM t1) t; COUNT(*) @@ -3736,7 +3736,7 @@ sq 2 4 DEALLOCATE PREPARE stmt1; -SELECT f2, AVG(f21), +SELECT f2, AVG(f21), (SELECT t.f3 FROM t2 AS t WHERE t2.f2=t.f2 AND t.f3=MAX(t2.f3)) AS test FROM t2 GROUP BY f2; f2 AVG(f21) test @@ -3744,12 +3744,12 @@ f2 AVG(f21) test 2 2.0000 2004-02-29 11:11:11 DROP TABLE t1,t2; CREATE TABLE t1 (a int, b INT, c CHAR(10) NOT NULL); -INSERT INTO t1 VALUES -(1,1,'a'), (1,2,'b'), (1,3,'c'), (1,4,'d'), (1,5,'e'), -(2,1,'f'), (2,2,'g'), (2,3,'h'), (3,4,'i'), (3,3,'j'), +INSERT INTO t1 VALUES +(1,1,'a'), (1,2,'b'), (1,3,'c'), (1,4,'d'), (1,5,'e'), +(2,1,'f'), (2,2,'g'), (2,3,'h'), (3,4,'i'), (3,3,'j'), (3,2,'k'), (3,1,'l'), (1,9,'m'); -SELECT a, MAX(b), -(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b)) AS test +SELECT a, MAX(b), +(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b)) AS test FROM t1 GROUP BY a; a MAX(b) test 1 9 m @@ -3900,7 +3900,7 @@ COUNT(*) a (SELECT MIN(m) FROM t2 WHERE m = count(*)) 2 2 2 3 3 3 1 4 1 -SELECT COUNT(*), a +SELECT COUNT(*), a FROM t1 GROUP BY a HAVING (SELECT MIN(m) FROM t2 WHERE m = count(*)) > 1; COUNT(*) a @@ -3931,7 +3931,7 @@ INSERT INTO t1 VALUES (1,1,0,'a'), (1,2,0,'b'), (1,3,0,'c'), (1,4,0,'d'), (1,5,0,'e'), (2,1,0,'f'), (2,2,0,'g'), (2,3,0,'h'), (3,4,0,'i'), (3,3,0,'j'), (3,2,0,'k'), (3,1,0,'l'), (1,9,0,'m'), (1,0,10,'n'), (2,0,5,'o'), (3,0,7,'p'); SELECT a, MAX(b), -(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b + 0)) as test +(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b + 0)) as test FROM t1 GROUP BY a; a MAX(b) test 1 9 m @@ -3953,7 +3953,7 @@ a AVG(b) test 3 2.5000 NULL SELECT tt.a, (SELECT (SELECT c FROM t1 as t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a) -LIMIT 1) FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test +LIMIT 1) FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test FROM t1 as tt; a test 1 n @@ -3975,7 +3975,7 @@ a test SELECT tt.a, (SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a) LIMIT 1) -FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test +FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test FROM t1 as tt GROUP BY tt.a; a test 1 n @@ -3984,7 +3984,7 @@ a test SELECT tt.a, MAX( (SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a) LIMIT 1) -FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1)) as test +FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1)) as test FROM t1 as tt GROUP BY tt.a; a test 1 n @@ -4027,11 +4027,11 @@ COUNT(1) 1 SELECT SUM( (SELECT AVG( (SELECT t1.a FROM t2) ) FROM DUAL) ) FROM t1; ERROR HY000: Invalid use of group function -SELECT +SELECT SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING t1.a < 12) ) FROM t2) ) FROM t1; ERROR HY000: Invalid use of group function -SELECT t1.a as XXA, +SELECT t1.a as XXA, SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING XXA < 12) ) FROM t2) ) FROM t1; ERROR HY000: Invalid use of group function @@ -4048,25 +4048,25 @@ INSERT INTO t1 VALUES (3,'FL'), (2,'GA'), (4,'FL'), (1,'GA'), (5,'NY'), (7,'FL'), (6,'NY'); CREATE TABLE t2 (id int NOT NULL, INDEX idx(id)); INSERT INTO t2 VALUES (7), (5), (1), (3); -SELECT id, st FROM t1 +SELECT id, st FROM t1 WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id); id st 3 FL 1 GA 7 FL -SELECT id, st FROM t1 +SELECT id, st FROM t1 WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id) GROUP BY id; id st 1 GA 3 FL 7 FL -SELECT id, st FROM t1 +SELECT id, st FROM t1 WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id); id st 2 GA 4 FL -SELECT id, st FROM t1 +SELECT id, st FROM t1 WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id) GROUP BY id; id st @@ -4237,7 +4237,7 @@ a b DROP TABLE t1,t2; CREATE TABLE t1(a INT, b INT); INSERT INTO t1 VALUES (1,1), (1,2), (2,3), (2,4); -EXPLAIN +EXPLAIN SELECT a AS out_a, MIN(b) FROM t1 WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a) GROUP BY a; @@ -4246,7 +4246,7 @@ SELECT a AS out_a, MIN(b) FROM t1 WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a) GROUP BY a; ERROR 42S22: Unknown column 'out_a' in 'where clause' -EXPLAIN +EXPLAIN SELECT a AS out_a, MIN(b) FROM t1 t1_outer WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a) GROUP BY a; @@ -4277,16 +4277,16 @@ Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 Note 1003 select 2 AS `2` from `test`.`t1` where exists(select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)) EXPLAIN EXTENDED -SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION +SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION (SELECT 1 FROM t2 WHERE t1.a = t2.a)); -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION (SELECT 1 FROM t2 WHERE t1.a = t2.a))' at line 2 DROP TABLE t1,t2; create table t1(f11 int, f12 int); create table t2(f21 int unsigned not null, f22 int, f23 varchar(10)); insert into t1 values(1,1),(2,2), (3, 3); set session sort_buffer_size= 33*1024; -select count(*) from t1 where f12 = +select count(*) from t1 where f12 = (select f22 from t2 where f22 = f12 order by f21 desc, f22, f23 limit 1); count(*) 3 @@ -4327,12 +4327,12 @@ IF( FROM t2 VPC, t4 a2, t2 a3 WHERE VPC.f4 = a2.f10 AND a3.f2 = a4 -LIMIT 1) IS NULL, -0, +LIMIT 1) IS NULL, +0, t3.f5 ) ) AS a6 -FROM +FROM t2, t3, t1 JOIN t2 a1 ON t1.f9 = a1.f4 GROUP BY a4; a4 f3 a6 @@ -4341,7 +4341,7 @@ a4 f3 a6 DROP TABLE t1, t2, t3, t4; create table t1 (a float(5,4) zerofill); create table t2 (a float(5,4),b float(2,0)); -select t1.a from t1 where +select t1.a from t1 where t1.a= (select b from t2 limit 1) and not t1.a= (select a from t2 limit 1) ; a @@ -4362,7 +4362,7 @@ Warnings: Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 AS `1` from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (<cache>(1) = <ref_null_helper>(1)))) DROP TABLE t1; End of 5.0 tests. -CREATE TABLE t1 (a int, b int); +CREATE TABLE t1 (a INT, b INT); INSERT INTO t1 VALUES (2,22),(1,11),(2,22); SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a; a @@ -4385,22 +4385,22 @@ WHERE (SELECT COUNT(t0.b) FROM t1 t WHERE t.b>20) GROUP BY a; ERROR HY000: Invalid use of group function SET @@sql_mode=default; DROP TABLE t1; -CREATE TABLE t1 (s1 char(1)); +CREATE TABLE t1 (s1 CHAR(1)); INSERT INTO t1 VALUES ('a'); SELECT * FROM t1 WHERE _utf8'a' = ANY (SELECT s1 FROM t1); s1 a DROP TABLE t1; -CREATE TABLE t1(c int, KEY(c)); -CREATE TABLE t2(a int, b int); +CREATE TABLE t1(c INT, KEY(c)); +CREATE TABLE t2(a INT, b INT); INSERT INTO t2 VALUES (1, 10), (2, NULL); INSERT INTO t1 VALUES (1), (3); SELECT * FROM t2 WHERE b NOT IN (SELECT max(t.c) FROM t1, t1 t WHERE t.c>10); a b DROP TABLE t1,t2; -CREATE TABLE t1(pk int PRIMARY KEY, a int, INDEX idx(a)); +CREATE TABLE t1(pk INT PRIMARY KEY, a INT, INDEX idx(a)); INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20); -CREATE TABLE t2(pk int PRIMARY KEY, a int, b int, INDEX idxa(a)); +CREATE TABLE t2(pk INT PRIMARY KEY, a INT, b INT, INDEX idxa(a)); INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100); SELECT * FROM t1 WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b); @@ -4409,36 +4409,36 @@ pk a 3 30 2 20 DROP TABLE t1,t2; -CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY b (b)); +CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), KEY b (b)); INSERT INTO t1 VALUES (1,NULL), (9,NULL); CREATE TABLE t2 ( -a int, -b int, -c int, -d int, +a INT, +b INT, +c INT, +d INT, PRIMARY KEY (a), UNIQUE KEY b (b,c,d), KEY b_2 (b), KEY c (c), KEY d (d) ); -INSERT INTO t2 VALUES +INSERT INTO t2 VALUES (43, 2, 11 ,30), (44, 2, 12 ,30), (45, 1, 1 ,10000), (46, 1, 2 ,10000), (556,1, 32 ,10000); CREATE TABLE t3 ( -a int, -b int, -c int, +a INT, +b INT, +c INT, PRIMARY KEY (a), UNIQUE KEY b (b,c), KEY c (c), KEY b_2 (b) ); INSERT INTO t3 VALUES (1,1,1), (2,32,1); -explain +explain SELECT t1.a, (SELECT 1 FROM t2 WHERE t2.b=t3.c AND t2.c=t1.a ORDER BY t2.d LIMIT 1) AS incorrect FROM t1, t3 WHERE t3.b=t1.a; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 index b,b_2 b 10 NULL 2 Using index @@ -4479,7 +4479,7 @@ DELETE FROM v3; DROP VIEW v1,v2,v3; DROP TABLE t1,t2; # -# BUG#37822: Correlated subquery with IN and IS UNKNOWN provides wrong result +# Bug#37822 Correlated subquery with IN and IS UNKNOWN provides wrong result # create table t1(id integer primary key, g integer, v integer, s char(1)); create table t2(id integer primary key, g integer, v integer, s char(1)); diff --git a/mysql-test/r/synchronization.result b/mysql-test/r/synchronization.result index 5d8585f1f883776e224a0db6aa11c0bea1a96942..3f6d16178dd53dcee10f62f6a44c656b83fb8ce2 100644 --- a/mysql-test/r/synchronization.result +++ b/mysql-test/r/synchronization.result @@ -1,6 +1,6 @@ -drop table if exists t1,t2; -CREATE TABLE t1 (x1 int); -ALTER TABLE t1 CHANGE x1 x2 int; +DROP TABLE IF EXISTS t1,t2; +CREATE TABLE t1 (x1 INT); +ALTER TABLE t1 CHANGE x1 x2 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -8,7 +8,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -16,7 +16,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -24,7 +24,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -32,7 +32,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -40,7 +40,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -48,7 +48,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -56,7 +56,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -64,7 +64,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -72,7 +72,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -80,7 +80,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -88,7 +88,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -96,7 +96,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -104,7 +104,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -112,7 +112,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -120,7 +120,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -128,7 +128,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -136,7 +136,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -144,7 +144,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -152,7 +152,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; -ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 INT; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result index 6a692ed58e40ebdb61ff6e713a3ef05ced7e90e8..b62814437514a067b4bff1c5bee2b40b24adda9a 100644 --- a/mysql-test/r/type_datetime.result +++ b/mysql-test/r/type_datetime.result @@ -619,3 +619,22 @@ ERROR 42000: Invalid default value for 'da' create table t1 (t time default '916:00:00 a'); ERROR 42000: Invalid default value for 't' set @@sql_mode= @org_mode; +SELECT CAST(CAST('2006-08-10 10:11:12.0123450' AS DATETIME) AS DECIMAL(30,7)); +CAST(CAST('2006-08-10 10:11:12.0123450' AS DATETIME) AS DECIMAL(30,7)) +20060810101112.0123450 +Warnings: +Warning 1292 Truncated incorrect datetime value: '2006-08-10 10:11:12.0123450' +SELECT CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.0123450' AS DATETIME) AS DECIMAL(30,7)); +CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.0123450' AS DATETIME) AS DECIMAL(30,7)) +20060810101112.0123450 +Warnings: +Warning 1292 Truncated incorrect datetime value: '00000002006-000008-0000010 000010:0000011:00000012.0123450' +SELECT CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.012345' AS DATETIME) AS DECIMAL(30,7)); +CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.012345' AS DATETIME) AS DECIMAL(30,7)) +20060810101112.0123450 +SELECT CAST(CAST('2008-07-29T10:42:51.1234567' AS DateTime) AS DECIMAL(30,7)); +CAST(CAST('2008-07-29T10:42:51.1234567' AS DateTime) AS DECIMAL(30,7)) +20080729104251.1234560 +Warnings: +Warning 1292 Truncated incorrect datetime value: '2008-07-29T10:42:51.1234567' +End of 5.1 tests diff --git a/mysql-test/r/type_float.result b/mysql-test/r/type_float.result index d4cfd1c04eddd58a41ddb9e56ccdcfe5e42e6590..351c89ebe9dc2e467eda806e7c11a38067ba0fb4 100644 --- a/mysql-test/r/type_float.result +++ b/mysql-test/r/type_float.result @@ -385,12 +385,12 @@ Warning 1264 Out of range value for column 'f1' at row 1 Warning 1264 Out of range value for column 'f1' at row 2 select f1 + 0e0 from t1; f1 + 0e0 -1.0000000150475e+29 --1.0000000150475e+29 -1.0000000150475e+30 --1.0000000150475e+30 -1.0000000150475e+30 --1.0000000150475e+30 +1.00000001504747e+29 +-1.00000001504747e+29 +1.00000001504747e+30 +-1.00000001504747e+30 +1.00000001504747e+30 +-1.00000001504747e+30 drop table t1; create table t1(d double, u bigint unsigned); insert into t1(d) values (9.22337203685479e18), @@ -401,4 +401,9 @@ u 9223372036854790144 18400000000000000000 drop table t1; +CREATE TABLE t1 (f1 DOUBLE); +INSERT INTO t1 VALUES(-1.79769313486231e+308); +SELECT f1 FROM t1; +f1 +-1.79769313486231e+308 End of 5.0 tests diff --git a/mysql-test/r/windows.result b/mysql-test/r/windows.result index d056bde4dca92bb46ffedf4b637e5f6d56798cd4..4e0d73ea0ebd4b982b667f628d63c57657e6a7b5 100644 --- a/mysql-test/r/windows.result +++ b/mysql-test/r/windows.result @@ -19,6 +19,24 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used DROP TABLE t1; +CREATE DATABASE `TESTDB`; +USE `TESTDB`; +CREATE FUNCTION test_fn() RETURNS INTEGER +BEGIN +DECLARE rId bigint; +RETURN rId; +END +// +CREATE FUNCTION test_fn2() RETURNS INTEGER +BEGIN +DECLARE rId bigint; +RETURN rId; +END +// +DROP FUNCTION `TESTDB`.`test_fn`; +DROP FUNCTION `testdb`.`test_fn2`; +USE test; +DROP DATABASE `TESTDB`; End of 5.0 tests. drop procedure if exists proc_1; create procedure proc_1() install plugin my_plug soname '\\root\\some_plugin.dll'; diff --git a/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result b/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result index 0606c223126215e9d5f82876057f4bfba7430b25..4f3bc57e57650c96a3d4cf1a1fb3c5a95d118abb 100644 --- a/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result +++ b/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result @@ -379,9 +379,7 @@ master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Query # # use `test`; COMMIT -master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Query # # use `test`; TRUNCATE table t2 -master-bin.000001 # Xid # # COMMIT /* XID */ master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F @@ -401,9 +399,7 @@ master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Query # # use `test`; ROLLBACK -master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Query # # use `test`; TRUNCATE table t2 -master-bin.000001 # Query # # use `test`; COMMIT master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F diff --git a/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result b/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result index 6d943ed9da159d247a878f5d1efa090c5ca6660c..38488c9331dd0aef38b576449712512f168e5922 100644 --- a/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result +++ b/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result @@ -346,9 +346,7 @@ master-bin.000001 # Query # # use `test`; INSERT INTO t1 values (3,3) master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t2 master-bin.000001 # Query # # use `test`; CREATE TABLE t2 (a int, b int, primary key (a)) engine=innodb master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (4,4) -master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Query # # use `test`; TRUNCATE table t2 -master-bin.000001 # Xid # # COMMIT /* XID */ master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (5,5) master-bin.000001 # Query # # use `test`; DROP TABLE t2 master-bin.000001 # Query # # use `test`; INSERT INTO t1 values (6,6) @@ -356,9 +354,7 @@ master-bin.000001 # Query # # use `test`; CREATE TEMPORARY TABLE t2 (a int, b in master-bin.000001 # Query # # use `test`; INSERT INTO t1 values (7,7) master-bin.000001 # Query # # use `test`; INSERT INTO t1 values (8,8) master-bin.000001 # Query # # use `test`; INSERT INTO t1 values (9,9) -master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Query # # use `test`; TRUNCATE table t2 -master-bin.000001 # Query # # use `test`; COMMIT master-bin.000001 # Query # # use `test`; INSERT INTO t1 values (10,10) master-bin.000001 # Query # # use `test`; BEGIN master-bin.000001 # Query # # use `test`; INSERT INTO t2 values (100,100) diff --git a/mysql-test/suite/binlog/r/binlog_truncate_innodb.result b/mysql-test/suite/binlog/r/binlog_truncate_innodb.result new file mode 100644 index 0000000000000000000000000000000000000000..ab237898a7486f6d7aaef76d142e1178934a1157 --- /dev/null +++ b/mysql-test/suite/binlog/r/binlog_truncate_innodb.result @@ -0,0 +1,63 @@ +CREATE TABLE t1 (a INT) ENGINE=InnoDB; +CREATE TABLE t2 (a INT) ENGINE=InnoDB; +INSERT INTO t2 VALUES (1),(2),(3); +**** Truncate of empty table shall be logged +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +show binlog events from <binlog_start>; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t1 +master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t2 +DROP TABLE t1,t2; +CREATE TABLE t1 (a INT) ENGINE=InnoDB; +CREATE TABLE t2 (a INT) ENGINE=InnoDB; +INSERT INTO t2 VALUES (1),(2),(3); +SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; +**** Truncate of empty table shall be logged +TRUNCATE TABLE t1; +SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; +TRUNCATE TABLE t2; +show binlog events from <binlog_start>; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t1 +master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t2 +DROP TABLE t1,t2; +CREATE TABLE t1 (a INT) ENGINE=InnoDB; +CREATE TABLE t2 (a INT) ENGINE=InnoDB; +INSERT INTO t2 VALUES (1),(2),(3); +SET TRANSACTION ISOLATION LEVEL READ COMMITTED; +**** Truncate of empty table shall be logged +TRUNCATE TABLE t1; +SET TRANSACTION ISOLATION LEVEL READ COMMITTED; +TRUNCATE TABLE t2; +show binlog events from <binlog_start>; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t1 +master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t2 +DROP TABLE t1,t2; +CREATE TABLE t1 (a INT) ENGINE=InnoDB; +CREATE TABLE t2 (a INT) ENGINE=InnoDB; +INSERT INTO t2 VALUES (1),(2),(3); +SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; +**** Truncate of empty table shall be logged +TRUNCATE TABLE t1; +SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; +TRUNCATE TABLE t2; +show binlog events from <binlog_start>; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t1 +master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t2 +DROP TABLE t1,t2; +CREATE TABLE t1 (a INT) ENGINE=InnoDB; +CREATE TABLE t2 (a INT) ENGINE=InnoDB; +INSERT INTO t2 VALUES (1),(2),(3); +SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; +**** Truncate of empty table shall be logged +TRUNCATE TABLE t1; +SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; +TRUNCATE TABLE t2; +show binlog events from <binlog_start>; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t1 +master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t2 +DROP TABLE t1,t2; diff --git a/mysql-test/suite/binlog/r/binlog_truncate_myisam.result b/mysql-test/suite/binlog/r/binlog_truncate_myisam.result new file mode 100644 index 0000000000000000000000000000000000000000..9f01c01517884840b8fac870ede9883e1cdf1d6c --- /dev/null +++ b/mysql-test/suite/binlog/r/binlog_truncate_myisam.result @@ -0,0 +1,12 @@ +RESET MASTER; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +CREATE TABLE t2 (a INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1),(2),(3); +**** Truncate of empty table shall be logged +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +show binlog events from <binlog_start>; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t1 +master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t2 +DROP TABLE t1,t2; diff --git a/mysql-test/suite/binlog/t/binlog_truncate_innodb-master.opt b/mysql-test/suite/binlog/t/binlog_truncate_innodb-master.opt new file mode 100644 index 0000000000000000000000000000000000000000..69cc489a9693529b793bd93a092a76c212dd383b --- /dev/null +++ b/mysql-test/suite/binlog/t/binlog_truncate_innodb-master.opt @@ -0,0 +1 @@ +--loose-innodb \ No newline at end of file diff --git a/mysql-test/suite/binlog/t/binlog_truncate_innodb.test b/mysql-test/suite/binlog/t/binlog_truncate_innodb.test new file mode 100644 index 0000000000000000000000000000000000000000..be0918a43f0bcc98a317ad37323710d2cea2bfc4 --- /dev/null +++ b/mysql-test/suite/binlog/t/binlog_truncate_innodb.test @@ -0,0 +1,29 @@ +source include/have_log_bin.inc; +source include/have_innodb.inc; + +# It is necessary to reset the master since otherwise the binlog test +# might show the wrong binary log. The default for SHOW BINLOG EVENTS +# is to show the first binary log, not the current one (which is +# actually a better idea). + +RESET MASTER; + +let $engine = InnoDB; +source extra/binlog_tests/binlog_truncate.test; + +# Under transaction isolation level READ UNCOMMITTED and READ +# COMMITTED, InnoDB does not permit statement-based replication of +# row-deleting statement. In these cases, TRUNCATE TABLE should still +# be replicated as a statement. + +let $before_truncate = SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; +source extra/binlog_tests/binlog_truncate.test; + +let $before_truncate = SET TRANSACTION ISOLATION LEVEL READ COMMITTED; +source extra/binlog_tests/binlog_truncate.test; + +let $before_truncate = SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; +source extra/binlog_tests/binlog_truncate.test; + +let $before_truncate = SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; +source extra/binlog_tests/binlog_truncate.test; diff --git a/mysql-test/suite/binlog/t/binlog_truncate_myisam.test b/mysql-test/suite/binlog/t/binlog_truncate_myisam.test new file mode 100644 index 0000000000000000000000000000000000000000..e0e4673e8769574797affb4af5047d5209a1d01f --- /dev/null +++ b/mysql-test/suite/binlog/t/binlog_truncate_myisam.test @@ -0,0 +1,11 @@ +source include/have_log_bin.inc; + +# It is necessary to reset the master since otherwise the binlog test +# might show the wrong binary log. The default for SHOW BINLOG EVENTS +# is to show the first binary log, not the current one (which is +# actually a better idea). + +RESET MASTER; + +let $engine = MyISAM; +source extra/binlog_tests/binlog_truncate.test; diff --git a/mysql-test/suite/binlog/t/disabled.def b/mysql-test/suite/binlog/t/disabled.def index 888298bbb09e2eebe1471f7dde7bdc4bff6f2b9e..0018387de9423cc14be5e7fbab4fa288f8bf57da 100644 --- a/mysql-test/suite/binlog/t/disabled.def +++ b/mysql-test/suite/binlog/t/disabled.def @@ -9,3 +9,5 @@ # Do not use any TAB characters for whitespace. # ############################################################################## +binlog_truncate_innodb : BUG#42643 2009-02-06 mats Changes to InnoDB requires to complete fix for BUG#36763 + diff --git a/mysql-test/suite/rpl/r/rpl_drop_if_exists.result b/mysql-test/suite/rpl/r/rpl_drop_if_exists.result new file mode 100644 index 0000000000000000000000000000000000000000..59a2470cfdb5fdb59cfc5bd028f0f3f0c37d69f9 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_drop_if_exists.result @@ -0,0 +1,98 @@ +RESET MASTER; +DROP PROCEDURE IF EXISTS db_bug_13684.p; +DROP FUNCTION IF EXISTS db_bug_13684.f; +DROP TRIGGER IF EXISTS db_bug_13684.tr; +DROP VIEW IF EXISTS db_bug_13684.v; +DROP EVENT IF EXISTS db_bug_13684.e; +DROP TABLE IF EXISTS db_bug_13684.t; +DROP DATABASE IF EXISTS db_bug_13684; +show binlog events from <binlog_start>; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; DROP PROCEDURE IF EXISTS db_bug_13684.p +master-bin.000001 # Query # # use `test`; DROP FUNCTION IF EXISTS db_bug_13684.f +master-bin.000001 # Query # # use `test`; DROP TRIGGER IF EXISTS db_bug_13684.tr +master-bin.000001 # Query # # use `test`; DROP VIEW IF EXISTS db_bug_13684.v +master-bin.000001 # Query # # use `test`; DROP EVENT IF EXISTS db_bug_13684.e +master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS db_bug_13684.t +master-bin.000001 # Query # # DROP DATABASE IF EXISTS db_bug_13684 +CREATE DATABASE db_bug_13684; +CREATE TABLE db_bug_13684.t (a int); +CREATE EVENT db_bug_13684.e +ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR +DO +UPDATE db_bug_13684.t SET a = a + 1; +CREATE VIEW db_bug_13684.v +AS SELECT * FROM db_bug_13684.t; +CREATE TRIGGER db_bug_13684.tr BEFORE INSERT ON db_bug_13684.t +FOR EACH ROW BEGIN +END; +CREATE PROCEDURE db_bug_13684.p (OUT p1 INT) +BEGIN +END; +CREATE FUNCTION db_bug_13684.f (s CHAR(20)) +RETURNS CHAR(50) DETERMINISTIC +RETURN s; +show binlog events from <binlog_start>; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; DROP PROCEDURE IF EXISTS db_bug_13684.p +master-bin.000001 # Query # # use `test`; DROP FUNCTION IF EXISTS db_bug_13684.f +master-bin.000001 # Query # # use `test`; DROP TRIGGER IF EXISTS db_bug_13684.tr +master-bin.000001 # Query # # use `test`; DROP VIEW IF EXISTS db_bug_13684.v +master-bin.000001 # Query # # use `test`; DROP EVENT IF EXISTS db_bug_13684.e +master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS db_bug_13684.t +master-bin.000001 # Query # # DROP DATABASE IF EXISTS db_bug_13684 +master-bin.000001 # Query # # CREATE DATABASE db_bug_13684 +master-bin.000001 # Query # # use `test`; CREATE TABLE db_bug_13684.t (a int) +master-bin.000001 # Query # # use `test`; CREATE EVENT db_bug_13684.e +ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR +DO +UPDATE db_bug_13684.t SET a = a + 1 +master-bin.000001 # Query # # use `test`; CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `db_bug_13684`.`v` AS SELECT * FROM db_bug_13684.t +master-bin.000001 # Query # # use `test`; CREATE DEFINER=`root`@`localhost` TRIGGER db_bug_13684.tr BEFORE INSERT ON db_bug_13684.t +FOR EACH ROW BEGIN +END +master-bin.000001 # Query # # use `test`; CREATE DEFINER=`root`@`localhost` PROCEDURE `db_bug_13684`.`p`(OUT p1 INT) +BEGIN +END +master-bin.000001 # Query # # use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `db_bug_13684`.`f`(s CHAR(20)) RETURNS char(50) CHARSET latin1 + DETERMINISTIC +RETURN s +DROP PROCEDURE IF EXISTS db_bug_13684.p; +DROP FUNCTION IF EXISTS db_bug_13684.f; +DROP TRIGGER IF EXISTS db_bug_13684.tr; +DROP VIEW IF EXISTS db_bug_13684.v; +DROP EVENT IF EXISTS db_bug_13684.e; +DROP TABLE IF EXISTS db_bug_13684.t; +DROP DATABASE IF EXISTS db_bug_13684; +show binlog events from <binlog_start>; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; DROP PROCEDURE IF EXISTS db_bug_13684.p +master-bin.000001 # Query # # use `test`; DROP FUNCTION IF EXISTS db_bug_13684.f +master-bin.000001 # Query # # use `test`; DROP TRIGGER IF EXISTS db_bug_13684.tr +master-bin.000001 # Query # # use `test`; DROP VIEW IF EXISTS db_bug_13684.v +master-bin.000001 # Query # # use `test`; DROP EVENT IF EXISTS db_bug_13684.e +master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS db_bug_13684.t +master-bin.000001 # Query # # DROP DATABASE IF EXISTS db_bug_13684 +master-bin.000001 # Query # # CREATE DATABASE db_bug_13684 +master-bin.000001 # Query # # use `test`; CREATE TABLE db_bug_13684.t (a int) +master-bin.000001 # Query # # use `test`; CREATE EVENT db_bug_13684.e +ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR +DO +UPDATE db_bug_13684.t SET a = a + 1 +master-bin.000001 # Query # # use `test`; CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `db_bug_13684`.`v` AS SELECT * FROM db_bug_13684.t +master-bin.000001 # Query # # use `test`; CREATE DEFINER=`root`@`localhost` TRIGGER db_bug_13684.tr BEFORE INSERT ON db_bug_13684.t +FOR EACH ROW BEGIN +END +master-bin.000001 # Query # # use `test`; CREATE DEFINER=`root`@`localhost` PROCEDURE `db_bug_13684`.`p`(OUT p1 INT) +BEGIN +END +master-bin.000001 # Query # # use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `db_bug_13684`.`f`(s CHAR(20)) RETURNS char(50) CHARSET latin1 + DETERMINISTIC +RETURN s +master-bin.000001 # Query # # use `test`; DROP PROCEDURE IF EXISTS db_bug_13684.p +master-bin.000001 # Query # # use `test`; DROP FUNCTION IF EXISTS db_bug_13684.f +master-bin.000001 # Query # # use `test`; DROP TRIGGER IF EXISTS db_bug_13684.tr +master-bin.000001 # Query # # use `test`; DROP VIEW IF EXISTS db_bug_13684.v +master-bin.000001 # Query # # use `test`; DROP EVENT IF EXISTS db_bug_13684.e +master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS db_bug_13684.t +master-bin.000001 # Query # # DROP DATABASE IF EXISTS db_bug_13684 diff --git a/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result b/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result index 8602718ba464cf42122e0cd4cbd1a520bb89036c..1e795a85ce1e5109b5febc70767496a6a0a45750 100644 --- a/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result +++ b/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result @@ -963,9 +963,7 @@ master-bin.000001 # Xid 1 # # master-bin.000001 # Query 1 # use `test_rpl`; BEGIN master-bin.000001 # Query 1 # use `test_rpl`; INSERT INTO t1 VALUES(1, 't1, text 1') master-bin.000001 # Xid 1 # # -master-bin.000001 # Query 1 # use `test_rpl`; BEGIN master-bin.000001 # Query 1 # use `test_rpl`; TRUNCATE t1 -master-bin.000001 # Xid 1 # # master-bin.000001 # Query 1 # use `test_rpl`; BEGIN master-bin.000001 # Query 1 # use `test_rpl`; DELETE FROM t1 master-bin.000001 # Xid 1 # # diff --git a/mysql-test/suite/rpl/r/rpl_sp.result b/mysql-test/suite/rpl/r/rpl_sp.result index 4a8a4050c02344d1bb68f06f8df225ace6c29478..86d126f617685b6ceb7b94c64bfa2f226a14b98d 100644 --- a/mysql-test/suite/rpl/r/rpl_sp.result +++ b/mysql-test/suite/rpl/r/rpl_sp.result @@ -511,6 +511,7 @@ master-bin.000001 # Query 1 # use `mysqltest1`; drop procedure foo master-bin.000001 # Query 1 # use `mysqltest1`; drop function fn1 master-bin.000001 # Query 1 # drop database mysqltest1 master-bin.000001 # Query 1 # drop user "zedjzlcsjhd"@127.0.0.1 +master-bin.000001 # Query 1 # use `test`; drop function if exists f1 master-bin.000001 # Query 1 # use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11) READS SQL DATA begin @@ -526,12 +527,15 @@ master-bin.000001 # Query 1 # use `test`; create table t1 (a int) master-bin.000001 # Query 1 # use `test`; insert into t1 (a) values (f1()) master-bin.000001 # Query 1 # use `test`; drop view v1 master-bin.000001 # Query 1 # use `test`; drop function f1 +master-bin.000001 # Query 1 # use `test`; DROP PROCEDURE IF EXISTS p1 master-bin.000001 # Query 1 # use `test`; DROP TABLE IF EXISTS t1 master-bin.000001 # Query 1 # use `test`; CREATE TABLE t1(col VARCHAR(10)) master-bin.000001 # Query 1 # use `test`; CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`(arg VARCHAR(10)) INSERT INTO t1 VALUES(arg) master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 VALUES( NAME_CONST('arg',_latin1'test' COLLATE 'latin1_swedish_ci')) master-bin.000001 # Query 1 # use `test`; DROP PROCEDURE p1 +master-bin.000001 # Query 1 # use `test`; DROP PROCEDURE IF EXISTS p1 +master-bin.000001 # Query 1 # use `test`; DROP FUNCTION IF EXISTS f1 master-bin.000001 # Query 1 # use `test`; CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`() SET @a = 1 master-bin.000001 # Query 1 # use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11) @@ -842,6 +846,9 @@ drop user "zedjzlcsjhd"@127.0.0.1 /*!*/; use test/*!*/; SET TIMESTAMP=t/*!*/; +drop function if exists f1 +/*!*/; +SET TIMESTAMP=t/*!*/; CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11) READS SQL DATA begin @@ -869,6 +876,9 @@ SET TIMESTAMP=t/*!*/; drop function f1 /*!*/; SET TIMESTAMP=t/*!*/; +DROP PROCEDURE IF EXISTS p1 +/*!*/; +SET TIMESTAMP=t/*!*/; DROP TABLE IF EXISTS t1 /*!*/; SET TIMESTAMP=t/*!*/; @@ -885,6 +895,12 @@ SET TIMESTAMP=t/*!*/; DROP PROCEDURE p1 /*!*/; SET TIMESTAMP=t/*!*/; +DROP PROCEDURE IF EXISTS p1 +/*!*/; +SET TIMESTAMP=t/*!*/; +DROP FUNCTION IF EXISTS f1 +/*!*/; +SET TIMESTAMP=t/*!*/; CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`() SET @a = 1 /*!*/; diff --git a/mysql-test/suite/rpl/r/rpl_truncate_2myisam.result b/mysql-test/suite/rpl/r/rpl_truncate_2myisam.result index 92e130648562967668324ecd54728765626c8814..38fb9e277643a3bba3df3f74d600e2f06a855eeb 100644 --- a/mysql-test/suite/rpl/r/rpl_truncate_2myisam.result +++ b/mysql-test/suite/rpl/r/rpl_truncate_2myisam.result @@ -4,265 +4,43 @@ reset master; reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; start slave; -STOP SLAVE; -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t1; +**** Resetting master and slave **** +include/stop_slave.inc RESET SLAVE; -START SLAVE; -**** On Master **** -SET @old_session_binlog_format= @@session.binlog_format; -SET @old_global_binlog_format= @@global.binlog_format; -SET SESSION BINLOG_FORMAT=STATEMENT; -SET GLOBAL BINLOG_FORMAT=STATEMENT; -CREATE TABLE t1 (a INT, b LONG) ENGINE=MyISAM; -INSERT INTO t1 VALUES (1,1), (2,2); -SELECT * FROM t1; -a b -1 1 -2 2 -**** On Slave **** -INSERT INTO t1 VALUE (3,3); -SELECT * FROM t1; -a b -1 1 -2 2 -3 3 -**** On Master **** -TRUNCATE TABLE t1; -SELECT * FROM t1; -a b -**** On Slave **** -SELECT * FROM t1; -a b -**** On Master **** -DROP TABLE t1; -show binlog events from <binlog_start>; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t1 -master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b LONG) ENGINE=MyISAM -master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (1,1), (2,2) -master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t1 -master-bin.000001 # Query # # use `test`; DROP TABLE t1 RESET MASTER; -SET @@session.binlog_format= @old_session_binlog_format; -SET @@global.binlog_format= @old_global_binlog_format; -STOP SLAVE; -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t1; -RESET SLAVE; -START SLAVE; +include/start_slave.inc **** On Master **** -SET @old_session_binlog_format= @@session.binlog_format; -SET @old_global_binlog_format= @@global.binlog_format; -SET SESSION BINLOG_FORMAT=MIXED; -SET GLOBAL BINLOG_FORMAT=MIXED; CREATE TABLE t1 (a INT, b LONG) ENGINE=MyISAM; INSERT INTO t1 VALUES (1,1), (2,2); -SELECT * FROM t1; -a b -1 1 -2 2 -**** On Slave **** -INSERT INTO t1 VALUE (3,3); -SELECT * FROM t1; -a b -1 1 -2 2 -3 3 **** On Master **** TRUNCATE TABLE t1; -SELECT * FROM t1; -a b -**** On Slave **** -SELECT * FROM t1; -a b +Comparing tables master:test.t1 and slave:test.t1 +==== Test using a table with delete triggers ==== **** On Master **** -DROP TABLE t1; -show binlog events from <binlog_start>; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t1 -master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b LONG) ENGINE=MyISAM -master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (1,1), (2,2) -master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t1 -master-bin.000001 # Query # # use `test`; DROP TABLE t1 -RESET MASTER; -SET @@session.binlog_format= @old_session_binlog_format; -SET @@global.binlog_format= @old_global_binlog_format; -STOP SLAVE; -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t1; -RESET SLAVE; -START SLAVE; -**** On Master **** -SET @old_session_binlog_format= @@session.binlog_format; -SET @old_global_binlog_format= @@global.binlog_format; -SET SESSION BINLOG_FORMAT=ROW; -SET GLOBAL BINLOG_FORMAT=ROW; -CREATE TABLE t1 (a INT, b LONG) ENGINE=MyISAM; -INSERT INTO t1 VALUES (1,1), (2,2); -SELECT * FROM t1; -a b -1 1 -2 2 -**** On Slave **** -INSERT INTO t1 VALUE (3,3); -SELECT * FROM t1; -a b -1 1 -2 2 -3 3 +SET @count := 1; +CREATE TABLE t2 (a INT, b LONG) ENGINE=MyISAM; +CREATE TRIGGER trg1 BEFORE DELETE ON t1 FOR EACH ROW SET @count := @count + 1; **** On Master **** TRUNCATE TABLE t1; -SELECT * FROM t1; -a b -**** On Slave **** -SELECT * FROM t1; -a b -**** On Master **** -DROP TABLE t1; -show binlog events from <binlog_start>; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t1 -master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b LONG) ENGINE=MyISAM -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Table_map # # table_id: # (test.t1) -master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F -master-bin.000001 # Query # # use `test`; COMMIT -master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t1 -master-bin.000001 # Query # # use `test`; DROP TABLE t1 -RESET MASTER; -SET @@session.binlog_format= @old_session_binlog_format; -SET @@global.binlog_format= @old_global_binlog_format; -STOP SLAVE; -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t1; +Comparing tables master:test.t2 and slave:test.t2 +DROP TABLE t1,t2; +**** Resetting master and slave **** +include/stop_slave.inc RESET SLAVE; -START SLAVE; -**** On Master **** -SET @old_session_binlog_format= @@session.binlog_format; -SET @old_global_binlog_format= @@global.binlog_format; -SET SESSION BINLOG_FORMAT=STATEMENT; -SET GLOBAL BINLOG_FORMAT=STATEMENT; -CREATE TABLE t1 (a INT, b LONG) ENGINE=MyISAM; -INSERT INTO t1 VALUES (1,1), (2,2); -SELECT * FROM t1; -a b -1 1 -2 2 -**** On Slave **** -INSERT INTO t1 VALUE (3,3); -SELECT * FROM t1; -a b -1 1 -2 2 -3 3 -**** On Master **** -DELETE FROM t1; -SELECT * FROM t1; -a b -**** On Slave **** -SELECT * FROM t1; -a b -**** On Master **** -DROP TABLE t1; -show binlog events from <binlog_start>; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t1 -master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b LONG) ENGINE=MyISAM -master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (1,1), (2,2) -master-bin.000001 # Query # # use `test`; DELETE FROM t1 -master-bin.000001 # Query # # use `test`; DROP TABLE t1 RESET MASTER; -SET @@session.binlog_format= @old_session_binlog_format; -SET @@global.binlog_format= @old_global_binlog_format; -STOP SLAVE; -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t1; -RESET SLAVE; -START SLAVE; +include/start_slave.inc **** On Master **** -SET @old_session_binlog_format= @@session.binlog_format; -SET @old_global_binlog_format= @@global.binlog_format; -SET SESSION BINLOG_FORMAT=MIXED; -SET GLOBAL BINLOG_FORMAT=MIXED; CREATE TABLE t1 (a INT, b LONG) ENGINE=MyISAM; INSERT INTO t1 VALUES (1,1), (2,2); -SELECT * FROM t1; -a b -1 1 -2 2 -**** On Slave **** -INSERT INTO t1 VALUE (3,3); -SELECT * FROM t1; -a b -1 1 -2 2 -3 3 **** On Master **** DELETE FROM t1; -SELECT * FROM t1; -a b -**** On Slave **** -SELECT * FROM t1; -a b +Comparing tables master:test.t1 and slave:test.t1 +==== Test using a table with delete triggers ==== **** On Master **** -DROP TABLE t1; -show binlog events from <binlog_start>; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t1 -master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b LONG) ENGINE=MyISAM -master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (1,1), (2,2) -master-bin.000001 # Query # # use `test`; DELETE FROM t1 -master-bin.000001 # Query # # use `test`; DROP TABLE t1 -RESET MASTER; -SET @@session.binlog_format= @old_session_binlog_format; -SET @@global.binlog_format= @old_global_binlog_format; -STOP SLAVE; -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t1; -RESET SLAVE; -START SLAVE; -**** On Master **** -SET @old_session_binlog_format= @@session.binlog_format; -SET @old_global_binlog_format= @@global.binlog_format; -SET SESSION BINLOG_FORMAT=ROW; -SET GLOBAL BINLOG_FORMAT=ROW; -CREATE TABLE t1 (a INT, b LONG) ENGINE=MyISAM; -INSERT INTO t1 VALUES (1,1), (2,2); -SELECT * FROM t1; -a b -1 1 -2 2 -**** On Slave **** -INSERT INTO t1 VALUE (3,3); -SELECT * FROM t1; -a b -1 1 -2 2 -3 3 +SET @count := 1; +CREATE TABLE t2 (a INT, b LONG) ENGINE=MyISAM; +CREATE TRIGGER trg1 BEFORE DELETE ON t1 FOR EACH ROW SET @count := @count + 1; **** On Master **** DELETE FROM t1; -SELECT * FROM t1; -a b -**** On Slave **** -SELECT * FROM t1; -a b -3 3 -**** On Master **** -DROP TABLE t1; -show binlog events from <binlog_start>; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t1 -master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b LONG) ENGINE=MyISAM -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Table_map # # table_id: # (test.t1) -master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F -master-bin.000001 # Query # # use `test`; COMMIT -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Table_map # # table_id: # (test.t1) -master-bin.000001 # Delete_rows # # table_id: # flags: STMT_END_F -master-bin.000001 # Query # # use `test`; COMMIT -master-bin.000001 # Query # # use `test`; DROP TABLE t1 -RESET MASTER; -SET @@session.binlog_format= @old_session_binlog_format; -SET @@global.binlog_format= @old_global_binlog_format; +Comparing tables master:test.t2 and slave:test.t2 +DROP TABLE t1,t2; diff --git a/mysql-test/suite/rpl/r/rpl_truncate_3innodb.result b/mysql-test/suite/rpl/r/rpl_truncate_3innodb.result index 94461c33c46edf6332f51c3b4740b67f86a233b2..b5e5936834dc64881b5193c3309a46f462484791 100644 --- a/mysql-test/suite/rpl/r/rpl_truncate_3innodb.result +++ b/mysql-test/suite/rpl/r/rpl_truncate_3innodb.result @@ -4,283 +4,43 @@ reset master; reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; start slave; -STOP SLAVE; -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t1; +**** Resetting master and slave **** +include/stop_slave.inc RESET SLAVE; -START SLAVE; -**** On Master **** -SET @old_session_binlog_format= @@session.binlog_format; -SET @old_global_binlog_format= @@global.binlog_format; -SET SESSION BINLOG_FORMAT=STATEMENT; -SET GLOBAL BINLOG_FORMAT=STATEMENT; -CREATE TABLE t1 (a INT, b LONG) ENGINE=InnoDB; -INSERT INTO t1 VALUES (1,1), (2,2); -SELECT * FROM t1; -a b -1 1 -2 2 -**** On Slave **** -INSERT INTO t1 VALUE (3,3); -SELECT * FROM t1; -a b -1 1 -2 2 -3 3 -**** On Master **** -TRUNCATE TABLE t1; -SELECT * FROM t1; -a b -**** On Slave **** -SELECT * FROM t1; -a b -**** On Master **** -DROP TABLE t1; -show binlog events from <binlog_start>; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t1 -master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b LONG) ENGINE=InnoDB -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (1,1), (2,2) -master-bin.000001 # Xid # # COMMIT /* XID */ -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t1 -master-bin.000001 # Xid # # COMMIT /* XID */ -master-bin.000001 # Query # # use `test`; DROP TABLE t1 RESET MASTER; -SET @@session.binlog_format= @old_session_binlog_format; -SET @@global.binlog_format= @old_global_binlog_format; -STOP SLAVE; -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t1; -RESET SLAVE; -START SLAVE; +include/start_slave.inc **** On Master **** -SET @old_session_binlog_format= @@session.binlog_format; -SET @old_global_binlog_format= @@global.binlog_format; -SET SESSION BINLOG_FORMAT=MIXED; -SET GLOBAL BINLOG_FORMAT=MIXED; CREATE TABLE t1 (a INT, b LONG) ENGINE=InnoDB; INSERT INTO t1 VALUES (1,1), (2,2); -SELECT * FROM t1; -a b -1 1 -2 2 -**** On Slave **** -INSERT INTO t1 VALUE (3,3); -SELECT * FROM t1; -a b -1 1 -2 2 -3 3 **** On Master **** TRUNCATE TABLE t1; -SELECT * FROM t1; -a b -**** On Slave **** -SELECT * FROM t1; -a b +Comparing tables master:test.t1 and slave:test.t1 +==== Test using a table with delete triggers ==== **** On Master **** -DROP TABLE t1; -show binlog events from <binlog_start>; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t1 -master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b LONG) ENGINE=InnoDB -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (1,1), (2,2) -master-bin.000001 # Xid # # COMMIT /* XID */ -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t1 -master-bin.000001 # Xid # # COMMIT /* XID */ -master-bin.000001 # Query # # use `test`; DROP TABLE t1 -RESET MASTER; -SET @@session.binlog_format= @old_session_binlog_format; -SET @@global.binlog_format= @old_global_binlog_format; -STOP SLAVE; -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t1; -RESET SLAVE; -START SLAVE; -**** On Master **** -SET @old_session_binlog_format= @@session.binlog_format; -SET @old_global_binlog_format= @@global.binlog_format; -SET SESSION BINLOG_FORMAT=ROW; -SET GLOBAL BINLOG_FORMAT=ROW; -CREATE TABLE t1 (a INT, b LONG) ENGINE=InnoDB; -INSERT INTO t1 VALUES (1,1), (2,2); -SELECT * FROM t1; -a b -1 1 -2 2 -**** On Slave **** -INSERT INTO t1 VALUE (3,3); -SELECT * FROM t1; -a b -1 1 -2 2 -3 3 +SET @count := 1; +CREATE TABLE t2 (a INT, b LONG) ENGINE=InnoDB; +CREATE TRIGGER trg1 BEFORE DELETE ON t1 FOR EACH ROW SET @count := @count + 1; **** On Master **** TRUNCATE TABLE t1; -SELECT * FROM t1; -a b -**** On Slave **** -SELECT * FROM t1; -a b -**** On Master **** -DROP TABLE t1; -show binlog events from <binlog_start>; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t1 -master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b LONG) ENGINE=InnoDB -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Table_map # # table_id: # (test.t1) -master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F -master-bin.000001 # Xid # # COMMIT /* XID */ -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Query # # use `test`; TRUNCATE TABLE t1 -master-bin.000001 # Xid # # COMMIT /* XID */ -master-bin.000001 # Query # # use `test`; DROP TABLE t1 -RESET MASTER; -SET @@session.binlog_format= @old_session_binlog_format; -SET @@global.binlog_format= @old_global_binlog_format; -STOP SLAVE; -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t1; +Comparing tables master:test.t2 and slave:test.t2 +DROP TABLE t1,t2; +**** Resetting master and slave **** +include/stop_slave.inc RESET SLAVE; -START SLAVE; -**** On Master **** -SET @old_session_binlog_format= @@session.binlog_format; -SET @old_global_binlog_format= @@global.binlog_format; -SET SESSION BINLOG_FORMAT=STATEMENT; -SET GLOBAL BINLOG_FORMAT=STATEMENT; -CREATE TABLE t1 (a INT, b LONG) ENGINE=InnoDB; -INSERT INTO t1 VALUES (1,1), (2,2); -SELECT * FROM t1; -a b -1 1 -2 2 -**** On Slave **** -INSERT INTO t1 VALUE (3,3); -SELECT * FROM t1; -a b -1 1 -2 2 -3 3 -**** On Master **** -DELETE FROM t1; -SELECT * FROM t1; -a b -**** On Slave **** -SELECT * FROM t1; -a b -**** On Master **** -DROP TABLE t1; -show binlog events from <binlog_start>; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t1 -master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b LONG) ENGINE=InnoDB -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (1,1), (2,2) -master-bin.000001 # Xid # # COMMIT /* XID */ -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Query # # use `test`; DELETE FROM t1 -master-bin.000001 # Xid # # COMMIT /* XID */ -master-bin.000001 # Query # # use `test`; DROP TABLE t1 RESET MASTER; -SET @@session.binlog_format= @old_session_binlog_format; -SET @@global.binlog_format= @old_global_binlog_format; -STOP SLAVE; -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t1; -RESET SLAVE; -START SLAVE; +include/start_slave.inc **** On Master **** -SET @old_session_binlog_format= @@session.binlog_format; -SET @old_global_binlog_format= @@global.binlog_format; -SET SESSION BINLOG_FORMAT=MIXED; -SET GLOBAL BINLOG_FORMAT=MIXED; CREATE TABLE t1 (a INT, b LONG) ENGINE=InnoDB; INSERT INTO t1 VALUES (1,1), (2,2); -SELECT * FROM t1; -a b -1 1 -2 2 -**** On Slave **** -INSERT INTO t1 VALUE (3,3); -SELECT * FROM t1; -a b -1 1 -2 2 -3 3 **** On Master **** DELETE FROM t1; -SELECT * FROM t1; -a b -**** On Slave **** -SELECT * FROM t1; -a b +Comparing tables master:test.t1 and slave:test.t1 +==== Test using a table with delete triggers ==== **** On Master **** -DROP TABLE t1; -show binlog events from <binlog_start>; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t1 -master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b LONG) ENGINE=InnoDB -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (1,1), (2,2) -master-bin.000001 # Xid # # COMMIT /* XID */ -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Query # # use `test`; DELETE FROM t1 -master-bin.000001 # Xid # # COMMIT /* XID */ -master-bin.000001 # Query # # use `test`; DROP TABLE t1 -RESET MASTER; -SET @@session.binlog_format= @old_session_binlog_format; -SET @@global.binlog_format= @old_global_binlog_format; -STOP SLAVE; -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t1; -RESET SLAVE; -START SLAVE; -**** On Master **** -SET @old_session_binlog_format= @@session.binlog_format; -SET @old_global_binlog_format= @@global.binlog_format; -SET SESSION BINLOG_FORMAT=ROW; -SET GLOBAL BINLOG_FORMAT=ROW; -CREATE TABLE t1 (a INT, b LONG) ENGINE=InnoDB; -INSERT INTO t1 VALUES (1,1), (2,2); -SELECT * FROM t1; -a b -1 1 -2 2 -**** On Slave **** -INSERT INTO t1 VALUE (3,3); -SELECT * FROM t1; -a b -1 1 -2 2 -3 3 +SET @count := 1; +CREATE TABLE t2 (a INT, b LONG) ENGINE=InnoDB; +CREATE TRIGGER trg1 BEFORE DELETE ON t1 FOR EACH ROW SET @count := @count + 1; **** On Master **** DELETE FROM t1; -SELECT * FROM t1; -a b -**** On Slave **** -SELECT * FROM t1; -a b -3 3 -**** On Master **** -DROP TABLE t1; -show binlog events from <binlog_start>; -Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS t1 -master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b LONG) ENGINE=InnoDB -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Table_map # # table_id: # (test.t1) -master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F -master-bin.000001 # Xid # # COMMIT /* XID */ -master-bin.000001 # Query # # use `test`; BEGIN -master-bin.000001 # Table_map # # table_id: # (test.t1) -master-bin.000001 # Delete_rows # # table_id: # flags: STMT_END_F -master-bin.000001 # Xid # # COMMIT /* XID */ -master-bin.000001 # Query # # use `test`; DROP TABLE t1 -RESET MASTER; -SET @@session.binlog_format= @old_session_binlog_format; -SET @@global.binlog_format= @old_global_binlog_format; +Comparing tables master:test.t2 and slave:test.t2 +DROP TABLE t1,t2; diff --git a/mysql-test/suite/rpl/t/rpl_cross_version.test b/mysql-test/suite/rpl/t/rpl_cross_version.test index adeba7f2b15f5d7b97cf42a7bf87a37a2edb74da..bb2ca35015249693b4937c6fac5539ef854022fb 100644 --- a/mysql-test/suite/rpl/t/rpl_cross_version.test +++ b/mysql-test/suite/rpl/t/rpl_cross_version.test @@ -11,7 +11,7 @@ # --source include/have_log_bin.inc ---source include/not_windows.inc + # # Bug#31240 load data infile replication between (4.0 or 4.1) and 5.1 fails # diff --git a/mysql-test/suite/rpl/t/rpl_drop_if_exists.test b/mysql-test/suite/rpl/t/rpl_drop_if_exists.test new file mode 100644 index 0000000000000000000000000000000000000000..6b2b37ae791f49d4062fbcdb1aea0a2e52c4ab1e --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_drop_if_exists.test @@ -0,0 +1,115 @@ +# BUG#13684: +# SP: DROP PROCEDURE|FUNCTION IF EXISTS not binlogged if routine +# does not exist +# +# There is an inconsistency with DROP DATABASE IF EXISTS, DROP +# TABLE IF EXISTS and DROP VIEW IF EXISTS: those are binlogged even +# if the DB or TABLE does not exist, whereas DROP PROCEDURE IF +# EXISTS does not. It would be nice or at least consistent if DROP +# PROCEDURE/STATEMENT worked the same too. +# +# Description: +# DROP PROCEDURE|FUNCTION IF EXISTS does not get binlogged whereas DROP +# DATABASE|TABLE|TRIGGER|... IF EXISTS do. +# +# Fixed DROP PROCEDURE|FUNCTION IF EXISTS by adding a call to +# write_bin_log in mysql_execute_command. Checked also if all +# documented "DROP (...) IF EXISTS" get binlogged. Left out DROP +# SERVER IF EXISTS because it seems that it only gets binlogged when +# using row event (see BUG#25705). +# +# TODO: add DROP SERVER IF EXISTS to the test case when its +# binlogging procedure gets fixed (BUG#25705). Furthermore, when +# logging in RBR format the events that get logged are effectively in +# RBR format and not in STATEMENT format meaning that one must needs +# to be extra careful when writing a test for it, or change the CREATE +# SERVER logging to always log as STATEMENT. You can quickly check this +# by enabling the flag below $fixed_bug_25705=1 and watch the diff on +# the STDOUT. More detail may be found on the generated reject file. +# +# Test is implemented as follows: +# +# i) test each "drop if exists" (DDL), found in MySQL 5.1 manual, +# on inexistent objects (except for DROP SERVER); +# ii) show binlog events; +# iii) create an object for each drop if exists statement; +# iv) issue "drop if exists" in existent objects. +# v) show binlog events; +# +# References: +# http://dev.mysql.com/doc/refman/5.1/en/sql-syntax-data-definition.html +# +--source include/have_log_bin.inc +RESET MASTER; + +disable_warnings; + +# test all "drop if exists" in manual with inexistent objects +DROP PROCEDURE IF EXISTS db_bug_13684.p; +DROP FUNCTION IF EXISTS db_bug_13684.f; +DROP TRIGGER IF EXISTS db_bug_13684.tr; +DROP VIEW IF EXISTS db_bug_13684.v; +DROP EVENT IF EXISTS db_bug_13684.e; +DROP TABLE IF EXISTS db_bug_13684.t; +DROP DATABASE IF EXISTS db_bug_13684; + +let $fixed_bug_25705 = 0; + +if($fixed_bug_25705) +{ + DROP SERVER IF EXISTS s_bug_13684; +} +--source include/show_binlog_events.inc + +# test drop with existing values + +# create +CREATE DATABASE db_bug_13684; + +CREATE TABLE db_bug_13684.t (a int); + +CREATE EVENT db_bug_13684.e + ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR + DO + UPDATE db_bug_13684.t SET a = a + 1; + +CREATE VIEW db_bug_13684.v + AS SELECT * FROM db_bug_13684.t; + +CREATE TRIGGER db_bug_13684.tr BEFORE INSERT ON db_bug_13684.t + FOR EACH ROW BEGIN + END; + +CREATE PROCEDURE db_bug_13684.p (OUT p1 INT) + BEGIN + END; + +CREATE FUNCTION db_bug_13684.f (s CHAR(20)) + RETURNS CHAR(50) DETERMINISTIC + RETURN s; + +if($fixed_bug_25705) +{ + CREATE SERVER s_bug_13684 + FOREIGN DATA WRAPPER mysql + OPTIONS (USER 'Remote', HOST '192.168.1.106', DATABASE 'test'); +} + +--source include/show_binlog_events.inc + +# drop existing +DROP PROCEDURE IF EXISTS db_bug_13684.p; +DROP FUNCTION IF EXISTS db_bug_13684.f; +DROP TRIGGER IF EXISTS db_bug_13684.tr; +DROP VIEW IF EXISTS db_bug_13684.v; +DROP EVENT IF EXISTS db_bug_13684.e; +DROP TABLE IF EXISTS db_bug_13684.t; +DROP DATABASE IF EXISTS db_bug_13684; +if($fixed_bug_25705) +{ + DROP SERVER IF EXISTS s_bug_13684; +} + +--source include/show_binlog_events.inc + +enable_warnings; diff --git a/mysql-test/t/backup.test b/mysql-test/t/backup.test index 61e80ec682ebb3f80adaf7869a4a2cbc420442da..c761f48cbcb50bddc22b84157290930915a413ea 100644 --- a/mysql-test/t/backup.test +++ b/mysql-test/t/backup.test @@ -1,7 +1,10 @@ # The server need to be started in $MYSQLTEST_VARDIR since it # uses ../../std_data/ --- source include/uses_vardir.inc +--source include/uses_vardir.inc + +# Save the initial number of concurrent sessions +--source include/count_sessions.inc # # This test is a bit tricky as we can't use backup table to overwrite an old @@ -57,6 +60,9 @@ unlock tables; connection con1; reap; drop table t5; +connection default; +disconnect con1; +disconnect con2; remove_file $MYSQLTEST_VARDIR/tmp/t1.MYD; remove_file $MYSQLTEST_VARDIR/tmp/t2.MYD; remove_file $MYSQLTEST_VARDIR/tmp/t3.MYD; @@ -68,6 +74,7 @@ remove_file $MYSQLTEST_VARDIR/tmp/t3.frm; remove_file $MYSQLTEST_VARDIR/tmp/t4.frm; remove_file $MYSQLTEST_VARDIR/tmp/t5.frm; + # End of 4.1 tests # End of 5.0 tests @@ -87,4 +94,11 @@ DROP TABLE `t+1`; RESTORE TABLE `t+1` FROM '../../tmp'; SELECT * FROM `t+1`; DROP TABLE `t+1`; +# +remove_file $MYSQLTEST_VARDIR/tmp/t@002b1.frm; +remove_file $MYSQLTEST_VARDIR/tmp/t@002b1.MYD; + + +# Wait till all disconnects are completed +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/check.test b/mysql-test/t/check.test index 363f9d419d64c20b3fe9b1a5d917d852ce6f848e..ff23b352b5a26943d5e36a3a17a662a061ef51b1 100644 --- a/mysql-test/t/check.test +++ b/mysql-test/t/check.test @@ -1,3 +1,6 @@ +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + connect (con1,localhost,root,,); connect (con2,localhost,root,,); connection con1; @@ -21,16 +24,18 @@ connection con2; insert into t1 values (200000); connection con1; reap; +connection default; +disconnect con1; +disconnect con2; drop table t1; + # End of 4.1 tests # -# Bug #9897 Views: 'Check Table' crashes MySQL, with a view and a table -# in the statement +# Bug#9897 Views: 'Check Table' crashes MySQL, with a view and a table +# in the statement # - -connection default; Create table t1(f1 int); Create table t2(f1 int); Create view v1 as Select * from t1; @@ -38,11 +43,15 @@ Check Table v1,t2; drop view v1; drop table t1, t2; + # -# BUG#26325 - TEMPORARY TABLE "corrupt" after first read, according to CHECK -# TABLE +# Bug#26325 TEMPORARY TABLE "corrupt" after first read, according to CHECK TABLE # CREATE TEMPORARY TABLE t1(a INT); CHECK TABLE t1; REPAIR TABLE t1; DROP TABLE t1; + + +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/compress.test b/mysql-test/t/compress.test index cd40aef002c86fba529b2ed88a8e2644a2c59c1d..0a20daef8de3a3820281050f0ced9c5003c64fde 100644 --- a/mysql-test/t/compress.test +++ b/mysql-test/t/compress.test @@ -6,6 +6,10 @@ -- source include/have_compress.inc +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + + connect (comp_con,localhost,root,,,,,COMPRESS); # Check compression turned on @@ -17,3 +21,10 @@ select * from information_schema.session_status where variable_name= 'COMPRESSIO # Check compression turned on SHOW STATUS LIKE 'Compression'; + +connection default; +disconnect comp_con; + +# Wait till all disconnects are completed +--source include/wait_until_count_sessions.inc + diff --git a/mysql-test/t/fulltext.test b/mysql-test/t/fulltext.test index 852369fd56804d692d5647cbba89708cdcdc4f66..11dbff5ce9af094ca3144c765dc6470759bc8f8c 100644 --- a/mysql-test/t/fulltext.test +++ b/mysql-test/t/fulltext.test @@ -454,3 +454,11 @@ INSERT INTO t1 VALUES('aaa15'); SELECT MATCH(a) AGAINST('aaa1* aaa14 aaa16' IN BOOLEAN MODE) FROM t1; SELECT MATCH(a) AGAINST('aaa1* aaa14 aaa15 aaa16' IN BOOLEAN MODE) FROM t1; DROP TABLE t1; + +# +# BUG#36737 - having + full text operator crashes mysql +# +CREATE TABLE t1(a TEXT); +--error ER_WRONG_ARGUMENTS +SELECT GROUP_CONCAT(a) AS st FROM t1 HAVING MATCH(st) AGAINST('test' IN BOOLEAN MODE); +DROP TABLE t1; diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 5d77c678d52d61187b4136b8db1527648c30e9e8..b71dbe91467e9cf61c88f550cdfb915cdb9f06d4 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -1273,4 +1273,13 @@ select format(a, 2) from t1; --disable_metadata drop table t1; +# +# Bug #41868: crash or memory overrun with concat + upper, date_format functions +# + +CREATE TABLE t1 (c DATE, aa VARCHAR(30)); +INSERT INTO t1 VALUES ('2008-12-31','aaaaaa'); +SELECT DATE_FORMAT(c, GET_FORMAT(DATE, 'eur')) h, CONCAT(UPPER(aa),', ', aa) i FROM t1; +DROP TABLE t1; + --echo End of 5.0 tests diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test index a9491dc2736fc1f8c90b7771c248648148dc2e1d..2e42bdbf06cebee66029d5a1c2d10c1a81d9ecea 100644 --- a/mysql-test/t/grant.test +++ b/mysql-test/t/grant.test @@ -3,6 +3,9 @@ # Grant tests not performed with embedded server -- source include/not_embedded.inc +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + SET @old_log_bin_trust_function_creators= @@global.log_bin_trust_function_creators; SET GLOBAL log_bin_trust_function_creators = 1; @@ -81,7 +84,7 @@ delete from mysql.db where user='mysqltest_1'; delete from mysql.tables_priv where user='mysqltest_1'; delete from mysql.columns_priv where user='mysqltest_1'; flush privileges; ---error 1141 +--error ER_NONEXISTING_GRANT show grants for mysqltest_1@localhost; # @@ -119,15 +122,15 @@ drop table t1; # # Test some error conditions # ---error 1221 +--error ER_WRONG_USAGE GRANT FILE on mysqltest.* to mysqltest_1@localhost; -select 1; # To test that the previous command didn't cause problems +select 1; # To test that the previous command didn't cause problems # -# Bug #4898: User privileges depending on ORDER BY Settings of table db +# Bug#4898 User privileges depending on ORDER BY Settings of table db # insert into mysql.user (host, user) values ('localhost', 'test11'); -insert into mysql.db (host, db, user, select_priv) values +insert into mysql.db (host, db, user, select_priv) values ('localhost', 'a%', 'test11', 'Y'), ('localhost', 'ab%', 'test11', 'Y'); alter table mysql.db order by db asc; flush privileges; @@ -139,7 +142,7 @@ delete from mysql.user where user='test11'; delete from mysql.db where user='test11'; # -# Bug#6123: GRANT USAGE inserts useless Db row +# Bug#6123 GRANT USAGE inserts useless Db row # create database mysqltest1; grant usage on mysqltest1.* to test6123 identified by 'magic123'; @@ -148,7 +151,7 @@ delete from mysql.user where user='test6123'; drop database mysqltest1; # -# Test for 'drop user', 'revoke privileges, grant' +# Test for 'drop user', 'revoke privileges, grant' # create table t1 (a int); @@ -163,7 +166,7 @@ grant select(a) on test.t1 to drop_user@localhost; show grants for drop_user@localhost; # -# Bug3086 +# Bug#3086 SHOW GRANTS doesn't follow ANSI_QUOTES # set sql_mode=ansi_quotes; show grants for drop_user@localhost; @@ -181,7 +184,7 @@ show grants for drop_user@localhost; revoke all privileges, grant option from drop_user@localhost; show grants for drop_user@localhost; drop user drop_user@localhost; ---error 1269 +--error ER_REVOKE_GRANTS revoke all privileges, grant option from drop_user@localhost; grant select(a) on test.t1 to drop_user1@localhost; @@ -191,10 +194,10 @@ grant select on *.* to drop_user4@localhost; # Drop user now implicitly revokes all privileges. drop user drop_user1@localhost, drop_user2@localhost, drop_user3@localhost, drop_user4@localhost; ---error 1269 +--error ER_REVOKE_GRANTS revoke all privileges, grant option from drop_user1@localhost, drop_user2@localhost, drop_user3@localhost, drop_user4@localhost; ---error 1396 +--error ER_CANNOT_USER drop user drop_user1@localhost, drop_user2@localhost, drop_user3@localhost, drop_user4@localhost; drop table t1; @@ -204,12 +207,12 @@ show grants for mysqltest_1@localhost; drop user mysqltest_1@localhost; # -# Bug #3403 Wrong encodin in SHOW GRANTS output +# Bug#3403 Wrong encoding in SHOW GRANTS output # SET NAMES koi8r; CREATE DATABASE ÂÄ; USE ÂÄ; -CREATE TABLE ÔÁ (ËÏÌ int); +CREATE TABLE ÔÁ (ËÏÌ INT); GRANT SELECT ON ÂÄ.* TO ÀÚÅÒ@localhost; SHOW GRANTS FOR ÀÚÅÒ@localhost; @@ -230,7 +233,7 @@ DROP DATABASE SET NAMES latin1; # -# Bug #5831: REVOKE ALL PRIVILEGES, GRANT OPTION does not revoke everything +# Bug#5831 REVOKE ALL PRIVILEGES, GRANT OPTION does not revoke everything # USE test; CREATE TABLE t1 (a int ); @@ -299,7 +302,7 @@ DROP DATABASE testdb9; DROP DATABASE testdb10; # -# Bug #6932: a problem with 'revoke ALL PRIVILEGES' +# Bug#6932 a problem with 'revoke ALL PRIVILEGES' # create table t1(a int, b int, c int, d int); @@ -313,7 +316,7 @@ drop user grant_user@localhost; drop table t1; # -# Bug#7391: Cross-database multi-table UPDATE security problem +# Bug#7391 Cross-database multi-table UPDATE security problem # create database mysqltest_1; create database mysqltest_2; @@ -322,36 +325,36 @@ create table mysqltest_1.t2 select 1 b, 2 r; create table mysqltest_2.t1 select 1 c, 2 s; create table mysqltest_2.t2 select 1 d, 2 t; -#test the column privileges +# test the column privileges grant update (a) on mysqltest_1.t1 to mysqltest_3@localhost; grant select (b) on mysqltest_1.t2 to mysqltest_3@localhost; grant select (c) on mysqltest_2.t1 to mysqltest_3@localhost; grant update (d) on mysqltest_2.t2 to mysqltest_3@localhost; connect (conn1,localhost,mysqltest_3,,); connection conn1; -SELECT * FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES - WHERE GRANTEE = '''mysqltest_3''@''localhost''' +SELECT * FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES + WHERE GRANTEE = '''mysqltest_3''@''localhost''' ORDER BY TABLE_NAME,COLUMN_NAME,PRIVILEGE_TYPE; SELECT * FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES - WHERE GRANTEE = '''mysqltest_3''@''localhost''' + WHERE GRANTEE = '''mysqltest_3''@''localhost''' ORDER BY TABLE_NAME,PRIVILEGE_TYPE; SELECT * from INFORMATION_SCHEMA.SCHEMA_PRIVILEGES - WHERE GRANTEE = '''mysqltest_3''@''localhost''' + WHERE GRANTEE = '''mysqltest_3''@''localhost''' ORDER BY TABLE_SCHEMA,PRIVILEGE_TYPE; SELECT * from INFORMATION_SCHEMA.USER_PRIVILEGES WHERE GRANTEE = '''mysqltest_3''@''localhost''' ORDER BY TABLE_CATALOG,PRIVILEGE_TYPE; ---error 1143 +--error ER_COLUMNACCESS_DENIED_ERROR update mysqltest_1.t1, mysqltest_1.t2 set q=10 where b=1; ---error 1143 +--error ER_COLUMNACCESS_DENIED_ERROR update mysqltest_1.t2, mysqltest_2.t2 set d=20 where d=1; ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR update mysqltest_1.t1, mysqltest_2.t2 set d=20 where d=1; ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR update mysqltest_2.t1, mysqltest_1.t2 set c=20 where b=1; ---error 1143 +--error ER_COLUMNACCESS_DENIED_ERROR update mysqltest_2.t1, mysqltest_2.t2 set d=10 where s=2; -#the following two should work +# the following two should work update mysqltest_1.t1, mysqltest_2.t2 set a=10,d=10; update mysqltest_1.t1, mysqltest_2.t1 set a=20 where c=20; connection master; @@ -362,7 +365,7 @@ revoke all on mysqltest_1.t2 from mysqltest_3@localhost; revoke all on mysqltest_2.t1 from mysqltest_3@localhost; revoke all on mysqltest_2.t2 from mysqltest_3@localhost; -#test the db/table level privileges +# test the db/table level privileges grant all on mysqltest_2.* to mysqltest_3@localhost; grant select on *.* to mysqltest_3@localhost; # Next grant is needed to trigger bug#7391. Do not optimize! @@ -374,17 +377,17 @@ connection conn2; use mysqltest_1; update mysqltest_2.t1, mysqltest_2.t2 set c=500,d=600; # the following failed before, should fail now. ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR update mysqltest_1.t1, mysqltest_1.t2 set a=100,b=200; use mysqltest_2; -#the following used to succeed, it must fail now. ---error 1142 +# the following used to succeed, it must fail now. +--error ER_TABLEACCESS_DENIED_ERROR update mysqltest_1.t1, mysqltest_1.t2 set a=100,b=200; ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR update mysqltest_2.t1, mysqltest_1.t2 set c=100,b=200; ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR update mysqltest_1.t1, mysqltest_2.t2 set a=100,d=200; -#lets see the result +# lets see the result connection master; select t1.*,t2.* from mysqltest_1.t1,mysqltest_1.t2; select t1.*,t2.* from mysqltest_2.t1,mysqltest_2.t2; @@ -396,6 +399,7 @@ delete from mysql.columns_priv where user="mysqltest_3"; flush privileges; drop database mysqltest_1; drop database mysqltest_2; +disconnect conn2; # # just SHOW PRIVILEGES test @@ -403,7 +407,7 @@ drop database mysqltest_2; SHOW PRIVILEGES; # -# Rights for renaming test (Bug #3270) +# Rights for renaming test (Bug#3270) # connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK); connection root; @@ -414,16 +418,18 @@ create table mysqltest.t1 (a int,b int,c int); grant all on mysqltest.t1 to mysqltest_1@localhost; connect (user1,localhost,mysqltest_1,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK); connection user1; --- error 1142 +-- error ER_TABLEACCESS_DENIED_ERROR alter table t1 rename t2; disconnect user1; connection root; revoke all privileges on mysqltest.t1 from mysqltest_1@localhost; delete from mysql.user where user=_binary'mysqltest_1'; drop database mysqltest; +connection default; +disconnect root; # -# check all new table priveleges +# check all new table privileges # CREATE USER dummy@localhost; CREATE DATABASE mysqltest; @@ -488,7 +494,7 @@ REVOKE ALL PRIVILEGES, GRANT OPTION FROM dummy@localhost; DROP USER dummy@localhost; DROP DATABASE mysqltest; # -# Bug #11330: Entry in tables_priv with host = '' causes crash +# Bug#11330 Entry in tables_priv with host = '' causes crash # connection default; use mysql; @@ -499,7 +505,7 @@ flush privileges; use test; # -# Bug #10892 user variables not auto cast for comparisons +# Bug#10892 user variables not auto cast for comparisons # Check that we don't get illegal mix of collations # set @user123="non-existent"; @@ -518,18 +524,18 @@ show grants for root@localhost; set names latin1; # -# Bug #15598 Server crashes in specific case during setting new password +# Bug#15598 Server crashes in specific case during setting new password # - Caused by a user with host '' # create user mysqltest_7@; set password for mysqltest_7@ = password('systpass'); show grants for mysqltest_7@; drop user mysqltest_7@; ---error 1141 +--error ER_NONEXISTING_GRANT show grants for mysqltest_7@; # -# Bug#14385: GRANT and mapping to correct user account problems +# Bug#14385 GRANT and mapping to correct user account problems # create database mysqltest; use mysqltest; @@ -545,7 +551,7 @@ flush privileges; drop database mysqltest; # -# Bug #27515: DROP previlege is not required for RENAME TABLE +# Bug#27515 DROP previlege is not required for RENAME TABLE # connection master; create database db27515; @@ -556,7 +562,7 @@ grant insert, create on db27515.t2 to user27515@localhost; connect (conn27515, localhost, user27515, , db27515); connection conn27515; ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR rename table t1 to t2; disconnect conn27515; @@ -568,7 +574,7 @@ drop database db27515; --echo End of 4.1 tests # -# Bug #16297 In memory grant tables not flushed when users's hostname is "" +# Bug#16297 In memory grant tables not flushed when users's hostname is "" # use test; create table t1 (a int); @@ -585,11 +591,11 @@ create user mysqltest_8; create user mysqltest_8@host8; # Try to create them again ---error 1396 +--error ER_CANNOT_USER create user mysqltest_8@''; ---error 1396 +--error ER_CANNOT_USER create user mysqltest_8; ---error 1396 +--error ER_CANNOT_USER create user mysqltest_8@host8; select user, QUOTE(host) from mysql.user where user="mysqltest_8"; @@ -684,44 +690,43 @@ flush privileges; show grants for mysqltest_8@''; show grants for mysqltest_8; drop user mysqltest_8@''; ---error 1141 +--error ER_NONEXISTING_GRANT show grants for mysqltest_8@''; show grants for mysqltest_8; select * from information_schema.user_privileges where grantee like "'mysqltest_8'%"; drop user mysqltest_8; --replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT ---error 1045 +--error ER_ACCESS_DENIED_ERROR connect (conn6,localhost,mysqltest_8,,); connection master; ---error 1141 +--error ER_NONEXISTING_GRANT show grants for mysqltest_8; drop user mysqltest_8@host8; ---error 1141 +--error ER_NONEXISTING_GRANT show grants for mysqltest_8@host8; # Restore the anonymous users. insert into mysql.user select * from t2; flush privileges; drop table t2; - drop table t1; # -# Bug#20214: Incorrect error when user calls SHOW CREATE VIEW on non -# privileged view +# Bug#20214 Incorrect error when user calls SHOW CREATE VIEW on non +# privileged view # connection master; CREATE DATABASE mysqltest3; -use mysqltest3; +USE mysqltest3; CREATE TABLE t_nn (c1 INT); CREATE VIEW v_nn AS SELECT * FROM t_nn; CREATE DATABASE mysqltest2; -use mysqltest2; +USE mysqltest2; CREATE TABLE t_nn (c1 INT); CREATE VIEW v_nn AS SELECT * FROM t_nn; @@ -743,24 +748,18 @@ SHOW CREATE VIEW mysqltest2.v_nn; --error ER_TABLEACCESS_DENIED_ERROR SHOW CREATE TABLE mysqltest2.v_nn; - - # fail because of missing SHOW VIEW --error ER_TABLEACCESS_DENIED_ERROR SHOW CREATE VIEW mysqltest2.v_yn; --error ER_TABLEACCESS_DENIED_ERROR SHOW CREATE TABLE mysqltest2.v_yn; - - # succeed (despite of missing SELECT, having SHOW VIEW bails us out) SHOW CREATE TABLE mysqltest2.v_ny; # succeed (despite of missing SELECT, having SHOW VIEW bails us out) SHOW CREATE VIEW mysqltest2.v_ny; - - # fail because of missing (specific or generic) SELECT --error ER_TABLEACCESS_DENIED_ERROR SHOW CREATE TABLE mysqltest3.t_nn; @@ -769,16 +768,12 @@ SHOW CREATE TABLE mysqltest3.t_nn; --error ER_TABLEACCESS_DENIED_ERROR SHOW CREATE VIEW mysqltest3.t_nn; - - # fail because of missing missing (specific or generic) SELECT (and SHOW VIEW) --error ER_TABLEACCESS_DENIED_ERROR SHOW CREATE VIEW mysqltest3.v_nn; --error ER_TABLEACCESS_DENIED_ERROR SHOW CREATE TABLE mysqltest3.v_nn; - - # succeed thanks to generic SELECT SHOW CREATE TABLE mysqltest2.t_nn; @@ -786,17 +781,13 @@ SHOW CREATE TABLE mysqltest2.t_nn; --error ER_WRONG_OBJECT SHOW CREATE VIEW mysqltest2.t_nn; - - # succeed, have SELECT and SHOW VIEW SHOW CREATE VIEW mysqltest2.v_yy; # succeed, have SELECT and SHOW VIEW SHOW CREATE TABLE mysqltest2.v_yy; - - -#clean-up +# clean-up connection master; # succeed, we're root @@ -809,38 +800,33 @@ SHOW CREATE TABLE mysqltest2.t_nn; --error ER_WRONG_OBJECT SHOW CREATE VIEW mysqltest2.t_nn; - - DROP VIEW mysqltest2.v_nn; DROP VIEW mysqltest2.v_yn; DROP VIEW mysqltest2.v_ny; DROP VIEW mysqltest2.v_yy; - DROP TABLE mysqltest2.t_nn; - DROP DATABASE mysqltest2; - - - DROP VIEW mysqltest3.v_nn; DROP TABLE mysqltest3.t_nn; - DROP DATABASE mysqltest3; - +disconnect mysqltest_1; REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'mysqltest_1'@'localhost'; DROP USER 'mysqltest_1'@'localhost'; # restore the original database -use test; +USE test; +connection default; +disconnect master; + # -# Bug #10668: CREATE USER does not enforce username length limit +# Bug#10668 CREATE USER does not enforce username length limit # --error ER_WRONG_STRING_LENGTH create user mysqltest1_thisisreallytoolong; # -# Test for BUG#16899: Possible buffer overflow in handling of DEFINER-clause. +# Test for Bug#16899 Possible buffer overflow in handling of DEFINER-clause. # # These checks are intended to ensure that appropriate errors are risen when # illegal user name or hostname is specified in user-clause of GRANT/REVOKE @@ -848,7 +834,7 @@ create user mysqltest1_thisisreallytoolong; # # -# Bug #22369: Alter table rename combined with other alterations causes lost tables +# Bug#22369 Alter table rename combined with other alterations causes lost tables # CREATE DATABASE mysqltest1; CREATE TABLE mysqltest1.t1 ( @@ -968,7 +954,7 @@ REVOKE EXECUTE ON PROCEDURE t1 FROM some_user_name@1234567890abcdefghij123456789 # -# BUG#23556: TRUNCATE TABLE still maps to DELETE +# Bug#23556 TRUNCATE TABLE still maps to DELETE # CREATE USER bug23556@localhost; CREATE DATABASE bug23556; @@ -1000,8 +986,12 @@ DROP TABLE t1; USE test; DROP DATABASE bug23556; DROP USER bug23556@localhost; +connection default; +disconnect bug23556; + + # -# Bug #6774: Replication fails with Wrong usage of DB GRANT and GLOBAL PRIVILEGES +# Bug#6774 Replication fails with Wrong usage of DB GRANT and GLOBAL PRIVILEGES # # Check if GRANT ... ON * ... fails when no database is selected connect (con1, localhost, root,,*NO-ONE*); @@ -1013,7 +1003,7 @@ connection default; # -# BUG#9504: Stored procedures: execute privilege doesn't make 'use database' +# Bug#9504 Stored procedures: execute privilege doesn't make 'use database' # okay. # @@ -1038,8 +1028,8 @@ CREATE PROCEDURE mysqltest2.p_inv() SQL SECURITY INVOKER SELECT 1; CREATE FUNCTION mysqltest3.f_def() RETURNS INT SQL SECURITY DEFINER - RETURN 1; - + RETURN 1; + CREATE FUNCTION mysqltest4.f_inv() RETURNS INT SQL SECURITY INVOKER RETURN 1; @@ -1095,7 +1085,7 @@ DROP USER mysqltest_1@localhost; # -# BUG#27337: Privileges are not restored properly. +# Bug#27337 Privileges are not restored properly. # # Actually, the patch for this bugs fixes two problems. So, here are two test # cases. @@ -1157,7 +1147,7 @@ DROP DATABASE mysqltest2; DROP USER mysqltest_1@localhost; -# Test case 2: priveleges are not checked properly for prepared statements. +# Test case 2: privileges are not checked properly for prepared statements. # Prepare. @@ -1230,6 +1220,7 @@ EXECUTE stmt2; --echo --echo ---> connection: default +--disconnect bug27337_con1 --disconnect bug27337_con2 DROP DATABASE mysqltest1; @@ -1239,21 +1230,21 @@ DROP USER mysqltest_1@localhost; DROP USER mysqltest_2@localhost; # -# Bug#27878: Unchecked privileges on a view referring to a table from another -# database. +# Bug#27878 Unchecked privileges on a view referring to a table from another +# database. # -use test; +USE test; CREATE TABLE t1 (f1 int, f2 int); INSERT INTO t1 VALUES(1,1), (2,2); CREATE DATABASE db27878; GRANT UPDATE(f1) ON t1 TO 'mysqltest_1'@'localhost'; GRANT SELECT ON `test`.* TO 'mysqltest_1'@'localhost'; GRANT ALL ON db27878.* TO 'mysqltest_1'@'localhost'; -use db27878; +USE db27878; CREATE SQL SECURITY INVOKER VIEW db27878.v1 AS SELECT * FROM test.t1; connect (user1,localhost,mysqltest_1,,test); connection user1; -use db27878; +USE db27878; --error 1356 UPDATE v1 SET f2 = 4; SELECT * FROM test.t1; @@ -1264,7 +1255,7 @@ REVOKE SELECT ON `test`.* FROM 'mysqltest_1'@'localhost'; REVOKE ALL ON db27878.* FROM 'mysqltest_1'@'localhost'; DROP USER mysqltest_1@localhost; DROP DATABASE db27878; -use test; +USE test; DROP TABLE t1; --echo # @@ -1273,8 +1264,10 @@ DROP TABLE t1; CREATE TEMPORARY TABLE mysql.user (id INT); FLUSH PRIVILEGES; DROP TABLE mysql.user; + + # -# Bug #33201 Crash occurs when granting update privilege on one column of a view +# Bug#33201 Crash occurs when granting update privilege on one column of a view # drop table if exists test; drop function if exists test_function; @@ -1305,7 +1298,7 @@ SET PASSWORD FOR CURRENT_USER() = PASSWORD(""); --echo End of 5.0 tests # -# Bug#21432: Database/Table name limited to 64 bytes, not chars, problems with multi-byte +# Bug#21432 Database/Table name limited to 64 bytes, not chars, problems with multi-byte # set names utf8; grant select on test.* to юзер_юзер@localhost; @@ -1317,7 +1310,7 @@ grant select on test.* to очень_длинный_юзер@localhost; set names default; # -# Bug #20901 - CREATE privilege is enough to insert into a table +# Bug#20901 CREATE privilege is enough to insert into a table # create database mysqltest; @@ -1329,7 +1322,7 @@ create table t1 (i INT); connect (user1,localhost,mysqltest,,mysqltest); connection user1; # show we don't have INSERT ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR insert into t1 values (1); # show we have CREATE create table t2 (i INT); @@ -1348,11 +1341,11 @@ insert into t2 values (1); # CREATE IF NOT EXISTS...SELECT, t1 exists, no INSERT, must fail ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR create table if not exists t1 select * from t2; # CREATE IF NOT EXISTS...SELECT, no t3 yet, no INSERT, must fail ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR create table if not exists t3 select * from t2; # CREATE IF NOT EXISTS...SELECT, t4 exists, have INSERT, must succeed @@ -1366,7 +1359,7 @@ create table if not exists t5 select * from t2; create table t6 select * from t2; # CREATE...SELECT, no t7 yet, no INSERT, must fail ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR create table t7 select * from t2; # CREATE...SELECT, t4 exists, have INSERT, must still fail (exists) @@ -1374,7 +1367,7 @@ create table t7 select * from t2; create table t4 select * from t2; # CREATE...SELECT, t1 exists, no INSERT, must fail ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR create table t1 select * from t2; @@ -1394,7 +1387,7 @@ use test; # -# Bug #16470 crash on grant if old grant tables +# Bug#16470 crash on grant if old grant tables # --echo FLUSH PRIVILEGES without procs_priv table. RENAME TABLE mysql.procs_priv TO mysql.procs_gone; @@ -1415,7 +1408,7 @@ FLUSH PRIVILEGES; # -# Bug#33464: DROP FUNCTION caused a crash. +# Bug#33464 DROP FUNCTION caused a crash. # CREATE DATABASE dbbug33464; CREATE USER 'userbug33464'@'localhost'; @@ -1472,8 +1465,11 @@ DROP PROCEDURE sp3; --error 0, ER_CANNOT_USER DROP USER 'userbug33464'@'localhost'; -use test; +USE test; DROP DATABASE dbbug33464; SET @@global.log_bin_trust_function_creators= @old_log_bin_trust_function_creators; + +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 7105d7e04f0de208159d4e34eb00122f09f49c53..ef6e3eaca123e5663f4c124d2be8edcf1c8f48e8 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -5,6 +5,10 @@ # on the presence of the log tables (which are CSV-based). --source include/have_csv.inc +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + + # Test for information_schema.schemata & # show databases @@ -44,11 +48,11 @@ create view v1 (c) as table_name<>'ndb_apply_status'; select * from v1; -select c,table_name from v1 +select c,table_name from v1 inner join information_schema.TABLES v2 on (v1.c=v2.table_name) where v1.c like "t%"; -select c,table_name from v1 +select c,table_name from v1 left join information_schema.TABLES v2 on (v1.c=v2.table_name) where v1.c like "t%"; @@ -77,16 +81,17 @@ grant select (a) on mysqltest.t1 to mysqltest_2@localhost; grant select on mysqltest.v1 to mysqltest_3; connect (user3,localhost,mysqltest_2,,); connection user3; -select table_name, column_name, privileges from information_schema.columns +select table_name, column_name, privileges from information_schema.columns where table_schema = 'mysqltest' and table_name = 't1'; show columns from mysqltest.t1; connect (user4,localhost,mysqltest_3,,mysqltest); connection user4; select table_name, column_name, privileges from information_schema.columns where table_schema = 'mysqltest' and table_name = 'v1'; ---error 1345 +--error ER_VIEW_NO_EXPLAIN explain select * from v1; connection default; +disconnect user4; drop view v1, mysqltest.v1; drop tables mysqltest.t4, mysqltest.t1, t2, t3, t5; @@ -136,7 +141,7 @@ delimiter ;| # # Bug#7222 information_schema: errors in "routines" # -select parameter_style, sql_data_access, dtd_identifier +select parameter_style, sql_data_access, dtd_identifier from information_schema.routines where routine_schema='test'; --replace_column 5 # 6 # @@ -163,7 +168,7 @@ drop view v1; connect (user1,localhost,mysqltest_1,,); connection user1; select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES; ---error 1305 +--error ER_SP_DOES_NOT_EXIST show create function sub1; connection user3; select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES; @@ -182,6 +187,7 @@ show create function sub2; show function status like "sub2"; connection default; disconnect user1; +disconnect user3; drop function sub2; show create procedure sel2; @@ -321,7 +327,7 @@ drop view v1; create table t1(a NUMERIC(5,3), b NUMERIC(5,1), c float(5,2), d NUMERIC(6,4), e float, f DECIMAL(6,3), g int(11), h DOUBLE(10,3), i DOUBLE); -select COLUMN_NAME,COLUMN_TYPE, CHARACTER_MAXIMUM_LENGTH, +select COLUMN_NAME,COLUMN_TYPE, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE from information_schema.columns where table_name= 't1'; drop table t1; @@ -334,7 +340,7 @@ drop table t115; delimiter //; create procedure p108 () begin declare c cursor for select data_type from information_schema.columns; open c; open c; end;// ---error 1325 +--error ER_SP_CURSOR_ALREADY_OPEN call p108()// delimiter ;// drop procedure p108; @@ -344,24 +350,24 @@ where table_name= "user"; select * from v1; drop view v1; -create view vo as select 'a' union select 'a'; +create view vo as select 'a' union select 'a'; show index from vo; select * from information_schema.TABLE_CONSTRAINTS where TABLE_NAME= "vo"; select * from information_schema.KEY_COLUMN_USAGE where -TABLE_NAME= "vo"; +TABLE_NAME= "vo"; drop view vo; select TABLE_NAME,TABLE_TYPE,ENGINE -from information_schema.tables +from information_schema.tables where table_schema='information_schema' limit 2; show tables from information_schema like "T%"; ---error 1044 +--error ER_DBACCESS_DENIED_ERROR create database information_schema; use information_schema; show full tables like "T%"; ---error 1109 +--error ER_UNKNOWN_TABLE create table t1(a int); use test; show tables; @@ -369,15 +375,15 @@ use information_schema; show tables like "T%"; # -# Bug#7210: information_schema: can't access when table-name = reserved word +# Bug#7210 information_schema: can't access when table-name = reserved word # select table_name from tables where table_name='user'; select column_name, privileges from columns where table_name='user' and column_name like '%o%'; # -# Bug#7212: information_schema: "Can't find file" errors if storage engine gone -# Bug#7211: information_schema: crash if bad view +# Bug#7212 information_schema: "Can't find file" errors if storage engine gone +# Bug#7211 information_schema: crash if bad view # use test; create function sub1(i int) returns int @@ -404,9 +410,9 @@ drop view v3; drop table t4; # -# Bug#7213: information_schema: redundant non-standard TABLE_NAMES table +# Bug#7213 information_schema: redundant non-standard TABLE_NAMES table # ---error 1109 +--error ER_UNKNOWN_TABLE select * from information_schema.table_names; # @@ -419,7 +425,7 @@ where table_schema="information_schema" and table_name="COLUMNS" and # # Bug#2718 information_schema: errors in "tables" # -select TABLE_ROWS from information_schema.tables where +select TABLE_ROWS from information_schema.tables where table_schema="information_schema" and table_name="COLUMNS"; select table_type from information_schema.tables where table_schema="mysql" and table_name="user"; @@ -432,14 +438,14 @@ show status where variable_name like "%database%"; show variables where variable_name like "skip_show_databas"; # -# Bug #7981:SHOW GLOBAL STATUS crashes server +# Bug#7981 SHOW GLOBAL STATUS crashes server # # We don't actually care about the value, just that it doesn't crash. --replace_column 2 # show global status like "Threads_running"; # -# Bug #7915 crash,JOIN VIEW, subquery, +# Bug#7915 crash,JOIN VIEW, subquery, # SELECT .. FROM INFORMATION_SCHEMA.COLUMNS # create table t1(f1 int); @@ -450,7 +456,7 @@ drop view v1; drop table t1, t2; # -# Bug #7476: crash on SELECT * FROM INFORMATION_SCHEMA.TABLES +# Bug#7476 crash on SELECT * FROM INFORMATION_SCHEMA.TABLES # use test; CREATE TABLE t_crashme ( f1 BIGINT); @@ -478,26 +484,26 @@ drop view a2, a1; drop table t_crashme; # -# Bug #7215 information_schema: columns are longtext instead of varchar -# Bug #7217 information_schema: columns are varbinary() instead of timestamp +# Bug#7215 information_schema: columns are longtext instead of varchar +# Bug#7217 information_schema: columns are varbinary() instead of timestamp # select table_schema,table_name, column_name from -information_schema.columns +information_schema.columns where data_type = 'longtext'; select table_name, column_name, data_type from information_schema.columns where data_type = 'datetime'; # -# Bug #8164 subquery with INFORMATION_SCHEMA.COLUMNS, 100 % CPU +# Bug#8164 subquery with INFORMATION_SCHEMA.COLUMNS, 100 % CPU # SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES A -WHERE NOT EXISTS +WHERE NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS B WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA AND A.TABLE_NAME = B.TABLE_NAME); # -# Bug #9344 INFORMATION_SCHEMA, wrong content, numeric columns +# Bug#9344 INFORMATION_SCHEMA, wrong content, numeric columns # create table t1 @@ -515,21 +521,22 @@ WHERE TABLE_NAME= 't1'; drop table t1; # -# Bug#10261 INFORMATION_SCHEMA.COLUMNS, incomplete result for non root user +# Bug#10261 INFORMATION_SCHEMA.COLUMNS, incomplete result for non root user # grant select on test.* to mysqltest_4@localhost; connect (user10261,localhost,mysqltest_4,,); connection user10261; -SELECT TABLE_NAME, COLUMN_NAME, PRIVILEGES FROM INFORMATION_SCHEMA.COLUMNS +SELECT TABLE_NAME, COLUMN_NAME, PRIVILEGES FROM INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME='TABLE_NAME'; connection default; +disconnect user10261; delete from mysql.user where user='mysqltest_4'; delete from mysql.db where user='mysqltest_4'; flush privileges; # -# Bug #9404 information_schema: Weird error messages +# Bug#9404 information_schema: Weird error messages # with SELECT SUM() ... GROUP BY queries # SELECT table_schema, count(*) FROM information_schema.TABLES WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') AND table_name<>'ndb_binlog_index' AND table_name<>'ndb_apply_status' GROUP BY TABLE_SCHEMA; @@ -570,7 +577,7 @@ drop table t1; # -# Bug #10964 Information Schema:Authorization check on privilege tables is improper +# Bug#10964 Information Schema:Authorization check on privilege tables is improper # create database mysqltest; @@ -614,12 +621,16 @@ select * from information_schema.user_privileges where grantee like '%user%' order by grantee; show grants; connection default; +disconnect con1; +disconnect con2; +disconnect con3; +disconnect con4; drop user user1@localhost, user2@localhost, user3@localhost, user4@localhost; use test; drop database mysqltest; # -# Bug #11055 information_schema: routines.sql_data_access has wrong value +# Bug#11055 information_schema: routines.sql_data_access has wrong value # --disable_warnings drop procedure if exists p1; @@ -634,13 +645,13 @@ drop procedure p1; drop procedure p2; # -# Bug #9434 SHOW CREATE DATABASE information_schema; +# Bug#9434 SHOW CREATE DATABASE information_schema; # show create database information_schema; # -# Bug #11057 information_schema: columns table has some questionable contents -# Bug #12301 information_schema: NUMERIC_SCALE must be 0 for integer columns +# Bug#11057 information_schema: columns table has some questionable contents +# Bug#12301 information_schema: NUMERIC_SCALE must be 0 for integer columns # create table t1(f1 LONGBLOB, f2 LONGTEXT); select column_name,data_type,CHARACTER_OCTET_LENGTH, @@ -656,7 +667,7 @@ where table_name='t1'; drop table t1; # -# Bug #12127 triggers do not show in info_schema before they are used if set to the database +# Bug#12127 triggers do not show in info_schema before they are used if set to the database # create table t1 (f1 integer); create trigger tr1 after insert on t1 for each row set @test_var=42; @@ -678,8 +689,8 @@ show columns from t1; drop table t1; # -# Bug #12636: SHOW TABLE STATUS with where condition containing a subquery -# over information schema +# Bug#12636 SHOW TABLE STATUS with where condition containing a subquery +# over information schema # CREATE TABLE t1 (a int); @@ -693,7 +704,7 @@ SHOW TABLE STATUS FROM test DROP TABLE t1,t2; # -# Bug #12905 show fields from view behaving erratically with current database +# Bug#12905 show fields from view behaving erratically with current database # create table t1(f1 int); create view v1 (c) as select f1 from t1; @@ -701,28 +712,29 @@ connect (con5,localhost,root,,*NO-ONE*); select database(); show fields from test.v1; connection default; +disconnect con5; drop view v1; drop table t1; # -# Bug #9846 Inappropriate error displayed while dropping table from 'INFORMATION_SCHEMA' +# Bug#9846 Inappropriate error displayed while dropping table from 'INFORMATION_SCHEMA' # --error ER_PARSE_ERROR alter database information_schema; ---error 1044 +--error ER_DBACCESS_DENIED_ERROR drop database information_schema; ---error 1044 +--error ER_DBACCESS_DENIED_ERROR drop table information_schema.tables; ---error 1044 +--error ER_DBACCESS_DENIED_ERROR alter table information_schema.tables; # -# Bug #9683 INFORMATION_SCH: Creation of temporary table allowed in Information_schema DB +# Bug#9683 INFORMATION_SCH: Creation of temporary table allowed in Information_schema DB # use information_schema; ---error 1044 +--error ER_DBACCESS_DENIED_ERROR create temporary table schemata(f1 char(10)); # -# Bug #10708 SP's can use INFORMATION_SCHEMA as ROUTINE_SCHEMA +# Bug#10708 SP's can use INFORMATION_SCHEMA as ROUTINE_SCHEMA # delimiter |; --error ER_BAD_DB_ERROR @@ -731,13 +743,13 @@ BEGIN SELECT 'foo' FROM DUAL; END | delimiter ;| -select ROUTINE_NAME from routines where ROUTINE_SCHEMA='information_schema'; +select ROUTINE_NAME from routines where ROUTINE_SCHEMA='information_schema'; # -# Bug #10734 Grant of privileges other than 'select' and 'create view' should fail on schema +# Bug#10734 Grant of privileges other than 'select' and 'create view' should fail on schema # ---error 1044 +--error ER_DBACCESS_DENIED_ERROR grant all on information_schema.* to 'user1'@'localhost'; ---error 1044 +--error ER_DBACCESS_DENIED_ERROR grant select on information_schema.* to 'user1'@'localhost'; # @@ -763,9 +775,9 @@ where table_name="v1"; drop view v1; # -# Bug #14387 SHOW COLUMNS doesn't work on temporary tables -# Bug #15224 SHOW INDEX from temporary table doesn't work -# Bug #12770 DESC cannot display the info. about temporary table +# Bug#14387 SHOW COLUMNS doesn't work on temporary tables +# Bug#15224 SHOW INDEX from temporary table doesn't work +# Bug#12770 DESC cannot display the info. about temporary table # create temporary table t1(f1 int, index(f1)); show columns from t1; @@ -850,6 +862,7 @@ connection con16681; select * from information_schema.views where table_name='v1' or table_name='v2'; connection default; +disconnect con16681; drop view v1, v2; drop table t1; drop user mysqltest_1@localhost; @@ -864,8 +877,9 @@ select concat(@a, table_name), @a, table_name from information_schema.tables where table_schema = 'test'; drop table t1,t2; + # -# Bug#20230: routine_definition is not null +# Bug#20230 routine_definition is not null # --disable_warnings DROP PROCEDURE IF EXISTS p1; @@ -898,7 +912,7 @@ DROP PROCEDURE p1; DROP USER mysql_bug20230@localhost; # -# Bug#18925: subqueries with MIN/MAX functions on INFORMARTION_SCHEMA +# Bug#18925 subqueries with MIN/MAX functions on INFORMARTION_SCHEMA # SELECT t.table_name, c1.column_name @@ -931,8 +945,8 @@ SELECT t.table_name, c1.column_name ); # -# Bug#21231: query with a simple non-correlated subquery over -# INFORMARTION_SCHEMA.TABLES +# Bug#2123 query with a simple non-correlated subquery over +# INFORMARTION_SCHEMA.TABLES # SELECT MAX(table_name) FROM information_schema.tables WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test'); @@ -940,7 +954,7 @@ SELECT table_name from information_schema.tables WHERE table_name=(SELECT MAX(table_name) FROM information_schema.tables WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test')); # -# Bug #23037: Bug in field "Default" of query "SHOW COLUMNS FROM table" +# Bug#23037 Bug in field "Default" of query "SHOW COLUMNS FROM table" # # Note, MyISAM/InnoDB can't take more that 65532 chars, because the row # size is limited to 65535 bytes (BLOBs not counted) @@ -981,7 +995,7 @@ DROP TABLE bug23037; DROP FUNCTION get_value; # -# Bug#22413: EXPLAIN SELECT FROM view with ORDER BY yield server crash +# Bug#22413 EXPLAIN SELECT FROM view with ORDER BY yield server crash # create view v1 as select table_schema as object_schema, @@ -1007,7 +1021,7 @@ drop table t1,t2; # -# Bug#24630 Subselect query crashes mysqld +# Bug#24630 Subselect query crashes mysqld # select 1 as f1 from information_schema.tables where "CHARACTER_SETS"= (select cast(table_name as char) from information_schema.tables @@ -1034,8 +1048,8 @@ group by t.table_name order by num1, t.table_name; # create table t1(f1 int); create view v1 as select f1+1 as a from t1; -create table t2 (f1 int, f2 int); -create view v2 as select f1+1 as a, f2 as b from t2; +create table t2 (f1 int, f2 int); +create view v2 as select f1+1 as a, f2 as b from t2; select table_name, is_updatable from information_schema.views; # # Note: we can perform 'delete' for non updatable view. @@ -1045,7 +1059,7 @@ drop view v1,v2; drop table t1,t2; # -# Bug#25859 ALTER DATABASE works w/o parameters +# Bug#25859 ALTER DATABASE works w/o parameters # --error ER_PARSE_ERROR alter database; @@ -1074,6 +1088,7 @@ show triggers; select trigger_name from information_schema.triggers where event_object_table='t1'; connection default; +disconnect con27629; drop user mysqltest_1@localhost; drop database mysqltest; @@ -1097,13 +1112,13 @@ drop table t1; # # Bug#30079 A check for "hidden" I_S tables is flawed # ---error 1109 +--error ER_UNKNOWN_TABLE show fields from information_schema.table_names; ---error 1109 +--error ER_UNKNOWN_TABLE show keys from information_schema.table_names; # -# Bug#34529: Crash on complex Falcon I_S select after ALTER .. PARTITION BY +# Bug#34529 Crash on complex Falcon I_S select after ALTER .. PARTITION BY # USE information_schema; SET max_heap_table_size = 16384; @@ -1112,9 +1127,9 @@ CREATE TABLE test.t1( a INT ); # What we need to create here is a bit of a corner case: # We need a star query with information_schema tables, where the first -# branch of the star join produces zero rows, so that reading of the +# branch of the star join produces zero rows, so that reading of the # second branch never happens. At the same time we have to make sure -# that data for at least the last table is swapped from MEMORY/HEAP to +# that data for at least the last table is swapped from MEMORY/HEAP to # MyISAM. This and only this triggers the bug. SELECT * FROM tables ta @@ -1142,10 +1157,11 @@ connect (con3148,localhost,user3148,,test); connection con3148; select user,db from information_schema.processlist; connection default; +disconnect con3148; drop user user3148@localhost; # -# Bug #26174 Server Crash: INSERT ... SELECT ... FROM I_S.GLOBAL_STATUS +# Bug#26174 Server Crash: INSERT ... SELECT ... FROM I_S.GLOBAL_STATUS # in Event (see also openssl_1.test) # --disable_warnings @@ -1183,7 +1199,7 @@ SET GLOBAL event_scheduler=0; # # WL#3732 Information schema optimization -# +# explain select table_name from information_schema.views where table_schema='test' and table_name='v1'; @@ -1231,7 +1247,7 @@ DROP VIEW v1; # SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME ='information_schema'; - + # # Bug#31381 Error in retrieving Data from INFORMATION_SCHEMA # @@ -1277,7 +1293,7 @@ show events where Db= 'information_schema'; use test; --echo # ---echo # Bug#34166: Server crash in SHOW OPEN TABLES and prelocking +--echo # Bug#34166 Server crash in SHOW OPEN TABLES and prelocking --echo # --disable_warnings drop table if exists t1; @@ -1299,8 +1315,8 @@ drop table t1; drop function f1; # -# BUG#34656 - KILL a query = Assertion failed: m_status == DA_ERROR || -# m_status == DA_OK +# Bug#34656 KILL a query = Assertion failed: m_status == DA_ERROR || +# m_status == DA_OK # connect (conn1, localhost, root,,); connection conn1; @@ -1378,13 +1394,13 @@ select * from information_schema.global_variables where variable_name='init_conn set global init_connect=""; # -# Bug #34517 SHOW GLOBAL STATUS does not work properly in embedded server. +# Bug#34517 SHOW GLOBAL STATUS does not work properly in embedded server. # create table t0 select * from information_schema.global_status where VARIABLE_NAME='COM_SELECT'; SELECT 1; select a.VARIABLE_VALUE - b.VARIABLE_VALUE from t0 b, information_schema.global_status a - where a.VARIABLE_NAME = b.VARIABLE_NAME; + where a.VARIABLE_NAME = b.VARIABLE_NAME; drop table t0; # @@ -1395,3 +1411,7 @@ SELECT CREATE_OPTIONS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='t1'; DROP TABLE t1; --echo End of 5.1 tests. + +# Wait till all disconnects are completed +--source include/wait_until_count_sessions.inc + diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test index 118f8771f913fe5822b3f8303c2db7d95905dc97..2fbfe2721e230c6540f3fe98a38b68fdac85d026 100644 --- a/mysql-test/t/merge.test +++ b/mysql-test/t/merge.test @@ -1418,8 +1418,6 @@ TABLE_SCHEMA = 'test' and TABLE_NAME='tm1'; DROP TABLE tm1; ---echo End of 5.1 tests - # # Bug#36006 - Optimizer does table scan for select count(*) # @@ -1435,4 +1433,67 @@ EXPLAIN SELECT COUNT(*) FROM t1; EXPLAIN SELECT COUNT(*) FROM t4; DROP TABLE t1, t2, t3, t4; +# +# BUG#39185 - Cardinality for merge tables calculated incorrectly. +# +CREATE TABLE t1(a INT, KEY(a)); +INSERT INTO t1 VALUES(0),(1),(2),(3),(4); +ANALYZE TABLE t1; +CREATE TABLE m1(a INT, KEY(a)) ENGINE=MERGE UNION=(t1); +SELECT CARDINALITY FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA='test' AND TABLE_NAME='m1'; +SELECT CARDINALITY FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA='test' AND TABLE_NAME='m1'; +SELECT CARDINALITY FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA='test' AND TABLE_NAME='m1'; +SELECT CARDINALITY FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA='test' AND TABLE_NAME='m1'; +DROP TABLE t1, m1; + +--echo # +--echo # Bug #40675 MySQL 5.1 crash with index merge algorithm and Merge tables +--echo # + +--echo # create MYISAM table t1 and insert values into it +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES(1); + +--echo # create MYISAM table t2 and insert values into it +CREATE TABLE t2(a INT, b INT, dummy CHAR(16) DEFAULT '', KEY(a), KEY(b)); +INSERT INTO t2(a,b) VALUES +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), +(1,2); + +--echo # Create the merge table t3 +CREATE TABLE t3(a INT, b INT, dummy CHAR(16) DEFAULT '', KEY(a), KEY(b)) +ENGINE=MERGE UNION=(t2) INSERT_METHOD=FIRST; + +--echo # Lock tables t1 and t3 for write +LOCK TABLES t1 WRITE, t3 WRITE; + +--echo # Insert values into the merge table t3 +INSERT INTO t3(a,b) VALUES(1,2); + +--echo # select from the join of t2 and t3 (The merge table) +SELECT t3.a FROM t1,t3 WHERE t3.b=2 AND t3.a=1; + +--echo # Unlock the tables +UNLOCK TABLES; + +--echo # drop the created tables +DROP TABLE t1, t2, t3; + --echo End of 5.1 tests diff --git a/mysql-test/t/multi_update.test b/mysql-test/t/multi_update.test index 0793ef15fafa924e9846064130f98d2b692809ab..fc37fd6a27d8bd3d6b10ad58820d24a5a9ff04ec 100644 --- a/mysql-test/t/multi_update.test +++ b/mysql-test/t/multi_update.test @@ -25,17 +25,17 @@ let $1 = 100; while ($1) { let $2 = 5; - eval insert into t1(t) values ('$1'); + eval insert into t1(t) values ('$1'); while ($2) { - eval insert into t2(id2,t) values ($1,'$2'); + eval insert into t2(id2,t) values ($1,'$2'); let $3 = 10; while ($3) { - eval insert into t3(id3,t) values ($1,'$2'); + eval insert into t3(id3,t) values ($1,'$2'); dec $3; } - dec $2; + dec $2; } dec $1; } @@ -80,11 +80,11 @@ let $1 = 1000; while ($1) { let $2 = 5; - eval insert into t1 values ($1,'aaaaaaaaaaaaaaaaaaaa'); + eval insert into t1 values ($1,'aaaaaaaaaaaaaaaaaaaa'); while ($2) { - eval insert into t2(id2,t) values ($1,'bbbbbbbbbbbbbbbbb'); - dec $2; + eval insert into t2(id2,t) values ($1,'bbbbbbbbbbbbbbbbb'); + dec $2; } dec $1; } @@ -318,7 +318,7 @@ update t2, t1 set t2.field=t1.field delete t1, t2 from t2 inner join t1 on t1.id1=t2.id2 where 0=1; -delete t1, t2 from t2,t1 +delete t1, t2 from t2,t1 where t1.id1=t2.id2 and 0=1; drop table t1,t2; @@ -352,7 +352,7 @@ create table `t2` (`c2_id` int(10) unsigned NULL auto_increment, `c2_p_id` int(1 insert into t1 values (0,'A01-Comp',1); insert into t1 values (0,'B01-Comp',1); insert into t2 values (0,1,'A Note',1); -update t1 left join t2 on p_id = c2_p_id set c2_note = 'asdf-1' where p_id = 2; +update t1 left join t2 on p_id = c2_p_id set c2_note = 'asdf-1' where p_id = 2; select * from t1; select * from t2; drop table t1, t2; @@ -380,6 +380,9 @@ revoke all privileges on mysqltest.t1 from mysqltest_1@localhost; revoke all privileges on mysqltest.* from mysqltest_1@localhost; delete from mysql.user where user=_binary'mysqltest_1'; drop database mysqltest; +connection default; +disconnect user1; +disconnect root; # # multi delete wrong table check @@ -394,7 +397,7 @@ drop table t1, t2, t3; # # multi* unique updating table check # -create table t1 (col1 int); +create table t1 (col1 int); create table t2 (col1 int); -- error ER_UPDATE_TABLE_USED update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1; @@ -402,16 +405,16 @@ update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1; delete t1 from t1,t2 where t1.col1 < (select max(col1) from t1) and t1.col1 = t2.col1; drop table t1,t2; -# Test for BUG#5837 - delete with outer join and const tables +# Test for Bug#5837 delete with outer join and const tables --disable_warnings create table t1 ( - aclid bigint not null primary key, - status tinyint(1) not null + aclid bigint not null primary key, + status tinyint(1) not null ) engine = innodb; create table t2 ( - refid bigint not null primary key, - aclid bigint, index idx_acl(aclid) + refid bigint not null primary key, + aclid bigint, index idx_acl(aclid) ) engine = innodb; --enable_warnings insert into t2 values(1,null); @@ -419,7 +422,7 @@ delete t2, t1 from t2 left join t1 on (t2.aclid=t1.aclid) where t2.refid='1'; drop table t1, t2; # -# Bug#19225: unchecked error leads to server crash +# Bug#19225 unchecked error leads to server crash # create table t1(a int); create table t2(a int); @@ -429,7 +432,7 @@ drop table t1, t2; # End of 4.1 tests # -# Test for bug #1980. +# Test for Bug#1980. # --disable_warnings create table t1 ( c char(8) not null ) engine=innodb; @@ -490,11 +493,22 @@ send alter table t1 add column c int default 100 after a; connect (updater,localhost,root,,test); connection updater; -sleep 2; +# Wait till "alter table t1 ..." of session changer is in work. +# = There is one session is in state "Locked". +let $wait_condition= select count(*)= 1 from information_schema.processlist + where state= 'Locked'; +--source include/wait_condition.inc send update t1, v1 set t1.b=t1.a+t1.b+v1.b where t1.a=v1.a; connection locker; -sleep 2; +# Wait till +# - "alter table t1 ..." of session changer and +# - "update t1, v1 ..." of session updater +# are in work. +# = There are two session is in state "Locked". +let $wait_condition= select count(*)= 2 from information_schema.processlist + where state= 'Locked'; +--source include/wait_condition.inc unlock tables; connection changer; @@ -507,6 +521,11 @@ select * from t2; drop view v1; drop table t1, t2; +connection default; +disconnect locker; +disconnect changer; +disconnect updater; + # # Test multi updates and deletes using primary key and without. # @@ -538,8 +557,9 @@ select * from t2 order by id; drop table t1, t2; # -# Bug#27716 multi-update did partially and has not binlogged +# Bug#27716 multi-update did partially and has not binlogged # + CREATE TABLE `t1` ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL, @@ -561,29 +581,29 @@ set @@session.binlog_format= mixed; insert into t1 values (1,1),(2,2); insert into t2 values (1,1),(4,4); reset master; -error ER_DUP_ENTRY; +--error ER_DUP_ENTRY UPDATE t2,t1 SET t2.a=t1.a+2; # check select * from t2 /* must be (3,1), (4,4) */; show master status /* there must be the UPDATE query event */; -# B. testing multi_update::send_error() ineffective update -# (as there is a policy described at mysql_update() still go to binlog) +# B. testing multi_update::send_error() ineffective update +# (as there is a policy described at mysql_update() still go to binlog) delete from t1; delete from t2; insert into t1 values (1,2),(3,4),(4,4); insert into t2 values (1,2),(3,4),(4,4); reset master; -error ER_DUP_ENTRY; +--error ER_DUP_ENTRY UPDATE t2,t1 SET t2.a=t2.b where t2.a=t1.a; show master status /* there must be the UPDATE query event */; -# cleanup bug#27716 +# cleanup drop table t1, t2; set @@session.binlog_format= @sav_binlog_format; # -# Bug #29136 erred multi-delete on trans table does not rollback +# Bug#29136 erred multi-delete on trans table does not rollback # # prepare @@ -610,7 +630,7 @@ delete t3.* from t2,t3 where t2.a=t3.a; select count(*) from t1 /* must be 1 */; select count(*) from t3 /* must be 1 */; -# cleanup bug#29136 +# cleanup drop table t1, t2, t3; # diff --git a/mysql-test/t/overflow.test b/mysql-test/t/overflow.test index a62ef9c4cd203d6d14d5eafccae236c66b7f01c4..774c43be65834aaba80042d337379ec2363b9925 100644 --- a/mysql-test/t/overflow.test +++ b/mysql-test/t/overflow.test @@ -1,6 +1,14 @@ +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + connect (con1,localhost,root,,); connection con1; --- error 1064,1102,1280 +--error ER_PARSE_ERROR,ER_WRONG_DB_NAME,ER_WRONG_NAME_FOR_INDEX drop database AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; +connection default; +disconnect con1; # End of 4.1 tests + +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/packet.test b/mysql-test/t/packet.test index 93b46766d99d4b23df6c4a9c89810185830cbde2..7e08a0f6c3fd2581b3cbe417a399df15a7a0cadb 100644 --- a/mysql-test/t/packet.test +++ b/mysql-test/t/packet.test @@ -4,10 +4,18 @@ # swallowing them and returning an error --source include/not_windows.inc +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + + # # Check protocol handling # +set @max_allowed_packet=@@global.max_allowed_packet; +set @net_buffer_length=@@global.net_buffer_length; + + # setting values below minimum threshold of 1024 will cause truncating set global max_allowed_packet=100; set global net_buffer_length=100; @@ -22,8 +30,10 @@ select repeat('a',2000); connect (con1,localhost,root,,); connection con1; select @@net_buffer_length, @@max_allowed_packet; ---error 1153 +--error ER_NET_PACKET_TOO_LARGE SELECT length("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") as len; +connection default; +disconnect con1; # # Reset to default values and reconnect @@ -34,5 +44,13 @@ connect (con2,localhost,root,,); connection con2; SELECT length("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") as len; select length(repeat('a',2000)); +connection default; +disconnect con2; + +set global max_allowed_packet=@max_allowed_packet; +set global net_buffer_length=@net_buffer_length; # End of 4.1 tests + +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/query_cache_notembedded.test b/mysql-test/t/query_cache_notembedded.test index c3889ef02678b3b4846a7fd6518555bb3f6e51e3..095d47f5bdf47336e7a5ad6eb7fe1a06dcffacca 100644 --- a/mysql-test/t/query_cache_notembedded.test +++ b/mysql-test/t/query_cache_notembedded.test @@ -1,6 +1,10 @@ -- source include/have_query_cache.inc -- source include/not_embedded.inc +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + + # # Tests with query cache # @@ -79,7 +83,7 @@ show status like "Qcache_free_blocks"; drop table t1, t2, t3, t11, t21; # -# do not use QC if tables locked (BUG#12385) +# do not use QC if tables locked (Bug#12385) # connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK); connection root; @@ -96,10 +100,13 @@ SELECT * FROM t1; connection root; SELECT * FROM t1; drop table t1; +connection default; +disconnect root; +disconnect root2; # -# query in QC from normal execution and SP (BUG#6897) -# improved to also test BUG#3583 and BUG#12990 +# query in QC from normal execution and SP (Bug#6897) +# improved to also test Bug#3583 and Bug#12990 # flush query cache; reset query cache; @@ -181,7 +188,7 @@ drop procedure f4; drop table t1; # -# bug#14767: INSERT in SF + concurrent SELECT with query cache +# Bug#14767 INSERT in SF + concurrent SELECT with query cache # connection default; SET @old_log_bin_trust_function_creators= @@global.log_bin_trust_function_creators; @@ -257,6 +264,7 @@ SELECT id FROM view1 WHERE id>2; show status like 'Qcache_queries_in_cache'; connection default; +USE test; DROP DATABASE bug30269; disconnect bug30269; DROP USER 'bug30269'@'localhost'; @@ -266,3 +274,5 @@ set GLOBAL query_cache_limit=default; set GLOBAL query_cache_min_res_unit=default; set GLOBAL query_cache_size=default; +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/read_only.test b/mysql-test/t/read_only.test index fd41a3225a640b1c9b47a54bb13931d776b3a9bb..5a498404b03e8ef8f6e3492ddc22150291484289 100644 --- a/mysql-test/t/read_only.test +++ b/mysql-test/t/read_only.test @@ -2,7 +2,10 @@ # check that it blocks updates unless they are only on temporary tables. # should work with embedded server after mysqltest is fixed --- source include/not_embedded.inc +--source include/not_embedded.inc +--source include/count_sessions.inc + +set @start_read_only= @@global.read_only; --disable_warnings DROP TABLE IF EXISTS t1,t2,t3; @@ -13,12 +16,15 @@ DROP TABLE IF EXISTS t1,t2,t3; grant CREATE, SELECT, DROP on *.* to test@localhost; +--echo connect (con1,localhost,test,,test); connect (con1,localhost,test,,test); +--echo connection default; connection default; set global read_only=0; +--echo connection con1; connection con1; create table t1 (a int); @@ -27,6 +33,7 @@ insert into t1 values(1); create table t2 select * from t1; +--echo connection default; connection default; set global read_only=1; @@ -36,28 +43,29 @@ set global read_only=1; create table t3 (a int); drop table t3; +--echo connection con1; connection con1; select @@global.read_only; ---error 1290 +--error ER_OPTION_PREVENTS_STATEMENT create table t3 (a int); ---error 1290 +--error ER_OPTION_PREVENTS_STATEMENT insert into t1 values(1); # if a statement, after parse stage, looks like it will update a # non-temp table, it will be rejected, even if at execution it would # have turned out that 0 rows would be updated ---error 1290 +--error ER_OPTION_PREVENTS_STATEMENT update t1 set a=1 where 1=0; # multi-update is special (see sql_parse.cc) so we test it ---error 1290 +--error ER_OPTION_PREVENTS_STATEMENT update t1,t2 set t1.a=t2.a+1 where t1.a=t2.a; # check multi-delete to be sure ---error 1290 +--error ER_OPTION_PREVENTS_STATEMENT delete t1,t2 from t1,t2 where t1.a=t2.a; # With temp tables updates should be accepted: @@ -71,7 +79,7 @@ insert into t3 values(1); insert into t4 select * from t3; # a non-temp table updated: ---error 1290 +--error ER_OPTION_PREVENTS_STATEMENT update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a; # no non-temp table updated (just swapped): @@ -79,7 +87,7 @@ update t1,t3 set t3.a=t1.a+1 where t1.a=t3.a; update t4,t3 set t4.a=t3.a+1 where t4.a=t3.a; ---error 1290 +--error ER_OPTION_PREVENTS_STATEMENT delete t1 from t1,t3 where t1.a=t3.a; delete t3 from t1,t3 where t1.a=t3.a; @@ -98,7 +106,7 @@ delete t1 from t1,t3 where t1.a=t3.a; drop table t1; ---error 1290 +--error ER_OPTION_PREVENTS_STATEMENT insert into t1 values(1); # @@ -109,77 +117,96 @@ insert into t1 values(1); # - is an error in the same connection # - is ok in a different connection +--echo connection default; connection default; set global read_only=0; lock table t1 write; +--echo connection con1; connection con1; lock table t2 write; +--echo connection default; connection default; --error ER_LOCK_OR_ACTIVE_TRANSACTION set global read_only=1; unlock tables ; # The following call blocks until con1 releases the write lock. # Blocking is expected. +--echo send set global read_only=1; send set global read_only=1; +--echo connection con1; connection con1; ---sleep 1 select @@global.read_only; unlock tables ; ---sleep 1 +let $wait_condition= SELECT @@global.read_only= 1; +--source include/wait_condition.inc select @@global.read_only; +--echo connection default; connection default; +--echo reap; reap; # LOCK TABLE ... READ / READ_ONLY # - is an error in the same connection # - is ok in a different connection +--echo connection default; connection default; set global read_only=0; lock table t1 read; +--echo connection con1; connection con1; lock table t2 read; +--echo connection default; connection default; --error ER_LOCK_OR_ACTIVE_TRANSACTION set global read_only=1; unlock tables ; # The following call blocks until con1 releases the read lock. # Blocking is a limitation, and could be improved. +--echo send set global read_only=1; send set global read_only=1; +--echo connection con1; connection con1; ---sleep 1 select @@global.read_only; unlock tables ; ---sleep 1 +let $wait_condition= SELECT @@global.read_only= 1; +--source include/wait_condition.inc select @@global.read_only; +--echo connection default; connection default; +--echo reap; reap; # pending transaction / READ_ONLY # - is an error in the same connection # - is ok in a different connection +--echo connection default; connection default; set global read_only=0; BEGIN; +--echo connection con1; connection con1; BEGIN; +--echo connection default; connection default; --error ER_LOCK_OR_ACTIVE_TRANSACTION set global read_only=1; ROLLBACK; + set global read_only=1; +--echo connection con1; connection con1; select @@global.read_only; ROLLBACK; @@ -188,21 +215,26 @@ ROLLBACK; # - in the same SUPER connection # - in another SUPER connection +--echo connection default; connection default; set global read_only=0; flush tables with read lock; set global read_only=1; unlock tables; +--echo connect (root2,localhost,root,,test); connect (root2,localhost,root,,test); +--echo connection default; connection default; set global read_only=0; flush tables with read lock; +--echo connection root2; connection root2; set global read_only=1; +--echo connection default; connection default; select @@global.read_only; unlock tables; @@ -221,6 +253,7 @@ drop temporary table if exists ttt; # # Cleanup # +--echo connection default; connection default; set global read_only=0; drop table t1,t2; @@ -244,14 +277,18 @@ grant all on mysqltest_db2.* to `mysqltest_u1`@`%`; create database mysqltest_db1; grant all on mysqltest_db1.* to `mysqltest_u1`@`%`; flush privileges; +--echo connect (con_bug27440,127.0.0.1,mysqltest_u1,,test,MASTER_MYPORT,); connect (con_bug27440,127.0.0.1,mysqltest_u1,,test,$MASTER_MYPORT,); +--echo connection con_bug27440; connection con_bug27440; --error ER_OPTION_PREVENTS_STATEMENT create database mysqltest_db2; show databases like '%mysqltest_db2%'; --error ER_OPTION_PREVENTS_STATEMENT drop database mysqltest_db1; +--echo disconnect con_bug27440; disconnect con_bug27440; +--echo connection default; connection default; delete from mysql.user where User like 'mysqltest_%'; delete from mysql.db where User like 'mysqltest_%'; @@ -259,4 +296,8 @@ delete from mysql.tables_priv where User like 'mysqltest_%'; delete from mysql.columns_priv where User like 'mysqltest_%'; flush privileges; drop database mysqltest_db1; -set global read_only=0; +set global read_only= @start_read_only; +disconnect con1; +disconnect root2; +--source include/wait_until_count_sessions.inc + diff --git a/mysql-test/t/rename.test b/mysql-test/t/rename.test index fce37d8466dcbfea47f5737dcc0b2990e7983a7e..5aa1a51a90f4d3be8556581dbba8248f20df2780 100644 --- a/mysql-test/t/rename.test +++ b/mysql-test/t/rename.test @@ -2,6 +2,8 @@ # Test of rename table # +--source include/count_sessions.inc + --disable_warnings drop table if exists t0,t1,t2,t3,t4; # Clear up from other tests (to ensure that SHOW TABLES below is right) @@ -19,16 +21,16 @@ rename table t3 to t4, t2 to t3, t1 to t2, t4 to t1; select * from t1; # The following should give errors ---error 1050,1050 +--error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR rename table t1 to t2; ---error 1050,1050 +--error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR rename table t1 to t1; ---error 1050,1050 +--error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR rename table t3 to t4, t2 to t3, t1 to t2, t4 to t2; show tables like "t_"; ---error 1050,1050 +--error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR rename table t3 to t1, t2 to t3, t1 to t2, t4 to t1; ---error 1017,1017 +--error ER_FILE_NOT_FOUND,ER_FILE_NOT_FOUND rename table t3 to t4, t5 to t3, t1 to t2, t4 to t1; select * from t1; @@ -63,7 +65,7 @@ connection con2; # Wait for the the tables to be renamed # i.e the query below succeds let $query= select * from t2, t4; -source include/wait_for_query_to_suceed.inc; +source include/wait_for_query_to_succeed.inc; show tables; @@ -83,13 +85,15 @@ connection default; create table t1(f1 int); create view v1 as select * from t1; alter table v1 rename to v2; ---error 1146 +--error ER_NO_SUCH_TABLE alter table v1 rename to v2; rename table v2 to v1; ---error 1050 +--error ER_TABLE_EXISTS_ERROR rename table v2 to v1; drop view v1; drop table t1; - --echo End of 5.0 tests + +--source include/wait_until_count_sessions.inc + diff --git a/mysql-test/t/sp-threads.test b/mysql-test/t/sp-threads.test index d8a8ce5dae7edbfc1af360c8f9d1ea1ff7282cee..e1012e2b72df51451dc9989dddc24f7932c1f988 100644 --- a/mysql-test/t/sp-threads.test +++ b/mysql-test/t/sp-threads.test @@ -5,6 +5,9 @@ # except security/privilege tests, they go to sp-security.test # +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + connect (con1root,localhost,root,,); connect (con2root,localhost,root,,); connect (con3root,localhost,root,,); @@ -17,7 +20,7 @@ drop table if exists t1; --enable_warnings create table t1 (s1 int, s2 int, s3 int); -delimiter //; +delimiter //; create procedure bug4934() begin insert into t1 values (1,0,1); @@ -38,7 +41,7 @@ drop table t1; create table t1 (s1 int, s2 int, s3 int); drop procedure bug4934; -delimiter //; +delimiter //; create procedure bug4934() begin end// @@ -58,7 +61,7 @@ drop procedure bug4934; # -# BUG #9486 "Can't perform multi-update in stored procedure" +# Bug#9486 Can't perform multi-update in stored procedure # --disable_warnings drop procedure if exists bug9486; @@ -87,8 +90,9 @@ reap; drop procedure bug9486; drop table t1, t2; + # -# BUG#11158: Can't perform multi-delete in stored procedure +# Bug#11158 Can't perform multi-delete in stored procedure # --disable_warnings drop procedure if exists bug11158; @@ -114,8 +118,9 @@ connection con1root; drop procedure bug11158; drop table t1, t2; + # -# BUG#11554: Server crashes on statement indirectly using non-cached function +# Bug#11554 Server crashes on statement indirectly using non-cached function # --disable_warnings drop function if exists bug11554; @@ -134,7 +139,7 @@ drop table t1; drop view v1; -# BUG#12228 +# Bug#12228 Crash happens during calling specific SP in multithread environment --disable_warnings drop procedure if exists p1; drop procedure if exists p2; @@ -168,18 +173,26 @@ connection con2root; unlock tables; connection con1root; -# Crash will be here if we hit BUG#12228 +# Crash will be here if we hit Bug#12228 reap; drop procedure p1; drop procedure p2; drop table t1; + # -# BUG#NNNN: New bug synopsis +# Bug#NNNN New bug synopsis # #--disable_warnings #drop procedure if exists bugNNNN; #--enable_warnings #create procedure bugNNNN... +connection default; +disconnect con1root; +disconnect con2root; +disconnect con3root; + +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 9dcb645b28d5663c5b6ad21baa453ddac02d8274..e82764d6ac48c2b203f77622f6328b8af559dd7a 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -78,9 +78,9 @@ select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1); (select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a); explain extended (select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a); select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2; -select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from +select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from (select * from t2 where a>1) as tt; -explain extended select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from +explain extended select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from (select * from t2 where a>1) as tt; select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3) order by 1 desc limit 1); select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a > t1.a) order by 1 desc limit 1); @@ -367,7 +367,7 @@ let $wait_condition= SELECT COUNT(*) <> $row_count_before FROM t1; --source include/wait_condition.inc select * from t1; # -#TODO: should be uncommented after bug 380 fix pushed +#TODO: should be uncommented after Bug#380 fix pushed #INSERT INTO t1 (x) SELECT (SELECT SUM(a)+b FROM t2) from t3; #select * from t1; drop table t1, t2, t3; @@ -536,7 +536,7 @@ do (SELECT a from t1); -- error ER_NO_SUCH_TABLE set @a:=(SELECT a from t1); -CREATE TABLE t1 (a int, KEY(a)); +CREATE TABLE t1 (a int, KEY(a)); HANDLER t1 OPEN; -- error ER_PARSE_ERROR HANDLER t1 READ a=((SELECT 1)); @@ -678,7 +678,7 @@ CREATE TABLE t2 ( INSERT INTO t2 VALUES ('AUS','Australia','Oceania','Australia and New Zealand',7741220.00,1901,18886000,79.8,351182.00,392911.00,'Australia','Constitutional Monarchy, Federation','Elisabeth II',135,'AU'); INSERT INTO t2 VALUES ('AZE','Azerbaijan','Asia','Middle East',86600.00,1991,7734000,62.9,4127.00,4100.00,'Azärbaycan','Federal Republic','Heydär Äliyev',144,'AZ'); -select t2.Continent, t1.Name, t1.Population from t2 LEFT JOIN t1 ON t2.Code = t1.t2 where t1.Population IN (select max(t1.Population) AS Population from t1, t2 where t1.t2 = t2.Code group by Continent); +select t2.Continent, t1.Name, t1.Population from t2 LEFT JOIN t1 ON t2.Code = t1.t2 where t1.Population IN (select max(t1.Population) AS Population from t1, t2 where t1.t2 = t2.Code group by Continent); drop table t1, t2; @@ -732,9 +732,9 @@ drop table t1,t2; # # correct NULL in <CONSTANT> IN (SELECT ...) # -create table t1 (a int, unique index indexa (a)); -insert into t1 values (-1), (-4), (-2), (NULL); -select -10 IN (select a from t1 FORCE INDEX (indexa)); +create table t1 (a int, unique index indexa (a)); +insert into t1 values (-1), (-4), (-2), (NULL); +select -10 IN (select a from t1 FORCE INDEX (indexa)); drop table t1; # @@ -816,7 +816,7 @@ disable_query_log; let $1 = 10000; while ($1) { - eval insert into t1 values (rand()*100000+200,rand()*100000); + eval insert into t1 values (rand()*100000+200,rand()*100000); dec $1; } enable_query_log; @@ -842,7 +842,7 @@ create table t2 (a int, b int); create table t3 (a int, b int); insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10); insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1); -insert into t3 values (3,3), (2,2), (1,1); +insert into t3 values (3,3), (2,2), (1,1); select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3; drop table t1,t2,t3; @@ -1010,7 +1010,7 @@ drop table t1, t2; # # unresolved field error # -create table t1 (s1 int); +create table t1 (s1 int); create table t2 (s1 int); -- error ER_BAD_FIELD_ERROR select * from t1 where (select count(*) from t2 where t1.s2) = 1; @@ -1035,11 +1035,12 @@ INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5); SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100; DROP TABLE t1; + # -# Bug 2198 +# Bug#2198 SELECT INTO OUTFILE (with Sub-Select) Problem # -create table t1 (a int, b decimal(13, 3)); +create table t1 (a int, b decimal(13, 3)); insert into t1 values (1, 0.123); let $outfile_abs= $MYSQLTEST_VARDIR/tmp/subselect.out.file.1; let $outfile_rel= ../../tmp/subselect.out.file.1; @@ -1052,8 +1053,9 @@ eval load data infile "$outfile_rel" into table t1; select * from t1; drop table t1; + # -# Bug 2479 +# Bug#2479 dependant subquery with limit crash # CREATE TABLE `t1` ( @@ -1091,8 +1093,9 @@ select 2 in (select * from t1); SET SQL_SELECT_LIMIT=default; drop table t1; + # -# Bug #3118: subselect + order by +# Bug#3118 subselect + order by # CREATE TABLE t1 (a int, b int, INDEX (a)); @@ -1131,8 +1134,9 @@ insert into t1 values (1); explain select benchmark(1000, (select a from t1 where a=sha(rand()))); drop table t1; + # -# bug 3188 +# Bug#3188 Ambiguous Column in Subselect crashes server # create table t1(id int); create table t2(id int); @@ -1141,8 +1145,9 @@ create table t3(flag int); select (select * from t3 where id not null) from t1, t2; drop table t1,t2,t3; + # -# aggregate functions (Bug #3505) +# aggregate functions (Bug#3505 Wrong results on use of ORDER BY with subqueries) # CREATE TABLE t1 (id INT); CREATE TABLE t2 (id INT); @@ -1333,8 +1338,9 @@ select * from t1 up where exists (select * from t1 where t1.a=up.a); explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a); drop table t1; + # -# Bug #4102: subselect in HAVING +# Bug#4102 subselect in HAVING # CREATE TABLE t1 (t1_a int); @@ -1345,8 +1351,10 @@ SELECT * FROM t1, t2 table2 WHERE t1_a = 1 AND table2.t2_a = 1 HAVING table2.t2_b = (SELECT MAX(t2_b) FROM t2 WHERE t2_a = table2.t2_a); DROP TABLE t1, t2; + # -# Test problem with NULL and derived tables (Bug #4097) +# Test problem with NULL and derived tables +# (Bug#4097 JOIN with subquery causes entire column to report NULL) # CREATE TABLE t1 (id int(11) default NULL,name varchar(10) default NULL); @@ -1356,18 +1364,19 @@ INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix'); SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id; drop table t1,t2; + # # outer fields resolving in INSERT/REPLACE and CRETE with SELECT # CREATE TABLE t1 ( a int, b int ); CREATE TABLE t2 ( c int, d int ); INSERT INTO t1 VALUES (1,2), (2,3), (3,4); -SELECT a AS abc, b FROM t1 outr WHERE b = +SELECT a AS abc, b FROM t1 outr WHERE b = (SELECT MIN(b) FROM t1 WHERE a=outr.a); -INSERT INTO t2 SELECT a AS abc, b FROM t1 outr WHERE b = +INSERT INTO t2 SELECT a AS abc, b FROM t1 outr WHERE b = (SELECT MIN(b) FROM t1 WHERE a=outr.a); select * from t2; -CREATE TABLE t3 SELECT a AS abc, b FROM t1 outr WHERE b = +CREATE TABLE t3 SELECT a AS abc, b FROM t1 outr WHERE b = (SELECT MIN(b) FROM t1 WHERE a=outr.a); select * from t3; prepare stmt1 from "INSERT INTO t2 SELECT a AS abc, b FROM t1 outr WHERE b = (SELECT MIN(b) FROM t1 WHERE a=outr.a);"; @@ -1391,19 +1400,21 @@ insert into t2 values (1,2); select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1); drop table t1,t2; + # -# BUG#4769 - fulltext in subselect +# Bug#4769 - fulltext in subselect # -create table t1 (a int not null auto_increment primary key, b varchar(40), fulltext(b)); -insert into t1 (b) values ('ball'),('ball games'), ('games'), ('foo'), ('foobar'), ('Serg'), ('Sergei'),('Georg'), ('Patrik'),('Hakan'); -create table t2 (a int); -insert into t2 values (1),(3),(2),(7); -select a,b from t1 where match(b) against ('Ball') > 0; -select a from t2 where a in (select a from t1 where match(b) against ('Ball') > 0); +create table t1 (a int not null auto_increment primary key, b varchar(40), fulltext(b)); +insert into t1 (b) values ('ball'),('ball games'), ('games'), ('foo'), ('foobar'), ('Serg'), ('Sergei'),('Georg'), ('Patrik'),('Hakan'); +create table t2 (a int); +insert into t2 values (1),(3),(2),(7); +select a,b from t1 where match(b) against ('Ball') > 0; +select a from t2 where a in (select a from t1 where match(b) against ('Ball') > 0); drop table t1,t2; + # -# BUG#5003 - like in subselect +# Bug#5003 - like in subselect # CREATE TABLE t1(`IZAVORGANG_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`KUERZEL` VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_bin,`IZAANALYSEART_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`IZAPMKZ_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin); CREATE INDEX AK01IZAVORGANG ON t1(izaAnalyseart_id,Kuerzel); @@ -1460,10 +1471,10 @@ SELECT b.sc FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.s SELECT b.ac FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b; drop tables t1,t2; + # -# Test for bug #6462. "Same request on same data returns different -# results." a.k.a. "Proper cleanup of subqueries is missing for -# SET and DO statements". +# Test for Bug#6462 Same request on same data returns different results +# a.k.a. "Proper cleanup of subqueries is missing for SET and DO statements". # create table t1 (a int not null, b int not null, c int, primary key (a,b)); insert into t1 values (1,1,1), (2,2,2), (3,3,3); @@ -1485,9 +1496,11 @@ drop table t1; connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK); connection root; set @got_val= (SELECT 1 FROM (SELECT 'A' as my_col) as T1 ) ; +connection default; +disconnect root; # -# primary query with temporary table and subquery with groupping +# primary query with temporary table and subquery with grouping # create table t1 (a int, b int); create table t2 (a int, b int); @@ -1548,14 +1561,15 @@ INSERT INTO t1 VALUES ('ASM','American Samoa','Oceania','Polynesia',199.00,0,680 INSERT INTO t1 VALUES ('ATF','French Southern territories','Antarctica','Antarctica',7780.00,0,0,NULL,0.00,NULL,'Terres australes françaises','Nonmetropolitan Territory of France','Jacques Chirac',NULL,'TF'); INSERT INTO t1 VALUES ('UMI','United States Minor Outlying Islands','Oceania','Micronesia/Caribbean',16.00,0,0,NULL,0.00,NULL,'United States Minor Outlying Islands','Dependent Territory of the US','George W. Bush',NULL,'UM'); /*!40000 ALTER TABLE t1 ENABLE KEYS */; -SELECT DISTINCT Continent AS c FROM t1 outr WHERE - Code <> SOME ( SELECT Code FROM t1 WHERE Continent = outr.Continent AND +SELECT DISTINCT Continent AS c FROM t1 outr WHERE + Code <> SOME ( SELECT Code FROM t1 WHERE Continent = outr.Continent AND Population < 200); drop table t1; + # -# Test for BUG#7885: Server crash when 'any' subselect compared to -# non-existant field. +# Test for Bug#7885 Server crash when 'any' subselect compared to +# non-existant field. # create table t1 (a1 int); create table t2 (b1 int); @@ -1604,8 +1618,9 @@ select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx; select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx from DUAL; drop table t1; + # -# Test for BUG#8218 +# Test for Bug#8218 Join does not pass string from right table # CREATE TABLE t1 ( categoryId int(11) NOT NULL, @@ -1675,38 +1690,39 @@ select count(distinct t2.userid) pass, groupstuff.*, count(t2.courseid) crse, - t1.categoryid, + t1.categoryid, t2.courseid, date_format(date, '%b%y') as colhead -from t2 -join t1 on t2.courseid=t1.courseid +from t2 +join t1 on t2.courseid=t1.courseid join ( - select - t5.userid, - parentid, - parentgroup, - childid, - groupname, - grouptypeid - from t5 - join + select + t5.userid, + parentid, + parentgroup, + childid, + groupname, + grouptypeid + from t5 + join ( - select t4.id as parentid, - t4.name as parentgroup, - t4.id as childid, - t4.name as groupname, - t4.grouptypeid - from t4 - ) as gin on t5.groupid=gin.childid -) as groupstuff on t2.userid = groupstuff.userid -group by + select t4.id as parentid, + t4.name as parentgroup, + t4.id as childid, + t4.name as groupname, + t4.grouptypeid + from t4 + ) as gin on t5.groupid=gin.childid +) as groupstuff on t2.userid = groupstuff.userid +group by groupstuff.groupname, colhead , t2.courseid; drop table t1, t2, t3, t4, t5; + # -# Transformation in left expression of subquery (BUG#8888) +# Transformation in left expression of subquery (Bug#8888) # create table t1 (a int); insert into t1 values (1), (2), (3); @@ -1751,8 +1767,9 @@ select (1,2,3) = (select * from t1); select (select * from t1) = (1,2,3); drop table t1; + # -# Item_int_with_ref check (BUG#10020) +# Item_int_with_ref check (Bug#10020) # CREATE TABLE `t1` ( `itemid` bigint(20) unsigned NOT NULL auto_increment, @@ -1775,15 +1792,16 @@ INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1'); SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30; drop tables t1,t2; -# BUG#11821 : Select from subselect using aggregate function on an enum -# segfaults: + +# Bug#11821 Select from subselect using aggregate function on an enum segfaults create table t1 (fld enum('0','1')); insert into t1 values ('1'); select * from (select max(fld) from t1) as foo; drop table t1; + # -# Bug #11867: queries with ROW(,elems>) IN (SELECT DISTINCT <cols> FROM ...) +# Bug#11867 queries with ROW(,elems>) IN (SELECT DISTINCT <cols> FROM ...) # CREATE TABLE t1 (one int, two int, flag char(1)); @@ -1813,8 +1831,9 @@ explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FR explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1; DROP TABLE t1,t2; + # -# Bug #12392: where cond with IN predicate for rows and NULL values in table +# Bug#12392 where cond with IN predicate for rows and NULL values in table # CREATE TABLE t1 (a char(5), b char(5)); @@ -1824,8 +1843,9 @@ SELECT * FROM t1 WHERE (a,b) IN (('aaa','aaa'), ('aaa','bbb')); DROP TABLE t1; + # -# Bug #11479: subquery over left join with an empty inner table +# Bug#11479 subquery over left join with an empty inner table # CREATE TABLE t1 (a int); @@ -1842,9 +1862,10 @@ SELECT * FROM t1 DROP TABLE t1,t2,t3; + # -# Bug#18503: Queries with a quantified subquery returning empty set may -# return a wrong result. +# Bug#18503 Queries with a quantified subquery returning empty set may +# return a wrong result. # CREATE TABLE t1 (f1 INT); CREATE TABLE t2 (f2 INT); @@ -1856,8 +1877,9 @@ INSERT INTO t2 VALUES (2); SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE f2=0); DROP TABLE t1, t2; + # -# Bug#16302: Quantified subquery without any tables gives wrong results +# Bug#16302 Quantified subquery without any tables gives wrong results # select 1 from dual where 1 < any (select 2); select 1 from dual where 1 < all (select 2); @@ -1866,7 +1888,8 @@ select 1 from dual where 2 > all (select 1); select 1 from dual where 1 < any (select 2 from dual); select 1 from dual where 1 < all (select 2 from dual where 1!=1); -# BUG#20975 Wrong query results for subqueries within NOT + +# Bug#20975 Wrong query results for subqueries within NOT create table t1 (s1 char); insert into t1 values (1),(2); @@ -1883,8 +1906,9 @@ select * from t1 where (s1 = ALL (select s1/s1 from t1)); select * from t1 where NOT(s1 = ALL (select s1/s1 from t1)); drop table t1; + # -# Bug #16255: Subquery in where +# Bug#16255 Subquery in where # create table t1 ( retailerID varchar(8) NOT NULL, @@ -1900,15 +1924,16 @@ INSERT INTO t1 VALUES("0037", "2", "2006-01-06 12:25:53"); INSERT INTO t1 VALUES("0048", "1", "2006-01-06 12:37:50"); INSERT INTO t1 VALUES("0059", "1", "2006-01-06 12:37:50"); -select * from t1 r1 - where (r1.retailerID,(r1.changed)) in - (SELECT r2.retailerId,(max(changed)) from t1 r2 +select * from t1 r1 + where (r1.retailerID,(r1.changed)) in + (SELECT r2.retailerId,(max(changed)) from t1 r2 group by r2.retailerId); drop table t1; + # -# Bug #21180: Subselect with index for both WHERE and ORDER BY -# produces empty result +# Bug#21180 Subselect with index for both WHERE and ORDER BY +# produces empty result # create table t1(a int, primary key (a)); insert into t1 values (10); @@ -1916,38 +1941,39 @@ insert into t1 values (10); create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)); insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989'); -explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r - ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' +explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r + ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; -SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r - ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' +SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r + ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; -explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r - ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' +explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r + ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; -SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r - ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' +SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r + ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; drop table t1,t2; + # -# Bug #21853: assert failure for a grouping query with -# an ALL/ANY quantified subquery in HAVING +# Bug#21853 assert failure for a grouping query with +# an ALL/ANY quantified subquery in HAVING # -CREATE TABLE t1 ( - field1 int NOT NULL, - field2 int NOT NULL, - field3 int NOT NULL, - PRIMARY KEY (field1,field2,field3) +CREATE TABLE t1 ( + field1 int NOT NULL, + field2 int NOT NULL, + field3 int NOT NULL, + PRIMARY KEY (field1,field2,field3) +); +CREATE TABLE t2 ( + fieldA int NOT NULL, + fieldB int NOT NULL, + PRIMARY KEY (fieldA,fieldB) ); -CREATE TABLE t2 ( - fieldA int NOT NULL, - fieldB int NOT NULL, - PRIMARY KEY (fieldA,fieldB) -); INSERT INTO t1 VALUES (1,1,1), (1,1,2), (1,2,1), (1,2,2), (1,2,3), (1,3,1); @@ -1959,19 +1985,20 @@ SELECT field1, field2, COUNT(*) SELECT field1, field2 FROM t1 GROUP BY field1, field2 - HAVING COUNT(*) >= ALL (SELECT fieldB + HAVING COUNT(*) >= ALL (SELECT fieldB FROM t2 WHERE fieldA = field1); SELECT field1, field2 FROM t1 GROUP BY field1, field2 - HAVING COUNT(*) < ANY (SELECT fieldB + HAVING COUNT(*) < ANY (SELECT fieldB FROM t2 WHERE fieldA = field1); DROP TABLE t1, t2; + # -# Bug #23478: not top-level IN subquery returning a non-empty result set -# with possible NULL values by index access from the outer query +# Bug#23478 not top-level IN subquery returning a non-empty result set +# with possible NULL values by index access from the outer query # CREATE TABLE t1(a int, INDEX (a)); @@ -1986,24 +2013,26 @@ SELECT a, a IN (SELECT a FROM t1) FROM t2; DROP TABLE t1,t2; + # -# Bug #11302: getObject() returns a String for a sub-query of type datetime +# Bug#11302 getObject() returns a String for a sub-query of type datetime # CREATE TABLE t1 (a DATETIME); INSERT INTO t1 VALUES ('1998-09-23'), ('2003-03-25'); -CREATE TABLE t2 AS SELECT - (SELECT a FROM t1 WHERE a < '2000-01-01') AS sub_a +CREATE TABLE t2 AS SELECT + (SELECT a FROM t1 WHERE a < '2000-01-01') AS sub_a FROM t1 WHERE a > '2000-01-01'; SHOW CREATE TABLE t2; -CREATE TABLE t3 AS (SELECT a FROM t1 WHERE a < '2000-01-01') UNION (SELECT a FROM t1 WHERE a > '2000-01-01'); +CREATE TABLE t3 AS (SELECT a FROM t1 WHERE a < '2000-01-01') UNION (SELECT a FROM t1 WHERE a > '2000-01-01'); SHOW CREATE TABLE t3; DROP TABLE t1,t2,t3; + # -# Bug 24670: subquery witout tables but with a WHERE clause +# Bug#24670 subquery witout tables but with a WHERE clause # CREATE TABLE t1 (a int); @@ -2015,9 +2044,10 @@ EXPLAIN SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL; DROP TABLE t1; + # -# Bug 24653: sorting by expressions containing subselects -# that return more than one row +# Bug#24653 sorting by expressions containing subselects +# that return more than one row # CREATE TABLE t1 (a int); @@ -2100,8 +2130,9 @@ select * from t1; select min(a) from t1 group by grp; drop table t1; + # -# Test for bug #9338: lame substitution of c1 instead of c2 +# Test for Bug#9338 lame substitution of c1 instead of c2 # CREATE table t1 ( c1 integer ); @@ -2121,15 +2152,16 @@ SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2 DROP TABLE t1,t2; + # -# Test for bug #9516: wrong evaluation of not_null_tables attribute in SQ +# Test for Bug#9516 wrong evaluation of not_null_tables attribute in SQ # CREATE TABLE t1 ( c1 integer ); INSERT INTO t1 VALUES ( 1 ); INSERT INTO t1 VALUES ( 2 ); INSERT INTO t1 VALUES ( 3 ); -INSERT INTO t1 VALUES ( 6 ); - +INSERT INTO t1 VALUES ( 6 ); + CREATE TABLE t2 ( c2 integer ); INSERT INTO t2 VALUES ( 1 ); INSERT INTO t2 VALUES ( 4 ); @@ -2140,13 +2172,14 @@ CREATE TABLE t3 ( c3 integer ); INSERT INTO t3 VALUES ( 7 ); INSERT INTO t3 VALUES ( 8 ); -SELECT c1,c2 FROM t1 LEFT JOIN t2 ON c1 = c2 +SELECT c1,c2 FROM t1 LEFT JOIN t2 ON c1 = c2 WHERE EXISTS (SELECT c3 FROM t3 WHERE c2 IS NULL ); DROP TABLE t1,t2,t3; + # -# Item_int_with_ref check (BUG#10020) +# Item_int_with_ref check (Bug#10020) # CREATE TABLE `t1` ( `itemid` bigint(20) unsigned NOT NULL auto_increment, @@ -2169,9 +2202,10 @@ INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1'); SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30; drop tables t1,t2; + # # Correct building of equal fields list (do not include outer -# fields) (BUG#6384) +# fields) (Bug#6384) # CREATE TABLE t1 (EMPNUM CHAR(3)); CREATE TABLE t2 (EMPNUM CHAR(3) ); @@ -2185,44 +2219,46 @@ WHERE t1.EMPNUM NOT IN select * from t1; DROP TABLE t1,t2; + # -# Test for bug #11487: range access in a subquery +# Test for Bug#11487 range access in a subquery # CREATE TABLE t1(select_id BIGINT, values_id BIGINT); INSERT INTO t1 VALUES (1, 1); -CREATE TABLE t2 (select_id BIGINT, values_id BIGINT, +CREATE TABLE t2 (select_id BIGINT, values_id BIGINT, PRIMARY KEY(select_id,values_id)); INSERT INTO t2 VALUES (0, 1), (0, 2), (0, 3), (1, 5); -SELECT values_id FROM t1 +SELECT values_id FROM t1 WHERE values_id IN (SELECT values_id FROM t2 WHERE select_id IN (1, 0)); -SELECT values_id FROM t1 +SELECT values_id FROM t1 WHERE values_id IN (SELECT values_id FROM t2 WHERE select_id BETWEEN 0 AND 1); -SELECT values_id FROM t1 +SELECT values_id FROM t1 WHERE values_id IN (SELECT values_id FROM t2 WHERE select_id = 0 OR select_id = 1); DROP TABLE t1, t2; -# BUG#11821 : Select from subselect using aggregate function on an enum -# segfaults: + +# Bug#11821 Select from subselect using aggregate function on an enum segfaults create table t1 (fld enum('0','1')); insert into t1 values ('1'); select * from (select max(fld) from t1) as foo; drop table t1; + # -# Test for bug #11762: subquery with an aggregate function in HAVING +# Test for Bug#11762 subquery with an aggregate function in HAVING # CREATE TABLE t1 (a int, b int); CREATE TABLE t2 (c int, d int); CREATE TABLE t3 (e int); -INSERT INTO t1 VALUES +INSERT INTO t1 VALUES (1,10), (2,10), (1,20), (2,20), (3,20), (2,30), (4,40); INSERT INTO t2 VALUES (2,10), (2,20), (4,10), (5,10), (3,20), (2,40); @@ -2252,7 +2288,7 @@ SELECT a FROM t1 GROUP BY a WHERE EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e < d)); SELECT a FROM t1 GROUP BY a HAVING a IN (SELECT c FROM t2 - WHERE MIN(b) < d AND + WHERE MIN(b) < d AND EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d)); SELECT a, SUM(a) FROM t1 GROUP BY a; @@ -2280,9 +2316,9 @@ SELECT t1.a FROM t1 GROUP BY t1.a -- error ER_INVALID_GROUP_FUNC_USE SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > ALL(SELECT t2.c FROM t2 - WHERE EXISTS(SELECT t3.e FROM t3 + WHERE EXISTS(SELECT t3.e FROM t3 WHERE SUM(t1.a+t2.c) < t3.e/4)); --- error ER_INVALID_GROUP_FUNC_USE +-- error ER_INVALID_GROUP_FUNC_USE SELECT t1.a from t1 GROUP BY t1.a HAVING AVG(SUM(t1.b)) > 20; SELECT t1.a FROM t1 GROUP BY t1.a @@ -2298,9 +2334,10 @@ SELECT t1.a, SUM(b) AS sum FROM t1 GROUP BY t1.a DROP TABLE t1,t2,t3; + # -# Test for bug #16603: GROUP BY in a row subquery with a quantifier -# when an index is defined on the grouping field +# Test for Bug#16603 GROUP BY in a row subquery with a quantifier +# when an index is defined on the grouping field CREATE TABLE t1 (a varchar(5), b varchar(10)); INSERT INTO t1 VALUES @@ -2319,27 +2356,30 @@ SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a); DROP TABLE t1; + # -# Bug#17366: Unchecked Item_int results in server crash +# Bug#17366 Unchecked Item_int results in server crash # create table t1( f1 int,f2 int); insert into t1 values (1,1),(2,2); select tt.t from (select 'crash1' as t, f2 from t1) as tt left join t1 on tt.t = 'crash2' and tt.f2 = t1.f2 where tt.t = 'crash1'; drop table t1; + # -# Bug #18306: server crash on delete using subquery. +# Bug#18306 server crash on delete using subquery. # -create table t1 (c int, key(c)); +create table t1 (c int, key(c)); insert into t1 values (1142477582), (1142455969); create table t2 (a int, b int); insert into t2 values (2, 1), (1, 0); delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1; drop table t1, t2; + # -# Bug #7549: Missing error message for invalid view selection with subquery +# Bug#7549 Missing error message for invalid view selection with subquery # CREATE TABLE t1 (a INT); @@ -2353,16 +2393,18 @@ SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1); DROP TABLE t1; + # -# Bug#19077: A nested materialized derived table is used before being populated. +# Bug#19077 A nested materialized derived table is used before being populated. # create table t1 (i int, j bigint); insert into t1 values (1, 2), (2, 2), (3, 2); select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3; drop table t1; -# -# Bug#19700: subselect returning BIGINT always returned it as SIGNED + +# +# Bug#19700 subselect returning BIGINT always returned it as SIGNED # CREATE TABLE t1 (i BIGINT UNSIGNED); INSERT INTO t1 VALUES (10000000000000000000); # > MAX SIGNED BIGINT 9323372036854775807 @@ -2384,8 +2426,9 @@ SELECT t1.i FROM t1 WHERE t1.i = CAST((SELECT MAX(i) FROM t2) AS UNSIGNED); DROP TABLE t1; DROP TABLE t2; -# -# Bug#20519: subselect with LIMIT M, N + +# +# Bug#20519 subselect with LIMIT M, N # CREATE TABLE t1 ( @@ -2402,7 +2445,7 @@ CREATE TABLE t2 ( date date NOT NULL, PRIMARY KEY (id) ); -INSERT INTO t2 VALUES +INSERT INTO t2 VALUES (1, 1, '2006-03-30'), (2, 2, '2006-04-06'), (3, 3, '2006-04-13'), (4, 2, '2006-04-20'), (5, 1, '2006-05-01'); @@ -2424,8 +2467,9 @@ SELECT *, FROM t1; DROP TABLE t1,t2; + # -# Bug#20869: subselect with range access by DESC +# Bug#20869 subselect with range access by DESC # CREATE TABLE t1 ( @@ -2434,7 +2478,7 @@ CREATE TABLE t1 ( t datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (i1,i2,t) ); -INSERT INTO t1 VALUES +INSERT INTO t1 VALUES (24,1,'2005-03-03 16:31:31'),(24,1,'2005-05-27 12:40:07'), (24,1,'2005-05-27 12:40:08'),(24,1,'2005-05-27 12:40:10'), (24,1,'2005-05-27 12:40:25'),(24,1,'2005-05-27 12:40:30'), @@ -2452,34 +2496,34 @@ INSERT INTO t2 VALUES (24,1,'2006-06-20 12:29:40'); EXPLAIN SELECT * FROM t1,t2 - WHERE t1.t = (SELECT t1.t FROM t1 + WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 ORDER BY t1.t DESC LIMIT 1); SELECT * FROM t1,t2 - WHERE t1.t = (SELECT t1.t FROM t1 + WHERE t1.t = (SELECT t1.t FROM t1 WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 ORDER BY t1.t DESC LIMIT 1); DROP TABLE t1, t2; + # -# Bug#14654 : Cannot select from the same table twice within a UNION -# statement +# Bug#14654 Cannot select from the same table twice within a UNION statement # CREATE TABLE t1 (i INT); (SELECT i FROM t1) UNION (SELECT i FROM t1); #TODO:not supported --error ER_PARSE_ERROR -SELECT sql_no_cache * FROM t1 WHERE NOT EXISTS +SELECT sql_no_cache * FROM t1 WHERE NOT EXISTS ( - (SELECT i FROM t1) UNION + (SELECT i FROM t1) UNION (SELECT i FROM t1) ); #TODO:not supported --error ER_PARSE_ERROR -SELECT * FROM t1 +SELECT * FROM t1 WHERE NOT EXISTS (((SELECT i FROM t1) UNION (SELECT i FROM t1))); #TODO:not supported @@ -2489,14 +2533,15 @@ explain select ((select t11.i from t1 t11) union (select t12.i from t1 t12)) #TODO:not supported --error ER_PARSE_ERROR -explain select * from t1 where not exists +explain select * from t1 where not exists ((select t11.i from t1 t11) union (select t12.i from t1 t12)); DROP TABLE t1; + # -# Bug#21798: memory leak during query execution with subquery in column -# list using a function +# Bug#21798 memory leak during query execution with subquery in column +# list using a function # CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b)); insert into t1 (a) values (FLOOR(rand() * 100)); @@ -2514,15 +2559,16 @@ insert into t1 (a) select FLOOR(rand() * 100) from t1; insert into t1 (a) select FLOOR(rand() * 100) from t1; insert into t1 (a) select FLOOR(rand() * 100) from t1; -SELECT a, - (SELECT REPEAT(' ',250) FROM t1 i1 - WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a +SELECT a, + (SELECT REPEAT(' ',250) FROM t1 i1 + WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a FROM t1 ORDER BY a LIMIT 5; DROP TABLE t1; + # -# Bug #21540: Subqueries with no from and aggregate functions return -# wrong results +# Bug#21540 Subqueries with no from and aggregate functions return +# wrong results CREATE TABLE t1 (a INT, b INT); CREATE TABLE t2 (a INT); INSERT INTO t2 values (1); @@ -2531,29 +2577,30 @@ SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a; SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) FROM t1 GROUP BY t1.a; SELECT COUNT(DISTINCT t1.b), (SELECT COUNT(DISTINCT t1.b)) FROM t1 GROUP BY t1.a; -SELECT COUNT(DISTINCT t1.b), +SELECT COUNT(DISTINCT t1.b), (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) FROM t1 GROUP BY t1.a; SELECT ( SELECT ( SELECT COUNT(DISTINCT t1.b) ) -) +) FROM t1 GROUP BY t1.a; SELECT ( SELECT ( SELECT ( SELECT COUNT(DISTINCT t1.b) ) - ) - FROM t1 GROUP BY t1.a LIMIT 1) + ) + FROM t1 GROUP BY t1.a LIMIT 1) FROM t1 t2 GROUP BY t2.a; -DROP TABLE t1,t2; +DROP TABLE t1,t2; + # -# Bug #21727: Correlated subquery that requires filesort: -# slow with big sort_buffer_size +# Bug#21727 Correlated subquery that requires filesort: +# slow with big sort_buffer_size # CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b)); @@ -2571,26 +2618,27 @@ while ($1) { eval INSERT INTO t2(y,z) VALUES(@id,RAND()*1000); dec $2; - } + } dec $1; } enable_query_log; SET SESSION sort_buffer_size = 32 * 1024; -SELECT SQL_NO_CACHE COUNT(*) +SELECT SQL_NO_CACHE COUNT(*) FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c FROM t1) t; SET SESSION sort_buffer_size = 8 * 1024 * 1024; -SELECT SQL_NO_CACHE COUNT(*) +SELECT SQL_NO_CACHE COUNT(*) FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c FROM t1) t; DROP TABLE t1,t2; + # -# Bug #25219: EXIST subquery with UNION over a mix of -# correlated and uncorrelated selects +# Bug#25219 EXIST subquery with UNION over a mix of +# correlated and uncorrelated selects # CREATE TABLE t1 (id char(4) PRIMARY KEY, c int); @@ -2622,10 +2670,11 @@ SELECT * FROM t1 DROP TABLE t1,t2,t3; -# -# Bug#23800: Outer fields in correlated subqueries is used in a temporary -# table created for sorting. -# + +# +# Bug#23800 Outer fields in correlated subqueries is used in a temporary +# table created for sorting. +# CREATE TABLE t1(f1 int); CREATE TABLE t2(f2 int, f21 int, f3 timestamp); INSERT INTO t1 VALUES (1),(1),(2),(2); @@ -2636,19 +2685,20 @@ PREPARE stmt1 FROM 'SELECT ((SELECT f2 FROM t2 WHERE f21=f1 LIMIT 1) * COUNT(f1) EXECUTE stmt1; EXECUTE stmt1; DEALLOCATE PREPARE stmt1; -SELECT f2, AVG(f21), +SELECT f2, AVG(f21), (SELECT t.f3 FROM t2 AS t WHERE t2.f2=t.f2 AND t.f3=MAX(t2.f3)) AS test FROM t2 GROUP BY f2; -DROP TABLE t1,t2; -CREATE TABLE t1 (a int, b INT, c CHAR(10) NOT NULL); -INSERT INTO t1 VALUES - (1,1,'a'), (1,2,'b'), (1,3,'c'), (1,4,'d'), (1,5,'e'), - (2,1,'f'), (2,2,'g'), (2,3,'h'), (3,4,'i'), (3,3,'j'), - (3,2,'k'), (3,1,'l'), (1,9,'m'); -SELECT a, MAX(b), - (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b)) AS test - FROM t1 GROUP BY a; -DROP TABLE t1; +DROP TABLE t1,t2; +CREATE TABLE t1 (a int, b INT, c CHAR(10) NOT NULL); +INSERT INTO t1 VALUES + (1,1,'a'), (1,2,'b'), (1,3,'c'), (1,4,'d'), (1,5,'e'), + (2,1,'f'), (2,2,'g'), (2,3,'h'), (3,4,'i'), (3,3,'j'), + (3,2,'k'), (3,1,'l'), (1,9,'m'); +SELECT a, MAX(b), + (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b)) AS test + FROM t1 GROUP BY a; +DROP TABLE t1; + # # Bug#21904 (parser problem when using IN with a double "(())") @@ -2749,21 +2799,23 @@ DROP TABLE t1; DROP TABLE t2; DROP TABLE t1xt2; + +# +# Bug#26728 derived table with concatanation of literals in select list # -# Bug #26728: derived table with concatanation of literals in select list -# CREATE TABLE t1 (a int); -INSERT INTO t1 VALUES (3), (1), (2); +INSERT INTO t1 VALUES (3), (1), (2); SELECT 'this is ' 'a test.' AS col1, a AS col2 FROM t1; SELECT * FROM (SELECT 'this is ' 'a test.' AS col1, a AS t2 FROM t1) t; DROP table t1; + +# +# Bug#27257 COUNT(*) aggregated in outer query # -# Bug #27257: COUNT(*) aggregated in outer query -# CREATE TABLE t1 (a int, b int); CREATE TABLE t2 (m int, n int); @@ -2778,15 +2830,16 @@ SELECT COUNT(*), a, (SELECT MIN(m) FROM t2 WHERE m = count(*)) FROM t1 GROUP BY a; -SELECT COUNT(*), a +SELECT COUNT(*), a FROM t1 GROUP BY a HAVING (SELECT MIN(m) FROM t2 WHERE m = count(*)) > 1; DROP TABLE t1,t2; + +# +# Bug#27229 GROUP_CONCAT in subselect with COUNT() as an argument # -# Bug #27229: GROUP_CONCAT in subselect with COUNT() as an argument -# CREATE TABLE t1 (a int, b int); CREATE TABLE t2 (m int, n int); @@ -2803,8 +2856,9 @@ SELECT COUNT(*) c, a, DROP table t1,t2; + # -# Bug#27321: Wrong subquery result in a grouping select +# Bug#27321 Wrong subquery result in a grouping select # CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b)); INSERT INTO t1 VALUES (1,1,0,'a'), (1,2,0,'b'), (1,3,0,'c'), (1,4,0,'d'), @@ -2812,7 +2866,7 @@ INSERT INTO t1 VALUES (1,1,0,'a'), (1,2,0,'b'), (1,3,0,'c'), (1,4,0,'d'), (3,2,0,'k'), (3,1,0,'l'), (1,9,0,'m'), (1,0,10,'n'), (2,0,5,'o'), (3,0,7,'p'); SELECT a, MAX(b), - (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b + 0)) as test + (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b + 0)) as test FROM t1 GROUP BY a; SELECT a x, MAX(b), (SELECT t.c FROM t1 AS t WHERE x=t.a AND t.b=MAX(t1.b + 0)) as test @@ -2823,25 +2877,27 @@ SELECT a, AVG(b), SELECT tt.a, (SELECT (SELECT c FROM t1 as t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a) - LIMIT 1) FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test + LIMIT 1) FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test FROM t1 as tt; SELECT tt.a, (SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a) LIMIT 1) - FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test + FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test FROM t1 as tt GROUP BY tt.a; SELECT tt.a, MAX( (SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a) LIMIT 1) - FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1)) as test + FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1)) as test FROM t1 as tt GROUP BY tt.a; DROP TABLE t1; + + +# +# Bug#27348 SET FUNCTION used in a subquery from WHERE condition # -# Bug #27348: SET FUNCTION used in a subquery from WHERE condition -# CREATE TABLE t1 (a int, b int); INSERT INTO t1 VALUES (2,22),(1,11),(2,22); @@ -2866,9 +2922,9 @@ SET @@sql_mode=default; DROP TABLE t1; + # -# Bug #27363: nested aggregates in outer, subquery / sum(select -# count(outer)) +# Bug#27363 nested aggregates in outer, subquery / sum(select count(outer)) # CREATE TABLE t1 (a INT); INSERT INTO t1 values (1),(1),(1),(1); CREATE TABLE t2 (x INT); INSERT INTO t1 values (1000),(1001),(1002); @@ -2883,28 +2939,30 @@ SELECT COUNT(1) FROM DUAL; SELECT SUM( (SELECT AVG( (SELECT t1.a FROM t2) ) FROM DUAL) ) FROM t1; --error ER_INVALID_GROUP_FUNC_USE -SELECT +SELECT SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING t1.a < 12) ) FROM t2) ) FROM t1; --error ER_INVALID_GROUP_FUNC_USE -SELECT t1.a as XXA, +SELECT t1.a as XXA, SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING XXA < 12) ) FROM t2) ) FROM t1; DROP TABLE t1,t2; + # -# Bug #27807: Server crash when executing subquery with EXPLAIN -# -CREATE TABLE t1 (a int, b int, KEY (a)); +# Bug#27807 Server crash when executing subquery with EXPLAIN +# +CREATE TABLE t1 (a int, b int, KEY (a)); INSERT INTO t1 VALUES (1,1),(2,1); EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b); DROP TABLE t1; + +# +# Bug#28377 grouping query with a correlated subquery in WHERE condition # -# Bug #28377: grouping query with a correlated subquery in WHERE condition -# CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)); INSERT INTO t1 VALUES @@ -2912,24 +2970,25 @@ INSERT INTO t1 VALUES CREATE TABLE t2 (id int NOT NULL, INDEX idx(id)); INSERT INTO t2 VALUES (7), (5), (1), (3); -SELECT id, st FROM t1 +SELECT id, st FROM t1 WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id); -SELECT id, st FROM t1 +SELECT id, st FROM t1 WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id) GROUP BY id; -SELECT id, st FROM t1 +SELECT id, st FROM t1 WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id); -SELECT id, st FROM t1 +SELECT id, st FROM t1 WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id) GROUP BY id; DROP TABLE t1,t2; + +# +# Bug#28728 crash with EXPLAIN EXTENDED for a query with a derived table +# over a grouping subselect # -# Bug #28728: crash with EXPLAIN EXTENDED for a query with a derived table -# over a grouping subselect -# CREATE TABLE t1 (a int); @@ -2940,10 +2999,11 @@ SELECT * FROM (SELECT count(*) FROM t1 GROUP BY a) as res; DROP TABLE t1; + # -# Bug #28811: crash for query containing subquery with ORDER BY and LIMIT 1 +# Bug#28811 crash for query containing subquery with ORDER BY and LIMIT 1 # - + CREATE TABLE t1 ( a varchar(255) default NULL, b timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, @@ -2974,8 +3034,8 @@ DROP TABLE t1,t2; # -# Bug #27333: subquery grouped for aggregate of outer query / no aggregate -# of subquery +# Bug#27333 subquery grouped for aggregate of outer query / no aggregate +# of subquery # CREATE TABLE t1 (a INTEGER, b INTEGER); CREATE TABLE t2 (x INTEGER); @@ -3015,7 +3075,7 @@ SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=1) FROM t1; DROP TABLE t1,t2; # -# Bug #31884: Assertion + crash in subquery in the SELECT clause. +# Bug#31884 Assertion + crash in subquery in the SELECT clause. # CREATE TABLE t1 (a1 INT, a2 INT); @@ -3030,7 +3090,7 @@ SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1; DROP TABLE t1, t2; # -# Bug #28076: inconsistent binary/varbinary comparison +# Bug#28076 inconsistent binary/varbinary comparison # CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5)); @@ -3071,8 +3131,9 @@ SELECT LEFT(t1.a1,1) FROM t1,t3 WHERE t1.b1=t3.a3; SELECT a2 FROM t2 WHERE t2.a2 IN (SELECT t1.a1 FROM t1,t3 WHERE t1.b1=t3.a3); DROP TABLE t1, t2, t3; + # -# Bug #30788: Inconsistent retrieval of char/varchar +# Bug#30788 Inconsistent retrieval of char/varchar # CREATE TABLE t1 (a CHAR(1), b VARCHAR(10)); @@ -3096,16 +3157,16 @@ SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500); DROP TABLE t1,t2; + # -# Bug #32400: Complex SELECT query returns correct result only on some -# occasions +# Bug#32400 Complex SELECT query returns correct result only on some occasions # CREATE TABLE t1(a INT, b INT); INSERT INTO t1 VALUES (1,1), (1,2), (2,3), (2,4); --error ER_BAD_FIELD_ERROR -EXPLAIN +EXPLAIN SELECT a AS out_a, MIN(b) FROM t1 WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a) GROUP BY a; @@ -3115,7 +3176,7 @@ SELECT a AS out_a, MIN(b) FROM t1 WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a) GROUP BY a; -EXPLAIN +EXPLAIN SELECT a AS out_a, MIN(b) FROM t1 t1_outer WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a) GROUP BY a; @@ -3128,7 +3189,7 @@ DROP TABLE t1; # -# Bug #32036: EXISTS within a WHERE clause with a UNION crashes MySQL 5.122 +# Bug#32036 EXISTS within a WHERE clause with a UNION crashes MySQL 5.122 # CREATE TABLE t1 (a INT); @@ -3145,14 +3206,15 @@ SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); #TODO:not supported --error ER_PARSE_ERROR EXPLAIN EXTENDED -SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION +SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION (SELECT 1 FROM t2 WHERE t1.a = t2.a)); DROP TABLE t1,t2; + # -# Bug#33675: Usage of an uninitialized memory by filesort in a subquery -# caused server crash. +# Bug#33675 Usage of an uninitialized memory by filesort in a subquery +# caused server crash. # create table t1(f11 int, f12 int); create table t2(f21 int unsigned not null, f22 int, f23 varchar(10)); @@ -3168,13 +3230,14 @@ while ($i) --enable_warnings --enable_query_log set session sort_buffer_size= 33*1024; -select count(*) from t1 where f12 = +select count(*) from t1 where f12 = (select f22 from t2 where f22 = f12 order by f21 desc, f22, f23 limit 1); drop table t1,t2; + # -# BUG#33794 "MySQL crashes executing specific query on specific dump" +# Bug#33794 "MySQL crashes executing specific query on specific dump" # CREATE TABLE t4 ( f7 varchar(32) collate utf8_bin NOT NULL default '', @@ -3216,24 +3279,25 @@ SELECT FROM t2 VPC, t4 a2, t2 a3 WHERE VPC.f4 = a2.f10 AND a3.f2 = a4 - LIMIT 1) IS NULL, - 0, + LIMIT 1) IS NULL, + 0, t3.f5 ) ) AS a6 -FROM +FROM t2, t3, t1 JOIN t2 a1 ON t1.f9 = a1.f4 GROUP BY a4; DROP TABLE t1, t2, t3, t4; + # -# BUG#36139 "float, zerofill, crash with subquery" +# Bug#36139 "float, zerofill, crash with subquery" # create table t1 (a float(5,4) zerofill); create table t2 (a float(5,4),b float(2,0)); -select t1.a from t1 where +select t1.a from t1 where t1.a= (select b from t2 limit 1) and not t1.a= (select a from t2 limit 1) ; @@ -3241,8 +3305,8 @@ drop table t1, t2; # -# Bug #36011: Server crash with explain extended on query with dependent -# subqueries +# Bug#36011 Server crash with explain extended on query with dependent +# subqueries # CREATE TABLE t1 (a INT); @@ -3254,10 +3318,10 @@ DROP TABLE t1; --echo End of 5.0 tests. # -# Bug #27348: SET FUNCTION used in a subquery from WHERE condition -# +# Bug#27348 SET FUNCTION used in a subquery from WHERE condition +# -CREATE TABLE t1 (a int, b int); +CREATE TABLE t1 (a INT, b INT); INSERT INTO t1 VALUES (2,22),(1,11),(2,22); SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a; @@ -3282,17 +3346,17 @@ DROP TABLE t1; # # Bug#20835 (literal string with =any values) # -CREATE TABLE t1 (s1 char(1)); +CREATE TABLE t1 (s1 CHAR(1)); INSERT INTO t1 VALUES ('a'); SELECT * FROM t1 WHERE _utf8'a' = ANY (SELECT s1 FROM t1); DROP TABLE t1; # -# Bug #37004: NOT IN subquery with MAX over an empty set +# Bug#37004 NOT IN subquery with MAX over an empty set # -CREATE TABLE t1(c int, KEY(c)); -CREATE TABLE t2(a int, b int); +CREATE TABLE t1(c INT, KEY(c)); +CREATE TABLE t2(a INT, b INT); INSERT INTO t2 VALUES (1, 10), (2, NULL); INSERT INTO t1 VALUES (1), (3); @@ -3301,30 +3365,30 @@ SELECT * FROM t2 WHERE b NOT IN (SELECT max(t.c) FROM t1, t1 t WHERE t.c>10); DROP TABLE t1,t2; # -# Bug #38191: Server crash with subquery containing DISTINCT and ORDER BY +# Bug#38191 Server crash with subquery containing DISTINCT and ORDER BY # -CREATE TABLE t1(pk int PRIMARY KEY, a int, INDEX idx(a)); +CREATE TABLE t1(pk INT PRIMARY KEY, a INT, INDEX idx(a)); INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20); -CREATE TABLE t2(pk int PRIMARY KEY, a int, b int, INDEX idxa(a)); +CREATE TABLE t2(pk INT PRIMARY KEY, a INT, b INT, INDEX idxa(a)); INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100); SELECT * FROM t1 WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b); DROP TABLE t1,t2; # -# Bug #37548: result value erronously reported being NULL in certain subqueries +# Bug#37548 result value erronously reported being NULL in certain subqueries # -CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY b (b)); +CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), KEY b (b)); INSERT INTO t1 VALUES (1,NULL), (9,NULL); CREATE TABLE t2 ( - a int, - b int, - c int, - d int, + a INT, + b INT, + c INT, + d INT, PRIMARY KEY (a), UNIQUE KEY b (b,c,d), KEY b_2 (b), @@ -3332,7 +3396,7 @@ CREATE TABLE t2 ( KEY d (d) ); -INSERT INTO t2 VALUES +INSERT INTO t2 VALUES (43, 2, 11 ,30), (44, 2, 12 ,30), (45, 1, 1 ,10000), @@ -3340,9 +3404,9 @@ INSERT INTO t2 VALUES (556,1, 32 ,10000); CREATE TABLE t3 ( - a int, - b int, - c int, + a INT, + b INT, + c INT, PRIMARY KEY (a), UNIQUE KEY b (b,c), KEY c (c), @@ -3351,7 +3415,7 @@ CREATE TABLE t3 ( INSERT INTO t3 VALUES (1,1,1), (2,32,1); -explain +explain SELECT t1.a, (SELECT 1 FROM t2 WHERE t2.b=t3.c AND t2.c=t1.a ORDER BY t2.d LIMIT 1) AS incorrect FROM t1, t3 WHERE t3.b=t1.a; SELECT t1.a, (SELECT 1 FROM t2 WHERE t2.b=t3.c AND t2.c=t1.a ORDER BY t2.d LIMIT 1) AS incorrect FROM t1, t3 WHERE t3.b=t1.a; @@ -3370,22 +3434,22 @@ INSERT INTO t1 (id) VALUES (1); INSERT INTO t2 (id) VALUES (1); CREATE VIEW v1 AS - SELECT t2.c AS c FROM t1, t2 - WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION; +SELECT t2.c AS c FROM t1, t2 +WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION; UPDATE v1 SET c=1; CREATE VIEW v2 (a,b) AS - SELECT t2.id, t2.c AS c FROM t1, t2 - WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION; +SELECT t2.id, t2.c AS c FROM t1, t2 +WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION; ---error 1369 +--error ER_VIEW_CHECK_FAILED INSERT INTO v2(a,b) VALUES (2,2); INSERT INTO v2(a,b) VALUES (1,2); SELECT * FROM v1; CREATE VIEW v3 AS - SELECT t2.c AS c FROM t2 - WHERE 1 IN (SELECT id FROM t1) WITH CHECK OPTION; +SELECT t2.c AS c FROM t2 +WHERE 1 IN (SELECT id FROM t1) WITH CHECK OPTION; DELETE FROM v3; @@ -3393,7 +3457,7 @@ DROP VIEW v1,v2,v3; DROP TABLE t1,t2; --echo # ---echo # BUG#37822: Correlated subquery with IN and IS UNKNOWN provides wrong result +--echo # Bug#37822 Correlated subquery with IN and IS UNKNOWN provides wrong result --echo # create table t1(id integer primary key, g integer, v integer, s char(1)); create table t2(id integer primary key, g integer, v integer, s char(1)); diff --git a/mysql-test/t/synchronization.test b/mysql-test/t/synchronization.test index 71e13a65ec3bd40ecc27039a5061bfac1da425ae..aef06245717cc7eacdd4a946484e8fd4f5d4dc13 100644 --- a/mysql-test/t/synchronization.test +++ b/mysql-test/t/synchronization.test @@ -1,10 +1,13 @@ +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + # -# Test for Bug #2385 CREATE TABLE LIKE lacks locking on source and destination -# table +# Test for Bug#2385 CREATE TABLE LIKE lacks locking on source and destination +# table # --disable_warnings -drop table if exists t1,t2; +DROP TABLE IF EXISTS t1,t2; --enable_warnings connect (con1,localhost,root,,); @@ -12,12 +15,12 @@ connect (con2,localhost,root,,); # locking of source: -CREATE TABLE t1 (x1 int); +CREATE TABLE t1 (x1 INT); let $1= 10; while ($1) { connection con1; - send ALTER TABLE t1 CHANGE x1 x2 int; + send ALTER TABLE t1 CHANGE x1 x2 INT; connection con2; CREATE TABLE t2 LIKE t1; replace_result x1 xx x2 xx; @@ -25,7 +28,7 @@ while ($1) DROP TABLE t2; connection con1; reap; - send ALTER TABLE t1 CHANGE x2 x1 int; + send ALTER TABLE t1 CHANGE x2 x1 INT; connection con2; CREATE TABLE t2 LIKE t1; replace_result x1 xx x2 xx; @@ -37,4 +40,11 @@ while ($1) } DROP TABLE t1; +connection default; +disconnect con1; +disconnect con2; + # End of 4.1 tests + +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/timezone_grant.test b/mysql-test/t/timezone_grant.test index 450c1edc47ee929d6eb2514431607d58757cd415..8013f2b04cee4df59bec57ca8f3634e48be2d35e 100644 --- a/mysql-test/t/timezone_grant.test +++ b/mysql-test/t/timezone_grant.test @@ -1,15 +1,18 @@ # Embedded server testing does not support grants -- source include/not_embedded.inc +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + --disable_warnings drop tables if exists t1, t2; drop view if exists v1; --enable_warnings # -# Test for bug #6116 "SET time_zone := ... requires access to mysql.time_zone -# tables". We should allow implicit access to time zone description tables -# even for unprivileged users. +# Test for Bug#6116 SET time_zone := ... requires access to mysql.time_zone tables +# We should allow implicit access to time zone description tables even for +# unprivileged users. # # Let us prepare playground @@ -33,18 +36,20 @@ select convert_tz(b, 'Europe/Moscow', 'UTC') from t1; update t1, t2 set t1.b = convert_tz('2004-10-21 19:00:00', 'Europe/Moscow', 'UTC') where t1.a = t2.c and t2.d = (select max(d) from t2); # But still these two statements should not work: ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR select * from mysql.time_zone_name; ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR select Name, convert_tz('2004-10-21 19:00:00', Name, 'UTC') from mysql.time_zone_name; +connection default; +disconnect tzuser; + # -# Test for bug #6765 "Implicit access to time zone description tables -# requires privileges for them if some table or column level grants -# present" +# Bug#6765 Implicit access to time zone description tables requires privileges +# for them if some table or column level grants present # connection default; -# Let use some table-level grants instead of db-level +# Let use some table-level grants instead of db-level # to make life more interesting delete from mysql.db where user like 'mysqltest\_%'; flush privileges; @@ -61,14 +66,14 @@ select convert_tz(b, 'Europe/Moscow', 'UTC') from t1; update t1, t2 set t1.b = convert_tz('2004-11-30 12:00:00', 'Europe/Moscow', 'UTC') where t1.a = t2.c and t2.d = (select max(d) from t2); # Again these two statements should not work (but with different errors): ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR select * from mysql.time_zone_name; ---error 1142 +--error ER_TABLEACCESS_DENIED_ERROR select Name, convert_tz('2004-11-30 12:00:00', Name, 'UTC') from mysql.time_zone_name; # -# Bug #9979: Use of CONVERT_TZ in multiple-table UPDATE causes bogus -# privilege error +# Bug#9979 Use of CONVERT_TZ in multiple-table UPDATE causes bogus +# privilege error # drop table t1, t2; create table t1 (a int, b datetime); @@ -80,6 +85,7 @@ update t1 join t2 on (t1.a = t2.a) set t1.b = convert_tz('2005-01-01 10:00','UTC # Clean-up connection default; +disconnect tzuser2; delete from mysql.user where user like 'mysqltest\_%'; delete from mysql.db where user like 'mysqltest\_%'; delete from mysql.tables_priv where user like 'mysqltest\_%'; @@ -89,10 +95,9 @@ drop table t1, t2; # End of 4.1 tests # -# Additional test for bug #15153: CONVERT_TZ() is not allowed in all -# places in views. +# Additional test for Bug#15153 CONVERT_TZ() is not allowed in all places in views. # -# Let us check that usage of CONVERT_TZ() function in view does not +# Let us check that usage of CONVERT_TZ() function in view does not # require additional privileges. # Let us rely on that previous tests done proper cleanups @@ -109,7 +114,11 @@ drop view v1; --error ER_TABLEACCESS_DENIED_ERROR create view v1 as select a, convert_tz(b, 'UTC', 'Europe/Moscow') as lb from t1, mysql.time_zone; connection default; +disconnect tzuser3; drop table t1; drop user mysqltest_1@localhost; # End of 5.0 tests + +# Wait till we reached the initial number of concurrent sessions +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test index eb1b7bde844c1106149dd6426f7500f5a571ec54..d4fa6bed1869236f79c09185022c11377b4d8808 100644 --- a/mysql-test/t/type_datetime.test +++ b/mysql-test/t/type_datetime.test @@ -427,3 +427,22 @@ create table t1 (da date default '1962-03-32 23:33:34', dt datetime default '196 --error 1067 create table t1 (t time default '916:00:00 a'); set @@sql_mode= @org_mode; + +# +# Bug #42146 - DATETIME fractional seconds parse error +# +# show we trucate microseconds from the right -- special case: leftmost is 0 +SELECT CAST(CAST('2006-08-10 10:11:12.0123450' AS DATETIME) AS DECIMAL(30,7)); + +# show that we ignore leading zeroes for all other fields +SELECT CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.0123450' AS DATETIME) AS DECIMAL(30,7)); +# once more with feeling (but no warnings) +SELECT CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.012345' AS DATETIME) AS DECIMAL(30,7)); + +# +# Bug #38435 - LONG Microseconds cause MySQL to fail a CAST to DATETIME or DATE +# +# show we truncate microseconds from the right +SELECT CAST(CAST('2008-07-29T10:42:51.1234567' AS DateTime) AS DECIMAL(30,7)); + +--echo End of 5.1 tests diff --git a/mysql-test/t/type_float.test b/mysql-test/t/type_float.test index 53bcf44061df61b57f88c83d7aed7da1c304a87f..42703e11863eb40cae0f4151ba8596b0ceae297f 100644 --- a/mysql-test/t/type_float.test +++ b/mysql-test/t/type_float.test @@ -267,4 +267,12 @@ select u from t1; drop table t1; +# +# Bug #21205: Different number of digits for float/doble/real in --ps-protocol +# + +CREATE TABLE t1 (f1 DOUBLE); +INSERT INTO t1 VALUES(-1.79769313486231e+308); +SELECT f1 FROM t1; + --echo End of 5.0 tests diff --git a/mysql-test/t/windows.test b/mysql-test/t/windows.test index 6871caaa7560c787dcb76b57dcd313e5505501c2..89cd2ed19e84f30a3a3b6e8ce671fad716823df1 100755 --- a/mysql-test/t/windows.test +++ b/mysql-test/t/windows.test @@ -35,6 +35,37 @@ CREATE TABLE t1 (a int, b int); INSERT INTO t1 VALUES (1,1); EXPLAIN SELECT * FROM t1 WHERE b = (SELECT max(2)); DROP TABLE t1; +# +# Bug #33813: Schema names are case-sensitive in DROP FUNCTION +# + +CREATE DATABASE `TESTDB`; + +USE `TESTDB`; +DELIMITER //; + +CREATE FUNCTION test_fn() RETURNS INTEGER +BEGIN +DECLARE rId bigint; +RETURN rId; +END +// + +CREATE FUNCTION test_fn2() RETURNS INTEGER +BEGIN +DECLARE rId bigint; +RETURN rId; +END +// + +DELIMITER ;// + +DROP FUNCTION `TESTDB`.`test_fn`; +DROP FUNCTION `testdb`.`test_fn2`; + +USE test; +DROP DATABASE `TESTDB`; + --echo End of 5.0 tests. --disable_warnings diff --git a/sql-bench/test-create.sh b/sql-bench/test-create.sh index bc2f17c1f0a3ced8043f1f4c07e091ddf71280e6..63672519e614ff0fca6c415e5609cfc8c0f61df7 100644 --- a/sql-bench/test-create.sh +++ b/sql-bench/test-create.sh @@ -247,7 +247,7 @@ for ($i=2 ; $i <= $keys ; $i++) $loop_time=new Benchmark; for ($i=1 ; $i <= $opt_loop_count ; $i++) { - do_many($dbh,$server->create("bench_$i", \@fields, \@index)); + do_many($dbh,$server->create("bench_$i", \@fields, \@keys)); $dbh->do("drop table bench_$i" . $server->{'drop_attr'}) or die $DBI::errstr; } diff --git a/sql-common/my_time.c b/sql-common/my_time.c index 155e0237e3cb6a038305e062ba3b37f75c3902d2..747c5797ed486c558572e57e78e09e7a1cbe5cf5 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -264,8 +264,19 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, { const char *start= str; ulong tmp_value= (uint) (uchar) (*str++ - '0'); + + /* + Internal format means no delimiters; every field has a fixed + width. Otherwise, we scan until we find a delimiter and discard + leading zeroes -- except for the microsecond part, where leading + zeroes are significant, and where we never process more than six + digits. + */ + my_bool scan_until_delim= !is_internal_format && + ((i != format_position[6])); + while (str != end && my_isdigit(&my_charset_latin1,str[0]) && - (!is_internal_format || --field_length)) + (scan_until_delim || --field_length)) { tmp_value=tmp_value*10 + (ulong) (uchar) (*str - '0'); str++; diff --git a/sql/item_func.cc b/sql/item_func.cc index 34cb50ee7fa7c2b559dd7a7ba422d524ba9d0e30..ec95254baaa8b346be2b357710cd5ec3f3bd5d2f 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -5371,7 +5371,10 @@ bool Item_func_match::fix_fields(THD *thd, Item **ref) if (item->type() == Item::REF_ITEM) args[i]= item= *((Item_ref *)item)->ref; if (item->type() != Item::FIELD_ITEM) - key=NO_SUCH_KEY; + { + my_error(ER_WRONG_ARGUMENTS, MYF(0), "AGAINST"); + return TRUE; + } } /* Check that all columns come from the same table. diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 015128cda1f364f0653a02f00858eb962c1c7eec..3fba92489408ebddd11d3b9dc8040816c7a00613 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -282,16 +282,12 @@ class Default_object_creation_ctx : public Object_creation_ctx */ #define TABLE_DEF_CACHE_MIN 256 -/* - Value of 9236 discovered through binary search 2006-09-26 on Ubuntu Dapper - Drake, libc6 2.3.6-0ubuntu2, Linux kernel 2.6.15-27-686, on x86. (Added - 100 bytes as reasonable buffer against growth and other environments' - requirements.) - - Feel free to raise this by the smallest amount you can to get the - "execution_constants" test to pass. - */ -#define STACK_MIN_SIZE 12000 ///< Abort if less stack during eval. +/* + Stack reservation. + Feel free to raise this by the smallest amount you can to get the + "execution_constants" test to pass. +*/ +#define STACK_MIN_SIZE 16000 // Abort if less stack during eval. #define STACK_MIN_SIZE_FOR_OPEN 1024*80 #define STACK_BUFF_ALLOC 352 ///< For stack overrun checks diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 0213eea889b3f90d207190d4541251d2be2ff549..88b923244e7c02aa9dbd72a3966febf3d990b770 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -688,6 +688,8 @@ bool mysqld_embedded=0; bool mysqld_embedded=1; #endif +static my_bool plugins_are_initialized= FALSE; + #ifndef DBUG_OFF static const char* default_dbug_option; #endif @@ -1172,10 +1174,10 @@ extern "C" void unireg_abort(int exit_code) { DBUG_ENTER("unireg_abort"); + if (opt_help) + usage(); if (exit_code) sql_print_error("Aborting\n"); - else if (opt_help) - usage(); clean_up(!opt_help && (exit_code || !opt_bootstrap)); /* purecov: inspected */ DBUG_PRINT("quit",("done with cleanup in unireg_abort")); wait_for_signal_thread_to_end(); @@ -3843,12 +3845,15 @@ server."); if (ha_init_errors()) DBUG_RETURN(1); - if (plugin_init(&defaults_argc, defaults_argv, - (opt_noacl ? PLUGIN_INIT_SKIP_PLUGIN_TABLE : 0) | - (opt_help ? PLUGIN_INIT_SKIP_INITIALIZATION : 0))) - { - sql_print_error("Failed to initialize plugins."); - unireg_abort(1); + { + if (plugin_init(&defaults_argc, defaults_argv, + (opt_noacl ? PLUGIN_INIT_SKIP_PLUGIN_TABLE : 0) | + (opt_help ? PLUGIN_INIT_SKIP_INITIALIZATION : 0))) + { + sql_print_error("Failed to initialize plugins."); + unireg_abort(1); + } + plugins_are_initialized= TRUE; /* Don't separate from init function */ } if (opt_help) @@ -7423,7 +7428,8 @@ static void usage(void) default_collation_name= (char*) default_charset_info->name; print_version(); puts("\ -Copyright (C) 2000 MySQL AB, by Monty and others\n\ +Copyright (C) 2000-2008 MySQL AB, by Monty and others\n\ +Copyright (C) 2008 Sun Microsystems, Inc.\n\ This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\ and you are welcome to modify and redistribute it under the GPL license\n\n\ Starts the MySQL database server\n"); @@ -7453,6 +7459,13 @@ Starts the MySQL database server\n"); /* Print out all the options including plugin supplied options */ my_print_help_inc_plugins(my_long_options, sizeof(my_long_options)/sizeof(my_option)); + if (! plugins_are_initialized) + { + puts("\n\ +Plugins have parameters that are not reflected in this list\n\ +because execution stopped before plugins were initialized."); + } + puts("\n\ To see what values a running MySQL server is using, type\n\ 'mysqladmin variables' instead of 'mysqld --verbose --help'."); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 6db9f1df0f2c285e33c82f54b0d8a2baa7f00fc9..d17bf085e3b5c0b01363d2b1c5a9398dee048402 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -5103,8 +5103,15 @@ int decide_logging_format(THD *thd, TABLE_LIST *tables) { if (mysql_bin_log.is_open() && (thd->options & OPTION_BIN_LOG)) { - handler::Table_flags flags_some_set= handler::Table_flags(); - handler::Table_flags flags_all_set= ~handler::Table_flags(); + /* + Compute the starting vectors for the computations by creating a + set with all the capabilities bits set and one with no + capabilities bits set. + */ + handler::Table_flags flags_some_set= 0; + handler::Table_flags flags_all_set= + HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE; + my_bool multi_engine= FALSE; void* prev_ht= NULL; for (TABLE_LIST *table= tables; table; table= table->next_global) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 118dc5af68f5f15133b9385f81958888562ccd9e..597478933d68218c69d99ffc6b7686efc0e33c60 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1587,6 +1587,11 @@ bool select_send::send_data(List<Item> &items) my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); break; } + /* + Reset buffer to its original state, as it may have been altered in + Item::send(). + */ + buffer.set(buff, sizeof(buff), &my_charset_bin); } thd->sent_row_count++; if (thd->is_error()) diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 1a23077f6a0734e7ce5dc703a1d7ae95902cd7f9..d87eafa3e0c6e6417cd651f295c4c1094a11e991 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -51,6 +51,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, THD::killed_state killed_status= THD::NOT_KILLED; DBUG_ENTER("mysql_delete"); + THD::enum_binlog_query_type query_type= + thd->lex->sql_command == SQLCOM_TRUNCATE ? + THD::STMT_QUERY_TYPE : + THD::ROW_QUERY_TYPE; + if (open_and_lock_tables(thd, table_list)) DBUG_RETURN(TRUE); if (!(table= table_list->table)) @@ -135,6 +140,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, DBUG_PRINT("debug", ("Trying to use delete_all_rows()")); if (!(error=table->file->ha_delete_all_rows())) { + /* + If delete_all_rows() is used, it is not possible to log the + query in row format, so we have to log it in statement format. + */ + query_type= THD::STMT_QUERY_TYPE; error= -1; // ok deleted= maybe_deleted; goto cleanup; @@ -374,6 +384,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, { if (mysql_bin_log.is_open()) { + bool const is_trans= + thd->lex->sql_command == SQLCOM_TRUNCATE ? + FALSE : + transactional_table; + if (error < 0) thd->clear_error(); /* @@ -381,10 +396,13 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, storage engine does not inject the rows itself, we replicate statement-based; otherwise, 'ha_delete_row()' was used to delete specific rows which we might log row-based. + + Note that TRUNCATE TABLE is not transactional and should + therefore be treated as a DDL. */ - int log_result= thd->binlog_query(THD::ROW_QUERY_TYPE, + int log_result= thd->binlog_query(query_type, thd->query, thd->query_length, - transactional_table, FALSE, killed_status); + is_trans, FALSE, killed_status); if (log_result && transactional_table) { diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 592dbe9f43bd220e5b49c3ff1c509909f147ba12..7c5f469da41030867797128d1d4a8adaef1f66d0 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4427,6 +4427,7 @@ mysql_execute_command(THD *thd) case SP_KEY_NOT_FOUND: if (lex->drop_if_exists) { + write_bin_log(thd, TRUE, thd->query, thd->query_length); push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), SP_COM_STRING(lex), lex->spname->m_name.str); diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 34b310931d63a806483458b5867c3e263ad7c812..d661505d1a93c4509d74a0f7b0b2472c63870a01 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -71,25 +71,22 @@ bool String::realloc(uint32 alloc_length) char *new_ptr; if (alloced) { - if ((new_ptr= (char*) my_realloc(Ptr,len,MYF(MY_WME)))) - { - Ptr=new_ptr; - Alloced_length=len; - } - else - return TRUE; // Signal error + if (!(new_ptr= (char*) my_realloc(Ptr,len,MYF(MY_WME)))) + return TRUE; // Signal error } else if ((new_ptr= (char*) my_malloc(len,MYF(MY_WME)))) { + if (str_length > len - 1) + str_length= 0; if (str_length) // Avoid bugs in memcpy on AIX memcpy(new_ptr,Ptr,str_length); new_ptr[str_length]=0; - Ptr=new_ptr; - Alloced_length=len; alloced=1; } else return TRUE; // Signal error + Ptr= new_ptr; + Alloced_length= len; } Ptr[alloc_length]=0; // This make other funcs shorter return FALSE; @@ -115,7 +112,7 @@ bool String::set_real(double num,uint decimals, CHARSET_INFO *cs) str_charset=cs; if (decimals >= NOT_FIXED_DEC) { - uint32 len= my_sprintf(buff,(buff, "%.14g",num));// Enough for a DATETIME + uint32 len= my_sprintf(buff,(buff, "%.15g",num));// Enough for a DATETIME return copy(buff, len, &my_charset_latin1, cs, &dummy_errors); } #ifdef HAVE_FCONVERT @@ -667,7 +664,7 @@ void String::qs_append(const char *str, uint32 len) void String::qs_append(double d) { char *buff = Ptr + str_length; - str_length+= my_sprintf(buff, (buff, "%.14g", d)); + str_length+= my_sprintf(buff, (buff, "%.15g", d)); } void String::qs_append(double *d) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 7df035bbfc3edc0e700471fb4484f870f900e431..588c4334b848423359bbfebadfcf988c94e4f08e 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -9261,6 +9261,11 @@ drop: THD *thd= YYTHD; LEX *lex= thd->lex; sp_name *spname; + if ($4.str && check_db_name(&$4)) + { + my_error(ER_WRONG_DB_NAME, MYF(0), $4.str); + MYSQL_YYABORT; + } if (lex->sphead) { my_error(ER_SP_NO_DROP_SP, MYF(0), "FUNCTION"); diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index 956f0e421cc6701e709aa30acb3394fdb3150a91..d674f6bc150c2cc220c773ecbf1eb9f77a41ea6c 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -116,7 +116,7 @@ static handler *myisammrg_create_handler(handlerton *hton, */ ha_myisammrg::ha_myisammrg(handlerton *hton, TABLE_SHARE *table_arg) - :handler(hton, table_arg), file(0) + :handler(hton, table_arg), file(0), is_cloned(0) {} @@ -413,7 +413,28 @@ int ha_myisammrg::open(const char *name, int mode __attribute__((unused)), /* retrieve children table list. */ my_errno= 0; - if (!(file= myrg_parent_open(name, myisammrg_parent_open_callback, this))) + if (is_cloned) + { + /* + Open and attaches the MyISAM tables,that are under the MERGE table + parent, on the MyISAM storage engine interface directly within the + MERGE engine. The new MyISAM table instances, as well as the MERGE + clone itself, are not visible in the table cache. This is not a + problem because all locking is handled by the original MERGE table + from which this is cloned of. + */ + if (!(file= myrg_open(table->s->normalized_path.str, table->db_stat, + HA_OPEN_IGNORE_IF_LOCKED))) + { + DBUG_PRINT("error", ("my_errno %d", my_errno)); + DBUG_RETURN(my_errno ? my_errno : -1); + } + + file->children_attached= TRUE; + + info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST); + } + else if (!(file= myrg_parent_open(name, myisammrg_parent_open_callback, this))) { DBUG_PRINT("error", ("my_errno %d", my_errno)); DBUG_RETURN(my_errno ? my_errno : -1); @@ -422,6 +443,55 @@ int ha_myisammrg::open(const char *name, int mode __attribute__((unused)), DBUG_RETURN(0); } +/** + Returns a cloned instance of the current handler. + + @return A cloned handler instance. + */ +handler *ha_myisammrg::clone(MEM_ROOT *mem_root) +{ + MYRG_TABLE *u_table,*newu_table; + ha_myisammrg *new_handler= + (ha_myisammrg*) get_new_handler(table->s, mem_root, table->s->db_type()); + if (!new_handler) + return NULL; + + /* Inform ha_myisammrg::open() that it is a cloned handler */ + new_handler->is_cloned= TRUE; + /* + Allocate handler->ref here because otherwise ha_open will allocate it + on this->table->mem_root and we will not be able to reclaim that memory + when the clone handler object is destroyed. + */ + if (!(new_handler->ref= (uchar*) alloc_root(mem_root, ALIGN_SIZE(ref_length)*2))) + { + delete new_handler; + return NULL; + } + + if (new_handler->ha_open(table, table->s->normalized_path.str, table->db_stat, + HA_OPEN_IGNORE_IF_LOCKED)) + { + delete new_handler; + return NULL; + } + + /* + Iterate through the original child tables and + copy the state into the cloned child tables. + We need to do this because all the child tables + can be involved in delete. + */ + newu_table= new_handler->file->open_tables; + for (u_table= file->open_tables; u_table < file->end_table; u_table++) + { + newu_table->table->state= u_table->table->state; + newu_table++; + } + + return new_handler; + } + /** @brief Attach children to a MERGE table. @@ -613,9 +683,10 @@ int ha_myisammrg::close(void) DBUG_ENTER("ha_myisammrg::close"); /* Children must not be attached here. Unless the MERGE table has no - children. In this case children_attached is always true. + children or the handler instance has been cloned. In these cases + children_attached is always true. */ - DBUG_ASSERT(!this->file->children_attached || !this->file->tables); + DBUG_ASSERT(!this->file->children_attached || !this->file->tables || this->is_cloned); rc= myrg_close(file); file= 0; DBUG_RETURN(rc); diff --git a/storage/myisammrg/ha_myisammrg.h b/storage/myisammrg/ha_myisammrg.h index 4e7ddebb83661d5cc6953048e44c210c1d0b7d65..21d41c9d75a51045cc28c08551726d081dd43d0d 100644 --- a/storage/myisammrg/ha_myisammrg.h +++ b/storage/myisammrg/ha_myisammrg.h @@ -25,6 +25,7 @@ class ha_myisammrg: public handler { MYRG_INFO *file; + my_bool is_cloned; /* This instance has been cloned */ public: TABLE_LIST *next_child_attach; /* next child to attach */ @@ -60,6 +61,7 @@ class ha_myisammrg: public handler int open(const char *name, int mode, uint test_if_locked); int attach_children(void); int detach_children(void); + virtual handler *clone(MEM_ROOT *mem_root); int close(void); int write_row(uchar * buf); int update_row(const uchar * old_data, uchar * new_data); diff --git a/storage/myisammrg/myrg_open.c b/storage/myisammrg/myrg_open.c index 64b4be2b7ca216a95693f34852e1a0d8928a85d0..14ba2853b225e1163c4e67e0970ed9a4c7290435 100644 --- a/storage/myisammrg/myrg_open.c +++ b/storage/myisammrg/myrg_open.c @@ -33,7 +33,6 @@ myrg_attach_children(). Please duplicate changes in these functions or make common sub-functions. */ -/* purecov: begin deadcode */ /* not used in MySQL server */ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking) { @@ -198,7 +197,6 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking) my_errno=save_errno; DBUG_RETURN (NULL); } -/* purecov: end */ /** @@ -428,10 +426,11 @@ int myrg_attach_children(MYRG_INFO *m_info, int handle_locking, if (!m_info->rec_per_key_part) { if(!(m_info->rec_per_key_part= (ulong*) - my_malloc(key_parts * sizeof(long), MYF(MY_WME|MY_ZEROFILL)))) + my_malloc(key_parts * sizeof(long), MYF(MY_WME)))) goto err; /* purecov: inspected */ errpos= 1; } + bzero((char*) m_info->rec_per_key_part, key_parts * sizeof(long)); } /* Add MyISAM table info. */ diff --git a/support-files/my-huge.cnf.sh b/support-files/my-huge.cnf.sh index 5be8f5e67a06071436e1920dcdb7f4d9ca4b0ce7..8763dc61bb455f519d17852f3e532ac789386010 100644 --- a/support-files/my-huge.cnf.sh +++ b/support-files/my-huge.cnf.sh @@ -124,7 +124,6 @@ server-id = 1 #innodb_data_home_dir = @localstatedir@/ #innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend #innodb_log_group_home_dir = @localstatedir@/ -#innodb_log_arch_dir = @localstatedir@/ # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high #innodb_buffer_pool_size = 384M diff --git a/support-files/my-large.cnf.sh b/support-files/my-large.cnf.sh index 0d5719e44382a97ec9d19c28d6a4f88db1cdde97..2a010acdfd816c771567d208fe1d70f00bd3e573 100644 --- a/support-files/my-large.cnf.sh +++ b/support-files/my-large.cnf.sh @@ -124,7 +124,6 @@ server-id = 1 #innodb_data_home_dir = @localstatedir@/ #innodb_data_file_path = ibdata1:10M:autoextend #innodb_log_group_home_dir = @localstatedir@/ -#innodb_log_arch_dir = @localstatedir@/ # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high #innodb_buffer_pool_size = 256M diff --git a/support-files/my-medium.cnf.sh b/support-files/my-medium.cnf.sh index 211b8ed5e8e217e426d5358ce08ec9cf2a55e75a..9dc2a29933237a5d48be75cb12b3d6c5ec315221 100644 --- a/support-files/my-medium.cnf.sh +++ b/support-files/my-medium.cnf.sh @@ -122,7 +122,6 @@ server-id = 1 #innodb_data_home_dir = @localstatedir@/ #innodb_data_file_path = ibdata1:10M:autoextend #innodb_log_group_home_dir = @localstatedir@/ -#innodb_log_arch_dir = @localstatedir@/ # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high #innodb_buffer_pool_size = 16M diff --git a/support-files/my-small.cnf.sh b/support-files/my-small.cnf.sh index 7bf8f323d576665b05e0158c86621c664b753b6c..c7a995ba95ac85e05c3118650eb1b668ba444703 100644 --- a/support-files/my-small.cnf.sh +++ b/support-files/my-small.cnf.sh @@ -55,7 +55,6 @@ server-id = 1 #innodb_data_home_dir = @localstatedir@/ #innodb_data_file_path = ibdata1:10M:autoextend #innodb_log_group_home_dir = @localstatedir@/ -#innodb_log_arch_dir = @localstatedir@/ # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high #innodb_buffer_pool_size = 16M