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