comparison tests/Test_Rbooleans.java @ 0:a5a898f6886c

Copy of MonetDB java directory changeset e6e32756ad31.
author Sjoerd Mullender <sjoerd@acm.org>
date Wed, 21 Sep 2016 09:34:48 +0200 (2016-09-21)
parents
children 04fbf3655452
comparison
equal deleted inserted replaced
-1:000000000000 0:a5a898f6886c
1 /*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V.
7 */
8
9 import java.sql.*;
10
11 public class Test_Rbooleans {
12 public static void main(String[] args) throws Exception {
13 Class.forName("nl.cwi.monetdb.jdbc.MonetDriver");
14 Connection con = DriverManager.getConnection(args[0]);
15 Statement stmt = con.createStatement();
16 ResultSet rs = null;
17 //DatabaseMetaData dbmd = con.getMetaData();
18
19 con.setAutoCommit(false);
20 // >> false: auto commit should be off now
21 System.out.println("0. false\t" + con.getAutoCommit());
22
23 try {
24 stmt.executeUpdate("CREATE TABLE table_Test_Rbooleans ( id int, tiny_int tinyint, small_int smallint, medium_int mediumint, \"integer\" int, big_int bigint, a_real real, a_float float, a_double double, a_decimal decimal(8,2), a_numeric numeric(8), bool boolean, a_char char(4), b_char char(5), a_varchar varchar(20), PRIMARY KEY (id) )");
25
26 // all falses
27 stmt.executeUpdate("INSERT INTO table_Test_Rbooleans VALUES (1, 0, 0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0, false, 'fals', 'false', 'false')");
28 // all trues
29 stmt.executeUpdate("INSERT INTO table_Test_Rbooleans VALUES (2, 1, 1, 1, 1, 1, 1.0, 1.0, 1.0, 1.0, 1, true, 'true', 'true ', 'true')");
30 // sneakier
31 stmt.executeUpdate("INSERT INTO table_Test_Rbooleans VALUES (3, 2, 3, 4, 5, 6, 7.1, 8.2, 9.3, 10.4, 11, true, 'TrUe', 'fAlSe', 'true/false')");
32 stmt.executeUpdate("INSERT INTO table_Test_Rbooleans VALUES (4, 2, 3, 4, 5, 6, 7.1, 8.2, 9.3, 10.4, 11, true, 't ', 'f ', 'TRUE ')");
33
34 rs = stmt.executeQuery("SELECT * FROM table_Test_Rbooleans ORDER BY id ASC");
35
36 // all should give false
37 rs.next();
38 System.out.println("1. " + rs.getInt("id") + ", " + rs.getBoolean("tiny_int") + ", " + rs.getBoolean("small_int") + ", " + rs.getBoolean("medium_int") + ", " + rs.getBoolean("integer") + ", " + rs.getBoolean("big_int") + ", " + rs.getBoolean("a_real") + ", " + rs.getBoolean("a_double") + ", " + rs.getBoolean("a_decimal") + ", " + rs.getBoolean("a_numeric") + ", " + rs.getBoolean("bool") + ", " + rs.getBoolean("a_char") + ", " + rs.getBoolean("b_char") + ", " + rs.getBoolean("a_varchar"));
39 // all should give true except the one before last
40 rs.next();
41 System.out.println("2. " + rs.getInt("id") + ", " + rs.getBoolean("tiny_int") + ", " + rs.getBoolean("small_int") + ", " + rs.getBoolean("medium_int") + ", " + rs.getBoolean("integer") + ", " + rs.getBoolean("big_int") + ", " + rs.getBoolean("a_real") + ", " + rs.getBoolean("a_double") + ", " + rs.getBoolean("a_decimal") + ", " + rs.getBoolean("a_numeric") + ", " + rs.getBoolean("bool") + ", " + rs.getBoolean("a_char") + ", " + rs.getBoolean("b_char") + ", " + rs.getBoolean("a_varchar"));
42 // should give true for all but the last two
43 rs.next();
44 System.out.println("3. " + rs.getInt("id") + ", " + rs.getBoolean("tiny_int") + ", " + rs.getBoolean("small_int") + ", " + rs.getBoolean("medium_int") + ", " + rs.getBoolean("integer") + ", " + rs.getBoolean("big_int") + ", " + rs.getBoolean("a_real") + ", " + rs.getBoolean("a_double") + ", " + rs.getBoolean("a_decimal") + ", " + rs.getBoolean("a_numeric") + ", " + rs.getBoolean("bool") + ", " + rs.getBoolean("a_char") + ", " + rs.getBoolean("b_char") + ", " + rs.getBoolean("a_varchar"));
45 // should give true for all but the last three
46 rs.next();
47 System.out.println("4. " + rs.getInt("id") + ", " + rs.getBoolean("tiny_int") + ", " + rs.getBoolean("small_int") + ", " + rs.getBoolean("medium_int") + ", " + rs.getBoolean("integer") + ", " + rs.getBoolean("big_int") + ", " + rs.getBoolean("a_real") + ", " + rs.getBoolean("a_double") + ", " + rs.getBoolean("a_decimal") + ", " + rs.getBoolean("a_numeric") + ", " + rs.getBoolean("bool") + ", " + rs.getBoolean("a_char") + ", " + rs.getBoolean("b_char") + ", " + rs.getBoolean("a_varchar"));
48 } catch (SQLException e) {
49 System.out.println("failed :( "+ e.getMessage());
50 System.out.println("ABORTING TEST!!!");
51 }
52
53 con.rollback();
54 con.close();
55 }
56 }