Class SqlBuilder

java.lang.Object
anderix.datajets.SqlBuilder

public class SqlBuilder extends Object
Facilitates creation of SQL statements in an object-oriented manner. The basic use of a SqlBuilder object follows this pattern:
  1. Instantiate SqlBuilder object
  2. Define table to connect to
  3. Define fields in that table
  4. Define identity field (if applicable)
  5. Set field values (if applicable)
  6. Return completed SQL statement
For example, this code creates a SELECT statement:
//Example: creating a SELECT statement
SqlBuilder sql = new SqlBuilder;
String table = "my_table";
sql.setTable(table);
String[] fields = new String[]{"field1", "field2"};
sql.setFieldList(fields);
System.out.println(sql.selectStatement());
SqlBuilder contains methods for adding WHERE clauses to SELECT, INSERT, UPDATE, and DELETE statements. There are also methods for adding JOIN, GROUP BY, HAVING, and ORDER BY clauses to SELECT statements. Calling these methods for INSERT, UPDATE or DELETE statements will have no effect.

Some statments require that the identity field be specified. This can be done in the setFieldList method or in an appropriate constructor. The methods that require an identity field are:

  • selectByIdStatement
  • updateByIdStatement
  • deleteByIdStatement
When creating an INSERT or UPDATE statment, you may populate parameter values by calling setValue or setValueToNull. If you do not set field values, the statement will be returned with ? as a placeholder value.

