-
- case SQL_SCAN: /* Default state == 0, set in _allocAH */
- if (qry[pos] == ';' && AH->sqlparse.braceDepth == 0)
- {
- /* We've got the end of a statement.
- * Send It & reset the buffer.
- */
-
- /*
- * fprintf(stderr, " sending: '%s'\n\n",
- * AH->sqlBuf->data);
- */
- ExecuteSqlCommand(AH, AH->sqlBuf, "could not execute query", false);
- resetPQExpBuffer(AH->sqlBuf);
- AH->sqlparse.lastChar = '\0';
-
- /*
- * Remove any following newlines - so that embedded
- * COPY commands don't get a starting newline.
- */
- pos++;
- for (; pos < (eos - qry) && qry[pos] == '\n'; pos++);
-
- /* We've got our line, so exit */
- return qry + pos;
- }
- else
- {
- /*
- * Look for normal boring quote chars, or dollar-quotes. We make
- * the assumption that $-quotes will not have an ident character
- * before them in all pg_dump output.
- */
- if ( qry[pos] == '"'
- || qry[pos] == '\''
- || ( qry[pos] == '$' && _isIdentChar(AH->sqlparse.lastChar) == 0 )
- )
- {
- /* fprintf(stderr,"[startquote]\n"); */
- AH->sqlparse.state = SQL_IN_QUOTE;
- AH->sqlparse.quoteChar = qry[pos];
- AH->sqlparse.backSlash = 0;
- if (qry[pos] == '$')
- {
- /* override the state */
- AH->sqlparse.state = SQL_IN_DOLLARTAG;
- /* Used for checking first char of tag */
- startDT = 1;
- /* We store the tag for later comparison. */
- AH->sqlparse.tagBuf = createPQExpBuffer();
- /* Get leading $ */
- appendPQExpBufferChar(AH->sqlparse.tagBuf, qry[pos]);
- }
- }
- else if (qry[pos] == '-' && AH->sqlparse.lastChar == '-')
- AH->sqlparse.state = SQL_IN_SQL_COMMENT;
- else if (qry[pos] == '*' && AH->sqlparse.lastChar == '/')
- AH->sqlparse.state = SQL_IN_EXT_COMMENT;
- else if (qry[pos] == '(')
- AH->sqlparse.braceDepth++;
- else if (qry[pos] == ')')
- AH->sqlparse.braceDepth--;
-
- AH->sqlparse.lastChar = qry[pos];
- }
- break;
-
- case SQL_IN_DOLLARTAG:
-
- /* Like a quote, we look for a closing char *but* we only
- * allow a very limited set of contained chars, and no escape chars.
- * If invalid chars are found, we abort tag processing.
- */
-
- if (qry[pos] == '$')
- {
- /* fprintf(stderr,"[endquote]\n"); */
- /* Get trailing $ */
- appendPQExpBufferChar(AH->sqlparse.tagBuf, qry[pos]);
- AH->sqlparse.state = SQL_IN_DOLLARQUOTE;
- }
- else
- {
- if ( _isDQChar(qry[pos], startDT) )
- {
- /* Valid, so add */
- appendPQExpBufferChar(AH->sqlparse.tagBuf, qry[pos]);
- }
- else
- {
- /* Jump back to 'scan' state, we're not really in a tag,
- * and valid tag chars do not include the various chars
- * we look for in this state machine, so it's safe to just
- * jump from this state back to SCAN. We set consumed = 0
- * so that this char gets rescanned in new state.
- */
- destroyPQExpBuffer(AH->sqlparse.tagBuf);
- AH->sqlparse.state = SQL_SCAN;
- consumed = 0;
- }
- }
- startDT = 0;
- break;
-
-
- case SQL_IN_DOLLARQUOTE: