List:Commits« Previous MessageNext Message »
From:mmatthews Date:March 11 2006 1:18am
Subject:Connector/J commit: r5052 - in branches: branch_3_1/connector-j branch_3_1/connector-j/src/com/mysql/jdbc branch_3_1/connector-j/src/testsuite/regress...
View as plain text  
Added:
   branches/branch_5_0/connector-j/.settings/org.eclipse.jdt.ui.prefs
Modified:
   branches/branch_3_1/connector-j/CHANGES
   branches/branch_3_1/connector-j/src/com/mysql/jdbc/CharsetMapping.java
   branches/branch_3_1/connector-j/src/com/mysql/jdbc/Connection.java
   branches/branch_3_1/connector-j/src/testsuite/regression/StringRegressionTest.java
   branches/branch_5_0/connector-j/CHANGES
   branches/branch_5_0/connector-j/src/com/mysql/jdbc/CharsetMapping.java
   branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java
   branches/branch_5_0/connector-j/src/testsuite/regression/StringRegressionTest.java
   branches/branch_5_1/connector-j/CHANGES
   branches/branch_5_1/connector-j/src/com/mysql/jdbc/CharsetMapping.java
   branches/branch_5_1/connector-j/src/com/mysql/jdbc/Connection.java
   branches/branch_5_1/connector-j/src/testsuite/regression/StringRegressionTest.java
Log:
Map latin1 -> CP1252 on MySQL > 4.1.0.

Modified: branches/branch_3_1/connector-j/CHANGES
===================================================================
--- branches/branch_3_1/connector-j/CHANGES	2006-03-11 01:02:51 UTC (rev 5051)
+++ branches/branch_3_1/connector-j/CHANGES	2006-03-11 01:18:02 UTC (rev 5052)
@@ -73,6 +73,8 @@
 	  
 	- Fixed BUG#17587 - clearParameters() on a closed prepared statement
 	  causes NPE.
+	  
+	- Map "latin1" on MySQL server to CP1252 for MySQL > 4.1.0.
     
 11-30-05 - Version 3.1.12
 

Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/CharsetMapping.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/CharsetMapping.java	2006-03-11 01:02:51 UTC (rev 5051)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/CharsetMapping.java	2006-03-11 01:18:02 UTC (rev 5052)
@@ -115,6 +115,7 @@
 			+ "Cp1251 = 			cp1251csas,"
 			+ "Cp1256 = 			cp1256,"
 	 		+ "Cp1251 = 			win1251ukr,"
+	 		+ "Cp1252 =             latin1,"
 			+ "Cp1257 = 			cp1257,"
 			+ "MacRoman = 			macroman,"
 			+ "MacCentralEurope = 	macce,"
@@ -403,6 +404,12 @@
 
 	final static String getJavaEncodingForMysqlEncoding(String mysqlEncoding,
 			Connection conn) throws SQLException {
+		
+		if (conn != null && conn.versionMeetsMinimum(4, 1, 0) && 
+				"latin1".equalsIgnoreCase(mysqlEncoding)) {
+			return "cp1252";
+		}
+		
 		return (String) MYSQL_TO_JAVA_CHARSET_MAP.get(mysqlEncoding);
 	}
 

Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/Connection.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/Connection.java	2006-03-11 01:02:51 UTC (rev 5051)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/Connection.java	2006-03-11 01:18:02 UTC (rev 5052)
@@ -2249,7 +2249,15 @@
 				// versions > 4.1.0
 
 				try {
-					setEncoding(CharsetMapping.INDEX_TO_CHARSET[this.io.serverCharsetIndex]);
+					String serverEncodingToSet = 
+						CharsetMapping.INDEX_TO_CHARSET[this.io.serverCharsetIndex];
+					
+					if (versionMeetsMinimum(4, 1, 0) && 
+							"ISO8859_1".equalsIgnoreCase(serverEncodingToSet)) {
+						serverEncodingToSet = "Cp1252";
+					}
+					
+					setEncoding(serverEncodingToSet);
 				} catch (ArrayIndexOutOfBoundsException outOfBoundsEx) {
 					if (realJavaEncoding != null) {
 						// user knows best, try it

Modified: branches/branch_3_1/connector-j/src/testsuite/regression/StringRegressionTest.java
===================================================================
--- branches/branch_3_1/connector-j/src/testsuite/regression/StringRegressionTest.java	2006-03-11 01:02:51 UTC (rev 5051)
+++ branches/branch_3_1/connector-j/src/testsuite/regression/StringRegressionTest.java	2006-03-11 01:18:02 UTC (rev 5052)
@@ -783,4 +783,55 @@
 			System.setErr(oldError);
 		}
 	}
+	
+	public void testCodePage1252() throws Exception {
+		if (versionMeetsMinimum(4, 1, 0)) {
+			/* 
+			 * from ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT
+			 * 
+			 *  0x80	0x20AC	#EURO SIGN
+			 *  0x81	      	#UNDEFINED
+			 *  0x82	0x201A	#SINGLE LOW-9 QUOTATION MARK
+			 *  0x83	0x0192	#LATIN SMALL LETTER F WITH HOOK
+			 *  0x84	0x201E	#DOUBLE LOW-9 QUOTATION MARK
+			 *  0x85	0x2026	#HORIZONTAL ELLIPSIS
+			 *  0x86	0x2020	#DAGGER
+			 *  0x87	0x2021	#DOUBLE DAGGER
+			 *  0x88	0x02C6	#MODIFIER LETTER CIRCUMFLEX ACCENT
+			 *  0x89	0x2030	#PER MILLE SIGN
+			 *  0x8A	0x0160	#LATIN CAPITAL LETTER S WITH CARON
+			 *  0x8B	0x2039	#SINGLE LEFT-POINTING ANGLE QUOTATION MARK
+			 *  0x8C	0x0152	#LATIN CAPITAL LIGATURE OE
+			 *  0x8D	      	#UNDEFINED
+			 *  0x8E	0x017D	#LATIN CAPITAL LETTER Z WITH CARON
+			 *  0x8F	      	#UNDEFINED
+			 *  0x90	      	#UNDEFINED
+			 */
+			String codePage1252 = new String(new byte[] {
+					(byte)0x80,
+					(byte)0x82,
+					(byte)0x83,
+					(byte)0x84,
+					(byte)0x85,
+					(byte)0x86,
+					(byte)0x87,
+					(byte)0x88,
+					(byte)0x89,
+					(byte)0x8a,
+					(byte)0x8b,
+					(byte)0x8c,
+					(byte)0x8e}, "Cp1252");
+			
+			System.out.println(codePage1252);
+			
+			Properties props = new Properties();
+			props.setProperty("characterEncoding", "Cp1252");
+			Connection cp1252Conn = getConnectionWithProps(props);
+			createTable("testCp1252", "(field1 varchar(32) CHARACTER SET latin1)");
+			cp1252Conn.createStatement().executeUpdate("INSERT INTO testCp1252 VALUES ('" + codePage1252 + "')");
+			this.rs = cp1252Conn.createStatement().executeQuery("SELECT field1 FROM testCp1252");
+			this.rs.next();
+			assertEquals(this.rs.getString(1), codePage1252);
+		}
+	}
 }

Added: branches/branch_5_0/connector-j/.settings/org.eclipse.jdt.ui.prefs
===================================================================
--- branches/branch_5_0/connector-j/.settings/org.eclipse.jdt.ui.prefs	2006-03-11 01:02:51 UTC (rev 5051)
+++ branches/branch_5_0/connector-j/.settings/org.eclipse.jdt.ui.prefs	2006-03-11 01:18:02 UTC (rev 5052)
@@ -0,0 +1,3 @@
+#Tue Feb 07 16:51:26 CST 2006
+eclipse.preferences.version=1
+internal.default.compliance=user

Modified: branches/branch_5_0/connector-j/CHANGES
===================================================================
--- branches/branch_5_0/connector-j/CHANGES	2006-03-11 01:02:51 UTC (rev 5051)
+++ branches/branch_5_0/connector-j/CHANGES	2006-03-11 01:18:02 UTC (rev 5052)
@@ -176,7 +176,9 @@
 
 	- Fixed BUG#17587 - clearParameters() on a closed prepared statement
 	  causes NPE.
-    
+    	  
+	- Map "latin1" on MySQL server to CP1252 for MySQL > 4.1.0.
+	
 11-30-05 - Version 3.1.12
 
     - Fixed client-side prepared statement bug with embedded ? inside

Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/CharsetMapping.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/CharsetMapping.java	2006-03-11 01:02:51 UTC (rev 5051)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/CharsetMapping.java	2006-03-11 01:18:02 UTC (rev 5052)
@@ -115,6 +115,7 @@
 			+ "Cp1251 = 			cp1251csas,"
 			+ "Cp1256 = 			cp1256,"
 	 		+ "Cp1251 = 			win1251ukr,"
