]> granicus.if.org Git - postgresql/commitdiff
accept url and fk action fix from Kris Jurka
authorDave Cramer <davec@fastcrypt.com>
Mon, 3 Nov 2003 15:22:07 +0000 (15:22 +0000)
committerDave Cramer <davec@fastcrypt.com>
Mon, 3 Nov 2003 15:22:07 +0000 (15:22 +0000)
src/interfaces/jdbc/org/postgresql/Driver.java.in
src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
src/interfaces/jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
src/interfaces/jdbc/org/postgresql/test/jdbc2/DriverTest.java

index 7c1436b8128d1d032c0b82ee2c18cf175d3a6f11..e515417c36e8dbc734af07ea22bca78781cf8642 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright (c) 2003, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/Driver.java.in,v 1.36 2003/09/13 04:02:12 barry Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/Driver.java.in,v 1.37 2003/11/03 15:22:06 davec Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -111,7 +111,7 @@ public class Driver implements java.sql.Driver
         *
         * Our protocol takes the forms:
         * <PRE>
-        *      jdbc:org.postgresql://host:port/database?param1=val1&...
+        *      jdbc:postgresql://host:port/database?param1=val1&...
         * </PRE>
         *
         * @param url the URL of the database to connect to
@@ -163,7 +163,7 @@ public class Driver implements java.sql.Driver
         * Returns true if the driver thinks it can open a connection to the
         * given URL.  Typically, drivers will return true if they understand
         * the subprotocol specified in the URL and false if they don't.  Our
-        * protocols start with jdbc:org.postgresql:
+        * protocols start with jdbc:postgresql:
         *
         * @see java.sql.Driver#acceptsURL
         * @param url the URL of the driver
@@ -286,7 +286,8 @@ public class Driver implements java.sql.Driver
 
                //parse the server part of the url
                StringTokenizer st = new StringTokenizer(l_urlServer, ":/", true);
-               for (int count = 0; (st.hasMoreTokens()); count++)
+               int count;
+               for (count = 0; (st.hasMoreTokens()); count++)
                {
                        String token = st.nextToken();
 
@@ -357,6 +358,9 @@ public class Driver implements java.sql.Driver
                                }
                        }
                }
+               if (count <= 1) {
+                       return null;
+               }
 
                // if we extracted an IPv6 address out earlier put it back
                if (ipv6address != null)
@@ -364,7 +368,7 @@ public class Driver implements java.sql.Driver
 
                //parse the args part of the url
                StringTokenizer qst = new StringTokenizer(l_urlArgs, "&");
-               for (int count = 0; (qst.hasMoreTokens()); count++)
+               for (count = 0; (qst.hasMoreTokens()); count++)
                {
                        String token = qst.nextToken();
                        int l_pos = token.indexOf('=');
index 7dbcad2e4d55f0333b5808ab985e2a6235521570..0ded6e608b875f6e2dec9a776bfff64b9152a316 100644 (file)
@@ -3114,7 +3114,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
                        if ( deleteRule != null )
                        {
 
-                               String rule = updateRule.substring(8, updateRule.length() - 4);
+                               String rule = deleteRule.substring(8, deleteRule.length() - 4);
 
                                int action = java.sql.DatabaseMetaData.importedKeyNoAction;
                                if ("cascade".equals(rule))
@@ -3123,6 +3123,8 @@ public abstract class AbstractJdbc1DatabaseMetaData
                                        action = java.sql.DatabaseMetaData.importedKeySetNull;
                                else if ("setdefault".equals(rule))
                                        action = java.sql.DatabaseMetaData.importedKeySetDefault;
+                               else if ("restrict".equals(rule))
+                                       action = java.sql.DatabaseMetaData.importedKeyRestrict;
                                tuple[10] = Integer.toString(action).getBytes();
                        }
 
index eb7df0cd492105e0d73d8b0ba885ffa6f515d4d9..735b971d65c68f016aa0d3b2982aa5687815dd45 100644 (file)
@@ -9,7 +9,7 @@
  * Copyright (c) 2003, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.22 2003/10/29 02:39:09 davec Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.23 2003/11/03 15:22:07 davec Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -210,8 +210,8 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
        public byte getByte(int columnIndex) throws SQLException
        {
                String s = getString(columnIndex);
-
-               if (s != null)
+               
+               if (s != null )
                {
                        try
                        {
@@ -232,6 +232,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                                                s = s.trim();
                                                break;
                                }
+                               if ( s.length() == 0 ) return 0;
                                return Byte.parseByte(s);
                        }
                        catch (NumberFormatException e)
index 4dc8a656a35688e81729e45c662d522d8f296958..0e7ab5862be90804de3108b32134a931691a8708 100644 (file)
@@ -9,7 +9,7 @@ import java.sql.*;
  *
  * PS: Do you know how difficult it is to type on a train? ;-)
  *
- * $Id: DatabaseMetaDataTest.java,v 1.18 2003/05/29 04:39:48 barry Exp $
+ * $Id: DatabaseMetaDataTest.java,v 1.19 2003/11/03 15:22:07 davec Exp $
  */
 
 public class DatabaseMetaDataTest extends TestCase
@@ -137,6 +137,38 @@ public class DatabaseMetaDataTest extends TestCase
                        fail(ex.getMessage());
                }
        }
