[libpostgresql-jdbc-java] 06/19: metadata encoding patch from Kris Jurka

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:19:07 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL7_4_1
in repository libpostgresql-jdbc-java.

commit 6af010f2bbf64b7caeaac1226bc5e8724118f785
Author: Dave Cramer <davec at fastcrypt.com>
Date:   Fri Dec 12 00:24:13 2003 +0000

    metadata encoding patch from Kris Jurka
---
 .../jdbc1/AbstractJdbc1DatabaseMetaData.java       | 121 +++++++++++----------
 1 file changed, 65 insertions(+), 56 deletions(-)

diff --git a/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java b/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
index 259288a..25b7083 100644
--- a/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
+++ b/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
@@ -5,6 +5,7 @@ import java.sql.*;
 import java.util.*;
 import org.postgresql.core.BaseStatement;
 import org.postgresql.core.Field;
+import org.postgresql.core.Encoding;
 import org.postgresql.util.PSQLException;
 import org.postgresql.util.PSQLState;
 import org.postgresql.Driver;
@@ -22,6 +23,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
 										   "vacuum,verbose,version";
 
 	protected AbstractJdbc1Connection connection; // The connection association
+	protected Encoding encoding;
 
 	// These define various OID's. Hopefully they will stay constant.
 	protected static final int iVarcharOid = 1043;	// OID for varchar