+	 		+ "Cp1252 =             latin1,"
 			+ "Cp1257 = 			cp1257,"
 			+ "MacRoman = 			macroman,"
 			+ "MacCentralEurope = 	macce,"
@@ -403,6 +404,12 @@
 
 	final static String getJavaEncodingForMysqlEncoding(String mysqlEncoding,
 			Connection conn) throws SQLException {
+		
+		if (conn != null && conn.versionMeetsMinimum(4, 1, 0) && 
+				"latin1".equalsIgnoreCase(mysqlEncoding)) {
+			return "cp1252";
+		}
+		
 		return (String) MYSQL_TO_JAVA_CHARSET_MAP.get(mysqlEncoding);
 	}
 

Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java	2006-03-11 01:02:51 UTC (rev 5051)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java	2006-03-11 01:18:02 UTC (rev 5052)
@@ -2276,7 +2276,15 @@
 				// versions > 4.1.0
 
 				try {
-					setEncoding(CharsetMapping.INDEX_TO_CHARSET[this.io.serverCharsetIndex]);
+					String serverEncodingToSet = 
+						CharsetMapping.INDEX_TO_CHARSET[this.io.serverCharsetIndex];
+					
+					if (versionMeetsMinimum(4, 1, 0) && 
+							"ISO8859_1".equalsIgnoreCase(serverEncodingToSet)) {
+						serverEncodingToSet = "Cp1252";
+					}
+					
+					setEncoding(serverEncodingToSet);
 				} catch (ArrayIndexOutOfBoundsException outOfBoundsEx) {
 					if (realJavaEncoding != null) {
 						// user knows best, try it
@@ -5420,6 +5428,65 @@
 		return this.io.versionMeetsMinimum(major, minor, subminor);
 	}
 	
+	public synchronized boolean isSameResource(Connection otherConnection) {
+		if (otherConnection == null) {
+			return false;
+		}
+		
+		boolean directCompare = true;
+		
+		String otherHost = otherConnection.origHostToConnectTo;
+		String otherOrigDatabase = otherConnection.origDatabaseToConnectTo;
+		String otherCurrentCatalog = otherConnection.database;
+		
+		if (!nullSafeCompare(otherHost, this.origHostToConnectTo)) {
+			directCompare = false;
+		} else if (otherHost != null & otherHost.indexOf(",") == -1 && 
+				otherHost.indexOf(":") == -1) {
+			// need to check port numbers
+			directCompare = (otherConnection.origPortToConnectTo == 
+				this.origPortToConnectTo);
+		}
+		
+		if (directCompare) {
+			if (!nullSafeCompare(otherOrigDatabase, this.origDatabaseToConnectTo)) {			directCompare = false;
+				directCompare = false;
+			} else if (!nullSafeCompare(otherCurrentCatalog, this.database)) {
+				directCompare = false;
+			}
+		}
+
+		if (directCompare) {
+			return true;
+		}
+		
+		// Has the user explicitly set a resourceId?
+		String otherResourceId = otherConnection.getResourceId();
+		String myResourceId = getResourceId();
+		
+		if (otherResourceId != null || myResourceId != null) {
+			directCompare = nullSafeCompare(otherResourceId, myResourceId);
+			
+			if (directCompare) {
+				return true;
+			}
+		}
+		
+		return false;	
+	}
+	
+	private static boolean nullSafeCompare(String s1, String s2) {
+		if (s1 == null && s2 == null) {
+			return true;
+		}
+
+		if (s1 == null && s2 != null) {
+			return false;
+		}
+
+		return s1.equals(s2);
+	}
+	
 	protected boolean isCursorFetchEnabled() throws SQLException {
 		return (versionMeetsMinimum(5, 0, 2) && getUseCursorFetch());
 	}

Modified: branches/branch_5_0/connector-j/src/testsuite/regression/StringRegressionTest.java
===================================================================
--- branches/branch_5_0/connector-j/src/testsuite/regression/StringRegressionTest.java	2006-03-11 01:02:51 UTC (rev 5051)
+++ branches/branch_5_0/connector-j/src/testsuite/regression/StringRegressionTest.java	2006-03-11 01:18:02 UTC (rev 5052)
@@ -789,4 +789,55 @@
 			}
 		}
 	}
