Class QueryFunction

java.lang.Object
com.ptsmods.mysqlw.query.QueryFunction
All Implemented Interfaces:
CharSequence

public class QueryFunction extends Object implements CharSequence
To make sure that functions don't get enquoted when putting them in a query, wrap them in this class. An example would be JSON_CONTAINS(`column`, '{"value": {"child": 7}}') or GeomFromText('POINT(42.8, 69.7)') although that one is obsolete. This class also implements CharSequence so that it can be passed as a key when selecting. (Otherwise it gets put between graves unless it's an asterisk.)
  • Constructor Details

    • QueryFunction

      public QueryFunction(String function)
      Creates a new QueryFunction.
      Parameters:
      function - The function this QueryFunction should contain
  • Method Details

    • add

      public static QueryFunction add(String arg1, String arg2)
      Creates a basic new QueryFunction that adds two columns or variables together.
      Parameters:
      arg1 - The first column or variable
      arg2 - The second column or variable
      Returns:
      Addition QueryFunction
    • subtract

      public static QueryFunction subtract(String arg1, String arg2)
      Creates a basic new QueryFunction that subtracts two columns or variables from each other.
      Parameters:
      arg1 - The first column or variable
      arg2 - The second column or variable
      Returns:
      Subtraction QueryFunction
    • multiply

      public static QueryFunction multiply(String arg1, String arg2)
      Creates a basic new QueryFunction that multiplies two columns or variables.
      Parameters:
      arg1 - The first column or variable
      arg2 - The second column or variable
      Returns:
      Multiplication QueryFunction
    • divide

      public static QueryFunction divide(String arg1, String arg2)
      Creates a basic new QueryFunction that divides two columns or variables.
      Parameters:
      arg1 - The first column or variable
      arg2 - The second column or variable
      Returns:
      Division QueryFunction
    • count

      public static QueryFunction count(String arg)
      Creates a basic new QueryFunction that counts rows.
      Parameters:
      arg - What to count
      Returns:
      Count QueryFunction
    • getFunction

      public String getFunction()
      Returns:
      The function this QueryFunction contains.
    • length

      public int length()
      Specified by:
      length in interface CharSequence
    • charAt

      public char charAt(int index)
      Specified by:
      charAt in interface CharSequence
    • subSequence

      public CharSequence subSequence(int start, int end)
      Specified by:
      subSequence in interface CharSequence
    • toString

      public String toString()
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object