You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2005/10/07 00:28:56 UTC

svn commit: r306942 - in /db/derby/code/branches/10.1/java: client/org/apache/derby/client/net/ client/org/apache/derby/jdbc/ drda/org/apache/derby/impl/drda/ testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ testing/org/apache/derby...

Author: kmarsden
Date: Thu Oct  6 15:28:44 2005
New Revision: 306942

URL: http://svn.apache.org/viewcvs?rev=306942&view=rev
Log:
DERBY-374
Invalid URL with Derby Client when connecting to Network Server causes protocol exception.
merged from trunk with
svn merge -r 292916:292917 https://svn.apache.org/repos/asf/db/derby/code/trunk

Contributed by Deepa Remesh



Modified:
    db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/NetConnection.java
    db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/NetConnectionReply.java
    db/derby/code/branches/10.1/java/client/org/apache/derby/jdbc/ClientDriver.java
    db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/Database.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDriver.out
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java

Modified: db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/NetConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/NetConnection.java?rev=306942&r1=306941&r2=306942&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/NetConnection.java (original)
+++ db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/NetConnection.java Thu Oct  6 15:28:44 2005
@@ -128,6 +128,13 @@
 
     // stored the password for deferred reset only.
     private transient char[] deferredResetPassword_ = null;
+    
+    //If Network Server gets null connection from the embedded driver, 
+    //it sends RDBAFLRM followed by SQLCARD with null SQLException.
+    //Client will parse the SQLCARD and set connectionNull to true if the
+    //SQLCARD is empty. If connectionNull=true, connect method in 
+    //ClientDriver will in turn return null connection.
+    private boolean connectionNull = false;
 
     private void setDeferredResetPassword(String password) {
         deferredResetPassword_ = (password == null) ? null : flipBits(password.toCharArray());
@@ -186,7 +193,8 @@
         String password = ClientDataSource.getPassword(properties);
         securityMechanism_ = ClientDataSource.getSecurityMechanism(properties);
         flowConnect(password, securityMechanism_);
-        completeConnect();
+        if(!isConnectionNull())
+        	completeConnect();
     }
 
     // For JDBC 2 Connections
@@ -1502,5 +1510,18 @@
         agent_.flowOutsideUOW();
         agent_.endReadChain();
     }
+    
+	/**
+	 * @return Returns the connectionNull.
+	 */
+	public boolean isConnectionNull() {
+		return connectionNull;
+	}
+	/**
+	 * @param connectionNull The connectionNull to set.
+	 */
+	public void setConnectionNull(boolean connectionNull) {
+		this.connectionNull = connectionNull;
+	}
 }
 

Modified: db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/NetConnectionReply.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/NetConnectionReply.java?rev=306942&r1=306941&r2=306942&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/NetConnectionReply.java (original)
+++ db/derby/code/branches/10.1/java/client/org/apache/derby/client/net/NetConnectionReply.java Thu Oct  6 15:28:44 2005
@@ -485,7 +485,12 @@
         }
 
         NetSqlca netSqlca = parseSQLCARD(null);
-        netConnection.completeSqlca(netSqlca);
+        
+        //Check if the SQLCARD has null SQLException
+        if(netSqlca.getSqlErrmc() == null)
+        	netConnection.setConnectionNull(true);
+        else
+        	netConnection.completeSqlca(netSqlca);
     }
 
 

Modified: db/derby/code/branches/10.1/java/client/org/apache/derby/jdbc/ClientDriver.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/client/org/apache/derby/jdbc/ClientDriver.java?rev=306942&r1=306941&r2=306942&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/client/org/apache/derby/jdbc/ClientDriver.java (original)
+++ db/derby/code/branches/10.1/java/client/org/apache/derby/jdbc/ClientDriver.java Thu Oct  6 15:28:44 2005
@@ -129,6 +129,10 @@
                         port,
                         database,
                         augmentedProperties);
+        
+        if(conn.isConnectionNull())
+        	return null;
+        
         return conn;
     }
 

Modified: db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=306942&r1=306941&r2=306942&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Thu Oct  6 15:28:44 2005
@@ -973,6 +973,13 @@
 		verifyRequiredObject(codePoint,CodePoint.ACCRDB);
 		int svrcod = parseACCRDB();
 
+		//If network server gets a null connection form InternalDriver, reply with
+		//RDBAFLRM and SQLCARD with null SQLException 
+		if(database.getConnection() == null && databaseAccessException == null){
+			writeRDBfailure(CodePoint.RDBAFLRM);
+			return false;
+		}		
+		
 		//if earlier we couldn't access the database
 		if (databaseAccessException != null)
 		{
@@ -983,43 +990,16 @@
 				|| failureType == CodePoint.RDBATHRM)
 			{
 				writeRDBfailure(failureType);
-				writeSQLCARD(databaseAccessException,
-					CodePoint.SVRCOD_ERROR,0,0);
 			}
 			else
 			{
 				writeRDBfailure(CodePoint.RDBAFLRM);
-
-				// RDBAFLRM requires TYPDEFNAM and TYPDEFOVR
-				writer.createDssObject();
-				writer.writeScalarString(CodePoint.TYPDEFNAM,
-										 CodePoint.TYPDEFNAM_QTDSQLASC);
-				writeTYPDEFOVR();
-				writer.endDss();
-
-				// Finally, per DDM spec, "an SQLCARD always follows
-				// the RDBAFLRM".
-				writeSQLCARD(databaseAccessException,
-							 CodePoint.SVRCOD_ERROR,0,0);
 			}
