com.alpine.sql

SQLGenerator

trait SQLGenerator extends AnyRef

The purpose of SQLGenerator is to provide an object to facilitate the construction of commonly used SQL queries. Because SQL generation can vary between different database types, each SQLGenerator is instantiated for a particular database type.

For certain methods, when specifying table names, fully qualify and delimit as necessary (i.e. "schemaname"."tablename"). Delimiting is required for table names with non-standard characters ([A-Za-z][A-Za-z0-9]*). Not all databases support delimiters or non-standard characters (such as Teradata). For those databases that support schemas, specifying the schema name is recommended.

For certain methods, when specifying column names, these must be a comma-separated string of columns that one would find in a SELECT query. This can include expressions that are aliased (i.e. sqlexpression AS aliasname). Any columns with non-standard characters should be delimited (i.e. "columnname"). When SELECTing from more than one table, if column names are not unique, then columns should be fully qualified (i.e. "schemaname"."tablename"."columnname" AS "columnalias").

For certain methods, when specifying a source table, it is permissible to specify more than one table as a join (i.e. table1 INNER JOIN table2 ON ...).

For certain methods, when specifying a whereClause, the literal "WHERE" should be included. Note that we can include anything that follows a FROM clause here, such as GROUP BY, ORDER BY, etc.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. SQLGenerator
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def dbType: TypeValue

    Returns the DatabaseType.

    Returns the DatabaseType.TypeValue object that represents the database type. Each SQLGenerator is instantiated for a particular database type.

    returns

    the DatabaseType.TypeValue object that represents the database type of this SQLGenerator

  2. abstract def getCreateTableAsSelectSQL(selectQuery: String, destinationTable: String): String

    Returns a SQL DDL statement to generate a table based on a SELECT query, not necessarily from any particular table.

    Returns a SQL DDL statement to generate a table based on a SELECT query, not necessarily from any particular table. The entire SELECT query must be supplied to generate something like "CREATE TABLE destinationTable AS selectQuery". This method is useful for calls to UDFs or stored procedures that might be database-specific and don't conform to selecting columns from a source table.

    NOTE: Currently, this works only on certain databases like PostgreSQL, Greenplum, Oracle, MySQL, Teradata, but not MSSQL, which does not support CREATE TABLE ... AS SELECT ....

    Table name should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename").

    selectQuery is not necessarily a SELECT query, but any query that can feed the CREATE TABLE statement.

    selectQuery

    query (not necessary SELECT) to be used for CREATE TABLE

    destinationTable

    name of destination table to be created from SELECT query

    returns

    generated SQL statement

  3. abstract def getCreateTableAsSelectSQL(columns: String, sourceTable: String, destinationTable: String): String

    Returns a SQL DDL statement to generate a table based on a SELECT query from an existing table.

    Returns a SQL DDL statement to generate a table based on a SELECT query from an existing table. For most databases, this is something like "CREATE TABLE destinationTable AS SELECT columns FROM sourceTable"

    Table names should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename"). it is acceptable to specify a table join as the source table (i.e. table1 INNER JOIN table2 ...), but in such cases, column names might not be unique and full qualification and aliasing may be required (i.e. "schemaname"."tablename"."columnname" AS "aliasname")

    columns

    String of comma-separated columns to be SELECTed

    sourceTable

    name of source table from which we SELECT

    destinationTable

    name of destination table to be created from SELECT query

    returns

    generated SQL statement

  4. abstract def getCreateTableAsSelectSQL(columns: String, sourceTable: String, destinationTable: String, whereClause: String): String

    Returns a SQL DDL statement to generate a table based on a SELECT query from an existing table.

    Returns a SQL DDL statement to generate a table based on a SELECT query from an existing table. For most databases, this is something like "CREATE TABLE destinationTable AS SELECT columns FROM sourceTable whereClause"

    Table names should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename"). it is acceptable to specify a table join as the source table (i.e. table1 INNER JOIN table2 ...), but in such cases, column names might not be unique and full qualification and aliasing may be required (i.e. "schemaname"."tablename"."columnname" AS "aliasname")

    The specified WHERE clause should include the "WHERE" keyword. Note that this is simply SQL that is appended to the query as "SELECT columns FROM sourceTable whereClause" and can include other SQL outside of just a WHERE clause, such as GROUP BY, ORDER BY, etc.

    columns

    String of comma-separated columns to be SELECTed

    sourceTable

    name of source table from which we SELECT

    destinationTable

    name of destination table to be created from SELECT query

    whereClause

    where clause of the SELECT query, including the literal "WHERE" keyword

    returns

    generated SQL statement

  5. abstract def getCreateTableOrViewAsSelectSQL(selectQuery: String, destinationTableOrView: String, isView: Boolean): String

    Returns a SQL DDL statement to generate a table or view based on a SELECT query, not necessarily from any particular table.

    Returns a SQL DDL statement to generate a table or view based on a SELECT query, not necessarily from any particular table. The entire SELECT query must be supplied to generate something like "CREATE TABLE destinationTable AS selectQuery" or "CREATE VIEW destinationTable AS selectQuery", depending on the isView parameter. This method is useful for calls to UDFs or stored procedures that might be database-specific and don't conform to selecting columns from a source table.

    NOTE: Currently, creating a table works only on certain databases but not MSSQL, which does not support CREATE TABLE ... AS SELECT ....

    Table or view name should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename" or "schemaname"."viewname").

    selectQuery is not necessarily a SELECT query, but any query that can feed the CREATE TABLE statement.

    selectQuery

    query (not necessary SELECT) to be used for CREATE TABLE

    destinationTableOrView

    name of destination table to be created from SELECT query

    returns

    generated SQL statement

  6. abstract def getCreateTableOrViewAsSelectSQL(columns: String, sourceTable: String, destinationTable: String, isView: Boolean): String

    Returns a SQL DDL statement to generate a table or view based on a SELECT query from an existing table.

    Returns a SQL DDL statement to generate a table or view based on a SELECT query from an existing table. For most databases, this is something like "CREATE TABLE destinationTable AS SELECT columns FROM sourceTable" or "CREATE VIEW destinationTable AS SELECT columns FROM sourceTable", depending on the isView parameter

    Table and view names should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename", "schemaname"."viewname"). it is acceptable to specify a table join as the source table (i.e. table1 INNER JOIN table2 ...), but in such cases, column names might not be unique and full qualification and aliasing may be required (i.e. "schemaname"."tablename"."columnname" AS "aliasname")

    columns

    String of comma-separated columns to be SELECTed

    sourceTable

    name of source table from which we SELECT

    destinationTable

    name of destination table or view to be created from SELECT query

    isView

    true if generating a view, false if generating a table

    returns

    generated SQL statement

  7. abstract def getCreateTableOrViewAsSelectSQL(columns: String, sourceTable: String, destinationTable: String, whereClause: String, isView: Boolean): String

    Returns a SQL DDL statement to generate a table or view based on a SELECT query from an existing table.

    Returns a SQL DDL statement to generate a table or view based on a SELECT query from an existing table. For most databases, this is something like "CREATE TABLE destinationTable AS SELECT columns FROM sourceTable whereClause" or "CREATE VIEW destinationTable AS SELECT columns FROM sourceTable whereClause", depending on the isView parameter

    Table and view names should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename", "schemaname"."viewname"). it is acceptable to specify a table join as the source table (i.e. table1 INNER JOIN table2 ...), but in such cases, column names might not be unique and full qualification and aliasing may be required (i.e. "schemaname"."tablename"."columnname" AS "aliasname")

    The specified WHERE clause should include the "WHERE" keyword. Note that this is simply SQL that is appended to the query as "SELECT columns FROM sourceTable whereClause" and can include other SQL outside of just a WHERE clause, such as GROUP BY, ORDER BY, etc.

    columns

    String of comma-separated columns to be SELECTed

    sourceTable

    name of source table from which we SELECT

    destinationTable

    name of destination table or view to be created from SELECT query

    whereClause

    where clause of the SELECT query, including the literal "WHERE" keyword

    isView

    true if generating a view, false if generating a table

    returns

    generated SQL statement

  8. abstract def getCreateTempTableAsSelectSQL(selectQuery: String, destinationTable: String): String

    Returns a SQL DDL statement to generate a temporary table based on a SELECT query, not necessarily from any particular table.

    Returns a SQL DDL statement to generate a temporary table based on a SELECT query, not necessarily from any particular table. The entire SELECT query must be supplied to generate something like "CREATE TEMP TABLE destinationTable AS selectQuery". This method is useful for calls to UDFs or stored procedures that might be database-specific and don't conform to selecting columns from a source table.

    NOTE: Currently, this works only on certain databases that support temporary tables.

    Table name should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename").

    selectQuery is not necessarily a SELECT query, but any query that can feed the CREATE TABLE statement.

    selectQuery

    query (not necessary SELECT) to be used for CREATE TABLE

    destinationTable

    name of destination table to be created from SELECT query

    returns

    generated SQL statement

  9. abstract def getCreateViewAsSelectSQL(selectQuery: String, destinationView: String): String

    Returns a SQL DDL statement to generate a view based on a SELECT query, not necessarily from any particular table.

    Returns a SQL DDL statement to generate a view based on a SELECT query, not necessarily from any particular table. The entire SELECT query must be supplied to generate something like "CREATE VIEW destinationTable AS selectQuery". This method is useful for calls to UDFs or stored procedures that might be database-specific and don't conform to selecting columns from a source table.

    Table name should be fully qualified and delimited, if necessary (i.e. "schemaname"."tablename").

    selectQuery is not necessarily a SELECT query, but any query that can feed the CREATE TABLE statement.

    selectQuery

    query (not necessary SELECT) to be used for CREATE VIEW

    destinationView

    name of destination table to be created from SELECT query

    returns

    generated SQL statement

  10. abstract def getCreateViewAsSelectSQL(columns: String, sourceTable: String, destinationView: String): String

    Returns a SQL DDL statement to generate a view based on a SELECT query from an existing table.

    Returns a SQL DDL statement to generate a view based on a SELECT query from an existing table. For most databases, this is something like "CREATE VIEW destinationTable AS SELECT columns FROM sourceTable"

    View names should be fully qualified and delimited, if necessary (i.e. "schemaname"."viewname"). it is acceptable to specify a table join as the source table (i.e. table1 INNER JOIN table2 ...), but in such cases, column names might not be unique and full qualification and aliasing may be required (i.e. "schemaname"."tablename"."columnname" AS "aliasname")

    columns

    String of comma-separated columns to be SELECTed

    sourceTable

    name of source table from which we SELECT

    destinationView

    name of destination view to be created from SELECT query

    returns

    generated SQL statement

  11. abstract def getCreateViewAsSelectSQL(columns: String, sourceTable: String, destinationView: String, whereClause: String): String

    Returns a SQL DDL statement to generate a view based on a SELECT query from an existing table.

    Returns a SQL DDL statement to generate a view based on a SELECT query from an existing table. For most databases, this is something like "CREATE VIEW destinationTable AS SELECT columns FROM sourceTable [whereClause]"

    View names should be fully qualified and delimited, if necessary (i.e. "schemaname"."viewname"). it is acceptable to specify a table join as the source table (i.e. table1 INNER JOIN table2 ...), but in such cases, column names might not be unique and full qualification and aliasing may be required (i.e. "schemaname"."tablename"."columnname" AS "aliasname")

    The specified WHERE clause should include the "WHERE" keyword. Note that this is simply SQL that is appended to the query as "SELECT columns FROM sourceTable whereClause" and can include other SQL outside of just a WHERE clause, such as GROUP BY, ORDER BY, etc.

    columns

    String of comma-separated columns to be SELECTed

    sourceTable

    name of source table from which we SELECT

    destinationView

    name of destination view to be created from SELECT query

    whereClause

    where clause of the SELECT query, including the literal "WHERE" keyword

    returns

    generated SQL statement

  12. abstract def getDropTableIfExistsSQL(tableName: String, cascade: Boolean = false): String

    Returns a SQL DDL statement to drop a table if it exists, and optionally, cascade the drop to dependent tables.

    Returns a SQL DDL statement to drop a table if it exists, and optionally, cascade the drop to dependent tables. For most databases, this is something like "DROP TABLE IF EXISTS tableName [CASCADE]"

    NOTE: Not all databases support CASCADE DROP

    tableName

    table to be dropped

    cascade

    true if dependent objects should also be dropped

    returns

    generated SQL statement

  13. abstract def getDropViewIfExistsSQL(viewName: String, cascade: Boolean = false): String

    Returns a SQL DDL statement to drop a view if it exists, and optionally, cascade the drop to dependent views.

    Returns a SQL DDL statement to drop a view if it exists, and optionally, cascade the drop to dependent views. For most databases, this is something like "DROP VIEW IF EXISTS viewName [CASCADE]"

    NOTE: Not all databases support CASCADE DROP

    viewName

    view to be dropped

    cascade

    true if dependent objects should also be dropped

    returns

    generated SQL statement

  14. abstract def getModuloExpression(dividend: String, divisor: String): String

    Returns the expression for modulo division for this database.

    Returns the expression for modulo division for this database. This differs widely among databases. For example, in PostgreSQL, this is "dividend % divisor". But in Oracle, this is "MODULO(dividend, divisor)". For this reason, we must pass in the expressions used for dividend and divisor.

    dividend

    SQL expression for the dividend to be passed to the MODULO (can be a simple column name)

    divisor

    SQL expression for the divisor to be passed to the MODULO (can be a simple number)

    returns

    a SQL expression for the given dividend modulo the given divisor

  15. abstract def getStandardDeviationFunctionName: String

    Returns the name of the standard deviation function to be used for this database.

    Returns the name of the standard deviation function to be used for this database. For example, in PostgreSQL, this is "stddev". Note that this is just the function name, and does not include the argument. A typical SQL call would be "stddev(expression)".

    returns

    name of the standard deviation function for the current database type

  16. abstract def getVarianceFunctionName: String

    Returns the name of the variance function to be used for this database.

    Returns the name of the variance function to be used for this database. For example, in PostgreSQL, this is "variance". Note that this is just the function name, and does not include the argument. A typical call would be "variance(expression)".

    returns

    name of the variance function for the current database type

  17. abstract def quoteChar: String

    Character or String to use when quoting identifiers.

    Character or String to use when quoting identifiers. Typically, this is a double-quote (for PostgreSQL and other databases), but can be other characters or even Strings for other platforms.

    returns

    the character or characters to be used to delimit identifiers for this database type

  18. abstract def quoteIdentifier(s: String): String

    Wraps an identifier in the appropriate quote character to preserve case and special characters.

    Wraps an identifier in the appropriate quote character to preserve case and special characters. If there is no quoting mechanism for this database type, just return the argument.

    s

    string to be delimited

    returns

    the given string, but with the appropriate delimiters for the current database type

  19. abstract def quoteObjectName(schemaName: String, objectName: String): String

    Wraps a schema and table or view name in the appropriate quote character to preserve case and special characters.

    Wraps a schema and table or view name in the appropriate quote character to preserve case and special characters. If schemaName is unspecified, quote only the objectName. Uses quoteIdentifier() for quoting.

    schemaName

    the schema name of the object (or "" if none)

    objectName

    the object name of the object

    returns

    a string composed of the given schema and object names, properly delimited

  20. abstract def useAliasForSelectSubQueries: Boolean

    If true, subqueries must be aliased.

    If true, subqueries must be aliased. Some databases, such as Oracle, require subqueries (queries that appear in the FROM clause) to be aliased. For example:

    SELECT ... FROM ( SELECT ... FROM foo WHERE ... ) AS fooalias WHERE ...

    returns

    true if subqueries must be aliased, false if otherwise

  21. abstract def escapeColumnName(s: String): String

    Wraps a column name in the appropriate quote character to preserve case and special characters.

    Wraps a column name in the appropriate quote character to preserve case and special characters. If there is no quoting mechanism for this database type, just return the argument.

    Note: Deprecated -- please use quoteIdentifier instead.

    s

    string to be delimited

    returns

    the given string, but with appropriate delimiters for the current database type

    Annotations
    @deprecated
    Deprecated

    (Since version 2016-04-22) Please use quoteIdentifier instead [Paul]

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def doubleToString(d: Double): String

    Converts a double to String representation.

    Converts a double to String representation. For most database vendors, this is just invoking toString on the double object. For Teradata, this will format the number of digits to no more than 15.

    d

    the double

    returns

    String representation of the double, limited to 15 characters for Teradata

  9. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  13. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  14. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  18. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  19. def toString(): String

    Definition Classes
    AnyRef → Any
  20. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped