Message-ID: From: "omeuid (@omeuid)" To: "postgresql-interfaces/psqlodbc" Date: Fri, 27 Sep 2024 16:53:20 +0000 Subject: [postgresql-interfaces/psqlodbc] issue #54: Escape sequence for the INSERT function fails. List-Id: X-GitHub-Author-Id: 6940566 X-GitHub-Author-Login: omeuid X-GitHub-Issue: 54 X-GitHub-Repo: postgresql-interfaces/psqlodbc X-GitHub-State: closed X-GitHub-Type: issue X-GitHub-Url: https://github.com/postgresql-interfaces/psqlodbc/issues/54 Content-Type: text/plain; charset=utf-8 The SQLGetInfo function for the `SQL_STRING_FUNCTIONS` param returns the following information: `SQL_FN_STR_CONCAT | SQL_FN_STR_INSERT | SQL_FN_STR_LEFT | SQL_FN_STR_LTRIM | SQL_FN_STR_LENGTH | SQL_FN_STR_LOCATE | SQL_FN_STR_LCASE | SQL_FN_STR_REPEAT | SQL_FN_STR_RIGHT | SQL_FN_STR_RTRIM | SQL_FN_STR_SUBSTRING | SQL_FN_STR_UCASE | SQL_FN_STR_ASCII | SQL_FN_STR_CHAR | SQL_FN_STR_LOCATE_2 | SQL_FN_STR_SPACE` Notice that INSERT function is returned (`SQL_FN_STR_INSERT `). But when you execute the following escape sequence an error is returned: * `SELECT {fn INSERT('aabcda', 2, 3 'zzz')}` The following errors are shown in the driver log: ``` [37872-19.426] execute.c[Exec_with_parameters_resolved]445: copying statement params: trans_status=1, len=40, stmt='SELECT {fn INSERT('aabcda', 2, 3 'zzz')}' [37872-19.426] convert.c[inner_process_tokens]3912: token_len=6 status=1 token=SELECT [37872-19.426] convert.c[inner_process_tokens]3912: token_len=1 status=0 token=( [37872-19.426] convert.c[inner_process_tokens]3912: token_len=1 status=0 token=, [37872-19.426] convert.c[inner_process_tokens]3912: token_len=1 status=1 token=2 [37872-19.426] convert.c[inner_process_tokens]3912: token_len=1 status=0 token=, [37872-19.426] convert.c[inner_process_tokens]3912: token_len=1 status=1 token=3 [37872-19.426] convert.c[convert_escape]5861: 4th param not found for the expression substring($1 from 1 for $2 - 1) || $4 || substring($1 from $2 + $3) [37872-19.426] convert.c[inner_process_tokens]3692: convert_escape error [37872-19.426]statement.[SC_log_error]2488: STATEMENT ERROR: func=copy_statement_with_parameters, desc='', errnum=1, errmsg='param not found' ``` It seems that the problem could be located in the `inner_process_tokens` or `prepareParametersNoDesc` methods from `convert.c` file. * Notice that the insert function should be delegated as `(substring($1 from 1 for $2 - 1) || $4 || substring($1 from $2 + $3))` (just like is indicated in convert.c), so the 4th param is included in the expression.