Index: AbstractJdbc2ResultSet.java =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v retrieving revision 1.14 diff -c -r1.14 AbstractJdbc2ResultSet.java *** AbstractJdbc2ResultSet.java 2003/02/27 05:56:27 1.14 --- AbstractJdbc2ResultSet.java 2003/03/01 00:21:39 *************** *** 1318,1335 **** else { // otherwise go and get the primary keys and create a hashtable of keys ! // if the user has supplied a quoted table name ! // remove the quotes, but preserve the case. ! // otherwise fold to lower case. ! String quotelessTableName; ! if (tableName.startsWith("\"") && tableName.endsWith("\"")) { ! quotelessTableName = tableName.substring(1,tableName.length()-1); ! } else { ! quotelessTableName = tableName.toLowerCase(); ! } ! java.sql.ResultSet rs = ((java.sql.Connection) connection).getMetaData().getPrimaryKeys("", "", quotelessTableName); ! ! for (; rs.next(); i++ ) { String columnName = rs.getString(4); // get the columnName --- 1318,1327 ---- else { // otherwise go and get the primary keys and create a hashtable of keys ! String[] s = quotelessTableName(tableName); ! String quotelessTableName = s[0]; ! String quotelessSchemaName = s[1]; ! java.sql.ResultSet rs = ((java.sql.Connection) connection).getMetaData().getPrimaryKeys("", quotelessSchemaName, quotelessTableName); for (; rs.next(); i++ ) { String columnName = rs.getString(4); // get the columnName *************** *** 1361,1368 **** return updateable; } - public void parseQuery() { String[] l_sqlFragments = ((AbstractJdbc2Statement)statement).getSqlFragments(); --- 1353,1409 ---- return updateable; } + /** Cracks out the table name and schema (if it exists) from a fully + * qualified table name. + * @param fullname string that we are trying to crack. Test cases:
+ 	 * Table: table ()
+ 	 * "Table": Table ()
+ 	 * Schema.Table: table (schema)
+ 	 * "Schema"."Table": Table (Schema)
+ 	 * "Schema"."Dot.Table": Dot.Table (Schema)
+ 	 * Schema."Dot.Table": Dot.Table (schema)
+ 	 * 
+ * @return String array with element zero always being the tablename and + * element 1 the schema name which may be a zero length string. + */ + public static String[] quotelessTableName(String fullname) { + StringBuffer buf = new StringBuffer(fullname); + String[] parts = new String[] {null, ""}; + StringBuffer acc = new StringBuffer(); + boolean betweenQuotes = false; + for (int i = 0; i < buf.length(); i++) { + char c = buf.charAt(i); + switch (c) { + case '"': + if ((i < buf.length() - 1) && (buf.charAt(i+1) == '"')) { + // two consecutive quotes - keep one + i++; + acc.append(c); // keep the quote + } + else { // Discard it + betweenQuotes = !betweenQuotes; + } + break; + case '.': + if (betweenQuotes) { // Keep it + acc.append(c); + } + else { // Have schema name + parts[1] = acc.toString(); + acc = new StringBuffer(); + } + break; + default: + acc.append((betweenQuotes) ? c : Character.toLowerCase(c)); + break; + } + } + // Always put table in slot 0 + parts[0] = acc.toString(); + return parts; + } + public void parseQuery() { String[] l_sqlFragments = ((AbstractJdbc2Statement)statement).getSqlFragments();