@Test public void testDynamicCommandWithIntoAndLoop() throws Exception {
//Test INTO clause with loop
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
FakeMetadataObject pm1 = metadata.getStore().findObject("pm1",FakeMetadataObject.MODEL); //$NON-NLS-1$
FakeMetadataObject rs2 = FakeMetadataFactory.createResultSet("pm1.rs1", pm1, new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
FakeMetadataObject rs2p1 = FakeMetadataFactory.createParameter("ret", 1, ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs2); //$NON-NLS-1$
StringBuffer procedure = new StringBuffer("CREATE VIRTUAL PROCEDURE \n"); //$NON-NLS-1$
procedure.append("BEGIN\n"); //$NON-NLS-1$
procedure.append("declare integer VARIABLES.e2_total=0;\n"); //$NON-NLS-1$
procedure.append("execute string 'SELECT e1, e2 FROM pm1.g1' as e1 string, e2 integer into #temp;\n"); //$NON-NLS-1$
procedure.append("loop on (Select e2 from #temp where e2 > 2) as mycursor\n"); //$NON-NLS-1$
procedure.append("BEGIN\n"); //$NON-NLS-1$
procedure.append("IF (mycursor.e2>5) \n"); //$NON-NLS-1$
procedure.append("VARIABLES.e2_total=VARIABLES.e2_total+mycursor.e2;\n"); //$NON-NLS-1$
procedure.append("END\n"); //$NON-NLS-1$
procedure.append("SELECT VARIABLES.e2_total;\n"); //$NON-NLS-1$
procedure.append("END"); //$NON-NLS-1$
QueryNode sq2n1 = new QueryNode(procedure.toString()); //$NON-NLS-1$
FakeMetadataObject sq1 = FakeMetadataFactory.createVirtualProcedure("pm1.sq1", pm1, Arrays.asList(new FakeMetadataObject[] { rs2p1 }), sq2n1); //$NON-NLS-1$
metadata.getStore().addObject(rs2);
metadata.getStore().addObject(sq1);
String userUpdateStr = "EXEC pm1.sq1()"; //$NON-NLS-1$