Skip to content

Commit efea5da

Browse files
author
Dave Cramer
committed
accept url and fk action fix from Kris Jurka
1 parent 90e53f0 commit efea5da

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

src/interfaces/jdbc/org/postgresql/Driver.java.in

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2003, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/Driver.java.in,v 1.36 2003/09/13 04:02:12 barry Exp $
9+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/Driver.java.in,v 1.37 2003/11/03 15:22:06 davec Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -111,7 +111,7 @@ public class Driver implements java.sql.Driver
111111
*
112112
* Our protocol takes the forms:
113113
* <PRE>
114-
* jdbc:org.postgresql://host:port/database?param1=val1&...
114+
* jdbc:postgresql://host:port/database?param1=val1&...
115115
* </PRE>
116116
*
117117
* @param url the URL of the database to connect to
@@ -163,7 +163,7 @@ public class Driver implements java.sql.Driver
163163
* Returns true if the driver thinks it can open a connection to the
164164
* given URL. Typically, drivers will return true if they understand
165165
* the subprotocol specified in the URL and false if they don't. Our
166-
* protocols start with jdbc:org.postgresql:
166+
* protocols start with jdbc:postgresql:
167167
*
168168
* @see java.sql.Driver#acceptsURL
169169
* @param url the URL of the driver
@@ -286,7 +286,8 @@ public class Driver implements java.sql.Driver
286286

287287
//parse the server part of the url
288288
StringTokenizer st = new StringTokenizer(l_urlServer, ":/", true);
289-
for (int count = 0; (st.hasMoreTokens()); count++)
289+
int count;
290+
for (count = 0; (st.hasMoreTokens()); count++)
290291
{
291292
String token = st.nextToken();
292293

@@ -357,14 +358,17 @@ public class Driver implements java.sql.Driver
357358
}
358359
}
359360
}
361+
if (count <= 1) {
362+
return null;
363+
}
360364

361365
// if we extracted an IPv6 address out earlier put it back
362366
if (ipv6address != null)
363367
urlProps.put("PGHOST",ipv6address);
364368

365369
//parse the args part of the url
366370
StringTokenizer qst = new StringTokenizer(l_urlArgs, "&");
367-
for (int count = 0; (qst.hasMoreTokens()); count++)
371+
for (count = 0; (qst.hasMoreTokens()); count++)
368372
{
369373
String token = qst.nextToken();
370374
int l_pos = token.indexOf('=');

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3114,7 +3114,7 @@ else if ("restrict".equals(rule))
31143114
if ( deleteRule != null )
31153115
{
31163116

3117-
String rule = updateRule.substring(8, updateRule.length() - 4);
3117+
String rule = deleteRule.substring(8, deleteRule.length() - 4);
31183118

31193119
int action = java.sql.DatabaseMetaData.importedKeyNoAction;
31203120
if ("cascade".equals(rule))
@@ -3123,6 +3123,8 @@ else if ("setnull".equals(rule))
31233123
action = java.sql.DatabaseMetaData.importedKeySetNull;
31243124
else if ("setdefault".equals(rule))
31253125
action = java.sql.DatabaseMetaData.importedKeySetDefault;
3126+
else if ("restrict".equals(rule))
3127+
action = java.sql.DatabaseMetaData.importedKeyRestrict;
31263128
tuple[10] = Integer.toString(action).getBytes();
31273129
}
31283130

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Copyright (c) 2003, PostgreSQL Global Development Group
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.22 2003/10/29 02:39:09 davec Exp $
12+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.23 2003/11/03 15:22:07 davec Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -210,8 +210,8 @@ public boolean getBoolean(int columnIndex) throws SQLException
210210
public byte getByte(int columnIndex) throws SQLException
211211
{
212212
String s = getString(columnIndex);
213-
214-
if (s != null)
213+
214+
if (s != null )
215215
{
216216
try
217217
{
@@ -232,6 +232,7 @@ public byte getByte(int columnIndex) throws SQLException
232232
s = s.trim();
233233
break;
234234
}
235+
if ( s.length() == 0 ) return 0;
235236
return Byte.parseByte(s);
236237
}
237238
catch (NumberFormatException e)

src/interfaces/jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* PS: Do you know how difficult it is to type on a train? ;-)
1111
*
12-
* $Id: DatabaseMetaDataTest.java,v 1.18 2003/05/29 04:39:48 barry Exp $
12+
* $Id: DatabaseMetaDataTest.java,v 1.19 2003/11/03 15:22:07 davec Exp $
1313
*/
1414

1515
public class DatabaseMetaDataTest extends TestCase
@@ -137,6 +137,38 @@ public void testCrossReference()
137137
fail(ex.getMessage());
138138
}
139139
}
140+
141+
public void testForeignKeyActions()
142+
{
143+
try {
144+
Connection conn = TestUtil.openDB();
145+
TestUtil.createTable(conn, "pkt", "id int primary key");
146+
TestUtil.createTable(conn, "fkt1", "id int references pkt on update restrict on delete cascade");
147+
TestUtil.createTable(conn, "fkt2", "id int references pkt on update set null on delete set default");
148+
DatabaseMetaData dbmd = conn.getMetaData();
149+
150+
ResultSet rs = dbmd.getImportedKeys(null,"","fkt1");
151+
assertTrue(rs.next());
152+
assertTrue(rs.getInt("UPDATE_RULE") == DatabaseMetaData.importedKeyRestrict);
153+
assertTrue(rs.getInt("DELETE_RULE") == DatabaseMetaData.importedKeyCascade);
154+
rs.close();
155+
156+
rs = dbmd.getImportedKeys(null,"","fkt2");
157+
assertTrue(rs.next());
158+
assertTrue(rs.getInt("UPDATE_RULE") == DatabaseMetaData.importedKeySetNull);
159+
assertTrue(rs.getInt("DELETE_RULE") == DatabaseMetaData.importedKeySetDefault);
160+
rs.close();
161+
162+
TestUtil.dropTable(conn,"fkt2");
163+
TestUtil.dropTable(conn,"fkt1");
164+
TestUtil.dropTable(conn,"pkt");
165+
}
166+
catch (SQLException ex)
167+
{
168+
fail(ex.getMessage());
169+
}
170+
}
171+
140172
public void testForeignKeys()
141173
{
142174
try

src/interfaces/jdbc/org/postgresql/test/jdbc2/DriverTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.sql.*;
66

77
/*
8-
* $Id: DriverTest.java,v 1.5 2002/08/14 20:35:40 barry Exp $
8+
* $Id: DriverTest.java,v 1.6 2003/11/03 15:22:07 davec Exp $
99
*
1010
* Tests the dynamically created class org.postgresql.Driver
1111
*
@@ -37,10 +37,12 @@ public void testAcceptsURL()
3737
assertTrue(drv.acceptsURL("jdbc:postgresql://localhost:5432/test"));
3838
assertTrue(drv.acceptsURL("jdbc:postgresql://127.0.0.1/anydbname"));
3939
assertTrue(drv.acceptsURL("jdbc:postgresql://127.0.0.1:5433/hidden"));
40+
assertTrue(drv.acceptsURL("jdbc:postgresql://[::1]:5740/db"));
4041

4142
// Badly formatted url's
4243
assertTrue(!drv.acceptsURL("jdbc:postgres:test"));
4344
assertTrue(!drv.acceptsURL("postgresql:test"));
45+
assertTrue(!drv.acceptsURL("db"));
4446

4547
}
4648
catch (SQLException ex)

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