Class SQLSyntaxUtil
java.lang.Object
com.github.tadukoo.database.mysql.syntax.SQLSyntaxUtil
SQL Syntax Util provides utilities for handling SQL syntax.
- Version:
- Alpha v.0.3
- Author:
- Logan Ferree (Tadukoo)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconvertValueToString(Object value) Converts the given object into a string to use for a value in MySQLstatic StringformatInsertStatement(String table, Collection<String> columnNames, Collection<Object> values) Creates an Insert statement for the given parametersstatic StringformatQuery(Collection<String> tables, Collection<String> returnColumns, Collection<String> cols, Collection<Object> values, boolean search) Creates a Select statement for the given parametersstatic StringformatUpdateStatement(String table, Collection<String> columnNames, Collection<Object> values, Collection<String> whereColNames, Collection<Object> whereValues) Creates an Update statement for the given parametersstatic ObjectgetValueBasedOnColumnDefinition(ResultSet resultSet, String tableName, ColumnDefinition columnDef) Extracts a value from the givenResultSetbased on the info in the givenColumnDefinitionstatic ColumnRefmakeColumnRef(String columnName) Makes a singleColumnRefusing the given columnNamemakeColumnRefs(Collection<String> columnNames) Makes a List ofColumnRefsusing the given columnNamesstatic ConditionalmakeConditional(Collection<String> columnNames, Collection<Object> values, boolean search) Makes aConditionalusing the given parametersstatic ConditionalStatementmakeConditionalStmt(boolean search, String columnName, Object value) Creates aConditionalStatementusing the given parameters.
-
Constructor Details
-
SQLSyntaxUtil
private SQLSyntaxUtil()Not allowed to instantiate SQLSyntaxUtil
-
-
Method Details
-
convertValueToString
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 givenResultSetbased on the info in the givenColumnDefinition- Parameters:
resultSet- TheResultSetto extract data fromtableName- The name of the table (can be blank)columnDef- TheColumnDefinitionto use for info- Returns:
- The extracted value
- Throws:
SQLException- If anything goes wrong
-
makeColumnRef
Makes a singleColumnRefusing the given columnName- Parameters:
columnName- The name of the column- Returns:
- A
ColumnRefwith the given columnName
-
makeColumnRefs
Makes a List ofColumnRefsusing the given columnNames- Parameters:
columnNames- The names of the columns- Returns:
- A List of
ColumnRefswith the given columnNames
-
makeConditionalStmt
public static ConditionalStatement makeConditionalStmt(boolean search, String columnName, Object value) Creates aConditionalStatementusing the given parameters.
If search isfalse, it will create an equals statement with the given columnName and value
If search istrue, 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 notcolumnName- The name of the columnvalue- The value for the conditional statement- Returns:
- A new
ConditionalStatement
-
makeConditional
public static Conditional makeConditional(Collection<String> columnNames, Collection<Object> values, boolean search) Makes aConditionalusing the given parameters- Parameters:
columnNames- The names of the columns to use in theConditionalvalues- The values to use in theConditionalsearch- Whether to consider this a search or not- Returns:
- The
Conditionalthat 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 intocolumnNames- The names of the columns to insert intovalues- 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 updatecolumnNames- The names of the columns to be updatedvalues- The values to be updatedwhereColNames- The names of the columns for the where statementwhereValues- 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 fromreturnColumns- The names of the columns to be returnedcols- The names of the columns to include in the where queryvalues- The values for the columns in the where querysearch- Whether this is a search (to do LIKE %value% for string values instead of equals)- Returns:
- The SQL text for the select statement
-