pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christian Ullrich <chris@chrullrich.net>
To: pgsql-odbc@postgresql.org
Subject: Re: Bug in execute.c
Date: Fri, 24 Apr 2015 09:48:08 +0200
Message-ID: <mhcsfo$k6k$1@ger.gmane.org> (raw)
In-Reply-To: <mhalik$s8k$1@ger.gmane.org>
References: <mhalik$s8k$1@ger.gmane.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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 */

view thread (3+ messages)  latest in thread

Message-ID: <mhcsfo$k6k$1@ger.gmane.org>
Permalink:  ../mhcsfo$k6k$1@ger.gmane.org/
Also on:    postgresql.org/message-id/mhcsfo$k6k$1@ger.gmane.org

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: chris@chrullrich.net
  Subject: Re: Bug in execute.c
  In-Reply-To: <mhcsfo$k6k$1@ger.gmane.org>
  References: <mhalik$s8k$1@ger.gmane.org> <mhcsfo$k6k$1@ger.gmane.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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