MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:mmatthews Date:September 7 2005 2:36pm
Subject:Connector/J commit: r4214 - branches/branch_5_0/connector-j/src/com/mysql/jdbc
View as plain text  
Modified:
   branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java
   branches/branch_5_0/connector-j/src/com/mysql/jdbc/EscapeProcessor.java
   branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java
Log:
Support for timezone adjustment in escape-processed {ts} tokens.

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	2005-09-07 00:04:44 UTC (rev 4213)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java	2005-09-07 14:36:02 UTC (rev 4214)
@@ -4079,7 +4079,8 @@
 		}
 
 		Object escapedSqlResult = EscapeProcessor.escapeSQL(sql,
-				serverSupportsConvertFn());
+				serverSupportsConvertFn(),
+				this);
 
 		if (escapedSqlResult instanceof String) {
 			return (String) escapedSqlResult;
@@ -4091,7 +4092,7 @@
 	private CallableStatement parseCallableStatement(String sql)
 			throws SQLException {
 		Object escapedSqlResult = EscapeProcessor.escapeSQL(sql,
-				serverSupportsConvertFn());
+				serverSupportsConvertFn(), this);
 
 		boolean isFunctionCall = false;
 		String parsedSql = null;

Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/EscapeProcessor.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/EscapeProcessor.java	2005-09-07 00:04:44 UTC (rev 4213)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/EscapeProcessor.java	2005-09-07 14:36:02 UTC (rev 4214)
@@ -30,7 +30,9 @@
 package com.mysql.jdbc;
 
 import java.sql.SQLException;
+import java.sql.Timestamp;
 
+import java.util.Calendar;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Locale;
@@ -95,7 +97,7 @@
 	 *             DOCUMENT ME!
 	 */
 	public static final Object escapeSQL(String sql,
-			boolean serverSupportsConvertFn) throws java.sql.SQLException {
+			boolean serverSupportsConvertFn, Connection conn) throws java.sql.SQLException {
 		boolean replaceEscapeSequence = false;
 		String escapeSequence = null;
 
@@ -142,7 +144,7 @@
 
 							Object remainingResults = escapeSQL(token
 									.substring(1, token.length() - 1),
-									serverSupportsConvertFn);
+									serverSupportsConvertFn, conn);
 
 							String remaining = null;
 
@@ -284,11 +286,60 @@
 							 * 
 							 * Thanks to Craig Longman for pointing out this bug
 							 */
-							newSql.append("'").append(year4).append("-")
+							if (!conn.getUseTimezone()) {
+								newSql.append("'").append(year4).append("-")
 									.append(month2).append("-").append(day2)
 									.append(" ").append(hour).append(":")
 									.append(minute).append(":").append(second)
 									.append("'");
+							} else {
+								Calendar localTzCal = Calendar.getInstance();
+								
+								try {
+									int year4Int = Integer.parseInt(year4);
+									int month2Int = Integer.parseInt(month2);
+									int day2Int = Integer.parseInt(day2);
+									int hourInt = Integer.parseInt(hour);
+									int minuteInt = Integer.parseInt(minute);
+									int secondInt = Integer.parseInt(second);
+									
+									
+									Timestamp toBeAdjusted = TimeUtil.fastTimestampCreate(
+											localTzCal,
+											year4Int,
+											month2Int,
+											day2Int,
+											hourInt,
+											minuteInt,
+											secondInt,
+											0);
+									
+									Timestamp inServerTimezone = TimeUtil.changeTimezone(
+											conn,
+											toBeAdjusted,
+											localTzCal.getTimeZone(),
+											conn.getServerTimezoneTZ(),
+											false);
+									
+									newSql.append("'");
+									
+									String timezoneLiteral = inServerTimezone.toString();
+									
+									int indexOfDot = timezoneLiteral.indexOf(".");
+									
+									if (indexOfDot != -1) {
+										timezoneLiteral = timezoneLiteral.substring(0, indexOfDot);
+									}
+									
+									newSql.append(timezoneLiteral);
+									newSql.append("'");			
+								
+								} catch (NumberFormatException nfe) {
+									throw new SQLException("Syntax error in TIMESTAMP escape sequence '" 
+										+ token + "'.",
+										SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+								}
+							}
 						} catch (java.util.NoSuchElementException e) {
 							throw new SQLException(
 									"Syntax error for TIMESTAMP escape sequence '"

Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java	2005-09-07 00:04:44 UTC (rev 4213)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java	2005-09-07 14:36:02 UTC (rev 4214)
@@ -450,7 +450,8 @@
 
 		if (this.doEscapeProcessing) {
 			Object escapedSqlResult = EscapeProcessor.escapeSQL(sql,
-					this.connection.serverSupportsConvertFn());
+					this.connection.serverSupportsConvertFn(),
+					this.connection);
 
 			if (escapedSqlResult instanceof String) {
 				sql = (String) escapedSqlResult;
@@ -747,7 +748,8 @@
 
 		if (this.doEscapeProcessing) {
 			Object escapedSqlResult = EscapeProcessor.escapeSQL(sql,
-					this.connection.serverSupportsConvertFn());
+					this.connection.serverSupportsConvertFn(),
+					this.connection);
 
 			if (escapedSqlResult instanceof String) {
 				sql = (String) escapedSqlResult;
@@ -904,7 +906,8 @@
 
 		if (this.doEscapeProcessing) {
 			Object escapedSqlResult = EscapeProcessor.escapeSQL(sql,
-					this.connection.serverSupportsConvertFn());
+					this.connection.serverSupportsConvertFn(),
+					this.connection);
 
 			if (escapedSqlResult instanceof String) {
 				sql = (String) escapedSqlResult;

Thread
Connector/J commit: r4214 - branches/branch_5_0/connector-j/src/com/mysql/jdbcmmatthews7 Sep