@sap/xsodata 8.2.1 → 8.3.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/CHANGELOG.md +10 -0
- package/index.js +2 -2
- package/lib/configuration.js +1 -1
- package/lib/db/connect.js +1 -1
- package/lib/db/dbSegment.js +68 -123
- package/lib/db/dbVersionChecks.js +2 -8
- package/lib/handlerConfiguration.js +2 -2
- package/lib/http/conditionalHttpHandler.js +27 -34
- package/lib/http/simpleHttpRequest.js +14 -18
- package/lib/http/simpleHttpResponse.js +9 -6
- package/lib/http/uriParser.js +9 -9
- package/lib/http/validator/httpRequestValidator.js +9 -9
- package/lib/model/annotationFactory.js +11 -11
- package/lib/model/association.js +3 -3
- package/lib/model/entityType.js +33 -67
- package/lib/model/metadataReader.js +31 -52
- package/lib/model/model.js +0 -1
- package/lib/model/validator/xsoDataConcurrencyTokenValidator.js +6 -6
- package/lib/model/xsodataReader.js +36 -28
- package/lib/processor/authorizationProcessor.js +22 -33
- package/lib/processor/batchProcessor.js +22 -33
- package/lib/processor/errorProcessor.js +4 -4
- package/lib/processor/exitProcessor.js +19 -19
- package/lib/processor/processor.js +9 -9
- package/lib/processor/resourceProcessor.js +31 -61
- package/lib/processor/resourceProcessorDelete.js +16 -16
- package/lib/processor/resourceProcessorDeleteLinks.js +25 -25
- package/lib/processor/resourceProcessorGet.js +5 -5
- package/lib/processor/resourceProcessorPost.js +43 -45
- package/lib/processor/resourceProcessorPut.js +35 -39
- package/lib/processor/resourceProcessorPutPostLinks.js +38 -39
- package/lib/security/securityContext.js +5 -5
- package/lib/serializer/atomSerializer.js +54 -55
- package/lib/serializer/atomXmlToJsonSerializer.js +32 -44
- package/lib/serializer/content.js +5 -5
- package/lib/serializer/json.js +31 -33
- package/lib/serializer/jsonSerializer.js +4 -4
- package/lib/serializer/metadataSerializer.js +32 -35
- package/lib/serializer/serializer.js +29 -43
- package/lib/serializer/serviceSerializer.js +19 -24
- package/lib/serializer/value.js +1 -2
- package/lib/serializer/xmlToJsonSerializer.js +18 -18
- package/lib/sql/createDeleteLinksStatements.js +10 -10
- package/lib/sql/createDeleteStatements.js +12 -12
- package/lib/sql/createGetStatements.js +49 -107
- package/lib/sql/createLinksSQLStatements_1_n.js +27 -27
- package/lib/sql/createPutPostLinksStatements.js +9 -9
- package/lib/sql/createPutStatements.js +0 -1
- package/lib/sql/dataCollectorDelete.js +9 -9
- package/lib/sql/dataCollectorDeleteLinks.js +3 -3
- package/lib/sql/dataCollectorGet.js +9 -17
- package/lib/sql/dataCollectorLinks.js +23 -27
- package/lib/sql/dataCollectorPost.js +20 -20
- package/lib/sql/dataCollectorPut.js +36 -36
- package/lib/sql/dataCollectorPutPostLinks.js +3 -3
- package/lib/sql/sqlStatement.js +81 -128
- package/lib/sql/sqlTools.js +3 -7
- package/lib/sql/statementProcessor.js +7 -14
- package/lib/uri/applyChecks.js +3 -3
- package/lib/uri/checks/checkAllowedMethod.js +3 -3
- package/lib/uri/checks/checkAllowedMethodForBatch.js +2 -2
- package/lib/uri/checks/checkAllowedMethodsForResourcePath.js +3 -3
- package/lib/uri/checks/checkFilterOnAggregatedColumn.js +5 -5
- package/lib/uri/checks/checkFilterOrderByOnGenKeyColumn.js +6 -6
- package/lib/uri/checks/checkGenKeyRestrictions.js +2 -2
- package/lib/uri/checks/checkModificationForbidden.js +3 -3
- package/lib/uri/checks/checkPostPutDeleteChecks.js +5 -5
- package/lib/uri/checks/checkSystemQueryOptions.js +10 -10
- package/lib/uri/checks.js +15 -15
- package/lib/uri/expandSelectTreeBuilder.js +12 -16
- package/lib/uri/oDataUriParser.js +20 -20
- package/lib/uri/queryParameterParser.js +25 -33
- package/lib/uri/resourcePathParser.js +47 -62
- package/lib/uri/uriType.js +4 -4
- package/lib/utils/associations.js +4 -4
- package/lib/utils/batch/batchExecutor.js +49 -51
- package/lib/utils/batch/batchObjects.js +10 -10
- package/lib/utils/batch/batchParser.js +27 -28
- package/lib/utils/batch/batchWriter.js +1 -1
- package/lib/utils/checkContentType.js +34 -39
- package/lib/utils/debugView.js +35 -36
- package/lib/utils/errors/applicationError.js +2 -2
- package/lib/utils/errors/debugInfo.js +2 -2
- package/lib/utils/errors/http/badRequest.js +2 -2
- package/lib/utils/errors/http/forbidden.js +2 -2
- package/lib/utils/errors/http/methodNotAllowed.js +2 -2
- package/lib/utils/errors/http/notAcceptable.js +2 -2
- package/lib/utils/errors/http/notFound.js +2 -2
- package/lib/utils/errors/http/notImplemented.js +2 -2
- package/lib/utils/errors/http/notModified.js +2 -2
- package/lib/utils/errors/http/notSupported.js +2 -2
- package/lib/utils/errors/http/preconditionFailed.js +2 -2
- package/lib/utils/errors/http/preconditionRequired.js +2 -2
- package/lib/utils/errors/http/unauthorized.js +2 -2
- package/lib/utils/errors/http/unsupportedMediaType.js +2 -2
- package/lib/utils/errors/httpError.js +2 -2
- package/lib/utils/errors/internalError.js +2 -2
- package/lib/utils/errors/modelFileError.js +2 -2
- package/lib/utils/errors/sqlError.js +2 -2
- package/lib/utils/errors/testError.js +2 -2
- package/lib/utils/errors/typeError.js +5 -5
- package/lib/utils/errors/xsODataError.js +1 -1
- package/lib/utils/logger.js +21 -32
- package/lib/utils/measurement.js +14 -13
- package/lib/utils/requestContext.js +2 -2
- package/lib/utils/stateMaschine.js +6 -6
- package/lib/utils/tableCleanup.js +3 -3
- package/lib/utils/typeConverter.js +21 -21
- package/lib/utils/typeConverters/converterTools.js +25 -331
- package/lib/utils/typeConverters/dbToJson.js +3 -3
- package/lib/utils/typeConverters/dbToUri.js +7 -7
- package/lib/utils/typeConverters/dbToXml.js +9 -9
- package/lib/utils/typeConverters/jsonToDb.js +20 -27
- package/lib/utils/typeConverters/uriToDb.js +45 -92
- package/lib/utils/typeConverters/xmlValueToJson.js +9 -13
- package/lib/utils/typedObjects.js +11 -79
- package/lib/utils/utils.js +20 -23
- package/lib/xsodata.js +37 -47
- package/package.json +9 -11
- package/.npmignore +0 -40
|
@@ -24,7 +24,7 @@ exports._masterTableInsert = masterTableInsert;
|
|
|
24
24
|
*/
|
|
25
25
|
exports.createGetSqlStatements = function (context, asyncDone) {
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const sqlContext = context.sql = {
|
|
28
28
|
netId: context.uniqueNetworkRequestID,
|
|
29
29
|
reqId: context.uniqueRequestID,
|
|
30
30
|
rId: 1,
|
|
@@ -42,7 +42,7 @@ exports.createGetSqlStatements = function (context, asyncDone) {
|
|
|
42
42
|
context.sql.cleanSessionDropContainer = [];
|
|
43
43
|
|
|
44
44
|
masterTable(sqlContext);
|
|
45
|
-
expandedTables(sqlContext, sqlContext.dbSegLast, ''
|
|
45
|
+
expandedTables(sqlContext, sqlContext.dbSegLast, '');
|
|
46
46
|
context.sql.container = sqlTools.collectSqls(context, sqlContext);
|
|
47
47
|
|
|
48
48
|
return asyncDone(null, context);
|
|
@@ -57,19 +57,7 @@ function masterTable(sqlContext) {
|
|
|
57
57
|
|
|
58
58
|
sqlContext.context.logger.debug('createGetStatements', 'masterTable');
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (dbSeg.restriction.onlyCount === true) {
|
|
63
|
-
//no expand, avoid temporary tables
|
|
64
|
-
dbSeg.sql.stmContainer.select = exports._masterTableSimpleSelect(sqlContext);
|
|
65
|
-
dbSeg.sql.stmContainer.select.setAddCalcViewHint();
|
|
66
|
-
dbSeg.sql.stmContainer.select.setHints(sqlContext.context.gModel.getHints());
|
|
67
|
-
} else if (dbSeg.restriction.onlyValue === true) {
|
|
68
|
-
//no expand, avoid temporary tables
|
|
69
|
-
dbSeg.sql.stmContainer.select = exports._masterTableSimpleSelect(sqlContext);
|
|
70
|
-
dbSeg.sql.stmContainer.select.setAddCalcViewHint();
|
|
71
|
-
dbSeg.sql.stmContainer.select.setHints(sqlContext.context.gModel.getHints());
|
|
72
|
-
} else if (dbSeg._ExpandedNavigations.length === 0) {
|
|
60
|
+
if (dbSeg.restriction.onlyCount === true || dbSeg.restriction.onlyValue === true || dbSeg._ExpandedNavigations.length === 0) {
|
|
73
61
|
//no expand, avoid temporary tables
|
|
74
62
|
dbSeg.sql.stmContainer.select = exports._masterTableSimpleSelect(sqlContext);
|
|
75
63
|
dbSeg.sql.stmContainer.select.setAddCalcViewHint();
|
|
@@ -130,26 +118,18 @@ function getLimit(sqlContext, name) {
|
|
|
130
118
|
return 1000;
|
|
131
119
|
}
|
|
132
120
|
}
|
|
133
|
-
return null;
|
|
134
121
|
}
|
|
135
122
|
|
|
136
|
-
|
|
137
123
|
function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
138
124
|
// SAPINFO A simple odata GET request without and expand is processed without using temporary tables.
|
|
139
125
|
// Count fallback it true if a SELECT is created which is used to obtain the max count for all records, even
|
|
140
126
|
// if the result set is empty. (If the result is not empty there would be a count column)
|
|
141
|
-
|
|
142
|
-
var dbSeg, isCount, select, orderBy, selectCount;
|
|
143
|
-
|
|
127
|
+
let dbSeg, isCount, select, orderBy, selectCount;
|
|
144
128
|
sqlContext.context.logger.debug('createGetStatements', 'masterTableSimpleSelect');
|
|
145
|
-
|
|
146
129
|
dbSeg = sqlContext.dbSegLast;
|
|
147
130
|
isCount = dbSeg.restriction.onlyCount || countFallback;
|
|
148
|
-
|
|
149
|
-
|
|
150
131
|
//create select statement
|
|
151
132
|
select = simpleSelectJoins(dbSeg, sqlContext);
|
|
152
|
-
|
|
153
133
|
//add Query $filter
|
|
154
134
|
if (sqlContext.systemQueryParameters.filter) {
|
|
155
135
|
if (!checkConditionsProps(sqlContext.systemQueryParameters.filter, dbSeg.entityType.propertiesMap)) {
|
|
@@ -162,7 +142,6 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
162
142
|
}
|
|
163
143
|
select.addWhereAnded(sqlContext.systemQueryParameters.filter);
|
|
164
144
|
}
|
|
165
|
-
|
|
166
145
|
//add Query $orderby
|
|
167
146
|
if (!isCount) {
|
|
168
147
|
if (sqlContext.systemQueryParameters.orderby) {
|
|
@@ -173,15 +152,12 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
173
152
|
if (orderBy.setAlias) { // Add WHERE statement from uri
|
|
174
153
|
orderBy.setAlias(dbSeg.getAlias());
|
|
175
154
|
}
|
|
176
|
-
|
|
177
155
|
if (orderBy.applyConverter) {
|
|
178
156
|
orderBy.applyConverter(replaceEdmPropertiesWithSqlProperties.bind(null, dbSeg));
|
|
179
157
|
}
|
|
180
|
-
|
|
181
158
|
select.addOrderBy(orderBy);
|
|
182
159
|
}
|
|
183
160
|
}
|
|
184
|
-
|
|
185
161
|
// group by & order by
|
|
186
162
|
if (dbSeg.entityType.hasAggregates()) {
|
|
187
163
|
select.addGroupBys(dbSeg.getAllSelectedNonAggregateIncludingJoinPropertiesForGroupBy());
|
|
@@ -196,10 +172,10 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
196
172
|
select.addSortOrders(dbSeg.getKeyProperties0123ForOrderBy(true));
|
|
197
173
|
} else {
|
|
198
174
|
let orderByProperties = dbSeg.getKeyProperties0123ForOrderByCalcView(true);
|
|
199
|
-
for (
|
|
200
|
-
for (
|
|
201
|
-
if (
|
|
202
|
-
|
|
175
|
+
for (const sel of select.select) {
|
|
176
|
+
for (const orderByProperty of orderByProperties) {
|
|
177
|
+
if (orderByProperty.getPropertyName() === sel.property) {
|
|
178
|
+
sel.alias = orderByProperty.expression.property;
|
|
203
179
|
}
|
|
204
180
|
}
|
|
205
181
|
}
|
|
@@ -207,17 +183,14 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
207
183
|
}
|
|
208
184
|
}
|
|
209
185
|
}
|
|
210
|
-
|
|
211
186
|
//add $skip --> Offset
|
|
212
187
|
if (sqlContext.systemQueryParameters.skip && !countFallback) {
|
|
213
188
|
select.addOffset(sqlContext.systemQueryParameters.skip);
|
|
214
189
|
}
|
|
215
|
-
|
|
216
190
|
//add $top --> Limit
|
|
217
191
|
if (!isCount) {
|
|
218
192
|
const maxRecords = getLimit(sqlContext, 'max_records');
|
|
219
193
|
const top = sqlContext.systemQueryParameters.top;
|
|
220
|
-
|
|
221
194
|
if (maxRecords) {
|
|
222
195
|
select.setCustomData('maxRecords', maxRecords);
|
|
223
196
|
if (top >= 0) {
|
|
@@ -239,7 +212,6 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
239
212
|
}
|
|
240
213
|
}
|
|
241
214
|
}
|
|
242
|
-
|
|
243
215
|
if (!countFallback) {
|
|
244
216
|
if (sqlContext.systemQueryParameters.inlinecount) {
|
|
245
217
|
select.addFallbackStatement(masterTableSimpleSelect(sqlContext, true));
|
|
@@ -252,13 +224,9 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
252
224
|
selectCount.addSelects([new sql.SelectFormula(null, 'count(*)', 'c')]);
|
|
253
225
|
} else if (!sqlContext.systemQueryParameters.expand && !countFallback &&
|
|
254
226
|
utils.isETagRequired(sqlContext.context, dbSeg)) {
|
|
255
|
-
|
|
256
227
|
addETagToSelect(dbSeg, select);
|
|
257
228
|
}
|
|
258
|
-
|
|
259
229
|
return selectCount || select;
|
|
260
|
-
|
|
261
|
-
|
|
262
230
|
/**
|
|
263
231
|
* scan the tree of conditions, and check that every given property exist in the corresponding entityType
|
|
264
232
|
* @param {object} tree - the conditions tree. It consists of an object with further objects, arrays or properties
|
|
@@ -266,9 +234,8 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
266
234
|
* @return {boolean}
|
|
267
235
|
* */
|
|
268
236
|
function checkConditionsProps(tree, props) {
|
|
269
|
-
var objpr;
|
|
270
237
|
// loop over all properties
|
|
271
|
-
for (objpr in tree) {
|
|
238
|
+
for (let objpr in tree) {
|
|
272
239
|
if (tree.hasOwnProperty(objpr)) {
|
|
273
240
|
// if the property is an object itself, then recursively call the check
|
|
274
241
|
if (typeof tree[objpr] === 'object') {
|
|
@@ -280,10 +247,8 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
280
247
|
}
|
|
281
248
|
}
|
|
282
249
|
}
|
|
283
|
-
|
|
284
250
|
return true;
|
|
285
251
|
}
|
|
286
|
-
|
|
287
252
|
/**
|
|
288
253
|
* scan the array of $orderby orders, and check that every given property exist in the corresponding entityType
|
|
289
254
|
* @param {object} tree - the conditions tree. It consists of an object with the array of orders
|
|
@@ -291,33 +256,28 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
291
256
|
* @return {boolean}
|
|
292
257
|
* */
|
|
293
258
|
function checkOrderbyProps(tree, props) {
|
|
294
|
-
|
|
259
|
+
let expression;
|
|
295
260
|
// loop over all orders
|
|
296
|
-
for (
|
|
297
|
-
expression =
|
|
261
|
+
for (const treeOrder of tree.orders) {
|
|
262
|
+
expression = treeOrder.expression;
|
|
298
263
|
// loop over all properties
|
|
299
264
|
if (!checkConditionsProps(expression, props)) {
|
|
300
265
|
return false;
|
|
301
266
|
}
|
|
302
267
|
}
|
|
303
|
-
|
|
304
268
|
return true;
|
|
305
269
|
}
|
|
306
|
-
|
|
307
270
|
/**
|
|
308
271
|
* handle the MxN properties in the associative 'over' table
|
|
309
272
|
* */
|
|
310
273
|
function handleKeyPropertiesInOverTable(inner, dbSeg) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
var i;
|
|
314
|
-
|
|
274
|
+
let seg1overProp, seg1parentsJoinProp, seg1childsJoinProp;
|
|
275
|
+
let seg2overProp, seg2parentsJoinProp, seg2childsJoinProp;
|
|
315
276
|
//create join property list from the first end ('dependent' | 'principal')
|
|
316
277
|
seg1overProp = (dbSeg.isPrincipal() ? 'dependent' : 'principal'); // seg1 is on the contrary to dbSeg (that referes to dbSegmentLast
|
|
317
278
|
seg1parentsJoinProp = dbSeg.getFrom().joinproperties;
|
|
318
279
|
seg1childsJoinProp = dbSeg.getOver()[seg1overProp];
|
|
319
|
-
|
|
320
|
-
for (i = 0; i < seg1parentsJoinProp.length; i++) {
|
|
280
|
+
for (let i = 0; i < seg1parentsJoinProp.length; i++) {
|
|
321
281
|
inner.addWhereAnded(new edm.BinaryOperator(edm.EQ,
|
|
322
282
|
/* no dbType required as the binary operator compares to properties, not property and value */
|
|
323
283
|
new edm.Property(seg1parentsJoinProp[i], dbSeg.previousDBSegment.getAlias()),
|
|
@@ -330,8 +290,7 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
330
290
|
seg2overProp = (dbSeg.isPrincipal() ? 'principal' : 'dependent');
|
|
331
291
|
seg2parentsJoinProp = dbSeg.getOver()[seg2overProp];
|
|
332
292
|
seg2childsJoinProp = dbSeg.getTo().joinproperties;
|
|
333
|
-
for (i = 0; i < seg2parentsJoinProp.length; i++) {
|
|
334
|
-
|
|
293
|
+
for (let i = 0; i < seg2parentsJoinProp.length; i++) {
|
|
335
294
|
inner.addWhereAnded(new edm.BinaryOperator(edm.EQ,
|
|
336
295
|
/* no dbType required as the binary operator compares to properties, not property and value */
|
|
337
296
|
new edm.Property(seg2childsJoinProp[i], dbSeg.getAlias()),
|
|
@@ -341,7 +300,6 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
341
300
|
));
|
|
342
301
|
}
|
|
343
302
|
}
|
|
344
|
-
|
|
345
303
|
/**
|
|
346
304
|
* handle the 1xN properties in the corresponding table
|
|
347
305
|
* */
|
|
@@ -349,9 +307,7 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
349
307
|
//create join property list
|
|
350
308
|
const parentsJoinProp = dbSeg.getFrom().joinproperties;
|
|
351
309
|
const childsJoinProp = dbSeg.getTo().joinproperties;
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
for (i = 0; i < parentsJoinProp.length; i++) {
|
|
310
|
+
for (let i = 0; i < parentsJoinProp.length; i++) {
|
|
355
311
|
inner.addWhereAnded(new edm.BinaryOperator(edm.EQ,
|
|
356
312
|
/* no dbType required as the binary operator compares to properties, not property and value */
|
|
357
313
|
new edm.Property(parentsJoinProp[i], dbSeg.previousDBSegment.getAlias()),
|
|
@@ -361,8 +317,6 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
361
317
|
));
|
|
362
318
|
}
|
|
363
319
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
320
|
/**
|
|
367
321
|
* Creates a sql command to select data to which the resource path points to, all segments of the resource path with their dbSeg equivalents are joined
|
|
368
322
|
* Sample: select "FromEntity1"."KEY_1" "0", "FromEntity1"."KEY_1", "FromEntity1"."INTEGER_1", "FromEntity1"."NVARCHAR_1" from "xsodata.test.tables::calc_nav__entity_from" as "FromEntity1"
|
|
@@ -372,21 +326,17 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
372
326
|
*/
|
|
373
327
|
function simpleSelectJoins(dbSeg, sqlContext) {
|
|
374
328
|
sqlContext.context.logger.debug('createGetStatements', 'simpleSelectJoins');
|
|
375
|
-
|
|
376
329
|
//create select statement
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
330
|
+
const stm = new sql.Select();
|
|
331
|
+
let inner = null;
|
|
380
332
|
if (dbSeg.previousDBSegment) { //end of recursion
|
|
381
333
|
inner = simpleSelectJoins(dbSeg.previousDBSegment, sqlContext);
|
|
382
|
-
|
|
383
334
|
if (dbSeg.getOver()) {
|
|
384
335
|
handleKeyPropertiesInOverTable(inner, dbSeg);
|
|
385
336
|
} else {
|
|
386
337
|
handleKeyProperties(inner, dbSeg);
|
|
387
338
|
}
|
|
388
339
|
}
|
|
389
|
-
|
|
390
340
|
//SELECT
|
|
391
341
|
if (dbSeg.nextDBSegment) {
|
|
392
342
|
stm.addSelects([new sql.SelectFormula(null, '1')]);
|
|
@@ -399,14 +349,11 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
399
349
|
// if (in future) an association via input parameter is used then the input parameter values must be added via ? into the sql command
|
|
400
350
|
// that's because calcview don't return their input parameter in the result set
|
|
401
351
|
let tmp = dbSeg.getPropertiesForSelectCollectInputParameters();
|
|
402
|
-
|
|
403
352
|
// since the input parameters may not be returned from the calcview the parameters are merged after the select
|
|
404
353
|
// from "calcview2" into the result. // Q: What does that mean: "calcview2"?
|
|
405
354
|
stm.byPassInputs = tmp.input;
|
|
406
355
|
stm.addSelects(tmp.selects);
|
|
407
|
-
|
|
408
356
|
stm.addSelects(dbSeg.getKeyPropertiesNotSelectedForSelect(undefined, dbSeg.entityType.inputParameters));
|
|
409
|
-
|
|
410
357
|
// keep aliased key properties
|
|
411
358
|
let selectProperties = dbSeg.getKeyProperties0123ForSelectOnCalcViewAs0123();
|
|
412
359
|
dbSeg.setAliasedKeyPropertiesOnCalcView(selectProperties);
|
|
@@ -415,20 +362,14 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
415
362
|
stm.addSelects(dbSeg.getPropertiesForSelect());
|
|
416
363
|
stm.addSelects(dbSeg.getKeyPropertiesNotSelectedForSelect());
|
|
417
364
|
}
|
|
418
|
-
//}
|
|
419
|
-
//stm.addSelects(dbSeg.getAllSelectedPropertiesConsideringAggregates());
|
|
420
365
|
}
|
|
421
|
-
|
|
422
366
|
if (dbSeg._ExpandedNavigations.length > 0 || dbSeg._SelectedNavigations.length > 0) {
|
|
423
367
|
stm.addSelects(dbSeg.getNavPropertiesForSelect());
|
|
424
368
|
}
|
|
425
|
-
//stm.addSelects(dbSeg.getQNonKeyProperties());
|
|
426
369
|
if (sqlContext.systemQueryParameters.inlinecount && !countFallback) {
|
|
427
370
|
stm.addSelects(new sql.SelectFormula(null, 'count(*) over () as ', '0count'));
|
|
428
371
|
}
|
|
429
|
-
|
|
430
372
|
}
|
|
431
|
-
|
|
432
373
|
//FROM
|
|
433
374
|
if (dbSeg.nextDBSegment && dbSeg.nextDBSegment.getOver()) {
|
|
434
375
|
stm.addFrom({
|
|
@@ -437,8 +378,7 @@ function masterTableSimpleSelect(sqlContext, countFallback) {
|
|
|
437
378
|
alias: dbSeg.getAssocAlias()
|
|
438
379
|
});
|
|
439
380
|
}
|
|
440
|
-
|
|
441
|
-
//fromSource.parameters = dbSeg.inputParams;
|
|
381
|
+
const fromSource = dbSeg.getAliasedTableName();
|
|
442
382
|
stm.addFrom(fromSource, dbSeg.getInputParameters());
|
|
443
383
|
if (inner) {
|
|
444
384
|
//WHERE set Exists first
|
|
@@ -460,10 +400,10 @@ function replaceEdmPropertiesWithSqlProperties(dbSeg, expression) {
|
|
|
460
400
|
|
|
461
401
|
function masterTableCreate(sqlContext, rId) {
|
|
462
402
|
sqlContext.context.logger.debug('createGetStatements', 'masterTableCreate');
|
|
463
|
-
|
|
464
|
-
|
|
403
|
+
const dbSeg = sqlContext.dbSegLast;
|
|
404
|
+
const isCount = sqlContext.systemQueryParameters.inlinecount;
|
|
465
405
|
|
|
466
|
-
|
|
406
|
+
const stmCreate = new sql.Create();
|
|
467
407
|
stmCreate.setModifiers(['local', 'temporary', dbSeg.entityType.tableStoreType]);
|
|
468
408
|
stmCreate.setTableName(rId);
|
|
469
409
|
|
|
@@ -494,17 +434,17 @@ function masterTableInsert(sqlContext) {
|
|
|
494
434
|
|
|
495
435
|
//SystemQuery option order: $format, $inlinecount, $filter, $orderby, $skiptoken, $skip, $top, $expand.
|
|
496
436
|
|
|
497
|
-
|
|
437
|
+
const dbSeg = sqlContext.dbSegLast;
|
|
498
438
|
|
|
499
|
-
|
|
439
|
+
const stmInsert = new sql.Insert();
|
|
500
440
|
stmInsert.setTableName({ table: dbSeg.sql.rId });
|
|
501
441
|
|
|
502
|
-
|
|
442
|
+
const selectRow = new sql.Select();
|
|
503
443
|
selectRow.addSelects(new sql.SelectFormula(null, '*'));
|
|
504
444
|
selectRow.addSelects(new sql.OverFormula('1row'));
|
|
505
445
|
|
|
506
446
|
|
|
507
|
-
|
|
447
|
+
const subSelect = exports._masterTableSimpleSelect(sqlContext);
|
|
508
448
|
|
|
509
449
|
selectRow.setFromBySubQuery(subSelect);
|
|
510
450
|
stmInsert.setSubSelect(selectRow);
|
|
@@ -514,9 +454,9 @@ function masterTableInsert(sqlContext) {
|
|
|
514
454
|
|
|
515
455
|
function masterTableSelect(sqlContext) {
|
|
516
456
|
sqlContext.context.logger.debug('createGetStatements', 'masterTableSelect');
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
457
|
+
const dbSeg = sqlContext.dbSegLast;
|
|
458
|
+
const stmSelect = new sql.Select();
|
|
459
|
+
const isCount = sqlContext.systemQueryParameters.inlinecount;
|
|
520
460
|
|
|
521
461
|
addSelectsForSelectFromTmp(stmSelect, dbSeg);
|
|
522
462
|
|
|
@@ -547,13 +487,15 @@ function masterTableSelect(sqlContext) {
|
|
|
547
487
|
}
|
|
548
488
|
|
|
549
489
|
function expandedTables(sqlContext, parentSeg, path) {
|
|
550
|
-
|
|
490
|
+
const navigationNames = parentSeg._ExpandedNavigations,
|
|
551
491
|
truncateContainer = sqlContext.context.sql.cleanSessionTruncateContainer,
|
|
552
492
|
dropContainer = sqlContext.context.sql.cleanSessionDropContainer;
|
|
493
|
+
let truncateStmt;
|
|
494
|
+
let dropStmt;
|
|
553
495
|
|
|
554
496
|
//loop thought expanded tables
|
|
555
|
-
for (
|
|
556
|
-
|
|
497
|
+
for (const navigationName of navigationNames) {
|
|
498
|
+
const dbSegExpanded = parentSeg.getRelevantNavigationSegments()[navigationName];
|
|
557
499
|
|
|
558
500
|
dbSegExpanded.sql.stmContainer = new sql.GetContainer();
|
|
559
501
|
|
|
@@ -599,7 +541,7 @@ function expandedTables(sqlContext, parentSeg, path) {
|
|
|
599
541
|
}
|
|
600
542
|
|
|
601
543
|
function expandCreate(dbSeg) {
|
|
602
|
-
|
|
544
|
+
const stmCreate = new sql.Create();
|
|
603
545
|
|
|
604
546
|
stmCreate.setModifiers(['local', 'temporary', dbSeg.entityType.tableStoreType]);
|
|
605
547
|
stmCreate.setTableName(dbSeg.sql.rId);
|
|
@@ -623,9 +565,9 @@ function expandCreate(dbSeg) {
|
|
|
623
565
|
}
|
|
624
566
|
|
|
625
567
|
function expandInsert(dbSeg, sqlContext) {
|
|
626
|
-
|
|
568
|
+
const subSelect = exports._expandSimpleSelect(dbSeg, undefined, sqlContext);
|
|
627
569
|
|
|
628
|
-
|
|
570
|
+
const stmInsert = new sql.Insert();
|
|
629
571
|
stmInsert.setTableName({ table: dbSeg.sql.rId });
|
|
630
572
|
stmInsert.setSubSelect(subSelect);
|
|
631
573
|
return stmInsert;
|
|
@@ -640,13 +582,13 @@ function expandInsert(dbSeg, sqlContext) {
|
|
|
640
582
|
* @returns {Select}
|
|
641
583
|
*/
|
|
642
584
|
function expandSimpleSelect(dbSeg, addEtag, sqlContext) {
|
|
643
|
-
|
|
585
|
+
const subSelect = new sql.Select();
|
|
644
586
|
|
|
645
587
|
//SELECT
|
|
646
588
|
//this adds the 1row index from the parent table.
|
|
647
589
|
subSelect.addSelects(new sql.SelectProperty(dbSeg.previousDBSegment.getAlias(), '1row', null, '0row'));
|
|
648
590
|
|
|
649
|
-
|
|
591
|
+
const over = createOverWithOrderBys(dbSeg); //this ensure the
|
|
650
592
|
subSelect.addSelects(over);
|
|
651
593
|
|
|
652
594
|
//Over with 1row is not required here because this dbSeg has no expands
|
|
@@ -663,7 +605,7 @@ function expandSimpleSelect(dbSeg, addEtag, sqlContext) {
|
|
|
663
605
|
alias: dbSeg.previousDBSegment.getAlias()
|
|
664
606
|
});
|
|
665
607
|
|
|
666
|
-
|
|
608
|
+
const onStatements = createOnStatements(dbSeg);
|
|
667
609
|
|
|
668
610
|
if (onStatements.first.length > 0) {
|
|
669
611
|
subSelect.addJoin({
|
|
@@ -672,7 +614,7 @@ function expandSimpleSelect(dbSeg, addEtag, sqlContext) {
|
|
|
672
614
|
}, onStatements.first);
|
|
673
615
|
}
|
|
674
616
|
|
|
675
|
-
|
|
617
|
+
const joinSelect = new sql.Select();
|
|
676
618
|
if (dbSeg.entityType.hasGeneratedKey()) {
|
|
677
619
|
joinSelect.addSelects(dbSeg.getAllSelectedIncludingJoinPropertiesConsideringAggregates());
|
|
678
620
|
} else {
|
|
@@ -690,7 +632,7 @@ function expandSimpleSelect(dbSeg, addEtag, sqlContext) {
|
|
|
690
632
|
|
|
691
633
|
// group bys
|
|
692
634
|
if (dbSeg.entityType.hasAggregates()) {
|
|
693
|
-
|
|
635
|
+
const groupBys = dbSeg.getAllSelectedNonAggregateIncludingJoinPropertiesForGroupBy();
|
|
694
636
|
joinSelect.addGroupBys(groupBys);
|
|
695
637
|
}
|
|
696
638
|
|
|
@@ -714,7 +656,7 @@ function expandSimpleSelect(dbSeg, addEtag, sqlContext) {
|
|
|
714
656
|
}
|
|
715
657
|
|
|
716
658
|
function createOverWithOrderBys(dbSeg) {
|
|
717
|
-
|
|
659
|
+
const over = new sql.OverFormula('1row'); //this ensure the
|
|
718
660
|
|
|
719
661
|
/* no dbType required as property is used only for SortOrder */
|
|
720
662
|
over.addSortOrder(new edm.SortOrder(new edm.Property('1row', dbSeg.previousDBSegment.getAlias()), 'ASC'));
|
|
@@ -729,11 +671,11 @@ function createOverWithOrderBys(dbSeg) {
|
|
|
729
671
|
}
|
|
730
672
|
|
|
731
673
|
function createOnStatements(dbSeg) {
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
674
|
+
const parentsJoinProps = dbSeg.getFrom().joinproperties;
|
|
675
|
+
const childJoinProps = dbSeg.getTo().joinproperties;
|
|
676
|
+
const overJoinProps = dbSeg.getOver();
|
|
735
677
|
|
|
736
|
-
|
|
678
|
+
const onStatements = {
|
|
737
679
|
first: [],
|
|
738
680
|
second: []
|
|
739
681
|
};
|
|
@@ -776,7 +718,7 @@ function createOnStatements(dbSeg) {
|
|
|
776
718
|
}
|
|
777
719
|
|
|
778
720
|
function expandSelect(dbSeg, sqlContext) {
|
|
779
|
-
|
|
721
|
+
const subSelect = new sql.Select();
|
|
780
722
|
|
|
781
723
|
subSelect.addSelects([new sql.SelectProperty(null, '0row')]);
|
|
782
724
|
subSelect.addSelects([new sql.SelectProperty(null, '1row')]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const sql = require('./sqlStatement');
|
|
4
|
+
const sqlTools = require('./sqlTools');
|
|
5
5
|
|
|
6
6
|
function masterTableCreate(sqlContext, rId) {
|
|
7
7
|
return createSQLCreateStmt(sqlContext.dbSegToBeUpdated, rId, true);
|
|
@@ -17,7 +17,7 @@ function masterTableCreate(sqlContext, rId) {
|
|
|
17
17
|
* @returns {Create} SQL CREATE statement
|
|
18
18
|
*/
|
|
19
19
|
function createSQLCreateForAssocTable(sqlContext, rId, from) {
|
|
20
|
-
|
|
20
|
+
const dbSeg = (from === 'principal' ? sqlContext.dbSegPrincipal : sqlContext.dbSegDependent);
|
|
21
21
|
|
|
22
22
|
return createSQLCreateStmt(dbSeg, rId, false);
|
|
23
23
|
}
|
|
@@ -31,7 +31,7 @@ function createSQLCreateForAssocTable(sqlContext, rId, from) {
|
|
|
31
31
|
* @returns {Create} SQL CREATE TEMPORARY TABLE statement
|
|
32
32
|
*/
|
|
33
33
|
function createSQLCreateStmt(dbSeg, rId, withForeignKeyProperties) {
|
|
34
|
-
|
|
34
|
+
const stmCreate = new sql.Create();
|
|
35
35
|
|
|
36
36
|
stmCreate.setModifiers(['local', 'temporary', dbSeg.entityType.tableStoreType]);
|
|
37
37
|
stmCreate.setTableName(rId);
|
|
@@ -62,7 +62,7 @@ function createSQLCreateStmt(dbSeg, rId, withForeignKeyProperties) {
|
|
|
62
62
|
* @returns {Select} SQL SELECT statement.
|
|
63
63
|
*/
|
|
64
64
|
function createSelectTemplate(dbSeg, withForeignKeyProperties) {
|
|
65
|
-
|
|
65
|
+
const stm = new sql.Select();
|
|
66
66
|
|
|
67
67
|
stm.addSelects(dbSeg.getQKeyProperties());
|
|
68
68
|
if (dbSeg._ExpandedNavigations.length > 0) {
|
|
@@ -82,9 +82,9 @@ function createSelectTemplate(dbSeg, withForeignKeyProperties) {
|
|
|
82
82
|
exports.createLinksStatementsCreateTmpTables = function (context, isDeleteScenario) {
|
|
83
83
|
context.logger.silly('createLinksSQLStatements', 'createLinksStatements');
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
const dbSegToBeUpdated = context.oData.links.toBeUpdated;
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
const sqlContext = {
|
|
88
88
|
context: context, // sqlContext gets parent context (includes "isHanaCloudDb")
|
|
89
89
|
netId: context.uniqueNetworkRequestID,
|
|
90
90
|
reqId: context.uniqueRequestID,
|
|
@@ -102,7 +102,7 @@ exports.createLinksStatementsCreateTmpTables = function (context, isDeleteScenar
|
|
|
102
102
|
|
|
103
103
|
dbSegToBeUpdated.sql.stmContainer = new sql.PutContainer();
|
|
104
104
|
|
|
105
|
-
createStatementContainerCreateTmpTables(sqlContext
|
|
105
|
+
createStatementContainerCreateTmpTables(sqlContext);
|
|
106
106
|
};
|
|
107
107
|
|
|
108
108
|
exports.createLinksStatementsInsert = function (context, isDeleteScenario) {
|
|
@@ -115,7 +115,7 @@ exports.createLinksStatementsInsert = function (context, isDeleteScenario) {
|
|
|
115
115
|
|
|
116
116
|
function createStatementContainerCreateTmpTables(sqlContext/*, isDeleteScenario*/) {
|
|
117
117
|
sqlContext.context.logger.debug('createLinksSQLStatements', 'createStatementContainer');
|
|
118
|
-
|
|
118
|
+
const dbSeg = sqlContext.dbSegToBeUpdated;
|
|
119
119
|
|
|
120
120
|
// This is to have same 'context.sql.container' property in all tests
|
|
121
121
|
sqlContext.context.sql.container = dbSeg.sql.stmContainer;
|
|
@@ -159,7 +159,7 @@ function createStatementContainerCreateTmpTables(sqlContext/*, isDeleteScenario*
|
|
|
159
159
|
|
|
160
160
|
function createStatementContainerInsert(sqlContext, isDeleteScenario) {
|
|
161
161
|
sqlContext.context.logger.debug('createLinksSQLStatements', 'createStatementContainer');
|
|
162
|
-
|
|
162
|
+
const dbSeg = sqlContext.dbSegToBeUpdated;
|
|
163
163
|
|
|
164
164
|
//create insert statement for master table
|
|
165
165
|
dbSeg.sql.stmContainer.insertTmp = masterTableInsertToNew(sqlContext, dbSeg.sql.rIdNew, isDeleteScenario);
|
|
@@ -176,9 +176,9 @@ function createStatementContainerInsert(sqlContext, isDeleteScenario) {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
function masterTableInsertToNew(sqlContext, rId, isDeleteScenario) {
|
|
179
|
-
|
|
180
|
-
linkDbSeg = sqlContext.context.oData.links.keySource
|
|
181
|
-
|
|
179
|
+
const dbSeg = sqlContext.dbSegToBeUpdated,
|
|
180
|
+
linkDbSeg = sqlContext.context.oData.links.keySource;
|
|
181
|
+
let subSelect,
|
|
182
182
|
dbValues,
|
|
183
183
|
insertStmt;
|
|
184
184
|
|
|
@@ -209,9 +209,9 @@ function masterTableInsertToNew(sqlContext, rId, isDeleteScenario) {
|
|
|
209
209
|
|
|
210
210
|
function masterTableInsertToOld(sqlContext, rId) {
|
|
211
211
|
sqlContext.context.logger.debug('createLinksSQLStatements', 'masterTableInsertToOld');
|
|
212
|
-
|
|
212
|
+
const dbSeg = sqlContext.dbSegToBeUpdated;
|
|
213
213
|
|
|
214
|
-
|
|
214
|
+
const subSelect = new sql.Select();
|
|
215
215
|
subSelect.addSelects(dbSeg.getQKeyProperties());
|
|
216
216
|
subSelect.addSelects(dbSeg.getQForeignKeyProperties());
|
|
217
217
|
subSelect.setFrom(dbSeg.getAliasedTableName());
|
|
@@ -220,7 +220,7 @@ function masterTableInsertToOld(sqlContext, rId) {
|
|
|
220
220
|
subSelect.addWhereKeyValuePairs(dbSeg.getQForeignKeyWithValues());
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
|
|
223
|
+
const stm = new sql.Insert();
|
|
224
224
|
stm.setTableName({ table: rId });
|
|
225
225
|
stm.setSubSelect(subSelect);
|
|
226
226
|
|
|
@@ -236,10 +236,10 @@ function masterTableInsertToOld(sqlContext, rId) {
|
|
|
236
236
|
* @returns {Insert} SQL INSERT statement
|
|
237
237
|
*/
|
|
238
238
|
function createInsertStmtForAssocTable(sqlContext, rId, from) {
|
|
239
|
-
|
|
239
|
+
const dbSeg = (from === 'principal' ? sqlContext.dbSegPrincipal : sqlContext.dbSegDependent);
|
|
240
240
|
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
const stm = new sql.Insert();
|
|
242
|
+
const subSelect = new sql.Select();
|
|
243
243
|
|
|
244
244
|
subSelect.addSelects(dbSeg.getQKeyProperties());
|
|
245
245
|
subSelect.addSelects(dbSeg.getQNonKeyProperties());
|
|
@@ -260,9 +260,9 @@ function createInsertStmtForAssocTable(sqlContext, rId, from) {
|
|
|
260
260
|
*/
|
|
261
261
|
function masterTableUpdate(sqlContext, rId) {
|
|
262
262
|
sqlContext.context.logger.debug('createLinksSQLStatements', 'masterTableUpdate');
|
|
263
|
-
|
|
263
|
+
const dbSeg = sqlContext.dbSegToBeUpdated;
|
|
264
264
|
|
|
265
|
-
|
|
265
|
+
const update = new sql.Update();
|
|
266
266
|
update.setTable(dbSeg.getAliasedTableName('PERM')); //overwrite alias
|
|
267
267
|
|
|
268
268
|
update.addSetCopyProperties(dbSeg.getQForeignKeyProperties(), 'TEMP');
|
|
@@ -296,14 +296,14 @@ exports.createMNSQLContext = function createMNSQLContext(context, dbSegment) {
|
|
|
296
296
|
|
|
297
297
|
exports.createMNStatementContainerCreateTmpTables = function createMNStatementContainerCreateTmpTable(sqlContext) {
|
|
298
298
|
sqlContext.context.logger.debug('createLinksSQLStatements', 'createMNStatementContainer');
|
|
299
|
-
|
|
299
|
+
const dbSeg = sqlContext.dbSegLast;
|
|
300
300
|
|
|
301
301
|
// This is to have same 'context.sql.container' property in all tests
|
|
302
302
|
sqlContext.context.sql.container = dbSeg.sql.stmContainer;
|
|
303
303
|
|
|
304
304
|
|
|
305
|
-
|
|
306
|
-
|
|
305
|
+
const over = dbSeg.getOver().object; // e.g. "xsodata.test.tables::complex_assoc_atob"
|
|
306
|
+
const alias = over.substring(over.indexOf('::') + 2, over.length);
|
|
307
307
|
dbSeg.sql.rId = sqlTools.rIdToNewTableName(alias, sqlContext.netId, sqlContext.reqId, sqlContext.rId++);
|
|
308
308
|
// principal and dependent (temp) tables, to be used in custom exits
|
|
309
309
|
dbSeg.sql.rIdPrincipal = sqlTools.rIdToAlteredTableName('#p', sqlContext.dbSegPrincipal._AliasName, sqlContext.netId, sqlContext.reqId, sqlContext.rId++);
|
|
@@ -336,7 +336,7 @@ exports.createMNStatementContainerCreateTmpTables = function createMNStatementCo
|
|
|
336
336
|
};
|
|
337
337
|
exports.createMNStatementContainerInsert = function createMNStatementContainerInsert(sqlContext) {
|
|
338
338
|
sqlContext.context.logger.debug('createLinksSQLStatements', 'createMNStatementContainer');
|
|
339
|
-
|
|
339
|
+
const dbSeg = sqlContext.dbSegLast;
|
|
340
340
|
|
|
341
341
|
//create insert statements for principal/dependent tables
|
|
342
342
|
dbSeg.sql.stmContainer.insertPrincipal = createInsertStmtForAssocTable(sqlContext, dbSeg.sql.rIdPrincipal, 'principal');
|
|
@@ -346,8 +346,8 @@ exports.createMNStatementContainerInsert = function createMNStatementContainerIn
|
|
|
346
346
|
|
|
347
347
|
function masterMNTableCreate(sqlContext, rId) {
|
|
348
348
|
sqlContext.context.logger.debug('createLinksSQLStatements', 'masterMNTableCreate');
|
|
349
|
-
|
|
350
|
-
|
|
349
|
+
const dbSeg = sqlContext.dbSegLast;
|
|
350
|
+
const stmCreate = new sql.Create();
|
|
351
351
|
stmCreate.setModifiers(['local', 'temporary', dbSeg.entityType.tableStoreType]);
|
|
352
352
|
stmCreate.setTableName(rId);
|
|
353
353
|
|