2
Copyright (C) 2002-2004 MySQL AB
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of version 2 of the GNU General Public License as
6
published by the Free Software Foundation.
8
There are special exceptions to the terms and conditions of the GPL
9
as it is applied to this software. View the full text of the
10
exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
11
software distribution.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
package testsuite.simple;
27
import java.sql.Connection;
28
import java.util.Properties;
29
import java.util.TimeZone;
31
import testsuite.BaseTestCase;
34
* Tests escape processing
36
* @author Mark Matthews
38
public class EscapeProcessingTest extends BaseTestCase {
40
// -----------------------------------------------------------
43
* Constructor for EscapeProcessingTest.
48
public EscapeProcessingTest(String name) {
53
// ----------------------------------------------------------------
56
* Tests the escape processing functionality
61
public void testEscapeProcessing() throws Exception {
62
String results = "select dayname (abs(now())), -- Today \n"
63
+ " '1997-05-24', -- a date \n"
64
+ " '10:30:29', -- a time \n"
65
+ " '1997-05-24 10:30:29', -- a timestamp \n"
66
+ " '{string data with { or } will not be altered' \n"
67
+ "-- Also note that you can safely include { and } in comments";
69
String exSql = "select {fn dayname ({fn abs({fn now()})})}, -- Today \n"
70
+ " {d '1997-05-24'}, -- a date \n"
71
+ " {t '10:30:29' }, -- a time \n"
72
+ " {ts '1997-05-24 10:30:29.123'}, -- a timestamp \n"
73
+ " '{string data with { or } will not be altered' \n"
74
+ "-- Also note that you can safely include { and } in comments";
76
String escapedSql = this.conn.nativeSQL(exSql);
78
assertTrue(results.equals(escapedSql));
83
* Runs all test cases in this test suite
87
public static void main(String[] args) {
88
junit.textui.TestRunner.run(EscapeProcessingTest.class);
92
* JDBC-4.0 spec will allow either SQL_ or not for type in {fn convert ...}
97
public void testConvertEscape() throws Exception {
98
assertEquals(conn.nativeSQL("{fn convert(abcd, SQL_INTEGER)}"), conn
99
.nativeSQL("{fn convert(abcd, INTEGER)}"));
103
* Tests that the escape tokenizer converts timestamp values
104
* wrt. timezones when useTimezone=true.
106
* @throws Exception if the test fails.
108
public void testTimestampConversion() throws Exception {
109
TimeZone currentTimezone = TimeZone.getDefault();
110
String[] availableIds = TimeZone.getAvailableIDs(currentTimezone.getRawOffset() + (3600 * 1000 * 2));
111
String newTimezone = null;
113
if (availableIds.length > 0) {
114
newTimezone = availableIds[0];
116
newTimezone = "UTC"; // punt
119
Properties props = new Properties();
121
props.setProperty("useTimezone", "true");
122
props.setProperty("serverTimezone", newTimezone);
123
Connection tzConn = null;
126
String escapeToken = "SELECT {ts '2002-11-12 10:00:00'} {t '05:11:02'}";
127
tzConn = getConnectionWithProps(props);
128
assertTrue(!tzConn.nativeSQL(escapeToken).equals(this.conn.nativeSQL(escapeToken)));
130
if (tzConn != null) {