typesql-cli 0.8.21 → 0.8.23
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/describe-nested-query.js +6 -6
- package/describe-nested-query.js.map +1 -1
- package/mysql-query-analyzer/collect-constraints.d.ts +2 -2
- package/mysql-query-analyzer/collect-constraints.d.ts.map +1 -1
- package/mysql-query-analyzer/collect-constraints.js +7 -7
- package/mysql-query-analyzer/collect-constraints.js.map +1 -1
- package/mysql-query-analyzer/infer-column-nullability.js +29 -29
- package/mysql-query-analyzer/infer-column-nullability.js.map +1 -1
- package/mysql-query-analyzer/infer-param-nullability.d.ts +1 -1
- package/mysql-query-analyzer/infer-param-nullability.d.ts.map +1 -1
- package/mysql-query-analyzer/infer-param-nullability.js +7 -7
- package/mysql-query-analyzer/infer-param-nullability.js.map +1 -1
- package/mysql-query-analyzer/parse.d.ts +1 -2
- package/mysql-query-analyzer/parse.d.ts.map +1 -1
- package/mysql-query-analyzer/parse.js +12 -13
- package/mysql-query-analyzer/parse.js.map +1 -1
- package/mysql-query-analyzer/select-columns.d.ts +5 -5
- package/mysql-query-analyzer/select-columns.d.ts.map +1 -1
- package/mysql-query-analyzer/select-columns.js +41 -43
- package/mysql-query-analyzer/select-columns.js.map +1 -1
- package/mysql-query-analyzer/traverse.d.ts.map +1 -1
- package/mysql-query-analyzer/traverse.js +164 -155
- package/mysql-query-analyzer/traverse.js.map +1 -1
- package/mysql-query-analyzer/unify.js +2 -2
- package/mysql-query-analyzer/unify.js.map +1 -1
- package/mysql-query-analyzer/verify-multiple-result.js +2 -2
- package/mysql-query-analyzer/verify-multiple-result.js.map +1 -1
- package/package.json +2 -2
- package/sqlite-query-analyzer/code-generator.js +10 -4
- package/sqlite-query-analyzer/code-generator.js.map +1 -1
- package/sqlite-query-analyzer/query-executor.d.ts +4 -3
- package/sqlite-query-analyzer/query-executor.d.ts.map +1 -1
- package/sqlite-query-analyzer/query-executor.js +3 -0
- package/sqlite-query-analyzer/query-executor.js.map +1 -1
- package/sqlite-query-analyzer/traverse.d.ts.map +1 -1
- package/sqlite-query-analyzer/traverse.js +177 -105
- package/sqlite-query-analyzer/traverse.js.map +1 -1
- package/util.d.ts.map +1 -1
@@ -90,16 +90,16 @@ function traverseSelectStatement(selectStatement, traverseContext, namedParamete
|
|
90
90
|
}
|
91
91
|
return traverseResult;
|
92
92
|
}
|
93
|
-
throw Error('traverseSelectStatement - not supported: ' + selectStatement.
|
93
|
+
throw Error('traverseSelectStatement - not supported: ' + selectStatement.getText());
|
94
94
|
}
|
95
95
|
function traverseInsertStatement(insertStatement, traverseContext) {
|
96
96
|
var _a, _b;
|
97
97
|
const allParameters = [];
|
98
98
|
const paramsNullability = {};
|
99
99
|
let exprOrDefaultList = [];
|
100
|
-
const valuesContext = (_a = insertStatement.insertFromConstructor()) === null || _a === void 0 ? void 0 : _a.insertValues().valueList().
|
100
|
+
const valuesContext = (_a = insertStatement.insertFromConstructor()) === null || _a === void 0 ? void 0 : _a.insertValues().valueList().values_list();
|
101
101
|
if (valuesContext) {
|
102
|
-
exprOrDefaultList = valuesContext.map(valueContext => { var _a; return ((_a = valueContext.children) === null || _a === void 0 ? void 0 : _a.filter(valueContext => valueContext instanceof ts_mysql_parser_1.ExprIsContext || valueContext.
|
102
|
+
exprOrDefaultList = valuesContext.map(valueContext => { var _a; return ((_a = valueContext.children) === null || _a === void 0 ? void 0 : _a.filter(valueContext => valueContext instanceof ts_mysql_parser_1.ExprIsContext || valueContext.getText() == 'DEFAULT')) || []; });
|
103
103
|
}
|
104
104
|
const insertIntoTable = (0, collect_constraints_1.getInsertIntoTable)(insertStatement);
|
105
105
|
const fromColumns = traverseContext.dbSchema
|
@@ -127,7 +127,7 @@ function traverseInsertStatement(insertStatement, traverseContext) {
|
|
127
127
|
paramsNullability[param.type.id] = paramNullabilityExpr.every(n => n) && column.notNull;
|
128
128
|
});
|
129
129
|
traverseContext.constraints.push({
|
130
|
-
expression: expr.
|
130
|
+
expression: expr.getText(),
|
131
131
|
//TODO - CHANGING ORDER SHOULDN'T AFFECT THE TYPE INFERENCE
|
132
132
|
type1: exprType.kind == 'TypeOperator' ? exprType.types[0] : exprType,
|
133
133
|
type2: (0, collect_constraints_1.freshVar)(column.columnName, column.columnType.type)
|
@@ -137,9 +137,9 @@ function traverseInsertStatement(insertStatement, traverseContext) {
|
|
137
137
|
}
|
138
138
|
});
|
139
139
|
});
|
140
|
-
const updateList = ((_b = insertStatement.insertUpdateList()) === null || _b === void 0 ? void 0 : _b.updateList().
|
140
|
+
const updateList = ((_b = insertStatement.insertUpdateList()) === null || _b === void 0 ? void 0 : _b.updateList().updateElement_list()) || [];
|
141
141
|
updateList.forEach(updateElement => {
|
142
|
-
const columnName = updateElement.columnRef().
|
142
|
+
const columnName = updateElement.columnRef().getText();
|
143
143
|
const field = (0, select_columns_1.splitName)(columnName);
|
144
144
|
const expr = updateElement.expr();
|
145
145
|
if (expr) {
|
@@ -150,7 +150,7 @@ function traverseInsertStatement(insertStatement, traverseContext) {
|
|
150
150
|
paramsNullability[param.type.id] = column.notNull;
|
151
151
|
});
|
152
152
|
traverseContext.constraints.push({
|
153
|
-
expression: expr.
|
153
|
+
expression: expr.getText(),
|
154
154
|
type1: exprType,
|
155
155
|
type2: (0, collect_constraints_1.freshVar)(column.columnName, column.columnType.type)
|
156
156
|
});
|
@@ -167,7 +167,7 @@ function traverseInsertStatement(insertStatement, traverseContext) {
|
|
167
167
|
paramsNullability[type.type.id] = column.notNull;
|
168
168
|
}
|
169
169
|
traverseContext.constraints.push({
|
170
|
-
expression: insertQueryExpression.
|
170
|
+
expression: insertQueryExpression.getText(),
|
171
171
|
type1: type.type,
|
172
172
|
type2: (0, collect_constraints_1.freshVar)(column.columnName, column.columnType.type)
|
173
173
|
});
|
@@ -198,7 +198,7 @@ function traverseInsertStatement(insertStatement, traverseContext) {
|
|
198
198
|
exports.traverseInsertStatement = traverseInsertStatement;
|
199
199
|
function traverseUpdateStatement(updateStatement, traverseContext, namedParamters) {
|
200
200
|
var _a;
|
201
|
-
const updateElement = updateStatement.updateList().
|
201
|
+
const updateElement = updateStatement.updateList().updateElement_list();
|
202
202
|
const withClause = updateStatement.withClause();
|
203
203
|
const withSchema = [];
|
204
204
|
if (withClause) {
|
@@ -216,11 +216,11 @@ function traverseUpdateStatement(updateStatement, traverseContext, namedParamter
|
|
216
216
|
if (expr) {
|
217
217
|
const paramBeforeExpr = traverseContext.parameters.length;
|
218
218
|
const result = traverseExpr(expr, traverseContext);
|
219
|
-
const columnName = updateElement.columnRef().
|
219
|
+
const columnName = updateElement.columnRef().getText();
|
220
220
|
const field = (0, select_columns_1.splitName)(columnName);
|
221
221
|
const column = (0, select_columns_1.findColumn)(field, updateColumns);
|
222
222
|
traverseContext.constraints.push({
|
223
|
-
expression: updateStatement.
|
223
|
+
expression: updateStatement.getText(),
|
224
224
|
type1: result,
|
225
225
|
type2: column.columnType //freshVar(column.columnName, )
|
226
226
|
});
|
@@ -289,7 +289,7 @@ function traverseDeleteStatement(deleteStatement, traverseContext) {
|
|
289
289
|
}
|
290
290
|
exports.traverseDeleteStatement = traverseDeleteStatement;
|
291
291
|
function getUpdateColumns(updateStatement, traverseContext) {
|
292
|
-
const tableReferences = updateStatement.tableReferenceList().
|
292
|
+
const tableReferences = updateStatement.tableReferenceList().tableReference_list();
|
293
293
|
const columns = traverseTableReferenceList(tableReferences, traverseContext, null);
|
294
294
|
return columns;
|
295
295
|
}
|
@@ -314,15 +314,24 @@ function traverseQueryExpression(queryExpression, traverseContext, cte, recursiv
|
|
314
314
|
if (withClause) {
|
315
315
|
traverseWithClause(withClause, traverseContext);
|
316
316
|
}
|
317
|
+
let exprResult;
|
317
318
|
const queryExpressionBody = queryExpression.queryExpressionBody();
|
318
319
|
if (queryExpressionBody) {
|
319
|
-
|
320
|
+
exprResult = traverseQueryExpressionBody(queryExpressionBody, traverseContext, cte, recursiveNames);
|
320
321
|
}
|
321
322
|
const queryExpressionParens = queryExpression.queryExpressionParens();
|
322
323
|
if (queryExpressionParens) {
|
323
|
-
|
324
|
+
exprResult = traverseQueryExpressionParens(queryExpressionParens, traverseContext, cte, recursiveNames);
|
325
|
+
}
|
326
|
+
const orderByClause = queryExpression.orderClause();
|
327
|
+
if (orderByClause) {
|
328
|
+
if (orderByClause.getText().toLowerCase() !== 'orderby?') {
|
329
|
+
orderByClause.orderList().orderExpression_list().forEach(orderByExpr => {
|
330
|
+
traverseExpr(orderByExpr.expr(), Object.assign(Object.assign({}, traverseContext), { fromColumns: exprResult.fromColumns || [] }));
|
331
|
+
});
|
332
|
+
}
|
324
333
|
}
|
325
|
-
|
334
|
+
return exprResult;
|
326
335
|
}
|
327
336
|
function traverseQueryExpressionParens(queryExpressionParens, traverseContext, cte, recursiveNames) {
|
328
337
|
const queryExpression = queryExpressionParens.queryExpression();
|
@@ -443,10 +452,10 @@ function traverseQuerySpecification(querySpec, traverseContext) {
|
|
443
452
|
exports.traverseQuerySpecification = traverseQuerySpecification;
|
444
453
|
function traverseWithClause(withClause, traverseContext) {
|
445
454
|
//result1, result2
|
446
|
-
withClause.
|
455
|
+
withClause.commonTableExpression_list().forEach(commonTableExpression => {
|
447
456
|
var _a, _b;
|
448
|
-
const cte = commonTableExpression.identifier().
|
449
|
-
const recursiveNames = withClause.RECURSIVE_SYMBOL() ? ((_a = commonTableExpression.columnInternalRefList()) === null || _a === void 0 ? void 0 : _a.
|
457
|
+
const cte = commonTableExpression.identifier().getText();
|
458
|
+
const recursiveNames = withClause.RECURSIVE_SYMBOL() ? ((_a = commonTableExpression.columnInternalRefList()) === null || _a === void 0 ? void 0 : _a.columnInternalRef_list().map(t => t.getText())) || [] : undefined;
|
450
459
|
const subQuery = commonTableExpression.subquery();
|
451
460
|
traverseSubquery(subQuery, traverseContext, cte, recursiveNames); //recursive= true??
|
452
461
|
(_b = traverseContext.dynamicSqlInfo.with) === null || _b === void 0 ? void 0 : _b.push({
|
@@ -463,7 +472,7 @@ function traverseWithClause(withClause, traverseContext) {
|
|
463
472
|
exports.traverseWithClause = traverseWithClause;
|
464
473
|
function traverseFromClause(fromClause, traverseContext) {
|
465
474
|
var _a;
|
466
|
-
const tableReferenceList = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.
|
475
|
+
const tableReferenceList = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference_list();
|
467
476
|
const fromColumns = tableReferenceList ? traverseTableReferenceList(tableReferenceList, traverseContext, null) : [];
|
468
477
|
return fromColumns;
|
469
478
|
}
|
@@ -488,7 +497,7 @@ function traverseTableReferenceList(tableReferenceList, traverseContext, current
|
|
488
497
|
}
|
489
498
|
const allJoinedColumns = [];
|
490
499
|
let firstLeftJoinIndex = -1;
|
491
|
-
tab.
|
500
|
+
tab.joinedTable_list().forEach((joined, index) => {
|
492
501
|
var _a, _b;
|
493
502
|
if (((_a = joined.innerJoinType()) === null || _a === void 0 ? void 0 : _a.INNER_SYMBOL()) || ((_b = joined.innerJoinType()) === null || _b === void 0 ? void 0 : _b.JOIN_SYMBOL())) {
|
494
503
|
firstLeftJoinIndex = -1; //dont need to add notNull = false to joins
|
@@ -540,7 +549,7 @@ function traverseTableReferenceList(tableReferenceList, traverseContext, current
|
|
540
549
|
traverseExpr(onClause, Object.assign(Object.assign({}, traverseContext), { fromColumns: allJoinedColumns.flatMap(c => c).concat(result) }));
|
541
550
|
const columns = (0, select_columns_1.getExpressions)(onClause, ts_mysql_parser_1.SimpleExprColumnRefContext);
|
542
551
|
columns.forEach(columnRef => {
|
543
|
-
const fieldName = (0, select_columns_1.splitName)(columnRef.expr.
|
552
|
+
const fieldName = (0, select_columns_1.splitName)(columnRef.expr.getText());
|
544
553
|
if ((innerJoinFragment === null || innerJoinFragment === void 0 ? void 0 : innerJoinFragment.relation) != fieldName.prefix) {
|
545
554
|
innerJoinFragment.parentRelation = fieldName.prefix;
|
546
555
|
}
|
@@ -573,7 +582,7 @@ function traverseTableFactor(tableFactor, traverseContext, currentFragment) {
|
|
573
582
|
}
|
574
583
|
const derivadTable = tableFactor.derivedTable();
|
575
584
|
if (derivadTable) {
|
576
|
-
const tableAlias = (_a = derivadTable.tableAlias()) === null || _a === void 0 ? void 0 : _a.identifier().
|
585
|
+
const tableAlias = (_a = derivadTable.tableAlias()) === null || _a === void 0 ? void 0 : _a.identifier().getText();
|
577
586
|
if (currentFragment) {
|
578
587
|
currentFragment.relation = tableAlias;
|
579
588
|
}
|
@@ -605,7 +614,7 @@ function traverseTableFactor(tableFactor, traverseContext, currentFragment) {
|
|
605
614
|
function traverseTableReferenceListParens(ctx, traverseContext) {
|
606
615
|
const tableReferenceList = ctx.tableReferenceList();
|
607
616
|
if (tableReferenceList) {
|
608
|
-
return traverseTableReferenceList(tableReferenceList.
|
617
|
+
return traverseTableReferenceList(tableReferenceList.tableReference_list(), traverseContext, null);
|
609
618
|
}
|
610
619
|
const tableReferenceListParens = ctx.tableReferenceListParens();
|
611
620
|
if (tableReferenceListParens) {
|
@@ -615,8 +624,8 @@ function traverseTableReferenceListParens(ctx, traverseContext) {
|
|
615
624
|
}
|
616
625
|
function traverseSingleTable(singleTable, dbSchema, withSchema, currentFragment, withFragments) {
|
617
626
|
var _a;
|
618
|
-
const table = singleTable === null || singleTable === void 0 ? void 0 : singleTable.tableRef().
|
619
|
-
const tableAlias = (_a = singleTable === null || singleTable === void 0 ? void 0 : singleTable.tableAlias()) === null || _a === void 0 ? void 0 : _a.identifier().
|
627
|
+
const table = singleTable === null || singleTable === void 0 ? void 0 : singleTable.tableRef().getText();
|
628
|
+
const tableAlias = (_a = singleTable === null || singleTable === void 0 ? void 0 : singleTable.tableAlias()) === null || _a === void 0 ? void 0 : _a.identifier().getText();
|
620
629
|
const tableName = (0, select_columns_1.splitName)(table);
|
621
630
|
if (currentFragment) {
|
622
631
|
currentFragment.relation = tableAlias || tableName.name;
|
@@ -666,12 +675,12 @@ function traverseSelectItemList(selectItemList, traverseContext) {
|
|
666
675
|
}
|
667
676
|
});
|
668
677
|
}
|
669
|
-
selectItemList.
|
678
|
+
selectItemList.selectItem_list().forEach(selectItem => {
|
670
679
|
var _a;
|
671
680
|
const tableWild = selectItem.tableWild();
|
672
681
|
if (tableWild) {
|
673
682
|
if (tableWild.MULT_OPERATOR()) {
|
674
|
-
const itemName = (0, select_columns_1.splitName)(selectItem.
|
683
|
+
const itemName = (0, select_columns_1.splitName)(selectItem.getText());
|
675
684
|
const allColumns = selectAllColumns(itemName.prefix, traverseContext.fromColumns);
|
676
685
|
allColumns.forEach(col => {
|
677
686
|
const columnType = (0, collect_constraints_1.createColumnType)(col);
|
@@ -737,7 +746,7 @@ function traverseExpr(expr, traverseContext) {
|
|
737
746
|
});
|
738
747
|
const columnsRef = (0, select_columns_1.getExpressions)(expr, ts_mysql_parser_1.ColumnRefContext);
|
739
748
|
columnsRef.forEach(colRef => {
|
740
|
-
const fileName = (0, select_columns_1.splitName)(colRef.expr.
|
749
|
+
const fileName = (0, select_columns_1.splitName)(colRef.expr.getText());
|
741
750
|
currentFragment.fields.push({
|
742
751
|
field: fileName.name,
|
743
752
|
name: fileName.name,
|
@@ -753,7 +762,7 @@ function traverseExpr(expr, traverseContext) {
|
|
753
762
|
if (expr2) {
|
754
763
|
return traverseExpr(expr2, traverseContext);
|
755
764
|
}
|
756
|
-
return (0, collect_constraints_1.freshVar)(expr.
|
765
|
+
return (0, collect_constraints_1.freshVar)(expr.getText(), 'tinyint');
|
757
766
|
;
|
758
767
|
}
|
759
768
|
if (expr instanceof ts_mysql_parser_1.ExprAndContext || expr instanceof ts_mysql_parser_1.ExprXorContext || expr instanceof ts_mysql_parser_1.ExprOrContext) {
|
@@ -778,7 +787,7 @@ function traverseExpr(expr, traverseContext) {
|
|
778
787
|
});
|
779
788
|
const columnsRef = (0, select_columns_1.getExpressions)(andExpression.expr, ts_mysql_parser_1.ColumnRefContext);
|
780
789
|
columnsRef.forEach(colRef => {
|
781
|
-
const fileName = (0, select_columns_1.splitName)(colRef.expr.
|
790
|
+
const fileName = (0, select_columns_1.splitName)(colRef.expr.getText());
|
782
791
|
currentFragment.fields.push({
|
783
792
|
field: fileName.name,
|
784
793
|
name: fileName.name,
|
@@ -788,9 +797,9 @@ function traverseExpr(expr, traverseContext) {
|
|
788
797
|
traverseContext.dynamicSqlInfo.where.push(currentFragment);
|
789
798
|
}
|
790
799
|
});
|
791
|
-
return (0, collect_constraints_1.freshVar)(expr.
|
800
|
+
return (0, collect_constraints_1.freshVar)(expr.getText(), 'tinyint');
|
792
801
|
}
|
793
|
-
throw Error('traverseExpr - not supported: ' + expr.
|
802
|
+
throw Error('traverseExpr - not supported: ' + expr.getText());
|
794
803
|
}
|
795
804
|
function traverseBoolPri(boolPri, traverseContext) {
|
796
805
|
if (boolPri instanceof ts_mysql_parser_1.PrimaryExprPredicateContext) {
|
@@ -801,7 +810,7 @@ function traverseBoolPri(boolPri, traverseContext) {
|
|
801
810
|
if (boolPri instanceof ts_mysql_parser_1.PrimaryExprIsNullContext) {
|
802
811
|
const boolPri2 = boolPri.boolPri();
|
803
812
|
traverseBoolPri(boolPri2, traverseContext);
|
804
|
-
return (0, collect_constraints_1.freshVar)(boolPri.
|
813
|
+
return (0, collect_constraints_1.freshVar)(boolPri.getText(), 'tinyint');
|
805
814
|
}
|
806
815
|
if (boolPri instanceof ts_mysql_parser_1.PrimaryExprCompareContext) {
|
807
816
|
const compareLeft = boolPri.boolPri();
|
@@ -810,11 +819,11 @@ function traverseBoolPri(boolPri, traverseContext) {
|
|
810
819
|
const typeLeft = traverseBoolPri(compareLeft, traverseContext);
|
811
820
|
const typeRight = traversePredicate(compareRight, traverseContext);
|
812
821
|
traverseContext.constraints.push({
|
813
|
-
expression: boolPri.
|
822
|
+
expression: boolPri.getText(),
|
814
823
|
type1: typeLeft,
|
815
824
|
type2: typeRight
|
816
825
|
});
|
817
|
-
return (0, collect_constraints_1.freshVar)(boolPri.
|
826
|
+
return (0, collect_constraints_1.freshVar)(boolPri.getText(), 'tinyint');
|
818
827
|
}
|
819
828
|
if (boolPri instanceof ts_mysql_parser_1.PrimaryExprAllAnyContext) {
|
820
829
|
const compareLeft = boolPri.boolPri();
|
@@ -822,19 +831,19 @@ function traverseBoolPri(boolPri, traverseContext) {
|
|
822
831
|
const typeLeft = traverseBoolPri(compareLeft, traverseContext);
|
823
832
|
const subQueryResult = traverseSubquery(compareRight, traverseContext);
|
824
833
|
traverseContext.constraints.push({
|
825
|
-
expression: boolPri.
|
834
|
+
expression: boolPri.getText(),
|
826
835
|
type1: typeLeft,
|
827
836
|
type2: {
|
828
837
|
kind: 'TypeOperator',
|
829
838
|
types: subQueryResult.columns.map(t => t.type)
|
830
839
|
}
|
831
840
|
});
|
832
|
-
return (0, collect_constraints_1.freshVar)(boolPri.
|
841
|
+
return (0, collect_constraints_1.freshVar)(boolPri.getText(), 'tinyint');
|
833
842
|
}
|
834
843
|
throw Error('traverseExpr - not supported: ' + boolPri.constructor.name);
|
835
844
|
}
|
836
845
|
function traversePredicate(predicate, traverseContext) {
|
837
|
-
const bitExpr = predicate.bitExpr()
|
846
|
+
const bitExpr = predicate.bitExpr(0); //TODO - predicate length = 2? [1] == predicateOperations
|
838
847
|
const bitExprType = traverseBitExpr(bitExpr, traverseContext);
|
839
848
|
const predicateOperations = predicate.predicateOperations();
|
840
849
|
if (predicateOperations) {
|
@@ -842,7 +851,7 @@ function traversePredicate(predicate, traverseContext) {
|
|
842
851
|
if (bitExprType.kind == 'TypeOperator' && rightType.kind == 'TypeOperator') {
|
843
852
|
rightType.types.forEach((t, i) => {
|
844
853
|
traverseContext.constraints.push({
|
845
|
-
expression: predicateOperations.
|
854
|
+
expression: predicateOperations.getText(),
|
846
855
|
type1: t, // ? array of id+id
|
847
856
|
type2: bitExprType.types[i],
|
848
857
|
mostGeneralType: true
|
@@ -852,7 +861,7 @@ function traversePredicate(predicate, traverseContext) {
|
|
852
861
|
if (bitExprType.kind == 'TypeVar' && rightType.kind == 'TypeOperator') {
|
853
862
|
rightType.types.forEach((t, i) => {
|
854
863
|
traverseContext.constraints.push({
|
855
|
-
expression: predicateOperations.
|
864
|
+
expression: predicateOperations.getText(),
|
856
865
|
type1: bitExprType, // ? array of id+id
|
857
866
|
type2: Object.assign(Object.assign({}, t), { list: true }),
|
858
867
|
mostGeneralType: true
|
@@ -865,7 +874,7 @@ function traversePredicate(predicate, traverseContext) {
|
|
865
874
|
return bitExprType;
|
866
875
|
}
|
867
876
|
function traverseExprList(exprList, traverseContext) {
|
868
|
-
const listType = exprList.
|
877
|
+
const listType = exprList.expr_list().map(item => {
|
869
878
|
const exprType = traverseExpr(item, traverseContext);
|
870
879
|
return exprType;
|
871
880
|
});
|
@@ -880,17 +889,17 @@ function traverseBitExpr(bitExpr, traverseContext) {
|
|
880
889
|
if (simpleExpr) {
|
881
890
|
return traverseSimpleExpr(simpleExpr, Object.assign(Object.assign({}, traverseContext), { where: false }));
|
882
891
|
}
|
883
|
-
if (bitExpr.
|
884
|
-
const bitExprLeft = bitExpr.bitExpr()
|
892
|
+
if (bitExpr.bitExpr_list().length == 2) {
|
893
|
+
const bitExprLeft = bitExpr.bitExpr(0);
|
885
894
|
const typeLeftTemp = traverseBitExpr(bitExprLeft, traverseContext);
|
886
895
|
const typeLeft = typeLeftTemp.kind == 'TypeOperator' ? typeLeftTemp.types[0] : typeLeftTemp;
|
887
896
|
//const newTypeLeft = typeLeft.name == '?'? freshVar('?', 'bigint') : typeLeft;
|
888
|
-
const bitExprRight = bitExpr.bitExpr()
|
897
|
+
const bitExprRight = bitExpr.bitExpr(1);
|
889
898
|
const typeRightTemp = traverseBitExpr(bitExprRight, traverseContext);
|
890
899
|
//In the expression 'id + (value + 2) + ?' the '(value+2)' is treated as a SimpleExprListContext and return a TypeOperator
|
891
900
|
const typeRight = typeRightTemp.kind == 'TypeOperator' ? typeRightTemp.types[0] : typeRightTemp;
|
892
901
|
//const newTypeRight = typeRight.name == '?'? freshVar('?', 'bigint') : typeRight;
|
893
|
-
const bitExprType = (0, collect_constraints_1.freshVar)(bitExpr.
|
902
|
+
const bitExprType = (0, collect_constraints_1.freshVar)(bitExpr.getText(), '?');
|
894
903
|
if (typeLeftTemp.kind == 'TypeVar' && typeRightTemp.kind == 'TypeVar' && typeLeftTemp.table == typeRightTemp.table) {
|
895
904
|
bitExprType.table = typeLeftTemp.table;
|
896
905
|
}
|
@@ -917,14 +926,14 @@ function traverseBitExpr(bitExpr, traverseContext) {
|
|
917
926
|
// coercionType: 'Sum'
|
918
927
|
// })
|
919
928
|
traverseContext.constraints.push({
|
920
|
-
expression: bitExprLeft.
|
929
|
+
expression: bitExprLeft.getText(),
|
921
930
|
type1: bitExprType,
|
922
931
|
type2: typeLeft,
|
923
932
|
mostGeneralType: true,
|
924
933
|
coercionType: 'Sum'
|
925
934
|
});
|
926
935
|
traverseContext.constraints.push({
|
927
|
-
expression: bitExprRight.
|
936
|
+
expression: bitExprRight.getText(),
|
928
937
|
type1: bitExprType,
|
929
938
|
type2: typeRight,
|
930
939
|
mostGeneralType: true,
|
@@ -941,12 +950,12 @@ function traverseBitExpr(bitExpr, traverseContext) {
|
|
941
950
|
return bitExprType;
|
942
951
|
}
|
943
952
|
if (bitExpr.INTERVAL_SYMBOL()) {
|
944
|
-
const bitExpr2 = bitExpr.bitExpr()
|
953
|
+
const bitExpr2 = bitExpr.bitExpr(0);
|
945
954
|
const leftType = traverseBitExpr(bitExpr2, traverseContext);
|
946
955
|
const expr = bitExpr.expr(); //expr interval
|
947
956
|
traverseExpr(expr, traverseContext);
|
948
957
|
traverseContext.constraints.push({
|
949
|
-
expression: bitExpr.
|
958
|
+
expression: bitExpr.getText(),
|
950
959
|
type1: leftType,
|
951
960
|
type2: (0, collect_constraints_1.freshVar)('datetime', 'datetime')
|
952
961
|
});
|
@@ -968,10 +977,10 @@ function traversePredicateOperations(predicateOperations, parentType, traverseCo
|
|
968
977
|
}
|
969
978
|
}
|
970
979
|
if (predicateOperations instanceof ts_mysql_parser_1.PredicateExprLikeContext) {
|
971
|
-
const simpleExpr = predicateOperations.simpleExpr()
|
980
|
+
const simpleExpr = predicateOperations.simpleExpr(0);
|
972
981
|
const rightType = traverseSimpleExpr(simpleExpr, Object.assign(Object.assign({}, traverseContext), { where: false }));
|
973
982
|
traverseContext.constraints.push({
|
974
|
-
expression: simpleExpr.
|
983
|
+
expression: simpleExpr.getText(),
|
975
984
|
type1: parentType,
|
976
985
|
type2: rightType
|
977
986
|
});
|
@@ -983,17 +992,17 @@ function traversePredicateOperations(predicateOperations, parentType, traverseCo
|
|
983
992
|
const bitExprType = traverseBitExpr(bitExpr, traverseContext);
|
984
993
|
const predicateType = traversePredicate(predicate, traverseContext);
|
985
994
|
traverseContext.constraints.push({
|
986
|
-
expression: predicateOperations.
|
995
|
+
expression: predicateOperations.getText(),
|
987
996
|
type1: parentType,
|
988
997
|
type2: bitExprType
|
989
998
|
});
|
990
999
|
traverseContext.constraints.push({
|
991
|
-
expression: predicateOperations.
|
1000
|
+
expression: predicateOperations.getText(),
|
992
1001
|
type1: parentType,
|
993
1002
|
type2: predicateType
|
994
1003
|
});
|
995
1004
|
traverseContext.constraints.push({
|
996
|
-
expression: predicateOperations.
|
1005
|
+
expression: predicateOperations.getText(),
|
997
1006
|
type1: bitExprType,
|
998
1007
|
type2: predicateType
|
999
1008
|
});
|
@@ -1004,11 +1013,11 @@ function traversePredicateOperations(predicateOperations, parentType, traverseCo
|
|
1004
1013
|
function traverseSimpleExpr(simpleExpr, traverseContext) {
|
1005
1014
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
1006
1015
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprColumnRefContext) {
|
1007
|
-
const fieldName = (0, select_columns_1.splitName)(simpleExpr.
|
1016
|
+
const fieldName = (0, select_columns_1.splitName)(simpleExpr.getText());
|
1008
1017
|
const column = (0, select_columns_1.findColumn)(fieldName, traverseContext.fromColumns);
|
1009
1018
|
const typeVar = (0, collect_constraints_1.freshVar)(column.columnName, column.columnType.type, column.tableAlias || column.table);
|
1010
1019
|
traverseContext.constraints.push({
|
1011
|
-
expression: simpleExpr.
|
1020
|
+
expression: simpleExpr.getText(),
|
1012
1021
|
type1: typeVar,
|
1013
1022
|
type2: column.columnType,
|
1014
1023
|
mostGeneralType: true
|
@@ -1033,19 +1042,19 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1033
1042
|
type: param,
|
1034
1043
|
notNull: false,
|
1035
1044
|
table: param.table || '',
|
1036
|
-
paramIndex: simpleExpr.start.
|
1045
|
+
paramIndex: simpleExpr.start.start
|
1037
1046
|
});
|
1038
1047
|
return param;
|
1039
1048
|
}
|
1040
1049
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprLiteralContext) {
|
1041
1050
|
const literal = simpleExpr.literal();
|
1042
1051
|
if (literal.textLiteral()) {
|
1043
|
-
const text = ((_a = literal.textLiteral()) === null || _a === void 0 ? void 0 : _a.
|
1052
|
+
const text = ((_a = literal.textLiteral()) === null || _a === void 0 ? void 0 : _a.getText().slice(1, -1)) || ''; //remove quotes
|
1044
1053
|
return (0, collect_constraints_1.freshVar)(text, 'varchar');
|
1045
1054
|
}
|
1046
1055
|
const numLiteral = literal.numLiteral();
|
1047
1056
|
if (numLiteral) {
|
1048
|
-
return (0, collect_constraints_1.freshVar)(numLiteral.
|
1057
|
+
return (0, collect_constraints_1.freshVar)(numLiteral.getText(), 'int');
|
1049
1058
|
// addNamedNode(simpleExpr, freshVar('bigint', 'bigint'), namedNodes)
|
1050
1059
|
// if(numLiteral.INT_NUMBER()) {
|
1051
1060
|
// const typeInt = freshVar('int', 'int');
|
@@ -1063,18 +1072,18 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1063
1072
|
}
|
1064
1073
|
const boolLiteral = literal.boolLiteral();
|
1065
1074
|
if (boolLiteral) {
|
1066
|
-
return (0, collect_constraints_1.freshVar)(boolLiteral.
|
1075
|
+
return (0, collect_constraints_1.freshVar)(boolLiteral.getText(), 'bit');
|
1067
1076
|
}
|
1068
1077
|
const nullLiteral = literal.nullLiteral();
|
1069
1078
|
if (nullLiteral) {
|
1070
|
-
return (0, collect_constraints_1.freshVar)(nullLiteral.
|
1079
|
+
return (0, collect_constraints_1.freshVar)(nullLiteral.getText(), '?');
|
1071
1080
|
}
|
1072
|
-
throw Error('literal not supported:' + literal.
|
1081
|
+
throw Error('literal not supported:' + literal.getText());
|
1073
1082
|
//...
|
1074
1083
|
}
|
1075
1084
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprListContext) {
|
1076
1085
|
const exprList = simpleExpr.exprList();
|
1077
|
-
const listType = exprList.
|
1086
|
+
const listType = exprList.expr_list().map(item => {
|
1078
1087
|
const exprType = traverseExpr(item, Object.assign(Object.assign({}, traverseContext), { where: false }));
|
1079
1088
|
return exprType;
|
1080
1089
|
});
|
@@ -1094,21 +1103,21 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1094
1103
|
}
|
1095
1104
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprCaseContext) {
|
1096
1105
|
//case when expr then expr else expr
|
1097
|
-
const caseType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1098
|
-
simpleExpr.
|
1106
|
+
const caseType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
|
1107
|
+
simpleExpr.whenExpression_list().forEach(whenExprCont => {
|
1099
1108
|
const whenExpr = whenExprCont.expr();
|
1100
1109
|
const whenType = traverseExpr(whenExpr, traverseContext);
|
1101
1110
|
traverseContext.constraints.push({
|
1102
|
-
expression: whenExpr.
|
1111
|
+
expression: whenExpr.getText(),
|
1103
1112
|
type1: whenType.kind == 'TypeOperator' ? whenType.types[0] : whenType,
|
1104
1113
|
type2: (0, collect_constraints_1.freshVar)('tinyint', 'tinyint') //bool
|
1105
1114
|
});
|
1106
1115
|
});
|
1107
|
-
const thenTypes = simpleExpr.
|
1116
|
+
const thenTypes = simpleExpr.thenExpression_list().map(thenExprCtx => {
|
1108
1117
|
const thenExpr = thenExprCtx.expr();
|
1109
1118
|
const thenType = traverseExpr(thenExpr, traverseContext);
|
1110
1119
|
traverseContext.constraints.push({
|
1111
|
-
expression: thenExprCtx.
|
1120
|
+
expression: thenExprCtx.getText(),
|
1112
1121
|
type1: caseType,
|
1113
1122
|
type2: thenType.kind == 'TypeOperator' ? thenType.types[0] : thenType,
|
1114
1123
|
mostGeneralType: true,
|
@@ -1119,7 +1128,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1119
1128
|
if (elseExpr) {
|
1120
1129
|
const elseType = traverseExpr(elseExpr, traverseContext);
|
1121
1130
|
traverseContext.constraints.push({
|
1122
|
-
expression: (_c = simpleExpr.elseExpression()) === null || _c === void 0 ? void 0 : _c.
|
1131
|
+
expression: (_c = simpleExpr.elseExpression()) === null || _c === void 0 ? void 0 : _c.getText(),
|
1123
1132
|
type1: caseType,
|
1124
1133
|
type2: elseType.kind == 'TypeOperator' ? elseType.types[0] : elseType,
|
1125
1134
|
mostGeneralType: true
|
@@ -1127,7 +1136,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1127
1136
|
thenTypes.forEach(thenType => {
|
1128
1137
|
var _a;
|
1129
1138
|
traverseContext.constraints.push({
|
1130
|
-
expression: (_a = simpleExpr.elseExpression()) === null || _a === void 0 ? void 0 : _a.
|
1139
|
+
expression: (_a = simpleExpr.elseExpression()) === null || _a === void 0 ? void 0 : _a.getText(),
|
1131
1140
|
type1: thenType,
|
1132
1141
|
type2: elseType.kind == 'TypeOperator' ? elseType.types[0] : elseType,
|
1133
1142
|
mostGeneralType: true
|
@@ -1137,13 +1146,13 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1137
1146
|
return caseType;
|
1138
1147
|
}
|
1139
1148
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprIntervalContext) {
|
1140
|
-
const exprList = simpleExpr.
|
1149
|
+
const exprList = simpleExpr.expr_list();
|
1141
1150
|
const exprLeft = exprList[0];
|
1142
1151
|
const exprRight = exprList[1];
|
1143
1152
|
const typeLeft = traverseExpr(exprLeft, traverseContext);
|
1144
1153
|
const typeRight = traverseExpr(exprRight, traverseContext);
|
1145
1154
|
traverseContext.constraints.push({
|
1146
|
-
expression: exprLeft.
|
1155
|
+
expression: exprLeft.getText(),
|
1147
1156
|
type1: typeLeft,
|
1148
1157
|
type2: (0, collect_constraints_1.freshVar)('bigint', 'bigint')
|
1149
1158
|
});
|
@@ -1151,7 +1160,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1151
1160
|
typeRight.type = 'datetime';
|
1152
1161
|
}
|
1153
1162
|
traverseContext.constraints.push({
|
1154
|
-
expression: exprRight.
|
1163
|
+
expression: exprRight.getText(),
|
1155
1164
|
type1: typeRight,
|
1156
1165
|
type2: (0, collect_constraints_1.freshVar)('datetime', 'datetime')
|
1157
1166
|
});
|
@@ -1160,12 +1169,12 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1160
1169
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprSumContext) {
|
1161
1170
|
const sumExpr = simpleExpr.sumExpr();
|
1162
1171
|
if (sumExpr.MAX_SYMBOL() || sumExpr.MIN_SYMBOL()) {
|
1163
|
-
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1172
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
|
1164
1173
|
const inSumExpr = (_d = sumExpr.inSumExpr()) === null || _d === void 0 ? void 0 : _d.expr();
|
1165
1174
|
if (inSumExpr) {
|
1166
1175
|
const inSumExprType = traverseExpr(inSumExpr, traverseContext);
|
1167
1176
|
traverseContext.constraints.push({
|
1168
|
-
expression: simpleExpr.
|
1177
|
+
expression: simpleExpr.getText(),
|
1169
1178
|
type1: functionType,
|
1170
1179
|
type2: inSumExprType,
|
1171
1180
|
mostGeneralType: true
|
@@ -1174,7 +1183,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1174
1183
|
return functionType;
|
1175
1184
|
}
|
1176
1185
|
if (sumExpr.COUNT_SYMBOL()) {
|
1177
|
-
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1186
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'bigint');
|
1178
1187
|
const inSumExpr = (_e = sumExpr.inSumExpr()) === null || _e === void 0 ? void 0 : _e.expr();
|
1179
1188
|
if (inSumExpr) {
|
1180
1189
|
traverseExpr(inSumExpr, traverseContext);
|
@@ -1182,12 +1191,12 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1182
1191
|
return functionType;
|
1183
1192
|
}
|
1184
1193
|
if (sumExpr.SUM_SYMBOL() || sumExpr.AVG_SYMBOL()) {
|
1185
|
-
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1194
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
|
1186
1195
|
const inSumExpr = (_f = sumExpr.inSumExpr()) === null || _f === void 0 ? void 0 : _f.expr();
|
1187
1196
|
if (inSumExpr) {
|
1188
1197
|
const inSumExprType = traverseExpr(inSumExpr, traverseContext);
|
1189
1198
|
traverseContext.constraints.push({
|
1190
|
-
expression: simpleExpr.
|
1199
|
+
expression: simpleExpr.getText(),
|
1191
1200
|
type1: functionType,
|
1192
1201
|
type2: inSumExprType,
|
1193
1202
|
mostGeneralType: true,
|
@@ -1202,7 +1211,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1202
1211
|
if (sumExpr.GROUP_CONCAT_SYMBOL()) {
|
1203
1212
|
const exprList = sumExpr.exprList();
|
1204
1213
|
if (exprList) {
|
1205
|
-
exprList.
|
1214
|
+
exprList.expr_list().map(item => {
|
1206
1215
|
const exprType = traverseExpr(item, traverseContext);
|
1207
1216
|
return exprType;
|
1208
1217
|
});
|
@@ -1211,7 +1220,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1211
1220
|
in which case the result type is VARCHAR or VARBINARY.
|
1212
1221
|
*/
|
1213
1222
|
//TODO - Infer TEXT/BLOB or VARCHAR/VARBINARY
|
1214
|
-
return (0, collect_constraints_1.freshVar)(sumExpr.
|
1223
|
+
return (0, collect_constraints_1.freshVar)(sumExpr.getText(), 'varchar');
|
1215
1224
|
;
|
1216
1225
|
}
|
1217
1226
|
}
|
@@ -1220,20 +1229,20 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1220
1229
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprRuntimeFunctionContext) {
|
1221
1230
|
const runtimeFunctionCall = simpleExpr.runtimeFunctionCall();
|
1222
1231
|
if (runtimeFunctionCall.NOW_SYMBOL()) {
|
1223
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1232
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'datetime');
|
1224
1233
|
}
|
1225
1234
|
if (runtimeFunctionCall.CURDATE_SYMBOL()) {
|
1226
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1235
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date');
|
1227
1236
|
}
|
1228
1237
|
if (runtimeFunctionCall.CURTIME_SYMBOL()) {
|
1229
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1238
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'time');
|
1230
1239
|
}
|
1231
1240
|
if (runtimeFunctionCall.REPLACE_SYMBOL()) {
|
1232
|
-
const exprList = runtimeFunctionCall.
|
1241
|
+
const exprList = runtimeFunctionCall.expr_list();
|
1233
1242
|
exprList.forEach(expr => {
|
1234
1243
|
const exprType = traverseExpr(expr, traverseContext);
|
1235
1244
|
traverseContext.constraints.push({
|
1236
|
-
expression: expr.
|
1245
|
+
expression: expr.getText(),
|
1237
1246
|
type1: exprType,
|
1238
1247
|
type2: (0, collect_constraints_1.freshVar)('varchar', 'varchar')
|
1239
1248
|
});
|
@@ -1251,13 +1260,13 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1251
1260
|
paramType.type = 'date';
|
1252
1261
|
}
|
1253
1262
|
traverseContext.constraints.push({
|
1254
|
-
expression: expr.
|
1263
|
+
expression: expr.getText(),
|
1255
1264
|
type1: paramType,
|
1256
|
-
type2: (0, collect_constraints_1.freshVar)(simpleExpr.
|
1265
|
+
type2: (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date')
|
1257
1266
|
});
|
1258
1267
|
}
|
1259
1268
|
const returnType = runtimeFunctionCall.YEAR_SYMBOL() ? 'year' : 'tinyint';
|
1260
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1269
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), returnType);
|
1261
1270
|
}
|
1262
1271
|
if (runtimeFunctionCall.DATE_SYMBOL()) {
|
1263
1272
|
const expr = (_h = runtimeFunctionCall.exprWithParentheses()) === null || _h === void 0 ? void 0 : _h.expr();
|
@@ -1270,12 +1279,12 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1270
1279
|
paramType.type = 'date';
|
1271
1280
|
}
|
1272
1281
|
traverseContext.constraints.push({
|
1273
|
-
expression: expr.
|
1282
|
+
expression: expr.getText(),
|
1274
1283
|
type1: paramType,
|
1275
|
-
type2: (0, collect_constraints_1.freshVar)(simpleExpr.
|
1284
|
+
type2: (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date')
|
1276
1285
|
});
|
1277
1286
|
}
|
1278
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1287
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date');
|
1279
1288
|
}
|
1280
1289
|
if (runtimeFunctionCall.HOUR_SYMBOL() || runtimeFunctionCall.MINUTE_SYMBOL() || runtimeFunctionCall.SECOND_SYMBOL()) {
|
1281
1290
|
const expr = (_j = runtimeFunctionCall.exprWithParentheses()) === null || _j === void 0 ? void 0 : _j.expr();
|
@@ -1291,23 +1300,23 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1291
1300
|
paramType.type = 'datetime';
|
1292
1301
|
}
|
1293
1302
|
traverseContext.constraints.push({
|
1294
|
-
expression: expr.
|
1303
|
+
expression: expr.getText(),
|
1295
1304
|
type1: paramType,
|
1296
|
-
type2: (0, collect_constraints_1.freshVar)(simpleExpr.
|
1305
|
+
type2: (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'time')
|
1297
1306
|
});
|
1298
1307
|
}
|
1299
1308
|
//HOUR can return values greater than 23. Ex.: SELECT HOUR('272:59:59');
|
1300
1309
|
//https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_hour
|
1301
1310
|
const returnType = runtimeFunctionCall.HOUR_SYMBOL() ? 'int' : 'tinyint';
|
1302
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1311
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), returnType);
|
1303
1312
|
}
|
1304
1313
|
const trimFunction = runtimeFunctionCall.trimFunction();
|
1305
1314
|
if (trimFunction) {
|
1306
|
-
const exprList = trimFunction.
|
1315
|
+
const exprList = trimFunction.expr_list();
|
1307
1316
|
if (exprList.length == 1) {
|
1308
1317
|
const exprType = traverseExpr(exprList[0], traverseContext);
|
1309
1318
|
traverseContext.constraints.push({
|
1310
|
-
expression: exprList[0].
|
1319
|
+
expression: exprList[0].getText(),
|
1311
1320
|
type1: exprType,
|
1312
1321
|
type2: (0, collect_constraints_1.freshVar)('varchar', 'varchar')
|
1313
1322
|
});
|
@@ -1316,12 +1325,12 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1316
1325
|
const exprType = traverseExpr(exprList[0], traverseContext);
|
1317
1326
|
const expr2Type = traverseExpr(exprList[1], traverseContext);
|
1318
1327
|
traverseContext.constraints.push({
|
1319
|
-
expression: exprList[0].
|
1328
|
+
expression: exprList[0].getText(),
|
1320
1329
|
type1: exprType,
|
1321
1330
|
type2: (0, collect_constraints_1.freshVar)('varchar', 'varchar')
|
1322
1331
|
});
|
1323
1332
|
traverseContext.constraints.push({
|
1324
|
-
expression: exprList[1].
|
1333
|
+
expression: exprList[1].getText(),
|
1325
1334
|
type1: expr2Type,
|
1326
1335
|
type2: (0, collect_constraints_1.freshVar)('varchar', 'varchar')
|
1327
1336
|
});
|
@@ -1330,7 +1339,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1330
1339
|
}
|
1331
1340
|
const substringFunction = runtimeFunctionCall.substringFunction();
|
1332
1341
|
if (substringFunction) {
|
1333
|
-
const exprList = substringFunction.
|
1342
|
+
const exprList = substringFunction.expr_list();
|
1334
1343
|
const varcharParam = (0, collect_constraints_1.freshVar)('varchar', 'varchar');
|
1335
1344
|
const intParam = (0, collect_constraints_1.freshVar)('int', 'int');
|
1336
1345
|
const params = {
|
@@ -1346,27 +1355,27 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1346
1355
|
|| runtimeFunctionCall.DATE_SUB_SYMBOL()) {
|
1347
1356
|
//SELECT ADDDATE('2008-01-02', INTERVAL 31 DAY)
|
1348
1357
|
//SELECT ADDDATE('2008-01-02', 31)
|
1349
|
-
const expr1 = runtimeFunctionCall.expr()
|
1350
|
-
const expr2 = runtimeFunctionCall.expr()
|
1358
|
+
const expr1 = runtimeFunctionCall.expr(0);
|
1359
|
+
const expr2 = runtimeFunctionCall.expr(1);
|
1351
1360
|
const typeExpr1 = traverseExpr(expr1, traverseContext);
|
1352
1361
|
const typeExpr2 = traverseExpr(expr2, traverseContext);
|
1353
1362
|
if (typeExpr1.kind == 'TypeVar' && ((0, collect_constraints_1.isDateLiteral)(typeExpr1.name) || (0, collect_constraints_1.isDateTimeLiteral)(typeExpr1.name))) {
|
1354
1363
|
typeExpr1.type = 'datetime';
|
1355
1364
|
}
|
1356
1365
|
traverseContext.constraints.push({
|
1357
|
-
expression: expr1.
|
1366
|
+
expression: expr1.getText(),
|
1358
1367
|
type1: typeExpr1,
|
1359
1368
|
type2: (0, collect_constraints_1.freshVar)('datetime', 'datetime')
|
1360
1369
|
});
|
1361
1370
|
traverseContext.constraints.push({
|
1362
|
-
expression: expr2.
|
1371
|
+
expression: expr2.getText(),
|
1363
1372
|
type1: typeExpr2,
|
1364
1373
|
type2: (0, collect_constraints_1.freshVar)('bigint', 'bigint')
|
1365
1374
|
});
|
1366
1375
|
return (0, collect_constraints_1.freshVar)('datetime', 'datetime');
|
1367
1376
|
}
|
1368
1377
|
if (runtimeFunctionCall.COALESCE_SYMBOL()) {
|
1369
|
-
const exprList = (_k = runtimeFunctionCall.exprListWithParentheses()) === null || _k === void 0 ? void 0 : _k.exprList().
|
1378
|
+
const exprList = (_k = runtimeFunctionCall.exprListWithParentheses()) === null || _k === void 0 ? void 0 : _k.exprList().expr_list();
|
1370
1379
|
if (exprList) {
|
1371
1380
|
const paramType = (0, collect_constraints_1.freshVar)('COALESCE', 'any');
|
1372
1381
|
const params = {
|
@@ -1376,7 +1385,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1376
1385
|
const paramsTypeList = traverseExprListParameters(exprList, params, traverseContext);
|
1377
1386
|
paramsTypeList.forEach((typeVar, paramIndex) => {
|
1378
1387
|
traverseContext.constraints.push({
|
1379
|
-
expression: runtimeFunctionCall.
|
1388
|
+
expression: runtimeFunctionCall.getText() + '_param' + (paramIndex + 1),
|
1380
1389
|
type1: paramType,
|
1381
1390
|
type2: typeVar,
|
1382
1391
|
mostGeneralType: true,
|
@@ -1389,31 +1398,31 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1389
1398
|
//MOD (number, number): number
|
1390
1399
|
if (runtimeFunctionCall.MOD_SYMBOL()) {
|
1391
1400
|
const functionType = (0, collect_constraints_1.freshVar)('number', 'number');
|
1392
|
-
const exprList = runtimeFunctionCall.
|
1401
|
+
const exprList = runtimeFunctionCall.expr_list();
|
1393
1402
|
const param1 = traverseExpr(exprList[0], traverseContext);
|
1394
1403
|
const param2 = traverseExpr(exprList[1], traverseContext);
|
1395
1404
|
traverseContext.constraints.push({
|
1396
|
-
expression: simpleExpr.
|
1405
|
+
expression: simpleExpr.getText(),
|
1397
1406
|
type1: (0, collect_constraints_1.freshVar)('number', 'number'),
|
1398
1407
|
type2: param1,
|
1399
1408
|
mostGeneralType: true,
|
1400
1409
|
coercionType: 'Numeric'
|
1401
1410
|
});
|
1402
1411
|
traverseContext.constraints.push({
|
1403
|
-
expression: simpleExpr.
|
1412
|
+
expression: simpleExpr.getText(),
|
1404
1413
|
type1: (0, collect_constraints_1.freshVar)('number', 'number'),
|
1405
1414
|
type2: param2,
|
1406
1415
|
mostGeneralType: true,
|
1407
1416
|
coercionType: 'Numeric'
|
1408
1417
|
});
|
1409
1418
|
traverseContext.constraints.push({
|
1410
|
-
expression: simpleExpr.
|
1419
|
+
expression: simpleExpr.getText(),
|
1411
1420
|
type1: functionType,
|
1412
1421
|
type2: param1,
|
1413
1422
|
mostGeneralType: true
|
1414
1423
|
});
|
1415
1424
|
traverseContext.constraints.push({
|
1416
|
-
expression: simpleExpr.
|
1425
|
+
expression: simpleExpr.getText(),
|
1417
1426
|
type1: functionType,
|
1418
1427
|
type2: param2,
|
1419
1428
|
mostGeneralType: true
|
@@ -1421,7 +1430,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1421
1430
|
return functionType;
|
1422
1431
|
}
|
1423
1432
|
if (runtimeFunctionCall.IF_SYMBOL()) {
|
1424
|
-
const exprList = runtimeFunctionCall.
|
1433
|
+
const exprList = runtimeFunctionCall.expr_list();
|
1425
1434
|
const expr1 = exprList[0];
|
1426
1435
|
const expr2 = exprList[1];
|
1427
1436
|
const expr3 = exprList[2];
|
@@ -1429,19 +1438,19 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1429
1438
|
const expr2Type = traverseExpr(expr2, traverseContext);
|
1430
1439
|
const expr3Type = traverseExpr(expr3, traverseContext);
|
1431
1440
|
traverseContext.constraints.push({
|
1432
|
-
expression: runtimeFunctionCall.
|
1441
|
+
expression: runtimeFunctionCall.getText(),
|
1433
1442
|
type1: expr2Type,
|
1434
1443
|
type2: expr3Type,
|
1435
1444
|
mostGeneralType: true
|
1436
1445
|
});
|
1437
1446
|
return expr2Type;
|
1438
1447
|
}
|
1439
|
-
throw Error('Function not supported: ' + runtimeFunctionCall.
|
1448
|
+
throw Error('Function not supported: ' + runtimeFunctionCall.getText());
|
1440
1449
|
}
|
1441
1450
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprFunctionContext) {
|
1442
1451
|
const functionIdentifier = (0, collect_constraints_1.getFunctionName)(simpleExpr);
|
1443
1452
|
if (functionIdentifier === 'concat_ws' || (functionIdentifier === null || functionIdentifier === void 0 ? void 0 : functionIdentifier.toLowerCase()) === 'concat') {
|
1444
|
-
const varcharType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1453
|
+
const varcharType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'varchar');
|
1445
1454
|
const params = {
|
1446
1455
|
kind: 'VariableLengthParams',
|
1447
1456
|
paramType: 'varchar'
|
@@ -1450,9 +1459,9 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1450
1459
|
return varcharType;
|
1451
1460
|
}
|
1452
1461
|
if (functionIdentifier === 'avg') {
|
1453
|
-
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1462
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
|
1454
1463
|
traverseContext.constraints.push({
|
1455
|
-
expression: simpleExpr.
|
1464
|
+
expression: simpleExpr.getText(),
|
1456
1465
|
type1: functionType,
|
1457
1466
|
type2: (0, collect_constraints_1.freshVar)('decimal', 'decimal'),
|
1458
1467
|
mostGeneralType: true
|
@@ -1465,7 +1474,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1465
1474
|
return functionType;
|
1466
1475
|
}
|
1467
1476
|
if (functionIdentifier === 'round') {
|
1468
|
-
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1477
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
|
1469
1478
|
const params = {
|
1470
1479
|
kind: 'FixedLengthParams',
|
1471
1480
|
paramsType: [functionType]
|
@@ -1473,7 +1482,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1473
1482
|
const paramsType = walkFunctionParameters(simpleExpr, params, traverseContext);
|
1474
1483
|
//The return value has the same type as the first argument
|
1475
1484
|
traverseContext.constraints.push({
|
1476
|
-
expression: simpleExpr.
|
1485
|
+
expression: simpleExpr.getText(),
|
1477
1486
|
type1: functionType,
|
1478
1487
|
type2: paramsType[0], //type of the first parameter
|
1479
1488
|
mostGeneralType: true
|
@@ -1487,7 +1496,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1487
1496
|
paramsType: [doubleParam, doubleParam]
|
1488
1497
|
};
|
1489
1498
|
walkFunctionParameters(simpleExpr, params, traverseContext);
|
1490
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1499
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'bigint');
|
1491
1500
|
}
|
1492
1501
|
if (functionIdentifier === 'str_to_date') {
|
1493
1502
|
const varcharParam = (0, collect_constraints_1.freshVar)('varchar', 'varchar');
|
@@ -1496,40 +1505,40 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1496
1505
|
paramsType: [varcharParam, varcharParam]
|
1497
1506
|
};
|
1498
1507
|
walkFunctionParameters(simpleExpr, params, traverseContext);
|
1499
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1508
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date');
|
1500
1509
|
}
|
1501
1510
|
if (functionIdentifier === 'datediff') {
|
1502
|
-
const udfExprList = (_l = simpleExpr.functionCall().udfExprList()) === null || _l === void 0 ? void 0 : _l.
|
1511
|
+
const udfExprList = (_l = simpleExpr.functionCall().udfExprList()) === null || _l === void 0 ? void 0 : _l.udfExpr_list();
|
1503
1512
|
if (udfExprList) {
|
1504
1513
|
udfExprList.forEach((inExpr) => {
|
1505
1514
|
const expr = inExpr.expr();
|
1506
1515
|
const exprType = traverseExpr(expr, traverseContext);
|
1507
1516
|
const newType = (0, collect_constraints_1.verifyDateTypesCoercion)(exprType);
|
1508
1517
|
traverseContext.constraints.push({
|
1509
|
-
expression: expr.
|
1518
|
+
expression: expr.getText(),
|
1510
1519
|
type1: newType,
|
1511
1520
|
type2: (0, collect_constraints_1.freshVar)('date', 'date'),
|
1512
1521
|
mostGeneralType: true
|
1513
1522
|
});
|
1514
1523
|
});
|
1515
1524
|
}
|
1516
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1525
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'bigint');
|
1517
1526
|
}
|
1518
1527
|
if (functionIdentifier === 'period_add' || functionIdentifier == 'period_diff') {
|
1519
|
-
const udfExprList = (_m = simpleExpr.functionCall().udfExprList()) === null || _m === void 0 ? void 0 : _m.
|
1528
|
+
const udfExprList = (_m = simpleExpr.functionCall().udfExprList()) === null || _m === void 0 ? void 0 : _m.udfExpr_list();
|
1520
1529
|
if (udfExprList) {
|
1521
1530
|
udfExprList.forEach((inExpr) => {
|
1522
1531
|
const expr = inExpr.expr();
|
1523
1532
|
const exprType = traverseExpr(expr, traverseContext);
|
1524
1533
|
traverseContext.constraints.push({
|
1525
|
-
expression: expr.
|
1534
|
+
expression: expr.getText(),
|
1526
1535
|
type1: exprType,
|
1527
1536
|
type2: (0, collect_constraints_1.freshVar)('bigint', 'bigint'),
|
1528
1537
|
mostGeneralType: true
|
1529
1538
|
});
|
1530
1539
|
});
|
1531
1540
|
}
|
1532
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1541
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'bigint');
|
1533
1542
|
}
|
1534
1543
|
if (functionIdentifier === 'lpad' || functionIdentifier == 'rpad') {
|
1535
1544
|
const varcharParam = (0, collect_constraints_1.freshVar)('varchar', 'varchar');
|
@@ -1567,11 +1576,11 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1567
1576
|
}
|
1568
1577
|
if (functionIdentifier === 'abs') {
|
1569
1578
|
const functionType = (0, collect_constraints_1.freshVar)('number', 'number');
|
1570
|
-
const udfExprList = (_o = simpleExpr.functionCall().udfExprList()) === null || _o === void 0 ? void 0 : _o.
|
1579
|
+
const udfExprList = (_o = simpleExpr.functionCall().udfExprList()) === null || _o === void 0 ? void 0 : _o.udfExpr_list();
|
1571
1580
|
udfExprList === null || udfExprList === void 0 ? void 0 : udfExprList.forEach(expr => {
|
1572
1581
|
const param1 = traverseExpr(expr.expr(), traverseContext);
|
1573
1582
|
traverseContext.constraints.push({
|
1574
|
-
expression: simpleExpr.
|
1583
|
+
expression: simpleExpr.getText(),
|
1575
1584
|
type1: functionType,
|
1576
1585
|
type2: param1,
|
1577
1586
|
mostGeneralType: true,
|
@@ -1582,11 +1591,11 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1582
1591
|
}
|
1583
1592
|
if (functionIdentifier == 'ceiling' || functionIdentifier == 'ceil') {
|
1584
1593
|
const functionType = (0, collect_constraints_1.freshVar)('number', 'number');
|
1585
|
-
const udfExprList = (_p = simpleExpr.functionCall().udfExprList()) === null || _p === void 0 ? void 0 : _p.
|
1594
|
+
const udfExprList = (_p = simpleExpr.functionCall().udfExprList()) === null || _p === void 0 ? void 0 : _p.udfExpr_list();
|
1586
1595
|
udfExprList === null || udfExprList === void 0 ? void 0 : udfExprList.forEach(expr => {
|
1587
1596
|
const param1 = traverseExpr(expr.expr(), traverseContext);
|
1588
1597
|
traverseContext.constraints.push({
|
1589
|
-
expression: simpleExpr.
|
1598
|
+
expression: simpleExpr.getText(),
|
1590
1599
|
type1: functionType,
|
1591
1600
|
type2: param1,
|
1592
1601
|
mostGeneralType: true,
|
@@ -1596,17 +1605,17 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1596
1605
|
return functionType;
|
1597
1606
|
}
|
1598
1607
|
if (functionIdentifier == 'timestampdiff') {
|
1599
|
-
const udfExprList = (_q = simpleExpr.functionCall().udfExprList()) === null || _q === void 0 ? void 0 : _q.
|
1608
|
+
const udfExprList = (_q = simpleExpr.functionCall().udfExprList()) === null || _q === void 0 ? void 0 : _q.udfExpr_list();
|
1600
1609
|
if (udfExprList) {
|
1601
1610
|
const [first, ...rest] = udfExprList;
|
1602
|
-
const unit = first.
|
1611
|
+
const unit = first.getText().trim().toLowerCase();
|
1603
1612
|
rest.forEach((inExpr, paramIndex) => {
|
1604
1613
|
const expr = inExpr.expr();
|
1605
1614
|
const exprType = traverseExpr(expr, traverseContext);
|
1606
1615
|
const newType = (0, collect_constraints_1.verifyDateTypesCoercion)(exprType);
|
1607
1616
|
//const expectedType = ['hour', 'minute', 'second'].includes(unit)? 'time' : 'datetime'
|
1608
1617
|
traverseContext.constraints.push({
|
1609
|
-
expression: expr.
|
1618
|
+
expression: expr.getText(),
|
1610
1619
|
type1: newType,
|
1611
1620
|
type2: (0, collect_constraints_1.freshVar)('datetime', 'datetime'),
|
1612
1621
|
mostGeneralType: true
|
@@ -1616,19 +1625,19 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1616
1625
|
return (0, collect_constraints_1.freshVar)('int', 'int');
|
1617
1626
|
}
|
1618
1627
|
if (functionIdentifier == 'ifnull' || functionIdentifier == 'nullif') {
|
1619
|
-
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1620
|
-
const udfExprList = (_r = simpleExpr.functionCall().udfExprList()) === null || _r === void 0 ? void 0 : _r.
|
1628
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
|
1629
|
+
const udfExprList = (_r = simpleExpr.functionCall().udfExprList()) === null || _r === void 0 ? void 0 : _r.udfExpr_list();
|
1621
1630
|
if (udfExprList) {
|
1622
1631
|
const [expr1, expr2] = udfExprList;
|
1623
1632
|
const expr1Type = traverseExpr(expr1.expr(), traverseContext);
|
1624
1633
|
traverseContext.constraints.push({
|
1625
|
-
expression: expr1.
|
1634
|
+
expression: expr1.getText(),
|
1626
1635
|
type1: functionType,
|
1627
1636
|
type2: expr1Type
|
1628
1637
|
});
|
1629
1638
|
const expr2Type = traverseExpr(expr2.expr(), traverseContext);
|
1630
1639
|
traverseContext.constraints.push({
|
1631
|
-
expression: expr2.
|
1640
|
+
expression: expr2.getText(),
|
1632
1641
|
type1: functionType,
|
1633
1642
|
type2: expr2Type
|
1634
1643
|
});
|
@@ -1638,15 +1647,15 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1638
1647
|
if (functionIdentifier == 'md5' //md5(str) - TODO - have input constraint = string
|
1639
1648
|
|| functionIdentifier == 'hex' //md5(n or str)
|
1640
1649
|
|| functionIdentifier == 'unhex') { //unhex (str) - TODO - have input constraint = string
|
1641
|
-
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1642
|
-
const udfExprList = (_s = simpleExpr.functionCall().udfExprList()) === null || _s === void 0 ? void 0 : _s.
|
1650
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'char');
|
1651
|
+
const udfExprList = (_s = simpleExpr.functionCall().udfExprList()) === null || _s === void 0 ? void 0 : _s.udfExpr_list();
|
1643
1652
|
if (udfExprList) {
|
1644
1653
|
const [expr1] = udfExprList;
|
1645
1654
|
const paramType = traverseExpr(expr1.expr(), traverseContext);
|
1646
1655
|
traverseContext.constraints.push({
|
1647
|
-
expression: expr1.
|
1656
|
+
expression: expr1.getText(),
|
1648
1657
|
type1: paramType,
|
1649
|
-
type2: (0, collect_constraints_1.freshVar)(expr1.
|
1658
|
+
type2: (0, collect_constraints_1.freshVar)(expr1.getText(), 'varchar')
|
1650
1659
|
});
|
1651
1660
|
}
|
1652
1661
|
return functionType;
|
@@ -1660,7 +1669,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1660
1669
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprCastContext) {
|
1661
1670
|
const castType = simpleExpr.castType();
|
1662
1671
|
if (castType.CHAR_SYMBOL()) {
|
1663
|
-
return (0, collect_constraints_1.freshVar)(castType.
|
1672
|
+
return (0, collect_constraints_1.freshVar)(castType.getText(), 'char');
|
1664
1673
|
}
|
1665
1674
|
}
|
1666
1675
|
throw Error('traverseSimpleExpr - not supported: ' + simpleExpr.constructor.name);
|
@@ -1671,7 +1680,7 @@ function traverseWindowFunctionCall(windowFunctionCall, traverseContext) {
|
|
1671
1680
|
|| windowFunctionCall.DENSE_RANK_SYMBOL()
|
1672
1681
|
|| windowFunctionCall.CUME_DIST_SYMBOL()
|
1673
1682
|
|| windowFunctionCall.PERCENT_RANK_SYMBOL()) {
|
1674
|
-
return (0, collect_constraints_1.freshVar)(windowFunctionCall.
|
1683
|
+
return (0, collect_constraints_1.freshVar)(windowFunctionCall.getText(), 'bigint');
|
1675
1684
|
}
|
1676
1685
|
const expr = windowFunctionCall.expr();
|
1677
1686
|
if (expr) {
|
@@ -1689,7 +1698,7 @@ function traverseExprListParameters(exprList, params, traverseContext) {
|
|
1689
1698
|
const exprType = traverseExpr(expr, traverseContext);
|
1690
1699
|
const paramType = params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType);
|
1691
1700
|
traverseContext.constraints.push({
|
1692
|
-
expression: expr.
|
1701
|
+
expression: expr.getText(),
|
1693
1702
|
type1: exprType,
|
1694
1703
|
type2: paramType,
|
1695
1704
|
mostGeneralType: true
|
@@ -1700,7 +1709,7 @@ function traverseExprListParameters(exprList, params, traverseContext) {
|
|
1700
1709
|
function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
|
1701
1710
|
var _a, _b;
|
1702
1711
|
const functionName = (0, collect_constraints_1.getFunctionName)(simpleExprFunction);
|
1703
|
-
const udfExprList = (_a = simpleExprFunction.functionCall().udfExprList()) === null || _a === void 0 ? void 0 : _a.
|
1712
|
+
const udfExprList = (_a = simpleExprFunction.functionCall().udfExprList()) === null || _a === void 0 ? void 0 : _a.udfExpr_list();
|
1704
1713
|
if (udfExprList) {
|
1705
1714
|
const paramTypes = udfExprList
|
1706
1715
|
.filter((undefined, paramIndex) => {
|
@@ -1710,7 +1719,7 @@ function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
|
|
1710
1719
|
const expr = inExpr.expr();
|
1711
1720
|
const exprType = traverseExpr(expr, traverseContext);
|
1712
1721
|
traverseContext.constraints.push({
|
1713
|
-
expression: expr.
|
1722
|
+
expression: expr.getText(),
|
1714
1723
|
type1: exprType,
|
1715
1724
|
type2: params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType),
|
1716
1725
|
});
|
@@ -1718,12 +1727,12 @@ function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
|
|
1718
1727
|
});
|
1719
1728
|
return paramTypes;
|
1720
1729
|
}
|
1721
|
-
const exprList = (_b = simpleExprFunction.functionCall().exprList()) === null || _b === void 0 ? void 0 : _b.
|
1730
|
+
const exprList = (_b = simpleExprFunction.functionCall().exprList()) === null || _b === void 0 ? void 0 : _b.expr_list();
|
1722
1731
|
if (exprList) {
|
1723
1732
|
const paramTypes = exprList.map((inExpr, paramIndex) => {
|
1724
1733
|
const inSumExprType = traverseExpr(inExpr, traverseContext);
|
1725
1734
|
traverseContext.constraints.push({
|
1726
|
-
expression: inExpr.
|
1735
|
+
expression: inExpr.getText(),
|
1727
1736
|
type1: params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType),
|
1728
1737
|
type2: inSumExprType,
|
1729
1738
|
mostGeneralType: true
|
@@ -1779,10 +1788,10 @@ function isMultipleRowResult(selectStatement, fromColumns) {
|
|
1779
1788
|
if (!fromClause) {
|
1780
1789
|
return false;
|
1781
1790
|
}
|
1782
|
-
if (querySpecs[0].selectItemList().
|
1791
|
+
if (querySpecs[0].selectItemList().getChildCount() == 1) {
|
1783
1792
|
const selectItem = querySpecs[0].selectItemList().getChild(0);
|
1784
1793
|
//if selectItem = * (TerminalNode) childCount = 0; selectItem.expr() throws exception
|
1785
|
-
const expr = selectItem.
|
1794
|
+
const expr = selectItem.getChildCount() > 0 ? selectItem.expr() : null;
|
1786
1795
|
if (expr) {
|
1787
1796
|
//SUM, MAX... WITHOUT GROUP BY are multipleRowsResult = false
|
1788
1797
|
const groupBy = querySpecs[0].groupByClause();
|
@@ -1791,7 +1800,7 @@ function isMultipleRowResult(selectStatement, fromColumns) {
|
|
1791
1800
|
}
|
1792
1801
|
}
|
1793
1802
|
}
|
1794
|
-
const joinedTable = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference()
|
1803
|
+
const joinedTable = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference(0).joinedTable_list();
|
1795
1804
|
if (joinedTable && joinedTable.length > 0) {
|
1796
1805
|
return true;
|
1797
1806
|
}
|
@@ -1806,10 +1815,10 @@ function isMultipleRowResult(selectStatement, fromColumns) {
|
|
1806
1815
|
exports.isMultipleRowResult = isMultipleRowResult;
|
1807
1816
|
function isLimitOne(selectStatement) {
|
1808
1817
|
const limitOptions = (0, parse_1.getLimitOptions)(selectStatement);
|
1809
|
-
if (limitOptions.length == 1 && limitOptions[0].
|
1818
|
+
if (limitOptions.length == 1 && limitOptions[0].getText() == '1') {
|
1810
1819
|
return true;
|
1811
1820
|
}
|
1812
|
-
if (limitOptions.length == 2 && limitOptions[1].
|
1821
|
+
if (limitOptions.length == 2 && limitOptions[1].getText() == '1') {
|
1813
1822
|
return true;
|
1814
1823
|
}
|
1815
1824
|
return false;
|
@@ -1833,7 +1842,7 @@ function verifyMultipleResult2(exprContext, fromColumns) {
|
|
1833
1842
|
return true;
|
1834
1843
|
}
|
1835
1844
|
if (exprContext instanceof ts_mysql_parser_1.ExprAndContext) {
|
1836
|
-
const oneIsSingleResult = exprContext.
|
1845
|
+
const oneIsSingleResult = exprContext.expr_list().some(expr => verifyMultipleResult2(expr, fromColumns) == false);
|
1837
1846
|
return oneIsSingleResult == false;
|
1838
1847
|
}
|
1839
1848
|
// if (exprContext instanceof ExprXorContext) {
|
@@ -1848,7 +1857,7 @@ exports.verifyMultipleResult2 = verifyMultipleResult2;
|
|
1848
1857
|
function isUniqueKeyComparation(compare, fromColumns) {
|
1849
1858
|
const tokens = (0, select_columns_1.getSimpleExpressions)(compare);
|
1850
1859
|
if (tokens.length == 1 && tokens[0] instanceof ts_mysql_parser_1.SimpleExprColumnRefContext) {
|
1851
|
-
const fieldName = (0, select_columns_1.splitName)(tokens[0].
|
1860
|
+
const fieldName = (0, select_columns_1.splitName)(tokens[0].getText());
|
1852
1861
|
const col = (0, select_columns_1.findColumn)(fieldName, fromColumns);
|
1853
1862
|
if (col.columnKey == 'PRI' || col.columnKey == 'UNI') { //TODO - UNIQUE
|
1854
1863
|
return true; //isUniqueKeyComparation = true
|