/** * Add a column in the table specified in input. A connection is obtained to the database * and automatically released after the addition of the column. * @param database the database to use * @param tableName the table where to add the column * @param columnName the column to add * @param type the type * @throws SQLException if there is a database problem */ public static void addColumn(Database database, String tableName, String columnName, Type type) throws SQLException { Connection connection = database.getConnection(); if (DatabaseUtil.tableExists(connection, tableName)) { try { addColumn(connection, tableName, columnName, type); } finally { connection.close(); } } }
/** * Add a column in the table specified in input. A connection is obtained to the database * and automatically released after the addition of the column. * @param database the database to use * @param tableName the table where to add the column * @param columnName the column to add * @param type the type * @throws SQLException if there is a database problem */ public static void addColumn(Database database, String tableName, String columnName, Type type) throws SQLException { Connection connection = database.getConnection(); if (DatabaseUtil.tableExists(connection, tableName)) { try { addColumn(connection, tableName, columnName, type); } finally { connection.close(); } } }
DatabaseUtil.addColumn(db, "savedbag", "intermine_state", DatabaseUtil.Type.text); DatabaseUtil.updateColumnValue(db, "savedbag", "intermine_state",
DatabaseUtil.addColumn(db, "savedbag", "intermine_state", DatabaseUtil.Type.text); DatabaseUtil.updateColumnValue(db, "savedbag", "intermine_state",
DatabaseUtil.addColumn(connection, "bagvalues", "extra", DatabaseUtil.Type.text); String sqlDeleteIndex = "DROP INDEX bagvalues_index1"; try {
DatabaseUtil.addColumn(connection, "bagvalues", "extra", DatabaseUtil.Type.text); String sqlDeleteIndex = "DROP INDEX bagvalues_index1"; try {
DatabaseUtil.addColumn(con, "FOO", "bar", DatabaseUtil.Type.integer); fail("An exception should have been thrown"); } catch (IllegalArgumentException e) { DatabaseUtil.addColumn(con, "table1", "BAR", DatabaseUtil.Type.integer); fail("An exception should have been thrown"); } catch (IllegalArgumentException e) { DatabaseUtil.addColumn(con, "table1", "col1", DatabaseUtil.Type.integer); assertTrue(DatabaseUtil.columnExists(con, "table1", "col1")); DatabaseUtil.addColumn(con, "table1", "col2", DatabaseUtil.Type.integer); assertTrue(DatabaseUtil.columnExists(con, "table1", "col2")); DatabaseUtil.updateColumnValue(db, "table1", "col2", 2); DatabaseUtil.addColumn(con, "table1", "col3", DatabaseUtil.Type.text); DatabaseUtil.updateColumnValue(db, "table1", "col3", "bar");