private void check(
     String input,
     Boolean isH2,
     String catalog,
     String schema,
     String table,
     String toString,
     String toStringTrue,
     String toStringFalse) {
   TableLocation location =
       isH2 == null ? TableLocation.parse(input) : TableLocation.parse(input, isH2);
   assertEquals(catalog, location.getCatalog());
   assertEquals(schema, location.getSchema());
   assertEquals(table, location.getTable());
   assertEquals(toString, location.toString());
   assertEquals(toStringTrue, location.toString(true));
   assertEquals(toStringFalse, location.toString(false));
 }
Exemple #2
0
 /**
  * Copy fields from table into a {@link org.h2.tools.SimpleResultSet}
  *
  * @param connection Active connection
  * @param rs Result set that will receive columns
  * @param tableLocation Import columns from this table
  * @throws SQLException Error
  */
 public static void copyFields(
     Connection connection, SimpleResultSet rs, TableLocation tableLocation) throws SQLException {
   DatabaseMetaData meta = connection.getMetaData();
   ResultSet columnsRs =
       meta.getColumns(
           tableLocation.getCatalog(null),
           tableLocation.getSchema(null),
           tableLocation.getTable(),
           null);
   Map<Integer, Object[]> columns = new HashMap<Integer, Object[]>();
   int COLUMN_NAME = 0,
       COLUMN_TYPE = 1,
       COLUMN_TYPENAME = 2,
       COLUMN_PRECISION = 3,
       COLUMN_SCALE = 4;
   try {
     while (columnsRs.next()) {
       Object[] columnInfoObjects = new Object[COLUMN_SCALE + 1];
       columnInfoObjects[COLUMN_NAME] = columnsRs.getString("COLUMN_NAME");
       columnInfoObjects[COLUMN_TYPE] = columnsRs.getInt("DATA_TYPE");
       columnInfoObjects[COLUMN_TYPENAME] = columnsRs.getString("TYPE_NAME");
       columnInfoObjects[COLUMN_PRECISION] = columnsRs.getInt("COLUMN_SIZE");
       columnInfoObjects[COLUMN_SCALE] = columnsRs.getInt("DECIMAL_DIGITS");
       columns.put(columnsRs.getInt("ORDINAL_POSITION"), columnInfoObjects);
     }
   } finally {
     columnsRs.close();
   }
   for (int i = 1; i <= columns.size(); i++) {
     Object[] columnInfoObjects = columns.get(i);
     rs.addColumn(
         (String) columnInfoObjects[COLUMN_NAME],
         (Integer) columnInfoObjects[COLUMN_TYPE],
         (String) columnInfoObjects[COLUMN_TYPENAME],
         (Integer) columnInfoObjects[COLUMN_PRECISION],
         (Integer) columnInfoObjects[COLUMN_SCALE]);
   }
 }
Exemple #3
0
 /**
  * Suffix a TableLocation
  *
  * @param inputTable Input table
  * @param suffix Suffix
  * @return suffixed TableLocation
  */
 public static TableLocation suffixTableLocation(TableLocation inputTable, String suffix) {
   return new TableLocation(
       inputTable.getCatalog(), inputTable.getSchema(), inputTable.getTable() + suffix);
 }