Skip to content

Commit 0b88b63

Browse files
author
Barry Lind
committed
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
1 parent 26b237f commit 0b88b63

File tree

2 files changed

+39
-45
lines changed

2 files changed

+39
-45
lines changed

src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3143,26 +3143,23 @@ else if ("setdefault".equals(rule))
31433143
//<unnamed>\000ww\000vv\000UNSPECIFIED\000m\000a\000n\000b\000
31443144
// we are primarily interested in the column names which are the last items in the string
31453145

3146-
StringTokenizer st = new StringTokenizer(targs, "\\000");
3147-
if (st.hasMoreTokens()) {
3148-
fkName = st.nextToken();
3146+
Vector tokens = tokenize(targs, "\\000");
3147+
if (tokens.size() > 0) {
3148+
fkName = (String)tokens.elementAt(0);
31493149
}
31503150

31513151
if (fkName.startsWith("<unnamed>")) {
31523152
fkName = targs;
31533153
}
31543154

3155-
int advance = 4 + (keySequence - 1) * 2;
3156-
for ( int i = 1; st.hasMoreTokens() && i < advance ; i++ )
3157-
st.nextToken(); // advance to the key column of interest
3158-
3159-
if ( st.hasMoreTokens() )
3160-
{
3161-
fkeyColumn = st.nextToken();
3155+
int element = 4 + (keySequence - 1) * 2;
3156+
if (tokens.size() > element) {
3157+
fkeyColumn = (String)tokens.elementAt(element);
31623158
}
3163-
if ( st.hasMoreTokens() )
3164-
{
3165-
pkeyColumn = st.nextToken();
3159+
3160+
element++;
3161+
if (tokens.size() > element) {
3162+
pkeyColumn = (String)tokens.elementAt(element);
31663163
}
31673164

31683165
tuple[3] = pkeyColumn.getBytes(); //PKCOLUMN_NAME
@@ -3568,8 +3565,33 @@ public java.sql.ResultSet getIndexInfo(String catalog, String schema, String tab
35683565
if (unique) {
35693566
sql += " AND i.indisunique ";
35703567
}
3571-
sql += " ORDER BY NON_UNIQUE, TYPE, INDEX_NAME ";
3568+
sql += " ORDER BY NON_UNIQUE, TYPE, INDEX_NAME, ORDINAL_POSITION ";
35723569
return connection.createStatement().executeQuery(sql);
35733570
}
35743571

3572+
/**
3573+
* Tokenize based on words not on single characters.
3574+
*/
3575+
private static Vector tokenize(String input, String delimiter) {
3576+
Vector result = new Vector();
3577+
int start = 0;
3578+
int end = input.length();
3579+
int delimiterSize = delimiter.length();
3580+
3581+
while (start < end) {
3582+
int delimiterIndex = input.indexOf(delimiter,start);
3583+
if (delimiterIndex < 0) {
3584+
result.addElement(input.substring(start));
3585+
break;
3586+
} else {
3587+
String token = input.substring(start,delimiterIndex);
3588+
result.addElement(token);
3589+
start = delimiterIndex + delimiterSize;
3590+
}
3591+
}
3592+
return result;
3593+
}
3594+
3595+
3596+
35753597
}

src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.postgresql.largeobject.*;
1414
import org.postgresql.util.*;
1515

16-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.19 2003/04/13 04:10:07 barry Exp $
16+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.20 2003/04/17 04:37:07 barry Exp $
1717
* This class defines methods of the jdbc1 specification. This class is
1818
* extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
1919
* methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
@@ -1512,35 +1512,7 @@ public void setObject(int parameterIndex, Object x) throws SQLException
15121512
{
15131513
if (x == null)
15141514
{
1515-
int l_sqlType;
1516-
if (x instanceof String)
1517-
l_sqlType = Types.VARCHAR;
1518-
else if (x instanceof BigDecimal)
1519-
l_sqlType = Types.DECIMAL;
1520-
else if (x instanceof Short)
1521-
l_sqlType = Types.SMALLINT;
1522-
else if (x instanceof Integer)
1523-
l_sqlType = Types.INTEGER;
1524-
else if (x instanceof Long)
1525-
l_sqlType = Types.BIGINT;
1526-
else if (x instanceof Float)
1527-
l_sqlType = Types.FLOAT;
1528-
else if (x instanceof Double)
1529-
l_sqlType = Types.DOUBLE;
1530-
else if (x instanceof byte[])
1531-
l_sqlType = Types.BINARY;
1532-
else if (x instanceof java.sql.Date)
1533-
l_sqlType = Types.DATE;
1534-
else if (x instanceof Time)
1535-
l_sqlType = Types.TIME;
1536-
else if (x instanceof Timestamp)
1537-
l_sqlType = Types.TIMESTAMP;
1538-
else if (x instanceof Boolean)
1539-
l_sqlType = Types.OTHER;
1540-
else
1541-
l_sqlType = Types.OTHER;
1542-
1543-
setNull(parameterIndex, l_sqlType);
1515+
setNull(parameterIndex, Types.OTHER);
15441516
return ;
15451517
}
15461518
if (x instanceof String)
@@ -1879,7 +1851,7 @@ public int getResultSetConcurrency() throws SQLException
18791851
public String toString()
18801852
{
18811853
if (m_sqlFragments == null)
1882-
return "";
1854+
return super.toString();
18831855

18841856
synchronized (sbuf)
18851857
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy