List:Internals« Previous MessageNext Message »
From:mmatthews Date:September 23 2005 5:24pm
Subject:Connector/J commit: r4297 - branches/branch_3_1/connector-j/src/com/mysql/jdbc
View as plain text  
Modified:
   branches/branch_3_1/connector-j/src/com/mysql/jdbc/Field.java
   branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSetMetaData.java
Log:
Backport of VAR[BINARY|CHAR] [BINARY] types detection from 
      5.0 branch.

Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/Field.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/Field.java	2005-09-23 15:14:37 UTC
(rev 4296)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/Field.java	2005-09-23 15:24:33 UTC
(rev 4297)
@@ -110,6 +110,8 @@
 	private int tableNameLength;
 
 	private int tableNameStart;
+	
+	private boolean useOldNameMetadata = false;
 
 	// ~ Constructors
 	// -----------------------------------------------------------
@@ -155,26 +157,52 @@
 		this.charsetName = this.connection
 				.getCharsetNameForIndex(this.charsetIndex);
 		
+		// Map MySqlTypes to java.sql Types
+		this.sqlType = MysqlDefs.mysqlToJavaType(this.mysqlType);
+		
 		// Re-map to 'real' blob type, if we're a BLOB
 
-		
 		if (this.mysqlType == MysqlDefs.FIELD_TYPE_BLOB) {
-			setBlobTypeBasedOnLength();
+			if (this.charsetIndex == 63 || 
+					!this.connection.versionMeetsMinimum(4, 1, 0)) {
+				setBlobTypeBasedOnLength();
+				this.sqlType = MysqlDefs.mysqlToJavaType(this.mysqlType);
+			} else {
+				// *TEXT masquerading as blob
+				this.mysqlType = MysqlDefs.FIELD_TYPE_VAR_STRING;
+				this.sqlType = Types.LONGVARCHAR;
+			}
 		}
 
-		// Map MySqlTypes to java.sql Types
-		this.sqlType = MysqlDefs.mysqlToJavaType(this.mysqlType);
+		// Handle VARBINARY/BINARY (server doesn't have a different type
+		// for this
 
-		// Handle VARBINARY (server doesn't have a different type
-		// for this
+		boolean isBinary = isBinary();
+
+		if (this.connection.versionMeetsMinimum(4, 1, 0) &&
+				this.mysqlType == MysqlDefs.FIELD_TYPE_VAR_STRING && 
+				isBinary &&
+				this.charsetIndex == 63) {
+			if (this.isOpaqueBinary()) {
+				this.sqlType = Types.VARBINARY;
+			}
+		} 
 		
 		if (this.connection.versionMeetsMinimum(4, 1, 0) &&
-				this.mysqlType == 253 && 
-				isBinary() &&
-				this.charsetIndex == 63) {
-			this.sqlType = Types.VARBINARY;
+				this.mysqlType == MysqlDefs.FIELD_TYPE_STRING && 
+				isBinary && this.charsetIndex == 63) {
+			//
+			// Okay, this is a hack, but there's currently no way
+			// to easily distinguish something like DATE_FORMAT( ..)
+			// from the "BINARY" column type, other than looking
+			// at the original column name.
+			//
+			
+			if (isOpaqueBinary()) {
+				this.sqlType = Types.BINARY;
+			}
 		}
-		
+
 		if (this.sqlType == Types.TINYINT && this.length == 1
 				&& this.connection.getTinyInt1isBit()) {
 			// Adjust for pseudo-boolean
@@ -200,8 +228,6 @@
 
 		
 
-		boolean isBinary = isBinary();
-
 		//
 		// Handle TEXT type (special case), Fix proposed by Peter McKeown
 		//
@@ -357,6 +383,10 @@
 		return this.collationName;
 	}
 
+	public String getColumnLabel() throws SQLException {
+		return getName(); // column name if not aliased, alias if used
+	}
+
 	/**
 	 * DOCUMENT ME!
 	 * 
@@ -460,6 +490,19 @@
 		return this.name;
 	}
 
+	public String getNameNoAliases() throws SQLException {
+		if (this.useOldNameMetadata) {
+			return getName();
+		}
+		
+		if (this.connection != null && 
+				this.connection.versionMeetsMinimum(4, 1, 0)) {
+			return getOriginalName();
+		}
+		
+		return getName();
+	}
+
 	/**
 	 * DOCUMENT ME!
 	 * 
@@ -605,6 +648,14 @@
 		return this.tableName;
 	}
 
+	public String getTableNameNoAliases() throws SQLException {
+		if (this.connection.versionMeetsMinimum(4, 1, 0)) {
+			return getOriginalTableName();
+		}
+			
+		return getTableName(); // pre-4.1, no aliases returned
+	}
+
 	/**
 	 * DOCUMENT ME!
 	 * 
@@ -662,7 +713,8 @@
 		//
 
 		if (this.charsetIndex == 63 && isBinary()
-				&& this.getMysqlType() == MysqlDefs.FIELD_TYPE_STRING) {
+				&& (this.getMysqlType() == MysqlDefs.FIELD_TYPE_STRING ||
+				this.getMysqlType() == MysqlDefs.FIELD_TYPE_VAR_STRING)) {
 
 			if (this.originalTableNameLength == 0) {
 				return false; // Probably from function
@@ -767,6 +819,10 @@
 		this.sqlType = MysqlDefs.mysqlToJavaType(this.mysqlType);
 	}
 
+	protected void setUseOldNameMetadata(boolean useOldNameMetadata) {
+		this.useOldNameMetadata = useOldNameMetadata;
+	}
+
 	/**
 	 * DOCUMENT ME!
 	 * 

Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSetMetaData.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSetMetaData.java	2005-09-23
15:14:37 UTC (rev 4296)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSetMetaData.java	2005-09-23
15:24:33 UTC (rev 4297)
@@ -264,12 +264,12 @@
 		case Types.VARBINARY:
 		case Types.LONGVARBINARY:
 
-			if (!f.isBlob()) {
-				return "java.lang.String"; //$NON-NLS-1$
-			} else if (!f.isBinary()) {
-				return "java.lang.String"; //$NON-NLS-1$
+			if (f.getMysqlType() == MysqlDefs.FIELD_TYPE_GEOMETRY) {
+				return "[B";
+			} else if (f.isBinary() || f.isBlob()) {
+				return "[B";
 			} else {
-				return "[B"; //$NON-NLS-1$
+				return "java.lang.String";
 			}
 
 		case Types.DATE:

Thread
Connector/J commit: r4297 - branches/branch_3_1/connector-j/src/com/mysql/jdbcmmatthews23 Sep