Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,7 @@ public ASTNode visitPlsqlBlock(final PlsqlBlockContext ctx) {
TypeAttributeSegments typeAttributeSegments = extractTypeAttributeSegments(ctx);
result.getTables().addAll(typeAttributeSegments.getTables());
result.getColumns().addAll(typeAttributeSegments.getColumns());
result.getAttributes().getAttribute(PackageTypeNamesSQLStatementAttribute.class).getPackageTypeNames().addAll(typeAttributeSegments.getPackageTypeNames());
result.getSqlStatements().addAll(getSqlStatementsInPlsql());
result.getVariableNames().addAll(getVariableNames());
getSqlStatementsInPlsql().forEach(each -> each.getSqlStatement().getVariableNames().addAll(getVariableNames()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.shardingsphere.sql.parser.statement.core.segment.procedure.ProcedureCallNameSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.procedure.SQLStatementSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.PackageTypeNamesSQLStatementAttribute;
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.ProcedureCallNamesSQLStatementAttribute;
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TableSQLStatementAttribute;
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.DDLStatement;
Expand Down Expand Up @@ -57,6 +58,6 @@ public final class OraclePLSQLBlockStatement extends DDLStatement {
public OraclePLSQLBlockStatement(final DatabaseType databaseType, final List<ProcedureCallNameSegment> procedureCallNames) {
super(databaseType);
this.procedureCallNames = procedureCallNames;
attributes = new SQLStatementAttributes(new ProcedureCallNamesSQLStatementAttribute(procedureCallNames), new TableSQLStatementAttribute(tables));
attributes = new SQLStatementAttributes(new ProcedureCallNamesSQLStatementAttribute(procedureCallNames), new TableSQLStatementAttribute(tables), new PackageTypeNamesSQLStatementAttribute());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4205,7 +4205,7 @@
</expression-projection>
</projections>
<from>
<simple-table name="tab" start-index="70" stop-index="72" />
<simple-table name="tab" start-index="70" stop-index="72" db-link="dbs2" at="@" />
</from>
</select>
</create-table>
Expand Down
2 changes: 1 addition & 1 deletion test/it/parser/src/main/resources/case/ddl/create-view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@
</simple-table>
</left>
<right>
<simple-table name="dept" alias="b" start-index="74" stop-index="100">
<simple-table name="dept" alias="b" start-index="74" stop-index="100" db-link="hq.example.com">
<owner name="jward" start-index="74" stop-index="78" />
</simple-table>
</right>
Expand Down
8 changes: 8 additions & 0 deletions test/it/parser/src/main/resources/case/ddl/plsql-block.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,12 @@
<sql-statement start-index="65" stop-index="89" statement-class-simple-name="SelectStatement" />
</sql-statements>
</plsql-block>
<plsql-block sql-case-id="plsql_block_with_package_type_variables_oracle">
<package-type-names>
<package-name name="foo_pkg" start-index="29" stop-index="35">
<owner name="foo_schema" start-index="18" stop-index="27" />
</package-name>
<package-name name="bar_pkg" start-index="57" stop-index="63" />
</package-type-names>
</plsql-block>
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -8280,4 +8280,23 @@
</expression-projection>
</projections>
</select>
<select sql-case-id="select_count_from_remote_table_in_subquery_oracle">
<projections start-index="7" stop-index="49">
<subquery-projection start-index="7" stop-index="49" text="(SELECT COUNT(r.id) FROM t_order@db_link r)">
<subquery>
<select>
<projections start-index="15" stop-index="25">
<aggregation-projection type="COUNT" expression="COUNT(r.id)" start-index="15" stop-index="25" />
</projections>
<from>
<simple-table name="t_order" alias="r" start-index="32" stop-index="48" db-link="db_link" at="@" />
</from>
</select>
</subquery>
</subquery-projection>
</projections>
<from>
<simple-table name="dual" start-index="56" stop-index="59" />
</from>
</select>
</sql-parser-test-cases>
4 changes: 2 additions & 2 deletions test/it/parser/src/main/resources/case/dml/select.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7948,7 +7948,7 @@

<select sql-case-id="select_with_db_link">
<from>
<simple-table name="employees" start-index="14" stop-index="25">
<simple-table name="employees" start-index="14" stop-index="25" db-link="remote">
<owner name="hr" start-index="14" stop-index="15" />
</simple-table>
</from>
Expand Down Expand Up @@ -15103,7 +15103,7 @@

<select sql-case-id="select_with_table_dblink_oracle">
<from>
<simple-table name="t_order" start-index="14" stop-index="20" />
<simple-table name="t_order" start-index="14" stop-index="20" db-link="db_link" />
</from>
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@
<sql-case id="plsql_block_ref_cursor_return_schema_table_with_local_cursor_oracle" value="DECLARE CURSOR foo_cursor IS SELECT 1 foo_id FROM dual; TYPE foo_ref IS REF CURSOR RETURN foo_schema.foo_cursor%ROWTYPE; BEGIN NULL; END;" db-types="Oracle" />
<sql-case id="plsql_block_cursor_return_local_cursor_rowtype_oracle" value="DECLARE CURSOR foo_cursor IS SELECT 1 foo_id FROM dual; CURSOR foo_other RETURN foo_cursor%ROWTYPE; BEGIN NULL; END;" db-types="Oracle" />
<sql-case id="plsql_block_nested_local_cursor_rowtype_oracle" value="&lt;&lt;foo_block&gt;&gt; DECLARE PROCEDURE foo_proc IS CURSOR foo_cursor IS SELECT 1 foo_id FROM dual; TYPE foo_ref IS REF CURSOR RETURN foo_block.foo_proc.foo_cursor%ROWTYPE; BEGIN NULL; END; foo_real foo_schema.foo_table.foo_id%TYPE; BEGIN NULL; END;" db-types="Oracle" />
<sql-case id="plsql_block_with_package_type_variables_oracle" value="DECLARE foo_first foo_schema.foo_pkg.foo_rec; foo_second bar_pkg.bar_rec; BEGIN NULL; END;" db-types="Oracle" />
</sql-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,5 @@
<sql-case id="select_leading_decimal_alias" value="SELECT .0$p, .1a20, .2_" db-types="MySQL,Doris" />
<sql-case id="select_qualified_scientific_identifier" value="SELECT event.1e1a20 FROM event" db-types="MySQL,Doris" />
<sql-case id="select_leading_scientific_alias" value="SELECT .1e1a20" db-types="MySQL,Doris" />
<sql-case id="select_count_from_remote_table_in_subquery_oracle" value="SELECT (SELECT COUNT(r.id) FROM t_order@db_link r) FROM dual" db-types="Oracle" />
</sql-cases>
Loading