If SqlBuilder does not have enough information to create the requested SQL statement, it will return an empty string ("");

  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor that does not establish table, fields or identity field.
    Constructor that establishes table.
    SqlBuilder(String table, String[] fields)
    Constructor that establishes table and fields.
    SqlBuilder(String table, String[] fields, int idFieldIndex)
    Constructor that establishes table, fields, and identity field.
    SqlBuilder(String table, String[] fields, String idField)
    Constructor that establishes table, fields, and identity field.
    SqlBuilder(String table, String[] fields, String[] fieldProperties, int idFieldIndex)
    Constructor that establishes table, fields, field properties and identity field.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addField(String fieldName)
    Adds a single field to the field list.
    void
    andHaving(int fieldIndex, Comparison operator, boolean value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(int fieldIndex, Comparison operator, byte value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(int fieldIndex, Comparison operator, double value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(int fieldIndex, Comparison operator, float value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(int fieldIndex, Comparison operator, int value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(int fieldIndex, Comparison operator, short value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(int fieldIndex, Comparison operator, String value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(int fieldIndex, Comparison operator, Date value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(String havingStatement)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(String fieldName, Comparison operator, boolean value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(String fieldName, Comparison operator, byte value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(String fieldName, Comparison operator, double value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(String fieldName, Comparison operator, float value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(String fieldName, Comparison operator, int value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(String fieldName, Comparison operator, short value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(String fieldName, Comparison operator, String value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andHaving(String fieldName, Comparison operator, Date value)
    Adds a HAVING clause to a SELECT statement with AND.
    void
    andWhere(int fieldIndex, Comparison operator, boolean value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(int fieldIndex, Comparison operator, byte value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(int fieldIndex, Comparison operator, double value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(int fieldIndex, Comparison operator, float value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(int fieldIndex, Comparison operator, int value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(int fieldIndex, Comparison operator, short value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(int fieldIndex, Comparison operator, String value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(int fieldIndex, Comparison operator, Date value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(String whereStatement)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(String fieldName, Comparison operator, boolean value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(String fieldName, Comparison operator, byte value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(String fieldName, Comparison operator, double value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(String fieldName, Comparison operator, float value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(String fieldName, Comparison operator, int value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(String fieldName, Comparison operator, short value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(String fieldName, Comparison operator, String value)
    Adds a WHERE clause to an SQL statement with AND.
    void
    andWhere(String fieldName, Comparison operator, Date value)
    Adds a WHERE clause to an SQL statement with AND.
    Creates a CREATE TABLE statement based on supplied values.
    deleteByIdStatement(int idToDelete)
    Creates an DELETE statement based on supplied values.
    Creates an DELETE statement based on supplied values.
    static String
    encode(String toEncode)
    Modifies a string so it will be processed as a complete string within SQL.
    Returns array of strings representing field names already established.
    Returns string representing table name already established.
    void
    groupBy(int groupByFieldIndex)
    Adds a GROUP BY clause to a SELECT statement.
    void
    groupBy(String groupByField)
    Adds a GROUP BY clause to a SELECT statement.
    Creates a INSERT statement based on supplied values.
    void
    join(JoinType joinType, String tableToJoin, String onStatement)
    Adds a JOIN clause to an SQL statement.
    void
    join(JoinType joinType, String tableToJoin, String fieldInFirstTable, Comparison operator, String fieldInTableToJoin)
    Adds a JOIN clause to an SQL statement.
    void
    join(String tableToJoin, String onStatement)
    Adds an INNER JOIN clause to an SQL statement.
    void
    join(String tableToJoin, String fieldInFirstTable, Comparison operator, String fieldInTableToJoin)
    Adds an INNER JOIN clause to an SQL statement.
    void
    join(String tableToJoin, String fieldInFirstTable, String fieldInTableToJoin)
    Adds an INNER JOIN clause to an SQL statement.
    void
    orderBy(int orderByFieldIndex, OrderDirection direction)
    Adds an ORDER BY clause to a SELECT statement with direction as the direction.
    void
    orderBy(String orderByField, OrderDirection direction)
    Adds a ORDER BY clause to a SELECT statement with direction as the direction.
    void
    orderByAscending(int orderByFieldIndex)
    Adds an ORDER BY clause to a SELECT statement with ASC as the direction.
    void
    orderByAscending(String orderByField)
    Adds a ORDER BY clause to a SELECT statement with ASC as the direction.
    void
    orderByDescending(int orderByFieldIndex)
    Adds an ORDER BY clause to a SELECT statement with DESC as the direction.
    void
    orderByDescending(String orderByField)
    Adds a ORDER BY clause to a SELECT statement with DESC as the direction.
    void
    orHaving(int fieldIndex, Comparison operator, boolean value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(int fieldIndex, Comparison operator, byte value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(int fieldIndex, Comparison operator, double value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(int fieldIndex, Comparison operator, float value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(int fieldIndex, Comparison operator, int value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(int fieldIndex, Comparison operator, short value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(int fieldIndex, Comparison operator, String value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(int fieldIndex, Comparison operator, Date value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(String havingStatement)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(String fieldName, Comparison operator, boolean value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(String fieldName, Comparison operator, byte value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(String fieldName, Comparison operator, double value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(String fieldName, Comparison operator, float value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(String fieldName, Comparison operator, int value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(String fieldName, Comparison operator, short value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(String fieldName, Comparison operator, String value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orHaving(String fieldName, Comparison operator, Date value)
    Adds a HAVING clause to a SELECT statement with OR.
    void
    orWhere(int fieldIndex, Comparison operator, boolean value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(int fieldIndex, Comparison operator, byte value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(int fieldIndex, Comparison operator, double value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(int fieldIndex, Comparison operator, float value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(int fieldIndex, Comparison operator, int value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(int fieldIndex, Comparison operator, short value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(int fieldIndex, Comparison operator, String value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(int fieldIndex, Comparison operator, Date value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(String whereStatement)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(String fieldName, Comparison operator, boolean value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(String fieldName, Comparison operator, byte value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(String fieldName, Comparison operator, double value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(String fieldName, Comparison operator, float value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(String fieldName, Comparison operator, int value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(String fieldName, Comparison operator, short value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(String fieldName, Comparison operator, String value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    orWhere(String fieldName, Comparison operator, Date value)
    Adds a WHERE clause to an SQL statement with OR.
    void
    prependField(int fieldIndex, String tableName)
    Prepends the field name with a table name.
    selectByIdStatement(int idToSelect)
    Creates a SELECT statement based on supplied values.
    Creates a SELECT statement based on supplied values.
    void
    setFieldList(String[] fields)
    Establishes fields.
    void
    setFieldList(String[] fields, int idFieldIndex)
    Establishes fields and identity field.
    void
    setFieldList(String[] fields, String idField)
    Establishes fields and identity field.
    void
    setFieldProperties(int fieldIndex, String fieldProperties)
    Sets properties of a field for CREATE TABLE statements.
    void
    Establishes table.
    void
    setValue(int fieldIndex, boolean fieldValue)
    Sets value of field for UPDATE and INSERT statements.
    void
    setValue(int fieldIndex, byte fieldValue)
    Sets value of field for UPDATE and INSERT statements.
    void
    setValue(int fieldIndex, double fieldValue)
    Sets value of field for UPDATE and INSERT statements.
    void
    setValue(int fieldIndex, float fieldValue)
    Sets value of field for UPDATE and INSERT statements.
    void
    setValue(int fieldIndex, int fieldValue)
    Sets value of field for UPDATE and INSERT statements.
    void
    setValue(int fieldIndex, long fieldValue)
    Sets value of field for UPDATE and INSERT statements.
    void
    setValue(int fieldIndex, short fieldValue)
    Sets value of field for UPDATE and INSERT statements.
    void
    setValue(int fieldIndex, Datum fieldValue)
    Sets value of field for UPDATE and INSERT statements.
    void
    setValue(int fieldIndex, Object fieldValue)
    Sets value of field for UPDATE and INSERT statements.
    void
    setValue(int fieldIndex, String fieldValue)
    Sets value of field for UPDATE and INSERT statements.
    void
    setValue(int fieldIndex, Date fieldValue)
    Sets value of field for UPDATE and INSERT statements.
    void
    setValueToNull(int fieldIndex)
    Sets value of field for UPDATE and INSERT statements to NULL.
    updateByIdStatement(int idToUpdate)
    Creates an UPDATE statement based on supplied values.
    Creates an UPDATE statement based on supplied values.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SqlBuilder

      public SqlBuilder(String table, String[] fields, String[] fieldProperties, int idFieldIndex)
      Constructor that establishes table, fields, field properties and identity field.
      Parameters:
      table - string name of the table in the database
      fields - array of strings representing each field
      fieldProperties - array of strings representing fieldProperties
      idFieldIndex - zero-based ordinal position of field in fields[]
    • SqlBuilder

      public SqlBuilder(String table, String[] fields, int idFieldIndex)
      Constructor that establishes table, fields, and identity field.
      Parameters:
      table - string name of the table in the database
      fields - array of strings representing each field
      idFieldIndex - zero-based ordinal position of field in fields[]
    • SqlBuilder

      public SqlBuilder(String table, String[] fields, String idField)
      Constructor that establishes table, fields, and identity field.
      Parameters:
      table - string name of the table in the database
      fields - array of strings representing each field
      idField - name of identity field
    • SqlBuilder

      public SqlBuilder(String table, String[] fields)
      Constructor that establishes table and fields.
      Parameters:
      table - string name of the table in the database
      fields - array of strings representing each field
    • SqlBuilder

      public SqlBuilder(String table)
      Constructor that establishes table. After instantiation, setFieldList must be called to populate field list and/or identity field.
      Parameters:
      table - string name of the table in the database
    • SqlBuilder

      public SqlBuilder()
      Constructor that does not establish table, fields or identity field.
  • Method Details

    • setFieldList

      public void setFieldList(String[] fields, int idFieldIndex)
      Establishes fields and identity field.
      Parameters:
      fields - array of strings representing each field
      idFieldIndex - zero-based ordinal position of field in fields[]
    • setFieldList

      public void setFieldList(String[] fields, String idField)
      Establishes fields and identity field.
      Parameters:
      fields - array of strings representing each field
      idField - name of identity field
    • setFieldList

      public void setFieldList(String[] fields)
      Establishes fields.
      Parameters:
      fields - array of strings representing each field
    • getFieldList

      public String[] getFieldList()
      Returns array of strings representing field names already established.
      Returns:
      fields as array of strings
    • addField

      public void addField(String fieldName)
      Adds a single field to the field list.
      Parameters:
      fieldName - the name of the field to add
    • prependField

      public void prependField(int fieldIndex, String tableName)
      Prepends the field name with a table name. This is used to differentiate fields from different tables that have the same name in queries that joins those tables.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
      tableName - name of the table to which the field belongs
    • setTable

      public void setTable(String table)
      Establishes table.
      Parameters:
      table - string representing table name
    • getTable

      public String getTable()
      Returns string representing table name already established.
      Returns:
      table name as string
    • setValue

      public void setValue(int fieldIndex, byte fieldValue)
      Sets value of field for UPDATE and INSERT statements.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
      fieldValue - value of field as byte
    • setValue

      public void setValue(int fieldIndex, double fieldValue)
      Sets value of field for UPDATE and INSERT statements.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
      fieldValue - value of field as double
    • setValue

      public void setValue(int fieldIndex, float fieldValue)
      Sets value of field for UPDATE and INSERT statements.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
      fieldValue - value of field as float
    • setValue

      public void setValue(int fieldIndex, long fieldValue)
      Sets value of field for UPDATE and INSERT statements.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
      fieldValue - value of field as long
    • setValue

      public void setValue(int fieldIndex, short fieldValue)
      Sets value of field for UPDATE and INSERT statements.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
      fieldValue - value of field as short
    • setValue

      public void setValue(int fieldIndex, boolean fieldValue)
      Sets value of field for UPDATE and INSERT statements.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
      fieldValue - value of field as boolean
    • setValue

      public void setValue(int fieldIndex, Date fieldValue)
      Sets value of field for UPDATE and INSERT statements.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
      fieldValue - value of field as java.util.Date
    • setValue

      public void setValue(int fieldIndex, int fieldValue)
      Sets value of field for UPDATE and INSERT statements.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
      fieldValue - value of field as int
    • setValueToNull

      public void setValueToNull(int fieldIndex)
      Sets value of field for UPDATE and INSERT statements to NULL.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
    • setValue

      public void setValue(int fieldIndex, String fieldValue)
      Sets value of field for UPDATE and INSERT statements.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
      fieldValue - value of field as java.lang.String
    • setValue

      public void setValue(int fieldIndex, Object fieldValue)
      Sets value of field for UPDATE and INSERT statements.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
      fieldValue - value of field as java.lang.String
    • setValue

      public void setValue(int fieldIndex, Datum fieldValue)
      Sets value of field for UPDATE and INSERT statements.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
      fieldValue - value of field as java.lang.String
    • setFieldProperties

      public void setFieldProperties(int fieldIndex, String fieldProperties)
      Sets properties of a field for CREATE TABLE statements.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList)
      fieldProperties - properties of field as java.lang.String
    • andWhere

      public void andWhere(int fieldIndex, Comparison operator, String value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - string representing value to compare to field
    • andWhere

      public void andWhere(String fieldName, Comparison operator, String value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - string representing value to compare to field
    • andWhere

      public void andWhere(int fieldIndex, Comparison operator, int value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - int representing value to compare to field
    • andWhere

      public void andWhere(String fieldName, Comparison operator, int value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - int representing value to compare to field
    • andWhere

      public void andWhere(int fieldIndex, Comparison operator, Date value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - java.util.Date representing value to compare to field
    • andWhere

      public void andWhere(String fieldName, Comparison operator, Date value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - java.util.Date representing value to compare to field
    • andWhere

      public void andWhere(int fieldIndex, Comparison operator, boolean value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - boolean representing value to compare to field
    • andWhere

      public void andWhere(String fieldName, Comparison operator, boolean value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - boolean representing value to compare to field
    • andWhere

      public void andWhere(int fieldIndex, Comparison operator, short value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - short representing value to compare to field
    • andWhere

      public void andWhere(String fieldName, Comparison operator, short value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - short representing value to compare to field
    • andWhere

      public void andWhere(int fieldIndex, Comparison operator, float value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - float representing value to compare to field
    • andWhere

      public void andWhere(String fieldName, Comparison operator, float value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - float representing value to compare to field
    • andWhere

      public void andWhere(int fieldIndex, Comparison operator, double value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - double representing value to compare to field
    • andWhere

      public void andWhere(String fieldName, Comparison operator, double value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - double representing value to compare to field
    • andWhere

      public void andWhere(int fieldIndex, Comparison operator, byte value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - byte representing value to compare to field
    • andWhere

      public void andWhere(String fieldName, Comparison operator, byte value)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - byte representing value to compare to field
    • andWhere

      public void andWhere(String whereStatement)
      Adds a WHERE clause to an SQL statement with AND.
      Parameters:
      whereStatement - string containing complete WHERE clause
    • orWhere

      public void orWhere(int fieldIndex, Comparison operator, String value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - string representing value to compare to field
    • orWhere

      public void orWhere(String fieldName, Comparison operator, String value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - string representing value to compare to field
    • orWhere

      public void orWhere(int fieldIndex, Comparison operator, int value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - int representing value to compare to field
    • orWhere

      public void orWhere(String fieldName, Comparison operator, int value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - int representing value to compare to field
    • orWhere

      public void orWhere(int fieldIndex, Comparison operator, Date value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - java.util.Date representing value to compare to field
    • orWhere

      public void orWhere(String fieldName, Comparison operator, Date value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - java.util.Date representing value to compare to field
    • orWhere

      public void orWhere(int fieldIndex, Comparison operator, boolean value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - boolean representing value to compare to field
    • orWhere

      public void orWhere(String fieldName, Comparison operator, boolean value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - boolean representing value to compare to field
    • orWhere

      public void orWhere(int fieldIndex, Comparison operator, short value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - short representing value to compare to field
    • orWhere

      public void orWhere(String fieldName, Comparison operator, short value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - short representing value to compare to field
    • orWhere

      public void orWhere(int fieldIndex, Comparison operator, float value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - float representing value to compare to field
    • orWhere

      public void orWhere(String fieldName, Comparison operator, float value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - float representing value to compare to field
    • orWhere

      public void orWhere(int fieldIndex, Comparison operator, double value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - double representing value to compare to field
    • orWhere

      public void orWhere(String fieldName, Comparison operator, double value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - double representing value to compare to field
    • orWhere

      public void orWhere(int fieldIndex, Comparison operator, byte value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - byte representing value to compare to field
    • orWhere

      public void orWhere(String fieldName, Comparison operator, byte value)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - byte representing value to compare to field
    • orWhere

      public void orWhere(String whereStatement)
      Adds a WHERE clause to an SQL statement with OR.
      Parameters:
      whereStatement - string containing complete WHERE clause
    • join

      public void join(String tableToJoin, String fieldInFirstTable, String fieldInTableToJoin)
      Adds an INNER JOIN clause to an SQL statement.
      Parameters:
      tableToJoin - name of the table to join
      fieldInFirstTable - name of field in first table
      fieldInTableToJoin - name of field in table specified in tableToJoin
    • join

      public void join(String tableToJoin, String fieldInFirstTable, Comparison operator, String fieldInTableToJoin)
      Adds an INNER JOIN clause to an SQL statement.
      Parameters:
      tableToJoin - name of the table to join
      fieldInFirstTable - name of field in first table
      operator - comparison operator for join
      fieldInTableToJoin - name of field in table specified in tableToJoin
    • join

      public void join(String tableToJoin, String onStatement)
      Adds an INNER JOIN clause to an SQL statement.
      Parameters:
      tableToJoin - name of the table to join
      onStatement - conditional statement to define the join
    • join

      public void join(JoinType joinType, String tableToJoin, String fieldInFirstTable, Comparison operator, String fieldInTableToJoin)
      Adds a JOIN clause to an SQL statement.
      Parameters:
      joinType - the type of join to add
      tableToJoin - name of the table to join
      fieldInFirstTable - name of field in first table
      operator - comparison operator for join
      fieldInTableToJoin - name of field in table specified in tableToJoin
    • join

      public void join(JoinType joinType, String tableToJoin, String onStatement)
      Adds a JOIN clause to an SQL statement.
      Parameters:
      joinType - the type of join to add
      tableToJoin - name of the table to join
      onStatement - conditional statement to define the join
    • groupBy

      public void groupBy(int groupByFieldIndex)
      Adds a GROUP BY clause to a SELECT statement.
      Parameters:
      groupByFieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to group by
    • groupBy

      public void groupBy(String groupByField)
      Adds a GROUP BY clause to a SELECT statement.
      Parameters:
      groupByField - string name of field to group by
    • andHaving

      public void andHaving(int fieldIndex, Comparison operator, String value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - string representing value to compare to field
    • andHaving

      public void andHaving(String fieldName, Comparison operator, String value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - string representing value to compare to field
    • andHaving

      public void andHaving(int fieldIndex, Comparison operator, int value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - int representing value to compare to field
    • andHaving

      public void andHaving(String fieldName, Comparison operator, int value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - int representing value to compare to field
    • andHaving

      public void andHaving(int fieldIndex, Comparison operator, Date value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - java.util.Date representing value to compare to field
    • andHaving

      public void andHaving(String fieldName, Comparison operator, Date value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - java.util.Date representing value to compare to field
    • andHaving

      public void andHaving(int fieldIndex, Comparison operator, boolean value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - boolean representing value to compare to field
    • andHaving

      public void andHaving(String fieldName, Comparison operator, boolean value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - boolean representing value to compare to field
    • andHaving

      public void andHaving(int fieldIndex, Comparison operator, short value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - short representing value to compare to field
    • andHaving

      public void andHaving(String fieldName, Comparison operator, short value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - short representing value to compare to field
    • andHaving

      public void andHaving(int fieldIndex, Comparison operator, float value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - float representing value to compare to field
    • andHaving

      public void andHaving(String fieldName, Comparison operator, float value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - float representing value to compare to field
    • andHaving

      public void andHaving(int fieldIndex, Comparison operator, double value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - double representing value to compare to field
    • andHaving

      public void andHaving(String fieldName, Comparison operator, double value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - double representing value to compare to field
    • andHaving

      public void andHaving(int fieldIndex, Comparison operator, byte value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - byte representing value to compare to field
    • andHaving

      public void andHaving(String fieldName, Comparison operator, byte value)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - byte representing value to compare to field
    • andHaving

      public void andHaving(String havingStatement)
      Adds a HAVING clause to a SELECT statement with AND.
      Parameters:
      havingStatement - string containing complete HAVING clause
    • orHaving

      public void orHaving(int fieldIndex, Comparison operator, String value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - string representing value to compare to field
    • orHaving

      public void orHaving(String fieldName, Comparison operator, String value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - string representing value to compare to field
    • orHaving

      public void orHaving(int fieldIndex, Comparison operator, int value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - int representing value to compare to field
    • orHaving

      public void orHaving(String fieldName, Comparison operator, int value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - int representing value to compare to field
    • orHaving

      public void orHaving(int fieldIndex, Comparison operator, Date value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - java.util.Date representing value to compare to field
    • orHaving

      public void orHaving(String fieldName, Comparison operator, Date value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - java.util.Date representing value to compare to field
    • orHaving

      public void orHaving(int fieldIndex, Comparison operator, boolean value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - boolean representing value to compare to field
    • orHaving

      public void orHaving(String fieldName, Comparison operator, boolean value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - boolean representing value to compare to field
    • orHaving

      public void orHaving(int fieldIndex, Comparison operator, short value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - short representing value to compare to field
    • orHaving

      public void orHaving(String fieldName, Comparison operator, short value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - short representing value to compare to field
    • orHaving

      public void orHaving(int fieldIndex, Comparison operator, float value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - float representing value to compare to field
    • orHaving

      public void orHaving(String fieldName, Comparison operator, float value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - float representing value to compare to field
    • orHaving

      public void orHaving(int fieldIndex, Comparison operator, double value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - double representing value to compare to field
    • orHaving

      public void orHaving(String fieldName, Comparison operator, double value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - double representing value to compare to field
    • orHaving

      public void orHaving(int fieldIndex, Comparison operator, byte value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - byte representing value to compare to field
    • orHaving

      public void orHaving(String fieldName, Comparison operator, byte value)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      fieldName - string name of field to test versus supplied value.
      operator - Comparison representing the type of comparison operation
      value - byte representing value to compare to field
    • orHaving

      public void orHaving(String havingStatement)
      Adds a HAVING clause to a SELECT statement with OR.
      Parameters:
      havingStatement - string containing complete HAVING clause
    • orderByAscending

      public void orderByAscending(int orderByFieldIndex)
      Adds an ORDER BY clause to a SELECT statement with ASC as the direction.
      Parameters:
      orderByFieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to sort by
    • orderByAscending

      public void orderByAscending(String orderByField)
      Adds a ORDER BY clause to a SELECT statement with ASC as the direction.
      Parameters:
      orderByField - string name of field to sort by
    • orderByDescending

      public void orderByDescending(String orderByField)
      Adds a ORDER BY clause to a SELECT statement with DESC as the direction.
      Parameters:
      orderByField - string name of field to sort by
    • orderByDescending

      public void orderByDescending(int orderByFieldIndex)
      Adds an ORDER BY clause to a SELECT statement with DESC as the direction.
      Parameters:
      orderByFieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to sort by
    • orderBy

      public void orderBy(int orderByFieldIndex, OrderDirection direction)
      Adds an ORDER BY clause to a SELECT statement with direction as the direction.
      Parameters:
      orderByFieldIndex - ordinal position of field in fields[] (as defined in constructor or setFieldList) to sort by
    • orderBy

      public void orderBy(String orderByField, OrderDirection direction)
      Adds a ORDER BY clause to a SELECT statement with direction as the direction.
      Parameters:
      orderByField - string name of field to sort by
    • selectByIdStatement

      public String selectByIdStatement(int idToSelect)
      Creates a SELECT statement based on supplied values.
      Parameters:
      idToSelect - int representing identity value of specific record to return
      Returns:
      SQL SELECT statement
    • selectStatement

      public String selectStatement()
      Creates a SELECT statement based on supplied values.
      Returns:
      SQL SELECT statement
    • insertStatement

      public String insertStatement()
      Creates a INSERT statement based on supplied values.
      Returns:
      SQL INSERT statement
    • updateByIdStatement

      public String updateByIdStatement(int idToUpdate)
      Creates an UPDATE statement based on supplied values.
      Parameters:
      idToUpdate - int representing identity value of specific record to update
      Returns:
      SQL UPDATE statement
    • updateStatement

      public String updateStatement()
      Creates an UPDATE statement based on supplied values.
      Returns:
      SQL UPDATE statement
    • createTableStatement

      public String createTableStatement()
      Creates a CREATE TABLE statement based on supplied values.
      Returns:
      SQL CREATE TABLE statement
    • deleteByIdStatement

      public String deleteByIdStatement(int idToDelete)
      Creates an DELETE statement based on supplied values.
      Parameters:
      idToDelete - int representing identity value of specific record to delete
      Returns:
      SQL DELETE statement
    • deleteStatement

      public String deleteStatement()
      Creates an DELETE statement based on supplied values.
      Returns:
      SQL DELETE statement
    • encode

      public static String encode(String toEncode)
      Modifies a string so it will be processed as a complete string within SQL.
      Parameters:
      toEncode - the string to encode
      Returns:
      the encoded string