From 92b7fd4fe598fc339b4ac88aa0b031bc99a6911d Mon Sep 17 00:00:00 2001 From: Kevin Wooten Date: Thu, 25 Jun 2020 13:43:20 -0700 Subject: [PATCH] Fix string based null handling for scalars, records & arrays (#494) --- .../postgres/system/procs/Arrays.java | 12 ++- .../postgres/system/procs/BaseDecoders.java | 4 - .../postgres/system/procs/Records.java | 8 +- .../impossibl/postgres/jdbc/ArrayTest.java | 89 +++++++++++++++++++ .../postgres/jdbc/ResultSetTest.java | 32 +++++++ .../impossibl/postgres/jdbc/StructTest.java | 50 ++++++++++- 6 files changed, 179 insertions(+), 16 deletions(-) diff --git a/driver/src/main/java/com/impossibl/postgres/system/procs/Arrays.java b/driver/src/main/java/com/impossibl/postgres/system/procs/Arrays.java index ed1e2855c..be21aaf01 100644 --- a/driver/src/main/java/com/impossibl/postgres/system/procs/Arrays.java +++ b/driver/src/main/java/com/impossibl/postgres/system/procs/Arrays.java @@ -284,6 +284,7 @@ int[] parseElementBuffers(char delim, CharSequence buffer, List el int[] dimensions = new int[0]; int len = buffer.length(); StringBuilder elementText = null; + boolean quoted = false; int depth = -1; int charIdx; @@ -305,7 +306,8 @@ int[] parseElementBuffers(char delim, CharSequence buffer, List el case '}': if (elementText != null) { ++dimensions[depth]; - elementText = addTextElement(elementText, elements); + elementText = addTextElement(elementText, quoted, elements); + quoted = false; } if (--depth < 0) { break scan; @@ -318,6 +320,7 @@ int[] parseElementBuffers(char delim, CharSequence buffer, List el case '"': elementText = new StringBuilder(); charIdx = readString(buffer, charIdx, elementText); + quoted = true; break; case '[': @@ -337,7 +340,8 @@ int[] parseElementBuffers(char delim, CharSequence buffer, List el if (ch == delim) { if (elementText != null) { ++dimensions[depth]; - elementText = addTextElement(elementText, elements); + elementText = addTextElement(elementText, quoted, elements); + quoted = false; } break; } @@ -353,9 +357,9 @@ int[] parseElementBuffers(char delim, CharSequence buffer, List el return dimensions; } - StringBuilder addTextElement(StringBuilder text, List elements) { + StringBuilder addTextElement(StringBuilder text, boolean quoted, List elements) { String textStr = text.toString(); - if (textStr.equalsIgnoreCase("NULL")) { + if (!quoted && textStr.equalsIgnoreCase("NULL")) { elements.add(null); } else { diff --git a/driver/src/main/java/com/impossibl/postgres/system/procs/BaseDecoders.java b/driver/src/main/java/com/impossibl/postgres/system/procs/BaseDecoders.java index 525105356..a756b989b 100644 --- a/driver/src/main/java/com/impossibl/postgres/system/procs/BaseDecoders.java +++ b/driver/src/main/java/com/impossibl/postgres/system/procs/BaseDecoders.java @@ -210,10 +210,6 @@ public Object decode(Context context, Type type, Short typeLength, Integer typeM targetClass = targetClass != null ? targetClass : getDefaultClass(); - if (buffer.length() == 4 && buffer.toString().equalsIgnoreCase("NULL")) { - return null; - } - try { return decodeValue(context, type, typeLength, typeModifier, buffer, targetClass, targetContext); } diff --git a/driver/src/main/java/com/impossibl/postgres/system/procs/Records.java b/driver/src/main/java/com/impossibl/postgres/system/procs/Records.java index a82bc7303..e5f307f6d 100644 --- a/driver/src/main/java/com/impossibl/postgres/system/procs/Records.java +++ b/driver/src/main/java/com/impossibl/postgres/system/procs/Records.java @@ -265,13 +265,7 @@ StringBuilder addTextElement(StringBuilder text, boolean empty, List