Class SQLSyntaxUtil

java.lang.Object
com.github.tadukoo.database.mysql.syntax.SQLSyntaxUtil

public class SQLSyntaxUtil extends Object
SQL Syntax Util provides utilities for handling SQL syntax.
Version:
Alpha v.0.3
Author:
Logan Ferree (Tadukoo)
  • Constructor Details

    • SQLSyntaxUtil

      private SQLSyntaxUtil()
      Not allowed to instantiate SQLSyntaxUtil
  • Method Details

    • convertValueToString

      public static String convertValueToString(Object value)
      Converts the given object into a string to use for a value in MySQL
      Parameters:
      value - The object to convert
      Returns:
      The string representing the given value
    • getValueBasedOnColumnDefinition

      public static Object getValueBasedOnColumnDefinition(ResultSet resultSet, String tableName, ColumnDefinition columnDef) throws SQLException
      Extracts a value from the given ResultSet based on the info in the given ColumnDefinition
      Parameters:
      resultSet - The ResultSet to extract data from
      tableName - The name of the table (can be blank)
      columnDef - The ColumnDefinition to use for info
      Returns:
      The extracted value
      Throws:
      SQLException - If anything goes wrong
    • makeColumnRef

      public static ColumnRef makeColumnRef(String columnName)
      Makes a single ColumnRef using the given columnName
      Parameters:
      columnName - The name of the column
      Returns:
      A ColumnRef with the given columnName
    • makeColumnRefs

      public static List<ColumnRef> makeColumnRefs(Collection<String> columnNames)
      Makes a List of ColumnRefs using the given columnNames
      Parameters:
      columnNames - The names of the columns
      Returns:
      A List of ColumnRefs with the given columnNames
    • makeConditionalStmt

      public static ConditionalStatement makeConditionalStmt(boolean search, String columnName, Object value)
      Creates a ConditionalStatement using the given parameters.

      If search is false, it will create an equals statement with the given columnName and value

      If search is true, it will create an equals statement for all non-string values. For String values, it will create a LIKE statement and surround the value with % for matching strings with that value anywhere in the string
      Parameters:
      search - Whether to consider this a search and do LIKE for strings, or not
      columnName - The name of the column
      value - The value for the conditional statement
      Returns:
      A new ConditionalStatement
    • makeConditional

      public static Conditional makeConditional(Collection<String> columnNames, Collection<Object> values, boolean search)
      Makes a Conditional using the given parameters
      Parameters:
      columnNames - The names of the columns to use in the Conditional
      values - The values to use in the Conditional
      search - Whether to consider this a search or not
      Returns:
      The Conditional that was made from the parameters
    • formatInsertStatement

      public static String formatInsertStatement(String table, Collection<String> columnNames, Collection<Object> values)
      Creates an Insert statement for the given parameters
      Parameters:
      table - The name of the table to insert into
      columnNames - The names of the columns to insert into
      values - The values to insert into the columns
      Returns:
      The SQL text for the insert statement
    • formatUpdateStatement

      public static String formatUpdateStatement(String table, Collection<String> columnNames, Collection<Object> values, Collection<String> whereColNames, Collection<Object> whereValues)
      Creates an Update statement for the given parameters
      Parameters:
      table - The name of the table to update
      columnNames - The names of the columns to be updated
      values - The values to be updated
      whereColNames - The names of the columns for the where statement
      whereValues - The values for the where statement
      Returns:
      The SQL text for the update statement
    • formatQuery

      public static String formatQuery(Collection<String> tables, Collection<String> returnColumns, Collection<String> cols, Collection<Object> values, boolean search)
      Creates a Select statement for the given parameters
      Parameters:
      tables - The name of the tables to select from
      returnColumns - The names of the columns to be returned
      cols - The names of the columns to include in the where query
      values - The values for the columns in the where query
      search - Whether this is a search (to do LIKE %value% for string values instead of equals)
      Returns:
      The SQL text for the select statement