Skip to content

Commit

Permalink
test: added test case for sql script and foreach executed on resultsets
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Jul 28, 2024
1 parent e0eb1ab commit 847bfa8
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions engine/src/test/java/com/arcadedb/query/sql/BatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,27 @@ public void testNestedBreak() {
Assertions.assertEquals(7, (Integer) result.next().getProperty("value"));
}

@Test
public void testForeachResultSet() {
database.command("sql", "CREATE DOCUMENT TYPE DocumentType");
database.transaction(() -> {
for (int i = 0; i < 100; i++)
database.command("sql", "INSERT INTO DocumentType set a = " + i);
});

final String script = "LET counter = 0;\n "
+ "\n"
+ "FOREACH( $row IN (select from DocumentType) ) {\n"
+ " LET counter = $counter + 1;\n"
+ "}\n"
+ "\n"
+ "RETURN $counter;";

final ResultSet result = database.command("sqlscript", script);
Assertions.assertTrue(result.hasNext());
Assertions.assertEquals(100, (Integer) result.next().getProperty("value"));
}

@Test
public void testUsingReservedVariableNames() {
try {
Expand Down

0 comments on commit 847bfa8

Please sign in to comment.