@syncfusion/ej2-querybuilder 20.3.50 → 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.
@@ -3163,6 +3163,8 @@ let QueryBuilder = class QueryBuilder extends Component {
3163
3163
  StartsWith: 'Starts With',
3164
3164
  EndsWith: 'Ends With',
3165
3165
  Contains: 'Contains',
3166
+ NotLike: 'Not Like',
3167
+ Like: 'Like',
3166
3168
  Equal: 'Equal',
3167
3169
  NotEqual: 'Not Equal',
3168
3170
  LessThan: 'Less Than',
@@ -3247,6 +3249,16 @@ let QueryBuilder = class QueryBuilder extends Component {
3247
3249
  isnull: 'IS NULL', isnotnull: 'IS NOT NULL', isempty: 'IS EMPTY', isnotempty: 'IS NOT EMPTY', notstartswith: 'NOT LIKE',
3248
3250
  notendswith: 'NOT LIKE', notcontains: 'NOT LIKE'
3249
3251
  };
3252
+ this.sqlOperators = {
3253
+ equal: '=', notequal: '!=', greaterthan: '>', greaterthanorequal: '>=', lessthan: '<', in: this.l10n.getConstant('In').toUpperCase(),
3254
+ notin: this.l10n.getConstant('NotIn').toUpperCase(), lessthanorequal: '<=', startswith: this.l10n.getConstant('Like').toUpperCase(),
3255
+ endswith: this.l10n.getConstant('Like').toUpperCase(), between: this.l10n.getConstant('Between').toUpperCase(),
3256
+ notbetween: this.l10n.getConstant('NotBetween').toUpperCase(), contains: this.l10n.getConstant('Like').toUpperCase(),
3257
+ isnull: this.l10n.getConstant('IsNull').toUpperCase(), isnotnull: this.l10n.getConstant('IsNotNull').toUpperCase(),
3258
+ isempty: this.l10n.getConstant('IsEmpty').toUpperCase(), isnotempty: this.l10n.getConstant('IsNotEmpty').toUpperCase(),
3259
+ notstartswith: this.l10n.getConstant('NotLike').toUpperCase(), notendswith: this.l10n.getConstant('NotLike').toUpperCase(),
3260
+ notcontains: this.l10n.getConstant('NotLike').toUpperCase()
3261
+ };
3250
3262
  if (!this.fields) {
3251
3263
  this.fields = { text: 'label', value: 'field' };
3252
3264
  }
@@ -4328,7 +4340,7 @@ let QueryBuilder = class QueryBuilder extends Component {
4328
4340
  }
4329
4341
  return false;
4330
4342
  }
