Skip to content
Snippets Groups Projects
Commit d1df4837 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

HowToSqlConditionLib.adoc added

parent 1a5548d5
No related branches found
No related tags found
No related merge requests found
How to use the SqlCondition
===========================
How to use the SqlCondition (state: 06.12.2018)
===============================================
:toc2: left
:numbered:
......@@ -72,6 +72,9 @@ The field name needs to be given with
Or if you use only COLUMNNAME, you have to provide the fieldType.
But keep in mind: Other than the original adito db. functions this lib caches the field types automatically (for the livetime of an SqlCondition Object).
So most times it is save to use the first method. Even in loops or if you use the same Column several times.
[source,javascript]
----
myDescriptiveNameOfTheCondition.orPrepared("PERS.FIRSTNAME", 'Bob', "#<?");
......@@ -136,4 +139,47 @@ Same as build and adds a string before and after the condition.
[source,javascript]
----
var myPreparedStatementArray = myDescriptiveNameOfTheCondition.buildSelect("select * from PERS", "1=0", "order by FIRSTNAME");
----
\ No newline at end of file
----
== real world example ==
Some examples, how this lib can be used.
[source,javascript]
----
var productPriceData = (db.ROW, db.array(SqlCondition.begin()
.andPrepare("PRODUCTPRICE.BUYSELL", buySell)
.andPrepare("PRODUCTPRICE.PRODUCT_ID", pid)
.andPrepare("PRODUCTPRICE.VALID_FROM", today, "# <= ?")
.andSqlCondition(SqlCondition.begin()
.orPrepare("PRODUCTPRICE.VALID_TO", today, "# >= ?")
.or("PRODUCTPRICE.VALID_TO is null"), "1 = 2");
.buildSelect("select PRICE, CURRENCY from PRODUCTPRICE", "1 = 2", "order by VALID_FROM desc")));
----
With a loop:
[source,javascript]
----
function _getClassificationCondition(include)
{
var resultingCondition = new SqlCondition();
resultingCondition.andPrepare("SALESPROJECT_CLASSIFICATION.SALESPROJECT_ID", salesprojectId)
.andPrepare("SALESPROJECT_CLASSIFICATION.CLASS", classId);
var typeCondition = new SqlCondition();
entryKeywords.forEach(function(entry)
{
if (include)
{
typeCondition.orPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry[0], "# = ?");
}
else
{
typeCondition.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry[0], "# <> ?");
}
});
resultingCondition.andSqlCondition(typeCondition, "1 = 0");
return resultingCondition;
}
----
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment