Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7dfc7e9

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 parentce7565a commit7dfc7e9

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((unsignedchar)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+
staticBOOL
1632+
insert_without_target(constchar*stmt,int*endpos)
1633+
{
1634+
constchar*wstmt=stmt;
1635+
1636+
while (isspace((unsignedchar)*(++wstmt)));
1637+
if (!*wstmt)
1638+
return FALSE;
1639+
if (strnicmp(wstmt,"VALUES",6))
1640+
return FALSE;
1641+
wstmt+=6;
1642+
if (!wstmt[0]|| !isspace((unsignedchar)wstmt[0]))
1643+
return FALSE;
1644+
while (isspace((unsignedchar)*(++wstmt)));
1645+
if (*wstmt!='('||*(++wstmt)!=')')
1646+
return FALSE;
1647+
wstmt++;
1648+
*endpos=wstmt-stmt;
1649+
return !wstmt[0]||isspace((unsignedchar)wstmt[0])
1650+
||';'==wstmt[0];
1651+
}
1652+
16251653
#ifdefMULTIBYTE
16261654
#definemy_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+
elseif (qp->token_len==3)
19671995
{
19681996
intendpos;
19691997

@@ -1985,6 +2013,20 @@ inner_process_tokens(QueryParse *qp, QueryBuild *qb)
19852013
}
19862014
}
19872015
}
2016+
elseif (qp->token_len==2)
2017+
{
2018+
intendpos;
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+
returnSQL_SUCCESS;
2028+
}
2029+
}
19882030
}
19892031
}
19902032
elseif (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+
returnFALSE;
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
inti;
440440

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

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp