Package org.apache.empire.db
Class DBSQLBuilder
java.lang.Object
org.apache.empire.db.DBSQLBuilder
- All Implemented Interfaces:
Appendable
- Direct Known Subclasses:
DBMSHandlerBase.DBMSBuilder,DBMSHandlerMSSQL.DBSQLBuilderMSSQL,DBMSHandlerMySQL.DBSQLBuilderMySQL
DBSQLBuilder
This class is used for building a single SQL statement
- Author:
- doebele
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DBCmdParamListprotected final DBMSHandlerprotected final StringBuilderprotected static final char -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDBSQLBuilder(DBMSHandler dbms) Don't use this directly Use dbms.createSQLBuilder() -
Method Summary
Modifier and TypeMethodDescriptionappend(char c) append(double d) append(long l) append(CharSequence sqlLiteral) append(CharSequence sqlLiteral, int start, int end) voidappend(DBCommandExpr subQueryCmd) append(DBSqlPhrase phrase) protected voidappendSimpleValue(DataType type, Object value) Returns a sql string for a given value.protected voidappendStringLiteral(DataType type, Object value) encodes Text values for an SQL command string.voidappendTemplate(String template, Object[] values, DataType[] dataTypes, long context, String arraySep) Expands an SQL template and adds it to the SQL commandvoidappendValue(DataType type, Object value) Appends the SQL representation of a valuefinal voidappendValue(DataType dataType, Object value, long context) Appends the SQL representation of a valuevoidappendValue(DataType dataType, Object value, long context, String arraySep) Appends the SQL representation of a valueprotected voidescapeAndAppendLiteral(String value) this helper function doubles up single quotes for SQLprotected StringgetDateTimeString(Object value, DBSqlPhrase sqlTemplate, DBSqlPhrase sqlPattern, DBSqlPhrase sqlCurrentDate) encodes a Date value for an SQL command string.getDbms()protected StringgetNumberString(Object value, DataType type) encodes a numeric value for an SQL command string.getPhrase(DBSqlPhrase phrase) intlength()voidvoidreset(int pos) voidsetCmdParams(DBCmdParamList cmdParamList) protected booleanstringToBoolean(String value) this function converts a string containing a boolean expression to a boolean.toString()returns the SQL as a String
-
Field Details
-
TEXT_DELIMITER
protected static final char TEXT_DELIMITER- See Also:
-
dbms
-
sql
-
cmdParamList
-
-
Constructor Details
-
DBSQLBuilder
Don't use this directly Use dbms.createSQLBuilder()- Parameters:
dbms- the dbms handler
-
-
Method Details
-
setCmdParams
-
toString
returns the SQL as a String -
getDbms
-
getPhrase
-
length
public int length() -
reset
public void reset(int pos) -
replace
-
append
- Specified by:
appendin interfaceAppendable
-
append
- Specified by:
appendin interfaceAppendable
-
append
- Specified by:
appendin interfaceAppendable
-
append
-
append
-
append
-
append
-
appendValue
Appends the SQL representation of a value- Parameters:
type- the data typevalue- an DBExpr object, array or a basis data type(e.g. int, String)
-
appendValue
Appends the SQL representation of a value- Parameters:
dataType- the DataTypevalue- an DBExpr object, array or a basis data type(e.g. int, String)context- the context of the DBColumnExpr objectarraySep- the separator value
-
appendValue
Appends the SQL representation of a value- Parameters:
dataType- the DataTypevalue- an DBExpr object, array or a basis data type(e.g. int, String)context- the context of the DBColumnExpr object
-
appendTemplate
public void appendTemplate(String template, Object[] values, DataType[] dataTypes, long context, String arraySep) Expands an SQL template and adds it to the SQL command- Parameters:
template- the SQL templatevalues- list of values to be inserted into the templatedataTypes- list of data typescontext- the context of the DBColumnExpr objectarraySep- the separator value
-
appendSimpleValue
Returns a sql string for a given value. Text will be enclosed in single quotes and existing single quotes will be doubled. Empty strings are treated as null. The syntax of Date, Datetime and Boolean values are DBMS specific.- Parameters:
type- the data type of the supplied valuevalue- the value which is inserted to the new String
-
getDateTimeString
protected String getDateTimeString(Object value, DBSqlPhrase sqlTemplate, DBSqlPhrase sqlPattern, DBSqlPhrase sqlCurrentDate) encodes a Date value for an SQL command string.- Parameters:
value- the value to encodesqlTemplate- the templatesqlPattern- the patternsqlCurrentDate- the current date phrase- Returns:
- the date time string
-
appendStringLiteral
encodes Text values for an SQL command string.- Parameters:
type- date type (can only be TEXT, CHAR, CLOB and UNIQUEID)value- the literal to be encoded
-
escapeAndAppendLiteral
this helper function doubles up single quotes for SQL- Parameters:
value- the string to escape and append
-
getNumberString
encodes a numeric value for an SQL command string.- Parameters:
value- the numeric valuetype- the number data type- Returns:
- the string representation of the number
-
stringToBoolean
this function converts a string containing a boolean expression to a boolean.- Parameters:
value- the string containing a boolean expression- Returns:
- true if the string contains either "true", "y" or "1" or false otherwise
-