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
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
convertValueToString
(Object value) Converts the given object into a string to use for a value in MySQLstatic String
formatInsertStatement
(String table, Collection<String> columnNames, Collection<Object> values) Creates an Insert statement for the given parametersstatic String
formatQuery
(Collection<String> tables, Collection<String> returnColumns, Collection<String> cols, Collection<Object> values, boolean search) Creates a Select statement for the given parametersstatic String
formatUpdateStatement
(String table, Collection<String> columnNames, Collection<Object> values, Collection<String> whereColNames, Collection<Object> whereValues) Creates an Update statement for the given parametersstatic Object
getValueBasedOnColumnDefinition
(ResultSet resultSet, String tableName, ColumnDefinition columnDef) Extracts a value from the givenResultSet
based on the info in the givenColumnDefinition
static ColumnRef
makeColumnRef
(String columnName) Makes a singleColumnRef
using the given columnNamemakeColumnRefs
(Collection<String> columnNames) Makes a List ofColumnRefs
using the given columnNamesstatic Conditional
makeConditional
(Collection<String> columnNames, Collection<Object> values, boolean search) Makes aConditional
using the given parametersstatic ConditionalStatement
makeConditionalStmt
(boolean search, String columnName, Object value) Creates aConditionalStatement
using 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 givenResultSet
based on the info in the givenColumnDefinition
- Parameters:
resultSet
- TheResultSet
to extract data fromtableName
- The name of the table (can be blank)columnDef
- TheColumnDefinition
to use for info- Returns:
- The extracted value
- Throws:
SQLException
- If anything goes wrong
-
makeColumnRef
Makes a singleColumnRef
using the given columnName- Parameters:
columnName
- The name of the column- Returns:
- A
ColumnRef
with the given columnName
-
makeColumnRefs
Makes a List ofColumnRefs
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 aConditionalStatement
using 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 aConditional
using the given parameters- Parameters:
columnNames
- The names of the columns to use in theConditional
values
- The values to use in theConditional
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 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
-