(it is possible but not recommended to use a whole join-string for the table e.g. "PERSON on PERSONID = PERSON_ID". Only use this, if you don't have a seperate string for the on-condition.)
Subselects are also possible by using a SqlBuilder
(e.g. newSelect("FIRSTNAME").from("PERSON"))
* pCondition is the on-condition.
You can provide it as String (e.g. "PERSONID = PERSON_ID")
or as SqlBuilder (e.g. newWhere("PERSON.PERSONID", myPersonid))
* pTableAlias just adds an alias-name for the table.
* pPrefix here you can specify a prefix for the join. (e.g. "left")
.leftJoin / .rightJoin fill this automatically
* pReplacementForWordJoin is for using something different as the word "join". This is added to support db-specific use cases.
An example:
[source,js]
----
var costData = newSelect("CAMPAIGNCOSTID, CAMPAIGNSTEP_ID, CAMPAIGNSTEP.NAME, CATEGORY, NET")
the parameter can be filled the same way as .select(pFields)
=== having
having(pCondition) adds a having condition to the sql.
pCondition can be a simple string or a SqlBuilder containing a condition. (only the condition from it is used)
=== order by
orderBy(pFields) just adds a order by to the sql
the parameter can be filled the same way as .select(pFields)
=== Examples and Use Cases
== Examples and Use Cases
==== already complete condition
=== already complete condition
If the first parameter is the only one you set, it is treated as a complete condition:
[source,js]
...
...
@@ -223,7 +278,7 @@ var cond = newWhere("PERSON.FIRSTNAME", "Tim")
// ( PERSON.FIRSTNAME = 'Tim' or PERSON.FIRSTNAME = 'Fritz' and PERSON.FIRSTNAME = 'Peter' )
----
==== simple condition with and & or
=== simple condition with and & or
You can just combine and & or as you like:
[source,js]
...
...
@@ -238,7 +293,7 @@ var cond = newWhere("PERSON.FIRSTNAME", "Tim")
(Note: the AND before OR: (Tim && Admin) || (Peter && Meier))
==== JDito Variables
=== JDito Variables
It is also possible to just pass JDito variables directly:
[source,js]
----
...
...
@@ -248,14 +303,14 @@ Note: it is checked for vars.getString(...) != null and vars.getString(...) != u
If you want to check also for != "" and vars.exists(...) you have to do it by yourself explicitely.
==== other condition than "# = ?"
=== other condition than "# = ?"
If you need something different as the default "# = ?" condition just pass a string to pCondition.
Note that the # is replaced by the Table.Column from the first param and ? is the place where the value schould be inserted.
==== codition like "year(#) = ?" with specific FieldType
=== condition like "year(#) = ?" with specific FieldType
It is also possible to use more complex sql such as "year(#) = ?" But keep in mind that this may change the SQLTYPE needed and you may have to provede it manually by the 4th param if it cannot be loaded by the table and column name.
==== Subquery
=== Subquery
Subqueries are also possible by providing either another Sql condition or a prepared-statement array.
Some possible combinations:
...
...
@@ -289,7 +344,7 @@ var cond = newWhere("TABLE.FIELD", aSqlBuilderContainingFullSelect)
// cond.build() results in ["( TABLE.FIELD = ( select LASTNAME from PERSON where PERSON.FIRSTNAME = ? ) ) ", [['Fritz', SQLTYPES.VARCHAR]]]
----
==== IN statement with array of values
=== IN statement with array of values
pValue can also be an array of values which is automatically transfered into a SQL prepared statement SQL like this: