Class DataStore

java.lang.Object
com.gmt2001.datastore.DataStore
Direct Known Subclasses:
H2Store, MariaDBStore, MySQLStore, SqliteStore

public sealed class DataStore extends Object permits H2Store, MySQLStore, MariaDBStore, SqliteStore
Provides access to the database in a key-value store style
Author:
gmt2001
See Also:
  • Constructor Details

    • DataStore

      protected DataStore(String unused)
      Constructor
      Parameters:
      unused - only used by old classes
  • Method Details

    • instance

      public static DataStore instance()
      Provides an instance of DataStore
      Returns:
      an instance of DataStore
    • resolveClassname

      public static String resolveClassname(String classname)
      Converts Datastore1 driver names to Datastore2 driver names
      Parameters:
      classname - the classname of the driver
      Returns:
      the converted classname
    • findTable

      public Optional<Table<?>> findTable(String fName)
      Attempts to find the named table case-insensitively

      The phantombot_ prefix is automatically prefixed to the table name

      Parameters:
      fName - the table name, without the phantombot_ prefix
      Returns:
      an Optional which contains the matching Table, if found
    • field

      public Field<String> field(String name, Table<?> tbl)
      Attempts to find the named field case-insensitively
      Parameters:
      name - the name of the field
      tbl - the Table to search
      Returns:
      an Optional which contains the matching Field, if found
    • dsl

      public DSLContext dsl()
      Returns:
      the active DSLContext
    • GetFileList

      public String[] GetFileList()
      Returns a list of tables in the database.

      Only tables with the phantombot_ prefix are returned. The prefix is removed

      Returns:
      an array of table names
    • GetCategoryList

      public String[] GetCategoryList(String fName)
      Returns a list of all values in the section column within the table
      Parameters:
      fName - a table name, without the phantombot_ prefix
      Returns:
      an array of sections
    • GetKeyList

      public String[] GetKeyList(String fName, String section)
      Returns a list of all values in the variable column within the table and section
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      Returns:
      an array of variables
    • GetKeyValueList

      public KeyValue[] GetKeyValueList(String fName, String section)
      Returns a list of all variable/value pairs within the table and section
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      Returns:
      an array of KeyValue pairs denoting the variables and values
    • GetKeysByOrder

      public String[] GetKeysByOrder(String fName)
      Returns a list of all values in the variable column within the default section of the table, sorted naturally in Descending order
      Parameters:
      fName - a table name, without the phantombot_ prefix
      Returns:
      a sorted list of variables
    • GetKeysByOrder

      public String[] GetKeysByOrder(String fName, String section)
      Returns a list of all values in the variable column within the table and section, sorted naturally in Descending order
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      Returns:
      a sorted list of variables
    • GetKeysByOrder

      public String[] GetKeysByOrder(String fName, String section, String order)
      Returns a list of all values in the variable column within the table and section, sorted naturally
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      Returns:
      a sorted list of variables
    • GetKeysByOrder

      public String[] GetKeysByOrder(String fName, String section, String order, String limit, String offset)
      Returns a list of values in the variable column within the table and section, sorted naturally
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      limit - the maximum number of results to return from this query
      offset - the offset to start reading from
      Returns:
      a sorted list of variables
    • GetKeysByNumberOrder

      public String[] GetKeysByNumberOrder(String fName)
      Returns a list of all values in the variable column within the default section of the table, sorted naturally Descending as integers
      Parameters:
      fName - a table name, without the phantombot_ prefix
      Returns:
      a sorted list of variables
    • GetKeysByNumberOrder

      public String[] GetKeysByNumberOrder(String fName, String section)
      Returns a list of all values in the variable column within the table and section, sorted naturally Descending as integers
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      Returns:
      a sorted list of variables
    • GetKeysByNumberOrder

      public String[] GetKeysByNumberOrder(String fName, String section, String order)
      Returns a list of all values in the variable column within the table and section, sorted naturally as integers
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      Returns:
      a sorted list of variables
    • GetKeysByNumberOrder

      public String[] GetKeysByNumberOrder(String fName, String section, String order, String limit, String offset)
      Returns a list of values in the variable column within the table and section, sorted naturally as integers
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      limit - the maximum number of results to return from this query
      offset - the offset to start reading from
      Returns:
      a sorted list of variables
    • GetKeysByOrderValue

      public String[] GetKeysByOrderValue(String fName)
      Returns a list of all values in the variable column within the default section of the table, sorted naturally Descending by the value column
      Parameters:
      fName - a table name, without the phantombot_ prefix
      Returns:
      a sorted list of variables
    • GetKeysByOrderValue

      public String[] GetKeysByOrderValue(String fName, String section)
      Returns a list of all values in the variable column within the table and section, sorted naturally Descending by the value column
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      Returns:
      a sorted list of variables
    • GetKeysByOrderValue

      public String[] GetKeysByOrderValue(String fName, String section, String order)
      Returns a list of all values in the variable column within the table and section, sorted naturally by the value column
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      Returns:
      a sorted list of variables
    • GetKeysByOrderValue

      public String[] GetKeysByOrderValue(String fName, String section, String order, String limit, String offset)
      Returns a list of values in the variable column within the table and section, sorted naturally by the value column
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      limit - the maximum number of results to return from this query
      offset - the offset to start reading from
      Returns:
      a sorted list of variables
    • GetKeysByNumberOrderValue

      public String[] GetKeysByNumberOrderValue(String fName)
      Returns a list of all values in the variable column within the default section of the table, sorted naturally Descending by the value column as integers
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      Returns:
      a sorted list of variables
    • GetKeysByNumberOrderValue

      public String[] GetKeysByNumberOrderValue(String fName, String section)
      Returns a list of all values in the variable column within the table and section, sorted naturally Descending by the value column as integers
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      Returns:
      a sorted list of variables
    • GetKeysByNumberOrderValue

      public String[] GetKeysByNumberOrderValue(String fName, String section, String order)
      Returns a list of all values in the variable column within the table and section, sorted naturally by the value column as integers
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      Returns:
      a sorted list of variables
    • GetKeysByNumberOrderValue

      public String[] GetKeysByNumberOrderValue(String fName, String section, String order, String limit, String offset)
      Returns a list of values in the variable column within the table and section, sorted naturally by the value column as integers
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      limit - the maximum number of results to return from this query
      offset - the offset to start reading from
      Returns:
      a sorted list of variables
    • GetKeyByValue

      public String GetKeyByValue(String fName, String section, String value)
      Returns the value of the variable column for the given table, section, and value
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      value - the value of the value column
      Returns:
      the variable; null if not found
    • GetKeysByLikeValues

      public String[] GetKeysByLikeValues(String fName, String section, String search)
      Returns a list of values in the variable column within the table and section, where the value of the value column contains the search phrase
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      search - the partial value of the value column to match against
      Returns:
      a list of variables
    • GetKeysByLikeKeys

      public String[] GetKeysByLikeKeys(String fName, String section, String search)
      Returns a list of values in the variable column within the table and section, where the value of the variable column contains the search phrase
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      search - the partial value of the variable column to match against
      Returns:
      a list of variables
    • GetKeysByLikeKeysOrder

      public String[] GetKeysByLikeKeysOrder(String fName, String search)
      Returns a list of all values in the variable column within the default section of the table, where the value of the variable column contains the search phrase, sorted naturally Descending
      Parameters:
      fName - a table name, without the phantombot_ prefix
      search - the partial value of the variable column to match against
      Returns:
      a sorted list of variables
    • GetKeysByLikeKeysOrder

      public String[] GetKeysByLikeKeysOrder(String fName, String section, String search)
      Returns a list of all values in the variable column within the table and section, where the value of the variable column contains the search phrase, sorted naturally Descending
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      search - the partial value of the variable column to match against
      Returns:
      a sorted list of variables
    • GetKeysByLikeKeysOrder

      public String[] GetKeysByLikeKeysOrder(String fName, String section, String search, String order)
      Returns a list of all values in the variable column within the table and section, where the value of the variable column contains the search phrase, sorted naturally
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      search - the partial value of the variable column to match against
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      Returns:
      a sorted list of variables
    • GetKeysByLikeKeysOrder

      public String[] GetKeysByLikeKeysOrder(String fName, String section, String search, String order, String limit, String offset)
      Returns a list of values in the variable column within the table and section, where the value of the variable column contains the search phrase, sorted naturally
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      search - the partial value of the variable column to match against
      order - sort order. Valid values: "ASC" (Ascending) or "DESC" (Descending)
      limit - the maximum number of results to return from this query
      offset - the offset to start reading from
      Returns:
      a sorted list of variables
    • OptRecord

      public Optional<SectionVariableValueRecord> OptRecord(String fName, String section, String key)
      Returns the record for the given table, section, and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      an Optional that may contain a SectionVariableValueRecord if the row exists
    • OptRecord

      public Optional<SectionVariableValueRecord> OptRecord(SectionVariableValueTable table, String section, String key)
      Returns the record for the given table, section, and key
      Parameters:
      table - the table to search
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      an Optional that may contain a SectionVariableValueRecord if the row exists
    • OptString

      public Optional<String> OptString(String fName, String section, String key)
      Returns the value of the value column for the given table, section, and key as a string

      It is not possible to distinguish between the SQL value NULL and the table/row not being found with this method

      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      an Optional that may contain the value
    • GetString

      public String GetString(String fName, String section, String key)
      Returns the value of the value column for the given table, section, and key as a string

      A return value of null may denote that the table/row is not found, or that the actual stored value is SQL NULL. Use HasKey(String, String, String) to verify if the row exists

      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      the value
    • GetString

      public String GetString(String fName, String section, String key, String fallback)
      Returns the value of the value column for the given table, section, and key as a string
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      fallback - the fallback String; returned if the key is not present or the string is null
      Returns:
      the value; fallback if not found or the value being null
    • SetString

      public void SetString(String fName, String section, String key, String value)
      Sets the value of the value column for the given table, section, and key as a string
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to update
      value - the new value of the value column
    • InsertString

      public void InsertString(String fName, String section, String key, String value)
      Sets the value of the value column for the given table, section, and key as a string
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to update
      value - the new value of the value column
    • IncreaseBatchString

      public void IncreaseBatchString(String fName, String section, String[] keys, String value)
      Increases the value of the value column as an integer for all keys of the given table and section
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      keys - the values of the variable column to update
      value - the new value to increase the value column by
    • SetBatchString

      public void SetBatchString(String fName, String section, String[] keys, String[] values)
      Performs a bulk SetString(String, String, String, String) operation, using available database features to do so more efficiently.

      The array index of the keys and value params are linked

      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      keys - the values of the variable column to update
      values - the new values to set the value column to
    • OptLong

      public Optional<Long> OptLong(String fName, String section, String key)
      Returns the value of the value column for the given table, section, and key as a long
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      an Optional that may contain the value as a long
    • GetLong

      public long GetLong(String fName, String section, String key)
      Returns the value of the value column for the given table, section, and key as a long
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      the value as a long; 0L if the conversion fails
    • GetLong

      public long GetLong(String fName, String section, String key, long fallback)
      Returns the value of the value column for the given table, section, and key as a long
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      fallback - the fallback int; returned if the key is not present
      Returns:
      the value as a long; fallback if the conversion fails
    • SetLong

      public void SetLong(String fName, String section, String key, long value)
      Sets the value of the value column for the given table, section, and key as a long
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      value - the new value of the value column
    • OptInteger

      public Optional<Integer> OptInteger(String fName, String section, String key)
      Returns the value of the value column for the given table, section, and key as an integer
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      an Optional that may contain the value as an integer
    • GetInteger

      public int GetInteger(String fName, String section, String key)
      Returns the value of the value column for the given table, section, and key as an integer
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      the value as an integer; 0 if the conversion fails
    • GetInteger

      public int GetInteger(String fName, String section, String key, int fallback)
      Returns the value of the value column for the given table, section, and key as an integer
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      fallback - the fallback integer; returned if the key is not present
      Returns:
      the value as an integer; fallback if the conversion fails
    • SetInteger

      public void SetInteger(String fName, String section, String key, int value)
      Sets the value of the value column for the given table, section, and key as an integer
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      value - the new value of the value column
    • OptFloat

      public Optional<Float> OptFloat(String fName, String section, String key)
      Returns the value of the value column for the given table, section, and key as a float
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      an Optional that may contain the value as a float
    • GetFloat

      public float GetFloat(String fName, String section, String key)
      Returns the value of the value column for the given table, section, and key as a float
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      the value as a float; 0.0f if the conversion fails
    • GetFloat

      public float GetFloat(String fName, String section, String key, float fallback)
      Returns the value of the value column for the given table, section, and key as a float
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      fallback - the fallback float; returned if the key is not present
      Returns:
      the value as a float; fallback if the conversion fails
    • SetFloat

      public void SetFloat(String fName, String section, String key, float value)
      Sets the value of the value column for the given table, section, and key as a float
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      value - the new value of the value column
    • OptDouble

      public Optional<Double> OptDouble(String fName, String section, String key)
      Returns the value of the value column for the given table, section, and key as a double
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      an Optional that may contain the value as a double
    • GetDouble

      public double GetDouble(String fName, String section, String key)
      Returns the value of the value column for the given table, section, and key as a double
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      the value as a double; 0.0 if the conversion fails
    • GetDouble

      public double GetDouble(String fName, String section, String key, double fallback)
      Returns the value of the value column for the given table, section, and key as a double
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      fallback - the fallback double; returned if the key is not present
      Returns:
      the value as a double; fallback if the conversion fails
    • SetDouble

      public void SetDouble(String fName, String section, String key, double value)
      Sets the value of the value column for the given table, section, and key as a double
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      value - the new value of the value column
    • OptBoolean

      public Optional<Boolean> OptBoolean(String fName, String section, String key)
      Returns the value of the value column for the given table, section, and key as a boolean
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      an Optional that may contain the value as a boolean; true if the value as a string is "1", "true", or "yes"; false otherwise
    • GetBoolean

      public boolean GetBoolean(String fName, String section, String key)
      Returns the value of the value column for the given table, section, and key as a boolean
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      Returns:
      true if the value as a string is "1", "true", or "yes"; false otherwise
    • GetBoolean

      public boolean GetBoolean(String fName, String section, String key, boolean fallback)
      Returns the value of the value column for the given table, section, and key as a boolean
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      fallback - the fallback boolean; returned if the key is not present
      Returns:
      true if the value as a string is "1", "true", or "yes"; fallback otherwise
    • SetBoolean

      public void SetBoolean(String fName, String section, String key, boolean value)
      Sets the value of the value column for the given table, section, and key as a boolean
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column to retrieve
      value - the new value of the value column
    • RemoveKey

      public void RemoveKey(String fName, String section, String key)
      Deletes the row that matches the given table, section, and key

      If section is null, deletes all rows with a matching table and key, regardless of section

      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column
    • RemoveSection

      public void RemoveSection(String fName, String section)
      Deletes all rows that match the given table and section
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section
    • AddFile

      public void AddFile(String fName)
      Creates a new table
      Parameters:
      fName - a table name, without the phantombot_ prefix
    • RemoveFile

      public void RemoveFile(String fName)
      Deletes the table
      Parameters:
      fName - a table name, without the phantombot_ prefix
    • RenameFile

      public void RenameFile(String fNameSource, String fNameDest)
      Renames the table
      Parameters:
      fNameSource - a table name for an existing table, without the phantombot_ prefix
      fNameDest - a new table name that does not yet exist, without the phantombot_ prefix
    • FileExists

      public boolean FileExists(String fName)
      Indicates if the given table already exists
      Parameters:
      fName - a table name, without the phantombot_ prefix
      Returns:
      true if the table exists
    • HasKey

      public boolean HasKey(String fName, String section, String key)
      Indicates if the given table contains a row matching the given section and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) or null for all sections
      key - the value of the variable column
      Returns:
      true if the key exists
    • exists

      public boolean exists(String fName, String key)
      Indicates if the given table contains a row matching the given key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      key - the value of the variable column
      Returns:
      true if the key exists
    • get

      public String get(String fName, String key)
      Returns the value of the value column from the default section of the given table and key as a string

      A return value of null may denote that the table/row is not found, or that the actual stored value is SQL NULL. Use exists(String, String) to verify if the row exists

      Parameters:
      fName - a table name, without the phantombot_ prefix
      key - the value of the variable column to retrieve
      Returns:
      the value; null if not found
    • set

      public void set(String fName, String key, String value)
      Sets the value of the value column for the default section of the given table and key as a string
      Parameters:
      fName - a table name, without the phantombot_ prefix
      key - the value of the variable column to update
      value - the new value of the value column
    • setbatch

      public void setbatch(String fName, String[] keys, String[] values)
      Performs a bulk set(String, String, String) operation, using available database features to do so more efficiently.

      The array index of the keys and value params are linked

      Parameters:
      fName - a table name, without the phantombot_ prefix
      keys - the values of the variable column to update
      value - the new values to set the value column to
    • del

      public void del(String fName, String key)
      Deletes the row from the default section that matches the given table and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      key - the value of the variable column
    • incr

      public void incr(String fName, String section, String key, int amount)
      Increases the value of the value column as an integer in the given table, section, and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column
      amount - the amount to increase the value of the value column by
    • incr

      public void incr(String fName, String key, int amount)
      Increases the value of the value column as an integer in the default section of the given table and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      key - the value of the variable column
      amount - the amount to increase the value of the value column by
    • incrL

      public void incrL(String fName, String section, String key, long amount)
      Increases the value of the value column as a long in the given table, section, and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column
      amount - the amount to increase the value of the value column by
    • incrL

      public void incrL(String fName, String key, long amount)
      Increases the value of the value column as a long in the default section of the given table and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      key - the value of the variable column
      amount - the amount to increase the value of the value column by
    • incrD

      public void incrD(String fName, String section, String key, double amount)
      Increases the value of the value column as an integer in the given table, section, and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column
      amount - the amount to increase the value of the value column by
    • incrD

      public void incrD(String fName, String key, double amount)
      Increases the value of the value column as an integer in the default section of the given table and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      key - the value of the variable column
      amount - the amount to increase the value of the value column by
    • incrF

      public void incrF(String fName, String section, String key, float amount)
      Increases the value of the value column as an integer in the given table, section, and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column
      amount - the amount to increase the value of the value column by
    • incrF

      public void incrF(String fName, String key, float amount)
      Increases the value of the value column as an integer in the default section of the given table and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      key - the value of the variable column
      amount - the amount to increase the value of the value column by
    • decr

      public void decr(String fName, String section, String key, int amount)
      Decreases the value of the value column as an integer in the given table, section, and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column
      value - the amount to decrease the value of the value column by
    • decr

      public void decr(String fName, String key, int amount)
      Decreases the value of the value column as an integer in the default section of the given table and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      key - the value of the variable column
      amount - the amount to decrease the value of the value column by
    • decrL

      public void decrL(String fName, String key, long amount)
      Decreases the value of the value column as a long in the default section of the given table and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      key - the value of the variable column
      amount - the amount to decrease the value of the value column by
    • decrL

      public void decrL(String fName, String section, String key, long amount)
      Decreases the value of the value column as a long in the given table, section, and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column
      amount - the amount to decrease the value of the value column by
    • decrD

      public void decrD(String fName, String key, double amount)
      Decreases the value of the value column as a long in the default section of the given table and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      key - the value of the variable column
      amount - the amount to decrease the value of the value column by
    • decrD

      public void decrD(String fName, String section, String key, double amount)
      Decreases the value of the value column as a long in the given table, section, and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column
      amount - the amount to decrease the value of the value column by
    • decrF

      public void decrF(String fName, String key, float amount)
      Decreases the value of the value column as a long in the default section of the given table and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      key - the value of the variable column
      amount - the amount to decrease the value of the value column by
    • decrF

      public void decrF(String fName, String section, String key, float amount)
      Decreases the value of the value column as a long in the given table, section, and key
      Parameters:
      fName - a table name, without the phantombot_ prefix
      section - a section name. "" (empty string) for the default section; null for all sections
      key - the value of the variable column
      amount - the amount to decrease the value of the value column by
    • searchByValue

      public String[] searchByValue(String fName, String search)
      Returns a list of values in the variable column within the default section of the table, where the value of the value column contains the search phrase
      Parameters:
      fName - a table name, without the phantombot_ prefix
      search - the partial value of the value column to match against
      Returns:
      a list of variables
    • searchByKey

      public String[] searchByKey(String fName, String search)
      Returns a list of values in the variable column within the default section of the table, where the value of the variable column contains the search phrase
      Parameters:
      fName - a table name, without the phantombot_ prefix
      search - the partial value of the variable column to match against
      Returns:
      a list of variables
    • query

      public List<List<String>> query(String sql, String[] replacements)
      Executes an SQL query

      The query is executed using a PreparedStatement with calls to PreparedStatement.setString(int, String)

      For example:
      executeSql("SELECT * FROM foo WHERE bar = ?", ["baz"])

      The value "baz" is escaped to prevent SQL injection, then inserted in place of the ?

      This yields the final query of
      SELECT * FROM foo WHERE bar = "baz"

      You can use ? as many times as necessary, but must provide the same number of elements in the replacements array for the replacement to work

      Replacements are performed in order from left to right

      Exceptions from failed SQL queries are NOT returned or thrown, but are logged in the core-error log

      Parameters:
      sql - The query to execute
      replacements - Replacements for PreparedStatement.setString(int, String)
      Returns:
      An List of data as strings representing the result set, if the query was a DQL statement; an empty list otherwise. The outer list represents rows; the inner array represents columns; the values of the inner list represent the value of the row-column pair at that index as a string
    • executeSql

      public String[][] executeSql(String sql, String[] replacements)
      Executes an SQL query

      The query is executed using a PreparedStatement with calls to PreparedStatement.setString(int, String)

      For example:
      executeSql("SELECT * FROM foo WHERE bar = ?", ["baz"])

      The value "baz" is escaped to prevent SQL injection, then inserted in place of the ?

      This yields the final query of
      SELECT * FROM foo WHERE bar = "baz"

      You can use ? as many times as necessary, but must provide the same number of elements in the replacements array for the replacement to work

      Replacements are performed in order from left to right

      Exceptions from failed SQL queries are NOT returned or thrown, but are logged in the core-error log

      Parameters:
      sql - The query to execute
      replacements - Replacements for PreparedStatement.setString(int, String)
      Returns:
      An array of data as strings representing the result set, if the query was a DQL statement; empty arrays otherwise. The outer array represents rows; the inner array represents columns; the values of the inner array represent the value of the row-column pair at that index as a string
    • CreateIndexes

      @Deprecated(since="3.9.0.0", forRemoval=true) public void CreateIndexes()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Indexes are created automatically upon CREATE TABLE
      Ensures that all tables created with AddFile(String) have a UNIQUE index across the section and variable columns

      If a constraint violation occurs while attempting to create the index, all rows violating the constraint except the first for each pair are deleted

    • DropIndexes

      @Deprecated(since="3.9.0.0", forRemoval=true) public void DropIndexes()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Indexes are dropped automatically upon DROP TABLE
      Drops all UNIQUE indexes from tables created with AddFile(String)
    • CanConnect

      public boolean CanConnect()
      Tests if the connection to the database succeeds
      Returns:
      true on success
    • canBackup

      public boolean canBackup()
      Indicates if this database type supports generating backup files
      Returns:
      true if backups are supported
    • backupDB

      public void backupDB(String filename)
      Backs up the database to the specified filename in the dbbackup folder
      Parameters:
      filename - The filename for the backup, without extension
    • dispose

      @Deprecated(since="3.9.0.0", forRemoval=true) public void dispose()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please instead call Datastore2.dispose()
      Cleanup open connections