@@ -73,6 +75,13 @@ public abstract class AbstractJdbc1DatabaseMetaData
 	public AbstractJdbc1DatabaseMetaData(AbstractJdbc1Connection conn)
 	{
 		this.connection = conn;
+		try {
+			this.encoding = conn.getEncoding();
+		}
+		catch (SQLException sqle) {
+			this.encoding = Encoding.defaultEncoding();
+		}
+
 	}
 
 	/*
@@ -1858,15 +1867,15 @@ public abstract class AbstractJdbc1DatabaseMetaData
 				tuple[0] = null;
 				tuple[1] = schema;
 				tuple[2] = procedureName;
-				tuple[3] = "returnValue".getBytes();
-				tuple[4] = Integer.toString(java.sql.DatabaseMetaData.procedureColumnReturn).getBytes();
-				tuple[5] = Integer.toString(connection.getSQLType(returnType)).getBytes();
-				tuple[6] = connection.getPGType(returnType).getBytes();
+				tuple[3] = encoding.encode("returnValue");
+				tuple[4] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.procedureColumnReturn));
+				tuple[5] = encoding.encode(Integer.toString(connection.getSQLType(returnType)));
+				tuple[6] = encoding.encode(connection.getPGType(returnType));
 				tuple[7] = null;
 				tuple[8] = null;
 				tuple[9] = null;
 				tuple[10] = null;
-				tuple[11] = Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown).getBytes();
+				tuple[11] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown));
 				tuple[12] = null;
 				v.addElement(tuple);
 			}
@@ -1878,15 +1887,15 @@ public abstract class AbstractJdbc1DatabaseMetaData
 				tuple[0] = null;
 				tuple[1] = schema;
 				tuple[2] = procedureName;
-				tuple[3] = ("$"+(i+1)).getBytes();
-				tuple[4] = Integer.toString(java.sql.DatabaseMetaData.procedureColumnIn).getBytes();
-				tuple[5] = Integer.toString(connection.getSQLType(argOid)).getBytes();
-				tuple[6] = connection.getPGType(argOid).getBytes();
+				tuple[3] = encoding.encode("$"+(i+1));
+				tuple[4] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.procedureColumnIn));
+				tuple[5] = encoding.encode(Integer.toString(connection.getSQLType(argOid)));
+				tuple[6] = encoding.encode(connection.getPGType(argOid));
 				tuple[7] = null;
 				tuple[8] = null;
 				tuple[9] = null;
 				tuple[10] = null;
-				tuple[11] = Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown).getBytes();
+				tuple[11] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown));
 				tuple[12] = null;
 				v.addElement(tuple);
 			}
@@ -1901,15 +1910,15 @@ public abstract class AbstractJdbc1DatabaseMetaData
 					tuple[0] = null;
 					tuple[1] = schema;
 					tuple[2] = procedureName;
-					tuple[3] = columnrs.getString("attname").getBytes();
-					tuple[4] = Integer.toString(java.sql.DatabaseMetaData.procedureColumnResult).getBytes();
-					tuple[5] = Integer.toString(connection.getSQLType(columnTypeOid)).getBytes();
-					tuple[6] = connection.getPGType(columnTypeOid).getBytes();
+					tuple[3] = columnrs.getBytes("attname");
+					tuple[4] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.procedureColumnResult));
+					tuple[5] = encoding.encode(Integer.toString(connection.getSQLType(columnTypeOid)));
+					tuple[6] = encoding.encode(connection.getPGType(columnTypeOid));
 					tuple[7] = null;
 					tuple[8] = null;
 					tuple[9] = null;
 					tuple[10] = null;
-					tuple[11] = Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown).getBytes();
+					tuple[11] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown));
 					tuple[12] = null;
 					v.addElement(tuple);
 				}
@@ -2205,7 +2214,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
 		for (i=0; i < types.length; i++)
 		{
 			byte[][] tuple = new byte[1][];
-			tuple[0] = types[i].getBytes();
+			tuple[0] = encoding.encode(types[i]);
 			v.addElement(tuple);
 		}
 
@@ -2338,46 +2347,46 @@ public abstract class AbstractJdbc1DatabaseMetaData
 			tuple[1] = rs.getBytes("nspname");	// Schema
 			tuple[2] = rs.getBytes("relname");	// Table name
 			tuple[3] = rs.getBytes("attname");	// Column name
-			tuple[4] = Integer.toString(connection.getSQLType(typeOid)).getBytes();
+			tuple[4] = encoding.encode(Integer.toString(connection.getSQLType(typeOid)));
 			String pgType = connection.getPGType(typeOid);
-			tuple[5] = pgType.getBytes();		// Type name
+			tuple[5] = encoding.encode(pgType);	// Type name
 
 			// by default no decimal_digits
 			// if the type is numeric or decimal we will
 			// overwrite later.
-			tuple[8] = "0".getBytes();
+			tuple[8] = encoding.encode("0");
 
 			if (pgType.equals("bpchar") || pgType.equals("varchar"))
 			{
 				int atttypmod = rs.getInt("atttypmod");
-				tuple[6] = Integer.toString(atttypmod != -1 ? atttypmod - VARHDRSZ : 0).getBytes();
+				tuple[6] = encoding.encode(Integer.toString(atttypmod != -1 ? atttypmod - VARHDRSZ : 0));
 			}
 			else if (pgType.equals("numeric") || pgType.equals("decimal")) 
 			{
 				int attypmod = rs.getInt("atttypmod") - VARHDRSZ;
-				tuple[6] = Integer.toString( ( attypmod >> 16 ) & 0xffff ).getBytes();
-				tuple[8] = Integer.toString(attypmod & 0xffff).getBytes();
-				tuple[9] = "10".getBytes();
+				tuple[6] = encoding.encode(Integer.toString( ( attypmod >> 16 ) & 0xffff ));
+				tuple[8] = encoding.encode(Integer.toString(attypmod & 0xffff));
+				tuple[9] = encoding.encode("10");
 			}
 			else if (pgType.equals("bit") || pgType.equals("varbit")) {
 				tuple[6] = rs.getBytes("atttypmod");
-				tuple[9] = "2".getBytes();
+				tuple[9] = encoding.encode("2");
 			}
 			else {
 				tuple[6] = rs.getBytes("attlen");
-				tuple[9] = "10".getBytes();
+				tuple[9] = encoding.encode("10");
 			}
 
 			tuple[7] = null;						// Buffer length
 
-			tuple[10] = Integer.toString(rs.getBoolean("attnotnull") ? java.sql.DatabaseMetaData.columnNoNulls : java.sql.DatabaseMetaData.columnNullable).getBytes();	// Nullable
+			tuple[10] = encoding.encode(Integer.toString(rs.getBoolean("attnotnull") ? java.sql.DatabaseMetaData.columnNoNulls : java.sql.DatabaseMetaData.columnNullable));	// Nullable
 			tuple[11] = rs.getBytes("description");				// Description (if any)
 			tuple[12] = rs.getBytes("adsrc");				// Column default
 			tuple[13] = null;						// sql data type (unused)
 			tuple[14] = null;						// sql datetime sub (unused)
 			tuple[15] = tuple[6];					// char octet length
 			tuple[16] = rs.getBytes("attnum");		// ordinal position
-			tuple[17] = (rs.getBoolean("attnotnull") ? "NO" : "YES").getBytes();	// Is nullable
+			tuple[17] = encoding.encode(rs.getBoolean("attnotnull") ? "NO" : "YES");	// Is nullable
 
 			v.addElement(tuple);
 		}
@@ -2476,7 +2485,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
 			}
 			sortStringArray(permNames);
 			for (i=0; i<permNames.length; i++) {
-				byte[] privilege = permNames[i].getBytes();
+				byte[] privilege = encoding.encode(permNames[i]);
 				Vector grantees = (Vector)permissions.get(permNames[i]);
 				for (int j=0; j<grantees.size(); j++) {
 					String grantee = (String)grantees.elementAt(j);
@@ -2486,10 +2495,10 @@ public abstract class AbstractJdbc1DatabaseMetaData
 					tuple[1] = schemaName;
 					tuple[2] = tableName;
 					tuple[3] = column;
-					tuple[4] = owner.getBytes();
-					tuple[5] = grantee.getBytes();
+					tuple[4] = encoding.encode(owner);
+					tuple[5] = encoding.encode(grantee);
 					tuple[6] = privilege;
-					tuple[7] = grantable.getBytes();
+					tuple[7] = encoding.encode(grantable);
 					v.addElement(tuple);
 				}
 			}
@@ -2579,7 +2588,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
 			}
 			sortStringArray(permNames);
 			for (i=0; i<permNames.length; i++) {
-				byte[] privilege = permNames[i].getBytes();
+				byte[] privilege = encoding.encode(permNames[i]);
 				Vector grantees = (Vector)permissions.get(permNames[i]);
 				for (int j=0; j<grantees.size(); j++) {
 					String grantee = (String)grantees.elementAt(j);
@@ -2588,10 +2597,10 @@ public abstract class AbstractJdbc1DatabaseMetaData
 					tuple[0] = null;
 					tuple[1] = schema;
 					tuple[2] = table;
-					tuple[3] = owner.getBytes();
-					tuple[4] = grantee.getBytes();
+					tuple[3] = encoding.encode(owner);
+					tuple[4] = encoding.encode(grantee);
 					tuple[5] = privilege;
-					tuple[6] = grantable.getBytes();
+					tuple[6] = encoding.encode(grantable);
 					v.addElement(tuple);
 				}
 			}
@@ -2785,14 +2794,14 @@ public abstract class AbstractJdbc1DatabaseMetaData
 		while (rs.next()) {
 			byte tuple[][] = new byte[8][];
 			int columnTypeOid = rs.getInt("atttypid");
-			tuple[0] = Integer.toString(scope).getBytes();
+			tuple[0] = encoding.encode(Integer.toString(scope));
 			tuple[1] = rs.getBytes("attname");
-			tuple[2] = Integer.toString(connection.getSQLType(columnTypeOid)).getBytes();
-			tuple[3] = connection.getPGType(columnTypeOid).getBytes();
+			tuple[2] = encoding.encode(Integer.toString(connection.getSQLType(columnTypeOid)));
+			tuple[3] = encoding.encode(connection.getPGType(columnTypeOid));
 			tuple[4] = null;
 			tuple[5] = null;
 			tuple[6] = null;
-			tuple[7] = Integer.toString(java.sql.DatabaseMetaData.bestRowNotPseudo).getBytes();
+			tuple[7] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.bestRowNotPseudo));
 			v.addElement(tuple);
 		}
 
@@ -2854,13 +2863,13 @@ public abstract class AbstractJdbc1DatabaseMetaData
 		 */
 
 		tuple[0] = null;
