Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/main/java/io/mo/util/ResultParser.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ private static String advanceToNextCommand(String text, SqlCommand cmd) {
private static RSSet convertToRSSet(String rsText, String separator) {
if (rsText == null || rsText.isEmpty()) return null;

// extractResult removes the newline immediately before the next SQL.
// An empty modern result therefore retains only a terminal row marker.
String rowTerminator = RESULT.ROW_SEPARATOR_NEW.substring(0, RESULT.ROW_SEPARATOR_NEW.length() - 1);
if (rsText.startsWith(RESULT.FULL_HEADER_LEAD)
&& rsText.endsWith(rowTerminator)
&& !rsText.contains(RESULT.ROW_SEPARATOR_NEW)) {
rsText = rsText.substring(0, rsText.length() - rowTerminator.length());
}

String rowSeparator = rsText.contains(RESULT.ROW_SEPARATOR_NEW) ? RESULT.ROW_SEPARATOR_NEW : "\n";

String normalized = rsText;
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/io/mo/util/ResultParserEmptyMetadataTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.mo.util;

import io.mo.result.RSSet;
import java.lang.reflect.Method;
import java.sql.Types;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class ResultParserEmptyMetadataTest {
@Test
public void parsesMetadataForEmptyResultBeforeNextCommand() throws Exception {
Method extract = ResultParser.class.getDeclaredMethod("extractResult", String.class, String.class, String.class);
Method convert = ResultParser.class.getDeclaredMethod("convertToRSSet", String.class, String.class);
extract.setAccessible(true);
convert.setAccessible(true);
String command = "execute clipped_range using @lo,@hi;";
String next = "set @lo = 1.5;";
String input = command + "\n" + "➤ a[4,32,0] 𝄀\n" + next;
String extracted = (String) extract.invoke(null, command, next, input);
RSSet result = (RSSet) convert.invoke(null, extracted, "space");
assertEquals(Types.INTEGER, result.getMeta().getType(0));
assertEquals("a[4,32,0]", result.getMeta().stringAt(0));
assertEquals(0, result.getRows().size());
}

@Test
public void preservesModernResultRowsAndLegacyResults() throws Exception {
Method convert = ResultParser.class.getDeclaredMethod("convertToRSSet", String.class, String.class);
convert.setAccessible(true);
RSSet modern = (RSSet) convert.invoke(null, "➤ a[4,32,0] 𝄀\n1", "space");
assertEquals(Types.INTEGER, modern.getMeta().getType(0));
assertEquals(1, modern.getRows().size());
RSSet legacy = (RSSet) convert.invoke(null, "a\n1", "space");
assertEquals(1, legacy.getRows().size());
}
}
Loading