English | 简体中文

api-docs / org.ktorm.expression / SqlFormatter

SqlFormatter

abstract class SqlFormatter : SqlExpressionVisitor (source code)

Subclass of SqlExpressionVisitor, visiting SQL expression trees using visitor pattern. After the visit completes,
the executable SQL string will be generated in the sql property with its execution parameters in parameters.

Types

NameSummary

Indentation

enum class Indentation

Constructors

NameSummary

<init>

SqlFormatter(
    database: Database,
    beautifySql: Boolean,
    indentSize: Int)

Subclass of SqlExpressionVisitor, visiting SQL expression trees using visitor pattern. After the visit completes,
the executable SQL string will be generated in the sql property with its execution parameters in parameters.

Properties

NameSummary

_builder

val _builder: StringBuilder

_depth

var _depth: Int

_parameters

val _parameters: ArrayList<ArgumentExpression<*>>

beautifySql

val beautifySql: Boolean

mark if we should output beautiful SQL strings with line-wrapping and indentation.

database

val database: Database

the current database object used to obtain metadata such as identifier quote string.

indentSize

val indentSize: Int

the indent size.

isIdentifier

val String.isIdentifier: Boolean

isIdentifierStart

val Char.isIdentifierStart: Boolean

isMixedCase

val String.isMixedCase: Boolean

parameters

val parameters: List<ArgumentExpression<*>>

return the SQL’s execution parameters after the visit completes.

quoted

val String.quoted: String

removeBrackets

val SqlExpression.removeBrackets: Boolean

sql

val sql: String

return the executable SQL string after the visit completes.

Functions

NameSummary

checkColumnName

open fun checkColumnName(name: String): Unit

newLine

fun newLine(indent: SqlFormatter.Indentation): Unit

removeLastBlank

fun removeLastBlank(): Unit

shouldQuote

open fun shouldQuote(identifier: String): Boolean

visit

open fun visit(expr: SqlExpression): SqlExpression

Dispatch different type of expression nodes to the specific visit* functions. Custom expression types that
are unknown to Ktorm will be dispatched to visitUnknown.

visitAggregate

open fun <T : Any> visitAggregate(
    expr: AggregateExpression<T>
): AggregateExpression<T>

visitArgument

open fun <T : Any> visitArgument(
    expr: ArgumentExpression<T>
): ArgumentExpression<T>

visitBetween

open fun <T : Any> visitBetween(
    expr: BetweenExpression<T>
): BetweenExpression<T>

visitBinary

open fun <T : Any> visitBinary(
    expr: BinaryExpression<T>
): BinaryExpression<T>

visitColumn

open fun <T : Any> visitColumn(
    expr: ColumnExpression<T>
): ColumnExpression<T>

visitColumnAssignments

open fun visitColumnAssignments(
    original: List<ColumnAssignmentExpression<*>>
): List<ColumnAssignmentExpression<*>>

visitColumnDeclaring

open fun <T : Any> visitColumnDeclaring(
    expr: ColumnDeclaringExpression<T>
): ColumnDeclaringExpression<T>

visitColumnDeclaringAtSelectClause

fun <T : Any> visitColumnDeclaringAtSelectClause(
    expr: ColumnDeclaringExpression<T>
): ColumnDeclaringExpression<T>

visitDelete

open fun visitDelete(
    expr: DeleteExpression
): DeleteExpression

visitExists

open fun visitExists(
    expr: ExistsExpression
): ExistsExpression

visitExpressionList

open fun <T : SqlExpression> visitExpressionList(
    original: List<T>,
    subVisitor: (T) -> T
): List<T>

visitFunction

open fun <T : Any> visitFunction(
    expr: FunctionExpression<T>
): FunctionExpression<T>

visitInList

open fun <T : Any> visitInList(
    expr: InListExpression<T>
): InListExpression<T>

visitInsert

open fun visitInsert(
    expr: InsertExpression
): InsertExpression

visitInsertFromQuery

open fun visitInsertFromQuery(
    expr: InsertFromQueryExpression
): InsertFromQueryExpression

visitJoin

open fun visitJoin(expr: JoinExpression): JoinExpression

visitOrderBy

open fun visitOrderBy(
    expr: OrderByExpression
): OrderByExpression

visitQuerySource

open fun visitQuerySource(
    expr: QuerySourceExpression
): QuerySourceExpression

visitSelect

open fun visitSelect(
    expr: SelectExpression
): SelectExpression

visitTable

open fun visitTable(expr: TableExpression): TableExpression

visitUnary

open fun <T : Any> visitUnary(
    expr: UnaryExpression<T>
): UnaryExpression<T>

visitUnion

open fun visitUnion(expr: UnionExpression): UnionExpression

visitUnknown

open fun visitUnknown(expr: SqlExpression): SqlExpression

visitUpdate

open fun visitUpdate(
    expr: UpdateExpression
): UpdateExpression

write

fun write(value: String): Unit

writeKeyword

fun writeKeyword(keyword: String): Unit

writePagination

abstract fun writePagination(expr: QueryExpression): Unit

Inherited Functions

NameSummary

visitCasting

open fun <T : Any> visitCasting(
    expr: CastingExpression<T>
): CastingExpression<T>

visitColumnAssignment

open fun <T : Any> visitColumnAssignment(
    expr: ColumnAssignmentExpression<T>
): ColumnAssignmentExpression<T>

visitColumnDeclaringList

open fun visitColumnDeclaringList(
    original: List<ColumnDeclaringExpression<*>>
): List<ColumnDeclaringExpression<*>>

visitGroupByList

open fun visitGroupByList(
    original: List<ScalarExpression<*>>
): List<ScalarExpression<*>>

visitOrderByList

open fun visitOrderByList(
    original: List<OrderByExpression>
): List<OrderByExpression>

visitQuery

open fun visitQuery(expr: QueryExpression): QueryExpression

visitScalar

open fun <T : Any> visitScalar(
    expr: ScalarExpression<T>
): ScalarExpression<T>

Inheritors

NameSummary

MySqlFormatter

open class MySqlFormatter : SqlFormatter

SqlFormatter implementation for MySQL, formatting SQL expressions as strings with their execution arguments.

OracleFormatter

open class OracleFormatter : SqlFormatter

SqlFormatter implementation for Oracle, formatting SQL expressions as strings with their execution arguments.

PostgreSqlFormatter

open class PostgreSqlFormatter : SqlFormatter

SqlFormatter implementation for PostgreSQL, formatting SQL expressions as strings with their execution arguments.

SQLiteFormatter

open class SQLiteFormatter : SqlFormatter

SqlFormatter implementation for SQLite, formatting SQL expressions as strings with their execution arguments.

SqlServerFormatter

open class SqlServerFormatter : SqlFormatter

SqlFormatter implementation for SqlServer, formatting SQL expressions as strings with their execution arguments.