Class DBSQLBuilder

java.lang.Object
org.apache.empire.db.DBSQLBuilder
All Implemented Interfaces:
Appendable
Direct Known Subclasses:
DBMSHandlerBase.DBMSBuilder, DBMSHandlerMSSQL.DBSQLBuilderMSSQL, DBMSHandlerMySQL.DBSQLBuilderMySQL

public abstract class DBSQLBuilder extends Object implements Appendable
DBSQLBuilder This class is used for building a single SQL statement
Author:
doebele
  • Field Details

  • Constructor Details

    • DBSQLBuilder

      protected DBSQLBuilder(DBMSHandler dbms)
      Don't use this directly Use dbms.createSQLBuilder()
      Parameters:
      dbms - the dbms handler
  • Method Details

    • setCmdParams

      public void setCmdParams(DBCmdParamList cmdParamList)
    • toString

      public String toString()
      returns the SQL as a String
      Overrides:
      toString in class Object
    • getDbms

      public DBMSHandler getDbms()
    • getPhrase

      public String getPhrase(DBSqlPhrase phrase)
    • length

      public int length()
    • reset

      public void reset(int pos)
    • replace

      public void replace(String find, String replace)
    • append

      public DBSQLBuilder append(CharSequence sqlLiteral)
      Specified by:
      append in interface Appendable
    • append

      public DBSQLBuilder append(CharSequence sqlLiteral, int start, int end)
      Specified by:
      append in interface Appendable
    • append

      public DBSQLBuilder append(char c)
      Specified by:
      append in interface Appendable
    • append

      public DBSQLBuilder append(long l)
    • append

      public DBSQLBuilder append(double d)
    • append

      public DBSQLBuilder append(DBSqlPhrase phrase)
    • append

      public void append(DBCommandExpr subQueryCmd)
    • appendValue

      public void appendValue(DataType type, Object value)
      Appends the SQL representation of a value
      Parameters:
      type - the data type
      value - an DBExpr object, array or a basis data type(e.g. int, String)
    • appendValue

      public void appendValue(DataType dataType, Object value, long context, String arraySep)
      Appends the SQL representation of a value
      Parameters:
      dataType - the DataType
      value - an DBExpr object, array or a basis data type(e.g. int, String)
      context - the context of the DBColumnExpr object
      arraySep - the separator value
    • appendValue

      public final void appendValue(DataType dataType, Object value, long context)
      Appends the SQL representation of a value
      Parameters:
      dataType - the DataType
      value - an DBExpr object, array or a basis data type(e.g. int, String)
      context - the context of the DBColumnExpr object
    • appendTemplate

      public void appendTemplate(String template, Object[] values, DataType[] dataTypes, long context, String arraySep)
      Expands an SQL template and adds it to the SQL command
      Parameters:
      template - the SQL template
      values - list of values to be inserted into the template
      dataTypes - list of data types
      context - the context of the DBColumnExpr object
      arraySep - the separator value
    • appendSimpleValue

      protected void appendSimpleValue(DataType type, Object value)
      Returns a sql string for a given value. Text will be enclosed in single quotes and existing single quotes will be doubled. Empty strings are treated as null. The syntax of Date, Datetime and Boolean values are DBMS specific.
      Parameters:
      type - the data type of the supplied value
      value - the value which is inserted to the new String
    • getDateTimeString

      protected String getDateTimeString(Object value, DBSqlPhrase sqlTemplate, DBSqlPhrase sqlPattern, DBSqlPhrase sqlCurrentDate)
      encodes a Date value for an SQL command string.
      Parameters:
      value - the value to encode
      sqlTemplate - the template
      sqlPattern - the pattern
      sqlCurrentDate - the current date phrase
      Returns:
      the date time string
    • appendStringLiteral

      protected void appendStringLiteral(DataType type, Object value)
      encodes Text values for an SQL command string.
      Parameters:
      type - date type (can only be TEXT, CHAR, CLOB and UNIQUEID)
      value - the literal to be encoded
    • escapeAndAppendLiteral

      protected void escapeAndAppendLiteral(String value)
      this helper function doubles up single quotes for SQL
      Parameters:
      value - the string to escape and append
    • getNumberString

      protected String getNumberString(Object value, DataType type)
      encodes a numeric value for an SQL command string.
      Parameters:
      value - the numeric value
      type - the number data type
      Returns:
      the string representation of the number
    • stringToBoolean

      protected boolean stringToBoolean(String value)
      this function converts a string containing a boolean expression to a boolean.
      Parameters:
      value - the string containing a boolean expression
      Returns:
      true if the string contains either "true", "y" or "1" or false otherwise