Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: AbstractJdbc2Array - another patch





On Thu, 22 Nov 2007, Marek Lewczuk wrote:

Well, I aware that java.lang.reflect.Array#newInstance can be used
however I didn't know for what versions of JDK reflect package can be used - if you have mentioned about it so I guess that I can - in the attachment you can find AbstractJdbc2Array patch - please review it.

Doesn't seem to work. The attached case fails in two different ways depending on whether compatible is set or not. The JDK methods you can use depends on where the code you are adding goes. In this case you're adding code to a JDBC2 class, so you are restricted to JDK1.2 code. JDBC3 -> 1.4, JDBC3g -> 1.5, JDBC4 -> 1.6.

I one to discuss one more thing - see below lines in the AbstractJdb2Array:
this.useObjects = connection.haveMinimumCompatibleVersion("8.3");
this.haveMinServer82 = connection.haveMinimumServerVersion("8.2");

We must clarify, when to use objects instead of primitive types ? Can you describe it ?


Right now you use objects if either dims > 1 or useObjects. I'm suggesting that we should only use objects if useObjects. That way people who want to get int[][] returned can get that via setting compatible=8.2.

Kris Jurka
import java.sql.*;

public class ArrayTest4 {

	public static void main(String args[]) throws Exception {
		Class.forName("org.postgresql.Driver");
		Connection conn;
		
		conn = DriverManager.getConnection("jdbc:postgresql://localhost:5830/jurka","jurka","");
		try {
			testMultiDim(conn);
		} catch (Exception e) {
			e.printStackTrace();
		}
		conn.close();
		
		conn = DriverManager.getConnection("jdbc:postgresql://localhost:5830/jurka?compatible=8.1","jurka","");
		try {
			testMultiDim(conn);
		} catch (Exception e) {
			e.printStackTrace();
		}
		conn.close();
	}

	private static void testMultiDim(Connection conn) throws SQLException {
		Statement stmt = conn.createStatement();

		ResultSet rs = stmt.executeQuery("SELECT '{{1,2},{4,5}}'::int[]");
		rs.next();
		Array arr = rs.getArray(1);
		Integer i[][] = (Integer[][])arr.getArray();

		rs.close();
		stmt.close();
	}
}



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group