OmniSciDB  5ade3759e0
OmniSciColumnTypeTest.java
Go to the documentation of this file.
1 package com.omnisci.jdbc;
2 
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotEquals;
5 
6 import org.junit.Test;
7 
8 import java.sql.*;
9 import java.util.HashMap;
10 import java.util.Properties;
11 
12 import javax.xml.transform.Result;
13 
14 public class OmniSciColumnTypeTest {
15  static Properties PROPERTIES = new Property_loader("type_test.properties");
16  static final String url = PROPERTIES.getProperty("default_db_connection_url");
17  static final String user = PROPERTIES.getProperty("default_super_user");
18  static final String password = PROPERTIES.getProperty("default_user_password");
19  private class Answer {
20  public Answer(int t, String n) {
21  type = t;
22  name = n;
23  }
24  public int type;
25  public String name;
26  }
27  private Answer[] answers = {new Answer(java.sql.Types.INTEGER, "INT"),
28  new Answer(java.sql.Types.FLOAT, "FLOAT"),
29  new Answer(java.sql.Types.OTHER, "POINT"),
30  new Answer(java.sql.Types.OTHER, "LINESTRING"),
31  new Answer(java.sql.Types.OTHER, "POLYGON"),
32  new Answer(java.sql.Types.OTHER, "MULTIPOLYGON")};
33  /* Test the basic connection and methods functionality */
34  @Test
35  public void tst1_types() throws Exception {
36  Connection conn = DriverManager.getConnection(url, user, password);
37  assertNotEquals(null, conn);
38  Statement statement = conn.createStatement();
39  try {
40  statement.executeUpdate(PROPERTIES.getProperty("drop_base_db"));
41  } catch (SQLException sQ) {
42  }
43 
44  statement.executeUpdate(PROPERTIES.getProperty("create_base_db"));
45  statement.close();
46  conn.close();
47  conn = DriverManager.getConnection(
48  PROPERTIES.getProperty("base_db_connection_url"), user, password);
49  statement = conn.createStatement();
50  statement.executeUpdate(PROPERTIES.getProperty("drop_base_table1"));
51  statement.executeUpdate(PROPERTIES.getProperty("create_base_table1"));
52 
53  ResultSet rs = statement.executeQuery(PROPERTIES.getProperty("select_base_table1"));
54  ResultSetMetaData rs_md = rs.getMetaData();
55  int col_cnt = rs_md.getColumnCount();
56  while (col_cnt > 0) {
57  int type = rs_md.getColumnType(col_cnt);
58  String name = rs_md.getColumnTypeName(col_cnt--);
59  assertEquals(type, answers[col_cnt].type);
60  assertEquals(name, answers[col_cnt].name);
61  }
62  statement.executeUpdate(PROPERTIES.getProperty("drop_base_table1"));
63  statement.executeUpdate(PROPERTIES.getProperty("drop_base_db"));
64  }
65 }