diff --git a/aliasDefinition/Data_alias/Data_alias.aod b/aliasDefinition/Data_alias/Data_alias.aod index c6a34fb55d8c01181ef7853da03ebf1897d0768d..33b32e1133b981bfb92d44fa8854a5686ae12b67 100644 --- a/aliasDefinition/Data_alias/Data_alias.aod +++ b/aliasDefinition/Data_alias/Data_alias.aod @@ -3443,20 +3443,6 @@ <title></title> <description></description> </entityFieldDb> - <entityFieldDb> - <name>ORGNAME</name> - <dbName></dbName> - <primaryKey v="false" /> - <columnType v="12" /> - <size v="50" /> - <scale v="0" /> - <notNull v="false" /> - <isUnique v="false" /> - <index v="false" /> - <documentation></documentation> - <title></title> - <description></description> - </entityFieldDb> <entityFieldDb> <name>DATE_NEW</name> <dbName></dbName> @@ -3569,6 +3555,20 @@ <title></title> <description></description> </entityFieldDb> + <entityFieldDb> + <name>RELATION_ID</name> + <dbName></dbName> + <primaryKey v="false" /> + <columnType v="1" /> + <size v="36" /> + <scale v="0" /> + <notNull v="true" /> + <isUnique v="false" /> + <index v="false" /> + <documentation></documentation> + <title></title> + <description></description> + </entityFieldDb> </entityFields> </entityDb> <entityDb> diff --git a/entity/SalesprojectCompetition_entity/SalesprojectCompetition_entity.aod b/entity/SalesprojectCompetition_entity/SalesprojectCompetition_entity.aod index 0de0f5401f69dfe8848a4cfb57b8ebdb73bfabd3..45202a13b647c27e2726f3d7098ffdf9e6435e06 100644 --- a/entity/SalesprojectCompetition_entity/SalesprojectCompetition_entity.aod +++ b/entity/SalesprojectCompetition_entity/SalesprojectCompetition_entity.aod @@ -5,7 +5,28 @@ <majorModelMode>DISTRIBUTED</majorModelMode> <recordContainerType>DB</recordContainerType> <alias>Data_alias</alias> + <fromClauseProcess>%aditoprj%/entity/SalesprojectCompetition_entity/fromClauseProcess.js</fromClauseProcess> <conditionProcess>%aditoprj%/entity/SalesprojectCompetition_entity/conditionProcess.js</conditionProcess> + <linkInformation> + <linkInformation> + <name>20f54241-6118-4887-b558-471d4657816c</name> + <tableName>SALESPROJECT_COMPETITION</tableName> + <primaryKey>SALESPROJECT_COMPETITIONID</primaryKey> + <isUIDTable v="true" /> + </linkInformation> + <linkInformation> + <name>32d1fb91-f382-4416-84d5-934676b495d8</name> + <tableName>ORG</tableName> + <primaryKey>ORGID</primaryKey> + <readonly v="true" /> + </linkInformation> + <linkInformation> + <name>02ac74a0-e9a1-44e8-9bc2-358b11b4cb54</name> + <tableName>RELATION</tableName> + <primaryKey>RELATIONID</primaryKey> + <readonly v="true" /> + </linkInformation> + </linkInformation> <entityFields> <entityIncomingField> <name>#INCOMING</name> @@ -36,13 +57,6 @@ <tableName>SALESPROJECT_COMPETITION</tableName> <columnName>INFO</columnName> </entityField> - <entityField> - <name>ORGNAME</name> - <title>Competitor</title> - <tableName>SALESPROJECT_COMPETITION</tableName> - <columnName>ORGNAME</columnName> - <mandatory v="true" /> - </entityField> <entityField> <name>REASON</name> <title>Reason</title> @@ -103,13 +117,21 @@ </entityDependency> </dependencies> </entityIncomingField> - </entityFields> - <linkInformation> - <linkInformation> - <name>474ddf87-d52d-4e4c-b5e3-30499a96d34c</name> + <entityField> + <name>RELATION_ID</name> + <title>Organisation</title> <tableName>SALESPROJECT_COMPETITION</tableName> - <primaryKey>SALESPROJECT_COMPETITIONID</primaryKey> - <isUIDTable v="true" /> - </linkInformation> - </linkInformation> + <columnName>RELATION_ID</columnName> + </entityField> + <entityField> + <name>ORG_NAME</name> + <tableName>ORG</tableName> + <columnName>NAME</columnName> + </entityField> + <entityField> + <name>ORG_ORGID</name> + <tableName>ORG</tableName> + <columnName>ORGID</columnName> + </entityField> + </entityFields> </entity> diff --git a/entity/SalesprojectCompetition_entity/fromClauseProcess.js b/entity/SalesprojectCompetition_entity/fromClauseProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..07f8a92fe2b62b8689d2aa03f069e783ea00c858 --- /dev/null +++ b/entity/SalesprojectCompetition_entity/fromClauseProcess.js @@ -0,0 +1,4 @@ +import("system.result"); + +result.string("SALESPROJECT_COMPETITION left join RELATION on (RELATION.RELATIONID = SALESPROJECT_COMPETITION.RELATION_ID) " + + "left join ORG on (ORG.ORGID = RELATION.ORG_ID)"); \ No newline at end of file diff --git a/entity/SalesprojectCycle_entity/SalesprojectCycle_entity.aod b/entity/SalesprojectCycle_entity/SalesprojectCycle_entity.aod index d1d4e7cb60c638b38f5f5f6f2c5de8fb0a3b90ae..54f0a57a75684f4dd25c5c25d7d8407af7a520b7 100644 --- a/entity/SalesprojectCycle_entity/SalesprojectCycle_entity.aod +++ b/entity/SalesprojectCycle_entity/SalesprojectCycle_entity.aod @@ -6,6 +6,7 @@ <recordContainerType>DB</recordContainerType> <alias>Data_alias</alias> <conditionProcess>%aditoprj%/entity/SalesprojectCycle_entity/conditionProcess.js</conditionProcess> + <onDBUpdate>%aditoprj%/entity/SalesprojectCycle_entity/onDBUpdate.js</onDBUpdate> <linkInformation> <linkInformation> <name>479f5969-fe03-4b36-8437-d2efc967e7b9</name> diff --git a/entity/SalesprojectCycle_entity/onDBUpdate.js b/entity/SalesprojectCycle_entity/onDBUpdate.js new file mode 100644 index 0000000000000000000000000000000000000000..10a9f323e81df96851efce750776cdc263439180 --- /dev/null +++ b/entity/SalesprojectCycle_entity/onDBUpdate.js @@ -0,0 +1 @@ +notifyToUpdateForecast() \ No newline at end of file diff --git a/entity/Salesproject_entity/onDBInsert.js b/entity/Salesproject_entity/onDBInsert.js index 24f917cdcd8ce993c006fb9db673be7d7216283b..46e16c3d687c541b66574fd13cfaa2c00fff2b87 100644 --- a/entity/Salesproject_entity/onDBInsert.js +++ b/entity/Salesproject_entity/onDBInsert.js @@ -1,5 +1,5 @@ import("system.vars"); import("Salesproject_lib"); -Salesproject.insertMilestone(vars.getString("$field.SALESPROJECTID"), 1, vars.get("$field.PHASE")); -Salesproject.insertMilestone(vars.getString("$field.SALESPROJECTID"), 2, vars.get("$field.STATE")); \ No newline at end of file +Salesproject.insertMilestone(vars.getString("$field.SALESPROJECTID"), 1, vars.get("$field.PHASE"), false); +Salesproject.insertMilestone(vars.getString("$field.SALESPROJECTID"), 2, vars.get("$field.STATE"), true); \ No newline at end of file diff --git a/entity/Salesproject_entity/onDBUpdate.js b/entity/Salesproject_entity/onDBUpdate.js index aeffbb32c2e40dc8932b2cf12d7d9223ad5ccfd9..514b528e696d35c1b2116d3fa05826d6e030790e 100644 --- a/entity/Salesproject_entity/onDBUpdate.js +++ b/entity/Salesproject_entity/onDBUpdate.js @@ -17,7 +17,7 @@ vars.get("$local.changed").forEach(function(fieldName) { } if (typeValue) { - Salesproject.insertMilestone(vars.getString("$field.SALESPROJECTID"), typeValue, vars.getString(fieldVar)); + Salesproject.insertMilestone(vars.getString("$field.SALESPROJECTID"), typeValue, vars.getString(fieldVar), true); } }); diff --git a/neonView/SalesprojectCompetitionEdit_view/SalesprojectCompetitionEdit_view.aod b/neonView/SalesprojectCompetitionEdit_view/SalesprojectCompetitionEdit_view.aod index f5892c53809ab8367ddd8fbead8b236c051f9635..ef5cf22d299b0fe4f411a5e1fbf440de5faf1e9d 100644 --- a/neonView/SalesprojectCompetitionEdit_view/SalesprojectCompetitionEdit_view.aod +++ b/neonView/SalesprojectCompetitionEdit_view/SalesprojectCompetitionEdit_view.aod @@ -14,8 +14,8 @@ <entityField>#ENTITY</entityField> <fields> <entityFieldLink> - <name>f3cc24f9-5c2c-468d-a080-3c7af92e3a89</name> - <entityField>ORGNAME</entityField> + <name>8b4c3245-7b3a-4cd0-90f0-09631e2dbde8</name> + <entityField>RELATION_ID</entityField> </entityFieldLink> <entityFieldLink> <name>cdbba6a7-59d1-4831-b098-98a82ad46444</name> diff --git a/neonView/SalesprojectCompetitionFilter_view/SalesprojectCompetitionFilter_view.aod b/neonView/SalesprojectCompetitionFilter_view/SalesprojectCompetitionFilter_view.aod index 11ae73d3e11e261ac99ec903c590947e567e8e9b..46bb55a1b157c5de2786299d56b1d41e784c459b 100644 --- a/neonView/SalesprojectCompetitionFilter_view/SalesprojectCompetitionFilter_view.aod +++ b/neonView/SalesprojectCompetitionFilter_view/SalesprojectCompetitionFilter_view.aod @@ -16,7 +16,7 @@ <columns> <neonTableColumn> <name>511ea459-1b6f-41e8-b35a-0f67361c82eb</name> - <entityField>ORGNAME</entityField> + <entityField>RELATION_ID</entityField> </neonTableColumn> <neonTableColumn> <name>322f7067-83ac-486e-9540-16d693775bdb</name> diff --git a/neonView/SalesprojectCompetitionPreview_view/SalesprojectCompetitionPreview_view.aod b/neonView/SalesprojectCompetitionPreview_view/SalesprojectCompetitionPreview_view.aod index ac49613c7c4440231b667717f01d111225618f09..110db8a6a7f6abd9a38e4021daea4b93c142a1d0 100644 --- a/neonView/SalesprojectCompetitionPreview_view/SalesprojectCompetitionPreview_view.aod +++ b/neonView/SalesprojectCompetitionPreview_view/SalesprojectCompetitionPreview_view.aod @@ -10,7 +10,7 @@ <children> <cardViewTemplate> <name>SalesprojectCompetitionHeader_template</name> - <titleField>ORGNAME</titleField> + <titleField>RELATION_ID</titleField> <descriptionField>INFO</descriptionField> <entityField>#ENTITY</entityField> </cardViewTemplate> diff --git a/others/db_changes/data/example_salesproject/SALESPROJECT_gfk.xml b/others/db_changes/data/example_salesproject/SALESPROJECT_gfk.xml index 49d73913e795ae76b5921dc0bb4c9e18dafe740b..a6aca25bd2d0e285cf9a5f0cda984d27d3f729ee 100644 --- a/others/db_changes/data/example_salesproject/SALESPROJECT_gfk.xml +++ b/others/db_changes/data/example_salesproject/SALESPROJECT_gfk.xml @@ -61,10 +61,9 @@ <column name="USER_NEW" value="admin"/> <column name="DATE_NEW" valueDate="2018-06-13T09:03:43"/> <column name="SALESPROJECT_ID" value="0833465c-8851-4fbb-b7e3-8c1d73c903da"/> - <column name="DATE_CANCELLED" valueDate="2018-06-13T09:03:43"/> <column name="INFO" value="starkes Prozess Know-How, wird gefährlich für uns. Dazu private Verbindungen"/> - <column name="ORGNAME" value="Lieferdienst GmbH und Co.KG"/> + <column name="RELATION_ID" value="e5a0bbdb-6cc4-4889-97ab-dc5143fbeac2"/> <column name="STATUS" valueNumeric="1"/> </insert> diff --git a/others/db_changes/struct/create_salesproject_competition.xml b/others/db_changes/struct/create_salesproject_competition.xml index 9619363054f355624192fcc6bd488d8f961d384c..84c4f33f4e672e9c37f5463fbf5ba1a5a3b7e59f 100644 --- a/others/db_changes/struct/create_salesproject_competition.xml +++ b/others/db_changes/struct/create_salesproject_competition.xml @@ -8,10 +8,11 @@ <column name="SALESPROJECT_ID" type="CHAR(36)"> <constraints nullable="false"/> </column> - + <column name="RELATION_ID" type="CHAR(36)"> + <constraints nullable="false"/> + </column> <column name="DATE_CANCELLED" type="TIMESTAMP"/> <column name="INFO" type="NCLOB"/> - <column name="ORGNAME" type="VARCHAR(50)"/> <column name="REASON" type="INTEGER"/> <column name="STATUS" type="INTEGER"/> diff --git a/others/guide/how to write JDito code.adoc b/others/guide/how to write JDito code.adoc index 5f7169bc0970fbf14f3d728365af380bbbed33f0..cd9eef7065612bb2ca1fe443508189287ac2e686 100644 --- a/others/guide/how to write JDito code.adoc +++ b/others/guide/how to write JDito code.adoc @@ -6,7 +6,7 @@ How to write JDito code == basics == * Keep everything english. Every title, caption, messages, comments, etc. should be english. Add german translation to the languages if necessary. * in JavaScript-Strings use `"` instead of `'` - even if its only 1 character. `'` is for SQL (within JS-Strings) - +* Parameters should not start with p because they are usable like normal variables. There is no real benefit from naming them p****. == code structure == === vars and others (var, let) === @@ -147,7 +147,23 @@ So just start your functions / methods name with a _ if you need private methods == JS-Doc == <1> JS-Doc comment: http://usejsdoc.org/ -<2> use the correct form for optional/required parameters: http://usejsdoc.org/tags-param.html +<2> use the correct form for optional/required parameters: http://usejsdoc.org/tags-param.html +Optional parameter: [alias=the current alias] +Required parameter: alias +[source,javascript] +---- +/** + * Description... + * ... + * + * @param {String} [alias=the current alias] the database alias where the condition shall be executed later (important for column types of preparedStatements) + * @example Here is an example + * @class + */ +function SqlCondition(alias) { +... +} +---- <3> examples are useful on more complex functions <4> constructor function; init properties (do not set functions ("methods") here!) <5> add functions ("methods") to the prototype, they are available through the prototype chain diff --git a/others/guide/instanceableLibExample.adoc b/others/guide/instanceableLibExample.adoc new file mode 100644 index 0000000000000000000000000000000000000000..bbc7a88b00183d68c8d46aaff442c2b356a136ac --- /dev/null +++ b/others/guide/instanceableLibExample.adoc @@ -0,0 +1,55 @@ += Example for a instanceable Lib = + +Remember to always change the comments to fit your class! + +Use speaking names for ALL variables, classes and functions! + +[source,javascript] +---- +import("..."); + +/** + * instanceable example Utility class; + * + * @param {String} param1 is for ... + * + * @example var myUtil = new UtilClass("-"); + * @class + */ +function UtilClass(param1) { + // here is the constructor. + // create class variables like this: + this.myVariable = param1; +} + +/** + * a public function + * + * @param {String} param1 is for ... + * @param {String} param2 is for ... + * + * @example var myResult = myUtil.myFunction("p1", "p2"); + * + * @return {String} a result + */ +UtilClass.prototype.myFunction = function(param1, param2) { + return this._privateStaticFunction1(param1, param2, this.myVariable); +} + +/** + * a private function + * + * @param {String} param1 is for ... + * @param {String} param2 is for ... + * @param {String} param3 is for ... + * + * @return {String} a result + */ +UtilClass.prototype._myPrivateFunction = function(param1, param2, param3) { + if(param1 && param2 && param3) { + ... + return param1 + param3 + param2; + } + + return ""; +} +---- \ No newline at end of file diff --git a/others/guide/staticLibExample.adoc b/others/guide/staticLibExample.adoc new file mode 100644 index 0000000000000000000000000000000000000000..e98a7822630c4a32567a6fd3d5613c8290df3e77 --- /dev/null +++ b/others/guide/staticLibExample.adoc @@ -0,0 +1,51 @@ += Example for a static Lib = + +Remember to always change the comments to fit your class! + +Use speaking names for ALL variables, classes and functions! + +[source,javascript] +---- +import("..."); + +/** + * a static Example Utility class + * + * Do not create an instance of this! + * @class + */ +function ExampleUtils() {} // leave this function empty! A constructor is not needed for static functions. + +/** + * a public static function + * + * @param {String} param1 is for ... + * @param {String} param2 is for ... + * + * @example var myResult = ExampleUtils.staticFunction1("p1", "p2"); + * + * @return {String} a result + */ +ExampleUtils.staticFunction1 = function(param1, param2) { + return this._privateStaticFunction1(param1, param2, "-") +} + +/** + * a private static function + * + * Do not use outside of ExampleUtils! + * + * @param {String} param1 is for ... + * @param {String} param2 is for ... + * @param {String} param3 is for ... + * + * @return {String} a result + */ +ExampleUtils._privateStaticFunction1 = function(param1, param2, param3) { + if(param1 && param2) { + ... + return param1 + param3 + param2; + } + + return ""; +} +---- \ No newline at end of file diff --git a/process/Salesproject_lib/process.js b/process/Salesproject_lib/process.js index 4d5599f65bde186da02439ee7a7d1d3cbeb3cca7..ff3579d430cf3959cc1f1ccbb37ff87c0d4db740 100644 --- a/process/Salesproject_lib/process.js +++ b/process/Salesproject_lib/process.js @@ -1,6 +1,8 @@ import("system.translate"); import("system.db"); import("system.eMath"); +import("system.question"); +import("system.logging"); import("Util_lib"); import("Keyword_lib"); @@ -27,7 +29,7 @@ Salesproject.getNextProjectNumber = function() { * * @param {String} projectNumber project number to check * - * @result {boolean} passed number is valid + * @result {Boolean} passed number is valid */ Salesproject.validateProjectNumber = function(projectNumber) { var JdUtils = new JDitoUtils(); @@ -40,19 +42,30 @@ Salesproject.validateProjectNumber = function(projectNumber) { * @param {String} salesprojectId of the salesproject * @param {Integer} type can be any value of the keyword SALESPROJECT.CYCLE.TYPE * @param {Integer} value value of the phase or state + * @param {Boolean} notifyForecast if true, notify user to update the forecast * - * @result {boolean} true if inserted, else false + * @result {Boolean} true if inserted, else false */ -Salesproject.insertMilestone = function(salesprojectId, type, value) { +Salesproject.insertMilestone = function(salesprojectId, type, value, notifyForecast) { if (KeywordUtils.createKeyword("SALESPROJECT.CYCLE.TYPE").exists(type)) { db.insertData( "SALESPROJECT_CYCLE", ["SALESPROJECT_CYCLEID", "SALESPROJECT_ID", "TYPE", "VALUE", "DATE_START", "USER_NEW", "DATE_NEW"], null, [util.getNewUUID(), salesprojectId, type, value, vars.get("$sys.date"), vars.get("$sys.user"), vars.get("$sys.date")]); - + if (notifyForecast) { + this.notifyToUpdateForecast() + } return true; } return false; } + +/** + * Notify the user to update the forecast + */ +Salesproject.notifyToUpdateForecast = function() { + // Todo logging.show durch sinnvolle Meldung ersetzen oder ähnlich... + logging.show(translate.text("Please update the forecast.")) +} \ No newline at end of file diff --git a/process/Sql_lib/process.js b/process/Sql_lib/process.js index 9cc2ce5f5d3555fff673de9dac091c58854e1588..74159ccb78b58abf12f57cd7ad8578fa5852b923 100644 --- a/process/Sql_lib/process.js +++ b/process/Sql_lib/process.js @@ -770,130 +770,124 @@ SqlUtils.getSingleColumnType = function(fieldOrTableName, columnName, alias) { return db.getColumnTypes(tableName, [columnName], alias)[0]; }; -//scope for internal functions; -//it's extremly important that the semicolon of the function expression above is correctly set because otherwise the function is called immediately -(function(){ - /** - * calls a given function for N blocks of sql-data as long as records are available or the paging-process is manually canceled - * - * @param {Object|String} sqlStatement the sql statement that shall be executed - * String: SQL-query in a simple text form - * Object: prepared-sql-query: [sqlStr, [[value1, type1], [valueN, typeN]]] - * @param {Number} blockSize Amount of records that shall be read per block. (you need to specify an ORDER BY in your SQL-query) - * "0" <=> all records - * @param {Object (function)} callbackFn a callback-function that is called for every block and has the following params: - * myCallback(myDataBlockAs2Darray, myLoopCountThatStartsWith1) - * If "false" is returned sqlPageData will abort the paging process and return false - * @param {String} [dbAlias=the current alias] Database-Aliasname, where the SQL-Statement shall be executed; default is the current dbalias - * @param {Number} [timeout=configured dbTimeout in Preferences] Timeout in milliseconds; When it's reached the SQL-Statement will abort; default is in PREFERENCES configured - * @param {Number} [startOffset=0] Position where to begin with the data-reading-process; default is 0 - * - * - * @return {bool} returns whether the function read all available data or not: - * false if the callback-function returned false, otherwise true - * - * @example - * var varValues = [];//you've got access to variables declared with 'var' - * let letValues = [];//you've got access to variables declared with 'let' - * var count = 0;//you cannot overwrite a variable of 'sqlPageData' by accident - * - * var sql = "select ORGNAME from ORG"; - * var blockSize = 5 * 1000; - * - * var allRows = +db.cell("select count(*) from ORG"); - * - * sqlPageData(sql, blockSize, function (pData, pRunNo){ - * var j = pData.length;//pData is the current block with data - * logging.log(pRunNo.toString() + "#" + j);//pRunNo is the amount how often the func. has been already called - * //you can calculate the progress easily by: progress = (blockSize* (pRunNo-1) + pData.length) / (allRows - startOffset) - * //example in per cent: - * var startOffset = 0;//we did not pass any startOffset to sqlPageData - this is equivalent to zero - * var progress = (blockSize* (pRunNo-1) + pData.length) / (allRows - startOffset); - * logging.log("progess: " + eMath.roundDec(progress * 100, 2, eMath.ROUND_CEILING) + "%"); - * - * for (var i = 0; i < j; i++) - * { - * varValues.push(pData[i][0]); - * letValues.push(pData[i][0]); - * } - * - * count += pRunNo * 100; - * logging.log("count:" + count);//you cannot overwrite a variable of 'sqlPageData' by accident - * }); - * - * logging.show(letValues);//contains orgnames - * logging.show(varValues);//contains orgnames - */ - SqlUtils.pageTableData = function(sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset) { - return _pageData(null, sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset); - }; - - /** - * calls a given function for N blocks of sql-data as long as records are available or the paging-process is manually canceled - * - * @param {Object|String} sqlStatement the sql statement that shall be executed - * String: SQL-query in a simple text form - * Object: prepared-sql-query: [sqlStr, [[value1, type1], [valueN, typeN]]] - * @param {Number} blockSize Amount of records that shall be read per block. (you need to specify an ORDER BY in your SQL-query) - * "0" <=> all records - * @param {Object (function)} callbackFn a callback-function that is called for every block and has the following params: - * myCallback(myColumnDataBlockAsArray, myLoopCountThatStartsWith1) - * If "false" is returned sqlPageData will abort the paging process and return false - * @param {String} [dbAlias=the current alias] Database-Aliasname, where the SQL-Statement shall be executed; default is the current dbalias - * @param {Number} [timeout=configured dbTimeout in Preferences] Timeout in milliseconds; When it's reached the SQL-Statement will abort; default is in PREFERENCES configured - * @param {Number} [startOffset=0] Position where to begin with the data-reading-process; default is 0 - * - * - * @return {bool} returns whether the function read all available data or not: - * false if the callback-function returned false, otherwise true - * - * @example - * similar to sqlTablePageData -> take a look at the example there - */ - SqlUtils.pageColumnData = function(sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset) { - return _pageData(db.COLUMN, sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset); - }; - - //internal function for paging through data; for description take a look at sqlArrayPageData - function _pageData(sqlType ,sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset){ - if (dbAlias == undefined) - dbAlias = db.getCurrentAlias(); - if (startOffset == undefined) - startOffset = 0; - - var count = 0; - while (startOffset > -1) { - var data; - if (sqlType == null) { - if (timeout == undefined) - data = db.tablePage(sqlStatement, dbAlias, startOffset, blockSize); - else - data = db.tablePage(sqlStatement, dbAlias, startOffset, blockSize, timeout); - } - else { - if (timeout == undefined) - data = db.arrayPage(sqlType, sqlStatement, dbAlias, startOffset, blockSize); - else - data = db.arrayPage(sqlType, sqlStatement, dbAlias, startOffset, blockSize, timeout); - } - - startOffset += blockSize; +/** +* calls a given function for N blocks of sql-data as long as records are available or the paging-process is manually canceled +* +* @param {Object|String} sqlStatement the sql statement that shall be executed +* String: SQL-query in a simple text form +* Object: prepared-sql-query: [sqlStr, [[value1, type1], [valueN, typeN]]] +* @param {Number} blockSize Amount of records that shall be read per block. (you need to specify an ORDER BY in your SQL-query) +* "0" <=> all records +* @param {Object (function)} callbackFn a callback-function that is called for every block and has the following params: +* myCallback(myDataBlockAs2Darray, myLoopCountThatStartsWith1) +* If "false" is returned sqlPageData will abort the paging process and return false +* @param {String} [dbAlias=the current alias] Database-Aliasname, where the SQL-Statement shall be executed; default is the current dbalias +* @param {Number} [timeout=configured dbTimeout in Preferences] Timeout in milliseconds; When it's reached the SQL-Statement will abort; default is in PREFERENCES configured +* @param {Number} [startOffset=0] Position where to begin with the data-reading-process; default is 0 +* +* +* @return {bool} returns whether the function read all available data or not: +* false if the callback-function returned false, otherwise true +* +* @example +* var varValues = [];//you've got access to variables declared with 'var' +* let letValues = [];//you've got access to variables declared with 'let' +* var count = 0;//you cannot overwrite a variable of 'sqlPageData' by accident +* +* var sql = "select ORGNAME from ORG"; +* var blockSize = 5 * 1000; +* +* var allRows = +db.cell("select count(*) from ORG"); +* +* sqlPageData(sql, blockSize, function (pData, pRunNo){ +* var j = pData.length;//pData is the current block with data +* logging.log(pRunNo.toString() + "#" + j);//pRunNo is the amount how often the func. has been already called +* //you can calculate the progress easily by: progress = (blockSize* (pRunNo-1) + pData.length) / (allRows - startOffset) +* //example in per cent: +* var startOffset = 0;//we did not pass any startOffset to sqlPageData - this is equivalent to zero +* var progress = (blockSize* (pRunNo-1) + pData.length) / (allRows - startOffset); +* logging.log("progess: " + eMath.roundDec(progress * 100, 2, eMath.ROUND_CEILING) + "%"); +* +* for (var i = 0; i < j; i++) +* { +* varValues.push(pData[i][0]); +* letValues.push(pData[i][0]); +* } +* +* count += pRunNo * 100; +* logging.log("count:" + count);//you cannot overwrite a variable of 'sqlPageData' by accident +* }); +* +* logging.show(letValues);//contains orgnames +* logging.show(varValues);//contains orgnames +*/ +SqlUtils.pageTableData = function(sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset) { + return SqlUtils._pageData(null, sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset); +}; - //this happens when all-records % blockSize == 0 - //we do not want to call the callback-fn - if (data.length == 0) - return true; - else if (data.length < blockSize || blockSize == 0)//blocksize 0 is everything - startOffset = -1;//call callback the last time +/** +* calls a given function for N blocks of sql-data as long as records are available or the paging-process is manually canceled +* +* @param {Object|String} sqlStatement the sql statement that shall be executed +* String: SQL-query in a simple text form +* Object: prepared-sql-query: [sqlStr, [[value1, type1], [valueN, typeN]]] +* @param {Number} blockSize Amount of records that shall be read per block. (you need to specify an ORDER BY in your SQL-query) +* "0" <=> all records +* @param {Object (function)} callbackFn a callback-function that is called for every block and has the following params: +* myCallback(myColumnDataBlockAsArray, myLoopCountThatStartsWith1) +* If "false" is returned sqlPageData will abort the paging process and return false +* @param {String} [dbAlias=the current alias] Database-Aliasname, where the SQL-Statement shall be executed; default is the current dbalias +* @param {Number} [timeout=configured dbTimeout in Preferences] Timeout in milliseconds; When it's reached the SQL-Statement will abort; default is in PREFERENCES configured +* @param {Number} [startOffset=0] Position where to begin with the data-reading-process; default is 0 +* +* +* @return {bool} returns whether the function read all available data or not: +* false if the callback-function returned false, otherwise true +* +* @example +* similar to sqlTablePageData -> take a look at the example there +*/ +SqlUtils.pageColumnData = function(sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset) { + return SqlUtils._pageData(db.COLUMN, sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset); +}; - if (callbackFn.call(this, data, ++count) === false) - return false;//callback can return false to manually stop the paging-process +//internal function for paging through data; for description take a look at sqlArrayPageData +SqlUtils._pageData = function(sqlType ,sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset) { + if (dbAlias == undefined) + dbAlias = db.getCurrentAlias(); + if (startOffset == undefined) + startOffset = 0; + + var count = 0; + while (startOffset > -1) { + var data; + if (sqlType == null) { + if (timeout == undefined) + data = db.tablePage(sqlStatement, dbAlias, startOffset, blockSize); + else + data = db.tablePage(sqlStatement, dbAlias, startOffset, blockSize, timeout); + } + else { + if (timeout == undefined) + data = db.arrayPage(sqlType, sqlStatement, dbAlias, startOffset, blockSize); + else + data = db.arrayPage(sqlType, sqlStatement, dbAlias, startOffset, blockSize, timeout); } - return true; - } -})(); + startOffset += blockSize; + //this happens when all-records % blockSize == 0 + //we do not want to call the callback-fn + if (data.length == 0) + return true; + else if (data.length < blockSize || blockSize == 0)//blocksize 0 is everything + startOffset = -1;//call callback the last time + + if (callbackFn.call(this, data, ++count) === false) + return false;//callback can return false to manually stop the paging-process + } + return true; +} /** * Builds a SQL IN condition, while accounting for the 1000 elements maximum