Class AlterTable


  • public class AlterTable
    extends Object
    Builds and performs alter table statements
    Since:
    3.3.0
    Author:
    osbornb
    • Constructor Detail

      • AlterTable

        public AlterTable()
    • Method Detail

      • alterTable

        public static String alterTable​(String table)
        Create the ALTER TABLE SQL command prefix
        Parameters:
        table - table name
        Returns:
        alter table SQL prefix
      • renameTable

        public static void renameTable​(GeoPackageCoreConnection db,
                                       String tableName,
                                       String newTableName)
        Rename a table
        Parameters:
        db - connection
        tableName - table name
        newTableName - new table name
      • renameTableSQL

        public static String renameTableSQL​(String tableName,
                                            String newTableName)
        Create the rename table SQL
        Parameters:
        tableName - table name
        newTableName - new table name
        Returns:
        rename table SQL
      • renameColumn

        public static void renameColumn​(GeoPackageCoreConnection db,
                                        String tableName,
                                        String columnName,
                                        String newColumnName)
        Rename a column
        Parameters:
        db - connection
        tableName - table name
        columnName - column name
        newColumnName - new column name
      • renameColumnSQL

        public static String renameColumnSQL​(String tableName,
                                             String columnName,
                                             String newColumnName)
        Create the rename column SQL
        Parameters:
        tableName - table name
        columnName - column name
        newColumnName - new column name
        Returns:
        rename table SQL
      • addColumn

        public static void addColumn​(GeoPackageCoreConnection db,
                                     String tableName,
                                     String columnName,
                                     String columnDef)
        Add a column
        Parameters:
        db - connection
        tableName - table name
        columnName - column name
        columnDef - column definition
      • addColumnSQL

        public static String addColumnSQL​(String tableName,
                                          String columnName,
                                          String columnDef)
        Create the add column SQL
        Parameters:
        tableName - table name
        columnName - column name
        columnDef - column definition
        Returns:
        add column SQL
      • dropColumn

        public static void dropColumn​(GeoPackageCoreConnection db,
                                      String tableName,
                                      String columnName)
        Drop a column
        Parameters:
        db - connection
        tableName - table name
        columnName - column name
      • alterColumn

        public static <T extends UserColumn> void alterColumn​(GeoPackageCoreConnection db,
                                                              UserTable<T> table,
                                                              T column)
        Alter a column
        Type Parameters:
        T - user column type
        Parameters:
        db - connection
        table - table
        column - column
      • copyTable

        public static void copyTable​(GeoPackageCoreConnection db,
                                     UserTable<? extends UserColumn> table,
                                     String newTableName,
                                     boolean transferContent)
        Copy the table
        Parameters:
        db - connection
        table - table
        newTableName - new table name
        transferContent - transfer row content to the new table
      • copyTable

        public static void copyTable​(GeoPackageCoreConnection db,
                                     String tableName,
                                     String newTableName)
        Copy the table and row content
        Parameters:
        db - connection
        tableName - table name
        newTableName - new table name
      • copyTable

        public static void copyTable​(GeoPackageCoreConnection db,
                                     String tableName,
                                     String newTableName,
                                     boolean transferContent)
        Copy the table
        Parameters:
        db - connection
        tableName - table name
        newTableName - new table name
        transferContent - transfer row content to the new table
      • alterTable

        public static void alterTable​(GeoPackageCoreConnection db,
                                      UserTable<? extends UserColumn> newTable)
        Alter a table with a new table schema assuming a default table mapping.

        This removes views on the table, creates a new table, transfers the old table data to the new, drops the old table, and renames the new table to the old. Indexes, triggers, and views that reference deleted columns are not recreated. An attempt is made to recreate the others including any modifications for renamed columns.

        Making Other Kinds Of Table Schema Changes:

        https://www.sqlite.org/lang_altertable.html

        Parameters:
        db - connection
        newTable - new table schema
      • alterTable

        public static void alterTable​(GeoPackageCoreConnection db,
                                      UserTable<? extends UserColumn> newTable,
                                      TableMapping tableMapping)
        Alter a table with a new table schema and table mapping.

        Altering a table: Removes views on the table, creates a new table, transfers the old table data to the new, drops the old table, and renames the new table to the old. Indexes, triggers, and views that reference deleted columns are not recreated. An attempt is made to recreate the others including any modifications for renamed columns.

        Creating a new table: Creates a new table and transfers the table data to the new. Triggers are not created on the new table. Indexes and views that reference deleted columns are not recreated. An attempt is made to create the others on the new table.

        Making Other Kinds Of Table Schema Changes:

        https://www.sqlite.org/lang_altertable.html

        Parameters:
        db - connection
        newTable - new table schema
        tableMapping - table mapping
      • alterTable

        public static void alterTable​(GeoPackageCoreConnection db,
                                      String sql,
                                      TableMapping tableMapping)
        Alter a table with a new table SQL creation statement and table mapping.

        Altering a table: Removes views on the table, creates a new table, transfers the old table data to the new, drops the old table, and renames the new table to the old. Indexes, triggers, and views that reference deleted columns are not recreated. An attempt is made to recreate the others including any modifications for renamed columns.

        Creating a new table: Creates a new table and transfers the table data to the new. Triggers are not created on the new table. Indexes and views that reference deleted columns are not recreated. An attempt is made to create the others on the new table.

        Making Other Kinds Of Table Schema Changes:

        https://www.sqlite.org/lang_altertable.html

        Parameters:
        db - connection
        sql - new table SQL
        tableMapping - table mapping