8000 Merge pull request #19 from ljodal/master · emrul/postgres-async-driver@9711116 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9711116

Browse files
committed
Merge pull request alaisi#19 from ljodal/master
Issue alaisi#18: Incorrect parsing of varchar arrays
2 parents a7ca232 + f1e99b1 commit 9711116

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/main/java/com/github/pgasync/impl/conversion/ArrayConversions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ static int readArray(final char[] text, final int start, List<Object> result) {
9494
i = readString(text, i, values);
9595
} else if(c == '{') {
9696
i = readArray(text, i, values);
97-
} else if (c == 'N') {
97+
} else if (c == 'N' && text.length > i + 4 &&
98+
text[i+1] == 'U' && text[i+2] == 'L' && text[i+3] == 'L' &&
99+
(text[i+4] == ',' || text[i+4] == '}' || Character.isWhitespace(text[i+4]))) {
98100
i = readNull(i, values);
99101
} else {
100102
i = readValue(text, i, values);

src/test/java/com/github/pgasync/impl/ArrayConversionsTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.math.BigDecimal;
77
import java.sql.Timestamp;
88
import java.util.ArrayList;
9+
import java.util.Collections;
910
import java.util.List;
1011

1112
import static java.util.Arrays.asList;
@@ -193,4 +194,20 @@ public void shouldAllowPrimitiveArrayParameters() {
193194
assertEquals(input[i], output[i].longValue());
194195
}
195196
}
197+
198+
@Test
199+
public void shouldParseUnquotedStringsCorrectly() {
200+
String[] values = new String[] {"NotNull", "NULLA", "string", null};
201+
dbr.query("INSERT INTO CA_TEST (TEXTA) VALUES($1)", Collections.singletonList(values));
202+
Row row = dbr.query("SELECT * FROM CA_TEST").row(0);
203+
assertArrayEquals(values, row.getArray("TEXTA", String[].class));
204+
}
205+
206+
@Test
207+
public void shouldParseNullTextCorrectly() {
208+
String[] values = new String[] {"NULL", null, "string"};
209+
dbr.query("INSERT INTO CA_TEST (TEXTA) VALUES($1)", Collections.singletonList(values));
210+
Row row = dbr.query("SELECT * FROM CA_TEST").row(0);
211+
assertArrayEquals(values, row.getArray("TEXTA", String[].class));
212+
}
196213
}

0 commit comments

Comments
 (0)
0