typesql-cli 0.8.21 → 0.8.22
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.js +152 -152
- package/mysql-query-analyzer/traverse.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/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/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
|
}
|
@@ -443,10 +443,10 @@ function traverseQuerySpecification(querySpec, traverseContext) {
|
|
443
443
|
exports.traverseQuerySpecification = traverseQuerySpecification;
|
444
444
|
function traverseWithClause(withClause, traverseContext) {
|
445
445
|
//result1, result2
|
446
|
-
withClause.
|
446
|
+
withClause.commonTableExpression_list().forEach(commonTableExpression => {
|
447
447
|
var _a, _b;
|
448
|
-
const cte = commonTableExpression.identifier().
|
449
|
-
const recursiveNames = withClause.RECURSIVE_SYMBOL() ? ((_a = commonTableExpression.columnInternalRefList()) === null || _a === void 0 ? void 0 : _a.
|
448
|
+
const cte = commonTableExpression.identifier().getText();
|
449
|
+
const recursiveNames = withClause.RECURSIVE_SYMBOL() ? ((_a = commonTableExpression.columnInternalRefList()) === null || _a === void 0 ? void 0 : _a.columnInternalRef_list().map(t => t.getText())) || [] : undefined;
|
450
450
|
const subQuery = commonTableExpression.subquery();
|
451
451
|
traverseSubquery(subQuery, traverseContext, cte, recursiveNames); //recursive= true??
|
452
452
|
(_b = traverseContext.dynamicSqlInfo.with) === null || _b === void 0 ? void 0 : _b.push({
|
@@ -463,7 +463,7 @@ function traverseWithClause(withClause, traverseContext) {
|
|
463
463
|
exports.traverseWithClause = traverseWithClause;
|
464
464
|
function traverseFromClause(fromClause, traverseContext) {
|
465
465
|
var _a;
|
466
|
-
const tableReferenceList = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.
|
466
|
+
const tableReferenceList = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference_list();
|
467
467
|
const fromColumns = tableReferenceList ? traverseTableReferenceList(tableReferenceList, traverseContext, null) : [];
|
468
468
|
return fromColumns;
|
469
469
|
}
|
@@ -488,7 +488,7 @@ function traverseTableReferenceList(tableReferenceList, traverseContext, current
|
|
488
488
|
}
|
489
489
|
const allJoinedColumns = [];
|
490
490
|
let firstLeftJoinIndex = -1;
|
491
|
-
tab.
|
491
|
+
tab.joinedTable_list().forEach((joined, index) => {
|
492
492
|
var _a, _b;
|
493
493
|
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
494
|
firstLeftJoinIndex = -1; //dont need to add notNull = false to joins
|
@@ -540,7 +540,7 @@ function traverseTableReferenceList(tableReferenceList, traverseContext, current
|
|
540
540
|
traverseExpr(onClause, Object.assign(Object.assign({}, traverseContext), { fromColumns: allJoinedColumns.flatMap(c => c).concat(result) }));
|
541
541
|
const columns = (0, select_columns_1.getExpressions)(onClause, ts_mysql_parser_1.SimpleExprColumnRefContext);
|
542
542
|
columns.forEach(columnRef => {
|
543
|
-
const fieldName = (0, select_columns_1.splitName)(columnRef.expr.
|
543
|
+
const fieldName = (0, select_columns_1.splitName)(columnRef.expr.getText());
|
544
544
|
if ((innerJoinFragment === null || innerJoinFragment === void 0 ? void 0 : innerJoinFragment.relation) != fieldName.prefix) {
|
545
545
|
innerJoinFragment.parentRelation = fieldName.prefix;
|
546
546
|
}
|
@@ -573,7 +573,7 @@ function traverseTableFactor(tableFactor, traverseContext, currentFragment) {
|
|
573
573
|
}
|
574
574
|
const derivadTable = tableFactor.derivedTable();
|
575
575
|
if (derivadTable) {
|
576
|
-
const tableAlias = (_a = derivadTable.tableAlias()) === null || _a === void 0 ? void 0 : _a.identifier().
|
576
|
+
const tableAlias = (_a = derivadTable.tableAlias()) === null || _a === void 0 ? void 0 : _a.identifier().getText();
|
577
577
|
if (currentFragment) {
|
578
578
|
currentFragment.relation = tableAlias;
|
579
579
|
}
|
@@ -605,7 +605,7 @@ function traverseTableFactor(tableFactor, traverseContext, currentFragment) {
|
|
605
605
|
function traverseTableReferenceListParens(ctx, traverseContext) {
|
606
606
|
const tableReferenceList = ctx.tableReferenceList();
|
607
607
|
if (tableReferenceList) {
|
608
|
-
return traverseTableReferenceList(tableReferenceList.
|
608
|
+
return traverseTableReferenceList(tableReferenceList.tableReference_list(), traverseContext, null);
|
609
609
|
}
|
610
610
|
const tableReferenceListParens = ctx.tableReferenceListParens();
|
611
611
|
if (tableReferenceListParens) {
|
@@ -615,8 +615,8 @@ function traverseTableReferenceListParens(ctx, traverseContext) {
|
|
615
615
|
}
|
616
616
|
function traverseSingleTable(singleTable, dbSchema, withSchema, currentFragment, withFragments) {
|
617
617
|
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().
|
618
|
+
const table = singleTable === null || singleTable === void 0 ? void 0 : singleTable.tableRef().getText();
|
619
|
+
const tableAlias = (_a = singleTable === null || singleTable === void 0 ? void 0 : singleTable.tableAlias()) === null || _a === void 0 ? void 0 : _a.identifier().getText();
|
620
620
|
const tableName = (0, select_columns_1.splitName)(table);
|
621
621
|
if (currentFragment) {
|
622
622
|
currentFragment.relation = tableAlias || tableName.name;
|
@@ -666,12 +666,12 @@ function traverseSelectItemList(selectItemList, traverseContext) {
|
|
666
666
|
}
|
667
667
|
});
|
668
668
|
}
|
669
|
-
selectItemList.
|
669
|
+
selectItemList.selectItem_list().forEach(selectItem => {
|
670
670
|
var _a;
|
671
671
|
const tableWild = selectItem.tableWild();
|
672
672
|
if (tableWild) {
|
673
673
|
if (tableWild.MULT_OPERATOR()) {
|
674
|
-
const itemName = (0, select_columns_1.splitName)(selectItem.
|
674
|
+
const itemName = (0, select_columns_1.splitName)(selectItem.getText());
|
675
675
|
const allColumns = selectAllColumns(itemName.prefix, traverseContext.fromColumns);
|
676
676
|
allColumns.forEach(col => {
|
677
677
|
const columnType = (0, collect_constraints_1.createColumnType)(col);
|
@@ -737,7 +737,7 @@ function traverseExpr(expr, traverseContext) {
|
|
737
737
|
});
|
738
738
|
const columnsRef = (0, select_columns_1.getExpressions)(expr, ts_mysql_parser_1.ColumnRefContext);
|
739
739
|
columnsRef.forEach(colRef => {
|
740
|
-
const fileName = (0, select_columns_1.splitName)(colRef.expr.
|
740
|
+
const fileName = (0, select_columns_1.splitName)(colRef.expr.getText());
|
741
741
|
currentFragment.fields.push({
|
742
742
|
field: fileName.name,
|
743
743
|
name: fileName.name,
|
@@ -753,7 +753,7 @@ function traverseExpr(expr, traverseContext) {
|
|
753
753
|
if (expr2) {
|
754
754
|
return traverseExpr(expr2, traverseContext);
|
755
755
|
}
|
756
|
-
return (0, collect_constraints_1.freshVar)(expr.
|
756
|
+
return (0, collect_constraints_1.freshVar)(expr.getText(), 'tinyint');
|
757
757
|
;
|
758
758
|
}
|
759
759
|
if (expr instanceof ts_mysql_parser_1.ExprAndContext || expr instanceof ts_mysql_parser_1.ExprXorContext || expr instanceof ts_mysql_parser_1.ExprOrContext) {
|
@@ -778,7 +778,7 @@ function traverseExpr(expr, traverseContext) {
|
|
778
778
|
});
|
779
779
|
const columnsRef = (0, select_columns_1.getExpressions)(andExpression.expr, ts_mysql_parser_1.ColumnRefContext);
|
780
780
|
columnsRef.forEach(colRef => {
|
781
|
-
const fileName = (0, select_columns_1.splitName)(colRef.expr.
|
781
|
+
const fileName = (0, select_columns_1.splitName)(colRef.expr.getText());
|
782
782
|
currentFragment.fields.push({
|
783
783
|
field: fileName.name,
|
784
784
|
name: fileName.name,
|
@@ -788,9 +788,9 @@ function traverseExpr(expr, traverseContext) {
|
|
788
788
|
traverseContext.dynamicSqlInfo.where.push(currentFragment);
|
789
789
|
}
|
790
790
|
});
|
791
|
-
return (0, collect_constraints_1.freshVar)(expr.
|
791
|
+
return (0, collect_constraints_1.freshVar)(expr.getText(), 'tinyint');
|
792
792
|
}
|
793
|
-
throw Error('traverseExpr - not supported: ' + expr.
|
793
|
+
throw Error('traverseExpr - not supported: ' + expr.getText());
|
794
794
|
}
|
795
795
|
function traverseBoolPri(boolPri, traverseContext) {
|
796
796
|
if (boolPri instanceof ts_mysql_parser_1.PrimaryExprPredicateContext) {
|
@@ -801,7 +801,7 @@ function traverseBoolPri(boolPri, traverseContext) {
|
|
801
801
|
if (boolPri instanceof ts_mysql_parser_1.PrimaryExprIsNullContext) {
|
802
802
|
const boolPri2 = boolPri.boolPri();
|
803
803
|
traverseBoolPri(boolPri2, traverseContext);
|
804
|
-
return (0, collect_constraints_1.freshVar)(boolPri.
|
804
|
+
return (0, collect_constraints_1.freshVar)(boolPri.getText(), 'tinyint');
|
805
805
|
}
|
806
806
|
if (boolPri instanceof ts_mysql_parser_1.PrimaryExprCompareContext) {
|
807
807
|
const compareLeft = boolPri.boolPri();
|
@@ -810,11 +810,11 @@ function traverseBoolPri(boolPri, traverseContext) {
|
|
810
810
|
const typeLeft = traverseBoolPri(compareLeft, traverseContext);
|
811
811
|
const typeRight = traversePredicate(compareRight, traverseContext);
|
812
812
|
traverseContext.constraints.push({
|
813
|
-
expression: boolPri.
|
813
|
+
expression: boolPri.getText(),
|
814
814
|
type1: typeLeft,
|
815
815
|
type2: typeRight
|
816
816
|
});
|
817
|
-
return (0, collect_constraints_1.freshVar)(boolPri.
|
817
|
+
return (0, collect_constraints_1.freshVar)(boolPri.getText(), 'tinyint');
|
818
818
|
}
|
819
819
|
if (boolPri instanceof ts_mysql_parser_1.PrimaryExprAllAnyContext) {
|
820
820
|
const compareLeft = boolPri.boolPri();
|
@@ -822,19 +822,19 @@ function traverseBoolPri(boolPri, traverseContext) {
|
|
822
822
|
const typeLeft = traverseBoolPri(compareLeft, traverseContext);
|
823
823
|
const subQueryResult = traverseSubquery(compareRight, traverseContext);
|
824
824
|
traverseContext.constraints.push({
|
825
|
-
expression: boolPri.
|
825
|
+
expression: boolPri.getText(),
|
826
826
|
type1: typeLeft,
|
827
827
|
type2: {
|
828
828
|
kind: 'TypeOperator',
|
829
829
|
types: subQueryResult.columns.map(t => t.type)
|
830
830
|
}
|
831
831
|
});
|
832
|
-
return (0, collect_constraints_1.freshVar)(boolPri.
|
832
|
+
return (0, collect_constraints_1.freshVar)(boolPri.getText(), 'tinyint');
|
833
833
|
}
|
834
834
|
throw Error('traverseExpr - not supported: ' + boolPri.constructor.name);
|
835
835
|
}
|
836
836
|
function traversePredicate(predicate, traverseContext) {
|
837
|
-
const bitExpr = predicate.bitExpr()
|
837
|
+
const bitExpr = predicate.bitExpr(0); //TODO - predicate length = 2? [1] == predicateOperations
|
838
838
|
const bitExprType = traverseBitExpr(bitExpr, traverseContext);
|
839
839
|
const predicateOperations = predicate.predicateOperations();
|
840
840
|
if (predicateOperations) {
|
@@ -842,7 +842,7 @@ function traversePredicate(predicate, traverseContext) {
|
|
842
842
|
if (bitExprType.kind == 'TypeOperator' && rightType.kind == 'TypeOperator') {
|
843
843
|
rightType.types.forEach((t, i) => {
|
844
844
|
traverseContext.constraints.push({
|
845
|
-
expression: predicateOperations.
|
845
|
+
expression: predicateOperations.getText(),
|
846
846
|
type1: t, // ? array of id+id
|
847
847
|
type2: bitExprType.types[i],
|
848
848
|
mostGeneralType: true
|
@@ -852,7 +852,7 @@ function traversePredicate(predicate, traverseContext) {
|
|
852
852
|
if (bitExprType.kind == 'TypeVar' && rightType.kind == 'TypeOperator') {
|
853
853
|
rightType.types.forEach((t, i) => {
|
854
854
|
traverseContext.constraints.push({
|
855
|
-
expression: predicateOperations.
|
855
|
+
expression: predicateOperations.getText(),
|
856
856
|
type1: bitExprType, // ? array of id+id
|
857
857
|
type2: Object.assign(Object.assign({}, t), { list: true }),
|
858
858
|
mostGeneralType: true
|
@@ -865,7 +865,7 @@ function traversePredicate(predicate, traverseContext) {
|
|
865
865
|
return bitExprType;
|
866
866
|
}
|
867
867
|
function traverseExprList(exprList, traverseContext) {
|
868
|
-
const listType = exprList.
|
868
|
+
const listType = exprList.expr_list().map(item => {
|
869
869
|
const exprType = traverseExpr(item, traverseContext);
|
870
870
|
return exprType;
|
871
871
|
});
|
@@ -880,17 +880,17 @@ function traverseBitExpr(bitExpr, traverseContext) {
|
|
880
880
|
if (simpleExpr) {
|
881
881
|
return traverseSimpleExpr(simpleExpr, Object.assign(Object.assign({}, traverseContext), { where: false }));
|
882
882
|
}
|
883
|
-
if (bitExpr.
|
884
|
-
const bitExprLeft = bitExpr.bitExpr()
|
883
|
+
if (bitExpr.bitExpr_list().length == 2) {
|
884
|
+
const bitExprLeft = bitExpr.bitExpr(0);
|
885
885
|
const typeLeftTemp = traverseBitExpr(bitExprLeft, traverseContext);
|
886
886
|
const typeLeft = typeLeftTemp.kind == 'TypeOperator' ? typeLeftTemp.types[0] : typeLeftTemp;
|
887
887
|
//const newTypeLeft = typeLeft.name == '?'? freshVar('?', 'bigint') : typeLeft;
|
888
|
-
const bitExprRight = bitExpr.bitExpr()
|
888
|
+
const bitExprRight = bitExpr.bitExpr(1);
|
889
889
|
const typeRightTemp = traverseBitExpr(bitExprRight, traverseContext);
|
890
890
|
//In the expression 'id + (value + 2) + ?' the '(value+2)' is treated as a SimpleExprListContext and return a TypeOperator
|
891
891
|
const typeRight = typeRightTemp.kind == 'TypeOperator' ? typeRightTemp.types[0] : typeRightTemp;
|
892
892
|
//const newTypeRight = typeRight.name == '?'? freshVar('?', 'bigint') : typeRight;
|
893
|
-
const bitExprType = (0, collect_constraints_1.freshVar)(bitExpr.
|
893
|
+
const bitExprType = (0, collect_constraints_1.freshVar)(bitExpr.getText(), '?');
|
894
894
|
if (typeLeftTemp.kind == 'TypeVar' && typeRightTemp.kind == 'TypeVar' && typeLeftTemp.table == typeRightTemp.table) {
|
895
895
|
bitExprType.table = typeLeftTemp.table;
|
896
896
|
}
|
@@ -917,14 +917,14 @@ function traverseBitExpr(bitExpr, traverseContext) {
|
|
917
917
|
// coercionType: 'Sum'
|
918
918
|
// })
|
919
919
|
traverseContext.constraints.push({
|
920
|
-
expression: bitExprLeft.
|
920
|
+
expression: bitExprLeft.getText(),
|
921
921
|
type1: bitExprType,
|
922
922
|
type2: typeLeft,
|
923
923
|
mostGeneralType: true,
|
924
924
|
coercionType: 'Sum'
|
925
925
|
});
|
926
926
|
traverseContext.constraints.push({
|
927
|
-
expression: bitExprRight.
|
927
|
+
expression: bitExprRight.getText(),
|
928
928
|
type1: bitExprType,
|
929
929
|
type2: typeRight,
|
930
930
|
mostGeneralType: true,
|
@@ -941,12 +941,12 @@ function traverseBitExpr(bitExpr, traverseContext) {
|
|
941
941
|
return bitExprType;
|
942
942
|
}
|
943
943
|
if (bitExpr.INTERVAL_SYMBOL()) {
|
944
|
-
const bitExpr2 = bitExpr.bitExpr()
|
944
|
+
const bitExpr2 = bitExpr.bitExpr(0);
|
945
945
|
const leftType = traverseBitExpr(bitExpr2, traverseContext);
|
946
946
|
const expr = bitExpr.expr(); //expr interval
|
947
947
|
traverseExpr(expr, traverseContext);
|
948
948
|
traverseContext.constraints.push({
|
949
|
-
expression: bitExpr.
|
949
|
+
expression: bitExpr.getText(),
|
950
950
|
type1: leftType,
|
951
951
|
type2: (0, collect_constraints_1.freshVar)('datetime', 'datetime')
|
952
952
|
});
|
@@ -968,10 +968,10 @@ function traversePredicateOperations(predicateOperations, parentType, traverseCo
|
|
968
968
|
}
|
969
969
|
}
|
970
970
|
if (predicateOperations instanceof ts_mysql_parser_1.PredicateExprLikeContext) {
|
971
|
-
const simpleExpr = predicateOperations.simpleExpr()
|
971
|
+
const simpleExpr = predicateOperations.simpleExpr(0);
|
972
972
|
const rightType = traverseSimpleExpr(simpleExpr, Object.assign(Object.assign({}, traverseContext), { where: false }));
|
973
973
|
traverseContext.constraints.push({
|
974
|
-
expression: simpleExpr.
|
974
|
+
expression: simpleExpr.getText(),
|
975
975
|
type1: parentType,
|
976
976
|
type2: rightType
|
977
977
|
});
|
@@ -983,17 +983,17 @@ function traversePredicateOperations(predicateOperations, parentType, traverseCo
|
|
983
983
|
const bitExprType = traverseBitExpr(bitExpr, traverseContext);
|
984
984
|
const predicateType = traversePredicate(predicate, traverseContext);
|
985
985
|
traverseContext.constraints.push({
|
986
|
-
expression: predicateOperations.
|
986
|
+
expression: predicateOperations.getText(),
|
987
987
|
type1: parentType,
|
988
988
|
type2: bitExprType
|
989
989
|
});
|
990
990
|
traverseContext.constraints.push({
|
991
|
-
expression: predicateOperations.
|
991
|
+
expression: predicateOperations.getText(),
|
992
992
|
type1: parentType,
|
993
993
|
type2: predicateType
|
994
994
|
});
|
995
995
|
traverseContext.constraints.push({
|
996
|
-
expression: predicateOperations.
|
996
|
+
expression: predicateOperations.getText(),
|
997
997
|
type1: bitExprType,
|
998
998
|
type2: predicateType
|
999
999
|
});
|
@@ -1004,11 +1004,11 @@ function traversePredicateOperations(predicateOperations, parentType, traverseCo
|
|
1004
1004
|
function traverseSimpleExpr(simpleExpr, traverseContext) {
|
1005
1005
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
1006
1006
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprColumnRefContext) {
|
1007
|
-
const fieldName = (0, select_columns_1.splitName)(simpleExpr.
|
1007
|
+
const fieldName = (0, select_columns_1.splitName)(simpleExpr.getText());
|
1008
1008
|
const column = (0, select_columns_1.findColumn)(fieldName, traverseContext.fromColumns);
|
1009
1009
|
const typeVar = (0, collect_constraints_1.freshVar)(column.columnName, column.columnType.type, column.tableAlias || column.table);
|
1010
1010
|
traverseContext.constraints.push({
|
1011
|
-
expression: simpleExpr.
|
1011
|
+
expression: simpleExpr.getText(),
|
1012
1012
|
type1: typeVar,
|
1013
1013
|
type2: column.columnType,
|
1014
1014
|
mostGeneralType: true
|
@@ -1033,19 +1033,19 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1033
1033
|
type: param,
|
1034
1034
|
notNull: false,
|
1035
1035
|
table: param.table || '',
|
1036
|
-
paramIndex: simpleExpr.start.
|
1036
|
+
paramIndex: simpleExpr.start.start
|
1037
1037
|
});
|
1038
1038
|
return param;
|
1039
1039
|
}
|
1040
1040
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprLiteralContext) {
|
1041
1041
|
const literal = simpleExpr.literal();
|
1042
1042
|
if (literal.textLiteral()) {
|
1043
|
-
const text = ((_a = literal.textLiteral()) === null || _a === void 0 ? void 0 : _a.
|
1043
|
+
const text = ((_a = literal.textLiteral()) === null || _a === void 0 ? void 0 : _a.getText().slice(1, -1)) || ''; //remove quotes
|
1044
1044
|
return (0, collect_constraints_1.freshVar)(text, 'varchar');
|
1045
1045
|
}
|
1046
1046
|
const numLiteral = literal.numLiteral();
|
1047
1047
|
if (numLiteral) {
|
1048
|
-
return (0, collect_constraints_1.freshVar)(numLiteral.
|
1048
|
+
return (0, collect_constraints_1.freshVar)(numLiteral.getText(), 'int');
|
1049
1049
|
// addNamedNode(simpleExpr, freshVar('bigint', 'bigint'), namedNodes)
|
1050
1050
|
// if(numLiteral.INT_NUMBER()) {
|
1051
1051
|
// const typeInt = freshVar('int', 'int');
|
@@ -1063,18 +1063,18 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1063
1063
|
}
|
1064
1064
|
const boolLiteral = literal.boolLiteral();
|
1065
1065
|
if (boolLiteral) {
|
1066
|
-
return (0, collect_constraints_1.freshVar)(boolLiteral.
|
1066
|
+
return (0, collect_constraints_1.freshVar)(boolLiteral.getText(), 'bit');
|
1067
1067
|
}
|
1068
1068
|
const nullLiteral = literal.nullLiteral();
|
1069
1069
|
if (nullLiteral) {
|
1070
|
-
return (0, collect_constraints_1.freshVar)(nullLiteral.
|
1070
|
+
return (0, collect_constraints_1.freshVar)(nullLiteral.getText(), '?');
|
1071
1071
|
}
|
1072
|
-
throw Error('literal not supported:' + literal.
|
1072
|
+
throw Error('literal not supported:' + literal.getText());
|
1073
1073
|
//...
|
1074
1074
|
}
|
1075
1075
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprListContext) {
|
1076
1076
|
const exprList = simpleExpr.exprList();
|
1077
|
-
const listType = exprList.
|
1077
|
+
const listType = exprList.expr_list().map(item => {
|
1078
1078
|
const exprType = traverseExpr(item, Object.assign(Object.assign({}, traverseContext), { where: false }));
|
1079
1079
|
return exprType;
|
1080
1080
|
});
|
@@ -1094,21 +1094,21 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1094
1094
|
}
|
1095
1095
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprCaseContext) {
|
1096
1096
|
//case when expr then expr else expr
|
1097
|
-
const caseType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1098
|
-
simpleExpr.
|
1097
|
+
const caseType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
|
1098
|
+
simpleExpr.whenExpression_list().forEach(whenExprCont => {
|
1099
1099
|
const whenExpr = whenExprCont.expr();
|
1100
1100
|
const whenType = traverseExpr(whenExpr, traverseContext);
|
1101
1101
|
traverseContext.constraints.push({
|
1102
|
-
expression: whenExpr.
|
1102
|
+
expression: whenExpr.getText(),
|
1103
1103
|
type1: whenType.kind == 'TypeOperator' ? whenType.types[0] : whenType,
|
1104
1104
|
type2: (0, collect_constraints_1.freshVar)('tinyint', 'tinyint') //bool
|
1105
1105
|
});
|
1106
1106
|
});
|
1107
|
-
const thenTypes = simpleExpr.
|
1107
|
+
const thenTypes = simpleExpr.thenExpression_list().map(thenExprCtx => {
|
1108
1108
|
const thenExpr = thenExprCtx.expr();
|
1109
1109
|
const thenType = traverseExpr(thenExpr, traverseContext);
|
1110
1110
|
traverseContext.constraints.push({
|
1111
|
-
expression: thenExprCtx.
|
1111
|
+
expression: thenExprCtx.getText(),
|
1112
1112
|
type1: caseType,
|
1113
1113
|
type2: thenType.kind == 'TypeOperator' ? thenType.types[0] : thenType,
|
1114
1114
|
mostGeneralType: true,
|
@@ -1119,7 +1119,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1119
1119
|
if (elseExpr) {
|
1120
1120
|
const elseType = traverseExpr(elseExpr, traverseContext);
|
1121
1121
|
traverseContext.constraints.push({
|
1122
|
-
expression: (_c = simpleExpr.elseExpression()) === null || _c === void 0 ? void 0 : _c.
|
1122
|
+
expression: (_c = simpleExpr.elseExpression()) === null || _c === void 0 ? void 0 : _c.getText(),
|
1123
1123
|
type1: caseType,
|
1124
1124
|
type2: elseType.kind == 'TypeOperator' ? elseType.types[0] : elseType,
|
1125
1125
|
mostGeneralType: true
|
@@ -1127,7 +1127,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1127
1127
|
thenTypes.forEach(thenType => {
|
1128
1128
|
var _a;
|
1129
1129
|
traverseContext.constraints.push({
|
1130
|
-
expression: (_a = simpleExpr.elseExpression()) === null || _a === void 0 ? void 0 : _a.
|
1130
|
+
expression: (_a = simpleExpr.elseExpression()) === null || _a === void 0 ? void 0 : _a.getText(),
|
1131
1131
|
type1: thenType,
|
1132
1132
|
type2: elseType.kind == 'TypeOperator' ? elseType.types[0] : elseType,
|
1133
1133
|
mostGeneralType: true
|
@@ -1137,13 +1137,13 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1137
1137
|
return caseType;
|
1138
1138
|
}
|
1139
1139
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprIntervalContext) {
|
1140
|
-
const exprList = simpleExpr.
|
1140
|
+
const exprList = simpleExpr.expr_list();
|
1141
1141
|
const exprLeft = exprList[0];
|
1142
1142
|
const exprRight = exprList[1];
|
1143
1143
|
const typeLeft = traverseExpr(exprLeft, traverseContext);
|
1144
1144
|
const typeRight = traverseExpr(exprRight, traverseContext);
|
1145
1145
|
traverseContext.constraints.push({
|
1146
|
-
expression: exprLeft.
|
1146
|
+
expression: exprLeft.getText(),
|
1147
1147
|
type1: typeLeft,
|
1148
1148
|
type2: (0, collect_constraints_1.freshVar)('bigint', 'bigint')
|
1149
1149
|
});
|
@@ -1151,7 +1151,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1151
1151
|
typeRight.type = 'datetime';
|
1152
1152
|
}
|
1153
1153
|
traverseContext.constraints.push({
|
1154
|
-
expression: exprRight.
|
1154
|
+
expression: exprRight.getText(),
|
1155
1155
|
type1: typeRight,
|
1156
1156
|
type2: (0, collect_constraints_1.freshVar)('datetime', 'datetime')
|
1157
1157
|
});
|
@@ -1160,12 +1160,12 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1160
1160
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprSumContext) {
|
1161
1161
|
const sumExpr = simpleExpr.sumExpr();
|
1162
1162
|
if (sumExpr.MAX_SYMBOL() || sumExpr.MIN_SYMBOL()) {
|
1163
|
-
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1163
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
|
1164
1164
|
const inSumExpr = (_d = sumExpr.inSumExpr()) === null || _d === void 0 ? void 0 : _d.expr();
|
1165
1165
|
if (inSumExpr) {
|
1166
1166
|
const inSumExprType = traverseExpr(inSumExpr, traverseContext);
|
1167
1167
|
traverseContext.constraints.push({
|
1168
|
-
expression: simpleExpr.
|
1168
|
+
expression: simpleExpr.getText(),
|
1169
1169
|
type1: functionType,
|
1170
1170
|
type2: inSumExprType,
|
1171
1171
|
mostGeneralType: true
|
@@ -1174,7 +1174,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1174
1174
|
return functionType;
|
1175
1175
|
}
|
1176
1176
|
if (sumExpr.COUNT_SYMBOL()) {
|
1177
|
-
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1177
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'bigint');
|
1178
1178
|
const inSumExpr = (_e = sumExpr.inSumExpr()) === null || _e === void 0 ? void 0 : _e.expr();
|
1179
1179
|
if (inSumExpr) {
|
1180
1180
|
traverseExpr(inSumExpr, traverseContext);
|
@@ -1182,12 +1182,12 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1182
1182
|
return functionType;
|
1183
1183
|
}
|
1184
1184
|
if (sumExpr.SUM_SYMBOL() || sumExpr.AVG_SYMBOL()) {
|
1185
|
-
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1185
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
|
1186
1186
|
const inSumExpr = (_f = sumExpr.inSumExpr()) === null || _f === void 0 ? void 0 : _f.expr();
|
1187
1187
|
if (inSumExpr) {
|
1188
1188
|
const inSumExprType = traverseExpr(inSumExpr, traverseContext);
|
1189
1189
|
traverseContext.constraints.push({
|
1190
|
-
expression: simpleExpr.
|
1190
|
+
expression: simpleExpr.getText(),
|
1191
1191
|
type1: functionType,
|
1192
1192
|
type2: inSumExprType,
|
1193
1193
|
mostGeneralType: true,
|
@@ -1202,7 +1202,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1202
1202
|
if (sumExpr.GROUP_CONCAT_SYMBOL()) {
|
1203
1203
|
const exprList = sumExpr.exprList();
|
1204
1204
|
if (exprList) {
|
1205
|
-
exprList.
|
1205
|
+
exprList.expr_list().map(item => {
|
1206
1206
|
const exprType = traverseExpr(item, traverseContext);
|
1207
1207
|
return exprType;
|
1208
1208
|
});
|
@@ -1211,7 +1211,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1211
1211
|
in which case the result type is VARCHAR or VARBINARY.
|
1212
1212
|
*/
|
1213
1213
|
//TODO - Infer TEXT/BLOB or VARCHAR/VARBINARY
|
1214
|
-
return (0, collect_constraints_1.freshVar)(sumExpr.
|
1214
|
+
return (0, collect_constraints_1.freshVar)(sumExpr.getText(), 'varchar');
|
1215
1215
|
;
|
1216
1216
|
}
|
1217
1217
|
}
|
@@ -1220,20 +1220,20 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1220
1220
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprRuntimeFunctionContext) {
|
1221
1221
|
const runtimeFunctionCall = simpleExpr.runtimeFunctionCall();
|
1222
1222
|
if (runtimeFunctionCall.NOW_SYMBOL()) {
|
1223
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1223
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'datetime');
|
1224
1224
|
}
|
1225
1225
|
if (runtimeFunctionCall.CURDATE_SYMBOL()) {
|
1226
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1226
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date');
|
1227
1227
|
}
|
1228
1228
|
if (runtimeFunctionCall.CURTIME_SYMBOL()) {
|
1229
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1229
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'time');
|
1230
1230
|
}
|
1231
1231
|
if (runtimeFunctionCall.REPLACE_SYMBOL()) {
|
1232
|
-
const exprList = runtimeFunctionCall.
|
1232
|
+
const exprList = runtimeFunctionCall.expr_list();
|
1233
1233
|
exprList.forEach(expr => {
|
1234
1234
|
const exprType = traverseExpr(expr, traverseContext);
|
1235
1235
|
traverseContext.constraints.push({
|
1236
|
-
expression: expr.
|
1236
|
+
expression: expr.getText(),
|
1237
1237
|
type1: exprType,
|
1238
1238
|
type2: (0, collect_constraints_1.freshVar)('varchar', 'varchar')
|
1239
1239
|
});
|
@@ -1251,13 +1251,13 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1251
1251
|
paramType.type = 'date';
|
1252
1252
|
}
|
1253
1253
|
traverseContext.constraints.push({
|
1254
|
-
expression: expr.
|
1254
|
+
expression: expr.getText(),
|
1255
1255
|
type1: paramType,
|
1256
|
-
type2: (0, collect_constraints_1.freshVar)(simpleExpr.
|
1256
|
+
type2: (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date')
|
1257
1257
|
});
|
1258
1258
|
}
|
1259
1259
|
const returnType = runtimeFunctionCall.YEAR_SYMBOL() ? 'year' : 'tinyint';
|
1260
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1260
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), returnType);
|
1261
1261
|
}
|
1262
1262
|
if (runtimeFunctionCall.DATE_SYMBOL()) {
|
1263
1263
|
const expr = (_h = runtimeFunctionCall.exprWithParentheses()) === null || _h === void 0 ? void 0 : _h.expr();
|
@@ -1270,12 +1270,12 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1270
1270
|
paramType.type = 'date';
|
1271
1271
|
}
|
1272
1272
|
traverseContext.constraints.push({
|
1273
|
-
expression: expr.
|
1273
|
+
expression: expr.getText(),
|
1274
1274
|
type1: paramType,
|
1275
|
-
type2: (0, collect_constraints_1.freshVar)(simpleExpr.
|
1275
|
+
type2: (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date')
|
1276
1276
|
});
|
1277
1277
|
}
|
1278
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1278
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date');
|
1279
1279
|
}
|
1280
1280
|
if (runtimeFunctionCall.HOUR_SYMBOL() || runtimeFunctionCall.MINUTE_SYMBOL() || runtimeFunctionCall.SECOND_SYMBOL()) {
|
1281
1281
|
const expr = (_j = runtimeFunctionCall.exprWithParentheses()) === null || _j === void 0 ? void 0 : _j.expr();
|
@@ -1291,23 +1291,23 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1291
1291
|
paramType.type = 'datetime';
|
1292
1292
|
}
|
1293
1293
|
traverseContext.constraints.push({
|
1294
|
-
expression: expr.
|
1294
|
+
expression: expr.getText(),
|
1295
1295
|
type1: paramType,
|
1296
|
-
type2: (0, collect_constraints_1.freshVar)(simpleExpr.
|
1296
|
+
type2: (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'time')
|
1297
1297
|
});
|
1298
1298
|
}
|
1299
1299
|
//HOUR can return values greater than 23. Ex.: SELECT HOUR('272:59:59');
|
1300
1300
|
//https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_hour
|
1301
1301
|
const returnType = runtimeFunctionCall.HOUR_SYMBOL() ? 'int' : 'tinyint';
|
1302
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1302
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), returnType);
|
1303
1303
|
}
|
1304
1304
|
const trimFunction = runtimeFunctionCall.trimFunction();
|
1305
1305
|
if (trimFunction) {
|
1306
|
-
const exprList = trimFunction.
|
1306
|
+
const exprList = trimFunction.expr_list();
|
1307
1307
|
if (exprList.length == 1) {
|
1308
1308
|
const exprType = traverseExpr(exprList[0], traverseContext);
|
1309
1309
|
traverseContext.constraints.push({
|
1310
|
-
expression: exprList[0].
|
1310
|
+
expression: exprList[0].getText(),
|
1311
1311
|
type1: exprType,
|
1312
1312
|
type2: (0, collect_constraints_1.freshVar)('varchar', 'varchar')
|
1313
1313
|
});
|
@@ -1316,12 +1316,12 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1316
1316
|
const exprType = traverseExpr(exprList[0], traverseContext);
|
1317
1317
|
const expr2Type = traverseExpr(exprList[1], traverseContext);
|
1318
1318
|
traverseContext.constraints.push({
|
1319
|
-
expression: exprList[0].
|
1319
|
+
expression: exprList[0].getText(),
|
1320
1320
|
type1: exprType,
|
1321
1321
|
type2: (0, collect_constraints_1.freshVar)('varchar', 'varchar')
|
1322
1322
|
});
|
1323
1323
|
traverseContext.constraints.push({
|
1324
|
-
expression: exprList[1].
|
1324
|
+
expression: exprList[1].getText(),
|
1325
1325
|
type1: expr2Type,
|
1326
1326
|
type2: (0, collect_constraints_1.freshVar)('varchar', 'varchar')
|
1327
1327
|
});
|
@@ -1330,7 +1330,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1330
1330
|
}
|
1331
1331
|
const substringFunction = runtimeFunctionCall.substringFunction();
|
1332
1332
|
if (substringFunction) {
|
1333
|
-
const exprList = substringFunction.
|
1333
|
+
const exprList = substringFunction.expr_list();
|
1334
1334
|
const varcharParam = (0, collect_constraints_1.freshVar)('varchar', 'varchar');
|
1335
1335
|
const intParam = (0, collect_constraints_1.freshVar)('int', 'int');
|
1336
1336
|
const params = {
|
@@ -1346,27 +1346,27 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1346
1346
|
|| runtimeFunctionCall.DATE_SUB_SYMBOL()) {
|
1347
1347
|
//SELECT ADDDATE('2008-01-02', INTERVAL 31 DAY)
|
1348
1348
|
//SELECT ADDDATE('2008-01-02', 31)
|
1349
|
-
const expr1 = runtimeFunctionCall.expr()
|
1350
|
-
const expr2 = runtimeFunctionCall.expr()
|
1349
|
+
const expr1 = runtimeFunctionCall.expr(0);
|
1350
|
+
const expr2 = runtimeFunctionCall.expr(1);
|
1351
1351
|
const typeExpr1 = traverseExpr(expr1, traverseContext);
|
1352
1352
|
const typeExpr2 = traverseExpr(expr2, traverseContext);
|
1353
1353
|
if (typeExpr1.kind == 'TypeVar' && ((0, collect_constraints_1.isDateLiteral)(typeExpr1.name) || (0, collect_constraints_1.isDateTimeLiteral)(typeExpr1.name))) {
|
1354
1354
|
typeExpr1.type = 'datetime';
|
1355
1355
|
}
|
1356
1356
|
traverseContext.constraints.push({
|
1357
|
-
expression: expr1.
|
1357
|
+
expression: expr1.getText(),
|
1358
1358
|
type1: typeExpr1,
|
1359
1359
|
type2: (0, collect_constraints_1.freshVar)('datetime', 'datetime')
|
1360
1360
|
});
|
1361
1361
|
traverseContext.constraints.push({
|
1362
|
-
expression: expr2.
|
1362
|
+
expression: expr2.getText(),
|
1363
1363
|
type1: typeExpr2,
|
1364
1364
|
type2: (0, collect_constraints_1.freshVar)('bigint', 'bigint')
|
1365
1365
|
});
|
1366
1366
|
return (0, collect_constraints_1.freshVar)('datetime', 'datetime');
|
1367
1367
|
}
|
1368
1368
|
if (runtimeFunctionCall.COALESCE_SYMBOL()) {
|
1369
|
-
const exprList = (_k = runtimeFunctionCall.exprListWithParentheses()) === null || _k === void 0 ? void 0 : _k.exprList().
|
1369
|
+
const exprList = (_k = runtimeFunctionCall.exprListWithParentheses()) === null || _k === void 0 ? void 0 : _k.exprList().expr_list();
|
1370
1370
|
if (exprList) {
|
1371
1371
|
const paramType = (0, collect_constraints_1.freshVar)('COALESCE', 'any');
|
1372
1372
|
const params = {
|
@@ -1376,7 +1376,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1376
1376
|
const paramsTypeList = traverseExprListParameters(exprList, params, traverseContext);
|
1377
1377
|
paramsTypeList.forEach((typeVar, paramIndex) => {
|
1378
1378
|
traverseContext.constraints.push({
|
1379
|
-
expression: runtimeFunctionCall.
|
1379
|
+
expression: runtimeFunctionCall.getText() + '_param' + (paramIndex + 1),
|
1380
1380
|
type1: paramType,
|
1381
1381
|
type2: typeVar,
|
1382
1382
|
mostGeneralType: true,
|
@@ -1389,31 +1389,31 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1389
1389
|
//MOD (number, number): number
|
1390
1390
|
if (runtimeFunctionCall.MOD_SYMBOL()) {
|
1391
1391
|
const functionType = (0, collect_constraints_1.freshVar)('number', 'number');
|
1392
|
-
const exprList = runtimeFunctionCall.
|
1392
|
+
const exprList = runtimeFunctionCall.expr_list();
|
1393
1393
|
const param1 = traverseExpr(exprList[0], traverseContext);
|
1394
1394
|
const param2 = traverseExpr(exprList[1], traverseContext);
|
1395
1395
|
traverseContext.constraints.push({
|
1396
|
-
expression: simpleExpr.
|
1396
|
+
expression: simpleExpr.getText(),
|
1397
1397
|
type1: (0, collect_constraints_1.freshVar)('number', 'number'),
|
1398
1398
|
type2: param1,
|
1399
1399
|
mostGeneralType: true,
|
1400
1400
|
coercionType: 'Numeric'
|
1401
1401
|
});
|
1402
1402
|
traverseContext.constraints.push({
|
1403
|
-
expression: simpleExpr.
|
1403
|
+
expression: simpleExpr.getText(),
|
1404
1404
|
type1: (0, collect_constraints_1.freshVar)('number', 'number'),
|
1405
1405
|
type2: param2,
|
1406
1406
|
mostGeneralType: true,
|
1407
1407
|
coercionType: 'Numeric'
|
1408
1408
|
});
|
1409
1409
|
traverseContext.constraints.push({
|
1410
|
-
expression: simpleExpr.
|
1410
|
+
expression: simpleExpr.getText(),
|
1411
1411
|
type1: functionType,
|
1412
1412
|
type2: param1,
|
1413
1413
|
mostGeneralType: true
|
1414
1414
|
});
|
1415
1415
|
traverseContext.constraints.push({
|
1416
|
-
expression: simpleExpr.
|
1416
|
+
expression: simpleExpr.getText(),
|
1417
1417
|
type1: functionType,
|
1418
1418
|
type2: param2,
|
1419
1419
|
mostGeneralType: true
|
@@ -1421,7 +1421,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1421
1421
|
return functionType;
|
1422
1422
|
}
|
1423
1423
|
if (runtimeFunctionCall.IF_SYMBOL()) {
|
1424
|
-
const exprList = runtimeFunctionCall.
|
1424
|
+
const exprList = runtimeFunctionCall.expr_list();
|
1425
1425
|
const expr1 = exprList[0];
|
1426
1426
|
const expr2 = exprList[1];
|
1427
1427
|
const expr3 = exprList[2];
|
@@ -1429,19 +1429,19 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1429
1429
|
const expr2Type = traverseExpr(expr2, traverseContext);
|
1430
1430
|
const expr3Type = traverseExpr(expr3, traverseContext);
|
1431
1431
|
traverseContext.constraints.push({
|
1432
|
-
expression: runtimeFunctionCall.
|
1432
|
+
expression: runtimeFunctionCall.getText(),
|
1433
1433
|
type1: expr2Type,
|
1434
1434
|
type2: expr3Type,
|
1435
1435
|
mostGeneralType: true
|
1436
1436
|
});
|
1437
1437
|
return expr2Type;
|
1438
1438
|
}
|
1439
|
-
throw Error('Function not supported: ' + runtimeFunctionCall.
|
1439
|
+
throw Error('Function not supported: ' + runtimeFunctionCall.getText());
|
1440
1440
|
}
|
1441
1441
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprFunctionContext) {
|
1442
1442
|
const functionIdentifier = (0, collect_constraints_1.getFunctionName)(simpleExpr);
|
1443
1443
|
if (functionIdentifier === 'concat_ws' || (functionIdentifier === null || functionIdentifier === void 0 ? void 0 : functionIdentifier.toLowerCase()) === 'concat') {
|
1444
|
-
const varcharType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1444
|
+
const varcharType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'varchar');
|
1445
1445
|
const params = {
|
1446
1446
|
kind: 'VariableLengthParams',
|
1447
1447
|
paramType: 'varchar'
|
@@ -1450,9 +1450,9 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1450
1450
|
return varcharType;
|
1451
1451
|
}
|
1452
1452
|
if (functionIdentifier === 'avg') {
|
1453
|
-
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1453
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
|
1454
1454
|
traverseContext.constraints.push({
|
1455
|
-
expression: simpleExpr.
|
1455
|
+
expression: simpleExpr.getText(),
|
1456
1456
|
type1: functionType,
|
1457
1457
|
type2: (0, collect_constraints_1.freshVar)('decimal', 'decimal'),
|
1458
1458
|
mostGeneralType: true
|
@@ -1465,7 +1465,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1465
1465
|
return functionType;
|
1466
1466
|
}
|
1467
1467
|
if (functionIdentifier === 'round') {
|
1468
|
-
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.
|
1468
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
|
1469
1469
|
const params = {
|
1470
1470
|
kind: 'FixedLengthParams',
|
1471
1471
|
paramsType: [functionType]
|
@@ -1473,7 +1473,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1473
1473
|
const paramsType = walkFunctionParameters(simpleExpr, params, traverseContext);
|
1474
1474
|
//The return value has the same type as the first argument
|
1475
1475
|
traverseContext.constraints.push({
|
1476
|
-
expression: simpleExpr.
|
1476
|
+
expression: simpleExpr.getText(),
|
1477
1477
|
type1: functionType,
|
1478
1478
|
type2: paramsType[0], //type of the first parameter
|
1479
1479
|
mostGeneralType: true
|
@@ -1487,7 +1487,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1487
1487
|
paramsType: [doubleParam, doubleParam]
|
1488
1488
|
};
|
1489
1489
|
walkFunctionParameters(simpleExpr, params, traverseContext);
|
1490
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1490
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'bigint');
|
1491
1491
|
}
|
1492
1492
|
if (functionIdentifier === 'str_to_date') {
|
1493
1493
|
const varcharParam = (0, collect_constraints_1.freshVar)('varchar', 'varchar');
|
@@ -1496,40 +1496,40 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1496
1496
|
paramsType: [varcharParam, varcharParam]
|
1497
1497
|
};
|
1498
1498
|
walkFunctionParameters(simpleExpr, params, traverseContext);
|
1499
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1499
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date');
|
1500
1500
|
}
|
1501
1501
|
if (functionIdentifier === 'datediff') {
|
1502
|
-
const udfExprList = (_l = simpleExpr.functionCall().udfExprList()) === null || _l === void 0 ? void 0 : _l.
|
1502
|
+
const udfExprList = (_l = simpleExpr.functionCall().udfExprList()) === null || _l === void 0 ? void 0 : _l.udfExpr_list();
|
1503
1503
|
if (udfExprList) {
|
1504
1504
|
udfExprList.forEach((inExpr) => {
|
1505
1505
|
const expr = inExpr.expr();
|
1506
1506
|
const exprType = traverseExpr(expr, traverseContext);
|
1507
1507
|
const newType = (0, collect_constraints_1.verifyDateTypesCoercion)(exprType);
|
1508
1508
|
traverseContext.constraints.push({
|
1509
|
-
expression: expr.
|
1509
|
+
expression: expr.getText(),
|
1510
1510
|
type1: newType,
|
1511
1511
|
type2: (0, collect_constraints_1.freshVar)('date', 'date'),
|
1512
1512
|
mostGeneralType: true
|
1513
1513
|
});
|
1514
1514
|
});
|
1515
1515
|
}
|
1516
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1516
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'bigint');
|
1517
1517
|
}
|
1518
1518
|
if (functionIdentifier === 'period_add' || functionIdentifier == 'period_diff') {
|
1519
|
-
const udfExprList = (_m = simpleExpr.functionCall().udfExprList()) === null || _m === void 0 ? void 0 : _m.
|
1519
|
+
const udfExprList = (_m = simpleExpr.functionCall().udfExprList()) === null || _m === void 0 ? void 0 : _m.udfExpr_list();
|
1520
1520
|
if (udfExprList) {
|
1521
1521
|
udfExprList.forEach((inExpr) => {
|
1522
1522
|
const expr = inExpr.expr();
|
1523
1523
|
const exprType = traverseExpr(expr, traverseContext);
|
1524
1524
|
traverseContext.constraints.push({
|
1525
|
-
expression: expr.
|
1525
|
+
expression: expr.getText(),
|
1526
1526
|
type1: exprType,
|
1527
1527
|
type2: (0, collect_constraints_1.freshVar)('bigint', 'bigint'),
|
1528
1528
|
mostGeneralType: true
|
1529
1529
|
});
|
1530
1530
|
});
|
1531
1531
|
}
|
1532
|
-
return (0, collect_constraints_1.freshVar)(simpleExpr.
|
1532
|
+
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'bigint');
|
1533
1533
|
}
|
1534
1534
|
if (functionIdentifier === 'lpad' || functionIdentifier == 'rpad') {
|
1535
1535
|
const varcharParam = (0, collect_constraints_1.freshVar)('varchar', 'varchar');
|
@@ -1567,11 +1567,11 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1567
1567
|
}
|
1568
1568
|
if (functionIdentifier === 'abs') {
|
1569
1569
|
const functionType = (0, collect_constraints_1.freshVar)('number', 'number');
|
1570
|
-
const udfExprList = (_o = simpleExpr.functionCall().udfExprList()) === null || _o === void 0 ? void 0 : _o.
|
1570
|
+
const udfExprList = (_o = simpleExpr.functionCall().udfExprList()) === null || _o === void 0 ? void 0 : _o.udfExpr_list();
|
1571
1571
|
udfExprList === null || udfExprList === void 0 ? void 0 : udfExprList.forEach(expr => {
|
1572
1572
|
const param1 = traverseExpr(expr.expr(), traverseContext);
|
1573
1573
|
traverseContext.constraints.push({
|
1574
|
-
expression: simpleExpr.
|
1574
|
+
expression: simpleExpr.getText(),
|
1575
1575
|
type1: functionType,
|
1576
1576
|
type2: param1,
|
1577
1577
|
mostGeneralType: true,
|
@@ -1582,11 +1582,11 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1582
1582
|
}
|
1583
1583
|
if (functionIdentifier == 'ceiling' || functionIdentifier == 'ceil') {
|
1584
1584
|
const functionType = (0, collect_constraints_1.freshVar)('number', 'number');
|
1585
|
-
const udfExprList = (_p = simpleExpr.functionCall().udfExprList()) === null || _p === void 0 ? void 0 : _p.
|
1585
|
+
const udfExprList = (_p = simpleExpr.functionCall().udfExprList()) === null || _p === void 0 ? void 0 : _p.udfExpr_list();
|
1586
1586
|
udfExprList === null || udfExprList === void 0 ? void 0 : udfExprList.forEach(expr => {
|
1587
1587
|
const param1 = traverseExpr(expr.expr(), traverseContext);
|
1588
1588
|
traverseContext.constraints.push({
|
1589
|
-
expression: simpleExpr.
|
1589
|
+
expression: simpleExpr.getText(),
|
1590
1590
|
type1: functionType,
|
1591
1591
|
type2: param1,
|
1592
1592
|
mostGeneralType: true,
|
@@ -1596,17 +1596,17 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1596
1596
|
return functionType;
|
1597
1597
|
}
|
1598
1598
|
if (functionIdentifier == 'timestampdiff') {
|
1599
|
-
const udfExprList = (_q = simpleExpr.functionCall().udfExprList()) === null || _q === void 0 ? void 0 : _q.
|
1599
|
+
const udfExprList = (_q = simpleExpr.functionCall().udfExprList()) === null || _q === void 0 ? void 0 : _q.udfExpr_list();
|
1600
1600
|
if (udfExprList) {
|
1601
1601
|
const [first, ...rest] = udfExprList;
|
1602
|
-
const unit = first.
|
1602
|
+
const unit = first.getText().trim().toLowerCase();
|
1603
1603
|
rest.forEach((inExpr, paramIndex) => {
|
1604
1604
|
const expr = inExpr.expr();
|
1605
1605
|
const exprType = traverseExpr(expr, traverseContext);
|
1606
1606
|
const newType = (0, collect_constraints_1.verifyDateTypesCoercion)(exprType);
|
1607
1607
|
//const expectedType = ['hour', 'minute', 'second'].includes(unit)? 'time' : 'datetime'
|
1608
1608
|
traverseContext.constraints.push({
|
1609
|
-
expression: expr.
|
1609
|
+
expression: expr.getText(),
|
1610
1610
|
type1: newType,
|
1611
1611
|
type2: (0, collect_constraints_1.freshVar)('datetime', 'datetime'),
|
1612
1612
|
mostGeneralType: true
|
@@ -1616,19 +1616,19 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1616
1616
|
return (0, collect_constraints_1.freshVar)('int', 'int');
|
1617
1617
|
}
|
1618
1618
|
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.
|
1619
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
|
1620
|
+
const udfExprList = (_r = simpleExpr.functionCall().udfExprList()) === null || _r === void 0 ? void 0 : _r.udfExpr_list();
|
1621
1621
|
if (udfExprList) {
|
1622
1622
|
const [expr1, expr2] = udfExprList;
|
1623
1623
|
const expr1Type = traverseExpr(expr1.expr(), traverseContext);
|
1624
1624
|
traverseContext.constraints.push({
|
1625
|
-
expression: expr1.
|
1625
|
+
expression: expr1.getText(),
|
1626
1626
|
type1: functionType,
|
1627
1627
|
type2: expr1Type
|
1628
1628
|
});
|
1629
1629
|
const expr2Type = traverseExpr(expr2.expr(), traverseContext);
|
1630
1630
|
traverseContext.constraints.push({
|
1631
|
-
expression: expr2.
|
1631
|
+
expression: expr2.getText(),
|
1632
1632
|
type1: functionType,
|
1633
1633
|
type2: expr2Type
|
1634
1634
|
});
|
@@ -1638,15 +1638,15 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1638
1638
|
if (functionIdentifier == 'md5' //md5(str) - TODO - have input constraint = string
|
1639
1639
|
|| functionIdentifier == 'hex' //md5(n or str)
|
1640
1640
|
|| 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.
|
1641
|
+
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'char');
|
1642
|
+
const udfExprList = (_s = simpleExpr.functionCall().udfExprList()) === null || _s === void 0 ? void 0 : _s.udfExpr_list();
|
1643
1643
|
if (udfExprList) {
|
1644
1644
|
const [expr1] = udfExprList;
|
1645
1645
|
const paramType = traverseExpr(expr1.expr(), traverseContext);
|
1646
1646
|
traverseContext.constraints.push({
|
1647
|
-
expression: expr1.
|
1647
|
+
expression: expr1.getText(),
|
1648
1648
|
type1: paramType,
|
1649
|
-
type2: (0, collect_constraints_1.freshVar)(expr1.
|
1649
|
+
type2: (0, collect_constraints_1.freshVar)(expr1.getText(), 'varchar')
|
1650
1650
|
});
|
1651
1651
|
}
|
1652
1652
|
return functionType;
|
@@ -1660,7 +1660,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1660
1660
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprCastContext) {
|
1661
1661
|
const castType = simpleExpr.castType();
|
1662
1662
|
if (castType.CHAR_SYMBOL()) {
|
1663
|
-
return (0, collect_constraints_1.freshVar)(castType.
|
1663
|
+
return (0, collect_constraints_1.freshVar)(castType.getText(), 'char');
|
1664
1664
|
}
|
1665
1665
|
}
|
1666
1666
|
throw Error('traverseSimpleExpr - not supported: ' + simpleExpr.constructor.name);
|
@@ -1671,7 +1671,7 @@ function traverseWindowFunctionCall(windowFunctionCall, traverseContext) {
|
|
1671
1671
|
|| windowFunctionCall.DENSE_RANK_SYMBOL()
|
1672
1672
|
|| windowFunctionCall.CUME_DIST_SYMBOL()
|
1673
1673
|
|| windowFunctionCall.PERCENT_RANK_SYMBOL()) {
|
1674
|
-
return (0, collect_constraints_1.freshVar)(windowFunctionCall.
|
1674
|
+
return (0, collect_constraints_1.freshVar)(windowFunctionCall.getText(), 'bigint');
|
1675
1675
|
}
|
1676
1676
|
const expr = windowFunctionCall.expr();
|
1677
1677
|
if (expr) {
|
@@ -1689,7 +1689,7 @@ function traverseExprListParameters(exprList, params, traverseContext) {
|
|
1689
1689
|
const exprType = traverseExpr(expr, traverseContext);
|
1690
1690
|
const paramType = params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType);
|
1691
1691
|
traverseContext.constraints.push({
|
1692
|
-
expression: expr.
|
1692
|
+
expression: expr.getText(),
|
1693
1693
|
type1: exprType,
|
1694
1694
|
type2: paramType,
|
1695
1695
|
mostGeneralType: true
|
@@ -1700,7 +1700,7 @@ function traverseExprListParameters(exprList, params, traverseContext) {
|
|
1700
1700
|
function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
|
1701
1701
|
var _a, _b;
|
1702
1702
|
const functionName = (0, collect_constraints_1.getFunctionName)(simpleExprFunction);
|
1703
|
-
const udfExprList = (_a = simpleExprFunction.functionCall().udfExprList()) === null || _a === void 0 ? void 0 : _a.
|
1703
|
+
const udfExprList = (_a = simpleExprFunction.functionCall().udfExprList()) === null || _a === void 0 ? void 0 : _a.udfExpr_list();
|
1704
1704
|
if (udfExprList) {
|
1705
1705
|
const paramTypes = udfExprList
|
1706
1706
|
.filter((undefined, paramIndex) => {
|
@@ -1710,7 +1710,7 @@ function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
|
|
1710
1710
|
const expr = inExpr.expr();
|
1711
1711
|
const exprType = traverseExpr(expr, traverseContext);
|
1712
1712
|
traverseContext.constraints.push({
|
1713
|
-
expression: expr.
|
1713
|
+
expression: expr.getText(),
|
1714
1714
|
type1: exprType,
|
1715
1715
|
type2: params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType),
|
1716
1716
|
});
|
@@ -1718,12 +1718,12 @@ function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
|
|
1718
1718
|
});
|
1719
1719
|
return paramTypes;
|
1720
1720
|
}
|
1721
|
-
const exprList = (_b = simpleExprFunction.functionCall().exprList()) === null || _b === void 0 ? void 0 : _b.
|
1721
|
+
const exprList = (_b = simpleExprFunction.functionCall().exprList()) === null || _b === void 0 ? void 0 : _b.expr_list();
|
1722
1722
|
if (exprList) {
|
1723
1723
|
const paramTypes = exprList.map((inExpr, paramIndex) => {
|
1724
1724
|
const inSumExprType = traverseExpr(inExpr, traverseContext);
|
1725
1725
|
traverseContext.constraints.push({
|
1726
|
-
expression: inExpr.
|
1726
|
+
expression: inExpr.getText(),
|
1727
1727
|
type1: params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType),
|
1728
1728
|
type2: inSumExprType,
|
1729
1729
|
mostGeneralType: true
|
@@ -1779,10 +1779,10 @@ function isMultipleRowResult(selectStatement, fromColumns) {
|
|
1779
1779
|
if (!fromClause) {
|
1780
1780
|
return false;
|
1781
1781
|
}
|
1782
|
-
if (querySpecs[0].selectItemList().
|
1782
|
+
if (querySpecs[0].selectItemList().getChildCount() == 1) {
|
1783
1783
|
const selectItem = querySpecs[0].selectItemList().getChild(0);
|
1784
1784
|
//if selectItem = * (TerminalNode) childCount = 0; selectItem.expr() throws exception
|
1785
|
-
const expr = selectItem.
|
1785
|
+
const expr = selectItem.getChildCount() > 0 ? selectItem.expr() : null;
|
1786
1786
|
if (expr) {
|
1787
1787
|
//SUM, MAX... WITHOUT GROUP BY are multipleRowsResult = false
|
1788
1788
|
const groupBy = querySpecs[0].groupByClause();
|
@@ -1791,7 +1791,7 @@ function isMultipleRowResult(selectStatement, fromColumns) {
|
|
1791
1791
|
}
|
1792
1792
|
}
|
1793
1793
|
}
|
1794
|
-
const joinedTable = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference()
|
1794
|
+
const joinedTable = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference(0).joinedTable_list();
|
1795
1795
|
if (joinedTable && joinedTable.length > 0) {
|
1796
1796
|
return true;
|
1797
1797
|
}
|
@@ -1806,10 +1806,10 @@ function isMultipleRowResult(selectStatement, fromColumns) {
|
|
1806
1806
|
exports.isMultipleRowResult = isMultipleRowResult;
|
1807
1807
|
function isLimitOne(selectStatement) {
|
1808
1808
|
const limitOptions = (0, parse_1.getLimitOptions)(selectStatement);
|
1809
|
-
if (limitOptions.length == 1 && limitOptions[0].
|
1809
|
+
if (limitOptions.length == 1 && limitOptions[0].getText() == '1') {
|
1810
1810
|
return true;
|
1811
1811
|
}
|
1812
|
-
if (limitOptions.length == 2 && limitOptions[1].
|
1812
|
+
if (limitOptions.length == 2 && limitOptions[1].getText() == '1') {
|
1813
1813
|
return true;
|
1814
1814
|
}
|
1815
1815
|
return false;
|
@@ -1833,7 +1833,7 @@ function verifyMultipleResult2(exprContext, fromColumns) {
|
|
1833
1833
|
return true;
|
1834
1834
|
}
|
1835
1835
|
if (exprContext instanceof ts_mysql_parser_1.ExprAndContext) {
|
1836
|
-
const oneIsSingleResult = exprContext.
|
1836
|
+
const oneIsSingleResult = exprContext.expr_list().some(expr => verifyMultipleResult2(expr, fromColumns) == false);
|
1837
1837
|
return oneIsSingleResult == false;
|
1838
1838
|
}
|
1839
1839
|
// if (exprContext instanceof ExprXorContext) {
|
@@ -1848,7 +1848,7 @@ exports.verifyMultipleResult2 = verifyMultipleResult2;
|
|
1848
1848
|
function isUniqueKeyComparation(compare, fromColumns) {
|
1849
1849
|
const tokens = (0, select_columns_1.getSimpleExpressions)(compare);
|
1850
1850
|
if (tokens.length == 1 && tokens[0] instanceof ts_mysql_parser_1.SimpleExprColumnRefContext) {
|
1851
|
-
const fieldName = (0, select_columns_1.splitName)(tokens[0].
|
1851
|
+
const fieldName = (0, select_columns_1.splitName)(tokens[0].getText());
|
1852
1852
|
const col = (0, select_columns_1.findColumn)(fieldName, fromColumns);
|
1853
1853
|
if (col.columnKey == 'PRI' || col.columnKey == 'UNI') { //TODO - UNIQUE
|
1854
1854
|
return true; //isUniqueKeyComparation = true
|