java.lang.Object
studio.magemonkey.codex.mccore.sql.direct.SQLTable

public class SQLTable extends Object

Represents a single table in a MySQL database.

If you close the MySQL connection, this will become invalid as it uses prepared statements from that connection. Get the tables each time you connect to the database rather than saving them.

  • Constructor Details

    • SQLTable

      public SQLTable(SQLDatabase sql, String name)

      Constructs a new table. This should only be called by SQLDatabase when it creates a new table or retrieves an already created one.

      Parameters:
      sql - sql connection
      name - name of the table
  • Method Details

    • getName

      public String getName()

      Retrieves the name of the table.

      Returns:
      table name
    • columnExists

      public boolean columnExists(String name)

      Checks whether or not a column exists in the table.

      Parameters:
      name - name of the column
      Returns:
      true if exists, false otherwise
    • getColumnType

      public String getColumnType(String name)
    • createColumn

      public void createColumn(String name, ColumnType type)

      Creates a new column in the table.

      Parameters:
      name - name of the column
      type - type of the column
    • query

      public ResultSet query(String name)
      Queries the MySQL table for a specific entry
      Parameters:
      name - entry name
      Returns:
      query results
    • queryAll

      public ResultSet queryAll()
      Queries the MySQL table
      Returns:
      query results
    • getAllData

      public <T extends ISQLEntryData> List<T> getAllData(Class<T> c)

      Loads the data from the table using the data class provided.

      This returns null an error occurred.

      Type Parameters:
      T - the type of the data class
      Parameters:
      c - the data class to use
      Returns:
      the list of loaded data
    • entryExists

      public boolean entryExists(String name)
      Checks if an entry already exists
      Parameters:
      name - entry name
      Returns:
      true if exists, false otherwise
    • createEntry

      public SQLEntry createEntry(String name)

      Creates a new entry from the table.

      If the entry already exists, that will be returned instead.

      Parameters:
      name - name of the entry
      Returns:
      entry representation
    • deleteEntry

      public boolean deleteEntry(String name)

      Deletes an entry from the table.

      Parameters:
      name - entry name
      Returns:
      true if successful, false otherwise