4331
- getSqlString(rules, enableEscape, queryStr) {
4343
+ getSqlString(rules, enableEscape, queryStr, sqlLocale) {
4332
4344
  let isRoot = false;
4333
4345
  if (!queryStr && queryStr !== '') {
4334
4346
  queryStr = '';
@@ -4339,27 +4351,33 @@ let QueryBuilder = class QueryBuilder extends Component {
4339
4351
  }
4340
4352
  let condition = rules.condition;
4341
4353
  if (rules.not) {
4354
+ let rulesNotCondition;
4342
4355
  if (isRoot) {
4343
- queryStr += 'NOT (';
4356
+ rulesNotCondition = sqlLocale ? this.l10n.getConstant('NOT').toUpperCase() + ' (' : 'NOT (';
4357
+ queryStr += rulesNotCondition;
4344
4358
  }
4345
4359
  else {
4346
- queryStr += ' NOT (';
4360
+ rulesNotCondition = sqlLocale ? ' ' + this.l10n.getConstant('NOT').toUpperCase() + ' (' : ' NOT (';
4361
+ queryStr += rulesNotCondition;
4347
4362
  }
4348
4363
  }
4349
4364
  for (let j = 0, jLen = rules.rules.length; j < jLen; j++) {
4350
4365
  if (rules.rules[j].rules) {
4351
- queryStr = this.getSqlString(rules.rules[j], enableEscape, queryStr);
4366
+ queryStr = this.getSqlString(rules.rules[j], enableEscape, queryStr, sqlLocale);
4352
4367
  }
4353
4368
  else {
4354
4369
  const rule = rules.rules[j];
4355
4370
  let valueStr = '';
4371
+ let ruleOpertor;
4372
+ ruleOpertor = sqlLocale ? this.sqlOperators[rule.operator] : this.operators[rule.operator];
4356
4373
  if (rule.value instanceof Array) {
4357
4374
  if (rule.operator.toString().indexOf('between') > -1) {
4375
+ let ruleCondition = sqlLocale ? ' ' + this.l10n.getConstant('AND').toUpperCase() + ' ' : ' ' + 'AND' + ' ';
4358
4376
  if (rule.type === 'date' && !this.isDateFunction(rule.value[0])) {
4359
- valueStr += '"' + rule.value[0] + '" AND "' + rule.value[1] + '"';
4377
+ valueStr += '"' + rule.value[0] + '"' + ruleCondition + '"' + rule.value[1] + '"';
4360
4378
  }
4361
4379
  else {
4362
- valueStr += rule.value[0] + ' AND ' + rule.value[1];
4380
+ valueStr += rule.value[0] + ruleCondition + rule.value[1];
4363
4381
  }
4364
4382
  }
4365
4383
  else {
@@ -4403,7 +4421,7 @@ let QueryBuilder = class QueryBuilder extends Component {
4403
4421
  rule.field = '"' + rule.field + '"';
4404
4422
  }
4405
4423
  }
4406
- queryStr += rule.field + ' ' + this.operators[rule.operator];
4424
+ queryStr += rule.field + ' ' + ruleOpertor;
4407
4425
  }
4408
4426
  else {
4409
4427
  if (enableEscape) {
@@ -4414,7 +4432,7 @@ let QueryBuilder = class QueryBuilder extends Component {
4414
4432
  rule.field = '"' + rule.field + '"';
4415
4433
  }
4416
4434
  }
4417
- queryStr += rule.field + ' ' + this.operators[rule.operator] + ' ' + valueStr;
4435
+ queryStr += rule.field + ' ' + ruleOpertor + ' ' + valueStr;
4418
4436
  }
4419
4437
  if (rule.condition && rule.condition !== '') {
4420
4438
  condition = rule.condition;
@@ -4424,7 +4442,8 @@ let QueryBuilder = class QueryBuilder extends Component {
4424
4442
  if (condition === '') {
4425
4443
  condition = rules.rules[j].condition;
4426
4444
  }
4427
- queryStr += ' ' + condition.toUpperCase() + ' ';
4445
+ condition = sqlLocale ? this.l10n.getConstant(condition.toUpperCase()).toUpperCase() : condition.toUpperCase();
4446
+ queryStr += ' ' + condition + ' ';
4428
4447
  }
4429
4448
  }
4430
4449
  if (!isRoot) {
@@ -4439,24 +4458,26 @@ let QueryBuilder = class QueryBuilder extends Component {
4439
4458
  * Sets the rules from the sql query.
4440
4459
  *
4441
4460
  * @param {string} sqlString - 'sql String' to be passed to set the rule.
4461
+ * @param {boolean} sqlLocale - Set `true` if Localization for Sql query.
4442
4462
  * @returns {void}
4443
4463
  */
4444
- setRulesFromSql(sqlString) {
4464
+ setRulesFromSql(sqlString, sqlLocale) {
4445
4465
  sqlString = sqlString.replace(/`/g, '');
4446
- const ruleModel = this.getRulesFromSql(sqlString);
4466
+ const ruleModel = this.getRulesFromSql(sqlString, sqlLocale);
4447
4467
  this.setRules({ condition: ruleModel.condition, not: ruleModel.not, rules: ruleModel.rules });
4448
4468
  }
4449
4469
  /**
4450
4470
  * Get the rules from SQL query.
4451
4471
  *
4452
4472
  * @param {string} sqlString - 'sql String' to be passed to get the rule.
4473
+ * @param {boolean} sqlLocale - Set `true` if Localization for Sql query.
4453
4474
  * @returns {object} - Rules from SQL query
4454
4475
  */
4455
- getRulesFromSql(sqlString) {
4476
+ getRulesFromSql(sqlString, sqlLocale) {
4456
4477
  this.parser = [];
4457
- this.sqlParser(sqlString);
4478
+ this.sqlParser(sqlString, sqlLocale);
4458
4479
  this.rule = { condition: 'and', not: false, rules: [] };
4459
- const rule = this.processParser(this.parser, this.rule, [0]);
4480
+ const rule = this.processParser(this.parser, this.rule, [0], sqlLocale);
4460
4481
  if (this.enableNotCondition) {
4461
4482
  return { condition: rule.condition, not: rule.not, rules: rule.rules };
4462
4483
  }
@@ -4469,28 +4490,45 @@ let QueryBuilder = class QueryBuilder extends Component {
4469
4490
  *
4470
4491
  * @param {RuleModel} rule - 'rule' to be passed to get the sql.
4471
4492
  * @param {boolean} allowEscape - Set `true` if it exclude the escape character.
4493
+ * @param {boolean} sqlLocale - Set `true` if Localization for Sql query.
4472
4494
  * @returns {object} - Sql query from rules.
4473
4495
  */
4474
- getSqlFromRules(rule, allowEscape) {
4496
+ getSqlFromRules(rule, allowEscape, sqlLocale) {
4475
4497
  if (!rule) {
4476
4498
  rule = this.getValidRules();
4477
4499
  }
4478
4500
  rule = this.getRuleCollection(rule, false);
4479
- return this.getSqlString(this.getValidRules(rule), allowEscape).replace(/"/g, '\'');
4501
+ return this.getSqlString(this.getValidRules(rule), allowEscape, null, sqlLocale).replace(/"/g, '\'');
4480
4502
  }
4481
- sqlParser(sqlString) {
4503
+ sqlParser(sqlString, sqlLocale) {
4482
4504
  let st = 0;
4483
4505
  let str;
4484
4506
  do {
4485
4507
  str = sqlString.slice(st);
4486
- st += this.parseSqlStrings(str);
4508
+ st += this.parseSqlStrings(str, sqlLocale);
4487
4509
  } while (str !== '');
4488
4510
  return this.parser;
4489
4511
  }
4490
- parseSqlStrings(sqlString) {
4512
+ parseSqlStrings(sqlString, sqlLocale) {
4491
4513
  const operators = ['=', '!=', '<=', '>=', '<', '>'];
4492
- const conditions = ['AND', 'OR', 'NOT'];
4493
- const subOp = ['IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'BETWEEN', 'NOT BETWEEN', 'IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY'];
4514
+ let conditions;
4515
+ if (sqlLocale) {
4516
+ conditions = [this.l10n.getConstant('AND').toUpperCase(), this.l10n.getConstant('OR').toUpperCase(), this.l10n.getConstant('NOT').toUpperCase()];
4517
+ }
4518
+ else {
4519
+ conditions = ['AND', 'OR', 'NOT'];
4520
+ }
4521
+ let subOp;
4522
+ if (sqlLocale) {
4523
+ subOp = [this.l10n.getConstant('In').toUpperCase(), this.l10n.getConstant('NotIn').toUpperCase(),
4524
+ this.l10n.getConstant('Like').toUpperCase(), this.l10n.getConstant('NotLike').toUpperCase(),
4525
+ this.l10n.getConstant('Between').toUpperCase(), this.l10n.getConstant('NotBetween').toUpperCase(),
4526
+ this.l10n.getConstant('IsNull').toUpperCase(), this.l10n.getConstant('IsNotNull').toUpperCase(),
4527
+ this.l10n.getConstant('IsEmpty').toUpperCase(), this.l10n.getConstant('IsNotEmpty').toUpperCase()];
4528
+ }
4529
+ else {
4530
+ subOp = ['IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'BETWEEN', 'NOT BETWEEN', 'IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY'];
4531
+ }
4494
4532
  let regexStr;
4495
4533
  let regex;
4496
4534
  let matchValue;
@@ -4557,7 +4595,7 @@ let QueryBuilder = class QueryBuilder extends Component {
4557
4595
  this.parser.push(['Literal', matchValue]);
4558
4596
  return matchValue.length + 2;
4559
4597
  }
4560
- if (this.checkNumberLiteral(sqlString)) {
4598
+ if (this.checkNumberLiteral(sqlString, sqlLocale)) {
4561
4599
  matchValue = /^[0-9]+(\.[0-9]+)?/.exec(sqlString)[0];
4562
4600
  this.parser.push(['Literal', matchValue]);
4563
4601
  return matchValue.length;
@@ -4601,7 +4639,7 @@ let QueryBuilder = class QueryBuilder extends Component {
4601
4639
  }
4602
4640
  return false;
4603
4641
  }
4604
- checkNumberLiteral(sqlString) {
4642
+ checkNumberLiteral(sqlString, sqlLocale) {
4605
4643
  const lastParser = this.parser[this.parser.length - 1];
4606
4644
  if (!lastParser) {
4607
4645
  return true;
@@ -4613,19 +4651,38 @@ let QueryBuilder = class QueryBuilder extends Component {
4613
4651
  if (lastParser[0] === 'Left' && (secParser && secParser[0] === 'Conditions')) {
4614
4652
  return true;
4615
4653
  }
4616
- if (lastParser[0] === 'Conditions' && (betweenParser && betweenParser[1].indexOf('between') < 0)) {
4654
+ let betweenOperator = sqlLocale ? this.l10n.getConstant('Between').toLowerCase() : 'between';
4655
+ if (lastParser[0] === 'Conditions' && (betweenParser && betweenParser[1].indexOf(betweenOperator) < 0)) {
4617
4656
  return true;
4618
4657
  }
4619
4658
  }
4620
4659
  }
4621
4660
  return false;
4622
4661
  }
4623
- getOperator(value, operator) {
4662
+ getOperator(value, operator, sqlLocale) {
4624
4663
  const operators = {
4625
4664
  '=': 'equal', '!=': 'notequal', '<': 'lessthan', '>': 'greaterthan', '<=': 'lessthanorequal',
4626
4665
  '>=': 'greaterthanorequal', 'in': 'in', 'not in': 'notin', 'between': 'between', 'not between': 'notbetween',
4627
4666
  'is empty': 'isempty', 'is null': 'isnull', 'is not null': 'isnotnull', 'is not empty': 'isnotempty'
4628
4667
  };
4668
+ if (sqlLocale) {
4669
+ let localeOperator = Object.keys(this.sqlOperators);
4670
+ for (let i = 0; i < localeOperator.length; i++) {
4671
+ if (this.sqlOperators[localeOperator[i]] === operator.toUpperCase()) {
4672
+ if (value && value.indexOf('%') === 0 && value[value.length - 1] === '%') {
4673
+ return (localeOperator[i] === 'notcontains') ? 'notcontains' : 'contains';
4674
+ }
4675
+ else if (value && value.indexOf('%') !== 0 && value.indexOf('%') === value.length - 1) {
4676
+ return (localeOperator[i] === 'notstartswith') ? 'notstartswith' : 'startswith';
4677
+ }
4678
+ else if (value && value.indexOf('%') === 0 && value.indexOf('%') !== value.length - 1) {
4679
+ return (localeOperator[i] === 'notendswith') ? 'notendswith' : 'endswith';
4680
+ }
4681
+ return localeOperator[i];
4682
+ }
4683
+ }
4684
+ return null;
4685
+ }
4629
4686
  if (value) {
4630
4687
  if (value.indexOf('%') === 0 && value[value.length - 1] === '%') {
4631
4688
  return (operator === 'not like') ? 'notcontains' : 'contains';
@@ -4649,7 +4706,10 @@ let QueryBuilder = class QueryBuilder extends Component {
4649
4706
  }
4650
4707
  getTypeFromColumn(rules) {
4651
4708
  const columnData = this.getColumn(rules.field);
4652
- return columnData.type;
4709
+ if (!isNullOrUndefined(columnData)) {
4710
+ return columnData.type;
4711
+ }
4712
+ return null;
4653
4713
  }
4654
4714
  getLabelFromColumn(field) {
4655
4715
  let label = '';
@@ -4682,7 +4742,7 @@ let QueryBuilder = class QueryBuilder extends Component {
4682
4742
  }
4683
4743
  return this.getColumn(fieldName).label;
4684
4744
  }
4685
- processParser(parser, rules, levelColl) {
4745
+ processParser(parser, rules, levelColl, sqlLocale) {
4686
4746
  let j;
4687
4747
  let jLen;
4688
4748
  let rule;
@@ -4701,18 +4761,27 @@ let QueryBuilder = class QueryBuilder extends Component {
4701
4761
  rule = { label: parser[i][1], field: parser[i][1] };
4702
4762
  if (parser[i + 1][0] === 'SubOperators') {
4703
4763
  if (parser[i + 1][1].indexOf('null') > -1 || parser[i + 1][1].indexOf('empty') > -1) {
4704
- rule.operator = this.getOperator(' ', parser[i + 1][1]);
4764
+ rule.operator = this.getOperator(' ', parser[i + 1][1], sqlLocale);
4705
4765
  rule.value = null;
4706
4766
  rule.type = this.getTypeFromColumn(rule);
4707
4767
  }
4708
4768
  else {
4709
4769
  const oper = parser[i + 3][1] ? parser[i + 3][1].replace(/'/g, '') : parser[i + 3][1];
4710
- rule.operator = this.getOperator(oper, parser[i + 1][1]);
4770
+ rule.operator = this.getOperator(oper, parser[i + 1][1], sqlLocale);
4711
4771
  }
4712
4772
  operator = parser[i + 1][1];
4713
4773
  i++;
4714
4774
  j = i + 1;
4715
4775
  jLen = iLen;
4776
+ if (sqlLocale && rule.operator === 'contains' || rule.operator === 'startswith' || rule.operator === 'endswith') {
4777
+ operator = 'like';
4778
+ }
4779
+ else if (sqlLocale && rule.operator === 'notcontains' || rule.operator === 'notstartswith' || rule.operator === 'notendswith') {
4780
+ operator = 'not like';
4781
+ }
4782
+ else if (sqlLocale) {
4783
+ operator = rule.operator;
4784
+ }
4716
4785
  for (j = i + 1; j < jLen; j++) {
4717
4786
  if (operator.indexOf('between') < 0 && parser[j][0] === 'Left') {
4718
4787
  isLeftOpened = true;
@@ -4778,7 +4847,7 @@ let QueryBuilder = class QueryBuilder extends Component {
4778
4847
  }
4779
4848
  }
4780
4849
  else if (parser[i + 1][0] === 'Operators') {
4781
- rule.operator = this.getOperator(parser[i + 2][1], parser[i + 1][1]);
4850
+ rule.operator = this.getOperator(parser[i + 2][1], parser[i + 1][1], sqlLocale);
4782
4851
  if (parser[i + 2][0] === 'Number') {
4783
4852
  rule.type = 'number';
4784
4853
  rule.value = Number(parser[i + 2][1]);
@@ -4792,7 +4861,7 @@ let QueryBuilder = class QueryBuilder extends Component {
4792
4861
  rules.rules.push(rule);
4793
4862
  }
4794
4863
  else if (parser[i][0] === 'Left') {
4795
- if (!(parser[0][0] === 'Left') && parser[i - 1][1] === 'not') {
4864
+ if (!(parser[0][0] === 'Left') && (parser[i - 1][1] === 'not' || sqlLocale && this.l10n.getConstant('NOT').toLowerCase() === parser[i - 1][1])) {
4796
4865
  continue;
4797
4866
  }
4798
4867
  this.parser = parser.splice(i + 1, iLen - (i + 1));
@@ -4811,11 +4880,11 @@ let QueryBuilder = class QueryBuilder extends Component {
4811
4880
  }
4812
4881
  levelColl.push(grpCount);
4813
4882
  rules.rules.push(subRules);
4814
- subRules = this.processParser(this.parser, subRules, levelColl);
4883
+ subRules = this.processParser(this.parser, subRules, levelColl, sqlLocale);
4815
4884
  return rules;
4816
4885
  }
4817
4886
  else if (parser[i][0] === 'Conditions') {
4818
- if (parser[i][1] === 'not') {
4887
+ if (parser[i][1] === 'not' || (sqlLocale && this.l10n.getConstant('NOT').toLowerCase() === parser[i][1])) {
4819
4888
  rules.not = true;
4820
4889
  }
4821
4890
  else {
@@ -4830,7 +4899,7 @@ let QueryBuilder = class QueryBuilder extends Component {
4830
4899
  for (l = 0; l < lLen; l++) {
4831
4900
  rules = this.findGroupByIdx(levelColl[l], rules, l === 0);
4832
4901
  }
4833
- return this.processParser(this.parser, rules, levelColl);
4902
+ return this.processParser(this.parser, rules, levelColl, sqlLocale);
4834
4903
  }
4835
4904
  }
4836
4905
  return rules;