forked from huawei/openGauss-server
1.解决打开--with-readline选项问题;2.移植命令补全功能
This commit is contained in:
parent
d4ec71fdab
commit
f72445a6cf
|
@ -388,6 +388,7 @@ openGauss支持以下操作系统:
|
|||
| glibc-devel | 2.17-111 |
|
||||
| patch | 2.7.1-10 |
|
||||
| lsb_release | 4.1 |
|
||||
| readline-devel| 7.0-13 |
|
||||
|
||||
### 下载openGauss
|
||||
|
||||
|
@ -508,19 +509,19 @@ openGauss-server中的build.sh是编译过程中的重要脚本工具。该工
|
|||
**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**版本:
|
||||
|
||||
```
|
||||
./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**版本:
|
||||
|
||||
```
|
||||
./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
|
||||
```
|
||||
|
||||
> **注意**
|
||||
|
|
|
@ -686,7 +686,7 @@ function install_gaussdb()
|
|||
echo "Begin configure." >> "$LOG_FILE" 2>&1
|
||||
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 [ "$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
|
||||
|
|
|
@ -2833,44 +2833,6 @@ bar
|
|||
</listitem>
|
||||
</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>
|
||||
<term><varname>HOST</varname></term>
|
||||
<listitem>
|
||||
|
|
|
@ -59,7 +59,7 @@ ifneq "$(MAKECMDGOALS)" "clean"
|
|||
endif
|
||||
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 \
|
||||
mbprint.o dumputils.o keywords.o kwlookup.o \
|
||||
mbprint.o dumputils.o keywords.o kwlookup.o tab-complete.o\
|
||||
sql_help.o \
|
||||
$(top_builddir)/src/lib/elog/elog.a \
|
||||
$(WIN32RES)
|
||||
|
|
|
@ -1051,10 +1051,6 @@ static backslashResult exec_command(const char* cmd, PsqlScanState scan_state, P
|
|||
success = false;
|
||||
}
|
||||
|
||||
if (useReadline && pset.cur_cmd_interactive) {
|
||||
setHistSize(opt0, newval, false);
|
||||
}
|
||||
|
||||
free(newval);
|
||||
newval = NULL;
|
||||
if (temp_opt != NULL)
|
||||
|
@ -1259,10 +1255,6 @@ static backslashResult exec_command(const char* cmd, PsqlScanState scan_state, P
|
|||
success = false;
|
||||
}
|
||||
|
||||
if (useReadline && pset.cur_cmd_interactive) {
|
||||
setHistSize(opt, NULL, true);
|
||||
}
|
||||
|
||||
if (NULL != opt) {
|
||||
free(opt);
|
||||
opt = NULL;
|
||||
|
|
|
@ -128,6 +128,29 @@ void* pg_calloc(size_t nmemb, size_t size)
|
|||
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
|
||||
* -- 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_zero(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);
|
||||
|
||||
|
|
|
@ -31,8 +31,6 @@ bool useReadline = false;
|
|||
#define NL_IN_HISTORY 0x01
|
||||
#endif
|
||||
|
||||
void setHistSize(const char* targetName, char* targetValue, bool setToDefault);
|
||||
|
||||
/*
|
||||
* 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
|
||||
char* end = NULL;
|
||||
long int result;
|
||||
#define MAXHISTSIZE 500
|
||||
#define DEFHISTSIZE 32
|
||||
if (targetName == NULL) {
|
||||
return;
|
||||
}
|
||||
if (strcmp(targetName, "HISTSIZE") == 0) {
|
||||
if (!setToDefault) {
|
||||
if (targetValue == NULL || strlen(targetValue) == 0) {
|
||||
fprintf(stderr, "warning:\"HISTSIZE\" is not changed,because its value can not be null\n");
|
||||
return;
|
||||
} 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);
|
||||
#ifdef USE_READLINE
|
||||
|
||||
#ifndef ENABLE_MULTIPLE_NODES
|
||||
flags &= useReadline;
|
||||
#endif
|
||||
|
||||
if (flags & 1) {
|
||||
useReadline = true;
|
||||
|
||||
/* these two things must be done in this order: */
|
||||
initialize_readline();
|
||||
rl_variable_bind ("enable-meta-key", "off");
|
||||
rl_initialize();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
#ifdef HAVE_LIBREADLINE
|
||||
/*
|
||||
* If some other file needs to have access to readline/history, include this
|
||||
* file and save yourself all this work.
|
||||
|
@ -16,19 +17,28 @@
|
|||
*/
|
||||
#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>
|
||||
#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"
|
||||
|
||||
char* gets_interactive(const char* prompt);
|
||||
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_send_history(PQExpBuffer history_buf);
|
||||
void setHistSize(const char* targetName, const char* targetValue, bool setToDefault);
|
||||
extern bool useReadline;
|
||||
extern bool SensitiveStrCheck(const char* target);
|
||||
|
||||
void initializeInput(int flags);
|
||||
|
||||
#endif /* INPUT_H */
|
||||
|
|
|
@ -148,11 +148,6 @@ int MainLoop(FILE* source, char* querystring)
|
|||
}
|
||||
pset.lineno = 0;
|
||||
|
||||
if (pset.cur_cmd_interactive) {
|
||||
const char* val = GetVariable(pset.vars, "HISTSIZE");
|
||||
setHistSize("HISTSIZE", val, val == NULL);
|
||||
}
|
||||
|
||||
/* Create working state */
|
||||
scan_state = psql_scan_create();
|
||||
|
||||
|
|
|
@ -505,7 +505,7 @@ int main(int argc, char* argv[])
|
|||
printf(_("Type \"help\" for help.\n\n"));
|
||||
|
||||
canAddHist = true;
|
||||
|
||||
initializeInput(options.no_readline ? 0 : 1);
|
||||
successResult = MainLoop(stdin);
|
||||
}
|
||||
|
||||
|
@ -613,7 +613,9 @@ static void parse_psql_options(int argc, char* const argv[], struct adhoc_opts*
|
|||
/* Database Security: Data importing/dumping support AES128. */
|
||||
char* dencrypt_key = NULL;
|
||||
errno_t rc = EOK;
|
||||
#ifdef USE_READLINE
|
||||
useReadline = false;
|
||||
#endif
|
||||
|
||||
rc = memset_s(options, sizeof(*options), 0, sizeof(*options));
|
||||
check_memset_s(rc);
|
||||
|
@ -731,7 +733,9 @@ static void parse_psql_options(int argc, char* const argv[], struct adhoc_opts*
|
|||
pset.enable_client_encryption = true;
|
||||
break;
|
||||
case 'r':
|
||||
#ifdef USE_READLINE
|
||||
useReadline = true;
|
||||
#endif
|
||||
break;
|
||||
case 'R':
|
||||
if (pset.popt.topt.recordSep.separator != NULL)
|
||||
|
@ -777,7 +781,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);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
setHistSize(value, equal_loc + 1, false);
|
||||
}
|
||||
|
||||
free(value);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,17 +1,9 @@
|
|||
--include chinese
|
||||
create table 华为(f int);
|
||||
insert into 华为 values (1);
|
||||
select * from 华为;
|
||||
create table 数据库(f int);
|
||||
insert into 数据库 values (1);
|
||||
select * from 数据库;
|
||||
f
|
||||
---
|
||||
1
|
||||
(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
|
||||
create table 华为(f int);
|
||||
insert into 华为 values (1);
|
||||
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
|
||||
create table 数据库(f int);
|
||||
insert into 数据库 values (1);
|
||||
select * from 数据库;
|
||||
|
|
Loading…
Reference in New Issue