Mercurial > hg > monetdb-java
changeset 247:3897bbab2d23 embedded
Small fixes.
author | Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> |
---|---|
date | Wed, 25 Jul 2018 17:56:48 +0200 (2018-07-25) |
parents | 694cfc607c47 |
children | 14e6f812b43c |
files | src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTableHeaderParser.java tests/Test_PSsqldata.java tests/Test_Rsqldata.java |
diffstat | 4 files changed, 55 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java @@ -2082,6 +2082,7 @@ public class MonetPreparedStatement exte case Types.NCHAR: case Types.NVARCHAR: case Types.LONGNVARCHAR: + case Types.OTHER: { String castprefix = ""; switch (paramMonetdbType) {
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTableHeaderParser.java +++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTableHeaderParser.java @@ -114,21 +114,59 @@ final class OldMapiTableHeaderParser { */ private static void getStringValues(char[] array, int stop, String[] stringValues) { int elem = 0, start = 2; + boolean inString = false, escaped = false; - for (int i = start + 1; i < stop; i++) { - if (array[i] == '\t' && array[i - 1] == ',') { - if (array[start] == '"') { - start++; // skip leading double quote - } - stringValues[elem++] = new String(array, start, i - (array[i - 2] == '"' ? 2 : 1) - start); - start = i + 1; + for (int i = start; i < stop; i++) { + switch(array[i]) { + case '\\': + escaped = !escaped; + break; + case '"': + /** + * If all strings are wrapped between two quotes, a \" can + * never exist outside a string. Thus if we believe that we + * are not within a string, we can safely assume we're about + * to enter a string if we find a quote. + * If we are in a string we should stop being in a string if + * we find a quote which is not prefixed by a \, for that + * would be an escaped quote. However, a nasty situation can + * occur where the string is like "test \\" as obvious, a + * test for a \ in front of a " doesn't hold here for all + * cases. Because "test \\\"" can exist as well, we need to + * know if a quote is prefixed by an escaping slash or not. + */ + if (!inString) { + inString = true; + } else if (!escaped) { + inString = false; + } + // reset escaped flag + escaped = false; + break; + case ',': + if (!inString && array[i + 1] == '\t') { + // we found the field separator + if (array[start] == '"') + start++; // skip leading double quote + if (elem < stringValues.length) { + stringValues[elem++] = new String(array, start, i - (array[i - 1] == '"' ? 1 : 0) - start); + } + i++; + start = i + 1; // reset start for the next name, skipping the field separator (a comma and tab) + } + // reset escaped flag + escaped = false; + break; + default: + escaped = false; + break; } } // add the left over part (last column) - if (array[start] == '"') { + if (array[start] == '"') start++; // skip leading double quote - } - stringValues[elem] = new String(array, start, stop - (array[stop - 1] == '"' ? 1 : 0) - start); + if (elem < stringValues.length) + stringValues[elem] = new String(array, start, stop - (array[stop - 1] == '"' ? 1 : 0) - start); } /**
--- a/tests/Test_PSsqldata.java +++ b/tests/Test_PSsqldata.java @@ -10,6 +10,7 @@ import java.net.URL; import java.sql.*; import nl.cwi.monetdb.jdbc.MonetINET; +import nl.cwi.monetdb.jdbc.MonetURL; public class Test_PSsqldata { public static void main(String[] args) throws Exception { @@ -62,8 +63,8 @@ public class Test_PSsqldata { MonetINET inet = (MonetINET)x; System.out.println("\t" + inet.getAddress() + "/" + inet.getNetmaskBits()); System.out.println("\t" + inet.getInetAddress().toString()); - } else if (x instanceof URL) { - URL url = (URL)x; + } else if (x instanceof MonetURL) { + MonetURL url = (MonetURL)x; System.out.println("\t" + url.toString()); } }
--- a/tests/Test_Rsqldata.java +++ b/tests/Test_Rsqldata.java @@ -10,6 +10,7 @@ import java.net.URL; import java.sql.*; import nl.cwi.monetdb.jdbc.MonetINET; +import nl.cwi.monetdb.jdbc.MonetURL; public class Test_Rsqldata { public static void main(String[] args) throws Exception { @@ -57,8 +58,8 @@ public class Test_Rsqldata { MonetINET inet = (MonetINET)x; System.out.println("\t" + inet.getAddress() + "/" + inet.getNetmaskBits()); System.out.println("\t" + inet.getInetAddress().toString()); - } else if (x instanceof URL) { - URL url = (URL)x; + } else if (x instanceof MonetURL) { + MonetURL url = (MonetURL)x; System.out.println("\t" + url.toString()); } }