typesql-cli 0.6.19 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/code-generator.d.ts +7 -1
- package/code-generator.d.ts.map +1 -1
- package/code-generator.js +237 -22
- package/code-generator.js.map +1 -1
- package/describe-dynamic-query.d.ts +3 -0
- package/describe-dynamic-query.d.ts.map +1 -0
- package/describe-dynamic-query.js +72 -0
- package/describe-dynamic-query.js.map +1 -0
- package/describe-query.d.ts +1 -1
- package/describe-query.d.ts.map +1 -1
- package/describe-query.js +9 -5
- package/describe-query.js.map +1 -1
- package/mysql-query-analyzer/infer-column-nullability.d.ts.map +1 -1
- package/mysql-query-analyzer/infer-column-nullability.js +3 -0
- package/mysql-query-analyzer/infer-column-nullability.js.map +1 -1
- package/mysql-query-analyzer/parse.d.ts.map +1 -1
- package/mysql-query-analyzer/parse.js +44 -1
- package/mysql-query-analyzer/parse.js.map +1 -1
- package/mysql-query-analyzer/select-columns.d.ts +7 -1
- package/mysql-query-analyzer/select-columns.d.ts.map +1 -1
- package/mysql-query-analyzer/select-columns.js +109 -2
- package/mysql-query-analyzer/select-columns.js.map +1 -1
- package/mysql-query-analyzer/traverse.d.ts +7 -6
- package/mysql-query-analyzer/traverse.d.ts.map +1 -1
- package/mysql-query-analyzer/traverse.js +393 -236
- package/mysql-query-analyzer/traverse.js.map +1 -1
- package/mysql-query-analyzer/types.d.ts +42 -0
- package/mysql-query-analyzer/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/ts-dynamic-query-descriptor.d.ts +5 -0
- package/ts-dynamic-query-descriptor.d.ts.map +1 -0
- package/ts-dynamic-query-descriptor.js +37 -0
- package/ts-dynamic-query-descriptor.js.map +1 -0
- package/types.d.ts +2 -1
- package/types.d.ts.map +1 -1
- package/mysql-query-analyzer/tempCodeRunnerFile.d.ts +0 -1
- package/mysql-query-analyzer/tempCodeRunnerFile.d.ts.map +0 -1
- package/mysql-query-analyzer/tempCodeRunnerFile.js +0 -5
- package/mysql-query-analyzer/tempCodeRunnerFile.js.map +0 -1
@@ -13,36 +13,48 @@ function traverseQueryContext(queryContext, dbSchema, namedParameters) {
|
|
13
13
|
var _a, _b, _c, _d;
|
14
14
|
const constraints = [];
|
15
15
|
const parameters = [];
|
16
|
+
const traverseContext = {
|
17
|
+
constraints,
|
18
|
+
dbSchema,
|
19
|
+
parameters,
|
20
|
+
fromColumns: [],
|
21
|
+
withSchema: [],
|
22
|
+
dynamicSqlInfo: {
|
23
|
+
select: [],
|
24
|
+
from: [],
|
25
|
+
where: []
|
26
|
+
}
|
27
|
+
};
|
16
28
|
const selectStatement = (_a = queryContext.simpleStatement()) === null || _a === void 0 ? void 0 : _a.selectStatement();
|
17
29
|
if (selectStatement) {
|
18
|
-
const typeInfer = traverseSelectStatement(selectStatement,
|
30
|
+
const typeInfer = traverseSelectStatement(selectStatement, traverseContext, namedParameters);
|
19
31
|
return typeInfer;
|
20
32
|
}
|
21
33
|
const insertStatement = (_b = queryContext.simpleStatement()) === null || _b === void 0 ? void 0 : _b.insertStatement();
|
22
34
|
if (insertStatement) {
|
23
|
-
return traverseInsertStatement(insertStatement,
|
35
|
+
return traverseInsertStatement(insertStatement, traverseContext);
|
24
36
|
}
|
25
37
|
const updateStatement = (_c = queryContext.simpleStatement()) === null || _c === void 0 ? void 0 : _c.updateStatement();
|
26
38
|
if (updateStatement) {
|
27
|
-
const typeInfer = traverseUpdateStatement(updateStatement,
|
39
|
+
const typeInfer = traverseUpdateStatement(updateStatement, traverseContext, namedParameters);
|
28
40
|
return typeInfer;
|
29
41
|
}
|
30
42
|
const deleteStatement = (_d = queryContext.simpleStatement()) === null || _d === void 0 ? void 0 : _d.deleteStatement();
|
31
43
|
if (deleteStatement) {
|
32
|
-
const typeInfer = traverseDeleteStatement(deleteStatement,
|
44
|
+
const typeInfer = traverseDeleteStatement(deleteStatement, traverseContext);
|
33
45
|
return typeInfer;
|
34
46
|
}
|
35
47
|
throw Error('traverseSql - not supported: ' + queryContext.constructor.name);
|
36
48
|
}
|
37
49
|
exports.traverseQueryContext = traverseQueryContext;
|
38
|
-
function traverseSelectStatement(selectStatement,
|
50
|
+
function traverseSelectStatement(selectStatement, traverseContext, namedParameters) {
|
39
51
|
const queryExpression = selectStatement.queryExpression();
|
40
52
|
if (queryExpression) {
|
41
|
-
const result = traverseQueryExpression(queryExpression,
|
53
|
+
const result = traverseQueryExpression(queryExpression, traverseContext);
|
42
54
|
const orderByParameters = (0, parse_1.extractOrderByParameters)(selectStatement);
|
43
55
|
const limitParameters = (0, parse_1.extractLimitParameters)(selectStatement);
|
44
56
|
const paramInference = (0, infer_param_nullability_1.inferParamNullabilityQueryExpression)(queryExpression);
|
45
|
-
const allParameters = parameters
|
57
|
+
const allParameters = traverseContext.parameters
|
46
58
|
.map((param, index) => {
|
47
59
|
const param2 = {
|
48
60
|
name: param.name,
|
@@ -55,7 +67,7 @@ function traverseSelectStatement(selectStatement, constraints, parameters, dbSch
|
|
55
67
|
const paramIndexes = (0, util_1.getParameterIndexes)(namedParameters.slice(0, allParameters.length)); //for [a, a, b, a] will return a: [0, 1, 3]; b: [2]
|
56
68
|
paramIndexes.forEach(paramIndex => {
|
57
69
|
(0, util_1.getPairWise)(paramIndex.indexes, (cur, next) => {
|
58
|
-
constraints.push({
|
70
|
+
traverseContext.constraints.push({
|
59
71
|
expression: paramIndex.paramName,
|
60
72
|
type1: allParameters[cur].type,
|
61
73
|
type2: allParameters[next].type
|
@@ -65,11 +77,12 @@ function traverseSelectStatement(selectStatement, constraints, parameters, dbSch
|
|
65
77
|
const isMultiRow = isMultipleRowResult(selectStatement, result.fromColumns);
|
66
78
|
const traverseResult = {
|
67
79
|
type: 'Select',
|
68
|
-
constraints,
|
80
|
+
constraints: traverseContext.constraints,
|
69
81
|
columns: result.columns,
|
70
82
|
parameters: allParameters,
|
71
83
|
limitParameters,
|
72
|
-
isMultiRow
|
84
|
+
isMultiRow,
|
85
|
+
dynamicSqlInfo: traverseContext.dynamicSqlInfo
|
73
86
|
};
|
74
87
|
const orderByColumns = orderByParameters.length > 0 ? getOrderByColumns(result.fromColumns, result.columns) : undefined;
|
75
88
|
if (orderByColumns) {
|
@@ -79,7 +92,7 @@ function traverseSelectStatement(selectStatement, constraints, parameters, dbSch
|
|
79
92
|
}
|
80
93
|
throw Error('traverseSelectStatement - not supported: ' + selectStatement.text);
|
81
94
|
}
|
82
|
-
function traverseInsertStatement(insertStatement,
|
95
|
+
function traverseInsertStatement(insertStatement, traverseContext) {
|
83
96
|
var _a, _b;
|
84
97
|
const allParameters = [];
|
85
98
|
const paramsNullability = {};
|
@@ -89,7 +102,7 @@ function traverseInsertStatement(insertStatement, constraints, parameters, dbSch
|
|
89
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.text == 'DEFAULT')) || []; });
|
90
103
|
}
|
91
104
|
const insertIntoTable = (0, collect_constraints_1.getInsertIntoTable)(insertStatement);
|
92
|
-
const fromColumns = dbSchema
|
105
|
+
const fromColumns = traverseContext.dbSchema
|
93
106
|
.filter(c => c.table == insertIntoTable)
|
94
107
|
.map(c => {
|
95
108
|
const col = {
|
@@ -102,17 +115,18 @@ function traverseInsertStatement(insertStatement, constraints, parameters, dbSch
|
|
102
115
|
return col;
|
103
116
|
});
|
104
117
|
const insertColumns = (0, collect_constraints_1.getInsertColumns)(insertStatement, fromColumns);
|
118
|
+
traverseContext.fromColumns = insertColumns;
|
105
119
|
exprOrDefaultList.forEach(exprOrDefault => {
|
106
120
|
exprOrDefault.forEach((expr, index) => {
|
107
121
|
const column = insertColumns[index];
|
108
122
|
if (expr instanceof ts_mysql_parser_1.ExprContext) {
|
109
|
-
const numberParamsBefore = parameters.length;
|
110
|
-
const exprType = traverseExpr(expr,
|
123
|
+
const numberParamsBefore = traverseContext.parameters.length;
|
124
|
+
const exprType = traverseExpr(expr, traverseContext);
|
111
125
|
const paramNullabilityExpr = (0, infer_param_nullability_1.inferParamNullability)(expr);
|
112
|
-
parameters.slice(numberParamsBefore).forEach(param => {
|
126
|
+
traverseContext.parameters.slice(numberParamsBefore).forEach(param => {
|
113
127
|
paramsNullability[param.id] = paramNullabilityExpr.every(n => n) && column.notNull;
|
114
128
|
});
|
115
|
-
constraints.push({
|
129
|
+
traverseContext.constraints.push({
|
116
130
|
expression: expr.text,
|
117
131
|
//TODO - CHANGING ORDER SHOULDN'T AFFECT THE TYPE INFERENCE
|
118
132
|
type1: exprType.kind == 'TypeOperator' ? exprType.types[0] : exprType,
|
@@ -129,13 +143,13 @@ function traverseInsertStatement(insertStatement, constraints, parameters, dbSch
|
|
129
143
|
const field = (0, select_columns_1.splitName)(columnName);
|
130
144
|
const expr = updateElement.expr();
|
131
145
|
if (expr) {
|
132
|
-
const numberParamsBefore = parameters.length;
|
133
|
-
const exprType = traverseExpr(expr,
|
146
|
+
const numberParamsBefore = traverseContext.parameters.length;
|
147
|
+
const exprType = traverseExpr(expr, traverseContext);
|
134
148
|
const column = (0, select_columns_1.findColumn)(field, fromColumns);
|
135
|
-
parameters.slice(numberParamsBefore).forEach(param => {
|
149
|
+
traverseContext.parameters.slice(numberParamsBefore).forEach(param => {
|
136
150
|
paramsNullability[param.id] = column.notNull;
|
137
151
|
});
|
138
|
-
constraints.push({
|
152
|
+
traverseContext.constraints.push({
|
139
153
|
expression: expr.text,
|
140
154
|
type1: exprType,
|
141
155
|
type2: (0, collect_constraints_1.freshVar)(column.columnName, column.columnType.type)
|
@@ -145,29 +159,29 @@ function traverseInsertStatement(insertStatement, constraints, parameters, dbSch
|
|
145
159
|
const insertQueryExpression = insertStatement.insertQueryExpression();
|
146
160
|
if (insertQueryExpression) {
|
147
161
|
//TODO - REMOVE numberParamsBefore (walk first insertQueryExpression)
|
148
|
-
const numberParamsBefore = parameters.length;
|
149
|
-
const exprTypes = traverseInsertQueryExpression(insertQueryExpression,
|
162
|
+
const numberParamsBefore = traverseContext.parameters.length;
|
163
|
+
const exprTypes = traverseInsertQueryExpression(insertQueryExpression, traverseContext);
|
150
164
|
exprTypes.columns.forEach((type, index) => {
|
151
165
|
const column = insertColumns[index];
|
152
166
|
if (type.type.kind == 'TypeVar') {
|
153
167
|
paramsNullability[type.type.id] = column.notNull;
|
154
168
|
}
|
155
|
-
constraints.push({
|
169
|
+
traverseContext.constraints.push({
|
156
170
|
expression: insertQueryExpression.text,
|
157
171
|
type1: type.type,
|
158
172
|
type2: (0, collect_constraints_1.freshVar)(column.columnName, column.columnType.type)
|
159
173
|
});
|
160
174
|
});
|
161
175
|
const paramNullabilityExpr = (0, infer_param_nullability_1.inferParamNullabilityQuery)(insertQueryExpression);
|
162
|
-
parameters.slice(numberParamsBefore).forEach((param, index) => {
|
176
|
+
traverseContext.parameters.slice(numberParamsBefore).forEach((param, index) => {
|
163
177
|
if (paramsNullability[param.id] == null) {
|
164
178
|
paramsNullability[param.id] = paramNullabilityExpr[index];
|
165
179
|
}
|
166
180
|
});
|
167
181
|
}
|
168
|
-
const typeInfo = (0, collect_constraints_1.generateTypeInfo)(parameters, constraints);
|
182
|
+
const typeInfo = (0, collect_constraints_1.generateTypeInfo)(traverseContext.parameters, traverseContext.constraints);
|
169
183
|
typeInfo.forEach((param, index) => {
|
170
|
-
const paramId = parameters[index].id;
|
184
|
+
const paramId = traverseContext.parameters[index].id;
|
171
185
|
allParameters.push({
|
172
186
|
name: 'param' + (allParameters.length + 1),
|
173
187
|
columnType: (0, describe_query_1.verifyNotInferred)(param),
|
@@ -176,40 +190,41 @@ function traverseInsertStatement(insertStatement, constraints, parameters, dbSch
|
|
176
190
|
});
|
177
191
|
const typeInferenceResult = {
|
178
192
|
type: 'Insert',
|
179
|
-
constraints: constraints,
|
193
|
+
constraints: traverseContext.constraints,
|
180
194
|
parameters: allParameters
|
181
195
|
};
|
182
196
|
return typeInferenceResult;
|
183
197
|
}
|
184
198
|
exports.traverseInsertStatement = traverseInsertStatement;
|
185
|
-
function traverseUpdateStatement(updateStatement,
|
199
|
+
function traverseUpdateStatement(updateStatement, traverseContext, namedParamters) {
|
186
200
|
var _a;
|
187
201
|
const updateElement = updateStatement.updateList().updateElement();
|
188
202
|
const withClause = updateStatement.withClause();
|
189
203
|
const withSchema = [];
|
190
204
|
if (withClause) {
|
191
|
-
traverseWithClause(withClause,
|
205
|
+
traverseWithClause(withClause, traverseContext);
|
192
206
|
}
|
193
|
-
const updateColumns = getUpdateColumns(updateStatement,
|
207
|
+
const updateColumns = getUpdateColumns(updateStatement, traverseContext);
|
208
|
+
traverseContext.fromColumns = updateColumns;
|
194
209
|
const dataTypes = [];
|
195
210
|
const whereParameters = [];
|
196
|
-
const paramsBefore = parameters.length;
|
211
|
+
const paramsBefore = traverseContext.parameters.length;
|
197
212
|
const whereExpr = (_a = updateStatement.whereClause()) === null || _a === void 0 ? void 0 : _a.expr();
|
198
213
|
const paramNullability = (0, infer_param_nullability_1.inferParamNullability)(updateStatement);
|
199
214
|
updateElement.forEach(updateElement => {
|
200
215
|
const expr = updateElement.expr();
|
201
216
|
if (expr) {
|
202
|
-
const paramBeforeExpr = parameters.length;
|
203
|
-
const result = traverseExpr(expr,
|
217
|
+
const paramBeforeExpr = traverseContext.parameters.length;
|
218
|
+
const result = traverseExpr(expr, traverseContext);
|
204
219
|
const columnName = updateElement.columnRef().text;
|
205
220
|
const field = (0, select_columns_1.splitName)(columnName);
|
206
221
|
const column = (0, select_columns_1.findColumn)(field, updateColumns);
|
207
|
-
constraints.push({
|
222
|
+
traverseContext.constraints.push({
|
208
223
|
expression: updateStatement.text,
|
209
224
|
type1: result,
|
210
225
|
type2: column.columnType //freshVar(column.columnName, )
|
211
226
|
});
|
212
|
-
parameters.slice(paramBeforeExpr, parameters.length).forEach((param, index) => {
|
227
|
+
traverseContext.parameters.slice(paramBeforeExpr, traverseContext.parameters.length).forEach((param, index) => {
|
213
228
|
dataTypes.push({
|
214
229
|
name: namedParamters[paramBeforeExpr + index] || field.name,
|
215
230
|
type: param,
|
@@ -219,11 +234,11 @@ function traverseUpdateStatement(updateStatement, constraints, parameters, dbSch
|
|
219
234
|
});
|
220
235
|
}
|
221
236
|
});
|
222
|
-
const paramsAfter = parameters.length;
|
237
|
+
const paramsAfter = traverseContext.parameters.length;
|
223
238
|
if (whereExpr) {
|
224
|
-
traverseExpr(whereExpr,
|
239
|
+
traverseExpr(whereExpr, traverseContext);
|
225
240
|
}
|
226
|
-
parameters.slice(0, paramsBefore).forEach((param, index) => {
|
241
|
+
traverseContext.parameters.slice(0, paramsBefore).forEach((param, index) => {
|
227
242
|
whereParameters.push({
|
228
243
|
name: namedParamters[index] || 'param' + (whereParameters.length + 1),
|
229
244
|
type: param,
|
@@ -231,7 +246,7 @@ function traverseUpdateStatement(updateStatement, constraints, parameters, dbSch
|
|
231
246
|
table: ''
|
232
247
|
});
|
233
248
|
});
|
234
|
-
parameters.slice(paramsAfter).forEach((param, index) => {
|
249
|
+
traverseContext.parameters.slice(paramsAfter).forEach((param, index) => {
|
235
250
|
whereParameters.push({
|
236
251
|
name: namedParamters[paramsAfter + index] || 'param' + (whereParameters.length + 1),
|
237
252
|
type: param,
|
@@ -241,20 +256,21 @@ function traverseUpdateStatement(updateStatement, constraints, parameters, dbSch
|
|
241
256
|
});
|
242
257
|
const typeInferenceResult = {
|
243
258
|
type: 'Update',
|
244
|
-
constraints,
|
259
|
+
constraints: traverseContext.constraints,
|
245
260
|
data: dataTypes,
|
246
261
|
parameters: whereParameters
|
247
262
|
};
|
248
263
|
return typeInferenceResult;
|
249
264
|
}
|
250
|
-
function traverseDeleteStatement(deleteStatement,
|
265
|
+
function traverseDeleteStatement(deleteStatement, traverseContext) {
|
251
266
|
var _a;
|
252
267
|
const whereExpr = (_a = deleteStatement.whereClause()) === null || _a === void 0 ? void 0 : _a.expr();
|
253
|
-
const deleteColumns = (0, collect_constraints_1.getDeleteColumns)(deleteStatement, dbSchema);
|
268
|
+
const deleteColumns = (0, collect_constraints_1.getDeleteColumns)(deleteStatement, traverseContext.dbSchema);
|
269
|
+
traverseContext.fromColumns = deleteColumns;
|
254
270
|
const allParameters = [];
|
255
271
|
if (whereExpr) {
|
256
|
-
traverseExpr(whereExpr,
|
257
|
-
const typeInfo = (0, collect_constraints_1.generateTypeInfo)(parameters, constraints);
|
272
|
+
traverseExpr(whereExpr, traverseContext);
|
273
|
+
const typeInfo = (0, collect_constraints_1.generateTypeInfo)(traverseContext.parameters, traverseContext.constraints);
|
258
274
|
const paramNullability = (0, infer_param_nullability_1.inferParamNullability)(whereExpr);
|
259
275
|
typeInfo.forEach((param, paramIndex) => {
|
260
276
|
allParameters.push({
|
@@ -266,56 +282,56 @@ function traverseDeleteStatement(deleteStatement, constraints, parameters, dbSch
|
|
266
282
|
}
|
267
283
|
const typeInferenceResult = {
|
268
284
|
type: 'Delete',
|
269
|
-
constraints,
|
285
|
+
constraints: traverseContext.constraints,
|
270
286
|
parameters: allParameters
|
271
287
|
};
|
272
288
|
return typeInferenceResult;
|
273
289
|
}
|
274
290
|
exports.traverseDeleteStatement = traverseDeleteStatement;
|
275
|
-
function getUpdateColumns(updateStatement,
|
291
|
+
function getUpdateColumns(updateStatement, traverseContext) {
|
276
292
|
const tableReferences = updateStatement.tableReferenceList().tableReference();
|
277
|
-
const columns = traverseTableReferenceList(tableReferences,
|
293
|
+
const columns = traverseTableReferenceList(tableReferences, traverseContext, null);
|
278
294
|
return columns;
|
279
295
|
}
|
280
296
|
exports.getUpdateColumns = getUpdateColumns;
|
281
|
-
function traverseInsertQueryExpression(insertQueryExpression,
|
297
|
+
function traverseInsertQueryExpression(insertQueryExpression, traverseContext) {
|
282
298
|
const queryExpressionOrParens = insertQueryExpression.queryExpressionOrParens();
|
283
|
-
return traverseQueryExpressionOrParens(queryExpressionOrParens,
|
299
|
+
return traverseQueryExpressionOrParens(queryExpressionOrParens, traverseContext);
|
284
300
|
}
|
285
|
-
function traverseQueryExpressionOrParens(queryExpressionOrParens,
|
301
|
+
function traverseQueryExpressionOrParens(queryExpressionOrParens, traverseContext) {
|
286
302
|
const queryExpression = queryExpressionOrParens.queryExpression();
|
287
303
|
if (queryExpression) {
|
288
|
-
return traverseQueryExpression(queryExpression,
|
304
|
+
return traverseQueryExpression(queryExpression, traverseContext);
|
289
305
|
}
|
290
306
|
const queryEpressionParens = queryExpressionOrParens.queryExpressionParens();
|
291
307
|
if (queryEpressionParens) {
|
292
|
-
return traverseQueryExpressionParens(queryEpressionParens,
|
308
|
+
return traverseQueryExpressionParens(queryEpressionParens, traverseContext);
|
293
309
|
}
|
294
310
|
throw Error("walkQueryExpressionOrParens");
|
295
311
|
}
|
296
|
-
function traverseQueryExpression(queryExpression,
|
312
|
+
function traverseQueryExpression(queryExpression, traverseContext, subQuery = false, recursiveNames) {
|
297
313
|
const withClause = queryExpression.withClause();
|
298
314
|
if (withClause) {
|
299
|
-
traverseWithClause(withClause,
|
315
|
+
traverseWithClause(withClause, traverseContext);
|
300
316
|
}
|
301
317
|
const queryExpressionBody = queryExpression.queryExpressionBody();
|
302
318
|
if (queryExpressionBody) {
|
303
|
-
return traverseQueryExpressionBody(queryExpressionBody,
|
319
|
+
return traverseQueryExpressionBody(queryExpressionBody, traverseContext, subQuery, recursiveNames);
|
304
320
|
}
|
305
321
|
const queryExpressionParens = queryExpression.queryExpressionParens();
|
306
322
|
if (queryExpressionParens) {
|
307
|
-
return traverseQueryExpressionParens(queryExpressionParens,
|
323
|
+
return traverseQueryExpressionParens(queryExpressionParens, traverseContext, recursiveNames);
|
308
324
|
}
|
309
325
|
throw Error("walkQueryExpression");
|
310
326
|
}
|
311
|
-
function traverseQueryExpressionParens(queryExpressionParens,
|
327
|
+
function traverseQueryExpressionParens(queryExpressionParens, traverseContext, recursiveNames) {
|
312
328
|
const queryExpression = queryExpressionParens.queryExpression();
|
313
329
|
if (queryExpression) {
|
314
|
-
return traverseQueryExpression(queryExpression,
|
330
|
+
return traverseQueryExpression(queryExpression, traverseContext, false, recursiveNames);
|
315
331
|
}
|
316
332
|
const queryExpressionParens2 = queryExpressionParens.queryExpressionParens();
|
317
333
|
if (queryExpressionParens2) {
|
318
|
-
return traverseQueryExpressionParens(queryExpressionParens,
|
334
|
+
return traverseQueryExpressionParens(queryExpressionParens, traverseContext, recursiveNames);
|
319
335
|
}
|
320
336
|
throw Error("walkQueryExpressionParens");
|
321
337
|
}
|
@@ -323,19 +339,19 @@ function createUnionVar(type, name) {
|
|
323
339
|
const newVar = Object.assign(Object.assign({}, type), { name: name, table: '' });
|
324
340
|
return newVar;
|
325
341
|
}
|
326
|
-
function traverseQueryExpressionBody(queryExpressionBody,
|
342
|
+
function traverseQueryExpressionBody(queryExpressionBody, traverseContext, subQuery = false, recursiveNames) {
|
327
343
|
const allQueries = (0, parse_1.getAllQuerySpecificationsFromSelectStatement)(queryExpressionBody);
|
328
344
|
const [first, ...unionQuerySpec] = allQueries;
|
329
|
-
const mainQueryResult = traverseQuerySpecification(first,
|
345
|
+
const mainQueryResult = traverseQuerySpecification(first, traverseContext, subQuery);
|
330
346
|
const resultTypes = mainQueryResult.columns.map((t, index) => unionQuerySpec.length == 0 ? t.type : createUnionVar(t.type, recursiveNames && recursiveNames.length > 0 ? recursiveNames[index] : t.name)); //TODO mover para traversequeryspecificat?
|
331
347
|
for (let queryIndex = 0; queryIndex < unionQuerySpec.length; queryIndex++) {
|
332
348
|
const columnNames = recursiveNames && recursiveNames.length > 0 ? recursiveNames : mainQueryResult.columns.map(col => col.name);
|
333
349
|
const newFromColumns = recursiveNames ? renameFromColumns(mainQueryResult.columns, columnNames) : [];
|
334
350
|
const unionQuery = unionQuerySpec[queryIndex];
|
335
|
-
const unionResult = traverseQuerySpecification(unionQuery,
|
351
|
+
const unionResult = traverseQuerySpecification(unionQuery, Object.assign(Object.assign({}, traverseContext), { fromColumns: newFromColumns }), subQuery);
|
336
352
|
resultTypes.forEach((t2, index) => {
|
337
353
|
mainQueryResult.columns[index].notNull = mainQueryResult.columns[index].notNull && unionResult.columns[index].notNull;
|
338
|
-
constraints.push({
|
354
|
+
traverseContext.constraints.push({
|
339
355
|
expression: 'union',
|
340
356
|
coercionType: 'Union',
|
341
357
|
mostGeneralType: true,
|
@@ -372,18 +388,18 @@ function renameFromColumns(fromColumns, recursiveNames) {
|
|
372
388
|
});
|
373
389
|
return newFromColumns;
|
374
390
|
}
|
375
|
-
function traverseQuerySpecification(querySpec,
|
391
|
+
function traverseQuerySpecification(querySpec, traverseContext, subQuery = false) {
|
376
392
|
const fromClause = querySpec.fromClause();
|
377
|
-
const
|
378
|
-
const allColumns = subQuery ?
|
379
|
-
const selectItemListResult = traverseSelectItemList(querySpec.selectItemList(),
|
393
|
+
const fromColumnsFrom = fromClause ? traverseFromClause(fromClause, traverseContext, subQuery) : [];
|
394
|
+
const allColumns = subQuery ? traverseContext.fromColumns.concat(fromColumnsFrom) : fromColumnsFrom; //(... where id = t1.id)
|
395
|
+
const selectItemListResult = traverseSelectItemList(querySpec.selectItemList(), Object.assign(Object.assign({}, traverseContext), { fromColumns: allColumns }), subQuery);
|
380
396
|
const whereClause = querySpec.whereClause();
|
381
397
|
//TODO - HAVING, BLAH
|
382
398
|
if (whereClause) {
|
383
399
|
const whereExpr = whereClause === null || whereClause === void 0 ? void 0 : whereClause.expr();
|
384
|
-
traverseExpr(whereExpr,
|
400
|
+
traverseExpr(whereExpr, Object.assign(Object.assign({}, traverseContext), { fromColumns: allColumns }), !subQuery);
|
385
401
|
}
|
386
|
-
const columnNullability = (0, infer_column_nullability_1.inferNotNull)(querySpec, dbSchema, allColumns);
|
402
|
+
const columnNullability = (0, infer_column_nullability_1.inferNotNull)(querySpec, traverseContext.dbSchema, allColumns);
|
387
403
|
const columns = selectItemListResult.types.map((t, index) => {
|
388
404
|
const resultType = {
|
389
405
|
name: t.name,
|
@@ -405,22 +421,22 @@ function traverseQuerySpecification(querySpec, constraints, parameters, dbSchema
|
|
405
421
|
};
|
406
422
|
return col;
|
407
423
|
});
|
408
|
-
traverseHavingClause(havingClause,
|
424
|
+
traverseHavingClause(havingClause, Object.assign(Object.assign({}, traverseContext), { fromColumns: selectColumns.concat(fromColumnsFrom) }));
|
409
425
|
}
|
410
426
|
return {
|
411
427
|
columns,
|
412
|
-
fromColumns
|
428
|
+
fromColumns: fromColumnsFrom
|
413
429
|
};
|
414
430
|
}
|
415
431
|
exports.traverseQuerySpecification = traverseQuerySpecification;
|
416
|
-
function traverseWithClause(withClause,
|
432
|
+
function traverseWithClause(withClause, traverseContext) {
|
417
433
|
//result1, result2
|
418
434
|
withClause.commonTableExpression().forEach(commonTableExpression => {
|
419
435
|
var _a;
|
420
436
|
const identifier = commonTableExpression.identifier().text;
|
421
437
|
const recursiveNames = withClause.RECURSIVE_SYMBOL() ? ((_a = commonTableExpression.columnInternalRefList()) === null || _a === void 0 ? void 0 : _a.columnInternalRef().map(t => t.text)) || [] : undefined;
|
422
438
|
const subQuery = commonTableExpression.subquery();
|
423
|
-
const subqueryResult = traverseSubquery(subQuery,
|
439
|
+
const subqueryResult = traverseSubquery(subQuery, traverseContext, recursiveNames); //recursive= true??
|
424
440
|
subqueryResult.columns.forEach(col => {
|
425
441
|
const withCol = {
|
426
442
|
table: identifier,
|
@@ -429,24 +445,35 @@ function traverseWithClause(withClause, constraints, parameters, dbSchema, withS
|
|
429
445
|
columnKey: "",
|
430
446
|
notNull: col.notNull
|
431
447
|
};
|
432
|
-
withSchema.push(withCol);
|
448
|
+
traverseContext.withSchema.push(withCol);
|
433
449
|
});
|
434
450
|
});
|
435
451
|
}
|
436
452
|
exports.traverseWithClause = traverseWithClause;
|
437
|
-
function traverseFromClause(fromClause,
|
453
|
+
function traverseFromClause(fromClause, traverseContext, subQuery = false) {
|
438
454
|
var _a;
|
439
455
|
const tableReferenceList = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference();
|
440
|
-
const fromColumns = tableReferenceList ? traverseTableReferenceList(tableReferenceList,
|
456
|
+
const fromColumns = tableReferenceList ? traverseTableReferenceList(tableReferenceList, traverseContext, null, subQuery) : [];
|
441
457
|
return fromColumns;
|
442
458
|
}
|
443
|
-
function traverseTableReferenceList(tableReferenceList,
|
459
|
+
function traverseTableReferenceList(tableReferenceList, traverseContext, currentFragment, subQuery = false) {
|
444
460
|
const result = [];
|
461
|
+
const fragements = [];
|
445
462
|
tableReferenceList.forEach(tab => {
|
446
463
|
const tableFactor = tab.tableFactor();
|
447
464
|
if (tableFactor) {
|
448
|
-
|
465
|
+
let paramBefore = traverseContext.parameters.length;
|
466
|
+
const fields = traverseTableFactor(tableFactor, traverseContext, currentFragment);
|
467
|
+
let paramsAfter = traverseContext.parameters.length;
|
449
468
|
result.push(...fields);
|
469
|
+
fragements.push({
|
470
|
+
fragment: 'FROM ' + (0, select_columns_1.extractOriginalSql)(tableFactor) + '',
|
471
|
+
fields: [],
|
472
|
+
dependOnFields: [],
|
473
|
+
dependOnParams: [],
|
474
|
+
parameters: Array.from({ length: paramsAfter - paramBefore }, (x, i) => i + paramBefore),
|
475
|
+
dependOn: []
|
476
|
+
});
|
450
477
|
}
|
451
478
|
const allJoinedColumns = [];
|
452
479
|
let firstLeftJoinIndex = -1;
|
@@ -460,11 +487,28 @@ function traverseTableReferenceList(tableReferenceList, constraints, parameters,
|
|
460
487
|
}
|
461
488
|
const tableReferences = joined.tableReference();
|
462
489
|
if (tableReferences) {
|
490
|
+
const innerJoinFragment = {
|
491
|
+
fragment: (0, select_columns_1.extractOriginalSql)(joined) + '',
|
492
|
+
fields: [],
|
493
|
+
dependOnFields: [],
|
494
|
+
dependOnParams: [],
|
495
|
+
parameters: [],
|
496
|
+
dependOn: []
|
497
|
+
};
|
463
498
|
const usingFields = (0, select_columns_1.extractFieldsFromUsingClause)(joined);
|
464
|
-
const
|
499
|
+
const paramsBefore = traverseContext.parameters.length;
|
500
|
+
const joinedFields = traverseTableReferenceList([tableReferences], traverseContext, innerJoinFragment);
|
501
|
+
const paramsAfter = traverseContext.parameters.length;
|
465
502
|
//doesn't duplicate the fields of the USING clause. Ex. INNER JOIN mytable2 USING(id);
|
466
503
|
const joinedFieldsFiltered = usingFields.length > 0 ? filterUsingFields(joinedFields, usingFields) : joinedFields;
|
467
504
|
allJoinedColumns.push(joinedFieldsFiltered);
|
505
|
+
innerJoinFragment.fields = [...joinedFieldsFiltered.map(f => ({
|
506
|
+
field: f.columnName,
|
507
|
+
table: f.tableAlias || f.table,
|
508
|
+
name: f.columnName
|
509
|
+
}))];
|
510
|
+
innerJoinFragment.parameters = Array.from({ length: paramsAfter - paramsBefore }, (x, i) => i + paramsAfter - 1);
|
511
|
+
fragements.push(innerJoinFragment);
|
468
512
|
const onClause = joined.expr(); //ON expr
|
469
513
|
if (onClause) {
|
470
514
|
joinedFieldsFiltered.forEach(field => {
|
@@ -482,7 +526,14 @@ function traverseTableReferenceList(tableReferenceList, constraints, parameters,
|
|
482
526
|
};
|
483
527
|
field.notNull = field.notNull || !(0, infer_column_nullability_1.possibleNull)(fieldName, onClause);
|
484
528
|
});
|
485
|
-
traverseExpr(onClause,
|
529
|
+
traverseExpr(onClause, Object.assign(Object.assign({}, traverseContext), { fromColumns: allJoinedColumns.flatMap(c => c).concat(result) }));
|
530
|
+
const columns = (0, select_columns_1.getExpressions)(onClause, ts_mysql_parser_1.SimpleExprColumnRefContext);
|
531
|
+
columns.forEach(columnRef => {
|
532
|
+
const fieldName = (0, select_columns_1.splitName)(columnRef.text);
|
533
|
+
if ((innerJoinFragment === null || innerJoinFragment === void 0 ? void 0 : innerJoinFragment.relation) != fieldName.prefix) {
|
534
|
+
innerJoinFragment.parentRelation = fieldName.prefix;
|
535
|
+
}
|
536
|
+
});
|
486
537
|
}
|
487
538
|
}
|
488
539
|
});
|
@@ -498,20 +549,26 @@ function traverseTableReferenceList(tableReferenceList, constraints, parameters,
|
|
498
549
|
});
|
499
550
|
});
|
500
551
|
});
|
552
|
+
if (!subQuery) {
|
553
|
+
traverseContext.dynamicSqlInfo.from = fragements;
|
554
|
+
}
|
501
555
|
return result;
|
502
556
|
}
|
503
|
-
function traverseTableFactor(tableFactor,
|
557
|
+
function traverseTableFactor(tableFactor, traverseContext, currentFragment) {
|
504
558
|
var _a;
|
505
559
|
const singleTable = tableFactor.singleTable();
|
506
560
|
if (singleTable) {
|
507
|
-
return traverseSingleTable(singleTable,
|
561
|
+
return traverseSingleTable(singleTable, traverseContext.dbSchema, traverseContext.withSchema, currentFragment);
|
508
562
|
}
|
509
563
|
const derivadTable = tableFactor.derivedTable();
|
510
564
|
if (derivadTable) {
|
511
565
|
const tableAlias = (_a = derivadTable.tableAlias()) === null || _a === void 0 ? void 0 : _a.identifier().text;
|
566
|
+
if (currentFragment) {
|
567
|
+
currentFragment.relation = tableAlias;
|
568
|
+
}
|
512
569
|
const subQuery = derivadTable.subquery();
|
513
570
|
if (subQuery) {
|
514
|
-
const subQueryResult = traverseSubquery(subQuery,
|
571
|
+
const subQueryResult = traverseSubquery(subQuery, traverseContext);
|
515
572
|
const result = subQueryResult.columns.map(t => {
|
516
573
|
const colDef = {
|
517
574
|
table: tableAlias || '',
|
@@ -528,57 +585,78 @@ function traverseTableFactor(tableFactor, constraints, parameters, dbSchema, wit
|
|
528
585
|
}
|
529
586
|
const tableReferenceListParens = tableFactor.tableReferenceListParens();
|
530
587
|
if (tableReferenceListParens) {
|
531
|
-
const listParens = traverseTableReferenceListParens(tableReferenceListParens,
|
588
|
+
const listParens = traverseTableReferenceListParens(tableReferenceListParens, traverseContext);
|
532
589
|
return listParens;
|
533
590
|
}
|
534
591
|
throw Error('traverseTableFactor - not supported: ' + tableFactor.constructor.name);
|
535
592
|
}
|
536
593
|
//tableReferenceList | tableReferenceListParens
|
537
|
-
function traverseTableReferenceListParens(ctx,
|
594
|
+
function traverseTableReferenceListParens(ctx, traverseContext) {
|
538
595
|
const tableReferenceList = ctx.tableReferenceList();
|
539
596
|
if (tableReferenceList) {
|
540
|
-
return traverseTableReferenceList(tableReferenceList.tableReference(),
|
597
|
+
return traverseTableReferenceList(tableReferenceList.tableReference(), traverseContext, null);
|
541
598
|
}
|
542
599
|
const tableReferenceListParens = ctx.tableReferenceListParens();
|
543
600
|
if (tableReferenceListParens) {
|
544
|
-
return traverseTableReferenceListParens(tableReferenceListParens,
|
601
|
+
return traverseTableReferenceListParens(tableReferenceListParens, traverseContext);
|
545
602
|
}
|
546
603
|
throw Error('traverseTableReferenceListParens - not supported: ' + ctx.constructor.name);
|
547
604
|
}
|
548
|
-
function traverseSingleTable(singleTable,
|
605
|
+
function traverseSingleTable(singleTable, dbSchema, withSchema, currentFragment) {
|
549
606
|
var _a;
|
550
607
|
const table = singleTable === null || singleTable === void 0 ? void 0 : singleTable.tableRef().text;
|
551
608
|
const tableAlias = (_a = singleTable === null || singleTable === void 0 ? void 0 : singleTable.tableAlias()) === null || _a === void 0 ? void 0 : _a.identifier().text;
|
552
609
|
const tableName = (0, select_columns_1.splitName)(table);
|
610
|
+
if (currentFragment) {
|
611
|
+
currentFragment.relation = tableAlias || tableName.name;
|
612
|
+
}
|
553
613
|
const fields = filterColumns(dbSchema, withSchema, tableAlias, tableName);
|
554
614
|
return fields;
|
555
615
|
}
|
556
|
-
function traverseSubquery(subQuery,
|
616
|
+
function traverseSubquery(subQuery, traverseContext, recursiveNames) {
|
557
617
|
const queryExpressionParens = subQuery.queryExpressionParens();
|
558
618
|
const queryExpression = queryExpressionParens.queryExpression();
|
559
619
|
if (queryExpression) {
|
560
|
-
return traverseQueryExpression(queryExpression,
|
620
|
+
return traverseQueryExpression(queryExpression, traverseContext, true, recursiveNames);
|
561
621
|
}
|
562
622
|
const queryExpressionParens2 = queryExpressionParens.queryExpressionParens();
|
563
623
|
if (queryExpressionParens2) {
|
564
|
-
return traverseQueryExpressionParens(queryExpressionParens2,
|
624
|
+
return traverseQueryExpressionParens(queryExpressionParens2, traverseContext);
|
565
625
|
}
|
566
626
|
throw Error('traverseSubquery - not expected: ' + subQuery.constructor.name);
|
567
627
|
}
|
568
|
-
function traverseSelectItemList(selectItemList,
|
628
|
+
function traverseSelectItemList(selectItemList, traverseContext, subQuery = false) {
|
569
629
|
const listType = [];
|
570
630
|
if (selectItemList.MULT_OPERATOR()) {
|
571
|
-
fromColumns.forEach(col => {
|
631
|
+
traverseContext.fromColumns.forEach(col => {
|
572
632
|
const columnType = (0, collect_constraints_1.createColumnType)(col);
|
573
633
|
listType.push(columnType);
|
634
|
+
const tableName = col.tableAlias || col.table;
|
635
|
+
const fieldFragment = {
|
636
|
+
fragment: `${tableName}.${col.columnName}`,
|
637
|
+
fragementWithoutAlias: `${tableName}.${col.columnName}`,
|
638
|
+
fields: [{
|
639
|
+
field: col.columnName,
|
640
|
+
name: col.columnName,
|
641
|
+
table: tableName
|
642
|
+
}],
|
643
|
+
dependOnFields: [],
|
644
|
+
dependOnParams: [],
|
645
|
+
parameters: [],
|
646
|
+
dependOn: []
|
647
|
+
};
|
648
|
+
if (!subQuery) {
|
649
|
+
traverseContext.dynamicSqlInfo.select.push(fieldFragment);
|
650
|
+
}
|
574
651
|
});
|
575
652
|
}
|
576
653
|
selectItemList.selectItem().forEach(selectItem => {
|
654
|
+
var _a;
|
577
655
|
const tableWild = selectItem.tableWild();
|
578
656
|
if (tableWild) {
|
579
657
|
if (tableWild.MULT_OPERATOR()) {
|
580
658
|
const itemName = (0, select_columns_1.splitName)(selectItem.text);
|
581
|
-
const allColumns = selectAllColumns(itemName.prefix, fromColumns);
|
659
|
+
const allColumns = selectAllColumns(itemName.prefix, traverseContext.fromColumns);
|
582
660
|
allColumns.forEach(col => {
|
583
661
|
const columnType = (0, collect_constraints_1.createColumnType)(col);
|
584
662
|
listType.push(columnType);
|
@@ -587,7 +665,32 @@ function traverseSelectItemList(selectItemList, constraints, parameters, dbSchem
|
|
587
665
|
}
|
588
666
|
const expr = selectItem.expr();
|
589
667
|
if (expr) {
|
590
|
-
const exprType = traverseExpr(expr,
|
668
|
+
const exprType = traverseExpr(expr, traverseContext);
|
669
|
+
const selectFragment = {
|
670
|
+
fragment: (0, select_columns_1.extractOriginalSql)(selectItem) + '',
|
671
|
+
fragementWithoutAlias: (0, select_columns_1.extractOriginalSql)(expr),
|
672
|
+
fields: [],
|
673
|
+
dependOnFields: [],
|
674
|
+
dependOnParams: [],
|
675
|
+
parameters: [],
|
676
|
+
dependOn: []
|
677
|
+
};
|
678
|
+
if (!subQuery) {
|
679
|
+
(_a = traverseContext.dynamicSqlInfo.select) === null || _a === void 0 ? void 0 : _a.push(selectFragment);
|
680
|
+
const columns = (0, select_columns_1.getExpressions)(expr, ts_mysql_parser_1.SimpleExprColumnRefContext);
|
681
|
+
const columnName = (0, select_columns_1.getColumnName)(selectItem);
|
682
|
+
columns.forEach(colRef => {
|
683
|
+
const fieldName = (0, select_columns_1.splitName)(colRef.text);
|
684
|
+
const column = (0, select_columns_1.findColumn)(fieldName, traverseContext.fromColumns);
|
685
|
+
selectFragment.fields.push({
|
686
|
+
field: fieldName.name,
|
687
|
+
name: columnName,
|
688
|
+
table: column.tableAlias || column.table
|
689
|
+
});
|
690
|
+
selectFragment.dependOn.push(column.tableAlias || column.table);
|
691
|
+
});
|
692
|
+
}
|
693
|
+
// const fields = exprType.kind == 'TypeVar' ? [{ field: exprType.name, table: exprType.table + '', name: getColumnName(selectItem) }] : []
|
591
694
|
if (exprType.kind == 'TypeOperator') {
|
592
695
|
const subqueryType = exprType.types[0];
|
593
696
|
subqueryType.name = (0, select_columns_1.getColumnName)(selectItem);
|
@@ -605,50 +708,104 @@ function traverseSelectItemList(selectItemList, constraints, parameters, dbSchem
|
|
605
708
|
};
|
606
709
|
return result;
|
607
710
|
}
|
608
|
-
function traverseHavingClause(havingClause,
|
711
|
+
function traverseHavingClause(havingClause, traverseContext) {
|
609
712
|
const havingExpr = havingClause.expr();
|
610
|
-
traverseExpr(havingExpr,
|
713
|
+
traverseExpr(havingExpr, traverseContext);
|
611
714
|
}
|
612
|
-
function traverseExpr(expr,
|
715
|
+
function traverseExpr(expr, traverseContext, where = false) {
|
613
716
|
if (expr instanceof ts_mysql_parser_1.ExprIsContext) {
|
614
717
|
const boolPri = expr.boolPri();
|
615
|
-
|
718
|
+
let paramsCount = traverseContext.parameters.length;
|
719
|
+
const boolPriType = traverseBoolPri(boolPri, traverseContext, where);
|
720
|
+
if (where) {
|
721
|
+
const currentFragment = {
|
722
|
+
fragment: 'AND ' + (0, select_columns_1.extractOriginalSql)(expr),
|
723
|
+
fields: [],
|
724
|
+
dependOnFields: [],
|
725
|
+
dependOnParams: [],
|
726
|
+
parameters: [],
|
727
|
+
dependOn: []
|
728
|
+
};
|
729
|
+
const paramsRight = (0, select_columns_1.getExpressions)(expr, ts_mysql_parser_1.SimpleExprParamMarkerContext);
|
730
|
+
paramsRight.forEach(_ => {
|
731
|
+
currentFragment.dependOnParams.push(paramsCount);
|
732
|
+
paramsCount++;
|
733
|
+
});
|
734
|
+
const columnsRef = (0, select_columns_1.getExpressions)(expr, ts_mysql_parser_1.ColumnRefContext);
|
735
|
+
columnsRef.forEach(colRef => {
|
736
|
+
const fileName = (0, select_columns_1.splitName)(colRef.text);
|
737
|
+
currentFragment.fields.push({
|
738
|
+
field: fileName.name,
|
739
|
+
name: fileName.name,
|
740
|
+
table: fileName.prefix
|
741
|
+
});
|
742
|
+
});
|
743
|
+
traverseContext.dynamicSqlInfo.where.push(currentFragment);
|
744
|
+
}
|
616
745
|
return boolPriType;
|
617
746
|
}
|
618
747
|
if (expr instanceof ts_mysql_parser_1.ExprNotContext) {
|
619
748
|
const expr2 = expr.expr();
|
620
749
|
if (expr2) {
|
621
|
-
return traverseExpr(expr2,
|
750
|
+
return traverseExpr(expr2, traverseContext);
|
622
751
|
}
|
623
752
|
return (0, collect_constraints_1.freshVar)(expr.text, 'tinyint');
|
624
753
|
;
|
625
754
|
}
|
626
755
|
if (expr instanceof ts_mysql_parser_1.ExprAndContext || expr instanceof ts_mysql_parser_1.ExprXorContext || expr instanceof ts_mysql_parser_1.ExprOrContext) {
|
627
|
-
const
|
628
|
-
|
629
|
-
|
630
|
-
|
756
|
+
const all = [];
|
757
|
+
(0, select_columns_1.getTopLevelAndExpr)(expr, all);
|
758
|
+
all.forEach(andExpression => {
|
759
|
+
let paramsCount = traverseContext.parameters.length;
|
760
|
+
traverseExpr(andExpression.expr, traverseContext, false);
|
761
|
+
if (where) {
|
762
|
+
const currentFragment = {
|
763
|
+
fragment: andExpression.operator + ' ' + (0, select_columns_1.extractOriginalSql)(andExpression.expr),
|
764
|
+
fields: [],
|
765
|
+
dependOnFields: [],
|
766
|
+
dependOnParams: [],
|
767
|
+
parameters: [],
|
768
|
+
dependOn: []
|
769
|
+
};
|
770
|
+
const paramsRight = (0, select_columns_1.getExpressions)(andExpression.expr, ts_mysql_parser_1.SimpleExprParamMarkerContext);
|
771
|
+
paramsRight.forEach(_ => {
|
772
|
+
currentFragment.dependOnParams.push(paramsCount);
|
773
|
+
paramsCount++;
|
774
|
+
});
|
775
|
+
const columnsRef = (0, select_columns_1.getExpressions)(andExpression.expr, ts_mysql_parser_1.ColumnRefContext);
|
776
|
+
columnsRef.forEach(colRef => {
|
777
|
+
const fileName = (0, select_columns_1.splitName)(colRef.text);
|
778
|
+
currentFragment.fields.push({
|
779
|
+
field: fileName.name,
|
780
|
+
name: fileName.name,
|
781
|
+
table: fileName.prefix
|
782
|
+
});
|
783
|
+
});
|
784
|
+
traverseContext.dynamicSqlInfo.where.push(currentFragment);
|
785
|
+
}
|
786
|
+
});
|
631
787
|
return (0, collect_constraints_1.freshVar)(expr.text, 'tinyint');
|
632
788
|
}
|
633
789
|
throw Error('traverseExpr - not supported: ' + expr.text);
|
634
790
|
}
|
635
|
-
function traverseBoolPri(boolPri,
|
791
|
+
function traverseBoolPri(boolPri, traverseContext, where = false) {
|
636
792
|
if (boolPri instanceof ts_mysql_parser_1.PrimaryExprPredicateContext) {
|
637
793
|
const predicate = boolPri.predicate();
|
638
|
-
const predicateType = traversePredicate(predicate,
|
794
|
+
const predicateType = traversePredicate(predicate, traverseContext, where);
|
639
795
|
return predicateType;
|
640
796
|
}
|
641
797
|
if (boolPri instanceof ts_mysql_parser_1.PrimaryExprIsNullContext) {
|
642
798
|
const boolPri2 = boolPri.boolPri();
|
643
|
-
traverseBoolPri(boolPri2,
|
644
|
-
return (0, collect_constraints_1.freshVar)(boolPri.text, '
|
799
|
+
traverseBoolPri(boolPri2, traverseContext);
|
800
|
+
return (0, collect_constraints_1.freshVar)(boolPri.text, 'tinyint');
|
645
801
|
}
|
646
802
|
if (boolPri instanceof ts_mysql_parser_1.PrimaryExprCompareContext) {
|
647
803
|
const compareLeft = boolPri.boolPri();
|
648
804
|
const compareRight = boolPri.predicate();
|
649
|
-
|
650
|
-
const
|
651
|
-
|
805
|
+
// let paramsCount = traverseContext.parameters.length;
|
806
|
+
const typeLeft = traverseBoolPri(compareLeft, traverseContext);
|
807
|
+
const typeRight = traversePredicate(compareRight, traverseContext);
|
808
|
+
traverseContext.constraints.push({
|
652
809
|
expression: boolPri.text,
|
653
810
|
type1: typeLeft,
|
654
811
|
type2: typeRight
|
@@ -658,9 +815,9 @@ function traverseBoolPri(boolPri, constraints, parameters, dbSchema, withSchema,
|
|
658
815
|
if (boolPri instanceof ts_mysql_parser_1.PrimaryExprAllAnyContext) {
|
659
816
|
const compareLeft = boolPri.boolPri();
|
660
817
|
const compareRight = boolPri.subquery();
|
661
|
-
const typeLeft = traverseBoolPri(compareLeft,
|
662
|
-
const subQueryResult = traverseSubquery(compareRight,
|
663
|
-
constraints.push({
|
818
|
+
const typeLeft = traverseBoolPri(compareLeft, traverseContext);
|
819
|
+
const subQueryResult = traverseSubquery(compareRight, traverseContext);
|
820
|
+
traverseContext.constraints.push({
|
664
821
|
expression: boolPri.text,
|
665
822
|
type1: typeLeft,
|
666
823
|
type2: {
|
@@ -672,15 +829,15 @@ function traverseBoolPri(boolPri, constraints, parameters, dbSchema, withSchema,
|
|
672
829
|
}
|
673
830
|
throw Error('traverseExpr - not supported: ' + boolPri.constructor.name);
|
674
831
|
}
|
675
|
-
function traversePredicate(predicate,
|
832
|
+
function traversePredicate(predicate, traverseContext, where = false) {
|
676
833
|
const bitExpr = predicate.bitExpr()[0]; //TODO - predicate length = 2? [1] == predicateOperations
|
677
|
-
const bitExprType = traverseBitExpr(bitExpr,
|
834
|
+
const bitExprType = traverseBitExpr(bitExpr, traverseContext, where);
|
678
835
|
const predicateOperations = predicate.predicateOperations();
|
679
836
|
if (predicateOperations) {
|
680
|
-
const rightType = traversePredicateOperations(predicateOperations, bitExprType,
|
837
|
+
const rightType = traversePredicateOperations(predicateOperations, bitExprType, traverseContext);
|
681
838
|
if (bitExprType.kind == 'TypeOperator' && rightType.kind == 'TypeOperator') {
|
682
839
|
rightType.types.forEach((t, i) => {
|
683
|
-
constraints.push({
|
840
|
+
traverseContext.constraints.push({
|
684
841
|
expression: predicateOperations.text,
|
685
842
|
type1: t,
|
686
843
|
type2: bitExprType.types[i],
|
@@ -690,7 +847,7 @@ function traversePredicate(predicate, constraints, parameters, dbSchema, withSch
|
|
690
847
|
}
|
691
848
|
if (bitExprType.kind == 'TypeVar' && rightType.kind == 'TypeOperator') {
|
692
849
|
rightType.types.forEach((t, i) => {
|
693
|
-
constraints.push({
|
850
|
+
traverseContext.constraints.push({
|
694
851
|
expression: predicateOperations.text,
|
695
852
|
type1: bitExprType,
|
696
853
|
type2: Object.assign(Object.assign({}, t), { list: true }),
|
@@ -703,9 +860,9 @@ function traversePredicate(predicate, constraints, parameters, dbSchema, withSch
|
|
703
860
|
}
|
704
861
|
return bitExprType;
|
705
862
|
}
|
706
|
-
function traverseExprList(exprList,
|
863
|
+
function traverseExprList(exprList, traverseContext) {
|
707
864
|
const listType = exprList.expr().map(item => {
|
708
|
-
const exprType = traverseExpr(item,
|
865
|
+
const exprType = traverseExpr(item, traverseContext);
|
709
866
|
return exprType;
|
710
867
|
});
|
711
868
|
const type = {
|
@@ -714,18 +871,18 @@ function traverseExprList(exprList, constraints, parameters, dbSchema, withSchem
|
|
714
871
|
};
|
715
872
|
return type;
|
716
873
|
}
|
717
|
-
function traverseBitExpr(bitExpr,
|
874
|
+
function traverseBitExpr(bitExpr, traverseContext, where = false) {
|
718
875
|
const simpleExpr = bitExpr.simpleExpr();
|
719
876
|
if (simpleExpr) {
|
720
|
-
return traverseSimpleExpr(simpleExpr,
|
877
|
+
return traverseSimpleExpr(simpleExpr, traverseContext, where);
|
721
878
|
}
|
722
879
|
if (bitExpr.bitExpr().length == 2) {
|
723
880
|
const bitExprLeft = bitExpr.bitExpr()[0];
|
724
|
-
const typeLeftTemp = traverseBitExpr(bitExprLeft,
|
881
|
+
const typeLeftTemp = traverseBitExpr(bitExprLeft, traverseContext);
|
725
882
|
const typeLeft = typeLeftTemp.kind == 'TypeOperator' ? typeLeftTemp.types[0] : typeLeftTemp;
|
726
883
|
//const newTypeLeft = typeLeft.name == '?'? freshVar('?', 'bigint') : typeLeft;
|
727
884
|
const bitExprRight = bitExpr.bitExpr()[1];
|
728
|
-
const typeRightTemp = traverseBitExpr(bitExprRight,
|
885
|
+
const typeRightTemp = traverseBitExpr(bitExprRight, traverseContext);
|
729
886
|
//In the expression 'id + (value + 2) + ?' the '(value+2)' is treated as a SimpleExprListContext and return a TypeOperator
|
730
887
|
const typeRight = typeRightTemp.kind == 'TypeOperator' ? typeRightTemp.types[0] : typeRightTemp;
|
731
888
|
//const newTypeRight = typeRight.name == '?'? freshVar('?', 'bigint') : typeRight;
|
@@ -734,35 +891,35 @@ function traverseBitExpr(bitExpr, constraints, parameters, dbSchema, withSchema,
|
|
734
891
|
bitExprType.table = typeLeftTemp.table;
|
735
892
|
}
|
736
893
|
//PRECISA?
|
737
|
-
// constraints.push({
|
894
|
+
// traverseContext.constraints.push({
|
738
895
|
// expression: bitExpr.text,
|
739
896
|
// type1: typeLeft,
|
740
897
|
// type2: typeRight,
|
741
898
|
// mostGeneralType: true,
|
742
899
|
// coercionType: 'Sum'
|
743
900
|
// })
|
744
|
-
// constraints.push({
|
901
|
+
// traverseContext.constraints.push({
|
745
902
|
// expression: bitExpr.text,
|
746
903
|
// type1: typeLeft,
|
747
904
|
// type2: typeRight,
|
748
905
|
// mostGeneralType: true,
|
749
906
|
// coercionType: 'Sum'
|
750
907
|
// })
|
751
|
-
// constraints.push({
|
908
|
+
// traverseContext.constraints.push({
|
752
909
|
// expression: bitExpr.text,
|
753
910
|
// type1: bitExprType,
|
754
911
|
// type2: typeRight,
|
755
912
|
// mostGeneralType: true,
|
756
913
|
// coercionType: 'Sum'
|
757
914
|
// })
|
758
|
-
constraints.push({
|
915
|
+
traverseContext.constraints.push({
|
759
916
|
expression: bitExprLeft.text,
|
760
917
|
type1: bitExprType,
|
761
918
|
type2: typeLeft,
|
762
919
|
mostGeneralType: true,
|
763
920
|
coercionType: 'Sum'
|
764
921
|
});
|
765
|
-
constraints.push({
|
922
|
+
traverseContext.constraints.push({
|
766
923
|
expression: bitExprRight.text,
|
767
924
|
type1: bitExprType,
|
768
925
|
type2: typeRight,
|
@@ -770,7 +927,7 @@ function traverseBitExpr(bitExpr, constraints, parameters, dbSchema, withSchema,
|
|
770
927
|
coercionType: 'Sum'
|
771
928
|
});
|
772
929
|
// const resultType = freshVar(bitExprRight.text, 'number');
|
773
|
-
// constraints.push({
|
930
|
+
// traverseContext.constraints.push({
|
774
931
|
// expression: bitExprRight.text,
|
775
932
|
// type1: resultType,
|
776
933
|
// type2: freshVar(bitExprRight.text, 'number'),
|
@@ -781,10 +938,10 @@ function traverseBitExpr(bitExpr, constraints, parameters, dbSchema, withSchema,
|
|
781
938
|
}
|
782
939
|
if (bitExpr.INTERVAL_SYMBOL()) {
|
783
940
|
const bitExpr2 = bitExpr.bitExpr()[0];
|
784
|
-
const leftType = traverseBitExpr(bitExpr2,
|
941
|
+
const leftType = traverseBitExpr(bitExpr2, traverseContext);
|
785
942
|
const expr = bitExpr.expr(); //expr interval
|
786
|
-
traverseExpr(expr,
|
787
|
-
constraints.push({
|
943
|
+
traverseExpr(expr, traverseContext);
|
944
|
+
traverseContext.constraints.push({
|
788
945
|
expression: bitExpr.text,
|
789
946
|
type1: leftType,
|
790
947
|
type2: (0, collect_constraints_1.freshVar)('datetime', 'datetime')
|
@@ -793,23 +950,23 @@ function traverseBitExpr(bitExpr, constraints, parameters, dbSchema, withSchema,
|
|
793
950
|
}
|
794
951
|
throw Error('traverseBitExpr - not supported: ' + bitExpr.constructor.name);
|
795
952
|
}
|
796
|
-
function traversePredicateOperations(predicateOperations, parentType,
|
953
|
+
function traversePredicateOperations(predicateOperations, parentType, traverseContext) {
|
797
954
|
if (predicateOperations instanceof ts_mysql_parser_1.PredicateExprInContext) {
|
798
955
|
const subquery = predicateOperations.subquery();
|
799
956
|
if (subquery) {
|
800
|
-
const subQueryResult = traverseSubquery(subquery,
|
957
|
+
const subQueryResult = traverseSubquery(subquery, traverseContext);
|
801
958
|
return { kind: 'TypeOperator', types: subQueryResult.columns.map(t => t.type) };
|
802
959
|
}
|
803
960
|
const exprList = predicateOperations.exprList();
|
804
961
|
if (exprList) {
|
805
|
-
const rightType = traverseExprList(exprList,
|
962
|
+
const rightType = traverseExprList(exprList, traverseContext);
|
806
963
|
return rightType;
|
807
964
|
}
|
808
965
|
}
|
809
966
|
if (predicateOperations instanceof ts_mysql_parser_1.PredicateExprLikeContext) {
|
810
967
|
const simpleExpr = predicateOperations.simpleExpr()[0];
|
811
|
-
const rightType = traverseSimpleExpr(simpleExpr,
|
812
|
-
constraints.push({
|
968
|
+
const rightType = traverseSimpleExpr(simpleExpr, traverseContext);
|
969
|
+
traverseContext.constraints.push({
|
813
970
|
expression: simpleExpr.text,
|
814
971
|
type1: parentType,
|
815
972
|
type2: rightType
|
@@ -819,19 +976,19 @@ function traversePredicateOperations(predicateOperations, parentType, constraint
|
|
819
976
|
if (predicateOperations instanceof ts_mysql_parser_1.PredicateExprBetweenContext) {
|
820
977
|
const bitExpr = predicateOperations.bitExpr();
|
821
978
|
const predicate = predicateOperations.predicate();
|
822
|
-
const bitExprType = traverseBitExpr(bitExpr,
|
823
|
-
const predicateType = traversePredicate(predicate,
|
824
|
-
constraints.push({
|
979
|
+
const bitExprType = traverseBitExpr(bitExpr, traverseContext);
|
980
|
+
const predicateType = traversePredicate(predicate, traverseContext);
|
981
|
+
traverseContext.constraints.push({
|
825
982
|
expression: predicateOperations.text,
|
826
983
|
type1: parentType,
|
827
984
|
type2: bitExprType
|
828
985
|
});
|
829
|
-
constraints.push({
|
986
|
+
traverseContext.constraints.push({
|
830
987
|
expression: predicateOperations.text,
|
831
988
|
type1: parentType,
|
832
989
|
type2: predicateType
|
833
990
|
});
|
834
|
-
constraints.push({
|
991
|
+
traverseContext.constraints.push({
|
835
992
|
expression: predicateOperations.text,
|
836
993
|
type1: bitExprType,
|
837
994
|
type2: predicateType
|
@@ -840,13 +997,13 @@ function traversePredicateOperations(predicateOperations, parentType, constraint
|
|
840
997
|
}
|
841
998
|
throw Error("Not supported: " + predicateOperations.constructor.name);
|
842
999
|
}
|
843
|
-
function traverseSimpleExpr(simpleExpr,
|
1000
|
+
function traverseSimpleExpr(simpleExpr, traverseContext, where = false) {
|
844
1001
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
845
1002
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprColumnRefContext) {
|
846
1003
|
const fieldName = (0, select_columns_1.splitName)(simpleExpr.text);
|
847
|
-
const column = (0, select_columns_1.findColumn)(fieldName, fromColumns);
|
1004
|
+
const column = (0, select_columns_1.findColumn)(fieldName, traverseContext.fromColumns);
|
848
1005
|
const typeVar = (0, collect_constraints_1.freshVar)(column.columnName, column.columnType.type, column.tableAlias || column.table);
|
849
|
-
constraints.push({
|
1006
|
+
traverseContext.constraints.push({
|
850
1007
|
expression: simpleExpr.text,
|
851
1008
|
type1: typeVar,
|
852
1009
|
type2: column.columnType,
|
@@ -856,7 +1013,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
856
1013
|
}
|
857
1014
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprParamMarkerContext) {
|
858
1015
|
const param = (0, collect_constraints_1.freshVar)('?', '?');
|
859
|
-
parameters.push(param);
|
1016
|
+
traverseContext.parameters.push(param);
|
860
1017
|
return param;
|
861
1018
|
}
|
862
1019
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprLiteralContext) {
|
@@ -897,7 +1054,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
897
1054
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprListContext) {
|
898
1055
|
const exprList = simpleExpr.exprList();
|
899
1056
|
const listType = exprList.expr().map(item => {
|
900
|
-
const exprType = traverseExpr(item,
|
1057
|
+
const exprType = traverseExpr(item, traverseContext, false);
|
901
1058
|
return exprType;
|
902
1059
|
});
|
903
1060
|
const resultType = {
|
@@ -908,7 +1065,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
908
1065
|
}
|
909
1066
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprSubQueryContext) {
|
910
1067
|
const subquery = simpleExpr.subquery();
|
911
|
-
const subqueryResult = traverseSubquery(subquery,
|
1068
|
+
const subqueryResult = traverseSubquery(subquery, traverseContext);
|
912
1069
|
return {
|
913
1070
|
kind: 'TypeOperator',
|
914
1071
|
types: subqueryResult.columns.map(t => (Object.assign(Object.assign({}, t.type), { table: '' })))
|
@@ -919,8 +1076,8 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
919
1076
|
const caseType = (0, collect_constraints_1.freshVar)(simpleExpr.text, '?');
|
920
1077
|
simpleExpr.whenExpression().forEach(whenExprCont => {
|
921
1078
|
const whenExpr = whenExprCont.expr();
|
922
|
-
const whenType = traverseExpr(whenExpr,
|
923
|
-
constraints.push({
|
1079
|
+
const whenType = traverseExpr(whenExpr, traverseContext);
|
1080
|
+
traverseContext.constraints.push({
|
924
1081
|
expression: whenExpr.text,
|
925
1082
|
type1: whenType.kind == 'TypeOperator' ? whenType.types[0] : whenType,
|
926
1083
|
type2: (0, collect_constraints_1.freshVar)('tinyint', 'tinyint') //bool
|
@@ -928,8 +1085,8 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
928
1085
|
});
|
929
1086
|
const thenTypes = simpleExpr.thenExpression().map(thenExprCtx => {
|
930
1087
|
const thenExpr = thenExprCtx.expr();
|
931
|
-
const thenType = traverseExpr(thenExpr,
|
932
|
-
constraints.push({
|
1088
|
+
const thenType = traverseExpr(thenExpr, traverseContext);
|
1089
|
+
traverseContext.constraints.push({
|
933
1090
|
expression: thenExprCtx.text,
|
934
1091
|
type1: caseType,
|
935
1092
|
type2: thenType.kind == 'TypeOperator' ? thenType.types[0] : thenType,
|
@@ -939,8 +1096,8 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
939
1096
|
});
|
940
1097
|
const elseExpr = (_b = simpleExpr.elseExpression()) === null || _b === void 0 ? void 0 : _b.expr();
|
941
1098
|
if (elseExpr) {
|
942
|
-
const elseType = traverseExpr(elseExpr,
|
943
|
-
constraints.push({
|
1099
|
+
const elseType = traverseExpr(elseExpr, traverseContext);
|
1100
|
+
traverseContext.constraints.push({
|
944
1101
|
expression: (_c = simpleExpr.elseExpression()) === null || _c === void 0 ? void 0 : _c.text,
|
945
1102
|
type1: caseType,
|
946
1103
|
type2: elseType.kind == 'TypeOperator' ? elseType.types[0] : elseType,
|
@@ -948,7 +1105,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
948
1105
|
});
|
949
1106
|
thenTypes.forEach(thenType => {
|
950
1107
|
var _a;
|
951
|
-
constraints.push({
|
1108
|
+
traverseContext.constraints.push({
|
952
1109
|
expression: (_a = simpleExpr.elseExpression()) === null || _a === void 0 ? void 0 : _a.text,
|
953
1110
|
type1: thenType,
|
954
1111
|
type2: elseType.kind == 'TypeOperator' ? elseType.types[0] : elseType,
|
@@ -962,9 +1119,9 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
962
1119
|
const exprList = simpleExpr.expr();
|
963
1120
|
const exprLeft = exprList[0];
|
964
1121
|
const exprRight = exprList[1];
|
965
|
-
const typeLeft = traverseExpr(exprLeft,
|
966
|
-
const typeRight = traverseExpr(exprRight,
|
967
|
-
constraints.push({
|
1122
|
+
const typeLeft = traverseExpr(exprLeft, traverseContext);
|
1123
|
+
const typeRight = traverseExpr(exprRight, traverseContext);
|
1124
|
+
traverseContext.constraints.push({
|
968
1125
|
expression: exprLeft.text,
|
969
1126
|
type1: typeLeft,
|
970
1127
|
type2: (0, collect_constraints_1.freshVar)('bigint', 'bigint')
|
@@ -972,7 +1129,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
972
1129
|
if (typeRight.kind == 'TypeVar' && ((0, collect_constraints_1.isDateLiteral)(typeRight.name) || (0, collect_constraints_1.isDateTimeLiteral)(typeRight.name))) {
|
973
1130
|
typeRight.type = 'datetime';
|
974
1131
|
}
|
975
|
-
constraints.push({
|
1132
|
+
traverseContext.constraints.push({
|
976
1133
|
expression: exprRight.text,
|
977
1134
|
type1: typeRight,
|
978
1135
|
type2: (0, collect_constraints_1.freshVar)('datetime', 'datetime')
|
@@ -985,8 +1142,8 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
985
1142
|
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.text, '?');
|
986
1143
|
const inSumExpr = (_d = sumExpr.inSumExpr()) === null || _d === void 0 ? void 0 : _d.expr();
|
987
1144
|
if (inSumExpr) {
|
988
|
-
const inSumExprType = traverseExpr(inSumExpr,
|
989
|
-
constraints.push({
|
1145
|
+
const inSumExprType = traverseExpr(inSumExpr, traverseContext);
|
1146
|
+
traverseContext.constraints.push({
|
990
1147
|
expression: simpleExpr.text,
|
991
1148
|
type1: functionType,
|
992
1149
|
type2: inSumExprType,
|
@@ -999,7 +1156,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
999
1156
|
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.text, 'bigint');
|
1000
1157
|
const inSumExpr = (_e = sumExpr.inSumExpr()) === null || _e === void 0 ? void 0 : _e.expr();
|
1001
1158
|
if (inSumExpr) {
|
1002
|
-
traverseExpr(inSumExpr,
|
1159
|
+
traverseExpr(inSumExpr, traverseContext);
|
1003
1160
|
}
|
1004
1161
|
return functionType;
|
1005
1162
|
}
|
@@ -1007,8 +1164,8 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1007
1164
|
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.text, '?');
|
1008
1165
|
const inSumExpr = (_f = sumExpr.inSumExpr()) === null || _f === void 0 ? void 0 : _f.expr();
|
1009
1166
|
if (inSumExpr) {
|
1010
|
-
const inSumExprType = traverseExpr(inSumExpr,
|
1011
|
-
constraints.push({
|
1167
|
+
const inSumExprType = traverseExpr(inSumExpr, traverseContext);
|
1168
|
+
traverseContext.constraints.push({
|
1012
1169
|
expression: simpleExpr.text,
|
1013
1170
|
type1: functionType,
|
1014
1171
|
type2: inSumExprType,
|
@@ -1025,7 +1182,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1025
1182
|
const exprList = sumExpr.exprList();
|
1026
1183
|
if (exprList) {
|
1027
1184
|
exprList.expr().map(item => {
|
1028
|
-
const exprType = traverseExpr(item,
|
1185
|
+
const exprType = traverseExpr(item, traverseContext);
|
1029
1186
|
return exprType;
|
1030
1187
|
});
|
1031
1188
|
/*
|
@@ -1053,8 +1210,8 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1053
1210
|
if (runtimeFunctionCall.REPLACE_SYMBOL()) {
|
1054
1211
|
const exprList = runtimeFunctionCall.expr();
|
1055
1212
|
exprList.forEach(expr => {
|
1056
|
-
const exprType = traverseExpr(expr,
|
1057
|
-
constraints.push({
|
1213
|
+
const exprType = traverseExpr(expr, traverseContext);
|
1214
|
+
traverseContext.constraints.push({
|
1058
1215
|
expression: expr.text,
|
1059
1216
|
type1: exprType,
|
1060
1217
|
type2: (0, collect_constraints_1.freshVar)('varchar', 'varchar')
|
@@ -1065,14 +1222,14 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1065
1222
|
if (runtimeFunctionCall.YEAR_SYMBOL() || runtimeFunctionCall.MONTH_SYMBOL() || runtimeFunctionCall.DAY_SYMBOL()) {
|
1066
1223
|
const expr = (_g = runtimeFunctionCall.exprWithParentheses()) === null || _g === void 0 ? void 0 : _g.expr();
|
1067
1224
|
if (expr) {
|
1068
|
-
const paramType = traverseExpr(expr,
|
1225
|
+
const paramType = traverseExpr(expr, traverseContext);
|
1069
1226
|
if (paramType.kind == 'TypeVar' && (0, collect_constraints_1.isDateTimeLiteral)(paramType.name)) {
|
1070
1227
|
paramType.type = 'datetime';
|
1071
1228
|
}
|
1072
1229
|
if (paramType.kind == 'TypeVar' && (0, collect_constraints_1.isDateLiteral)(paramType.name)) {
|
1073
1230
|
paramType.type = 'date';
|
1074
1231
|
}
|
1075
|
-
constraints.push({
|
1232
|
+
traverseContext.constraints.push({
|
1076
1233
|
expression: expr.text,
|
1077
1234
|
type1: paramType,
|
1078
1235
|
type2: (0, collect_constraints_1.freshVar)(simpleExpr.text, 'date')
|
@@ -1084,14 +1241,14 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1084
1241
|
if (runtimeFunctionCall.DATE_SYMBOL()) {
|
1085
1242
|
const expr = (_h = runtimeFunctionCall.exprWithParentheses()) === null || _h === void 0 ? void 0 : _h.expr();
|
1086
1243
|
if (expr) {
|
1087
|
-
const paramType = traverseExpr(expr,
|
1244
|
+
const paramType = traverseExpr(expr, traverseContext);
|
1088
1245
|
if (paramType.kind == 'TypeVar' && (0, collect_constraints_1.isDateTimeLiteral)(paramType.name)) {
|
1089
1246
|
paramType.type = 'datetime';
|
1090
1247
|
}
|
1091
1248
|
if (paramType.kind == 'TypeVar' && (0, collect_constraints_1.isDateLiteral)(paramType.name)) {
|
1092
1249
|
paramType.type = 'date';
|
1093
1250
|
}
|
1094
|
-
constraints.push({
|
1251
|
+
traverseContext.constraints.push({
|
1095
1252
|
expression: expr.text,
|
1096
1253
|
type1: paramType,
|
1097
1254
|
type2: (0, collect_constraints_1.freshVar)(simpleExpr.text, 'date')
|
@@ -1102,7 +1259,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1102
1259
|
if (runtimeFunctionCall.HOUR_SYMBOL() || runtimeFunctionCall.MINUTE_SYMBOL() || runtimeFunctionCall.SECOND_SYMBOL()) {
|
1103
1260
|
const expr = (_j = runtimeFunctionCall.exprWithParentheses()) === null || _j === void 0 ? void 0 : _j.expr();
|
1104
1261
|
if (expr) {
|
1105
|
-
const paramType = traverseExpr(expr,
|
1262
|
+
const paramType = traverseExpr(expr, traverseContext);
|
1106
1263
|
if (paramType.kind == 'TypeVar' && (0, collect_constraints_1.isTimeLiteral)(paramType.name)) {
|
1107
1264
|
paramType.type = 'time';
|
1108
1265
|
}
|
@@ -1112,7 +1269,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1112
1269
|
if (paramType.kind == 'TypeVar' && (0, collect_constraints_1.isDateTimeLiteral)(paramType.name)) {
|
1113
1270
|
paramType.type = 'datetime';
|
1114
1271
|
}
|
1115
|
-
constraints.push({
|
1272
|
+
traverseContext.constraints.push({
|
1116
1273
|
expression: expr.text,
|
1117
1274
|
type1: paramType,
|
1118
1275
|
type2: (0, collect_constraints_1.freshVar)(simpleExpr.text, 'time')
|
@@ -1127,22 +1284,22 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1127
1284
|
if (trimFunction) {
|
1128
1285
|
const exprList = trimFunction.expr();
|
1129
1286
|
if (exprList.length == 1) {
|
1130
|
-
const exprType = traverseExpr(exprList[0],
|
1131
|
-
constraints.push({
|
1287
|
+
const exprType = traverseExpr(exprList[0], traverseContext);
|
1288
|
+
traverseContext.constraints.push({
|
1132
1289
|
expression: exprList[0].text,
|
1133
1290
|
type1: exprType,
|
1134
1291
|
type2: (0, collect_constraints_1.freshVar)('varchar', 'varchar')
|
1135
1292
|
});
|
1136
1293
|
}
|
1137
1294
|
if (exprList.length == 2) {
|
1138
|
-
const exprType = traverseExpr(exprList[0],
|
1139
|
-
const expr2Type = traverseExpr(exprList[1],
|
1140
|
-
constraints.push({
|
1295
|
+
const exprType = traverseExpr(exprList[0], traverseContext);
|
1296
|
+
const expr2Type = traverseExpr(exprList[1], traverseContext);
|
1297
|
+
traverseContext.constraints.push({
|
1141
1298
|
expression: exprList[0].text,
|
1142
1299
|
type1: exprType,
|
1143
1300
|
type2: (0, collect_constraints_1.freshVar)('varchar', 'varchar')
|
1144
1301
|
});
|
1145
|
-
constraints.push({
|
1302
|
+
traverseContext.constraints.push({
|
1146
1303
|
expression: exprList[1].text,
|
1147
1304
|
type1: expr2Type,
|
1148
1305
|
type2: (0, collect_constraints_1.freshVar)('varchar', 'varchar')
|
@@ -1159,7 +1316,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1159
1316
|
kind: 'FixedLengthParams',
|
1160
1317
|
paramsType: [varcharParam, intParam, intParam]
|
1161
1318
|
};
|
1162
|
-
traverseExprListParameters(exprList, params,
|
1319
|
+
traverseExprListParameters(exprList, params, traverseContext);
|
1163
1320
|
return varcharParam;
|
1164
1321
|
}
|
1165
1322
|
if (runtimeFunctionCall.ADDDATE_SYMBOL()
|
@@ -1170,17 +1327,17 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1170
1327
|
//SELECT ADDDATE('2008-01-02', 31)
|
1171
1328
|
const expr1 = runtimeFunctionCall.expr()[0];
|
1172
1329
|
const expr2 = runtimeFunctionCall.expr()[1];
|
1173
|
-
const typeExpr1 = traverseExpr(expr1,
|
1174
|
-
const typeExpr2 = traverseExpr(expr2,
|
1330
|
+
const typeExpr1 = traverseExpr(expr1, traverseContext);
|
1331
|
+
const typeExpr2 = traverseExpr(expr2, traverseContext);
|
1175
1332
|
if (typeExpr1.kind == 'TypeVar' && ((0, collect_constraints_1.isDateLiteral)(typeExpr1.name) || (0, collect_constraints_1.isDateTimeLiteral)(typeExpr1.name))) {
|
1176
1333
|
typeExpr1.type = 'datetime';
|
1177
1334
|
}
|
1178
|
-
constraints.push({
|
1335
|
+
traverseContext.constraints.push({
|
1179
1336
|
expression: expr1.text,
|
1180
1337
|
type1: typeExpr1,
|
1181
1338
|
type2: (0, collect_constraints_1.freshVar)('datetime', 'datetime')
|
1182
1339
|
});
|
1183
|
-
constraints.push({
|
1340
|
+
traverseContext.constraints.push({
|
1184
1341
|
expression: expr2.text,
|
1185
1342
|
type1: typeExpr2,
|
1186
1343
|
type2: (0, collect_constraints_1.freshVar)('bigint', 'bigint')
|
@@ -1195,9 +1352,9 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1195
1352
|
kind: 'VariableLengthParams',
|
1196
1353
|
paramType: '?'
|
1197
1354
|
};
|
1198
|
-
const paramsTypeList = traverseExprListParameters(exprList, params,
|
1355
|
+
const paramsTypeList = traverseExprListParameters(exprList, params, traverseContext);
|
1199
1356
|
paramsTypeList.forEach((typeVar, paramIndex) => {
|
1200
|
-
constraints.push({
|
1357
|
+
traverseContext.constraints.push({
|
1201
1358
|
expression: runtimeFunctionCall.text + '_param' + (paramIndex + 1),
|
1202
1359
|
type1: paramType,
|
1203
1360
|
type2: typeVar,
|
@@ -1212,29 +1369,29 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1212
1369
|
if (runtimeFunctionCall.MOD_SYMBOL()) {
|
1213
1370
|
const functionType = (0, collect_constraints_1.freshVar)('number', 'number');
|
1214
1371
|
const exprList = runtimeFunctionCall.expr();
|
1215
|
-
const param1 = traverseExpr(exprList[0],
|
1216
|
-
const param2 = traverseExpr(exprList[1],
|
1217
|
-
constraints.push({
|
1372
|
+
const param1 = traverseExpr(exprList[0], traverseContext);
|
1373
|
+
const param2 = traverseExpr(exprList[1], traverseContext);
|
1374
|
+
traverseContext.constraints.push({
|
1218
1375
|
expression: simpleExpr.text,
|
1219
1376
|
type1: (0, collect_constraints_1.freshVar)('number', 'number'),
|
1220
1377
|
type2: param1,
|
1221
1378
|
mostGeneralType: true,
|
1222
1379
|
coercionType: 'Numeric'
|
1223
1380
|
});
|
1224
|
-
constraints.push({
|
1381
|
+
traverseContext.constraints.push({
|
1225
1382
|
expression: simpleExpr.text,
|
1226
1383
|
type1: (0, collect_constraints_1.freshVar)('number', 'number'),
|
1227
1384
|
type2: param2,
|
1228
1385
|
mostGeneralType: true,
|
1229
1386
|
coercionType: 'Numeric'
|
1230
1387
|
});
|
1231
|
-
constraints.push({
|
1388
|
+
traverseContext.constraints.push({
|
1232
1389
|
expression: simpleExpr.text,
|
1233
1390
|
type1: functionType,
|
1234
1391
|
type2: param1,
|
1235
1392
|
mostGeneralType: true
|
1236
1393
|
});
|
1237
|
-
constraints.push({
|
1394
|
+
traverseContext.constraints.push({
|
1238
1395
|
expression: simpleExpr.text,
|
1239
1396
|
type1: functionType,
|
1240
1397
|
type2: param2,
|
@@ -1247,10 +1404,10 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1247
1404
|
const expr1 = exprList[0];
|
1248
1405
|
const expr2 = exprList[1];
|
1249
1406
|
const expr3 = exprList[2];
|
1250
|
-
traverseExpr(expr1,
|
1251
|
-
const expr2Type = traverseExpr(expr2,
|
1252
|
-
const expr3Type = traverseExpr(expr3,
|
1253
|
-
constraints.push({
|
1407
|
+
traverseExpr(expr1, traverseContext);
|
1408
|
+
const expr2Type = traverseExpr(expr2, traverseContext);
|
1409
|
+
const expr3Type = traverseExpr(expr3, traverseContext);
|
1410
|
+
traverseContext.constraints.push({
|
1254
1411
|
expression: runtimeFunctionCall.text,
|
1255
1412
|
type1: expr2Type,
|
1256
1413
|
type2: expr3Type,
|
@@ -1268,12 +1425,12 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1268
1425
|
kind: 'VariableLengthParams',
|
1269
1426
|
paramType: 'varchar'
|
1270
1427
|
};
|
1271
|
-
walkFunctionParameters(simpleExpr, params,
|
1428
|
+
walkFunctionParameters(simpleExpr, params, traverseContext);
|
1272
1429
|
return varcharType;
|
1273
1430
|
}
|
1274
1431
|
if (functionIdentifier === 'avg') {
|
1275
1432
|
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.text, '?');
|
1276
|
-
constraints.push({
|
1433
|
+
traverseContext.constraints.push({
|
1277
1434
|
expression: simpleExpr.text,
|
1278
1435
|
type1: functionType,
|
1279
1436
|
type2: (0, collect_constraints_1.freshVar)('decimal', 'decimal'),
|
@@ -1283,7 +1440,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1283
1440
|
kind: 'FixedLengthParams',
|
1284
1441
|
paramsType: [functionType]
|
1285
1442
|
};
|
1286
|
-
walkFunctionParameters(simpleExpr, params,
|
1443
|
+
walkFunctionParameters(simpleExpr, params, traverseContext);
|
1287
1444
|
return functionType;
|
1288
1445
|
}
|
1289
1446
|
if (functionIdentifier === 'round') {
|
@@ -1292,9 +1449,9 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1292
1449
|
kind: 'FixedLengthParams',
|
1293
1450
|
paramsType: [functionType]
|
1294
1451
|
};
|
1295
|
-
const paramsType = walkFunctionParameters(simpleExpr, params,
|
1452
|
+
const paramsType = walkFunctionParameters(simpleExpr, params, traverseContext);
|
1296
1453
|
//The return value has the same type as the first argument
|
1297
|
-
constraints.push({
|
1454
|
+
traverseContext.constraints.push({
|
1298
1455
|
expression: simpleExpr.text,
|
1299
1456
|
type1: functionType,
|
1300
1457
|
type2: paramsType[0],
|
@@ -1308,7 +1465,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1308
1465
|
kind: 'FixedLengthParams',
|
1309
1466
|
paramsType: [doubleParam, doubleParam]
|
1310
1467
|
};
|
1311
|
-
walkFunctionParameters(simpleExpr, params,
|
1468
|
+
walkFunctionParameters(simpleExpr, params, traverseContext);
|
1312
1469
|
return (0, collect_constraints_1.freshVar)(simpleExpr.text, 'bigint');
|
1313
1470
|
}
|
1314
1471
|
if (functionIdentifier === 'str_to_date') {
|
@@ -1317,7 +1474,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1317
1474
|
kind: 'FixedLengthParams',
|
1318
1475
|
paramsType: [varcharParam, varcharParam]
|
1319
1476
|
};
|
1320
|
-
walkFunctionParameters(simpleExpr, params,
|
1477
|
+
walkFunctionParameters(simpleExpr, params, traverseContext);
|
1321
1478
|
return (0, collect_constraints_1.freshVar)(simpleExpr.text, 'date');
|
1322
1479
|
}
|
1323
1480
|
if (functionIdentifier === 'datediff') {
|
@@ -1325,9 +1482,9 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1325
1482
|
if (udfExprList) {
|
1326
1483
|
udfExprList.forEach((inExpr) => {
|
1327
1484
|
const expr = inExpr.expr();
|
1328
|
-
const exprType = traverseExpr(expr,
|
1485
|
+
const exprType = traverseExpr(expr, traverseContext);
|
1329
1486
|
const newType = (0, collect_constraints_1.verifyDateTypesCoercion)(exprType);
|
1330
|
-
constraints.push({
|
1487
|
+
traverseContext.constraints.push({
|
1331
1488
|
expression: expr.text,
|
1332
1489
|
type1: newType,
|
1333
1490
|
type2: (0, collect_constraints_1.freshVar)('date', 'date'),
|
@@ -1342,8 +1499,8 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1342
1499
|
if (udfExprList) {
|
1343
1500
|
udfExprList.forEach((inExpr) => {
|
1344
1501
|
const expr = inExpr.expr();
|
1345
|
-
const exprType = traverseExpr(expr,
|
1346
|
-
constraints.push({
|
1502
|
+
const exprType = traverseExpr(expr, traverseContext);
|
1503
|
+
traverseContext.constraints.push({
|
1347
1504
|
expression: expr.text,
|
1348
1505
|
type1: exprType,
|
1349
1506
|
type2: (0, collect_constraints_1.freshVar)('bigint', 'bigint'),
|
@@ -1360,7 +1517,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1360
1517
|
kind: 'FixedLengthParams',
|
1361
1518
|
paramsType: [varcharParam, intParam, varcharParam]
|
1362
1519
|
};
|
1363
|
-
walkFunctionParameters(simpleExpr, params,
|
1520
|
+
walkFunctionParameters(simpleExpr, params, traverseContext);
|
1364
1521
|
return varcharParam;
|
1365
1522
|
}
|
1366
1523
|
if (functionIdentifier === 'lower'
|
@@ -1375,7 +1532,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1375
1532
|
kind: 'FixedLengthParams',
|
1376
1533
|
paramsType: [varcharParam]
|
1377
1534
|
};
|
1378
|
-
walkFunctionParameters(simpleExpr, params,
|
1535
|
+
walkFunctionParameters(simpleExpr, params, traverseContext);
|
1379
1536
|
return varcharParam;
|
1380
1537
|
}
|
1381
1538
|
if (functionIdentifier === 'length' || functionIdentifier == 'char_length') {
|
@@ -1384,15 +1541,15 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1384
1541
|
kind: 'FixedLengthParams',
|
1385
1542
|
paramsType: [varcharParam]
|
1386
1543
|
};
|
1387
|
-
walkFunctionParameters(simpleExpr, params,
|
1544
|
+
walkFunctionParameters(simpleExpr, params, traverseContext);
|
1388
1545
|
return (0, collect_constraints_1.freshVar)('int', 'int');
|
1389
1546
|
}
|
1390
1547
|
if (functionIdentifier === 'abs') {
|
1391
1548
|
const functionType = (0, collect_constraints_1.freshVar)('number', 'number');
|
1392
1549
|
const udfExprList = (_o = simpleExpr.functionCall().udfExprList()) === null || _o === void 0 ? void 0 : _o.udfExpr();
|
1393
1550
|
udfExprList === null || udfExprList === void 0 ? void 0 : udfExprList.forEach(expr => {
|
1394
|
-
const param1 = traverseExpr(expr.expr(),
|
1395
|
-
constraints.push({
|
1551
|
+
const param1 = traverseExpr(expr.expr(), traverseContext);
|
1552
|
+
traverseContext.constraints.push({
|
1396
1553
|
expression: simpleExpr.text,
|
1397
1554
|
type1: functionType,
|
1398
1555
|
type2: param1,
|
@@ -1406,8 +1563,8 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1406
1563
|
const functionType = (0, collect_constraints_1.freshVar)('number', 'number');
|
1407
1564
|
const udfExprList = (_p = simpleExpr.functionCall().udfExprList()) === null || _p === void 0 ? void 0 : _p.udfExpr();
|
1408
1565
|
udfExprList === null || udfExprList === void 0 ? void 0 : udfExprList.forEach(expr => {
|
1409
|
-
const param1 = traverseExpr(expr.expr(),
|
1410
|
-
constraints.push({
|
1566
|
+
const param1 = traverseExpr(expr.expr(), traverseContext);
|
1567
|
+
traverseContext.constraints.push({
|
1411
1568
|
expression: simpleExpr.text,
|
1412
1569
|
type1: functionType,
|
1413
1570
|
type2: param1,
|
@@ -1424,10 +1581,10 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1424
1581
|
const unit = first.text.trim().toLowerCase();
|
1425
1582
|
rest.forEach((inExpr, paramIndex) => {
|
1426
1583
|
const expr = inExpr.expr();
|
1427
|
-
const exprType = traverseExpr(expr,
|
1584
|
+
const exprType = traverseExpr(expr, traverseContext);
|
1428
1585
|
const newType = (0, collect_constraints_1.verifyDateTypesCoercion)(exprType);
|
1429
1586
|
//const expectedType = ['hour', 'minute', 'second'].includes(unit)? 'time' : 'datetime'
|
1430
|
-
constraints.push({
|
1587
|
+
traverseContext.constraints.push({
|
1431
1588
|
expression: expr.text,
|
1432
1589
|
type1: newType,
|
1433
1590
|
type2: (0, collect_constraints_1.freshVar)('datetime', 'datetime'),
|
@@ -1442,14 +1599,14 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1442
1599
|
const udfExprList = (_r = simpleExpr.functionCall().udfExprList()) === null || _r === void 0 ? void 0 : _r.udfExpr();
|
1443
1600
|
if (udfExprList) {
|
1444
1601
|
const [expr1, expr2] = udfExprList;
|
1445
|
-
const expr1Type = traverseExpr(expr1.expr(),
|
1446
|
-
constraints.push({
|
1602
|
+
const expr1Type = traverseExpr(expr1.expr(), traverseContext);
|
1603
|
+
traverseContext.constraints.push({
|
1447
1604
|
expression: expr1.text,
|
1448
1605
|
type1: functionType,
|
1449
1606
|
type2: expr1Type
|
1450
1607
|
});
|
1451
|
-
const expr2Type = traverseExpr(expr2.expr(),
|
1452
|
-
constraints.push({
|
1608
|
+
const expr2Type = traverseExpr(expr2.expr(), traverseContext);
|
1609
|
+
traverseContext.constraints.push({
|
1453
1610
|
expression: expr2.text,
|
1454
1611
|
type1: functionType,
|
1455
1612
|
type2: expr2Type
|
@@ -1464,8 +1621,8 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1464
1621
|
const udfExprList = (_s = simpleExpr.functionCall().udfExprList()) === null || _s === void 0 ? void 0 : _s.udfExpr();
|
1465
1622
|
if (udfExprList) {
|
1466
1623
|
const [expr1] = udfExprList;
|
1467
|
-
const paramType = traverseExpr(expr1.expr(),
|
1468
|
-
constraints.push({
|
1624
|
+
const paramType = traverseExpr(expr1.expr(), traverseContext);
|
1625
|
+
traverseContext.constraints.push({
|
1469
1626
|
expression: expr1.text,
|
1470
1627
|
type1: paramType,
|
1471
1628
|
type2: (0, collect_constraints_1.freshVar)(expr1.text, 'varchar')
|
@@ -1477,7 +1634,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1477
1634
|
}
|
1478
1635
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprWindowingFunctionContext) {
|
1479
1636
|
const windowFunctionCall = simpleExpr.windowFunctionCall();
|
1480
|
-
return traverseWindowFunctionCall(windowFunctionCall,
|
1637
|
+
return traverseWindowFunctionCall(windowFunctionCall, traverseContext);
|
1481
1638
|
}
|
1482
1639
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprCastContext) {
|
1483
1640
|
const castType = simpleExpr.castType();
|
@@ -1487,7 +1644,7 @@ function traverseSimpleExpr(simpleExpr, constraints, parameters, dbSchema, withS
|
|
1487
1644
|
}
|
1488
1645
|
throw Error('traverseSimpleExpr - not supported: ' + simpleExpr.constructor.name);
|
1489
1646
|
}
|
1490
|
-
function traverseWindowFunctionCall(windowFunctionCall,
|
1647
|
+
function traverseWindowFunctionCall(windowFunctionCall, traverseContext) {
|
1491
1648
|
if (windowFunctionCall.ROW_NUMBER_SYMBOL()
|
1492
1649
|
|| windowFunctionCall.RANK_SYMBOL()
|
1493
1650
|
|| windowFunctionCall.DENSE_RANK_SYMBOL()
|
@@ -1497,20 +1654,20 @@ function traverseWindowFunctionCall(windowFunctionCall, constraints, parameters,
|
|
1497
1654
|
}
|
1498
1655
|
const expr = windowFunctionCall.expr();
|
1499
1656
|
if (expr) {
|
1500
|
-
return traverseExpr(expr,
|
1657
|
+
return traverseExpr(expr, traverseContext);
|
1501
1658
|
}
|
1502
1659
|
const exprWithParentheses = windowFunctionCall.exprWithParentheses();
|
1503
1660
|
if (exprWithParentheses) {
|
1504
1661
|
const expr = exprWithParentheses.expr();
|
1505
|
-
return traverseExpr(expr,
|
1662
|
+
return traverseExpr(expr, traverseContext);
|
1506
1663
|
}
|
1507
1664
|
throw Error('No support for expression' + windowFunctionCall.constructor.name);
|
1508
1665
|
}
|
1509
|
-
function traverseExprListParameters(exprList, params,
|
1666
|
+
function traverseExprListParameters(exprList, params, traverseContext) {
|
1510
1667
|
return exprList.map((expr, paramIndex) => {
|
1511
|
-
const exprType = traverseExpr(expr,
|
1668
|
+
const exprType = traverseExpr(expr, traverseContext);
|
1512
1669
|
const paramType = params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType);
|
1513
|
-
constraints.push({
|
1670
|
+
traverseContext.constraints.push({
|
1514
1671
|
expression: expr.text,
|
1515
1672
|
type1: exprType,
|
1516
1673
|
type2: paramType,
|
@@ -1519,7 +1676,7 @@ function traverseExprListParameters(exprList, params, constraints, parameters, d
|
|
1519
1676
|
return paramType;
|
1520
1677
|
});
|
1521
1678
|
}
|
1522
|
-
function walkFunctionParameters(simpleExprFunction, params,
|
1679
|
+
function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
|
1523
1680
|
var _a, _b;
|
1524
1681
|
const functionName = (0, collect_constraints_1.getFunctionName)(simpleExprFunction);
|
1525
1682
|
const udfExprList = (_a = simpleExprFunction.functionCall().udfExprList()) === null || _a === void 0 ? void 0 : _a.udfExpr();
|
@@ -1530,8 +1687,8 @@ function walkFunctionParameters(simpleExprFunction, params, constraints, paramet
|
|
1530
1687
|
})
|
1531
1688
|
.map((inExpr, paramIndex) => {
|
1532
1689
|
const expr = inExpr.expr();
|
1533
|
-
const exprType = traverseExpr(expr,
|
1534
|
-
constraints.push({
|
1690
|
+
const exprType = traverseExpr(expr, traverseContext);
|
1691
|
+
traverseContext.constraints.push({
|
1535
1692
|
expression: expr.text,
|
1536
1693
|
type1: exprType,
|
1537
1694
|
type2: params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType),
|
@@ -1543,8 +1700,8 @@ function walkFunctionParameters(simpleExprFunction, params, constraints, paramet
|
|
1543
1700
|
const exprList = (_b = simpleExprFunction.functionCall().exprList()) === null || _b === void 0 ? void 0 : _b.expr();
|
1544
1701
|
if (exprList) {
|
1545
1702
|
const paramTypes = exprList.map((inExpr, paramIndex) => {
|
1546
|
-
const inSumExprType = traverseExpr(inExpr,
|
1547
|
-
constraints.push({
|
1703
|
+
const inSumExprType = traverseExpr(inExpr, traverseContext);
|
1704
|
+
traverseContext.constraints.push({
|
1548
1705
|
expression: inExpr.text,
|
1549
1706
|
type1: params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType),
|
1550
1707
|
type2: inSumExprType,
|