tuple[6] = encodeString(Integer .toString((attypmod >> 16) & 0xffff)); tuple[8] = encodeString(Integer.toString(attypmod & 0xffff)); tuple[9] = encodeString("10");
tuple[6] = new Integer ((attypmod >> 16) & 0xffff); tuple[8] = new Integer (attypmod & 0xffff); tuple[9] = new Integer(10);
	public java.sql.ResultSet getColumns(String catalog, String schemaPattern,		String tableNamePattern, String columnNamePattern) throws SQLException	{		ArrayList v = new ArrayList(); // The new ResultSet tuple stuff		ResultSetField f[] = new ResultSetField[18]; // The field descriptors														// for the new ResultSet		f[0] = new ResultSetField("TABLE_CAT", TypeOid.VARCHAR,			getMaxNameLength());		f[1] = new ResultSetField("TABLE_SCHEM", TypeOid.VARCHAR,			getMaxNameLength());		f[2] = new ResultSetField("TABLE_NAME", TypeOid.VARCHAR,			getMaxNameLength());		f[3] = new ResultSetField("COLUMN_NAME", TypeOid.VARCHAR,			getMaxNameLength());		f[4] = new ResultSetField("DATA_TYPE", TypeOid.INT2, 2);		f[5] = new ResultSetField("TYPE_NAME", TypeOid.VARCHAR,			getMaxNameLength());		f[6] = new ResultSetField("COLUMN_SIZE", TypeOid.INT4, 4);		f[7] = new ResultSetField("BUFFER_LENGTH", TypeOid.VARCHAR,			getMaxNameLength());		f[8] = new ResultSetField("DECIMAL_DIGITS", TypeOid.INT4, 4);		f[9] = new ResultSetField("NUM_PREC_RADIX", TypeOid.INT4, 4);		f[10] = new ResultSetField("NULLABLE", TypeOid.INT4, 4);		f[11] = new ResultSetField("REMARKS", TypeOid.VARCHAR,			getMaxNameLength());		f[12] = new ResultSetField("COLUMN_DEF", TypeOid.VARCHAR,			getMaxNameLength());		f[13] = new ResultSetField("SQL_DATA_TYPE", TypeOid.INT4, 4);		f[14] = new ResultSetField("SQL_DATETIME_SUB", TypeOid.INT4, 4);		f[15] = new ResultSetField("CHAR_OCTET_LENGTH", TypeOid.VARCHAR,			getMaxNameLength());		f[16] = new ResultSetField("ORDINAL_POSITION", TypeOid.INT4, 4);		f[17] = new ResultSetField("IS_NULLABLE", TypeOid.VARCHAR,			getMaxNameLength());		String sql = "SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,a.attnum,def.adsrc,dsc.description "				+ " FROM pg_catalog.pg_namespace n "				+ " JOIN pg_catalog.pg_class c ON (c.relnamespace = n.oid) "				+ " JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid) "				+ " LEFT JOIN pg_catalog.pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = def.adnum) "				+ " LEFT JOIN pg_catalog.pg_description dsc ON (c.oid=dsc.objoid AND a.attnum = dsc.objsubid) "				+ " LEFT JOIN pg_catalog.pg_class dc ON (dc.oid=dsc.classoid AND dc.relname='pg_class') "				+ " LEFT JOIN pg_catalog.pg_namespace dn ON (dc.relnamespace=dn.oid AND dn.nspname='pg_catalog') "				+ " WHERE a.attnum > 0 AND NOT a.attisdropped ";		if(schemaPattern != null && !"".equals(schemaPattern))		{			sql += " AND n.nspname LIKE '" + escapeQuotes(schemaPattern)				+ "' ";		}		if(tableNamePattern != null && !"".equals(tableNamePattern))		{			sql += " AND c.relname LIKE '" + escapeQuotes(tableNamePattern)				+ "' ";		}		if(columnNamePattern != null && !"".equals(columnNamePattern))		{			sql += " AND a.attname LIKE '" + escapeQuotes(columnNamePattern)				+ "' ";		}		sql += " ORDER BY nspname,relname,attnum ";		ResultSet rs = m_connection.createStatement().executeQuery(sql);		while(rs.next())		{			byte[][] tuple = new byte[18][];			int typeOid = rs.getInt("atttypid");			tuple[0] = null; // Catalog name, not supported			tuple[1] = rs.getBytes("nspname"); // Schema			tuple[2] = rs.getBytes("relname"); // Table name			tuple[3] = rs.getBytes("attname"); // Column name			tuple[4] = encodeString(Integer.toString(m_connection				.getSQLType(typeOid)));			String pgType = m_connection.getPGType(typeOid);			tuple[5] = encodeString(pgType); // Type name			String defval = rs.getString("adsrc");			if(defval != null)			{				if(pgType.equals("int4"))				{					if(defval.indexOf("nextval(") != -1)						tuple[5] = encodeString("serial"); // Type name ==															// serial				}				else if(pgType.equals("int8"))				{					if(defval.indexOf("nextval(") != -1)						tuple[5] = encodeString("bigserial"); // Type name ==																// bigserial				}			}			// by default no decimal_digits			// if the type is numeric or decimal we will			// overwrite later.			tuple[8] = encodeString("0");			if(pgType.equals("bpchar") || pgType.equals("varchar"))			{				int atttypmod = rs.getInt("atttypmod");				tuple[6] = encodeString(Integer.toString(atttypmod != -1					? atttypmod - VARHDRSZ					: 0));			}			else if(pgType.equals("numeric") || pgType.equals("decimal"))			{				int attypmod = rs.getInt("atttypmod") - VARHDRSZ;				tuple[6] = encodeString(Integer					.toString((attypmod >> 16) & 0xffff));				tuple[8] = encodeString(Integer.toString(attypmod & 0xffff));				tuple[9] = encodeString("10");			}			else if(pgType.equals("bit") || pgType.equals("varbit"))			{				tuple[6] = rs.getBytes("atttypmod");				tuple[9] = encodeString("2");			}			else			{				tuple[6] = rs.getBytes("attlen");				tuple[9] = encodeString("10");			}			tuple[7] = null; // Buffer length			tuple[10] = encodeString(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] = encodeString(rs.getBoolean("attnotnull") ? "NO" : "YES"); // Is																					// nullable			v.add(tuple);		}		rs.close();		return createSyntheticResultSet(f, v);	}