Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7dfc7e9

Browse files
author
Hiroshi Inoue
committed
1) Improve the handling of the queries like (select ..) union (select ..)
whose first non-space character is '('. 2) Handle Insert .. () VALUES ().
1 parent ce7565a commit 7dfc7e9

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/interfaces/odbc/convert.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,34 @@ table_for_update(const char *stmt, int *endpos)
16221622
return !wstmt[0] || isspace((unsigned char) wstmt[0]);
16231623
}
16241624

1625+
/*----------
1626+
* Check if the statement is
1627+
* INSERT INTO ... () VALUES ()
1628+
* This isn't really a strict check but ...
1629+
*----------
1630+
*/
1631+
static BOOL
1632+
insert_without_target(const char *stmt, int *endpos)
1633+
{
1634+
const char *wstmt = stmt;
1635+
1636+
while (isspace((unsigned char) *(++wstmt)));
1637+
if (!*wstmt)
1638+
return FALSE;
1639+
if (strnicmp(wstmt, "VALUES", 6))
1640+
return FALSE;
1641+
wstmt += 6;
1642+
if (!wstmt[0] || !isspace((unsigned char) wstmt[0]))
1643+
return FALSE;
1644+
while (isspace((unsigned char) *(++wstmt)));
1645+
if (*wstmt != '(' || *(++wstmt) != ')')
1646+
return FALSE;
1647+
wstmt++;
1648+
*endpos = wstmt - stmt;
1649+
return !wstmt[0] || isspace((unsigned char) wstmt[0])
1650+
|| ';' == wstmt[0];
1651+
}
1652+
16251653
#ifdef MULTIBYTE
16261654
#define my_strchr(conn, s1,c1) pg_mbschr(conn->ccsc, s1,c1)
16271655
#else
@@ -1963,7 +1991,7 @@ inner_process_tokens(QueryParse *qp, QueryBuild *qb)
19631991
qb->npos -= qp->declare_pos;
19641992
}
19651993
}
1966-
if (qp->token_len == 3)
1994+
else if (qp->token_len == 3)
19671995
{
19681996
int endpos;
19691997

@@ -1985,6 +2013,20 @@ inner_process_tokens(QueryParse *qp, QueryBuild *qb)
19852013
}
19862014
}
19872015
}
2016+
else if (qp->token_len == 2)
2017+
{
2018+
int endpos;
2019+
2020+
if (STMT_TYPE_INSERT == qp->statement_type &&
2021+
strnicmp(qp->token_save, "()", 2) == 0 &&
2022+
insert_without_target(&qp->statement[qp->opos], &endpos))
2023+
{
2024+
qb->npos -= 2;
2025+
CVT_APPEND_STR(qb, "DEFAULT VALUES");
2026+
qp->opos += endpos;
2027+
return SQL_SUCCESS;
2028+
}
2029+
}
19882030
}
19892031
}
19902032
else if (qp->prev_token_end)

src/interfaces/odbc/parse.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,11 @@ parse_statement(StatementClass *stmt)
873873

874874
mylog("--------------------------------------------\n");
875875
mylog("nfld=%d, ntab=%d\n", irdflds->nfields, stmt->ntab);
876+
if (0 == stmt->ntab)
877+
{
878+
stmt->parse_status = STMT_PARSE_FATAL;
879+
return FALSE;
880+
}
876881

877882
for (i = 0; i < (int) irdflds->nfields; i++)
878883
{

src/interfaces/odbc/statement.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ statement_type(char *statement)
439439
int i;
440440

441441
/* ignore leading whitespace in query string */
442-
while (*statement && isspace((unsigned char) *statement))
442+
while (*statement && (isspace((unsigned char) *statement) || *statement == '('))
443443
statement++;
444444

445445
for (i = 0; Statement_Type[i].s; i++)

0 commit comments

Comments
 (0)