KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > testsuite > simple > EscapeProcessingTest


1 /*
2  Copyright (C) 2002-2004 MySQL AB
3
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.
7
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.
12
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.
17
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
21
22
23
24  */

25 package testsuite.simple;
26
27 import testsuite.BaseTestCase;
28
29 /**
30  * Tests escape processing
31  *
32  * @author Mark Matthews
33  */

34 public class EscapeProcessingTest extends BaseTestCase {
35     // ~ Constructors
36
// -----------------------------------------------------------
37

38     /**
39      * Constructor for EscapeProcessingTest.
40      *
41      * @param name
42      * the test to run
43      */

44     public EscapeProcessingTest(String JavaDoc name) {
45         super(name);
46     }
47
48     // ~ Methods
49
// ----------------------------------------------------------------
50

51     /**
52      * Tests the escape processing functionality
53      *
54      * @throws Exception
55      * if an error occurs
56      */

57     public void testEscapeProcessing() throws Exception JavaDoc {
58         String JavaDoc results = "select dayname (abs(now())), -- Today \n"
59                 + " '1997-05-24', -- a date \n"
60                 + " '10:30:29', -- a time \n"
61                 + " '1997-05-24 10:30:29', -- a timestamp \n"
62                 + " '{string data with { or } will not be altered' \n"
63                 + "-- Also note that you can safely include { and } in comments";
64
65         String JavaDoc exSql = "select {fn dayname ({fn abs({fn now()})})}, -- Today \n"
66                 + " {d '1997-05-24'}, -- a date \n"
67                 + " {t '10:30:29' }, -- a time \n"
68                 + " {ts '1997-05-24 10:30:29.123'}, -- a timestamp \n"
69                 + " '{string data with { or } will not be altered' \n"
70                 + "-- Also note that you can safely include { and } in comments";
71
72         String JavaDoc escapedSql = this.conn.nativeSQL(exSql);
73
74         assertTrue(results.equals(escapedSql));
75
76     }
77
78     /**
79      * Runs all test cases in this test suite
80      *
81      * @param args
82      */

83     public static void main(String JavaDoc[] args) {
84         junit.textui.TestRunner.run(EscapeProcessingTest.class);
85     }
86
87     /**
88      * JDBC-4.0 spec will allow either SQL_ or not for type in {fn convert ...}
89      *
90      * @throws Exception
91      * if the test fails
92      */

93     public void testConvertEscape() throws Exception JavaDoc {
94         assertEquals(conn.nativeSQL("{fn convert(abcd, SQL_INTEGER)}"), conn
95                 .nativeSQL("{fn convert(abcd, INTEGER)}"));
96     }
97 }
98
Popular Tags