+
+	public void testCodePage1252() throws Exception {
+		if (versionMeetsMinimum(4, 1, 0)) {
+			/* 
+			 * from ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT
+			 * 
+			 *  0x80	0x20AC	#EURO SIGN
+			 *  0x81	      	#UNDEFINED
+			 *  0x82	0x201A	#SINGLE LOW-9 QUOTATION MARK
+			 *  0x83	0x0192	#LATIN SMALL LETTER F WITH HOOK
+			 *  0x84	0x201E	#DOUBLE LOW-9 QUOTATION MARK
+			 *  0x85	0x2026	#HORIZONTAL ELLIPSIS
+			 *  0x86	0x2020	#DAGGER
+			 *  0x87	0x2021	#DOUBLE DAGGER
+			 *  0x88	0x02C6	#MODIFIER LETTER CIRCUMFLEX ACCENT
+			 *  0x89	0x2030	#PER MILLE SIGN
+			 *  0x8A	0x0160	#LATIN CAPITAL LETTER S WITH CARON
+			 *  0x8B	0x2039	#SINGLE LEFT-POINTING ANGLE QUOTATION MARK
+			 *  0x8C	0x0152	#LATIN CAPITAL LIGATURE OE
+			 *  0x8D	      	#UNDEFINED
+			 *  0x8E	0x017D	#LATIN CAPITAL LETTER Z WITH CARON
+			 *  0x8F	      	#UNDEFINED
+			 *  0x90	      	#UNDEFINED
+			 */
+			String codePage1252 = new String(new byte[] {
+					(byte)0x80,
+					(byte)0x82,
+					(byte)0x83,
+					(byte)0x84,
+					(byte)0x85,
+					(byte)0x86,
+					(byte)0x87,
+					(byte)0x88,
+					(byte)0x89,
+					(byte)0x8a,
+					(byte)0x8b,
+					(byte)0x8c,
+					(byte)0x8e}, "Cp1252");
+			
+			System.out.println(codePage1252);
+			
+			Properties props = new Properties();
+			props.setProperty("characterEncoding", "Cp1252");
+			Connection cp1252Conn = getConnectionWithProps(props);
+			createTable("testCp1252", "(field1 varchar(32) CHARACTER SET latin1)");
+			cp1252Conn.createStatement().executeUpdate("INSERT INTO testCp1252 VALUES ('" + codePage1252 + "')");
+			this.rs = cp1252Conn.createStatement().executeQuery("SELECT field1 FROM testCp1252");
+			this.rs.next();
+			assertEquals(this.rs.getString(1), codePage1252);
+		}
+	}
 }

Modified: branches/branch_5_1/connector-j/CHANGES
===================================================================
--- branches/branch_5_1/connector-j/CHANGES	2006-03-11 01:02:51 UTC (rev 5051)
+++ branches/branch_5_1/connector-j/CHANGES	2006-03-11 01:18:02 UTC (rev 5052)
@@ -177,7 +177,9 @@
 	  should be, however.
 	
 	- Fixed BUG#17587 - clearParameters() on a closed prepared statement
-	  causes NPE.
+	  causes NPE.	  
+	  
+	- Map "latin1" on MySQL server to CP1252 for MySQL > 4.1.0.
     
 11-30-05 - Version 3.1.12
 

Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/CharsetMapping.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/CharsetMapping.java	2006-03-11 01:02:51 UTC (rev 5051)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/CharsetMapping.java	2006-03-11 01:18:02 UTC (rev 5052)
@@ -115,6 +115,7 @@
 			+ "Cp1251 = 			cp1251csas,"
 			+ "Cp1256 = 			cp1256,"
 	 		+ "Cp1251 = 			win1251ukr,"
+	 		+ "Cp1252 =             latin1,"
 			+ "Cp1257 = 			cp1257,"
 			+ "MacRoman = 			macroman,"
 			+ "MacCentralEurope = 	macce,"
