{"record":{"id":"f66653f5a1ecf020","repo":"MyCATApache/Mycat-Server","slug":"not-a-query-sql-statement","errorCode":null,"errorMessage":"not a query sql statement","messagePattern":"not a query sql statement","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/backend/jdbc/mongodb/MongoSQLParser.java","lineNumber":66,"sourceCode":"\t        return parser.parseStatement();\r\n\t     }\r\n\t     catch (Exception e)\r\n\t     {\r\n\t         LOGGER.error(\"MongoSQLParser.parserError\", e);\r\n\t    }\r\n\t     throw new MongoSQLException.ErrorSQL(s);\r\n\t   }\t\r\n\t\r\n\tpublic  void setParams(List params)\r\n\t   {\r\n\t     this._pos = 1;\r\n\t     this._params = params;\r\n\t   }\r\n\t   \r\n\tpublic MongoData query() throws MongoSQLException{\r\n        if (!(statement instanceof SQLSelectStatement)) {\r\n        \t//return null;\r\n        \tthrow new IllegalArgumentException(\"not a query sql statement\");\r\n        }\r\n        MongoData mongo=new MongoData();\r\n        DBCursor c=null;\r\n        SQLSelectStatement selectStmt = (SQLSelectStatement)statement;\r\n        SQLSelectQuery sqlSelectQuery =selectStmt.getSelect().getQuery();\t\r\n        int icount=0;\r\n\t\tif(sqlSelectQuery instanceof MySqlSelectQueryBlock) {\r\n\t\t\tMySqlSelectQueryBlock mysqlSelectQuery = (MySqlSelectQueryBlock)selectStmt.getSelect().getQuery();\r\n\t\t\t\r\n\t\t\tBasicDBObject fields = new BasicDBObject();\r\n\t\t\t//显示的字段\r\n\t\t\tfor(SQLSelectItem item : mysqlSelectQuery.getSelectList()) {\r\n\t\t\t\t//System.out.println(item.toString());\r\n\t\t\t\tif (!(item.getExpr() instanceof SQLAllColumnExpr)) {\r\n\t\t\t\t\tif (item.getExpr() instanceof SQLAggregateExpr) {\r\n\t\t\t\t\t\tSQLAggregateExpr expr =(SQLAggregateExpr)item.getExpr();\r\n\t\t\t\t\t\tif (expr.getMethodName().equals(\"COUNT\")) {\r\n\t\t\t\t\t\t   icount=1;\r","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/backend/jdbc/mongodb/MongoSQLParser.java#L48-L84","documentation":"MongoSQLParser.query() requires the parsed Druid AST to be a SQLSelectStatement; anything else (INSERT, UPDATE, DELETE, DDL, etc.) triggers IllegalArgumentException(\"not a query sql statement\"). Only SELECT statements can be translated into a MongoDB find query by this parser.","triggerScenarios":"Passing a non-SELECT SQL string (INSERT/UPDATE/DELETE/SHOW/etc.) through a path that calls MongoSQLParser.query(), e.g. executing an INSERT or UPDATE via the query/read path of the MongoDB JDBC handler.","commonSituations":"Client sends an UPDATE or INSERT statement but the MyCat route sends it to the MongoDB backend handler that always invokes query(); SQL dialect differences make Druid parse the statement as non-select (e.g. 'SELECT ... INTO'); test harness passing arbitrary SQL.","solutions":["Only send SELECT statements down the query() path; route writes through executeUpdate/InsertData","Verify the SQL string actually parses as a Druid SQLSelectStatement (no trailing semicolon issues, no vendor-specific syntax)","Catch IllegalArgumentException around query() and redirect non-select statements to the update path","Pre-parse with Druid's SQLUtils to confirm statement type before calling query()"],"exampleFix":"// before\nMongoData data = parser.query(); // throws for non-SELECT\n\n// after\nif (parser.getStatement() instanceof SQLSelectStatement) {\n    MongoData data = parser.query();\n} else {\n    int affected = parser.executeUpdate();\n}","handlingStrategy":"type-guard","validationCode":"SQLStatement stmt = SQLUtils.parseStatements(sql, dbType).get(0);\nif (!(stmt instanceof SQLSelectStatement)) {\n    // route to update path instead of query()\n}","typeGuard":"boolean isQuery(SQLStatement statement) {\n    return statement instanceof SQLSelectStatement;\n}","tryCatchPattern":"try {\n    MongoData data = parser.query();\n} catch (IllegalArgumentException e) {\n    if (\"not a query sql statement\".equals(e.getMessage())) {\n        // re-dispatch via executeUpdate or reject the statement type\n    } else {\n        throw e;\n    }\n}","preventionTips":["Parse and classify SQL with Druid before choosing the query vs update path","Keep vendor-specific syntax out of statements sent to the Mongo handler","Add a regression test per statement type (SELECT/INSERT/UPDATE/DELETE) against query()"],"tags":["mongodb","sql","parser","illegal-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}