Home | History | Annotate | Download | only in sql
      1 /*
      2  * Copyright (C) 2007 Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package libcore.java.sql;
     18 
     19 
     20 import java.net.MalformedURLException;
     21 import java.net.URL;
     22 import java.sql.DatabaseMetaData;
     23 import java.sql.Date;
     24 import java.sql.PreparedStatement;
     25 import java.sql.ResultSet;
     26 import java.sql.ResultSetMetaData;
     27 import java.sql.SQLException;
     28 import java.sql.Statement;
     29 import java.sql.Time;
     30 import java.sql.Timestamp;
     31 import java.util.Arrays;
     32 import java.util.Calendar;
     33 import java.util.GregorianCalendar;
     34 import java.util.Iterator;
     35 import java.util.LinkedList;
     36 import java.util.List;
     37 import java.util.ListIterator;
     38 
     39 /**
     40  * Tests based on
     41  * <a href="http://java.sun.com/products/jdbc/download.html">JDBC 1.0 API spec</a> Table 1.0
     42  */
     43 public final class OldResultSetGetterTests extends OldSQLTest {
     44 
     45     String queryAllSelect = "select * from type";
     46 
     47     ResultSet res = null;
     48 
     49     Statement st = null;
     50 
     51     // Judgement concerning support is based on the result of ResultSet.getOject
     52     // and Table 1 of JDBC 1.0 spec.
     53     static boolean booleanSupported = false;
     54     static boolean blobSupported = false;
     55     static boolean bigIntSupported = false;
     56     static boolean smallIntSupported = false;
     57     static boolean mediumIntSupported = false;
     58     static boolean realSupported = false;
     59     static boolean floatSupported = false;
     60     static boolean dateSupported = false;
     61     static boolean timeSupported = false;
     62     static boolean timeStampSupported = false;
     63     static boolean dateTimeSupported = false;
     64     static boolean urlSupported= false;
     65     static boolean tinyIntSupported = false;
     66     static boolean decimalSupported = false;
     67     static boolean numericSupported = false;
     68 
     69     static List<String> colNames = Arrays.asList("BoolVal", "IntVal", "LongVal",
     70             "Bint", "Tint", "Sint", "Mint", "IntegerVal", "RealVal",
     71             "DoubleVal", "FloatVal", "DecVal", "NumVal", "charStr",
     72             "dateVal", "timeVal", "TS", "DT", "TBlob", "BlobVal", "MBlob",
     73             "LBlob", "TText", "TextVal", "MText", "LText", "MaxLongVal",
     74             "MinLongVal", "validURL", "invalidURL");
     75 
     76     static List<String> values = Arrays.asList("1", "-1", "22", "2", "33",
     77          "3","1","2","3.9","23.2","33.3","44",
     78         "5", "test string", "1799-05-26", "12:35:45", "2007-10-09 14:28:02.0",
     79         "1221-09-22 10:11:55","1","2","3","4","Test text message tiny",
     80         "Test text", "Test text message medium",
     81         "Test text message long");
     82 
     83     static boolean[] supported = new boolean[]{
     84         booleanSupported,
     85         true,
     86         true,
     87         bigIntSupported,
     88         tinyIntSupported,
     89         smallIntSupported,
     90         mediumIntSupported,
     91         true,
     92         realSupported,
     93         true,
     94         floatSupported,
     95         decimalSupported,
     96         numericSupported,
     97         true,
     98         dateSupported,
     99         timeSupported,
    100         timeStampSupported,
    101         dateTimeSupported,
    102         blobSupported,
    103         blobSupported,
    104         blobSupported,
    105         blobSupported,
    106         true,
    107         true,
    108         true,
    109         true,
    110         bigIntSupported,
    111         bigIntSupported,
    112         urlSupported,
    113         urlSupported
    114       };
    115 
    116     // Not supported: BIT,VARBINARY, LONGVARBINARY, BINARY, VARCHAR, LONGVARCHAR
    117     static Class[] typeMap = new Class[]{
    118             java.lang.String.class, //
    119             java.lang.Integer.class,//Types.INTEGER,
    120             java.lang.Integer.class, //Types.LONG, not a JDBC 1.0 type
    121             java.lang.Long.class,  // Types.BIGINT,
    122             java.lang.Byte.class,            // Types.TINYINT,
    123             java.lang.Short.class, // Types.SMALLINT,
    124             java.lang.Integer.class, //Types.MEDIUMINT, , not a JDBC 1.0 type
    125             java.lang.Integer.class, // Types.Integer
    126             java.lang.Float.class,   // Types.REAL,
    127             java.lang.Double.class,  // Types.FLOAT,
    128             java.lang.Double.class, // Types.DOUBLE,
    129             java.math.BigDecimal.class, // Types.DECIMAL,
    130             java.math.BigDecimal.class, // Types.NUMERIC,
    131             java.lang.String.class,     // Types.CHAR
    132             java.sql.Date.class,        // Types.DATE,
    133             java.sql.Time.class,        // Types.TIME,
    134             java.sql.Timestamp.class,  // Types.TIMESTAMP,
    135             java.sql.Date.class,       // types datetime, not a JDBC 1.0 type
    136             java.sql.Blob.class,       // Types.BLOB, not a JDBC 1.0 type
    137             java.sql.Blob.class,       // Types.BLOB, not a JDBC 1.0 type
    138             java.sql.Blob.class,       // Types.BLOB, not a JDBC 1.0 type
    139             java.sql.Blob.class,       // Types.BLOB, not a JDBC 1.0 type
    140             java.lang.String.class,    // not a JDBC 1.0 type
    141             java.lang.String.class,    // not a JDBC 1.0 type
    142             java.lang.String.class,    // not a JDBC 1.0 type
    143             java.lang.String.class,    // not a JDBC 1.0 type
    144             java.lang.Long.class,      // Types.BIGINT,
    145             java.lang.Long.class,      // Types.BIGINT,
    146             java.net.URL.class,        // not a JDBC 1.0 type
    147             java.net.URL.class         // not a JDBC 1.0 type
    148 
    149 
    150     };
    151 
    152     // first inserted row : actual values
    153     // second inserted row: null values
    154     String[] queries = {
    155             "create table type (" +
    156 
    157             " BoolVal BOOLEAN," + " IntVal INT," + " LongVal LONG,"
    158                     + " Bint BIGINT," + " Tint TINYINT," + " Sint SMALLINT,"
    159                     + " Mint MEDIUMINT, " +
    160 
    161                     " IntegerVal INTEGER, " + " RealVal REAL, "
    162                     + " DoubleVal DOUBLE, " + " FloatVal FLOAT, "
    163                     + " DecVal DECIMAL, " +
    164 
    165                     " NumVal NUMERIC, " + " charStr CHAR(20), "
    166                     + " dateVal DATE, " + " timeVal TIME, " + " TS TIMESTAMP, "
    167                     +
    168 
    169                     " DT DATETIME, " + " TBlob TINYBLOB, " + " BlobVal BLOB, "
    170                     + " MBlob MEDIUMBLOB, " + " LBlob LONGBLOB, " +
    171 
    172                     " TText TINYTEXT, " + " TextVal TEXT, "
    173                     + " MText MEDIUMTEXT, " + " LText LONGTEXT, " +
    174 
    175                     " MaxLongVal BIGINT, MinLongVal BIGINT, "+
    176 
    177                     " validURL URL, invalidURL URL "+
    178 
    179                     ");"
    180              ,
    181 
    182             "insert into type (BoolVal, IntVal, LongVal, Bint, Tint, Sint, Mint,"
    183                     + "IntegerVal, RealVal, DoubleVal, FloatVal, DecVal,"
    184                     + "NumVal, charStr, dateVal, timeVal, TS,"
    185                     + "DT, TBlob, BlobVal, MBlob, LBlob,"
    186                     + "TText, TextVal, MText, LText, MaxLongVal, MinLongVal,"
    187                     + " validURL, invalidURL"
    188                     + ") "
    189                     + "values (1, -1, 22, 2, 33,"
    190                     + "3, 1, 2, 3.9, 23.2, 33.3, 44,"
    191                     + "5, 'test string', '1799-05-26', '12:35:45', '2007-10-09 14:28:02.0',"
    192                     + "'1221-09-22 10:11:55', 1, 2, 3, 4,"
    193                     + "'Test text message tiny', 'Test text',"
    194                     + " 'Test text message medium', 'Test text message long', "
    195                     + Long.MAX_VALUE+", "+Long.MIN_VALUE+", "
    196                     + "'http://www.android.com', 'helloWorld' "+
    197                     ");"
    198             ,
    199 
    200            "insert into type (BoolVal, IntVal, LongVal, Bint, Tint, Sint, Mint,"
    201                     + "IntegerVal, RealVal, DoubleVal, FloatVal, DecVal,"
    202                     + "NumVal, charStr, dateVal, timeVal, TS,"
    203                     + "DT, TBlob, BlobVal, MBlob, LBlob,"
    204                     + "TText, TextVal, MText, LText, MaxLongVal, MinLongVal,"
    205                     +" validURL, invalidURL"
    206                     + ") "
    207                     + "values (null, null, null, null, null,"
    208                     + "null, null, null, null, null, null, null,"
    209                     + "null, null, null, null, null,"
    210                     + "null, null, null, null, null,"
    211                     + "null, null, null, null,null, null, null, null);"
    212     };
    213 
    214     @Override
    215     public void setUp() throws Exception {
    216         super.setUp();
    217         conn.setAutoCommit(false);
    218         st = conn.createStatement();
    219         for (int i = 0; i < queries.length; i++) {
    220             st.execute(queries[i]);
    221         }
    222         res = st.executeQuery(queryAllSelect);
    223         assertTrue(res.next());
    224     }
    225 
    226     public void tearDown() throws SQLException {
    227         try {
    228             st.execute("drop table if exists type");
    229             st.close();
    230             res.close();
    231         } finally {
    232             try {
    233                 st.close();
    234                 res.close();
    235             } catch (SQLException ee) {
    236             }
    237         }
    238         super.tearDown();
    239     }
    240 
    241     public void testGetBytesInt() throws SQLException {
    242         int i = 1;
    243         // null value
    244         i = 1;
    245         res.next();
    246         for (String t : values) {
    247             assertNull(res.getBytes(i));
    248             i++;
    249         }
    250 
    251         try {
    252             res.close();
    253             res.getBytes(24);
    254             fail("Should get Exception");
    255         } catch (SQLException e) {
    256             //ok
    257         }
    258 
    259     }
    260 
    261     public void testGetBytesIntVarbinary() throws SQLException {
    262         Statement st = null;
    263         Statement stQuery = null;
    264         PreparedStatement stPrep = null;
    265         ResultSet res = null;
    266 
    267         // setup
    268         try {
    269             String testString = "HelloWorld";
    270             st = conn.createStatement();
    271             st.executeUpdate("create table testBinary (VARBINARY value);");
    272             stPrep = conn
    273                     .prepareStatement("insert into testBinary values (?);");
    274             stPrep.setBytes(1, testString.getBytes());
    275             stPrep.execute();
    276 
    277             stQuery = conn.createStatement();
    278             res = stQuery.executeQuery("select * from testBinary");
    279             assertTrue(res.next());
    280             byte[] output = res.getBytes(1);
    281             String helloTest = new String(output);
    282             assertNotNull(helloTest);
    283             assertEquals(testString, helloTest);
    284         } finally {
    285             if (res != null) res.close();
    286             if (stPrep != null) stPrep.close();
    287             if (st != null) st.close();
    288             if (stQuery != null) stQuery.close();
    289         }
    290     }
    291 
    292     public void testGetBytesIntBinary() throws SQLException {
    293 
    294         Statement st = null;
    295         Statement stQuery = null;
    296         PreparedStatement stPrep = null;
    297         ResultSet res = null;
    298 
    299 
    300         // setup
    301 
    302         String testString = "HelloWorld";
    303         st = conn.createStatement();
    304         st.executeUpdate("create table testBinary (BINARY value);");
    305         stPrep = conn.prepareStatement("insert into testBinary values (?);");
    306         stPrep.setBytes(1, testString.getBytes());
    307         stPrep.execute();
    308         try {
    309             stQuery = conn.createStatement();
    310             res = stQuery.executeQuery("select * from testBinary");
    311             assertTrue(res.next());
    312             byte[] output = res.getBytes(1);
    313             String helloTest = new String(output);
    314             assertNotNull(helloTest);
    315             assertEquals(testString, helloTest);
    316         } finally {
    317             if (res != null) res.close();
    318             if (stPrep != null) stPrep.close();
    319             if (st != null) st.close();
    320             if (stQuery != null) stQuery.close();
    321         }
    322     }
    323 
    324     public void testGetBytesString() throws SQLException {
    325         int i = 1;
    326 
    327         // null value
    328         res.next();
    329         for (String t : colNames) {
    330             assertNull(res.getBytes(t));
    331         }
    332 
    333         try {
    334             res.close();
    335             res.getBytes(colNames.get(24));
    336             fail("Should get Exception");
    337         } catch (SQLException e) {
    338             //ok
    339         }
    340     }
    341 
    342     // last assertion fails: invalid conversion. Test passes on RI
    343     public void testGetBytesStringVarbinary() throws SQLException {
    344         Statement st = null;
    345         Statement stQuery = null;
    346         PreparedStatement stPrep = null;
    347         ResultSet res = null;
    348 
    349         // setup
    350         try {
    351             String testString = "HelloWorld";
    352             st = conn.createStatement();
    353             st.executeUpdate("create table testBinary (VARBINARY value);");
    354             stPrep = conn
    355                     .prepareStatement("insert into testBinary values (?);");
    356             stPrep.setBytes(1, testString.getBytes());
    357             stPrep.execute();
    358 
    359             stQuery = conn.createStatement();
    360             res = stQuery.executeQuery("select value from testBinary");
    361             assertTrue(res.next());
    362             byte[] output = res.getBytes("value");
    363             String helloTest = new String(output);
    364             assertNotNull(helloTest);
    365             assertEquals(testString, helloTest);
    366         } finally {
    367             if (res != null) res.close();
    368             if (stPrep != null) stPrep.close();
    369             if (st != null) st.close();
    370             if (stQuery != null) stQuery.close();
    371         }
    372 
    373     }
    374 
    375      // last assertion fails: invalid conversion. Test passes on RI
    376     public void testGetBytesStringBinary() throws SQLException {
    377         Statement st = null;
    378         Statement stQuery = null;
    379         PreparedStatement stPrep = null;
    380         ResultSet res = null;
    381 
    382         // setup
    383 
    384         String testString = "HelloWorld";
    385         st = conn.createStatement();
    386         st.executeUpdate("create table testBinary (BINARY value);");
    387         stPrep = conn.prepareStatement("insert into testBinary values (?);");
    388         stPrep.setBytes(1, testString.getBytes());
    389         stPrep.execute();
    390         try {
    391             stQuery = conn.createStatement();
    392             res = stQuery.executeQuery("select value from testBinary");
    393             assertTrue(res.next());
    394             byte[] output = res.getBytes("value");
    395             String helloTest = new String(output);
    396             assertNotNull(helloTest);
    397             assertEquals(testString, helloTest);
    398         } finally {
    399             if (res != null) res.close();
    400             if (stPrep != null) stPrep.close();
    401             if (st != null) st.close();
    402             if (stQuery != null) stQuery.close();
    403         }
    404     }
    405 
    406     public void testGetConcurrency() throws SQLException {
    407         assertEquals(ResultSet.CONCUR_UPDATABLE, res.getConcurrency());
    408     }
    409 
    410     public void testGetDateInt() throws SQLException {
    411         GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0);
    412         Date input = new Date(testCal.getTimeInMillis());
    413         Date d = res.getDate(15);
    414         assertEquals(input.toString(),"1799-05-26");
    415         assertEquals(input,d);
    416 
    417         try {
    418             d = res.getDate(500);
    419             fail("Should get exception");
    420         } catch (SQLException e) {
    421             //ok
    422         }
    423 
    424         // null value
    425         assertTrue(res.next());
    426         d = res.getDate(15);
    427         assertNull(d);
    428     }
    429 
    430     public void testGetDateIntCalendar() throws SQLException {
    431         GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0);
    432         Date input = new Date(testCal.getTimeInMillis());
    433         Date d = res.getDate(15, testCal);
    434 
    435         assertEquals(input.toString(),"1799-05-26");
    436         assertEquals(input,d);
    437 
    438         try {
    439             d = res.getDate(500, testCal);
    440             fail("Should get exception");
    441         } catch (SQLException e) {
    442             //ok
    443         }
    444 
    445 
    446         // null value
    447         assertTrue(res.next());
    448         d = res.getDate(15,testCal);
    449         assertNull(d);
    450     }
    451 
    452     public void testGetDateString() throws SQLException {
    453         GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0);
    454         Date input = new Date(testCal.getTimeInMillis());
    455         Date d = res.getDate("dateVal");
    456         assertEquals(input.toString(),"1799-05-26");
    457         assertEquals(input,d);
    458 
    459         try {
    460             d = res.getDate("bla");
    461             fail("Should get exception");
    462         } catch (SQLException e) {
    463             //ok
    464         }
    465 
    466         // null value
    467         assertTrue(res.next());
    468         d = res.getDate("dateVal");
    469         assertNull(d);
    470     }
    471 
    472     public void testGetDateStringCalendar() throws SQLException {
    473         GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0);
    474         Date input = new Date(testCal.getTimeInMillis());
    475         Date d = res.getDate("dateVal", testCal);
    476         assertEquals(input.toString(),"1799-05-26");
    477         assertEquals(input,d);
    478 
    479         try {
    480             res.getDate("bla", testCal);
    481             fail("Should get exception");
    482         } catch (SQLException e) {
    483             //ok
    484         }
    485 
    486         // null value
    487         assertTrue(res.next());
    488         d = res.getDate("dateVal",testCal);
    489         assertNull(d);
    490     }
    491 
    492     public void testGetDoubleInt() throws SQLException {
    493         double output = 0.0;
    494         double[] input = {2.0, 3.9 , 23.2};
    495 
    496         output = res.getDouble(8);
    497         assertEquals(input[0],output);
    498 
    499         output = res.getDouble(9);
    500         assertEquals(input[1],output);
    501 
    502         output = res.getDouble(10);
    503         assertEquals(input[2],output);
    504 
    505         try  {
    506             res.getDouble(500);
    507         } catch (SQLException e) {
    508             //ok
    509         }
    510 
    511         // null value
    512         res.next();
    513         output = res.getDouble(8);
    514         assertEquals(0.0,output);
    515 
    516         output = res.getDouble(9);
    517         assertEquals(0.0,output);
    518 
    519         output = res.getDouble(10);
    520         assertEquals(0.0,output);
    521     }
    522 
    523     public void testGetDoubleString() throws SQLException {
    524         double input = 23.2;
    525         double output = 0.0;
    526 
    527         output = res.getDouble("DoubleVal");
    528         assertEquals (input,output);
    529 
    530         try{
    531             res.getDouble("bla");
    532             fail("Exception expected");
    533         } catch (SQLException e) {
    534             // ok
    535         }
    536 
    537         // null value
    538         assertTrue(res.next());
    539         output = res.getDouble("DoubleVal");
    540         assertEquals (0.0 , output);
    541     }
    542 
    543     public void testGetFloatInt() throws SQLException {
    544         float defaultF = 0.0f;
    545         float[] input = {3.9f, 23.2f, 33.3f};
    546 
    547         float output = res.getFloat(9);
    548         assertEquals(input[0], output);
    549 
    550         output = res.getFloat(10);
    551         assertEquals(input[1], output);
    552 
    553         output = res.getFloat(11);
    554         assertEquals(input[2], output);
    555 
    556         try {
    557             res.getFloat(500);
    558             fail("Exception expected");
    559         } catch (SQLException e) {
    560             //ok
    561         }
    562 
    563         res.next();
    564         output = res.getFloat(8);
    565         assertEquals(defaultF, output);
    566 
    567         output = res.getFloat(9);
    568         assertEquals(defaultF, output);
    569 
    570         output = res.getFloat(10);
    571         assertEquals(defaultF, output);
    572     }
    573 
    574     public void testGetFloatString() throws SQLException {
    575         float defaultF = 0.0f;
    576         String[] input = {"RealVal", "DoubleVal", "FloatVal"};
    577         float[] inputF = {3.9f, 23.2f, 33.3f};
    578 
    579         float output = res.getFloat(input[0]);
    580         assertEquals(inputF[0], output);
    581 
    582         output = res.getFloat(input[1]);
    583         assertEquals(inputF[1], output);
    584 
    585         output = res.getFloat(input[2]);
    586         assertEquals(inputF[2], output);
    587 
    588         try {
    589             res.getFloat(500);
    590             fail("Exception expected");
    591         } catch (SQLException e) {
    592             //ok
    593         }
    594 
    595         res.next();
    596         output = res.getFloat(8);
    597         assertEquals(defaultF, output);
    598 
    599         output = res.getFloat(9);
    600         assertEquals(defaultF, output);
    601 
    602         output = res.getFloat(10);
    603         assertEquals(defaultF, output);
    604     }
    605 
    606     public void testGetIntInt() throws SQLException {
    607         // real input val -1, 22, 2, 33,3, 1, 2
    608         List<Integer> input = Arrays.asList(1, -1, 22, 2, 33,3, 1, 2);
    609         ListIterator<Integer> it = input.listIterator();
    610         Double test2 = new Double(23.2);
    611         for (int i = 1;i<9;i++ ) {
    612             assertEquals(it.next().intValue(),res.getInt(i));
    613         }
    614 
    615         try {
    616             res.getInt(500);
    617             fail("Exception expected");
    618         } catch (SQLException e) {
    619             //ok
    620         }
    621 
    622         res.next();
    623         for (int i = 2;i<11;i++ ) {
    624             assertEquals(0,res.getInt(i));
    625         }
    626     }
    627 
    628     public void testGetIntString() throws SQLException {
    629         List<String> inputS = Arrays.asList("BoolVal", "IntVal", "LongVal",
    630                 "Bint", "Tint", "Sint", "Mint", "IntegerVal");
    631         ListIterator<String> itS = inputS.listIterator();
    632         List<Integer> input = Arrays.asList(1, -1, 22, 2, 33, 3, 1, 2);
    633         ListIterator<Integer> it = input.listIterator();
    634         while (it.hasNext()) {
    635             assertEquals(it.next().intValue(), res.getInt(itS.next()));
    636         }
    637 
    638         try {
    639             res.getInt("bla");
    640             fail("Exception expected");
    641         } catch (SQLException e) {
    642             //ok
    643         }
    644 
    645         res.next();
    646         for (String s : inputS) {
    647             assertEquals(0, res.getInt(s));
    648         }
    649     }
    650 
    651     public void testGetLongInt() throws SQLException {
    652         long maxVal = Long.MAX_VALUE;
    653         long minVal = Long.MIN_VALUE;
    654 
    655         assertEquals(maxVal, res.getLong(27));
    656         assertEquals(minVal, res.getLong(28));
    657 
    658         try {
    659             res.getInt(500);
    660             fail("Exception expected");
    661         } catch (SQLException e) {
    662             //ok
    663         }
    664 
    665         res.next();
    666         assertEquals(0, res.getLong(27));
    667         assertEquals(0, res.getLong(28));
    668     }
    669 
    670     public void testGetLongString() throws SQLException {
    671         long maxVal = Long.MAX_VALUE;
    672         long minVal = Long.MIN_VALUE;
    673         assertEquals(maxVal, res.getLong("MaxLongVal"));
    674         assertEquals(minVal, res.getLong("MinLongVal"));
    675 
    676         try {
    677             res.getInt("bla");
    678             fail("Exception expected");
    679         } catch (SQLException e) {
    680             //ok
    681         }
    682 
    683         res.next();
    684         assertEquals(0,res.getLong("MaxLongVal"));
    685         assertEquals(0,res.getLong("MinLongVal"));
    686     }
    687 
    688     /**
    689      * Test method for {@link java.sql.ResultSet#getMetaData()}.
    690      * type mappings according to
    691      * http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame8.html
    692      * Not supported datatypes are not checked.
    693      *
    694      * Wrong value returned for Long: java.lang.String (VARCHAR)
    695      */
    696     public void testGetMetaData() throws SQLException {
    697         /*
    698          * List<String> types = Arrays.asList("BOOLEAN", "INT", "LONG",
    699          * "BIGINT", "TINYINT", "SMALLINT", "MEDIUMINT", "INTEGER", "REAL",
    700          * "DOUBLE", "FLOAT", "DECIMAL", "NUMERIC", "CHAR(20)", "DATE", "TIME",
    701          * "TIMESTAMP", "DATETIME", "TINYBLOB", "BLOB", "MEDIUMBLOB",
    702          * "LONGBLOB", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "BIGINT",
    703          * "BIGINT","URL","URL");
    704          */
    705         List<String> types = Arrays.asList("VARCHAR", "INTEGER", "INTEGER",
    706                 "BIGINT", "SMALLINT", "SHORT", "INTEGER", "INTEGER", "FLOAT",
    707                 "DOUBLE", "DOUBLE", "DECIMAL", "NUMERIC", "VARCHAR", "DATE",
    708                 "TIME", "TIMESTAMP", "DATETIME", "BLOB", "BLOB", "BLOB",
    709                 "BLOB", "VARCHAR", "VARCHAR", "VARCHAR", "VARCHAR", "BIGINT",
    710                 "BIGINT", "URL", "URL");
    711 
    712 
    713 
    714         ListIterator<String> it = types.listIterator();
    715         ListIterator<String> colNameIt = colNames.listIterator();
    716         ResultSetMetaData meta = res.getMetaData();
    717         assertNotNull(meta);
    718         assertEquals("Error in test setup. Columns do not match", types
    719                 .size(), meta.getColumnCount());
    720         for (int i = 1; i < 31; i++) {
    721             String colName = colNameIt.next();
    722             String type = it.next();
    723             if (supported[i - 1]) {
    724                 assertTrue("Wrong column name at " + i, colName
    725                         .equalsIgnoreCase(meta.getColumnName(i)));
    726                 assertTrue("Wrong type at " + i+" required" +type+ " but is "+meta.getColumnTypeName(i), type.equalsIgnoreCase(meta
    727                         .getColumnTypeName(i)));
    728             }
    729         }
    730     }
    731 
    732     // Wrong value returned for Long: java.lang.String
    733     public void testGetObjectInt() throws SQLException {
    734         for (int i = 1; i <= typeMap.length; i++) {
    735             if (supported[i-1]) {
    736                 Object value = res.getObject(i);
    737                 assertTrue("value " + value.getClass().getName()
    738                         + " does not correspond " + typeMap[i-1] + "at "+i, value
    739                         .getClass().equals(typeMap[i-1]));
    740             }
    741         }
    742 
    743         try {
    744             res.getObject(500);
    745             fail("Exception expected");
    746         } catch (SQLException e) {
    747             //ok
    748         }
    749 
    750         res.next();
    751         for (int i = 1; i <= typeMap.length; i++) {
    752             Object value = res.getObject(i);
    753             assertNull(value);
    754         }
    755     }
    756 
    757     // Wrong value returned for Long: java.lang.String
    758     public void testGetObjectString() throws SQLException {
    759         ListIterator<String> colNameIt = colNames.listIterator();
    760         for (int i = 1; i <= typeMap.length; i++) {
    761             String name = colNameIt.next();
    762             if (supported[i-1]) {
    763                 Object value = res.getObject(name);
    764                 assertTrue("value " + value.getClass().getName()
    765                         + " for "+name+" does not correspond " + typeMap[i-1] + "at "+i, value
    766                         .getClass().equals(typeMap[i-1]));
    767             }
    768         }
    769 
    770         try {
    771             res.getObject("bla");
    772             fail("Exception expected");
    773         } catch (SQLException e) {
    774             //ok
    775         }
    776 
    777 
    778         colNameIt = colNames.listIterator();
    779         res.next();
    780         for (int i = 1; i <= typeMap.length; i++) {
    781                 Object value = res.getObject(colNameIt.next());
    782                assertNull(value);
    783         }
    784     }
    785 
    786     // If there is no current row 0 must be returned. res.close() does not wrap up
    787     public void testGetRow() throws SQLException {
    788         assertEquals(1, res.getRow());
    789         assertTrue(res.isFirst());
    790         res.next();
    791         assertEquals(2, res.getRow());
    792         assertTrue(res.isLast());
    793         res.next();
    794         assertTrue(res.isAfterLast());
    795         assertEquals(0, res.getRow());
    796 
    797         try {
    798             res.close();
    799             res.getRow();
    800         } catch (SQLException e) {
    801             // ok
    802         }
    803     }
    804 
    805     public void testGetShortInt() throws SQLException {
    806         short shorty = res.getShort(6);
    807         assertEquals(3,shorty);
    808 
    809         res.next();
    810         shorty = res.getShort(6);
    811         assertEquals(0,shorty);
    812 
    813         try {
    814             res.getShort(500);
    815             fail("Exception expected");
    816         } catch (SQLException e) {
    817             //ok
    818         }
    819     }
    820 
    821     public void testGetShortString() throws SQLException {
    822         short shorty = res.getShort("Sint");
    823         assertEquals(3,shorty);
    824 
    825         res.next();
    826         shorty = res.getShort("Sint");
    827         assertEquals(0,shorty);
    828 
    829         try {
    830             res.getShort("bla");
    831             fail("Exception expected");
    832         } catch (SQLException e) {
    833             //ok
    834         }
    835     }
    836 
    837     /**
    838      * According to spec info.getStatement should return null but an exception
    839      * is thrown: stale result set.
    840      */
    841     public void testGetStatement() throws SQLException {
    842         DatabaseMetaData meta = conn.getMetaData();
    843         ResultSet info = meta.getTypeInfo();
    844         Statement statement2 = info.getStatement();
    845         assertNull(statement2);
    846 
    847         statement2 = res.getStatement();
    848         assertEquals(st, statement2);
    849 
    850        // exception testing
    851         try {
    852             res.close();
    853             res.getStatement();
    854             fail("Exception expected");
    855         } catch (SQLException e) {
    856             //ok
    857         }
    858     }
    859 
    860     public void testGetStringInt() throws SQLException {
    861         List<String> texts = Arrays.asList("Test text message tiny",
    862                 "Test text", "Test text message medium",
    863                 "Test text message long");
    864         int i = 23;
    865 
    866         //text and exception testing
    867         for (String t : texts) {
    868             assertEquals(t, res.getString(i));
    869             i++;
    870         }
    871 
    872         // the rest: everything should work with getString
    873 
    874         texts = Arrays.asList("1", "-1", "22", "2", "33",
    875          "3","1","2","3.9","23.2","33.3","44",
    876         "5", "test string", "1799-05-26", "12:35:45", "2007-10-09 14:28:02.0",
    877         "1221-09-22 10:11:55","1","2","3","4");
    878         i= 1;
    879 
    880         for (String t : texts) {
    881             assertEquals(t, res.getString(i));
    882             i++;
    883         }
    884 
    885         //null testing
    886         i = 1;
    887         res.next();
    888         for (String t : values) {
    889             assertNull(res.getString(i));
    890             i++;
    891         }
    892 
    893         // exception testing
    894         try {
    895             res.getString(500);
    896             fail("Exception expected");
    897         } catch (SQLException e) {
    898             //ok
    899         }
    900 
    901     }
    902 
    903     public void testGetStringString() throws SQLException {
    904         ListIterator<String> colNameIt = colNames.listIterator();
    905         for (String t : values) {
    906             assertEquals(t, res.getString(colNameIt.next()));
    907         }
    908 
    909         res.next();
    910         for (String name: colNames) {
    911             assertNull(res.getString(name));
    912         }
    913 
    914         try {
    915             res.getString("bla");
    916             fail("Exception expected");
    917         } catch (SQLException e) {
    918             //ok
    919         }
    920     }
    921 
    922     // getTime should return Time value for a TIMESTAMP type but returns null
    923     public void testGetTimeInt() throws SQLException {
    924         // values "12:35:45", "2007-10-09 14:28:02.0", "1221-09-22 10:11:55"
    925 
    926         Calendar cal = new GregorianCalendar();
    927         cal.clear();
    928         cal.set(Calendar.HOUR_OF_DAY, 12);
    929         cal.set(Calendar.MINUTE, 35);
    930         cal.set(Calendar.SECOND, 45);
    931         cal.set(Calendar.MILLISECOND, 0);
    932         // set with calendar value (correct init time: since epoch)
    933         long millis = cal.getTime().getTime();
    934         Time t1 = new java.sql.Time(millis);
    935         assertNotNull("t1", t1);
    936 
    937 
    938         Calendar cal2 = new GregorianCalendar();
    939         cal2.set(Calendar.YEAR, 2007);
    940         cal2.set(Calendar.MONTH, Calendar.OCTOBER);
    941         cal2.set(Calendar.DATE, 9);
    942         cal2.set(Calendar.HOUR_OF_DAY, 14);
    943         cal2.set(Calendar.MINUTE, 28);
    944         cal2.set(Calendar.SECOND, 02);
    945         cal2.set(Calendar.MILLISECOND, 0);
    946 
    947         long millis2 = cal2.getTime().getTime();
    948         Time t2 = new java.sql.Time(millis2);
    949 
    950         int i = 16;
    951 
    952         Time resTime = res.getTime(i);
    953         assertNotNull("Pos " + i + " null", resTime);
    954         assertEquals(t1.toString(), resTime.toString());
    955         assertEquals(t1.getTime(), resTime.getTime());
    956         assertEquals(t1, resTime);
    957         // Compatibility Test: TIMESTAMP value
    958         i = 17;
    959 
    960         resTime = res.getTime(i);
    961         assertNotNull("Pos " + i + " null", resTime);
    962         assertEquals(t2.toString(), resTime.toString());
    963         assertEquals(t2.getTime(), resTime.getTime());
    964         assertEquals(t2, resTime);
    965 
    966         i = 16;
    967         res.next();
    968         assertNull(res.getTime(i));
    969 
    970         try {
    971             res.getTime(500);
    972             fail("Exception expected");
    973         } catch (SQLException e) {
    974             // ok
    975         }
    976     }
    977 
    978      // getTime on TIMESTAMP value fails: returns null
    979     public void testGetTimeIntCalendar() throws SQLException {
    980         List<Time> times = new LinkedList<Time>();
    981         List<Calendar> cals = new LinkedList<Calendar>();
    982         // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0",
    983         // "1221-09-22 10:11:55");
    984 
    985         Calendar cal1 = new GregorianCalendar();
    986         cal1.clear();
    987         cal1.set(Calendar.HOUR_OF_DAY, 12);
    988         cal1.set(Calendar.MINUTE, 35);
    989         cal1.set(Calendar.SECOND, 45);
    990         cal1.set(Calendar.MILLISECOND, 0);
    991 
    992         long millis = cal1.getTime().getTime();
    993         Time t1 = new java.sql.Time(millis);
    994 
    995         Calendar cal2 = new GregorianCalendar();
    996         cal2.set(Calendar.YEAR, 2007);
    997         cal2.set(Calendar.MONTH, Calendar.OCTOBER);
    998         cal2.set(Calendar.DATE, 9);
    999         cal2.set(Calendar.HOUR_OF_DAY, 14);
   1000         cal2.set(Calendar.MINUTE, 28);
   1001         cal2.set(Calendar.SECOND, 02);
   1002         cal2.set(Calendar.MILLISECOND, 0);
   1003 
   1004         long millis2 = cal2.getTime().getTime();
   1005         Time t2 = new java.sql.Time(millis2);
   1006 
   1007         // TIME value
   1008 
   1009         int i = 16;
   1010 
   1011         Time timeRes = res.getTime(i,new GregorianCalendar());
   1012         assertNotNull(timeRes);
   1013         assertEquals(t1.toString(), timeRes.toString());
   1014         assertEquals(t1.getTime(), timeRes.getTime());
   1015         assertEquals(t1, timeRes);
   1016 
   1017         // TIMESTAMP value
   1018         i = 17;
   1019 
   1020          timeRes = res.getTime(i,new GregorianCalendar());
   1021          assertNotNull(timeRes);
   1022          assertEquals(t2.toString(), timeRes.toString());
   1023          assertEquals(t2.getTime(), timeRes.getTime());
   1024          assertEquals(t2, timeRes);
   1025 
   1026          res.next();
   1027          for (Calendar c : cals) {
   1028              assertNull(res.getTime(16,c));
   1029              i++;
   1030          }
   1031 
   1032         try {
   1033             res.getTime(500,Calendar.getInstance());
   1034             fail("Exception expected");
   1035         } catch (SQLException e) {
   1036             //ok
   1037         }
   1038     }
   1039 
   1040     // getTime should return a Time value for a TIMESTAMP type but returns null
   1041     public void testGetTimeString() throws SQLException {
   1042         List<Time> times = new LinkedList<Time>();
   1043 
   1044         List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT");
   1045         Iterator<String> it = stringTimes.iterator();
   1046 
   1047         // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0",
   1048         // "1221-09-22 10:11:55");
   1049 
   1050         Calendar cal = new GregorianCalendar();
   1051         cal.clear();
   1052         cal.set(Calendar.HOUR_OF_DAY, 12);
   1053         cal.set(Calendar.MINUTE, 35);
   1054         cal.set(Calendar.SECOND, 45);
   1055         cal.set(Calendar.MILLISECOND, 0);
   1056 
   1057         long millis = cal.getTime().getTime();
   1058         Time t1 = new java.sql.Time(millis);
   1059 
   1060         String col = it.next();
   1061 
   1062         Time timeRes = res.getTime(col);
   1063         assertNotNull(timeRes);
   1064         assertEquals(t1.toString(), timeRes.toString());
   1065         assertEquals(t1.getTime(), timeRes.getTime());
   1066         assertEquals(t1, timeRes);
   1067 
   1068         Calendar cal2 = new GregorianCalendar();
   1069         cal2.set(Calendar.YEAR, 2007);
   1070         cal2.set(Calendar.MONTH, Calendar.OCTOBER);
   1071         cal2.set(Calendar.DATE, 9);
   1072         cal2.set(Calendar.HOUR_OF_DAY, 14);
   1073         cal2.set(Calendar.MINUTE, 28);
   1074         cal2.set(Calendar.SECOND, 02);
   1075         cal2.set(Calendar.MILLISECOND, 0);
   1076 
   1077         long millis2 = cal.getTime().getTime();
   1078         Time t2 = new java.sql.Time(millis2);
   1079 
   1080         col = it.next();
   1081 
   1082         timeRes = res.getTime(col);
   1083         assertNotNull(timeRes);
   1084         assertEquals(t2.toString(), timeRes.toString());
   1085         assertEquals(t2.getTime(), timeRes.getTime());
   1086         assertEquals(t2, timeRes);
   1087 
   1088         res.next();
   1089         assertNull(res.getTime(col));
   1090 
   1091         try {
   1092             res.getTime("bla");
   1093             fail("Exception expected");
   1094         } catch (SQLException e) {
   1095             //ok
   1096         }
   1097     }
   1098 
   1099     // getTime on TIMESTAMP value fails: returns null
   1100     public void testGetTimeStringCalendar() throws SQLException {
   1101         List<Time> times = new LinkedList<Time>();
   1102 
   1103         List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT");
   1104         Iterator<String> it = stringTimes.iterator();
   1105         List<Calendar> cals = new LinkedList<Calendar>();
   1106 
   1107         // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0",
   1108         // "1221-09-22 10:11:55");
   1109 
   1110         Calendar cal1 = new GregorianCalendar();
   1111         cal1.clear();
   1112         cal1.set(Calendar.HOUR_OF_DAY, 12);
   1113         cal1.set(Calendar.MINUTE, 35);
   1114         cal1.set(Calendar.SECOND, 45);
   1115         cal1.set(Calendar.MILLISECOND, 0);
   1116 
   1117         long millis = cal1.getTime().getTime();
   1118         Time t1 = new java.sql.Time(millis);
   1119 
   1120         Calendar cal2 = new GregorianCalendar();
   1121         cal2.set(Calendar.YEAR, 2007);
   1122         cal2.set(Calendar.MONTH, Calendar.OCTOBER);
   1123         cal2.set(Calendar.DATE, 9);
   1124         cal2.set(Calendar.HOUR_OF_DAY, 14);
   1125         cal2.set(Calendar.MINUTE, 28);
   1126         cal2.set(Calendar.SECOND, 02);
   1127         cal2.set(Calendar.MILLISECOND, 0);
   1128 
   1129         long millis2 = cal2.getTime().getTime();
   1130         Time t2 = new java.sql.Time(millis2);
   1131 
   1132         // TIME value
   1133         String col = it.next();
   1134 
   1135         Time timeRes = res.getTime(col, new GregorianCalendar());
   1136         assertNotNull(timeRes);
   1137         assertEquals(t1.toString(), timeRes.toString());
   1138         assertEquals(t1.getTime(), timeRes.getTime());
   1139         assertEquals(t1, res.getTime(col));
   1140         //TIMESTAMP value
   1141         col = it.next();
   1142 
   1143         timeRes = res.getTime(col, new GregorianCalendar());
   1144         assertNotNull(timeRes);
   1145         assertEquals(t2.toString(), timeRes.toString());
   1146         assertEquals(t2.getTime(), timeRes.getTime());
   1147         assertEquals(t2, res.getTime(col));
   1148 
   1149         res.next();
   1150         assertNull(res.getTime(stringTimes.get(0), new GregorianCalendar()));
   1151 
   1152         try {
   1153             res.getTime("bla");
   1154             fail("Exception expected");
   1155         } catch (SQLException e) {
   1156             // ok
   1157         }
   1158     }
   1159 
   1160     public void testGetTimestampInt() throws SQLException {
   1161         List<Timestamp> times = new LinkedList<Timestamp>();
   1162 
   1163         List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT");
   1164         Iterator<String> it = stringTimes.iterator();
   1165         List<Calendar> cals = new LinkedList<Calendar>();
   1166 
   1167         Calendar cal2 = new GregorianCalendar();
   1168         cal2.set(Calendar.YEAR, 2007);
   1169         cal2.set(Calendar.MONTH, Calendar.OCTOBER);
   1170         cal2.set(Calendar.DATE, 9);
   1171         cal2.set(Calendar.HOUR_OF_DAY, 14);
   1172         cal2.set(Calendar.MINUTE, 28);
   1173         cal2.set(Calendar.SECOND, 02);
   1174         cal2.set(Calendar.MILLISECOND, 0);
   1175 
   1176         long millis = cal2.getTime().getTime();
   1177         Timestamp t2 = new Timestamp(millis);
   1178         times.add(t2);
   1179 
   1180         Calendar cal3 = new GregorianCalendar();
   1181         cal3.set(Calendar.YEAR, 1221);
   1182         cal3.set(Calendar.MONTH, Calendar.SEPTEMBER);
   1183         cal3.set(Calendar.DATE, 22);
   1184         cal3.set(Calendar.HOUR_OF_DAY, 10);
   1185         cal3.set(Calendar.MINUTE, 11);
   1186         cal3.set(Calendar.SECOND, 55);
   1187         cal3.set(Calendar.MILLISECOND, 0);
   1188 
   1189         millis = cal3.getTime().getTime();
   1190         Timestamp t3 = new Timestamp(millis);
   1191         times.add(t3);
   1192         // TIMESTAMP value
   1193         int i = 17;
   1194 
   1195         Timestamp timeRes = res.getTimestamp(i);
   1196         assertEquals(t2.toString(), timeRes.toString());
   1197         assertEquals(t2.getTime(), timeRes.getTime());
   1198         assertEquals(t2, timeRes);
   1199         // DATE value
   1200         i = 18;
   1201         timeRes = res.getTimestamp(i);
   1202         assertEquals(t3.toString(), timeRes.toString());
   1203         assertEquals(t3.getTime(), timeRes.getTime());
   1204         assertEquals(t3, timeRes);
   1205 
   1206         res.next();
   1207         assertNull(res.getTime(i));
   1208 
   1209         try {
   1210             res.getTime(500);
   1211             fail("Exception expected");
   1212         } catch (SQLException e) {
   1213             // ok
   1214         }
   1215     }
   1216 
   1217     public void testGetTimestampIntCalendar() throws SQLException {
   1218         List<Timestamp> times = new LinkedList<Timestamp>();
   1219 
   1220         List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT");
   1221         Iterator<String> it = stringTimes.iterator();
   1222 //        List<Calendar> cals = new LinkedList<Calendar>();
   1223 
   1224         Calendar cal2 = new GregorianCalendar();
   1225         cal2.set(Calendar.YEAR, 2007);
   1226         cal2.set(Calendar.MONTH, Calendar.OCTOBER);
   1227         cal2.set(Calendar.DATE, 9);
   1228         cal2.set(Calendar.HOUR_OF_DAY, 14);
   1229         cal2.set(Calendar.MINUTE, 28);
   1230         cal2.set(Calendar.SECOND, 02);
   1231         cal2.set(Calendar.MILLISECOND, 0);
   1232 
   1233         long millis = cal2.getTime().getTime();
   1234         Timestamp t2 = new Timestamp(millis);
   1235         times.add(t2);
   1236         //
   1237          Calendar cal3 = new GregorianCalendar();
   1238           cal3.set(Calendar.YEAR, 1221);
   1239           cal3.set(Calendar.MONTH, Calendar.SEPTEMBER);
   1240           cal3.set(Calendar.DATE, 22);
   1241          cal3.set(Calendar.HOUR_OF_DAY, 10);
   1242          cal3.set(Calendar.MINUTE, 11);
   1243          cal3.set(Calendar.SECOND, 55);
   1244          cal3.set(Calendar.MILLISECOND, 0);
   1245 
   1246          millis = cal3.getTime().getTime();
   1247          Timestamp t3 = new Timestamp(millis);
   1248          times.add(t3);
   1249 
   1250 //         cals.add(cal1);
   1251 //         cals.add(cal2);
   1252 //         cals.add(cal3);
   1253 //
   1254 //        ListIterator<Calendar> calIt = cals.listIterator();
   1255 
   1256         int i = 17;
   1257 
   1258         Timestamp timeRes = res.getTimestamp(i,new GregorianCalendar());
   1259         assertEquals(t2.toString(), timeRes.toString());
   1260         assertEquals(t2, timeRes);
   1261 
   1262         i = 18;
   1263 
   1264         timeRes = res.getTimestamp(i,new GregorianCalendar());
   1265         assertEquals(t3.toString(), timeRes.toString());
   1266         assertEquals(t3, timeRes);
   1267 
   1268         res.next();
   1269         assertNull(res.getTime(17,cal2));
   1270         assertNull(res.getTime(18,cal3));
   1271 
   1272         try {
   1273             res.getTime(500);
   1274             fail("Exception expected");
   1275         } catch (SQLException e) {
   1276             // ok
   1277         }
   1278     }
   1279 
   1280     public void testGetTimestampString() throws SQLException {
   1281         List<Timestamp> times = new LinkedList<Timestamp>();
   1282 
   1283         List<String> stringTimes = Arrays.asList( "TS", "DT");
   1284         Iterator<String> it = stringTimes.iterator();
   1285 //        List<Calendar> cals = new LinkedList<Calendar>();
   1286 
   1287         Calendar cal2 = new GregorianCalendar();
   1288         cal2.set(Calendar.YEAR, 2007);
   1289         cal2.set(Calendar.MONTH, Calendar.OCTOBER);
   1290         cal2.set(Calendar.DATE, 9);
   1291         cal2.set(Calendar.HOUR_OF_DAY, 14);
   1292         cal2.set(Calendar.MINUTE, 28);
   1293         cal2.set(Calendar.SECOND, 02);
   1294         cal2.set(Calendar.MILLISECOND, 0);
   1295 
   1296         long millis = cal2.getTime().getTime();
   1297         Timestamp t2 = new Timestamp(millis);
   1298         times.add(t2);
   1299         //
   1300          Calendar cal3 = new GregorianCalendar();
   1301           cal3.set(Calendar.YEAR, 1221);
   1302           cal3.set(Calendar.MONTH, Calendar.SEPTEMBER);
   1303           cal3.set(Calendar.DATE, 22);
   1304          cal3.set(Calendar.HOUR_OF_DAY, 10);
   1305          cal3.set(Calendar.MINUTE, 11);
   1306          cal3.set(Calendar.SECOND, 55);
   1307          cal3.set(Calendar.MILLISECOND, 0);
   1308 
   1309          millis = cal3.getTime().getTime();
   1310          Timestamp t3 = new Timestamp(millis);
   1311          times.add(t3);
   1312 
   1313         String col = it.next();
   1314 
   1315         Timestamp timeRes = res.getTimestamp(col);
   1316         assertEquals(t2.toString(), timeRes.toString());
   1317         assertEquals(t2.toString(), timeRes.toString());
   1318         assertEquals(t2.getTime(), timeRes.getTime());
   1319         assertEquals(t2, timeRes);
   1320         // DATE value
   1321         col = it.next();
   1322 
   1323         timeRes = res.getTimestamp(col);
   1324         assertEquals(t3.toString(), timeRes.toString());
   1325         assertEquals(t3.toString(), timeRes.toString());
   1326         assertEquals(t3.getTime(), timeRes.getTime());
   1327         assertEquals(t3, timeRes);
   1328 
   1329         res.next();
   1330         assertNull(res.getTime(stringTimes.get(0)));
   1331         assertNull(res.getTime(stringTimes.get(1)));
   1332 
   1333         try {
   1334             res.getTime(500);
   1335             fail("Exception expected");
   1336         } catch (SQLException e) {
   1337             // ok
   1338         }
   1339     }
   1340 
   1341     public void testGetTimestampStringCalendar() throws SQLException {
   1342         List<Timestamp> times = new LinkedList<Timestamp>();
   1343 
   1344         List<String> stringTimes = Arrays.asList( "TS", "DT");
   1345         Iterator<String> it = stringTimes.iterator();
   1346 
   1347         Calendar cal2 = new GregorianCalendar();
   1348         cal2.set(Calendar.YEAR, 2007);
   1349         cal2.set(Calendar.MONTH, Calendar.OCTOBER);
   1350         cal2.set(Calendar.DATE, 9);
   1351         cal2.set(Calendar.HOUR_OF_DAY, 14);
   1352         cal2.set(Calendar.MINUTE, 28);
   1353         cal2.set(Calendar.SECOND, 02);
   1354         cal2.set(Calendar.MILLISECOND, 0);
   1355 
   1356         long millis = cal2.getTime().getTime();
   1357         Timestamp t2 = new Timestamp(millis);
   1358         times.add(t2);
   1359         //
   1360          Calendar cal3 = new GregorianCalendar();
   1361           cal3.set(Calendar.YEAR, 1221);
   1362           cal3.set(Calendar.MONTH, Calendar.SEPTEMBER);
   1363           cal3.set(Calendar.DATE, 22);
   1364          cal3.set(Calendar.HOUR_OF_DAY, 10);
   1365          cal3.set(Calendar.MINUTE, 11);
   1366          cal3.set(Calendar.SECOND, 55);
   1367          cal3.set(Calendar.MILLISECOND, 0);
   1368 
   1369          millis = cal3.getTime().getTime();
   1370          Timestamp t3 = new Timestamp(millis);
   1371          times.add(t3);
   1372 
   1373         Timestamp timeRes = res.getTimestamp(stringTimes.get(0),cal2);
   1374         assertEquals(t2.toString(), timeRes.toString());
   1375         assertEquals(t2.getTime(), timeRes.getTime());
   1376         assertEquals(t2, timeRes);
   1377             // DATE value
   1378         timeRes = res.getTimestamp(stringTimes.get(1),cal3);
   1379         assertEquals(t3.toString(), timeRes.toString());
   1380         assertEquals(t3.getTime(), timeRes.getTime());
   1381         assertEquals(t3, timeRes);
   1382 
   1383         // calIt = cals.listIterator();
   1384 
   1385         res.next();
   1386         assertNull(res.getTime(stringTimes.get(0),cal2));
   1387         assertNull(res.getTime(stringTimes.get(1),cal3));
   1388 
   1389         try {
   1390             res.getTime(500);
   1391             fail("Exception expected");
   1392         } catch (SQLException e) {
   1393             // ok
   1394         }
   1395     }
   1396 
   1397     // res.close() does not wrap up
   1398     public void testGetType() throws SQLException {
   1399         assertEquals(ResultSet.TYPE_FORWARD_ONLY, res.getType());
   1400 
   1401         try {
   1402             st.close();
   1403             res.getType();
   1404             fail("Exception not thrown.");
   1405         } catch (SQLException e) {
   1406             //ok
   1407         }
   1408 
   1409     }
   1410 
   1411     public void testGetURLInt() throws SQLException, MalformedURLException {
   1412         URL input = new URL("http://www.android.com");
   1413         URL validURL = res.getURL(29);
   1414         assertEquals(input, validURL);
   1415 
   1416         try {
   1417             URL invalidURL = res.getURL(30);
   1418             assertNull(invalidURL);
   1419         } catch (SQLException e) {
   1420             // ok
   1421         }
   1422 
   1423         res.next();
   1424         assertNull(res.getURL(29));
   1425         assertNull(res.getURL(30));
   1426 
   1427         try {
   1428             res.getURL(500);
   1429             fail("Exception expected");
   1430         } catch (SQLException e) {
   1431             // ok
   1432         }
   1433     }
   1434 
   1435     public void testGetURLString() throws MalformedURLException, SQLException {
   1436         URL input = new URL("http://www.android.com");
   1437         URL validURL = res.getURL("validURL");
   1438         assertEquals(input, validURL);
   1439 
   1440         try {
   1441             URL invalidURL = res.getURL("invalidURL");
   1442             assertNull(invalidURL);
   1443         } catch (SQLException e) {
   1444             // ok
   1445         }
   1446 
   1447         res.next();
   1448         assertNull(res.getURL("validURL"));
   1449         assertNull(res.getURL("invalidURL"));
   1450 
   1451         try {
   1452             res.getURL("bla");
   1453             fail("Exception expected");
   1454         } catch (SQLException e) {
   1455             // ok
   1456         }
   1457     }
   1458 }
   1459