Hi 2016-11-17 12:00 GMT+01:00 Pavel Stehule <pavel.steh...@gmail.com>:
> > Hi > > a independent implementation of parametrized queries can looks like > attached patch: > > this code is simple without any unexpected behave. > > parameters are used when user doesn't require escaping and when > PARAMETRIZED_QUERIES variable is on > > Regards > here is a Daniel's syntax patch The independent implementation of using query parameters is good idea, the patch looks well, and there is a agreement with Tom. I implemented a Daniel proposal - it is few lines, but personally I prefer curly bracket syntax against `` syntax. When separator is double char, then the correct implementation will not be simple - the bad combinations "` ``, `` `" should be handled better. I wrote my arguments for my design, but if these arguments are not important for any other, then I can accept any other designs. regards Pavel > > Pavel > >
diff --git a/src/bin/psql/psqlscanslash.l b/src/bin/psql/psqlscanslash.l index 86832a8..15ad610 100644 --- a/src/bin/psql/psqlscanslash.l +++ b/src/bin/psql/psqlscanslash.l @@ -19,7 +19,7 @@ #include "postgres_fe.h" #include "psqlscanslash.h" - +#include "settings.h" #include "libpq-fe.h" } @@ -53,7 +53,7 @@ static int backtick_start_offset; #define LEXRES_OK 1 /* OK completion of backslash argument */ -static void evaluate_backtick(PsqlScanState state); +static void evaluate_backtick(PsqlScanState state, bool to_hex); #define ECHO psqlscan_emit(cur_state, yytext, yyleng) @@ -221,6 +221,13 @@ other . BEGIN(xslashbackquote); } +"``" { + backtick_start_offset = output_buf->len; + *option_quote = '@'; + unquoted_option_chars = 0; + BEGIN(xslashbackquote); + } + {dquote} { ECHO; *option_quote = '"'; @@ -354,10 +361,18 @@ other . "`" { /* In NO_EVAL mode, don't evaluate the command */ if (option_type != OT_NO_EVAL) - evaluate_backtick(cur_state); + evaluate_backtick(cur_state, false); BEGIN(xslasharg); } +"``" { + /* In NO_EVAL mode, don't evaluate the command */ + if (option_type != OT_NO_EVAL && *option_quote == '@') + evaluate_backtick(cur_state, true); + BEGIN(xslasharg); + } + + {other}|\n { ECHO; } } @@ -693,7 +708,7 @@ dequote_downcase_identifier(char *str, bool downcase, int encoding) * as a shell command and then replaced by the command's output. */ static void -evaluate_backtick(PsqlScanState state) +evaluate_backtick(PsqlScanState state, bool to_hex) { PQExpBuffer output_buf = state->output_buf; char *cmd = output_buf->data + backtick_start_offset; @@ -750,7 +765,20 @@ evaluate_backtick(PsqlScanState state) if (cmd_output.len > 0 && cmd_output.data[cmd_output.len - 1] == '\n') cmd_output.len--; - appendBinaryPQExpBuffer(output_buf, cmd_output.data, cmd_output.len); + + if (to_hex) + { + unsigned char *escaped_value; + size_t escaped_size; + + escaped_value = PQescapeByteaConn(pset.db, + (const unsigned char *) cmd_output.data, cmd_output.len, + &escaped_size); + + appendBinaryPQExpBuffer(output_buf, (const char *) escaped_value, escaped_size); + } + else + appendBinaryPQExpBuffer(output_buf, cmd_output.data, cmd_output.len); } termPQExpBuffer(&cmd_output);
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers