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

use sql builder in basic

parent 8e8d0fb1
No related branches found
No related tags found
No related merge requests found
Showing
with 115 additions and 97 deletions
......@@ -3,7 +3,7 @@ import("system.db");
import("system.result");
import("Sql_lib");
var cond = newWhere("ACTIVITYLINK.ACTIVITY_ID", "$param.ActivityId_param");
var cond = newWhereIfSet("ACTIVITYLINK.ACTIVITY_ID", "$param.ActivityId_param");
//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
result.string(cond.toString());
\ No newline at end of file
......@@ -10,7 +10,10 @@ if (vars.get("$param.OnlyActives_param") == "true")
cond.and("AB_KEYWORD_ENTRY.ISACTIVE", "1");
}
cond.andIfSet("AB_KEYWORD_ENTRY.KEYID", newWhere(vars.get("$param.ExcludedKeyIdsSubquery_param")), SqlBuilder.NOT_IN())
if (vars.get("$param.ExcludedKeyIdsSubquery_param"))
{
cond.and("AB_KEYWORD_ENTRY.KEYID not in ( " + vars.get("$param.ExcludedKeyIdsSubquery_param") + ")");
}
if (vars.getString("$param.WhitelistIds_param"))
cond.and("AB_KEYWORD_ENTRY.KEYID", JSON.parse(vars.getString("$param.WhitelistIds_param")), SqlBuilder.IN());
......
......@@ -6,9 +6,10 @@ import("Sql_lib");
if (vars.get("$field.UID") && vars.get("$field.DEST_OBJECTRELATIONTYPEID"))
{
db.deleteData("AB_OBJECTRELATION", SqlCondition.begin()
.andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID")
.andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID").build("1=2"));
newWhere("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID")
.and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID")
.deleteData(true, "AB_OBJECTRELATION");
question.showMessage(translate.withArguments("Deleted all usages of \"%0\".", [translate.text(vars.get("$field.SOURCE_RELATION_TITLE")) + " -> " + translate.text(vars.get("$field.DEST_RELATION_TITLE"))]), question.INFORMATION, translate.text("Successful"))
}
import("system.vars");
import("system.logging");
import("Sql_lib");
import("system.db");
import("system.result");
result.object(db.cell(SqlCondition.begin()
.andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID")
.andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID")
.buildSql("select count(*) from AB_OBJECTRELATION", "1=2")));
\ No newline at end of file
result.object(newSelect("count(*)")
.from("AB_OBJECTRELATION")
.whereIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID")
.andIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID")
.cell(true, "0"));
\ No newline at end of file
......@@ -4,16 +4,12 @@ import("system.translate");
import("system.question");
import("Sql_lib");
var usageCount = db.cell(SqlCondition.begin()
.andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID")
.andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID")
.buildSql("select count(*) from AB_OBJECTRELATION", "1=2"))
var usageCount = vars.get("$param.UsageCount_param");
if (usageCount <= 0)
{
db.deleteData("AB_OBJECTRELATIONTYPE", SqlCondition.begin()
.andPrepareVars("AB_OBJECTRELATIONTYPE.RELATION_TYPE", "$field.RELATION_TYPE")
.build("1=2"));
newWhere("AB_OBJECTRELATIONTYPE.RELATION_TYPE", "$field.RELATION_TYPE")
.deleteData(true, "AB_OBJECTRELATIONTYPE");
}
else
{
......
......@@ -30,10 +30,13 @@ vars.get("local.changed").forEach(function(pChange)
});
var updates = [];
var type1Cond = SqlCondition.begin().andPrepare("AB_OBJECTRELATIONTYPE.RELATION_TYPE", vars.get("$field.RELATION_TYPE"))
.andPrepare("AB_OBJECTRELATIONTYPE.SIDE", "1").build("1=2");
var type2Cond = SqlCondition.begin().andPrepare("AB_OBJECTRELATIONTYPE.RELATION_TYPE", vars.get("$field.RELATION_TYPE"))
.andPrepare("AB_OBJECTRELATIONTYPE.SIDE", "2").build("1=2");
var type1Cond = newWhere("AB_OBJECTRELATIONTYPE.RELATION_TYPE", vars.get("$field.RELATION_TYPE"))
.and("AB_OBJECTRELATIONTYPE.SIDE", "1")
.build();
var type2Cond = newWhere("AB_OBJECTRELATIONTYPE.RELATION_TYPE", vars.get("$field.RELATION_TYPE"))
.and("AB_OBJECTRELATIONTYPE.SIDE", "2")
.build();
for (let field in type1Fields) {
updates.push(["AB_OBJECTRELATIONTYPE", [field], null, [type1Fields[field]], type1Cond]);
......
import("system.logging");
import("Sql_lib");
import("system.vars");
import("system.result");
......@@ -6,16 +7,16 @@ import("ObjectRelation_lib");
var relationTypeData = ObjectRelationUtils.getRelationType(vars.get("$field.OBJECTRELATIONTYPEID"));
var sql1 = SqlUtils.translateStatementWithQuotes(SqlCondition.begin()
.andPrepareVars("AB_OBJECTRELATION.OBJECT1_ROWID", "$field.PARENT_ID")
.andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", relationTypeData[7])
.andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", relationTypeData[8])
.buildSql("select OBJECT2_ROWID from AB_OBJECTRELATION", "1=2"));
var sql2 = SqlUtils.translateStatementWithQuotes(SqlCondition.begin()
.andPrepareVars("AB_OBJECTRELATION.OBJECT2_ROWID", "$field.PARENT_ID")
.andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", relationTypeData[7])
.andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", relationTypeData[8])
.buildSql("select OBJECT1_ROWID from AB_OBJECTRELATION", "1=2"));
result.object([vars.get("$field.PARENT_ID")].concat(db.array(db.COLUMN, sql1 + " union " + sql2)));
\ No newline at end of file
var ids = newSelect("OBJECT2_ROWID")
.from("AB_OBJECTRELATION")
.whereIfSet("AB_OBJECTRELATION.OBJECT1_ROWID", "$field.PARENT_ID")
.and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", relationTypeData[7])
.and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", relationTypeData[8])
.union(newSelect("OBJECT1_ROWID")
.from("AB_OBJECTRELATION")
.whereIfSet("AB_OBJECTRELATION.OBJECT2_ROWID", "$field.PARENT_ID")
.and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", relationTypeData[7])
.and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", relationTypeData[8]))
.arrayColumn();
result.object([vars.get("$field.PARENT_ID")].concat(ids));
\ No newline at end of file
import("system.logging");
import("system.db");
import("system.translate");
import("system.result");
......@@ -276,10 +277,10 @@ function _getEntryData(pObjectId, pDirection, pRelationType1, pRelationType2, pP
{
if (pRelationType1 == undefined || pRelationType2 == undefined)
return [];
var myNum;
var otherNum;
if (pDirection == "normal")
{
otherNum = 1;
......@@ -291,27 +292,30 @@ function _getEntryData(pObjectId, pDirection, pRelationType1, pRelationType2, pP
myNum = 1;
}
var cond = SqlCondition.begin()
.andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pRelationType1)
.andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pRelationType2)
.andPrepare("AB_OBJECTRELATION.OBJECT" + myNum + "_ROWID", pObjectId)
.andPrepareIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", pObjectRelationId);
onConditionForRelationTypeJoin = newWhere("AB_OBJECTRELATIONTYPEID = AB_OBJECTRELATIONTYPE" + myNum)
.and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pRelationType1)
.and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pRelationType2)
.and("AB_OBJECTRELATION.OBJECT" + myNum + "_ROWID", pObjectId)
// set id to null, as only null works with .andIfSet
.andIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", (pObjectRelationId ? pObjectRelationId : null));
// exclude previous node
if (!pPrevId)
cond.and("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID is not null");
onConditionForRelationTypeJoin.and("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID is not null");
else
{
cond.andPrepare("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID", pPrevId, "# <> ?");
onConditionForRelationTypeJoin.and("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID", pPrevId, "# <> ?");
}
// TODO: BINDATA?
// var image = getImageObject("Beziehung");
var data = db.table(cond.buildSql(
"select OBJECT" + (pObjectRelationId ? myNum : otherNum) + "_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE, INFO, AB_OBJECTRELATIONTYPEID \n\
from AB_OBJECTRELATION \n\
join AB_OBJECTRELATIONTYPE on AB_OBJECTRELATIONTYPEID = AB_OBJECTRELATIONTYPE" + myNum + " and ","1=2", "", false));
var data = newSelect("OBJECT" + (pObjectRelationId ? myNum : otherNum) + "_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE, INFO, AB_OBJECTRELATIONTYPEID")
.from("AB_OBJECTRELATION")
.join("AB_OBJECTRELATIONTYPE", onConditionForRelationTypeJoin)
.table();
// try again with other side for "same"
if (data.length == 0 && pDirection == "same" && !pNoRecursion || pObjectRelationId && data.length > 0 && !data[0][ENTRY_DATA.objectId])
{
......@@ -379,13 +383,14 @@ function _getRootID(pObjectId, pObjectRelationTypeData)
{
var rootid = sourceid;
max--;
sourceid = db.cell(SqlCondition.begin()
.andPrepare("AB_OBJECTRELATION.OBJECT2_ROWID", sourceid)
.andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pObjectRelationTypeData[7])
.andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pObjectRelationTypeData[8])
.buildSql("select OBJECT1_ROWID from AB_OBJECTRELATION", "1=2"))
sourceid = newSelect("OBJECT1_ROWID")
.from("AB_OBJECTRELATION")
.where("AB_OBJECTRELATION.OBJECT2_ROWID", sourceid)
.and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pObjectRelationTypeData[7])
.and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pObjectRelationTypeData[8])
.cell()
}
while( sourceid != "" && max > 0 );
while(sourceid != "" && max > 0);
return rootid;
return currentObjectId;
}
\ No newline at end of file
......@@ -10,9 +10,8 @@ var isObjectRelationNode = typeof uid[2] == "string";
if (isObjectRelationNode)
{
var objectRelationId = uid[6];
db.deleteData("AB_OBJECTRELATION", SqlCondition.begin()
.andPrepareIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId)
.build("1=2"));
newWhereIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId)
.deleteData(true, "AB_OBJECTRELATION");
// Refresh otherwise the children of the deleted node would be moved to the root.
neon.refresh();
......
......@@ -11,8 +11,6 @@ if (isObjectRelationNode)
{
var objectRelationId = uid[6];
db.updateData("AB_OBJECTRELATION", ["INFO"], null, [vars.get("$field.INFO")],
SqlCondition.begin()
.andPrepareIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId)
.build("1=2"));
newWhereIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId)
.updateData(true, ["INFO"], null, [vars.get("$field.INFO")], "AB_OBJECTRELATION");
}
......@@ -2,8 +2,7 @@ import("system.db");
import("system.result");
import("Sql_lib");
var cond = new SqlCondition();
cond.andPrepareVars("OFFER.OBJECT_ROWID", "$param.ObjectRowId_param");
var cond = newWhereIfSet("OFFER.OBJECT_ROWID", "$param.ObjectRowId_param");
//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
result.string(cond.translate("1 = 1"));
\ No newline at end of file
//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
result.string(cond.toString());
\ No newline at end of file
......@@ -10,9 +10,10 @@ var contactid = vars.get("local.value");
if(contactid != "")
{
//Language Preset
var lang = db.cell(SqlCondition.begin()
.andPrepare("CONTACT.CONTACTID", contactid)
.buildSql("select ISOLANGUAGE from CONTACT"));
var lang = newSelect("ISOLANGUAGE")
.from("CONTACT")
.where("CONTACT.CONTACTID", contactid)
.cell();
if(lang != "")
neon.setFieldValue("field.ISOLANGUAGE", lang);
......
......@@ -20,9 +20,10 @@ if ((!vars.exists("$param.ContactId_param") || !vars.get("$param.ContactId_param
if (contactId)
{
var lang = db.cell(SqlCondition.begin()
.andPrepare("CONTACT.CONTACTID", contactId)
.buildSql("select ISOLANGUAGE from CONTACT"));
var lang = newSelect("ISOLANGUAGE")
.from("CONTACT")
.where("CONTACT.CONTACTID", contactId)
.cell();
if(lang != "")
neon.setFieldValue("field.ISOLANGUAGE", lang);
......
......@@ -16,8 +16,10 @@ else if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
if (vars.get("$field.ChoosenTEXFooter") != "")
{
var binaryId = db.cell(SqlCondition.begin()
.andPrepareVars("ASYS_BINARIES.ROW_ID", "$field.ChoosenTEXFooter")
.buildSql("select ID from ASYS_BINARIES"), SqlUtils.getBinariesAlias());
result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias())));
var binaryId = newSelect("ID", SqlUtils.getBinariesAlias())
.from("ASYS_BINARIES")
.whereIfSet("ASYS_BINARIES.ROW_ID", "$field.ChoosenTEXFooter")
.cell(true);
if (binaryId)
result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias())));
}
\ No newline at end of file
......@@ -16,8 +16,11 @@ else if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
if (vars.get("$field.ChoosenTEXHeader") != "")
{
var binaryId = db.cell(SqlCondition.begin()
.andPrepareVars("ASYS_BINARIES.ROW_ID", "$field.ChoosenTEXHeader")
.buildSql("select ID from ASYS_BINARIES"), SqlUtils.getBinariesAlias());
result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias())));
var binaryId = newSelect("ID", SqlUtils.getBinariesAlias())
.from("ASYS_BINARIES")
.whereIfSet("ASYS_BINARIES.ROW_ID", "$field.ChoosenTEXHeader")
.cell(true);
if (binaryId)
result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias())));
}
\ No newline at end of file
......@@ -4,9 +4,9 @@ import("system.result");
import("system.vars");
import("Sql_lib");
var iso3 = vars.get("$field.ISOLANGUAGE");
var latinName = db.cell(SqlCondition.begin()
.andPrepare("AB_LANGUAGE.ISO3", iso3)
.buildSql("select NAME_LATIN from AB_LANGUAGE", "1=0"));
latinName = translate.text(latinName);
result.string(latinName);
var latinName = newSelect("NAME_LATIN")
.from("AB_LANGUAGE")
.where("AB_LANGUAGE.ISO3", "$field.ISOLANGUAGE")
.cell();
result.string(translate.text(latinName));
......@@ -3,9 +3,10 @@ import("system.db");
import("Sql_lib");
import("system.neon");
var itemcount = db.cell(SqlCondition.begin()
.andPrepareVars("OFFERITEM.OFFER_ID", "$field.OFFERID")
.buildSql("select count(*) from OFFERITEM", "1=2"));
var itemcount = newSelect("count(*)")
.from("OFFERITEM")
.whereIfSet("OFFERITEM.OFFER_ID", "$field.OFFERID")
.cell(true, "0");
if(itemcount == "0")
result.string(neon.COMPONENTSTATE_DISABLED);
......
......@@ -2,4 +2,5 @@ import("Sql_lib");
import("system.vars");
import("system.db");
db.deleteData("OFFERITEM", SqlCondition.equals("OFFERITEM.OFFER_ID", vars.getString("$field.OFFERID"), "1=2"));
\ No newline at end of file
newWhere("OFFERITEM.OFFER_ID", "$field.OFFERID")
.deleteData(true, "OFFERITEM");
\ No newline at end of file
......@@ -3,16 +3,16 @@ import("system.db");
import("system.result");
import("Sql_lib");
var cond = new SqlCondition();
var cond = newWhere()
if(vars.exists("$param.ContactId_param") && vars.get("$param.ContactId_param"))
cond.andPrepareVars("OFFER.CONTACT_ID", "$param.ContactId_param");
cond.andIfSet("OFFER.CONTACT_ID", "$param.ContactId_param");
else {
cond.andPrepareVars("OFFER.OBJECT_ROWID", "$param.ObjectRowId_param");
cond.andPrepareVars("OFFER.OBJECT_TYPE", "$param.ObjectType_param");
cond.andIfSet("OFFER.OBJECT_ROWID", "$param.ObjectRowId_param");
cond.andIfSet("OFFER.OBJECT_TYPE", "$param.ObjectType_param");
}
cond.andPrepareVars("OFFER.STATUS", "$param.OfferStatus_param")
cond.andIfSet("OFFER.STATUS", "$param.OfferStatus_param")
//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
result.string(cond.translate("1 = 1"));
\ No newline at end of file
//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
result.string(cond.toString());
\ No newline at end of file
......@@ -2,4 +2,5 @@ import("Sql_lib");
import("system.vars");
import("system.db");
db.deleteData("OFFERITEM", SqlCondition.equals("OFFERITEM.OFFER_ID", vars.getString("$field.OFFERID"), "1=2"));
\ No newline at end of file
newWhere("OFFERITEM.OFFER_ID", "$field.OFFERID")
.deleteData(true, "OFFERITEM");
\ No newline at end of file
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