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

util.SqlUtil.kt Maven / Gradle / Ivy

There is a newer version: 1.1.10
Show newest version
package util

import ast.statement.SqlStatement
import database.DB
import visitor.outputvisitor.*

/**
 * 根据数据库类型选择不同的方言生成器
 * @param db DB 数据库类型
 * @return SqlOutPutVisitor sql语句生成器
 */
fun getOutPutVisitor(db: DB): SqlOutPutVisitor {
    return when (db) {
        DB.MYSQL -> MysqlOutPutVisitor()
        DB.PGSQL -> PgsqlOutPutVisitor()
        DB.SQLSERVER -> SqlserverOutPutVisitor()
        DB.SQLITE -> SqliteOutPutVisitor()
        DB.CLICKHOUSE -> ClickhouseOutPutVisitor()
        DB.HIVE -> HiveOutPutVisitor()
        DB.ORACLE -> OracleOutPutVisitor()
    }
}

/**
 * 根据数据库类型选择不同的方言生成器,生成sql
 * @param sqlStatement SqlStatement sql语法树
 * @param db DB 数据库类型
 * @return String sql语句
 */
fun toSqlString(sqlStatement: SqlStatement, db: DB): String {
    val visitor = getOutPutVisitor(db)
    visitor.visitSqlStatement(sqlStatement)
    return visitor.sql()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy