@syncfusion/ej2-querybuilder 20.3.56 → 20.3.59

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.
@@ -3227,6 +3227,8 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
3227
3227
  StartsWith: 'Starts With',
3228
3228
  EndsWith: 'Ends With',
3229
3229
  Contains: 'Contains',
3230
+ NotLike: 'Not Like',
3231
+ Like: 'Like',
3230
3232
  Equal: 'Equal',
3231
3233
  NotEqual: 'Not Equal',
3232
3234
  LessThan: 'Less Than',
@@ -3311,6 +3313,16 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
3311
3313
  isnull: 'IS NULL', isnotnull: 'IS NOT NULL', isempty: 'IS EMPTY', isnotempty: 'IS NOT EMPTY', notstartswith: 'NOT LIKE',
3312
3314
  notendswith: 'NOT LIKE', notcontains: 'NOT LIKE'
3313
3315
  };
3316
+ this.sqlOperators = {
3317
+ equal: '=', notequal: '!=', greaterthan: '>', greaterthanorequal: '>=', lessthan: '<', in: this.l10n.getConstant('In').toUpperCase(),
3318
+ notin: this.l10n.getConstant('NotIn').toUpperCase(), lessthanorequal: '<=', startswith: this.l10n.getConstant('Like').toUpperCase(),
3319
+ endswith: this.l10n.getConstant('Like').toUpperCase(), between: this.l10n.getConstant('Between').toUpperCase(),
3320
+ notbetween: this.l10n.getConstant('NotBetween').toUpperCase(), contains: this.l10n.getConstant('Like').toUpperCase(),
3321
+ isnull: this.l10n.getConstant('IsNull').toUpperCase(), isnotnull: this.l10n.getConstant('IsNotNull').toUpperCase(),
3322
+ isempty: this.l10n.getConstant('IsEmpty').toUpperCase(), isnotempty: this.l10n.getConstant('IsNotEmpty').toUpperCase(),
3323
+ notstartswith: this.l10n.getConstant('NotLike').toUpperCase(), notendswith: this.l10n.getConstant('NotLike').toUpperCase(),
3324
+ notcontains: this.l10n.getConstant('NotLike').toUpperCase()
3325
+ };
3314
3326
  if (!this.fields) {
3315
3327
  this.fields = { text: 'label', value: 'field' };
3316
3328
  }
@@ -4396,7 +4408,7 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4396
4408
  }
4397
4409
  return false;
4398
4410
  };
4399
- QueryBuilder.prototype.getSqlString = function (rules, enableEscape, queryStr) {
4411
+ QueryBuilder.prototype.getSqlString = function (rules, enableEscape, queryStr, sqlLocale) {
4400
4412
  var isRoot = false;
4401
4413
  if (!queryStr && queryStr !== '') {
4402
4414
  queryStr = '';
@@ -4407,27 +4419,33 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4407
4419
  }
4408
4420
  var condition = rules.condition;
4409
4421
  if (rules.not) {
4422
+ var rulesNotCondition = void 0;
4410
4423
  if (isRoot) {
4411
- queryStr += 'NOT (';
4424
+ rulesNotCondition = sqlLocale ? this.l10n.getConstant('NOT').toUpperCase() + ' (' : 'NOT (';
4425
+ queryStr += rulesNotCondition;
4412
4426
  }
4413
4427
  else {
4414
- queryStr += ' NOT (';
4428
+ rulesNotCondition = sqlLocale ? ' ' + this.l10n.getConstant('NOT').toUpperCase() + ' (' : ' NOT (';
4429
+ queryStr += rulesNotCondition;
4415
4430
  }
4416
4431
  }
4417
4432
  for (var j = 0, jLen = rules.rules.length; j < jLen; j++) {
4418
4433
  if (rules.rules[j].rules) {
4419
- queryStr = this.getSqlString(rules.rules[j], enableEscape, queryStr);
4434
+ queryStr = this.getSqlString(rules.rules[j], enableEscape, queryStr, sqlLocale);
4420
4435
  }
4421
4436
  else {
4422
4437
  var rule = rules.rules[j];
4423
4438
  var valueStr = '';
4439
+ var ruleOpertor = void 0;
4440
+ ruleOpertor = sqlLocale ? this.sqlOperators[rule.operator] : this.operators[rule.operator];
4424
4441
  if (rule.value instanceof Array) {
4425
4442
  if (rule.operator.toString().indexOf('between') > -1) {
4443
+ var ruleCondition = sqlLocale ? ' ' + this.l10n.getConstant('AND').toUpperCase() + ' ' : ' ' + 'AND' + ' ';
4426
4444
  if (rule.type === 'date' && !this.isDateFunction(rule.value[0])) {
4427
- valueStr += '"' + rule.value[0] + '" AND "' + rule.value[1] + '"';
4445
+ valueStr += '"' + rule.value[0] + '"' + ruleCondition + '"' + rule.value[1] + '"';
4428
4446
  }
4429
4447
  else {
4430
- valueStr += rule.value[0] + ' AND ' + rule.value[1];
4448
+ valueStr += rule.value[0] + ruleCondition + rule.value[1];
4431
4449
  }
4432
4450
  }
4433
4451
  else {
@@ -4471,7 +4489,7 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4471
4489
  rule.field = '"' + rule.field + '"';
4472
4490
  }
4473
4491
  }
4474
- queryStr += rule.field + ' ' + this.operators[rule.operator];
4492
+ queryStr += rule.field + ' ' + ruleOpertor;
4475
4493
  }
4476
4494
  else {
4477
4495
  if (enableEscape) {
@@ -4482,7 +4500,7 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4482
4500
  rule.field = '"' + rule.field + '"';
4483
4501
  }
4484
4502
  }
4485
- queryStr += rule.field + ' ' + this.operators[rule.operator] + ' ' + valueStr;
4503
+ queryStr += rule.field + ' ' + ruleOpertor + ' ' + valueStr;
4486
4504
  }
4487
4505
  if (rule.condition && rule.condition !== '') {
4488
4506
  condition = rule.condition;
@@ -4492,7 +4510,8 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4492
4510
  if (condition === '') {
4493
4511
  condition = rules.rules[j].condition;
4494
4512
  }
4495
- queryStr += ' ' + condition.toUpperCase() + ' ';
4513
+ condition = sqlLocale ? this.l10n.getConstant(condition.toUpperCase()).toUpperCase() : condition.toUpperCase();
4514
+ queryStr += ' ' + condition + ' ';
4496
4515
  }
4497
4516
  }
4498
4517
  if (!isRoot) {
@@ -4507,24 +4526,26 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4507
4526
  * Sets the rules from the sql query.
4508
4527
  *
4509
4528
  * @param {string} sqlString - 'sql String' to be passed to set the rule.
4529
+ * @param {boolean} sqlLocale - Set `true` if Localization for Sql query.
4510
4530
  * @returns {void}
4511
4531
  */
4512
- QueryBuilder.prototype.setRulesFromSql = function (sqlString) {
4532
+ QueryBuilder.prototype.setRulesFromSql = function (sqlString, sqlLocale) {
4513
4533
  sqlString = sqlString.replace(/`/g, '');
4514
- var ruleModel = this.getRulesFromSql(sqlString);
4534
+ var ruleModel = this.getRulesFromSql(sqlString, sqlLocale);
4515
4535
  this.setRules({ condition: ruleModel.condition, not: ruleModel.not, rules: ruleModel.rules });
4516
4536
  };
4517
4537
  /**
4518
4538
  * Get the rules from SQL query.
4519
4539
  *
4520
4540
  * @param {string} sqlString - 'sql String' to be passed to get the rule.
4541
+ * @param {boolean} sqlLocale - Set `true` if Localization for Sql query.
4521
4542
  * @returns {object} - Rules from SQL query
4522
4543
  */
4523
- QueryBuilder.prototype.getRulesFromSql = function (sqlString) {
4544
+ QueryBuilder.prototype.getRulesFromSql = function (sqlString, sqlLocale) {
4524
4545
  this.parser = [];
4525
- this.sqlParser(sqlString);
4546
+ this.sqlParser(sqlString, sqlLocale);
4526
4547
  this.rule = { condition: 'and', not: false, rules: [] };
4527
- var rule = this.processParser(this.parser, this.rule, [0]);
4548
+ var rule = this.processParser(this.parser, this.rule, [0], sqlLocale);
4528
4549
  if (this.enableNotCondition) {
4529
4550
  return { condition: rule.condition, not: rule.not, rules: rule.rules };
4530
4551
  }
@@ -4537,28 +4558,45 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4537
4558
  *
4538
4559
  * @param {RuleModel} rule - 'rule' to be passed to get the sql.
4539
4560
  * @param {boolean} allowEscape - Set `true` if it exclude the escape character.
4561
+ * @param {boolean} sqlLocale - Set `true` if Localization for Sql query.
4540
4562
  * @returns {object} - Sql query from rules.
4541
4563
  */
4542
- QueryBuilder.prototype.getSqlFromRules = function (rule, allowEscape) {
4564
+ QueryBuilder.prototype.getSqlFromRules = function (rule, allowEscape, sqlLocale) {
4543
4565
  if (!rule) {
4544
4566
  rule = this.getValidRules();
4545
4567
  }
4546
4568
  rule = this.getRuleCollection(rule, false);
4547
- return this.getSqlString(this.getValidRules(rule), allowEscape).replace(/"/g, '\'');
4569
+ return this.getSqlString(this.getValidRules(rule), allowEscape, null, sqlLocale).replace(/"/g, '\'');
4548
4570
  };
4549
- QueryBuilder.prototype.sqlParser = function (sqlString) {
4571
+ QueryBuilder.prototype.sqlParser = function (sqlString, sqlLocale) {
4550
4572
  var st = 0;
4551
4573
  var str;
4552
4574
  do {
4553
4575
  str = sqlString.slice(st);
4554
- st += this.parseSqlStrings(str);
4576
+ st += this.parseSqlStrings(str, sqlLocale);
4555
4577
  } while (str !== '');
4556
4578
  return this.parser;
4557
4579
  };
4558
- QueryBuilder.prototype.parseSqlStrings = function (sqlString) {
4580
+ QueryBuilder.prototype.parseSqlStrings = function (sqlString, sqlLocale) {
4559
4581
  var operators = ['=', '!=', '<=', '>=', '<', '>'];
4560
- var conditions = ['AND', 'OR', 'NOT'];
4561
- var subOp = ['IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'BETWEEN', 'NOT BETWEEN', 'IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY'];
4582
+ var conditions;
4583
+ if (sqlLocale) {
4584
+ conditions = [this.l10n.getConstant('AND').toUpperCase(), this.l10n.getConstant('OR').toUpperCase(), this.l10n.getConstant('NOT').toUpperCase()];
4585
+ }
4586
+ else {
4587
+ conditions = ['AND', 'OR', 'NOT'];
4588
+ }
4589
+ var subOp;
4590
+ if (sqlLocale) {
4591
+ subOp = [this.l10n.getConstant('In').toUpperCase(), this.l10n.getConstant('NotIn').toUpperCase(),
4592
+ this.l10n.getConstant('Like').toUpperCase(), this.l10n.getConstant('NotLike').toUpperCase(),
4593
+ this.l10n.getConstant('Between').toUpperCase(), this.l10n.getConstant('NotBetween').toUpperCase(),
4594
+ this.l10n.getConstant('IsNull').toUpperCase(), this.l10n.getConstant('IsNotNull').toUpperCase(),
4595
+ this.l10n.getConstant('IsEmpty').toUpperCase(), this.l10n.getConstant('IsNotEmpty').toUpperCase()];
4596
+ }
4597
+ else {
4598
+ subOp = ['IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'BETWEEN', 'NOT BETWEEN', 'IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY'];
4599
+ }
4562
4600
  var regexStr;
4563
4601
  var regex;
4564
4602
  var matchValue;
@@ -4625,7 +4663,7 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4625
4663
  this.parser.push(['Literal', matchValue]);
4626
4664
  return matchValue.length + 2;
4627
4665
  }
4628
- if (this.checkNumberLiteral(sqlString)) {
4666
+ if (this.checkNumberLiteral(sqlString, sqlLocale)) {
4629
4667
  matchValue = /^[0-9]+(\.[0-9]+)?/.exec(sqlString)[0];
4630
4668
  this.parser.push(['Literal', matchValue]);
4631
4669
  return matchValue.length;
@@ -4669,7 +4707,7 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4669
4707
  }
4670
4708
  return false;
4671
4709
  };
4672
- QueryBuilder.prototype.checkNumberLiteral = function (sqlString) {
4710
+ QueryBuilder.prototype.checkNumberLiteral = function (sqlString, sqlLocale) {
4673
4711
  var lastParser = this.parser[this.parser.length - 1];
4674
4712
  if (!lastParser) {
4675
4713
  return true;
@@ -4681,19 +4719,38 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4681
4719
  if (lastParser[0] === 'Left' && (secParser && secParser[0] === 'Conditions')) {
4682
4720
  return true;
4683
4721
  }
4684
- if (lastParser[0] === 'Conditions' && (betweenParser && betweenParser[1].indexOf('between') < 0)) {
4722
+ var betweenOperator = sqlLocale ? this.l10n.getConstant('Between').toLowerCase() : 'between';
4723
+ if (lastParser[0] === 'Conditions' && (betweenParser && betweenParser[1].indexOf(betweenOperator) < 0)) {
4685
4724
  return true;
4686
4725
  }
4687
4726
  }
4688
4727
  }
4689
4728
  return false;
4690
4729
  };
4691
- QueryBuilder.prototype.getOperator = function (value, operator) {
4730
+ QueryBuilder.prototype.getOperator = function (value, operator, sqlLocale) {
4692
4731
  var operators = {
4693
4732
  '=': 'equal', '!=': 'notequal', '<': 'lessthan', '>': 'greaterthan', '<=': 'lessthanorequal',
4694
4733
  '>=': 'greaterthanorequal', 'in': 'in', 'not in': 'notin', 'between': 'between', 'not between': 'notbetween',
4695
4734
  'is empty': 'isempty', 'is null': 'isnull', 'is not null': 'isnotnull', 'is not empty': 'isnotempty'
4696
4735
  };
4736
+ if (sqlLocale) {
4737
+ var localeOperator = Object.keys(this.sqlOperators);
4738
+ for (var i = 0; i < localeOperator.length; i++) {
4739
+ if (this.sqlOperators[localeOperator[i]] === operator.toUpperCase()) {
4740
+ if (value && value.indexOf('%') === 0 && value[value.length - 1] === '%') {
4741
+ return (localeOperator[i] === 'notcontains') ? 'notcontains' : 'contains';
4742
+ }
4743
+ else if (value && value.indexOf('%') !== 0 && value.indexOf('%') === value.length - 1) {
4744
+ return (localeOperator[i] === 'notstartswith') ? 'notstartswith' : 'startswith';
4745
+ }
4746
+ else if (value && value.indexOf('%') === 0 && value.indexOf('%') !== value.length - 1) {
4747
+ return (localeOperator[i] === 'notendswith') ? 'notendswith' : 'endswith';
4748
+ }
4749
+ return localeOperator[i];
4750
+ }
4751
+ }
4752
+ return null;
4753
+ }
4697
4754
  if (value) {
4698
4755
  if (value.indexOf('%') === 0 && value[value.length - 1] === '%') {
4699
4756
  return (operator === 'not like') ? 'notcontains' : 'contains';
@@ -4717,7 +4774,10 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4717
4774
  };
4718
4775
  QueryBuilder.prototype.getTypeFromColumn = function (rules) {
4719
4776
  var columnData = this.getColumn(rules.field);
4720
- return columnData.type;
4777
+ if (!isNullOrUndefined(columnData)) {
4778
+ return columnData.type;
4779
+ }
4780
+ return null;
4721
4781
  };
4722
4782
  QueryBuilder.prototype.getLabelFromColumn = function (field) {
4723
4783
  var label = '';
@@ -4750,7 +4810,7 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4750
4810
  }
4751
4811
  return this.getColumn(fieldName).label;
4752
4812
  };
4753
- QueryBuilder.prototype.processParser = function (parser, rules, levelColl) {
4813
+ QueryBuilder.prototype.processParser = function (parser, rules, levelColl, sqlLocale) {
4754
4814
  var j;
4755
4815
  var jLen;
4756
4816
  var rule;
@@ -4769,18 +4829,27 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4769
4829
  rule = { label: parser[i][1], field: parser[i][1] };
4770
4830
  if (parser[i + 1][0] === 'SubOperators') {
4771
4831
  if (parser[i + 1][1].indexOf('null') > -1 || parser[i + 1][1].indexOf('empty') > -1) {
4772
- rule.operator = this.getOperator(' ', parser[i + 1][1]);
4832
+ rule.operator = this.getOperator(' ', parser[i + 1][1], sqlLocale);
4773
4833
  rule.value = null;
4774
4834
  rule.type = this.getTypeFromColumn(rule);
4775
4835
  }
4776
4836
  else {
4777
4837
  var oper = parser[i + 3][1] ? parser[i + 3][1].replace(/'/g, '') : parser[i + 3][1];
4778
- rule.operator = this.getOperator(oper, parser[i + 1][1]);
4838
+ rule.operator = this.getOperator(oper, parser[i + 1][1], sqlLocale);
4779
4839
  }
4780
4840
  operator = parser[i + 1][1];
4781
4841
  i++;
4782
4842
  j = i + 1;
4783
4843
  jLen = iLen;
4844
+ if (sqlLocale && rule.operator === 'contains' || rule.operator === 'startswith' || rule.operator === 'endswith') {
4845
+ operator = 'like';
4846
+ }
4847
+ else if (sqlLocale && rule.operator === 'notcontains' || rule.operator === 'notstartswith' || rule.operator === 'notendswith') {
4848
+ operator = 'not like';
4849
+ }
4850
+ else if (sqlLocale) {
4851
+ operator = rule.operator;
4852
+ }
4784
4853
  for (j = i + 1; j < jLen; j++) {
4785
4854
  if (operator.indexOf('between') < 0 && parser[j][0] === 'Left') {
4786
4855
  isLeftOpened = true;
@@ -4846,7 +4915,7 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4846
4915
  }
4847
4916
  }
4848
4917
  else if (parser[i + 1][0] === 'Operators') {
4849
- rule.operator = this.getOperator(parser[i + 2][1], parser[i + 1][1]);
4918
+ rule.operator = this.getOperator(parser[i + 2][1], parser[i + 1][1], sqlLocale);
4850
4919
  if (parser[i + 2][0] === 'Number') {
4851
4920
  rule.type = 'number';
4852
4921
  rule.value = Number(parser[i + 2][1]);
@@ -4860,7 +4929,7 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4860
4929
  rules.rules.push(rule);
4861
4930
  }
4862
4931
  else if (parser[i][0] === 'Left') {
4863
- if (!(parser[0][0] === 'Left') && parser[i - 1][1] === 'not') {
4932
+ if (!(parser[0][0] === 'Left') && (parser[i - 1][1] === 'not' || sqlLocale && this.l10n.getConstant('NOT').toLowerCase() === parser[i - 1][1])) {
4864
4933
  continue;
4865
4934
  }
4866
4935
  this.parser = parser.splice(i + 1, iLen - (i + 1));
@@ -4879,11 +4948,11 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4879
4948
  }
4880
4949
  levelColl.push(grpCount);
4881
4950
  rules.rules.push(subRules);
4882
- subRules = this.processParser(this.parser, subRules, levelColl);
4951
+ subRules = this.processParser(this.parser, subRules, levelColl, sqlLocale);
4883
4952
  return rules;
4884
4953
  }
4885
4954
  else if (parser[i][0] === 'Conditions') {
4886
- if (parser[i][1] === 'not') {
4955
+ if (parser[i][1] === 'not' || (sqlLocale && this.l10n.getConstant('NOT').toLowerCase() === parser[i][1])) {
4887
4956
  rules.not = true;
4888
4957
  }
4889
4958
  else {
@@ -4898,7 +4967,7 @@ var QueryBuilder = /** @__PURE__ @class */ (function (_super) {
4898
4967
  for (l = 0; l < lLen; l++) {
4899
4968
  rules = this.findGroupByIdx(levelColl[l], rules, l === 0);
4900
4969
  }
4901
- return this.processParser(this.parser, rules, levelColl);
4970
+ return this.processParser(this.parser, rules, levelColl, sqlLocale);
4902
4971
  }
4903
4972
  }
4904
4973
  return rules;