All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fuzzycsv.rdbms.stmt.MySqlRenderer.groovy Maven / Gradle / Ivy

Go to download

A groovy/java tabular Data (from CSV,SQL,JSON) processing library that supports fuzzy column matching,tranformations/merging/querying etc

There is a newer version: 1.9.1-groovy4
Show newest version
package fuzzycsv.rdbms.stmt

import fuzzycsv.rdbms.FuzzyCSVDbExporter.Column
import org.codehaus.groovy.runtime.InvokerHelper

import static fuzzycsv.rdbms.FuzzyCsvDbInserter.inTicks

class MySqlRenderer extends DefaultSqlRenderer {


    private static SqlRenderer instance;

    static SqlRenderer getInstance() {
        if (instance == null)// don't care about synchronization
            instance = new MySqlRenderer()
        return instance
    }

    @Override
    String modifyColumn(String tableName, Column column) {
        def copy = mayBeModifyType(column)
        "ALTER TABLE ${quoteName(tableName)} MODIFY COLUMN ${toDataString(copy)};"
    }

    @Override
    String addColumn(String tableName, Column column) {
        def copy = mayBeModifyType(column)
        "ALTER TABLE ${quoteName(tableName)} ADD ${toDataString(copy)}"
    }

    Column mayBeModifyType(Column column) {
        Column copy = column
        if (column.type == 'text') {
            copy = new Column()
            InvokerHelper.setProperties(copy, column.properties)
            copy.type = 'longtext'
        }
        return copy
    }


    @Override
    String quoteName(String name) {
        inTicks(name)
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy