pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Bug in execute.c
3+ messages / 2 participants
[nested] [flat]

* Bug in execute.c
@ 2015-04-23 11:37 Christian Ullrich <chris@chrullrich.net>
  2015-04-24 07:48 ` Re: Bug in execute.c Christian Ullrich <chris@chrullrich.net>
  0 siblings, 1 reply; 3+ messages in thread

From: Christian Ullrich @ 2015-04-23 11:37 UTC (permalink / raw)
  To: pgsql-odbc

 From execute.c, SC_setInsertedTable(), line 790:

	if (ptr = strchr(cmd + 1, '.'), NULL != ptr)
		len = ptr - cmd;

This branch is supposed to extract an unquoted schema name from an 
INSERT statement. If that statement is

	INSERT INTO mytable VALUES (1, 1.5)

, the schema name will be "mytable VALUES (1, 1", and the table name, "5)".

I'm sorry I don't have a patch right now. I can come up with one, though.

-- 
Christian



-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Bug in execute.c
  2015-04-23 11:37 Bug in execute.c Christian Ullrich <chris@chrullrich.net>
@ 2015-04-24 07:48 ` Christian Ullrich <chris@chrullrich.net>
  2015-11-09 14:06   ` Re: Bug in execute.c Heikki Linnakangas <hlinnaka@iki.fi>
  0 siblings, 1 reply; 3+ messages in thread

From: Christian Ullrich @ 2015-04-24 07:48 UTC (permalink / raw)
  To: pgsql-odbc

* Christian Ullrich wrote:

>  From execute.c, SC_setInsertedTable(), line 790:
>
>      if (ptr = strchr(cmd + 1, '.'), NULL != ptr)
>          len = ptr - cmd;

> I'm sorry I don't have a patch right now. I can come up with one, though.

Patch attached. It may be a bit over the top. Please let me know what 
you think.

-- 
Christian

-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Attachments:

psqlodbc.patch (text/plain, 3.0K) download diff --git a/execute.c b/execute.c index 2eeffce..5342364 100644 --- a/execute.c +++ b/execute.c @@ -33,6 +33,8 @@ #include "lobj.h" #include "pgapifunc.h" +static const char* next_name_token(const char *s, size_t *len); + /*extern GLOBAL_VALUES globals;*/ @@ -738,10 +740,11 @@ SC_setInsertedTable(StatementClass *stmt, RETCODE retval) const char *cmd = stmt->statement, *ptr; ConnectionClass *conn; size_t len; + const char *token = NULL; if (STMT_TYPE_INSERT != stmt->statement_type) return; - if (SQL_NEED_DATA == retval) + if (!SQL_SUCCEEDED(retval)) return; conn = SC_get_conn(stmt); #ifdef NOT_USED /* give up the use of lastval() */ @@ -769,41 +772,70 @@ SC_setInsertedTable(StatementClass *stmt, RETCODE retval) return; NULL_THE_NAME(conn->schemaIns); NULL_THE_NAME(conn->tableIns); - if (!SQL_SUCCEEDED(retval)) - return; - while (TRUE) - { - if (IDENTIFIER_QUOTE == *cmd) - { - if (ptr = strchr(cmd + 1, IDENTIFIER_QUOTE), NULL == ptr) /* syntax error */ - { - NULL_THE_NAME(conn->schemaIns); - NULL_THE_NAME(conn->tableIns); - break; - } - len = ptr - cmd - 1; - cmd++; - ptr++; - } - else - { - if (ptr = strchr(cmd + 1, '.'), NULL != ptr) - len = ptr - cmd; + + len = 0; + token = next_name_token(cmd, &len); + if (token && *token == IDENTIFIER_QUOTE) + STRN_TO_NAME(conn->tableIns, token + 1, len - 2); + else + STRN_TO_NAME(conn->tableIns, token, len); + token = next_name_token(token, &len); + if (token && *token == '.') + { + token = next_name_token(token, &len); + if (token) { + if (NAME_IS_VALID(conn->tableIns)) + MOVE_NAME(conn->schemaIns, conn->tableIns); + if (*token == IDENTIFIER_QUOTE) + STRN_TO_NAME(conn->tableIns, token + 1, len - 2); else - { - ptr = cmd; - while (*ptr && !isspace((UCHAR) *ptr)) ptr++; - len = ptr - cmd; - } + STRN_TO_NAME(conn->tableIns, token, len); } - if (NAME_IS_VALID(conn->tableIns)) - MOVE_NAME(conn->schemaIns, conn->tableIns); - STRN_TO_NAME(conn->tableIns, cmd, len); - if ('.' == *ptr) - cmd = ptr + 1; - else + } + + if (!NAME_IS_VALID(conn->tableIns)) + NULL_THE_NAME(conn->schemaIns); +} + +/* Returns the next token from a qualified or unqualified name. + * + * s is the previous token. On entry, *len is the length of the + * previous token; on return, it is the length of the next one. If the + * token is quoted, the quotes are included in the result. If no valid + * token is found, NULL is returned. + */ +static const char* next_name_token(const char *s, size_t *len) +{ + const char *p; + + s += *len; + while (*s && isspace(*s)) ++s; + + switch (*s) { + case NULL: + break; + case '.': + *len = 1; + return s; + case IDENTIFIER_QUOTE: + p = strchr(s + 1, IDENTIFIER_QUOTE); + if (p) { + *len = p - s + 1; + return s; + } + break; + default: + p = s; + while (*p && !isspace(*p) && *p != '.') ++p; + if (p) { + *len = p - s; + return s; + } break; } + + *len = 0; + return NULL; } /* Execute a prepared SQL statement */
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: Bug in execute.c
  2015-04-23 11:37 Bug in execute.c Christian Ullrich <chris@chrullrich.net>
  2015-04-24 07:48 ` Re: Bug in execute.c Christian Ullrich <chris@chrullrich.net>
@ 2015-11-09 14:06   ` Heikki Linnakangas <hlinnaka@iki.fi>
  0 siblings, 0 replies; 3+ messages in thread

From: Heikki Linnakangas @ 2015-11-09 14:06 UTC (permalink / raw)
  To: Christian Ullrich <chris@chrullrich.net>; pgsql-odbc

On 04/24/2015 10:48 AM, Christian Ullrich wrote:
> * Christian Ullrich wrote:
>
>>   From execute.c, SC_setInsertedTable(), line 790:
>>
>>       if (ptr = strchr(cmd + 1, '.'), NULL != ptr)
>>           len = ptr - cmd;
>
>> I'm sorry I don't have a patch right now. I can come up with one, though.
>
> Patch attached. It may be a bit over the top. Please let me know what
> you think.

Thanks, applied! I also added a little regression test for this. I 
didn't try testing it exhaustively to see what kind of things would 
still trip it over (comments? newlines?), but this is certainly a step 
in the right direction. Well, it would be better to not have to do this 
parsing, but that's no reason to not improve what we have.

- Heikki



-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2015-11-09 14:06 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-04-23 11:37 Bug in execute.c Christian Ullrich <chris@chrullrich.net>
2015-04-24 07:48 ` Christian Ullrich <chris@chrullrich.net>
2015-11-09 14:06   ` Heikki Linnakangas <hlinnaka@iki.fi>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox