jsharmony 1.27.2 → 1.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AppSrv.File.js CHANGED
@@ -183,6 +183,7 @@ exports.Download = function (req, res, fullmodelid, keyid, fieldid, options) {
183
183
  if (!this.jsh.hasModel(req, fullmodelid)) throw new Error('Error: Model ' + fullmodelid + ' not found in collection.');
184
184
  var model = this.jsh.getModel(req, fullmodelid);
185
185
  var db = this.jsh.getModelDB(req, fullmodelid);
186
+ var dbcontext = this.jsh.getDBContext(req, model, db);
186
187
  //Verify model access
187
188
  if (!Helper.hasModelAction(req, model, 'B')) { Helper.GenError(req, res, -11, _this._tP('Invalid Model Access for @fullmodelid', { fullmodelid })); return; }
188
189
  if (model.unbound) { Helper.GenError(req, res, -11, 'Cannot run database queries on unbound models'); return; }
@@ -220,7 +221,7 @@ exports.Download = function (req, res, fullmodelid, keyid, fieldid, options) {
220
221
 
221
222
  var sql = db.sql.Download(_this.jsh, model, fields, keys, datalockqueries);
222
223
 
223
- this.ExecRow(req._DBContext, sql, sql_ptypes, sql_params, function (err, rslt) {
224
+ this.ExecRow(dbcontext, sql, sql_ptypes, sql_params, function (err, rslt) {
224
225
  //Get extension, filename
225
226
  if(err) jsh.Log.error(err);
226
227
  if ((rslt == null) || (rslt.length != 1) || (rslt[0] == null)) { return Helper.GenError(req, res, -33, 'Download file not found.'); }
@@ -58,6 +58,7 @@ exports.postModelExec = function (req, res, fullmodelid, Q, P, onComplete) {
58
58
  var model = jsh.getModel(req, fullmodelid);
59
59
  if (!Helper.hasModelAction(req, model, 'U')) { Helper.GenError(req, res, -11, _this._tP('Invalid Model Access for @fullmodelid', { fullmodelid })); return; }
60
60
  var db = jsh.getModelDB(req, fullmodelid);
61
+ var dbcontext = jsh.getDBContext(req, model, db);
61
62
 
62
63
  var fieldlist = this.getFieldNames(req, model.fields, 'U');
63
64
 
@@ -106,7 +107,7 @@ exports.postModelExec = function (req, res, fullmodelid, Q, P, onComplete) {
106
107
  sql_params = _this.ApplyTransTblEscapedParameters(sql_params, transtbl);
107
108
  var dbfunc = db.Recordset;
108
109
  if (model.sqltype && (model.sqltype == 'multirecordset')) dbfunc = db.MultiRecordset;
109
- dbfunc.call(db, req._DBContext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
110
+ dbfunc.call(db, dbcontext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
110
111
  if (err != null) { err.model = model; err.sql = sql; }
111
112
  if (stats) stats.model = model;
112
113
  if(model.onsqlupdated) sql_rslt = rslt;
@@ -39,6 +39,7 @@ exports.getModelForm = function (req, res, fullmodelid, Q, P, form_m) {
39
39
  var encryptedfields = this.getEncryptedFields(req, model.fields, 'B');
40
40
  var lovkeylist = this.getFieldNamesWithProp(model.fields, 'lovkey');
41
41
  var db = _this.jsh.getModelDB(req, fullmodelid);
42
+ var dbcontext = _this.jsh.getDBContext(req, model, db);
42
43
  if ((encryptedfields.length > 0) && !(req.secure) && (!_this.jsh.Config.system_settings.allow_insecure_http_encryption)) { Helper.GenError(req, res, -51, 'Encrypted fields require HTTPS connection'); return; }
43
44
 
44
45
 
@@ -149,7 +150,7 @@ exports.getModelForm = function (req, res, fullmodelid, Q, P, form_m) {
149
150
  var sql = db.sql.getModelForm(_this.jsh, model, selecttype, allfields, sql_allkeyfields, datalockqueries, sortfields);
150
151
  var dbfunc = db.Row;
151
152
  if (selecttype == 'multiple') dbfunc = db.Recordset;
152
- dbfunc.call(db, req._DBContext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
153
+ dbfunc.call(db, dbcontext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
153
154
  if ((err == null) && (rslt == null)) err = Helper.NewError('Record not found', -1);
154
155
  if (err != null) { err.model = model; err.sql = sql; }
155
156
  else {
@@ -250,6 +251,7 @@ exports.putModelForm = function (req, res, fullmodelid, Q, P, onComplete) {
250
251
  var encryptedfields = this.getEncryptedFields(req, model.fields, 'I');
251
252
  if ((encryptedfields.length > 0) && !(req.secure) && (!_this.jsh.Config.system_settings.allow_insecure_http_encryption)) { Helper.GenError(req, res, -51, 'Encrypted fields require HTTPS connection'); return; }
252
253
  var db = _this.jsh.getModelDB(req, fullmodelid);
254
+ var dbcontext = _this.jsh.getDBContext(req, model, db);
253
255
 
254
256
  var Pcheck = _.map(fieldlist, function (field) { return '&' + field; });
255
257
  Pcheck = Pcheck.concat(_.map(filelist, function (file) { return '|' + file; }));
@@ -348,7 +350,7 @@ exports.putModelForm = function (req, res, fullmodelid, Q, P, onComplete) {
348
350
  var sql_rslt = null;
349
351
  dbtasks[fullmodelid] = function (dbtrans, callback, transtbl) {
350
352
  sql_params = _this.ApplyTransTblEscapedParameters(sql_params, transtbl);
351
- db.Row(req._DBContext, dbsql.sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
353
+ db.Row(dbcontext, dbsql.sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
352
354
  if (stats) stats.model = model;
353
355
  if ((err == null) && (rslt != null) && (_this.jsh.map.rowcount in rslt) && (rslt[_this.jsh.map.rowcount] == 0)) err = Helper.NewError('No records affected', -3, stats);
354
356
  if (err != null) { err.model = model; err.sql = dbsql.sql; }
@@ -392,7 +394,7 @@ exports.putModelForm = function (req, res, fullmodelid, Q, P, onComplete) {
392
394
  }
393
395
  }
394
396
  });
395
- db.Row(req._DBContext, dbsql.enc_sql, enc_sql_ptypes, enc_sql_params, dbtrans, function (err, rslt, stats) {
397
+ db.Row(dbcontext, dbsql.enc_sql, enc_sql_ptypes, enc_sql_params, dbtrans, function (err, rslt, stats) {
396
398
  if (stats) stats.model = model;
397
399
  if ((err == null) && (rslt != null) && (_this.jsh.map.rowcount in rslt) && (rslt[_this.jsh.map.rowcount] == 0)) err = Helper.NewError('No records affected', -3, stats);
398
400
  if (err != null) { err.model = model; err.sql = dbsql.enc_sql; }
@@ -422,6 +424,7 @@ exports.postModelForm = function (req, res, fullmodelid, Q, P, onComplete) {
422
424
  var encryptedfields = this.getEncryptedFields(req, model.fields, 'U');
423
425
  if ((encryptedfields.length > 0) && !(req.secure) && (!_this.jsh.Config.system_settings.allow_insecure_http_encryption)) { Helper.GenError(req, res, -51, 'Encrypted fields require HTTPS connection'); return; }
424
426
  var db = _this.jsh.getModelDB(req, fullmodelid);
427
+ var dbcontext = _this.jsh.getDBContext(req, model, db);
425
428
 
426
429
  var Pcheck = _.map(fieldlist, function (field) { return '&' + field; });
427
430
  Pcheck = Pcheck.concat(_.map(filelist, function (file) { return '|' + file; }));
@@ -540,7 +543,7 @@ exports.postModelForm = function (req, res, fullmodelid, Q, P, onComplete) {
540
543
 
541
544
  dbtasks[fullmodelid] = function (dbtrans, callback, transtbl) {
542
545
  sql_params = _this.ApplyTransTblEscapedParameters(sql_params, transtbl);
543
- db.Row(req._DBContext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
546
+ db.Row(dbcontext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
544
547
  if (stats) stats.model = model;
545
548
  if ((err == null) && (rslt != null) && (_this.jsh.map.rowcount in rslt) && (rslt[_this.jsh.map.rowcount] == 0)) err = Helper.NewError('No records affected', -3, stats);
546
549
 
@@ -592,6 +595,7 @@ exports.deleteModelForm = function (req, res, fullmodelid, Q, P, onComplete) {
592
595
  var fieldlist = this.getFieldNames(req, model.fields, 'D');
593
596
  var filelist = this.getFileFieldNames(req, model.fields, '*');
594
597
  var db = _this.jsh.getModelDB(req, fullmodelid);
598
+ var dbcontext = _this.jsh.getDBContext(req, model, db);
595
599
 
596
600
  var Qcheck = _.map(keylist, function (key) { return '&' + key; });
597
601
  Qcheck = Qcheck.concat(_.map(fieldlist, function (field) { return '|' + field; }));
@@ -626,7 +630,7 @@ exports.deleteModelForm = function (req, res, fullmodelid, Q, P, onComplete) {
626
630
  var dbtasks = {};
627
631
  var sql_rslt = null;
628
632
  dbtasks[fullmodelid] = function (dbtrans, callback) {
629
- db.Row(req._DBContext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
633
+ db.Row(dbcontext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
630
634
  if (stats) stats.model = model;
631
635
  if ((err == null) && (rslt != null) && (_this.jsh.map.rowcount in rslt) && (rslt[_this.jsh.map.rowcount] == 0)) err = Helper.NewError('No records affected', -3, stats);
632
636
  if (err != null) { err.model = model; err.sql = sql; }
@@ -43,6 +43,7 @@ exports.getModelRecordset = function (req, res, fullmodelid, Q, P, rowlimit, opt
43
43
  encryptedfields = this.getEncryptedFields(req, model.fields, 'S'); //Encrypted fields can be used for search
44
44
  if ((encryptedfields.length > 0) && !(req.secure) && (!_this.jsh.Config.system_settings.allow_insecure_http_encryption)) { Helper.GenError(req, res, -51, 'Encrypted / hash fields require HTTPS connection'); return; }
45
45
  var db = _this.jsh.getModelDB(req, fullmodelid);
46
+ var dbcontext = _this.jsh.getDBContext(req, model, db);
46
47
  if ('d' in Q) P = JSON.parse(Q.d);
47
48
 
48
49
  if (!_this.ParamCheck('Q', Q, ['|rowstart', '|rowcount', '|sort', '|search', '|searchjson', '|d', '|meta', '|getcount'])) { Helper.GenError(req, res, -4, 'Invalid Parameters'); return; }
@@ -212,7 +213,7 @@ exports.getModelRecordset = function (req, res, fullmodelid, Q, P, rowlimit, opt
212
213
  var dbtaskname = fullmodelid;
213
214
  if (!is_insert) {
214
215
  dbtasks[dbtaskname] = function (dbtans, callback) {
215
- db.Recordset(req._DBContext, dbsql.sql, sql_ptypes, sql_params, dbtans, function (err, rslt, stats) {
216
+ db.Recordset(dbcontext, dbsql.sql, sql_ptypes, sql_params, dbtans, function (err, rslt, stats) {
216
217
  if (err != null) { err.model = model; err.sql = dbsql.sql; }
217
218
  else {
218
219
  if (stats) stats.model = model;
@@ -274,7 +275,7 @@ exports.getModelRecordset = function (req, res, fullmodelid, Q, P, rowlimit, opt
274
275
 
275
276
  if (getcount) {
276
277
  dbtasks['_count_' + dbtaskname] = function (dbtrans, callback) {
277
- db.Row(req._DBContext, dbsql.rowcount_sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
278
+ db.Row(dbcontext, dbsql.rowcount_sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
278
279
  if ((err == null) && (rslt == null)) err = Helper.NewError('Count not found', -14);
279
280
  if (err != null) { err.model = model; err.sql = dbsql.rowcount_sql; }
280
281
  if (stats) stats.model = model;
@@ -33,6 +33,7 @@ exports.getTabCode = function (req, res, fullmodelid, onComplete) {
33
33
  var keylist = this.getKeyNames(model.fields);
34
34
  var tabcodelist = [model.tabcode];
35
35
  var db = _this.jsh.getModelDB(req, fullmodelid);
36
+ var dbcontext = _this.jsh.getDBContext(req, model, db);
36
37
 
37
38
  if (req.query.action == 'insert') { return onComplete(); }
38
39
  else if (!_.includes(['update','browse'],req.query.action)) { Helper.GenError(req, res, -9, 'Action not supported'); return; }
@@ -65,7 +66,7 @@ exports.getTabCode = function (req, res, fullmodelid, onComplete) {
65
66
 
66
67
  var sql = db.sql.getTabCode(_this.jsh, model, selectfields, keys, datalockqueries);
67
68
 
68
- this.ExecScalar(req._DBContext, sql, sql_ptypes, sql_params, function (err, rslt) {
69
+ this.ExecScalar(dbcontext, sql, sql_ptypes, sql_params, function (err, rslt) {
69
70
  if (err) { _this.jsh.Log.error(err); Helper.GenError(req, res, -99999, 'An unexpected error has occurred'); return; }
70
71
  if (rslt && rslt[0]) {
71
72
  return onComplete(rslt[0]);
@@ -81,6 +82,7 @@ exports.addTitleTasks = function (req, res, model, Q, dbtasks, targetperm) {
81
82
  var fieldlist = [];
82
83
  var nodatalock = null;
83
84
  var db = this.jsh.getModelDB(req, model.id);
85
+ var dbcontext = this.jsh.getDBContext(req, model, db);
84
86
  if (typeof model.title !== 'undefined'){
85
87
  if(_.isString(model.title)) title = model.title;
86
88
  else if(model.title.insert && Helper.hasAction(targetperm,'I')){
@@ -147,7 +149,7 @@ exports.addTitleTasks = function (req, res, model, Q, dbtasks, targetperm) {
147
149
 
148
150
  dbtasks['_title'] = function (dbtrans, callback, transtbl) {
149
151
  _this.ApplyTransTblChainedParameters(transtbl, sql, sql_ptypes, sql_params, model.fields);
150
- db.Scalar(req._DBContext, sql, sql_ptypes, sql_params, dbtrans, function (err, title, stats) {
152
+ db.Scalar(dbcontext, sql, sql_ptypes, sql_params, dbtrans, function (err, title, stats) {
151
153
  if (err) { _this.jsh.Log.error(err); Helper.GenError(req, res, -99999, 'An unexpected error has occurred'); return; }
152
154
  if(title) title = Helper.ResolveParams(req, title);
153
155
  return callback(null, title, stats);
@@ -248,6 +250,7 @@ exports.addDefaultTasks = function (req, res, model, Q, dbtasks) {
248
250
  for(var dbid in defaultCommands){
249
251
  let defaultCommand = defaultCommands[dbid];
250
252
  var db = _this.jsh.getDB(dbid);
253
+ var dbcontext = _this.jsh.getDBContext(req, model, db);
251
254
  var dflt_sql = db.sql.getDefaultTasks(_this.jsh, defaultCommand.dflt_sql_fields);
252
255
 
253
256
  //Add parameters from querystring
@@ -257,7 +260,7 @@ exports.addDefaultTasks = function (req, res, model, Q, dbtasks) {
257
260
  dbtasks['_defaults_'+dbid] = function (dbtrans, callback, transtbl) {
258
261
  _this.ApplyTransTblChainedParameters(transtbl, dflt_sql, defaultCommand.dflt_ptypes, defaultCommand.dflt_params, model.fields);
259
262
  if (dflt_sql) {
260
- db.Row(req._DBContext, dflt_sql, defaultCommand.dflt_ptypes, defaultCommand.dflt_params, dbtrans, function (err, rslt, stats) {
263
+ db.Row(dbcontext, dflt_sql, defaultCommand.dflt_ptypes, defaultCommand.dflt_params, dbtrans, function (err, rslt, stats) {
261
264
  if (err == null) {
262
265
  for (var f in rslt) {
263
266
  if (rslt[f] == null) _defaults[f] = '';
@@ -284,6 +287,7 @@ exports.addBreadcrumbTasks = function (req, res, model, Q, dbtasks, targetperm)
284
287
  var fieldlist = [];
285
288
  var nodatalock = null;
286
289
  var db = this.jsh.getModelDB(req, model.id);
290
+ var dbcontext = this.jsh.getDBContext(req, model, db);
287
291
  if(model.breadcrumbs.insert && Helper.hasAction(targetperm,'I')){
288
292
  if(model.breadcrumbs.insert.sql){ sql = model.breadcrumbs.insert.sql; fieldlist = model.breadcrumbs.insert.sql_params; nodatalock = model.breadcrumbs.insert.nodatalock; }
289
293
  }
@@ -350,7 +354,7 @@ exports.addBreadcrumbTasks = function (req, res, model, Q, dbtasks, targetperm)
350
354
 
351
355
  dbtasks['_bcrumbs'] = function (dbtrans, callback, transtbl) {
352
356
  _this.ApplyTransTblChainedParameters(transtbl, sql, sql_ptypes, sql_params, model.fields);
353
- db.Row(req._DBContext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
357
+ db.Row(dbcontext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
354
358
  if ((err == null) && (rslt == null)) err = Helper.NewError('Breadcrumbs not found', -14);
355
359
  if (err != null) { err.model = model; err.sql = sql; }
356
360
  if (stats) stats.model = model;
@@ -384,6 +388,7 @@ exports.addLOVTasks = function (req, res, model, Q, dbtasks, options) {
384
388
  if(lov && lov.db){
385
389
  lovdb = jsh.getDB(lov.db);
386
390
  }
391
+ var dbcontext = jsh.getDBContext(req, model, lovdb);
387
392
 
388
393
  //If form and actions="B", do not get the full LOV
389
394
  var tgtactions = ejsext.getActions(req, model, field.actions, options.action);
@@ -469,7 +474,7 @@ exports.addLOVTasks = function (req, res, model, Q, dbtasks, options) {
469
474
 
470
475
  dbtasks['_LOV_' + field.name] = function (dbtrans, callback, transtbl) {
471
476
  _this.ApplyTransTblChainedParameters(transtbl, sql, lov_ptypes, lov_params, model.fields);
472
- lov_db_function.call(lovdb, req._DBContext, sql, lov_ptypes, lov_params, dbtrans, function (err, rslt, stats) {
477
+ lov_db_function.call(lovdb, dbcontext, sql, lov_ptypes, lov_params, dbtrans, function (err, rslt, stats) {
473
478
  if (err == null) {
474
479
  //Generate warning if the LOV options are too long, and sqlselect, sqltruncate is not defined for the field
475
480
  if(!rslt) rslt = [];
@@ -40,6 +40,7 @@ exports.getModelMultisel = function (req, res, fullmodelid, Q, P) {
40
40
  var allfieldslist = _.union([lovfield.name], fieldlist);
41
41
  var allfields = this.getFieldsByName(model.fields, allfieldslist);
42
42
  var db = _this.jsh.getModelDB(req, fullmodelid);
43
+ var dbcontext = _this.jsh.getDBContext(req, model, db);
43
44
 
44
45
  var is_insert = true;
45
46
  if (_this.ParamCheck('Q', Q, _.union(_.map(foreignkeylist, function (foreignkey) { return '&' + foreignkey; }), ['|_action']), false)) { is_insert = false; }
@@ -115,7 +116,7 @@ exports.getModelMultisel = function (req, res, fullmodelid, Q, P) {
115
116
 
116
117
  var dbtasks = {};
117
118
  dbtasks[fullmodelid] = function (dbtrans, callback) {
118
- db.Recordset(req._DBContext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
119
+ db.Recordset(dbcontext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
119
120
  if ((err == null) && (rslt == null)) err = Helper.NewError('Record not found', -1);
120
121
  if (err != null) { err.model = model; err.sql = sql; }
121
122
  if (stats) stats.model = model;
@@ -145,6 +146,7 @@ exports.postModelMultisel = function (req, res, fullmodelid, Q, P, onComplete) {
145
146
  var foreignkeylist = _this.getFieldNames(req, model.fields, 'F');
146
147
  var foreignkeyfields = this.getFieldsByName(model.fields, foreignkeylist);
147
148
  var db = _this.jsh.getModelDB(req, fullmodelid);
149
+ var dbcontext = _this.jsh.getDBContext(req, model, db);
148
150
 
149
151
  if (!_this.ParamCheck('Q', Q, _.map(foreignkeylist, function (foreignkey) { return '&' + foreignkey; }))) { Helper.GenError(req, res, -4, 'Invalid Parameters'); return; }
150
152
  if (!_this.ParamCheck('P', P, ['&' + lovfield.name])) { Helper.GenError(req, res, -4, 'Invalid Parameters'); return; }
@@ -229,7 +231,7 @@ exports.postModelMultisel = function (req, res, fullmodelid, Q, P, onComplete) {
229
231
  var sql_rslt = null;
230
232
  dbtasks[fullmodelid] = function (dbtrans, callback, transtbl) {
231
233
  sql_params = _this.ApplyTransTblEscapedParameters(sql_params, transtbl);
232
- db.Row(req._DBContext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
234
+ db.Row(dbcontext, sql, sql_ptypes, sql_params, dbtrans, function (err, rslt, stats) {
233
235
  if (err != null) { err.model = model; err.sql = sql; }
234
236
  if (stats) stats.model = model;
235
237
  if(model.onsqlupdated) sql_rslt = rslt;
package/AppSrvRpt.js CHANGED
@@ -59,7 +59,7 @@ AppSrvRpt.prototype.queueReport = function (req, res, fullmodelid, Q, P, params,
59
59
  if(req){
60
60
  if (!Helper.hasModelAction(req, model, 'B')) { return errorHandler(-11, jsh._tP('Invalid Model Access for @fullmodelid', { fullmodelid })); }
61
61
  db = db || jsh.getModelDB(req, fullmodelid);
62
- dbcontext = dbcontext || req._DBContext || 'report';
62
+ dbcontext = dbcontext || jsh.getDBContext(req, model, db) || 'report';
63
63
  }
64
64
  else if(!db) throw new Error('Either req or db is required.');
65
65
 
@@ -222,7 +222,7 @@ AppSrvRpt.prototype.parseReportSQLData = function (req, db, dbcontext, model, sq
222
222
  var _this = this;
223
223
  if(req){
224
224
  db = db || jsh.getModelDB(req, model.id);
225
- dbcontext = dbcontext || req._DBContext || 'report';
225
+ dbcontext = dbcontext || jsh.getDBContext(req, model, db) || 'report';
226
226
  }
227
227
  else if(!db) throw new Error('Either req or db is required.');
228
228
  _.each(rdata, function (dparams, dname) {
@@ -832,6 +832,7 @@ AppSrvRpt.prototype.runReportJob = function (req, res, fullmodelid, Q, P, onComp
832
832
  var sql_params = {};
833
833
  var verrors = {};
834
834
  var db = jsh.getModelDB(req, fullmodelid);
835
+ var dbcontext = jsh.getDBContext(req, model, db);
835
836
 
836
837
  var fields = thisapp.getFieldsByName(model.fields, fieldlist);
837
838
  if (fields.length == 0) return onComplete(null, {});
@@ -857,7 +858,7 @@ AppSrvRpt.prototype.runReportJob = function (req, res, fullmodelid, Q, P, onComp
857
858
 
858
859
  var dbtasks = {};
859
860
  dbtasks['jobqueue'] = function (callback) {
860
- db.Recordset(req._DBContext, sql, sql_ptypes, sql_params, function (err, rslt, stats) {
861
+ db.Recordset(dbcontext, sql, sql_ptypes, sql_params, function (err, rslt, stats) {
861
862
  if ((err == null) && (rslt == null)) err = Helper.NewError('Record not found', -1);
862
863
  if (err != null) { err.model = model; err.sql = sql; }
863
864
  if (stats) stats.model = model;
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # =========
2
- # jsharmony
2
+ # jsHarmony
3
3
  # =========
4
4
 
5
5
  Rapid Application Development (RAD) Platform for Node.js Database Application Development
@@ -489,6 +489,15 @@ exports.getModelDB = function(req, fullmodelid) {
489
489
  return this.getDB(dbid);
490
490
  };
491
491
 
492
+ exports.getDBContext = function(req, model, db){
493
+ var dbcontext = req._DBContext;
494
+ if(this.Config.onGetDBContext){
495
+ var sysContext = this.Config.onGetDBContext(this, req, model, db);
496
+ if(!Helper.isNullUndefined(sysContext)) dbcontext = sysContext;
497
+ }
498
+ return dbcontext;
499
+ };
500
+
492
501
  exports.getDB = function(dbid){
493
502
  if(!dbid) dbid = 'default';
494
503
  if(!(dbid in this.DB)) throw new Error('Database connection '+dbid+' not found');
@@ -2250,7 +2250,7 @@ exports.ParseEntities = function () {
2250
2250
  if (model.fields) _.each(model.fields, function (field) {
2251
2251
  if(field.lov){
2252
2252
  var lov = field.lov;
2253
- var lovDB = 'default';
2253
+ var lovDB = modelDB;
2254
2254
  if('database' in lov){
2255
2255
  lov.db = lov.database;
2256
2256
  }
@@ -263,6 +263,9 @@ function jsHarmonyConfig(config){
263
263
  //When a client tries to connect to a jsHarmony queue
264
264
  this.onQueueSubscribe = []; //function(cb, req, res, queueid){ return cb(); }
265
265
 
266
+ //Overriding the database context
267
+ this.onGetDBContext = null; //function(jsh, req, model, db){ return 'system'; }
268
+
266
269
  //Theme CSS files
267
270
  this.themes = {
268
271
  'light': [ 'jsHarmony.theme.light.css' ],
@@ -20,6 +20,7 @@ along with this package. If not, see <http://www.gnu.org/licenses/>.
20
20
  var _ = require('lodash');
21
21
  var async = require('async');
22
22
  var jshParser = require('./JSParser.js');
23
+ var Helper = require('./Helper.js');
23
24
 
24
25
  module.exports = exports = {};
25
26
 
@@ -56,18 +57,25 @@ exports.generateSQLObjects = function(table, options, callback){
56
57
  if(!options.withData) return generate_cb();
57
58
  var sqlWhere = '1=1';
58
59
  if((options.dataFilter||'').trim()) sqlWhere = options.dataFilter;
59
- db.Scalar('','select count(*) from ' + tabledef.table_selector + ' where '+sqlWhere,[],{},function(err,datacnt){
60
- if(err){ return generate_cb(err); }
61
- if(!options.dataFilter && (datacnt > options.maxDataCount)){
62
- _this.jsh.Log.warning('Warning: Skipping data for table ' + tabledef.table_selector + ', exceeds max rowcount of ' + options.maxDataCount + ', has ' + datacnt + ' rows' );
63
- return generate_cb(null);
60
+ Helper.execif(!options.dataFilter,
61
+ function(next){
62
+ db.Scalar('','select count(*) from ' + tabledef.table_selector,[],{},function(err,datacnt){
63
+ if(err){ return generate_cb(err); }
64
+ if(datacnt > options.maxDataCount){
65
+ _this.jsh.Log.warning('Warning: Skipping data for table ' + tabledef.table_selector + ', exceeds max rowcount of ' + options.maxDataCount + ', has ' + datacnt + ' rows' );
66
+ return generate_cb(null);
67
+ }
68
+ return next();
69
+ });
70
+ },
71
+ function(){
72
+ db.Recordset('','select * from ' + tabledef.table_selector + ' where '+sqlWhere,[],{},function(err,rslt){
73
+ if(err){ return generate_cb(err); }
74
+ tabledef.data = rslt;
75
+ return generate_cb(null);
76
+ });
64
77
  }
65
- db.Recordset('','select * from ' + tabledef.table_selector + ' where '+sqlWhere,[],{},function(err,rslt){
66
- if(err){ return generate_cb(err); }
67
- tabledef.data = rslt;
68
- return generate_cb(null);
69
- });
70
- });
78
+ );
71
79
  },
72
80
  //Generate SQL Object
73
81
  function(generate_cb){
package/lib/Helper.js CHANGED
@@ -1076,6 +1076,14 @@ exports.cubeMapReplace = function(mapping, txt){
1076
1076
  return rslt;
1077
1077
  };
1078
1078
 
1079
+ exports.pushArray = function(a,b){
1080
+ if(!a.push) throw new Error('First operand must be an array');
1081
+ if(!b) return;
1082
+ if(!b.length) return;
1083
+ for(var i=0;i<b.length;i++) a.push(b[i]);
1084
+ return a;
1085
+ };
1086
+
1079
1087
  exports.requireAnywhere = function(baseModule, moduleName){
1080
1088
  var Module = baseModule.constructor;
1081
1089
  var createRequire = Module.createRequire || Module.createRequireFromPath;
@@ -1130,7 +1138,7 @@ exports.gather = function(f_drain, options){ //f_drain(items, callback)
1130
1138
  _this.items.splice(0);
1131
1139
  f_drain(drainItems, function(err){
1132
1140
  if(!options.parallel) _this.isDraining = false;
1133
- return callback(err);
1141
+ return callback.apply(null, arguments);
1134
1142
  });
1135
1143
  }
1136
1144
  );
package/lib/WebConnect.js CHANGED
@@ -44,7 +44,7 @@ function WebConnect() {
44
44
  this.MAX_REDIRECTS = 20;
45
45
  }
46
46
  WebConnect.prototype.reqjson = function (url, method, post, headers, ftarget, callback, options) {
47
- this.req(url, method, post, headers, ftarget, function (err, res, rslt) {
47
+ return this.req(url, method, post, headers, ftarget, function (err, res, rslt) {
48
48
  if (callback) {
49
49
  if (err) return callback(err, null, null, null);
50
50
  if (rslt && (rslt == '---SAVEDTOFILE---')) return callback(err, '---SAVEDTOFILE---', null, res);
@@ -166,6 +166,7 @@ WebConnect.prototype.req = function (url, method, post, headers, ftarget, callba
166
166
  else req.write(post);
167
167
  }
168
168
  req.end();
169
+ return req;
169
170
  };
170
171
 
171
172
  exports.WebConnect = WebConnect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsharmony",
3
- "version": "1.27.2",
3
+ "version": "1.28.0",
4
4
  "description": "Rapid Application Development (RAD) Platform for Node.js Database Application Development",
5
5
  "main": "index.js",
6
6
  "scripts": {