1) Improve the handling of the queries like (select ..) union (select ..)
authorHiroshi Inoue
Thu, 1 Aug 2002 03:07:50 +0000 (03:07 +0000)
committerHiroshi Inoue
Thu, 1 Aug 2002 03:07:50 +0000 (03:07 +0000)
   whose first non-space character is '('.
2) Handle Insert .. () VALUES ().

src/interfaces/odbc/convert.c
src/interfaces/odbc/parse.c
src/interfaces/odbc/statement.c

index 15a1a23c73700750a95bbd5686ce319649f7c185..2b586192320883ef5049e3d6d22f87fc748f2856 100644 (file)
@@ -1622,6 +1622,34 @@ table_for_update(const char *stmt, int *endpos)
    return !wstmt[0] || isspace((unsigned char) wstmt[0]);
 }
 
+/*----------
+ * Check if the statement is
+ * INSERT INTO ... () VALUES ()
+ * This isn't really a strict check but ...
+ *----------
+ */
+static BOOL
+insert_without_target(const char *stmt, int *endpos)
+{
+   const char *wstmt = stmt;
+
+   while (isspace((unsigned char) *(++wstmt)));
+   if (!*wstmt)
+       return FALSE;
+   if (strnicmp(wstmt, "VALUES", 6))
+       return FALSE;
+   wstmt += 6;
+   if (!wstmt[0] || !isspace((unsigned char) wstmt[0]))
+       return FALSE;
+   while (isspace((unsigned char) *(++wstmt)));
+   if (*wstmt != '(' || *(++wstmt) != ')')
+       return FALSE;
+   wstmt++;
+   *endpos = wstmt - stmt;
+   return !wstmt[0] || isspace((unsigned char) wstmt[0])
+       || ';' == wstmt[0];
+}
+
 #ifdef MULTIBYTE
 #define        my_strchr(conn, s1,c1) pg_mbschr(conn->ccsc, s1,c1)
 #else
@@ -1963,7 +1991,7 @@ inner_process_tokens(QueryParse *qp, QueryBuild *qb)
                            qb->npos -= qp->declare_pos;
                        }
                    }
-                   if (qp->token_len == 3)
+                   else if (qp->token_len == 3)
                    {
                        int         endpos;
 
@@ -1985,6 +2013,20 @@ inner_process_tokens(QueryParse *qp, QueryBuild *qb)
                            }
                        }
                    }
+                   else if (qp->token_len == 2)
+                   {
+                       int endpos;
+
+                       if (STMT_TYPE_INSERT == qp->statement_type &&
+                           strnicmp(qp->token_save, "()", 2) == 0 &&
+                           insert_without_target(&qp->statement[qp->opos], &endpos))
+                       {
+                           qb->npos -= 2;
+                           CVT_APPEND_STR(qb, "DEFAULT VALUES");
+                           qp->opos += endpos;
+                           return SQL_SUCCESS;
+                       }
+                   }
                }
            }
            else if (qp->prev_token_end)
index b2661d5379d5c8f0366e1a639eedd526de13689f..a61b75e90cf0d8eb5883a2d5a9fe10e52aa8da2d 100644 (file)
@@ -873,6 +873,11 @@ parse_statement(StatementClass *stmt)
 
    mylog("--------------------------------------------\n");
    mylog("nfld=%d, ntab=%d\n", irdflds->nfields, stmt->ntab);
+   if (0 == stmt->ntab)
+   {
+       stmt->parse_status = STMT_PARSE_FATAL;
+       return  FALSE;
+   }
 
    for (i = 0; i < (int) irdflds->nfields; i++)
    {
index 391eb73bcbcd6e4cf28b5d5532d7bc70e28c0d53..66dbb0a41d545eeffffc2cd562fa66dfa6e57fa6 100644 (file)
@@ -439,7 +439,7 @@ statement_type(char *statement)
    int         i;
 
    /* ignore leading whitespace in query string */
-   while (*statement && isspace((unsigned char) *statement))
+   while (*statement && (isspace((unsigned char) *statement) || *statement == '('))
        statement++;
 
    for (i = 0; Statement_Type[i].s; i++)