+
+       public void testForeignKeyActions()
+       {
+               try {
+                       Connection conn = TestUtil.openDB();
+                       TestUtil.createTable(conn, "pkt", "id int primary key");
+                       TestUtil.createTable(conn, "fkt1", "id int references pkt on update restrict on delete cascade");
+                       TestUtil.createTable(conn, "fkt2", "id int references pkt on update set null on delete set default");
+                       DatabaseMetaData dbmd = conn.getMetaData();
+
+                       ResultSet rs = dbmd.getImportedKeys(null,"","fkt1");
+                       assertTrue(rs.next());
+                       assertTrue(rs.getInt("UPDATE_RULE") == DatabaseMetaData.importedKeyRestrict);
+                       assertTrue(rs.getInt("DELETE_RULE") == DatabaseMetaData.importedKeyCascade);
+                       rs.close();
+
+                       rs = dbmd.getImportedKeys(null,"","fkt2");
+                       assertTrue(rs.next());
+                       assertTrue(rs.getInt("UPDATE_RULE") == DatabaseMetaData.importedKeySetNull);
+                       assertTrue(rs.getInt("DELETE_RULE") == DatabaseMetaData.importedKeySetDefault);
+                       rs.close();
+
+                       TestUtil.dropTable(conn,"fkt2");
+                       TestUtil.dropTable(conn,"fkt1");
+                       TestUtil.dropTable(conn,"pkt");
+               }
+               catch (SQLException ex)
+               {
+                       fail(ex.getMessage());
+               }
+       }
+
        public void testForeignKeys()
        {
                try
index d8e0ca56ef464cd4501918748c9044842bfa919f..0c999eb21b1b46a7d46486baa7ce9e010d26cbb9 100644 (file)
@@ -5,7 +5,7 @@ import junit.framework.TestCase;
 import java.sql.*;
 
 /*
- * $Id: DriverTest.java,v 1.5 2002/08/14 20:35:40 barry Exp $
+ * $Id: DriverTest.java,v 1.6 2003/11/03 15:22:07 davec Exp $
  *
  * Tests the dynamically created class org.postgresql.Driver
  *
@@ -37,10 +37,12 @@ public class DriverTest extends TestCase
                        assertTrue(drv.acceptsURL("jdbc:postgresql://localhost:5432/test"));
                        assertTrue(drv.acceptsURL("jdbc:postgresql://127.0.0.1/anydbname"));
                        assertTrue(drv.acceptsURL("jdbc:postgresql://127.0.0.1:5433/hidden"));
+                       assertTrue(drv.acceptsURL("jdbc:postgresql://[::1]:5740/db"));
 
                        // Badly formatted url's
                        assertTrue(!drv.acceptsURL("jdbc:postgres:test"));
                        assertTrue(!drv.acceptsURL("postgresql:test"));
+                       assertTrue(!drv.acceptsURL("db"));
 
                }
                catch (SQLException ex)