-		tuple[1] = "ctid".getBytes();
-		tuple[2] = Integer.toString(connection.getSQLType("tid")).getBytes();
-		tuple[3] = "tid".getBytes();
+		tuple[1] = encoding.encode("ctid");
+		tuple[2] = encoding.encode(Integer.toString(connection.getSQLType("tid")));
+		tuple[3] = encoding.encode("tid");
 		tuple[4] = null;
 		tuple[5] = null;
 		tuple[6] = null;
-		tuple[7] = Integer.toString(java.sql.DatabaseMetaData.versionColumnPseudo).getBytes();
+		tuple[7] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.versionColumnPseudo));
 		v.addElement(tuple);
 
 		/* Perhaps we should check that the given
@@ -3157,7 +3166,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
 				else if ("restrict".equals(rule))
 					action = java.sql.DatabaseMetaData.importedKeyRestrict;
 
-				tuple[9] = Integer.toString(action).getBytes();
+				tuple[9] = encoding.encode(Integer.toString(action));
 
 			}
 
@@ -3175,7 +3184,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
 					action = java.sql.DatabaseMetaData.importedKeySetNull;
 				else if ("setdefault".equals(rule))
 					action = java.sql.DatabaseMetaData.importedKeySetDefault;
-				tuple[10] = Integer.toString(action).getBytes();
+				tuple[10] =  encoding.encode(Integer.toString(action)); 
 			}
 
 
@@ -3215,11 +3224,11 @@ public abstract class AbstractJdbc1DatabaseMetaData
 				pkeyColumn = (String)tokens.elementAt(element);
 			}
 
-			tuple[3] = pkeyColumn.getBytes(); //PKCOLUMN_NAME
-			tuple[7] = fkeyColumn.getBytes(); //FKCOLUMN_NAME
+			tuple[3] = encoding.encode(pkeyColumn); //PKCOLUMN_NAME
+			tuple[7] = encoding.encode(fkeyColumn); //FKCOLUMN_NAME
 
 			tuple[8] = rs.getBytes(6); //KEY_SEQ
-			tuple[11] = fkName.getBytes(); //FK_NAME this will give us a unique name for the foreign key
+			tuple[11] = encoding.encode(fkName); //FK_NAME this will give us a unique name for the foreign key
 			tuple[12] = rs.getBytes(7); //PK_NAME
 
 			// DEFERRABILITY
@@ -3233,7 +3242,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
 				else
 					deferrability = java.sql.DatabaseMetaData.importedKeyInitiallyImmediate;
 			}
-			tuple[13] = Integer.toString(deferrability).getBytes();
+			tuple[13] = encoding.encode(Integer.toString(deferrability));
 
 			tuples.addElement(tuple);
 		}
@@ -3496,18 +3505,18 @@ public abstract class AbstractJdbc1DatabaseMetaData
 		ResultSet rs = connection.createStatement().executeQuery(sql);
 		// cache some results, this will keep memory useage down, and speed
 		// things up a little.
-		byte b9[] = "9".getBytes();
-		byte b10[] = "10".getBytes();
-		byte bf[] = "f".getBytes();
-		byte bnn[] = Integer.toString(java.sql.DatabaseMetaData.typeNoNulls).getBytes();
-		byte bts[] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable).getBytes();
+		byte b9[] = encoding.encode("9");
+		byte b10[] = encoding.encode("10");
+		byte bf[] = encoding.encode("f");
+		byte bnn[] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.typeNoNulls));
+		byte bts[] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.typeSearchable));
 
 		while (rs.next())
 		{
 			byte[][] tuple = new byte[18][];
 			String typname = rs.getString(1);
-			tuple[0] = typname.getBytes();
-			tuple[1] = Integer.toString(connection.getSQLType(typname)).getBytes();
+			tuple[0] = encoding.encode(typname);
+			tuple[1] = encoding.encode(Integer.toString(connection.getSQLType(typname)));
 			tuple[2] = b9;	// for now
 			tuple[6] = bnn; // for now
 			tuple[7] = bf; // false for now - not case sensitive

-- 
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