forked from huawei/openGauss-server
!822 自动补齐功能添加HISTSIZE参数控制缓存命令条数以及补充自动补齐语法
Merge pull request !822 from chenxiaobin/gsql
This commit is contained in:
commit
87e796ba96
|
@ -2833,6 +2833,22 @@ bar
|
|||
</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>
|
||||
|
|
|
@ -1051,6 +1051,12 @@ static backslashResult exec_command(const char* cmd, PsqlScanState scan_state, P
|
|||
success = false;
|
||||
}
|
||||
|
||||
#ifdef USE_READLINE
|
||||
if (useReadline && pset.cur_cmd_interactive) {
|
||||
setHistSize(opt0, newval, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
free(newval);
|
||||
newval = NULL;
|
||||
if (temp_opt != NULL)
|
||||
|
@ -1255,6 +1261,12 @@ static backslashResult exec_command(const char* cmd, PsqlScanState scan_state, P
|
|||
success = false;
|
||||
}
|
||||
|
||||
#ifdef USE_READLINE
|
||||
if (useReadline && pset.cur_cmd_interactive) {
|
||||
setHistSize(opt, NULL, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (NULL != opt) {
|
||||
free(opt);
|
||||
opt = NULL;
|
||||
|
|
|
@ -248,6 +248,45 @@ bool SensitiveStrCheck(const char* target)
|
|||
}
|
||||
}
|
||||
|
||||
void setHistSize(const char* targetName, const char* targetValue, bool setToDefault)
|
||||
{
|
||||
#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);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Put any startup stuff related to input in here. It's good to maintain
|
||||
* abstraction this way.
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#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.
|
||||
|
@ -17,6 +16,8 @@
|
|||
*/
|
||||
#define USE_READLINE 1
|
||||
|
||||
#ifdef HAVE_LIBREADLINE
|
||||
|
||||
#if defined(HAVE_READLINE_READLINE_H)
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
|
@ -36,6 +37,7 @@ char* gets_fromFile(FILE* source);
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
@ -148,6 +148,11 @@ 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();
|
||||
|
||||
|
|
|
@ -782,6 +782,7 @@ 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
|
@ -7,3 +7,11 @@ select * from 数据库;
|
|||
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
|
||||
|
|
|
@ -2,3 +2,11 @@
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue