Commit 0b88b637 authored by Barry Lind's avatar Barry Lind

Applied patches from Kris Jurka fixing a string tokenizing problem and

fixing an order by problem for index metadata results.
Also includes removing some unused code as well as a fix to the toString
method on statement.

 Modified Files:
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
parent 26b237ff
...@@ -3143,26 +3143,23 @@ public abstract class AbstractJdbc1DatabaseMetaData ...@@ -3143,26 +3143,23 @@ public abstract class AbstractJdbc1DatabaseMetaData
//<unnamed>\000ww\000vv\000UNSPECIFIED\000m\000a\000n\000b\000 //<unnamed>\000ww\000vv\000UNSPECIFIED\000m\000a\000n\000b\000
// we are primarily interested in the column names which are the last items in the string // we are primarily interested in the column names which are the last items in the string
StringTokenizer st = new StringTokenizer(targs, "\\000"); Vector tokens = tokenize(targs, "\\000");
if (st.hasMoreTokens()) { if (tokens.size() > 0) {
fkName = st.nextToken(); fkName = (String)tokens.elementAt(0);
} }
if (fkName.startsWith("<unnamed>")) { if (fkName.startsWith("<unnamed>")) {
fkName = targs; fkName = targs;
} }
int advance = 4 + (keySequence - 1) * 2; int element = 4 + (keySequence - 1) * 2;
for ( int i = 1; st.hasMoreTokens() && i < advance ; i++ ) if (tokens.size() > element) {
st.nextToken(); // advance to the key column of interest fkeyColumn = (String)tokens.elementAt(element);
if ( st.hasMoreTokens() )
{
fkeyColumn = st.nextToken();
} }
if ( st.hasMoreTokens() )
{ element++;
pkeyColumn = st.nextToken(); if (tokens.size() > element) {
pkeyColumn = (String)tokens.elementAt(element);
} }
tuple[3] = pkeyColumn.getBytes(); //PKCOLUMN_NAME tuple[3] = pkeyColumn.getBytes(); //PKCOLUMN_NAME
...@@ -3568,8 +3565,33 @@ public abstract class AbstractJdbc1DatabaseMetaData ...@@ -3568,8 +3565,33 @@ public abstract class AbstractJdbc1DatabaseMetaData
if (unique) { if (unique) {
sql += " AND i.indisunique "; sql += " AND i.indisunique ";
} }
sql += " ORDER BY NON_UNIQUE, TYPE, INDEX_NAME "; sql += " ORDER BY NON_UNIQUE, TYPE, INDEX_NAME, ORDINAL_POSITION ";
return connection.createStatement().executeQuery(sql); return connection.createStatement().executeQuery(sql);
} }
/**
* Tokenize based on words not on single characters.
*/
private static Vector tokenize(String input, String delimiter) {
Vector result = new Vector();
int start = 0;
int end = input.length();
int delimiterSize = delimiter.length();
while (start < end) {
int delimiterIndex = input.indexOf(delimiter,start);
if (delimiterIndex < 0) {
result.addElement(input.substring(start));
break;
} else {
String token = input.substring(start,delimiterIndex);
result.addElement(token);
start = delimiterIndex + delimiterSize;
}
}
return result;
}
} }
...@@ -13,7 +13,7 @@ import org.postgresql.core.QueryExecutor; ...@@ -13,7 +13,7 @@ import org.postgresql.core.QueryExecutor;
import org.postgresql.largeobject.*; import org.postgresql.largeobject.*;
import org.postgresql.util.*; import org.postgresql.util.*;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.19 2003/04/13 04:10:07 barry Exp $ /* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.20 2003/04/17 04:37:07 barry Exp $
* This class defines methods of the jdbc1 specification. This class is * This class defines methods of the jdbc1 specification. This class is
* extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2 * extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
* methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement * methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
...@@ -1512,35 +1512,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement ...@@ -1512,35 +1512,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
{ {
if (x == null) if (x == null)
{ {
int l_sqlType; setNull(parameterIndex, Types.OTHER);
if (x instanceof String)
l_sqlType = Types.VARCHAR;
else if (x instanceof BigDecimal)
l_sqlType = Types.DECIMAL;
else if (x instanceof Short)
l_sqlType = Types.SMALLINT;
else if (x instanceof Integer)
l_sqlType = Types.INTEGER;
else if (x instanceof Long)
l_sqlType = Types.BIGINT;
else if (x instanceof Float)
l_sqlType = Types.FLOAT;
else if (x instanceof Double)
l_sqlType = Types.DOUBLE;
else if (x instanceof byte[])
l_sqlType = Types.BINARY;
else if (x instanceof java.sql.Date)
l_sqlType = Types.DATE;
else if (x instanceof Time)
l_sqlType = Types.TIME;
else if (x instanceof Timestamp)
l_sqlType = Types.TIMESTAMP;
else if (x instanceof Boolean)
l_sqlType = Types.OTHER;
else
l_sqlType = Types.OTHER;
setNull(parameterIndex, l_sqlType);
return ; return ;
} }
if (x instanceof String) if (x instanceof String)
...@@ -1879,7 +1851,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement ...@@ -1879,7 +1851,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
public String toString() public String toString()
{ {
if (m_sqlFragments == null) if (m_sqlFragments == null)
return ""; return super.toString();
synchronized (sbuf) synchronized (sbuf)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment