From 4ddc835e996e10c979c1aac8094d7c8ecc7298f0 Mon Sep 17 00:00:00 2001 From: Andreas Reichel Date: Mon, 1 May 2023 13:54:13 +0700 Subject: [PATCH] doc: Update the README.md --- README.md | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index aeef82101..643f6301a 100644 --- a/README.md +++ b/README.md @@ -19,29 +19,34 @@ SELECT 1 FROM dual WHERE a = b ```text SQL Text - └─Statements: net.sf.jsqlparser.statement.select.PlainSelect - ├─selectItems -> Collection - │ └─selectItems: net.sf.jsqlparser.statement.select.SelectExpressionItem - │ └─LongValue: 1 - ├─Table: dual - └─where: net.sf.jsqlparser.expression.operators.relational.EqualsTo - ├─Column: a - └─Column: b + └─Statements: net.sf.jsqlparser.statement.select.Select + ├─selectItems -> Collection + │ └─LongValue: 1 + ├─Table: dual + └─where: net.sf.jsqlparser.expression.operators.relational.EqualsTo + ├─Column: a + └─Column: b ``` ```java -Statement statement = CCJSqlParserUtil.parse(sqlStr); -if (statement instanceof PlainSelect) { - PlainSelect plainSelect = (PlainSelect) statement; +String sqlStr = "select 1 from dual where a=b"; - SelectExpressionItem selectExpressionItem = - (SelectExpressionItem) plainSelect.getSelectItems().get(0); +PlainSelect select = (PlainSelect) CCJSqlParserUtil.parse(sqlStr); - Table table = (Table) plainSelect.getFromItem(); +SelectItem selectItem = + select.getSelectItems().get(0); +Assertions.assertEquals( + new LongValue(1) + , selectItem.getExpression()); - EqualsTo equalsTo = (EqualsTo) plainSelect.getWhere(); - Column a = (Column) equalsTo.getLeftExpression(); - Column b = (Column) equalsTo.getRightExpression(); +Table table = (Table) select.getFromItem(); +Assertions.assertEquals("dual", table.getName()); + +EqualsTo equalsTo = (EqualsTo) select.getWhere(); +Column a = (Column) equalsTo.getLeftExpression(); +Column b = (Column) equalsTo.getRightExpression(); +Assertions.assertEquals("a", a.getColumnName()); +Assertions.assertEquals("b", b.getColumnName()); } ```