-
-			// Ignore anything that was chained to the ACCRDB.
-			skipRemainder(false);
-
-			// Finalize chain state for whatever we wrote in
-			// response to ACCRDB.
-			finalizeChain();
 			return false;
 		}
 		else if (database.accessCount > 1 )	// already in conversation with database
 		{
 			writeRDBfailure(CodePoint.RDBACCRM);
-
-			// Ignore anything that was chained to the ACCRDB.
-			skipRemainder(false);
-
-			// Finalize chain state for RDBACCRM
-			finalizeChain();
 			return false;
 		}
 		else // everything is fine 
@@ -1049,7 +1029,28 @@
 		writer.writeScalar2Bytes(CodePoint.SVRCOD, CodePoint.SVRCOD_ERROR);
 		writeRDBNAM(database.dbName);
     	writer.endDdmAndDss();
-
+    	
+    	switch(codePoint){
+    		case CodePoint.RDBAFLRM:
+    			//RDBAFLRM requires TYPDEFNAM and TYPDEFOVR
+    			writer.createDssObject();
+    			writer.writeScalarString(CodePoint.TYPDEFNAM,
+    									 CodePoint.TYPDEFNAM_QTDSQLASC);
+    			writeTYPDEFOVR();
+    			writer.endDss();
+    		case CodePoint.RDBNFNRM:
+    		case CodePoint.RDBATHRM:
+    			writeSQLCARD(databaseAccessException,CodePoint.SVRCOD_ERROR,0,0);
+    		case CodePoint.RDBACCRM:
+    			//Ignore anything that was chained to the ACCRDB.
+    			skipRemainder(false);
+
+    			// Finalize chain state for whatever we wrote in
+    			// response to ACCRDB.
+    			finalizeChain();
+    			break;
+    	}
+    	
 	}
 
 	/* Check the database access exception and return the appropriate

Modified: db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/Database.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/Database.java?rev=306942&r1=306941&r2=306942&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/Database.java (original)
+++ db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/Database.java Thu Oct  6 15:28:44 2005
@@ -116,7 +116,8 @@
 		throws SQLException
 	{
 		this.conn = conn;
-		defaultStatement.setStatement(conn);
+		if(conn != null)
+			defaultStatement.setStatement(conn);
 	}
 	/**
 	 * Get the connection
@@ -245,9 +246,11 @@
                 // take care of case of SECMEC_USRIDONL
                 if(password != null) 
 		    p.put(Attribute.PASSWORD_ATTR, password);
-		Connection conn = NetworkServerControlImpl.getDriver().connect(Attribute.PROTOCOL
-							 + dbName + attrString, p);
-		conn.setAutoCommit(false);
+        Connection conn = NetworkServerControlImpl.getDriver().connect(Attribute.PROTOCOL
+							 + shortDbName + attrString, p);
+		if(conn != null){
+			conn.setAutoCommit(false);
+		}
 		setConnection(conn);
 		return conn;
 	}

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDriver.out
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDriver.out?rev=306942&r1=306941&r2=306942&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDriver.out (original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/checkDriver.out Thu Oct  6 15:28:44 2005
@@ -42,3 +42,20 @@
 getUserName() = APP
 CURRENT SCHEMA = APP
  trace file exists
+doClientURLTest()
+doClientURLTest with url: jdbc:derby://localhost:1527/wombat:create=true
+Null connection returned for url jdbc:derby://localhost:1527/wombat:create=true
+doClientURLTest with url: jdbc:derby://localhost:1527/[DERBY_SYSTEM_HOME]/wombat:create=true
+EXPECTED EXCEPTION:DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ040, SQLERRMC: Failed to start database '[DERBY_SYSTEM_HOME]/wombat:create=true', see the next exception for details.::SQLSTATE: XJ001Java exception: 'The filename, directory name, or volume label syntax is incorrect: java.io.IOException'.
+doClientURLTest with url: jdbc:derby://localhost:1527/"wombat";create=true
+EXPECTED EXCEPTION:DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ041, SQLERRMC: Failed to create database '"wombat"', see the next exception for details.::SQLSTATE: XBM0HDirectory [DERBY_SYSTEM_HOME]/"wombat" cannot be created.
+doClientURLTest with url: jdbc:derby://localhost:1527/"[DERBY_SYSTEM_HOME]/wombat";create=true
+Null connection returned for url jdbc:derby://localhost:1527/"[DERBY_SYSTEM_HOME]/wombat";create=true
+doClientURLTest with url: jdbc:derby://localhost:1527/'[DERBY_SYSTEM_HOME]/wombat';create=true
+Null connection returned for url jdbc:derby://localhost:1527/'[DERBY_SYSTEM_HOME]/wombat';create=true
+doClientURLTest with url: jdbc:derby://localhost:1527/'wombat';create=true
+Connection info for connect(jdbc:derby://localhost:1527/'wombat';create=true, null)
+getURL() = jdbc:derby://localhost:1527/'wombat';create=true
+getUserName() = APP
+CURRENT SCHEMA = APP
+PASSED:Connection Successful with url: jdbc:derby://localhost:1527/'wombat';create=true

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java?rev=306942&r1=306941&r2=306942&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java (original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDriver.java Thu Oct  6 15:28:44 2005
@@ -49,6 +49,19 @@
 	
 	private static String DERBY_SYSTEM_HOME = System.getProperty("derby.system.home");
 	
+	private static String CLIENT_URL_WITH_COLON1 = 
+		"jdbc:derby://localhost:1527/wombat:create=true";
+	private static String CLIENT_URL_WITH_COLON2 = 
+		"jdbc:derby://localhost:1527/"+ DERBY_SYSTEM_HOME + File.separator +"wombat:create=true";
+	private static String CLIENT_URL_WITH_DOUBLE_QUOTES1 = 
+		"jdbc:derby://localhost:1527/\"wombat\";create=true"; 
+	private static String CLIENT_URL_WITH_DOUBLE_QUOTES2 = 
+		"jdbc:derby://localhost:1527/\"" + DERBY_SYSTEM_HOME + File.separator + "wombat\";create=true";
+	private static String CLIENT_URL_WITH_SINGLE_QUOTES1 = 
+		"jdbc:derby://localhost:1527/'" + DERBY_SYSTEM_HOME + File.separator + "wombat';create=true";
+	private static String CLIENT_URL_WITH_SINGLE_QUOTES2 = 
+		"jdbc:derby://localhost:1527/'wombat';create=true";
+	
 	// URLS to check.  New urls need to also be added to the acceptsUrl table
 	private static String[] urls = new String[]
 	{
@@ -58,6 +71,16 @@
 		INVALID_URL,
 	};
 	
+	//Client URLS
+	private static String[] clientUrls = new String[]
+	{
+		CLIENT_URL_WITH_COLON1,
+		CLIENT_URL_WITH_COLON2,
+		CLIENT_URL_WITH_DOUBLE_QUOTES1,
+		CLIENT_URL_WITH_DOUBLE_QUOTES2,
+		CLIENT_URL_WITH_SINGLE_QUOTES1,
+		CLIENT_URL_WITH_SINGLE_QUOTES2
+	};
 	
 	/**
 	 * url prefix for this framework
@@ -102,6 +125,7 @@
 			checkAcceptsURL(driver);
 			testEmbeddedAttributes(driver);
 			testClientAttributes(driver);
+			doClientURLTest(driver);
 		}
 		catch (SQLException se)
 		{
@@ -321,6 +345,34 @@
 	}
 	
 	/**
+	 * Tests client URLs to see connection is successful or the correct exception is thrown.
+	 * 
+	 * @param driver
+	 * @throws SQLException
+	 */
+	private static void doClientURLTest(Driver driver){
+		if (!TestUtil.isDerbyNetClientFramework())
+			return;
+		
+		System.out.println("doClientURLTest()");
+		Properties info = null;		//test with null Properties object
+
+		for (int i = 0; i < clientUrls.length;i++)
+		{
+			String url = clientUrls[i];
+			System.out.println("doClientURLTest with url: " + replaceSystemHome(url));
+			try{
+				Connection conn = testConnect(driver,url,info);
+				if(conn != null)
+					System.out.println("PASSED:Connection Successful with url: " + replaceSystemHome(url) );
+			}
+			catch(SQLException se){
+				System.out.println("EXPECTED EXCEPTION:"+replaceSystemHome(se.getMessage()));
+			}
+		}
+	}	
+	
+	/**
 	 * Make  java.sql.Driver.connect(String url, Properties info call) and print the status of
 	 * the connection.
 	 * 
@@ -330,7 +382,7 @@
 	 * 
 	 * @throws SQLException on error.
 	 */
-	private static void testConnect(Driver driver, String url, Properties info) throws SQLException
+	private static Connection testConnect(Driver driver, String url, Properties info) throws SQLException
 	{
 		String infoString = null;
 		if (info != null)
@@ -338,6 +390,11 @@
 		String urlString = replaceSystemHome(url);
 		Connection conn = driver.connect(url,info);
 		
+		if(conn == null){
+			System.out.println("Null connection returned for url "+urlString);
+			return conn;
+		}
+		
 		System.out.println("\nConnection info for connect(" + urlString + ", " + infoString +")");
 		String getUrlValue = conn.getMetaData().getURL();
 		// URL may include path of DERBY_SYSTEM_HOME for traceFile
@@ -350,7 +407,7 @@
 		rs.next();
 		System.out.println("CURRENT SCHEMA = " + rs.getString(1));
 		conn.close();
-
+		return conn;
 	}