[libpostgresql-jdbc-java] 57/128: Lookup correct array delimiter in Connection.createArrayOf.
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:18:30 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to annotated tag REL9_3_1100
in repository libpostgresql-jdbc-java.
commit 471a09ee31f92f04813b275402fbf5a8c6b16bf0
Author: Kris Jurka <jurka at ejurka.com>
Date: Tue Mar 26 05:33:45 2013 -0700
Lookup correct array delimiter in Connection.createArrayOf.
The old code had hardcoded a comma, but that's not true for all
datatypes.
Identification and fix by sumo in pull request #49, testcase by me.
---
org/postgresql/jdbc4/AbstractJdbc4Connection.java | 9 +++++----
org/postgresql/test/jdbc4/ArrayTest.java | 20 ++++++++++++++++++++
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/org/postgresql/jdbc4/AbstractJdbc4Connection.java b/org/postgresql/jdbc4/AbstractJdbc4Connection.java
index d25710a..817e457 100644
--- a/org/postgresql/jdbc4/AbstractJdbc4Connection.java
+++ b/org/postgresql/jdbc4/AbstractJdbc4Connection.java
@@ -82,29 +82,30 @@ abstract class AbstractJdbc4Connection extends org.postgresql.jdbc3g.AbstractJdb
if (oid == Oid.UNSPECIFIED)
throw new PSQLException(GT.tr("Unable to find server array type for provided name {0}.", typeName), PSQLState.INVALID_NAME);
+ char delim = getTypeInfo().getArrayDelimiter(oid);
StringBuffer sb = new StringBuffer();
- appendArray(sb, elements);
+ appendArray(sb, elements, delim);
// This will not work once we have a JDBC 5,
// but it'll do for now.
return new Jdbc4Array(this, oid, sb.toString());
}
- private static void appendArray(StringBuffer sb, Object elements)
+ private static void appendArray(StringBuffer sb, Object elements, char delim)
{
sb.append('{');
int nElements = java.lang.reflect.Array.getLength(elements);
for (int i=0; i<nElements; i++) {
if (i > 0) {
- sb.append(',');
+ sb.append(delim);
}
Object o = java.lang.reflect.Array.get(elements, i);
if (o == null) {
sb.append("NULL");
} else if (o.getClass().isArray()) {
- appendArray(sb, o);
+ appendArray(sb, o, delim);
} else {
String s = o.toString();
AbstractJdbc2Array.escapeArrayElement(sb, s);
diff --git a/org/postgresql/test/jdbc4/ArrayTest.java b/org/postgresql/test/jdbc4/ArrayTest.java
index f852aee..ae23d5c 100644
--- a/org/postgresql/test/jdbc4/ArrayTest.java
+++ b/org/postgresql/test/jdbc4/ArrayTest.java
@@ -10,6 +10,7 @@ package org.postgresql.test.jdbc4;
import java.sql.*;
import junit.framework.TestCase;
import org.postgresql.test.TestUtil;
+import org.postgresql.geometric.PGbox;
public class ArrayTest extends TestCase {
@@ -70,6 +71,25 @@ public class ArrayTest extends TestCase {
assertEquals("\"\\'z", out[1][1]);
}
+ public void testCreateArrayWithNonStandardDelimiter() throws SQLException {
+ PGbox in[] = new PGbox[2];
+ in[0] = new PGbox(1, 2, 3, 4);
+ in[1] = new PGbox(5, 6, 7, 8);
+
+ PreparedStatement pstmt = _conn.prepareStatement("SELECT ?::box[]");
+ pstmt.setArray(1, _conn.createArrayOf("box", in));
+ ResultSet rs = pstmt.executeQuery();
+ assertTrue(rs.next());
+ Array arr = rs.getArray(1);
+ ResultSet arrRs = arr.getResultSet();
+ assertTrue(arrRs.next());
+ assertEquals(in[0], arrRs.getObject(2));
+ assertTrue(arrRs.next());
+ assertEquals(in[1], arrRs.getObject(2));
+ assertFalse(arrRs.next());
+ }
+
+
public void testCreateArrayOfNull() throws SQLException {
if (!TestUtil.haveMinimumServerVersion(_conn, "8.2"))
return;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git
More information about the pkg-java-commits
mailing list