@@ -403,6 +404,12 @@
 
 	final static String getJavaEncodingForMysqlEncoding(String mysqlEncoding,
 			Connection conn) throws SQLException {
+		
+		if (conn != null && conn.versionMeetsMinimum(4, 1, 0) && 
+				"latin1".equalsIgnoreCase(mysqlEncoding)) {
+			return "cp1252";
+		}
+		
 		return (String) MYSQL_TO_JAVA_CHARSET_MAP.get(mysqlEncoding);
 	}
 

Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/Connection.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/Connection.java	2006-03-11 01:02:51 UTC (rev 5051)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/Connection.java	2006-03-11 01:18:02 UTC (rev 5052)
@@ -1396,7 +1396,15 @@
 				// versions > 4.1.0
 
 				try {
-					setEncoding(CharsetMapping.INDEX_TO_CHARSET[this.io.serverCharsetIndex]);
+					String serverEncodingToSet = 
+						CharsetMapping.INDEX_TO_CHARSET[this.io.serverCharsetIndex];
+					
+					if (versionMeetsMinimum(4, 1, 0) && 
+							"ISO8859_1".equalsIgnoreCase(serverEncodingToSet)) {
+						serverEncodingToSet = "Cp1252";
+					}
+					
+					setEncoding(serverEncodingToSet);
 				} catch (ArrayIndexOutOfBoundsException outOfBoundsEx) {
 					if (realJavaEncoding != null) {
 						// user knows best, try it

Modified: branches/branch_5_1/connector-j/src/testsuite/regression/StringRegressionTest.java
===================================================================
--- branches/branch_5_1/connector-j/src/testsuite/regression/StringRegressionTest.java	2006-03-11 01:02:51 UTC (rev 5051)
+++ branches/branch_5_1/connector-j/src/testsuite/regression/StringRegressionTest.java	2006-03-11 01:18:02 UTC (rev 5052)
@@ -789,4 +789,55 @@
 			}
 		}
 	}
+
+	public void testCodePage1252() throws Exception {
+		if (versionMeetsMinimum(4, 1, 0)) {
+			/* 
+			 * from ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT
+			 * 
+			 *  0x80	0x20AC	#EURO SIGN
+			 *  0x81	      	#UNDEFINED
+			 *  0x82	0x201A	#SINGLE LOW-9 QUOTATION MARK
+			 *  0x83	0x0192	#LATIN SMALL LETTER F WITH HOOK
+			 *  0x84	0x201E	#DOUBLE LOW-9 QUOTATION MARK
+			 *  0x85	0x2026	#HORIZONTAL ELLIPSIS
+			 *  0x86	0x2020	#DAGGER
+			 *  0x87	0x2021	#DOUBLE DAGGER
+			 *  0x88	0x02C6	#MODIFIER LETTER CIRCUMFLEX ACCENT
+			 *  0x89	0x2030	#PER MILLE SIGN
+			 *  0x8A	0x0160	#LATIN CAPITAL LETTER S WITH CARON
+			 *  0x8B	0x2039	#SINGLE LEFT-POINTING ANGLE QUOTATION MARK
+			 *  0x8C	0x0152	#LATIN CAPITAL LIGATURE OE
+			 *  0x8D	      	#UNDEFINED
+			 *  0x8E	0x017D	#LATIN CAPITAL LETTER Z WITH CARON
+			 *  0x8F	      	#UNDEFINED
+			 *  0x90	      	#UNDEFINED
+			 */
+			String codePage1252 = new String(new byte[] {
+					(byte)0x80,
+					(byte)0x82,
+					(byte)0x83,
+					(byte)0x84,
+					(byte)0x85,
+					(byte)0x86,
+					(byte)0x87,
+					(byte)0x88,
+					(byte)0x89,
+					(byte)0x8a,
+					(byte)0x8b,
+					(byte)0x8c,
+					(byte)0x8e}, "Cp1252");
+			
+			System.out.println(codePage1252);
+			
+			Properties props = new Properties();
+			props.setProperty("characterEncoding", "Cp1252");
+			Connection cp1252Conn = getConnectionWithProps(props);
+			createTable("testCp1252", "(field1 varchar(32) CHARACTER SET latin1)");
+			cp1252Conn.createStatement().executeUpdate("INSERT INTO testCp1252 VALUES ('" + codePage1252 + "')");
+			this.rs = cp1252Conn.createStatement().executeQuery("SELECT field1 FROM testCp1252");
+			this.rs.next();
+			assertEquals(this.rs.getString(1), codePage1252);
+		}
+	}
 }

Thread
Connector/J commit: r5052 - in branches: branch_3_1/connector-j branch_3_1/connector-j/src/com/mysql/jdbc branch_3_1/connector-j/src/testsuite/regress...mmatthews11 Mar