/**
         * Parse a token from a string containing a SQL statement.
         * If the prevToken @is null, then the first token in parsed.
         * If a SQL token can't be found in the string, then null
         * @is returned. If a SQL token @is found, data @is captured in
         * the returned SqlParseToken result.
         */
        protected SqlParseToken parseSqlToken(String sql, SqlParseToken prevToken)
        {
            if (sql == null)
            {
                _sqlParseToken.init();
                return(null);
            }

            int len = sql.length();
            int i, start;

            // Start at index 0, or where we left off last time

            if (prevToken == null)
            {
                i = 0;
            }
            else
            {
                i = prevToken.getEnd();
            }

            while (i < len && Character.isWhitespace(sql[i]))
            {
                i++;
            }

            // Must be at least 1 non-whitespace character

            if ((i + 1) >= len)
            {
                _sqlParseToken.init();
                return(null);
            }

            start = i;

            while (i < len && !Character.isWhitespace(sql[i]))
            {
                i++;
            }

            _sqlParseToken.assign(sql, start, i);

            return(_sqlParseToken);
        }
        private bool checkSql(Env env, ConnectionEntry connEntry, string sql)
        {
            SqlParseToken tok = parseSqlToken(sql, null);

            if (tok == null)
            {
                return(false);
            }

            switch (tok.getFirstChar())
            {
            case 'a':
            case 'A': {
                // drop/alter clears metadata cache
                _tableMetadataMap.clear();
                break;
            }

            case 'd':
            case 'D': {
                if (tok.matchesToken("DROP"))
                {
                    // drop/alter clears metadata cache
                    _tableMetadataMap.clear();

                    // If DROP @is dropping the current database, then clear
                    // the cached database name in the driver.
                    //
                    // php/144a

                    tok = parseSqlToken(sql, tok);

                    if ((tok != null) && tok.matchesToken("DATABASE"))
                    {
                        tok = parseSqlToken(sql, tok);

                        if (tok != null)
                        {
                            string dbname = tok.toUnquotedString();

                            if (dbname.equals(_catalog))
                            {
                                try {
                                    setCatalog(env, null);
                                } catch (SQLException e) {
                                    log.log(Level.FINEST, e.ToString(), e);
                                }
                            }
                        }
                    }
                }
                break;
            }

            case 'c':
            case 'C': {
                if (tok.matchesToken("CREATE"))
                {
                    // don't pool connections that create tables, because of mysql
                    // temporary tables
                    connEntry.markForPoolRemoval();
                }

                /*
                 * else if (tok.matchesToken("COMMIT")) {
                 * commit();
                 * setAutoCommit(true);
                 * return true;
                 * }
                 */
                break;
            }

                // reason for comment out?  no real perf gain?

                /*
                 * case 'b': case 'B': {
                 * if (tok.matchesToken("BEGIN")) {
                 * // Test for mediawiki performance
                 * setAutoCommit(false);
                 * return true;
                 * }
                 * break;
                 * }
                 *
                 * case 'r': case 'R': {
                 * if (tok.matchesToken("ROLLBACK")) {
                 * rollback();
                 * setAutoCommit(true);
                 * return true;
                 * }
                 * break;
                 * }
                 */
            }

            return(false);
        }