!590 1.解决打开--with-readline选项问题;2.移植命令补全功能
Merge pull request !590 from chenxiaobin/gsql
This commit is contained in:
@ -391,6 +391,7 @@ openGauss支持以下操作系统:
|
|||||||
| glibc-devel | 2.17-111 |
|
| glibc-devel | 2.17-111 |
|
||||||
| patch | 2.7.1-10 |
|
| patch | 2.7.1-10 |
|
||||||
| lsb_release | 4.1 |
|
| lsb_release | 4.1 |
|
||||||
|
| readline-devel| 7.0-13 |
|
||||||
|
|
||||||
### 下载openGauss
|
### 下载openGauss
|
||||||
|
|
||||||
@ -511,19 +512,19 @@ openGauss-server中的build.sh是编译过程中的重要脚本工具。该工
|
|||||||
**debug**版本:
|
**debug**版本:
|
||||||
|
|
||||||
```
|
```
|
||||||
./configure --gcc-version=7.3.0 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --without-readline --without-zlib
|
./configure --gcc-version=7.3.0 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --with-readline --without-zlib
|
||||||
```
|
```
|
||||||
|
|
||||||
**release**版本:
|
**release**版本:
|
||||||
|
|
||||||
```
|
```
|
||||||
./configure --gcc-version=7.3.0 CC=g++ CFLAGS="-O2 -g3" --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-thread-safety --without-readline --without-zlib
|
./configure --gcc-version=7.3.0 CC=g++ CFLAGS="-O2 -g3" --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-thread-safety --with-readline --without-zlib
|
||||||
```
|
```
|
||||||
|
|
||||||
**memcheck**版本:
|
**memcheck**版本:
|
||||||
|
|
||||||
```
|
```
|
||||||
./configure --gcc-version=7.3.0 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --without-readline --without-zlib --enable-memory-check
|
./configure --gcc-version=7.3.0 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --with-readline --without-zlib --enable-memory-check
|
||||||
```
|
```
|
||||||
|
|
||||||
> **注意**
|
> **注意**
|
||||||
|
@ -682,7 +682,7 @@ function install_gaussdb()
|
|||||||
echo "Begin configure." >> "$LOG_FILE" 2>&1
|
echo "Begin configure." >> "$LOG_FILE" 2>&1
|
||||||
chmod 755 configure
|
chmod 755 configure
|
||||||
|
|
||||||
shared_opt="--gcc-version=${gcc_version}.0 --prefix="${BUILD_DIR}" --3rd=${binarylibs_path} --enable-thread-safety --without-readline --without-zlib"
|
shared_opt="--gcc-version=${gcc_version}.0 --prefix="${BUILD_DIR}" --3rd=${binarylibs_path} --enable-thread-safety --with-readline --without-zlib"
|
||||||
if [ "$product_mode"x == "multiple"x ]; then
|
if [ "$product_mode"x == "multiple"x ]; then
|
||||||
if [ "$version_mode"x == "release"x ]; then
|
if [ "$version_mode"x == "release"x ]; then
|
||||||
./configure $shared_opt CFLAGS="-O2 -g3 ${GAUSSDB_EXTRA_FLAGS}" CC="${USE_CCACHE}g++" ${ENABLE_CCACHE} --enable-multiple-nodes $extra_config_opt >> "$LOG_FILE" 2>&1
|
./configure $shared_opt CFLAGS="-O2 -g3 ${GAUSSDB_EXTRA_FLAGS}" CC="${USE_CCACHE}g++" ${ENABLE_CCACHE} --enable-multiple-nodes $extra_config_opt >> "$LOG_FILE" 2>&1
|
||||||
|
@ -2833,44 +2833,6 @@ bar
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
|
||||||
<term><varname>HISTFILE</varname></term>
|
|
||||||
<listitem>
|
|
||||||
<para>
|
|
||||||
The file name that will be used to store the history list. The default
|
|
||||||
value is <filename>~/.psql_history</filename>. For example, putting:
|
|
||||||
<programlisting>
|
|
||||||
\set HISTFILE ~/.psql_history- :DBNAME
|
|
||||||
</programlisting>
|
|
||||||
in <filename>~/.psqlrc</filename> will cause
|
|
||||||
<application>gsql</application> to maintain a separate history for
|
|
||||||
each database.
|
|
||||||
</para>
|
|
||||||
<note>
|
|
||||||
<para>
|
|
||||||
This feature was shamelessly plagiarized from
|
|
||||||
<application>Bash</application>.
|
|
||||||
</para>
|
|
||||||
</note>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry>
|
|
||||||
<term><varname>HISTSIZE</varname></term>
|
|
||||||
<listitem>
|
|
||||||
<para>
|
|
||||||
The number of commands to store in the command history. The
|
|
||||||
default value is 500.
|
|
||||||
</para>
|
|
||||||
<note>
|
|
||||||
<para>
|
|
||||||
This feature was shamelessly plagiarized from
|
|
||||||
<application>Bash</application>.
|
|
||||||
</para>
|
|
||||||
</note>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><varname>HOST</varname></term>
|
<term><varname>HOST</varname></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
|
@ -59,7 +59,7 @@ ifneq "$(MAKECMDGOALS)" "clean"
|
|||||||
endif
|
endif
|
||||||
OBJS= command.o common.o help.o input.o stringutils.o mainloop.o copy.o \
|
OBJS= command.o common.o help.o input.o stringutils.o mainloop.o copy.o \
|
||||||
startup.o prompt.o variables.o large_obj.o print.o describe.o \
|
startup.o prompt.o variables.o large_obj.o print.o describe.o \
|
||||||
mbprint.o dumputils.o keywords.o kwlookup.o \
|
mbprint.o dumputils.o keywords.o kwlookup.o tab-complete.o\
|
||||||
sql_help.o \
|
sql_help.o \
|
||||||
$(top_builddir)/src/lib/elog/elog.a \
|
$(top_builddir)/src/lib/elog/elog.a \
|
||||||
$(WIN32RES)
|
$(WIN32RES)
|
||||||
|
@ -1051,10 +1051,6 @@ static backslashResult exec_command(const char* cmd, PsqlScanState scan_state, P
|
|||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useReadline && pset.cur_cmd_interactive) {
|
|
||||||
setHistSize(opt0, newval, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(newval);
|
free(newval);
|
||||||
newval = NULL;
|
newval = NULL;
|
||||||
if (temp_opt != NULL)
|
if (temp_opt != NULL)
|
||||||
@ -1259,10 +1255,6 @@ static backslashResult exec_command(const char* cmd, PsqlScanState scan_state, P
|
|||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useReadline && pset.cur_cmd_interactive) {
|
|
||||||
setHistSize(opt, NULL, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NULL != opt) {
|
if (NULL != opt) {
|
||||||
free(opt);
|
free(opt);
|
||||||
opt = NULL;
|
opt = NULL;
|
||||||
|
@ -128,6 +128,29 @@ void* pg_calloc(size_t nmemb, size_t size)
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* psql_realloc(void* ptr, size_t oldSize, size_t newSize)
|
||||||
|
{
|
||||||
|
void* tmp = NULL;
|
||||||
|
errno_t rc;
|
||||||
|
|
||||||
|
if (oldSize > newSize) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* When malloc failed gsql will exit, with no memory leak for ptr. */
|
||||||
|
tmp = pg_malloc(newSize);
|
||||||
|
if (tmp == NULL) {
|
||||||
|
psql_error("out of memory\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
rc = memcpy_s(tmp, newSize, ptr, oldSize);
|
||||||
|
securec_check_c(rc, "\0", "\0");
|
||||||
|
|
||||||
|
free(ptr);
|
||||||
|
ptr = NULL;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* setQFout
|
* setQFout
|
||||||
* -- handler for -o command line option and \o command
|
* -- handler for -o command line option and \o command
|
||||||
|
@ -59,6 +59,7 @@ extern char* pg_strdup(const char* string);
|
|||||||
extern void* pg_malloc(size_t size);
|
extern void* pg_malloc(size_t size);
|
||||||
extern void* pg_malloc_zero(size_t size);
|
extern void* pg_malloc_zero(size_t size);
|
||||||
extern void* pg_calloc(size_t nmemb, size_t size);
|
extern void* pg_calloc(size_t nmemb, size_t size);
|
||||||
|
extern void* psql_realloc(void* ptr, size_t oldSize, size_t newSize);
|
||||||
|
|
||||||
extern bool setQFout(const char* fname);
|
extern bool setQFout(const char* fname);
|
||||||
|
|
||||||
|
@ -31,8 +31,6 @@ bool useReadline = false;
|
|||||||
#define NL_IN_HISTORY 0x01
|
#define NL_IN_HISTORY 0x01
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setHistSize(const char* targetName, char* targetValue, bool setToDefault);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* gets_interactive()
|
* gets_interactive()
|
||||||
*
|
*
|
||||||
@ -250,41 +248,27 @@ bool SensitiveStrCheck(const char* target)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setHistSize(const char* targetName, const char* targetValue, bool setToDefault)
|
/*
|
||||||
|
* Put any startup stuff related to input in here. It's good to maintain
|
||||||
|
* abstraction this way.
|
||||||
|
*
|
||||||
|
* The only "flag" right now is 1 for use readline & history.
|
||||||
|
*/
|
||||||
|
void initializeInput(int flags)
|
||||||
{
|
{
|
||||||
#ifndef ENABLE_LLT
|
#ifdef USE_READLINE
|
||||||
char* end = NULL;
|
|
||||||
long int result;
|
#ifndef ENABLE_MULTIPLE_NODES
|
||||||
#define MAXHISTSIZE 500
|
flags &= useReadline;
|
||||||
#define DEFHISTSIZE 32
|
#endif
|
||||||
if (targetName == NULL) {
|
|
||||||
return;
|
if (flags & 1) {
|
||||||
}
|
useReadline = true;
|
||||||
if (strcmp(targetName, "HISTSIZE") == 0) {
|
|
||||||
if (!setToDefault) {
|
/* these two things must be done in this order: */
|
||||||
if (targetValue == NULL || strlen(targetValue) == 0) {
|
initialize_readline();
|
||||||
fprintf(stderr, "warning:\"HISTSIZE\" is not changed,because its value can not be null\n");
|
rl_variable_bind ("enable-meta-key", "off");
|
||||||
return;
|
rl_initialize();
|
||||||
} else {
|
|
||||||
errno = 0;
|
|
||||||
result = strtol(targetValue, &end, 0);
|
|
||||||
if ((errno == ERANGE && (result == LONG_MAX || result == LONG_MIN)) || (errno != 0 && result == 0)) {
|
|
||||||
fprintf(stderr, "warning:\"HISTSIZE\" is not changed,because its value overflows\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (*end || result < 0) {
|
|
||||||
fprintf(stderr, "warning:\"HISTSIZE\" is not changed,because its value must be positive integer\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result > MAXHISTSIZE) {
|
|
||||||
fprintf(stderr, "warning:\"HISTSIZE\" is set to 500,because its value can not be greater than 500\n");
|
|
||||||
result = MAXHISTSIZE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result = DEFHISTSIZE;
|
|
||||||
}
|
|
||||||
stifle_history((int)result);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#ifndef INPUT_H
|
#ifndef INPUT_H
|
||||||
#define INPUT_H
|
#define INPUT_H
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBREADLINE
|
||||||
/*
|
/*
|
||||||
* If some other file needs to have access to readline/history, include this
|
* If some other file needs to have access to readline/history, include this
|
||||||
* file and save yourself all this work.
|
* file and save yourself all this work.
|
||||||
@ -16,19 +17,28 @@
|
|||||||
*/
|
*/
|
||||||
#define USE_READLINE 1
|
#define USE_READLINE 1
|
||||||
|
|
||||||
|
#if defined(HAVE_READLINE_READLINE_H)
|
||||||
|
#include <readline/readline.h>
|
||||||
|
#include <readline/history.h>
|
||||||
|
#elif defined(HAVE_EDITLINE_READLINE_H)
|
||||||
#include <editline/readline.h>
|
#include <editline/readline.h>
|
||||||
|
#elif defined(HAVE_READLINE_H)
|
||||||
|
#include <readline.h>
|
||||||
|
#endif /* HAVE_READLINE_READLINE_H, etc */
|
||||||
|
#else
|
||||||
|
#include <editline/readline.h>
|
||||||
|
#endif /* HAVE_LIBREADLINE */
|
||||||
|
|
||||||
#include "libpq/pqexpbuffer.h"
|
#include "libpq/pqexpbuffer.h"
|
||||||
|
|
||||||
char* gets_interactive(const char* prompt);
|
char* gets_interactive(const char* prompt);
|
||||||
char* gets_fromFile(FILE* source);
|
char* gets_fromFile(FILE* source);
|
||||||
|
|
||||||
bool saveHistory(const char* fname, int max_lines, bool appendFlag, bool encodeFlag);
|
|
||||||
|
|
||||||
void pg_append_history(const char* s, PQExpBuffer history_buf);
|
void pg_append_history(const char* s, PQExpBuffer history_buf);
|
||||||
void pg_send_history(PQExpBuffer history_buf);
|
void pg_send_history(PQExpBuffer history_buf);
|
||||||
void setHistSize(const char* targetName, const char* targetValue, bool setToDefault);
|
|
||||||
extern bool useReadline;
|
extern bool useReadline;
|
||||||
extern bool SensitiveStrCheck(const char* target);
|
extern bool SensitiveStrCheck(const char* target);
|
||||||
|
|
||||||
|
void initializeInput(int flags);
|
||||||
|
|
||||||
#endif /* INPUT_H */
|
#endif /* INPUT_H */
|
||||||
|
@ -148,11 +148,6 @@ int MainLoop(FILE* source, char* querystring)
|
|||||||
}
|
}
|
||||||
pset.lineno = 0;
|
pset.lineno = 0;
|
||||||
|
|
||||||
if (pset.cur_cmd_interactive) {
|
|
||||||
const char* val = GetVariable(pset.vars, "HISTSIZE");
|
|
||||||
setHistSize("HISTSIZE", val, val == NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create working state */
|
/* Create working state */
|
||||||
scan_state = psql_scan_create();
|
scan_state = psql_scan_create();
|
||||||
|
|
||||||
|
@ -506,7 +506,7 @@ int main(int argc, char* argv[])
|
|||||||
printf(_("Type \"help\" for help.\n\n"));
|
printf(_("Type \"help\" for help.\n\n"));
|
||||||
|
|
||||||
canAddHist = true;
|
canAddHist = true;
|
||||||
|
initializeInput(options.no_readline ? 0 : 1);
|
||||||
successResult = MainLoop(stdin);
|
successResult = MainLoop(stdin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -614,7 +614,9 @@ static void parse_psql_options(int argc, char* const argv[], struct adhoc_opts*
|
|||||||
/* Database Security: Data importing/dumping support AES128. */
|
/* Database Security: Data importing/dumping support AES128. */
|
||||||
char* dencrypt_key = NULL;
|
char* dencrypt_key = NULL;
|
||||||
errno_t rc = EOK;
|
errno_t rc = EOK;
|
||||||
|
#ifdef USE_READLINE
|
||||||
useReadline = false;
|
useReadline = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
rc = memset_s(options, sizeof(*options), 0, sizeof(*options));
|
rc = memset_s(options, sizeof(*options), 0, sizeof(*options));
|
||||||
check_memset_s(rc);
|
check_memset_s(rc);
|
||||||
@ -732,7 +734,9 @@ static void parse_psql_options(int argc, char* const argv[], struct adhoc_opts*
|
|||||||
pset.enable_client_encryption = true;
|
pset.enable_client_encryption = true;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
|
#ifdef USE_READLINE
|
||||||
useReadline = true;
|
useReadline = true;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
if (pset.popt.topt.recordSep.separator != NULL)
|
if (pset.popt.topt.recordSep.separator != NULL)
|
||||||
@ -778,7 +782,6 @@ static void parse_psql_options(int argc, char* const argv[], struct adhoc_opts*
|
|||||||
fprintf(stderr, _("%s: could not set variable \"%s\"\n"), pset.progname, value);
|
fprintf(stderr, _("%s: could not set variable \"%s\"\n"), pset.progname, value);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
setHistSize(value, equal_loc + 1, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(value);
|
free(value);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,17 +1,9 @@
|
|||||||
--include chinese
|
--include chinese
|
||||||
create table 华为(f int);
|
create table 数据库(f int);
|
||||||
insert into 华为 values (1);
|
insert into 数据库 values (1);
|
||||||
select * from 华为;
|
select * from 数据库;
|
||||||
f
|
f
|
||||||
---
|
---
|
||||||
1
|
1
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
\set HISTSIZE -1
|
|
||||||
\set HISTSIZE 30.5
|
|
||||||
\set HISTSIZE 0
|
|
||||||
\set HISTSIZE 6
|
|
||||||
\set HISTSIZE 500
|
|
||||||
\set HISTSIZE 600
|
|
||||||
\set HISTSIZE 66666666666666666666666600
|
|
||||||
\set HISTSIZE -666666666666666666666666666
|
|
||||||
|
@ -1,12 +1,4 @@
|
|||||||
--include chinese
|
--include chinese
|
||||||
create table 华为(f int);
|
create table 数据库(f int);
|
||||||
insert into 华为 values (1);
|
insert into 数据库 values (1);
|
||||||
select * from 华为;
|
select * from 数据库;
|
||||||
\set HISTSIZE -1
|
|
||||||
\set HISTSIZE 30.5
|
|
||||||
\set HISTSIZE 0
|
|
||||||
\set HISTSIZE 6
|
|
||||||
\set HISTSIZE 500
|
|
||||||
\set HISTSIZE 600
|
|
||||||
\set HISTSIZE 66666666666666666666666600
|
|
||||||
\set HISTSIZE -666666666666666666666666666
|
|
||||||
|
Reference in New Issue
Block a user