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

Fixes, TODOs, refactorings

parent 27a84dfa
No related branches found
No related tags found
No related merge requests found
......@@ -35,7 +35,7 @@ ProductUtils.getCurrentProductPrice = function(pid, buySell) {
var actualPriceCondition = SqlCondition.begin()
.andPrepare("PRODUCTPRICE.BUYSELL", buySell)
.andPrepare("PRODUCTPRICE.PRODUCT_ID", pid)
.andPrepare("PRODUCTPRICE.CURRENCY", 1) // TODO: warum ist Currency hardgecoded auf 1??
.andPrepare("PRODUCTPRICE.CURRENCY", 1) // TODO: warum ist Currency hardgecoded auf 1?? --> Einheitliche Währungen einbauen (auch zeichen vor oder nach der zahel, etc.)
.andPrepare("PRODUCTPRICE.VALID_FROM", today, "# <= ?")
.andSqlCondition(SqlCondition.begin()
.orPrepare("PRODUCTPRICE.VALID_TO", today, "# >= ?")
......@@ -76,7 +76,7 @@ ProductUtils.getStockCount = function(pid) {
}
else
{
throw new Error();//TODO: add message
throw new Error(translate.withArguments("${PRODUCT_LIB_NO_PRODUCT_ID} function: %0", ["ProductUtils.getStockCount"]));
}
}
......
......@@ -17,14 +17,16 @@ import("Util_lib");
*
* @class
* @param {String} [alias=the current alias] the database alias where the condition shall be executed later (important for column types of preparedStatements)
* @example //TODO: add missing example
* @example
* see others/guide/HowToSqlConditionLib.adoc
*/
function SqlCondition(alias) {
//setting null is only needed to provide autocomplete for the ADITO-designer
// setting null is only needed to provide autocomplete for the ADITO-designer
this.preparedValues = null;
this._init();//the properties are initalized in an extra function because init is nearly the same as resetting (clearing) the SqlConditions
this._init(); // the properties are initalized in an extra function because init is nearly the same as resetting (clearing) the SqlConditions
this.alias = alias;
this._cachedTypes = {};
// save, if the last condition was an OR. For better bracket-placement
this._lastWasOr = false;
}
......@@ -535,8 +537,8 @@ SqlMaskingUtils.prototype.max = function(field)
}
/**
* returns the min-value sql expressions depending on the database behind the given alias
* note that this function does not verifiy if the field (and type) usage is valid at all
* returns the min-value sql expressions depending on the database behind the given alias
* note that this function does not verifiy if the field (and type) usage is valid at all
*
* @param {String} field expression
*
......@@ -548,36 +550,38 @@ SqlMaskingUtils.prototype.min = function(field)
}
/**
* masks the function cast of standard sql
* please note that this function does not do any validation if it's possible to cast the expression's datatype you pass to the function in every supported DBMS
*
* @param {String} field name of the database field that shall be castet
* @param {String} [targetDatatype] a SQLTYPES-value of the following: SQLTYPES.CHAR, SQLTYPES.VARCHAR, SQLTYPES.INTEGER,
* SQLTYPES.DECIMAL, SQLTYPES.DATE
* @param {int|int[]} targetLength specifies the length of the target data type;
* <br/>- char/varchar: length
* <br/>- decimal: [length, decimals]
*
* @return {String} sql part to be included in sql-statements
*/
* masks the function cast of standard sql
* please note that this function does not do any validation if it's possible to cast the expression's datatype you pass to the function in every supported DBMS
*
* Problems:
* Derby has problems with casting to CHAR({> 254}) https://db.apache.org/derby/docs/10.14/ref/rrefsqlj13733.html
*
* @param {String} field name of the database field that shall be castet
* @param {String} [targetDatatype] a SQLTYPES-value of the following: SQLTYPES.CHAR, SQLTYPES.VARCHAR, SQLTYPES.INTEGER,
* SQLTYPES.DECIMAL, SQLTYPES.DATE
* @param {int|int[]} targetLength specifies the length of the target data type;
* <br/>- char/varchar: length
* <br/>- decimal: [length, decimals]
*
* @return {String} sql part to be included in sql-statements
*/
SqlMaskingUtils.prototype.cast = function (field, targetDatatype, targetLength) {
//TODO: use callbacks for different handling?
/* Some informations if you want to add supported databaseTypes or dataTypes:
* You should consider using the _mapDefaults function-expression (details in the functions doc)
* However you shouldn't use the function in a "default"-Block of a switch-case because of the following behaviour:
* If a datatype is not supported you just have to NOT specify "sqlDataType" (leave it "undefined") -> an error is then raised
* Therefore you should explicitly define which Data-type is supported and which is not
*/
* You should consider using the _mapDefaults function-expression (details in the functions doc)
* However you shouldn't use the function in a "default"-Block of a switch-case because of the following behaviour:
* If a datatype is not supported you just have to NOT specify "sqlDataType" (leave it "undefined") -> an error is then raised
* Therefore you should explicitly define which Data-type is supported and which is not
*/
var dbType, functionName, sqlPart, sqlDataType, _mapDefaults;
dbType = this.dbType;
functionName = "cast";//overwrite this in the "switch (dbType)" if needed with your DBMS
/**
* handles default-scenarios for mapping input-targetDatatype to a string for a sql-statement
* e.g. SQLTYPES.INTEGER --> int
* @param {Number} dataType input as a value of "SQLTYPES." that will be mapped to a string
* @return {String} the mapped dataType for using in a sql-statement
*/
* handles default-scenarios for mapping input-targetDatatype to a string for a sql-statement
* e.g. SQLTYPES.INTEGER --> int
* @param {Number} dataType input as a value of "SQLTYPES." that will be mapped to a string
* @return {String} the mapped dataType for using in a sql-statement
*/
_mapDefaults = function (dataType) {
var res;
switch(dataType) {
......@@ -611,7 +615,6 @@ SqlMaskingUtils.prototype.cast = function (field, targetDatatype, targetLength)
sqlDataType = "varchar";
break;
case SQLTYPES.CHAR:
//TODO: throw error if(targetLength > 254)? https://db.apache.org/derby/docs/10.14/ref/rrefsqlj13733.html
sqlDataType = "char";
break;
case SQLTYPES.DECIMAL:
......@@ -678,7 +681,7 @@ SqlMaskingUtils.prototype.cast = function (field, targetDatatype, targetLength)
}
if (sqlDataType == undefined) {
throw new Error("sqlDataType is undefined");//TODO: add usefull message
throw new Error(translate.withArguments("${SQL_LIB_UNSUPPORTED_DBTYPE} function: %0", ["SqlMaskingUtils.prototype.cast._mapDefaults"]));
}
if(targetLength == undefined)
......@@ -779,7 +782,7 @@ SqlMaskingUtils.prototype.substring = function(field, start, length) {
sqlFnName = "substring";
break;
default:
throw new Error();//ToDo: add message
throw new Error(translate.withArguments("${SQL_LIB_UNSUPPORTED_DBTYPE} function: %0", ["SqlMaskingUtils.prototype.substring"]));
}
return sqlFnName + "(" + field + ", " + start + ", " + length + ")";
......@@ -833,7 +836,7 @@ SqlMaskingUtils.prototype.concat = function(fields, separatorCharacter, autoTrim
case db.DBTYPE_DERBY10:
break;
default:
throw new Error();//TODO: add Message
throw new Error(translate.withArguments("${SQL_LIB_UNSUPPORTED_DBTYPE} function: %0", ["SqlMaskingUtils.prototype.concat"]));
}
separatorSql = concatSql + "'" + separatorSql + "'";
_trimIfAutoTrimEnabled = function(f){
......
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