@sap/cds-compiler 6.7.3 → 6.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/bin/cdsc.js +5 -5
- package/bin/cdsse.js +1 -1
- package/lib/api/main.js +9 -8
- package/lib/api/options.js +2 -1
- package/lib/api/validate.js +1 -1
- package/lib/base/error.js +2 -0
- package/lib/base/message-registry.js +7 -2
- package/lib/base/messages.js +2 -2
- package/lib/{optionProcessor.js → base/optionProcessor.js} +3 -3
- package/lib/base/{model.js → specialOptions.js} +16 -39
- package/lib/checks/arrayOfs.js +1 -1
- package/lib/checks/elements.js +1 -1
- package/lib/checks/enricher.js +2 -2
- package/lib/checks/featureFlags.js +54 -24
- package/lib/checks/foreignKeys.js +1 -1
- package/lib/checks/invalidTarget.js +1 -1
- package/lib/checks/managedInType.js +1 -1
- package/lib/checks/onConditions.js +1 -1
- package/lib/checks/queryNoDbArtifacts.js +1 -1
- package/lib/checks/validator.js +10 -14
- package/lib/compiler/builtins.js +1 -1
- package/lib/compiler/checks.js +3 -3
- package/lib/compiler/define.js +5 -2
- package/lib/{base → compiler}/dictionaries.js +2 -0
- package/lib/compiler/extend.js +2 -2
- package/lib/compiler/generate.js +2 -2
- package/lib/compiler/index.js +11 -3
- package/lib/compiler/kick-start.js +1 -1
- package/lib/compiler/populate.js +2 -2
- package/lib/compiler/resolve.js +4 -2
- package/lib/compiler/shared.js +35 -6
- package/lib/compiler/utils.js +2 -4
- package/lib/compiler/xpr-rewrite.js +1 -1
- package/lib/edm/annotations/edmJson.js +2 -4
- package/lib/edm/annotations/genericTranslation.js +2 -1
- package/lib/edm/csn2edm.js +3 -2
- package/lib/edm/edmAnnoPreprocessor.js +1 -1
- package/lib/edm/edmInboundChecks.js +2 -1
- package/lib/edm/edmPreprocessor.js +3 -3
- package/lib/edm/edmUtils.js +2 -2
- package/lib/gen/BaseParser.js +1 -12
- package/lib/gen/CdlGrammar.checksum +1 -1
- package/lib/gen/CdlParser.js +1068 -1067
- package/lib/json/from-csn.js +7 -2
- package/lib/json/to-csn.js +17 -2
- package/lib/main.js +3 -3
- package/lib/model/csnUtils.js +2 -2
- package/lib/modelCompare/compare.js +1 -1
- package/lib/modelCompare/utils/filter.js +1 -0
- package/lib/parsers/AstBuildingParser.js +40 -3
- package/lib/parsers/index.js +1 -1
- package/lib/render/manageConstraints.js +1 -1
- package/lib/render/toCdl.js +3 -3
- package/lib/render/toHdbcds.js +2 -2
- package/lib/render/toSql.js +7 -7
- package/lib/render/utils/common.js +9 -2
- package/lib/render/utils/sql.js +14 -5
- package/lib/render/utils/standardDatabaseFunctions.js +108 -99
- package/lib/sql-identifier.js +9 -1
- package/lib/{model → tool-lib}/enrichCsn.js +2 -2
- package/lib/{model → tool-lib}/revealInternalProperties.js +2 -1
- package/lib/transform/addTenantFields.js +1 -1
- package/lib/transform/db/applyTransformations.js +1 -1
- package/lib/transform/db/assertUnique.js +1 -1
- package/lib/transform/db/assocsToQueries/transformExists.js +1 -1
- package/lib/transform/db/backlinks.js +2 -2
- package/lib/transform/db/expansion.js +2 -2
- package/lib/transform/db/flattening.js +3 -4
- package/lib/transform/db/killAnnotations.js +1 -0
- package/lib/transform/db/processSqlServices.js +2 -1
- package/lib/transform/db/rewriteCalculatedElements.js +2 -2
- package/lib/transform/db/temporal.js +30 -5
- package/lib/transform/db/views.js +16 -20
- package/lib/transform/draft/db.js +1 -2
- package/lib/transform/effective/associations.js +1 -1
- package/lib/transform/effective/flattening.js +1 -1
- package/lib/transform/effective/main.js +19 -4
- package/lib/transform/effective/types.js +1 -1
- package/lib/transform/{odata/fioriTreeViews.js → fioriTreeViews.js} +48 -25
- package/lib/transform/forOdata.js +5 -5
- package/lib/transform/forRelationalDB.js +41 -9
- package/lib/transform/localized.js +2 -2
- package/lib/transform/odata/createForeignKeys.js +1 -1
- package/lib/transform/odata/flattening.js +2 -2
- package/lib/transform/odata/toFinalBaseType.js +3 -2
- package/lib/transform/odata/typesExposure.js +3 -2
- package/lib/transform/transformUtils.js +2 -2
- package/lib/transform/translateAssocsToJoins.js +2 -1
- package/lib/transform/tupleExpansion.js +4 -4
- package/lib/transform/universalCsn/universalCsnEnricher.js +7 -3
- package/lib/transform/universalCsn/utils.js +1 -1
- package/lib/{base → utils}/lazyload.js +9 -0
- package/lib/{base → utils}/node-helpers.js +2 -0
- package/lib/utils/objectUtils.js +29 -6
- package/lib/{base → utils}/optionProcessorHelper.js +16 -6
- package/package.json +2 -2
- /package/lib/{model → base}/cloneCsn.js +0 -0
- /package/lib/{model → base}/csnRefs.js +0 -0
- /package/lib/{model/api.js → base/model-api.js} +0 -0
- /package/lib/{api → base}/trace.js +0 -0
- /package/lib/{model → base}/xprAsTree.js +0 -0
- /package/lib/{inspect → tool-lib}/index.js +0 -0
- /package/lib/{inspect → tool-lib}/inspectModelStatistics.js +0 -0
- /package/lib/{inspect → tool-lib}/inspectPropagation.js +0 -0
- /package/lib/{inspect → tool-lib}/inspectUtils.js +0 -0
- /package/lib/{base → utils}/shuffle.js +0 -0
package/lib/json/from-csn.js
CHANGED
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
* @returns {any} XSN property (e.g. string, object, ...)
|
|
116
116
|
*/
|
|
117
117
|
|
|
118
|
-
const { dictAdd } = require('../
|
|
118
|
+
const { dictAdd } = require('../compiler/dictionaries');
|
|
119
119
|
const { quotedLiteralPatterns } = require('../compiler/builtins');
|
|
120
120
|
const { isAnnotationExpression } = require('../base/builtins');
|
|
121
121
|
const { CompilerAssertion } = require('../base/error');
|
|
@@ -752,7 +752,7 @@ const schema = compileSchema( {
|
|
|
752
752
|
type: namespace,
|
|
753
753
|
},
|
|
754
754
|
meta: { // meta information
|
|
755
|
-
type:
|
|
755
|
+
type: meta, // TODO: should we test s/th here?
|
|
756
756
|
},
|
|
757
757
|
version: { // deprecated top-level property
|
|
758
758
|
type: ignore,
|
|
@@ -904,6 +904,11 @@ function arrayOf( fn, filter = undefined ) {
|
|
|
904
904
|
|
|
905
905
|
// Generic functions, objects (std signature) --------------------------------
|
|
906
906
|
|
|
907
|
+
function meta( obj ) {
|
|
908
|
+
ignore( obj );
|
|
909
|
+
return obj;
|
|
910
|
+
}
|
|
911
|
+
|
|
907
912
|
function ignore( obj ) {
|
|
908
913
|
if (obj && typeof obj === 'object') {
|
|
909
914
|
const array = (Array.isArray( obj )) ? obj : Object.values( obj );
|
package/lib/json/to-csn.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
14
|
const { locationString } = require('../base/messages');
|
|
15
|
-
const { isBetaEnabled } = require('../base/
|
|
15
|
+
const { isBetaEnabled } = require('../base/specialOptions');
|
|
16
16
|
const { pathName } = require('../compiler/utils');
|
|
17
17
|
const { CompilerAssertion } = require('../base/error');
|
|
18
18
|
|
|
@@ -260,10 +260,25 @@ function compactModel( model, options = model.options || {} ) {
|
|
|
260
260
|
break;
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
const srcNames = Object.keys( srcDict );
|
|
264
|
+
const firstMeta = srcDict[srcNames[0]].meta;
|
|
265
|
+
const meta = srcNames.length === 1 && firstMeta ? { ...firstMeta } : undefined;
|
|
266
|
+
if (meta?.flavor)
|
|
267
|
+
delete meta.flavor; // not supported, compilerCsnFlavor is used instead
|
|
268
|
+
const flavorMap = {
|
|
269
|
+
client: 'inferred',
|
|
270
|
+
gensrc: 'xtended',
|
|
271
|
+
universal: 'universal',
|
|
272
|
+
};
|
|
273
|
+
const compilerCsnFlavor = flavorMap[options.csnFlavor] ||
|
|
274
|
+
(options.parseCdl ? 'parsed' : 'inferred');
|
|
263
275
|
if (!options.testMode) {
|
|
264
|
-
csn.meta = Object.assign( {}, model.meta, { creator } );
|
|
276
|
+
csn.meta = Object.assign( {}, model.meta, meta, { creator, compilerCsnFlavor } );
|
|
265
277
|
csn.$version = csnVersion;
|
|
266
278
|
}
|
|
279
|
+
else if (meta !== undefined) {
|
|
280
|
+
csn.meta = Object.assign( {}, meta );
|
|
281
|
+
}
|
|
267
282
|
return csn;
|
|
268
283
|
}
|
|
269
284
|
|
package/lib/main.js
CHANGED
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
|
|
15
15
|
'use strict';
|
|
16
16
|
|
|
17
|
-
const lazyload = require('./
|
|
17
|
+
const lazyload = require('./utils/lazyload')( module );
|
|
18
18
|
|
|
19
|
-
const { traceApi } = require('./
|
|
19
|
+
const { traceApi } = require('./base/trace');
|
|
20
20
|
|
|
21
21
|
const snapi = lazyload('./api/main');
|
|
22
22
|
const csnUtils = lazyload('./model/csnUtils');
|
|
23
|
-
const modelApi = lazyload('./model
|
|
23
|
+
const modelApi = lazyload('./base/model-api');
|
|
24
24
|
const messages = lazyload('./base/messages');
|
|
25
25
|
const sqlIdentifier = lazyload('./sql-identifier');
|
|
26
26
|
const keywords = lazyload( './base/keywords' );
|
package/lib/model/csnUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { csnRefs, implicitAs, pathId } = require('
|
|
3
|
+
const { csnRefs, implicitAs, pathId } = require('../base/csnRefs');
|
|
4
4
|
const {
|
|
5
5
|
transformExpression,
|
|
6
6
|
transformAnnotationExpression,
|
|
@@ -13,7 +13,7 @@ const { isBuiltinType, isAnnotationExpression } = require('../base/builtins');
|
|
|
13
13
|
const { ModelError, CompilerAssertion } = require('../base/error');
|
|
14
14
|
const { typeParameters } = require('../compiler/builtins');
|
|
15
15
|
const { forEach } = require('../utils/objectUtils');
|
|
16
|
-
const { cloneAnnotationValue } = require('
|
|
16
|
+
const { cloneAnnotationValue } = require('../base/cloneCsn');
|
|
17
17
|
|
|
18
18
|
// Low-level utility functions to work with compact CSN.
|
|
19
19
|
|
|
@@ -148,6 +148,7 @@ const defaultAllowedTypeChanges = {
|
|
|
148
148
|
'cds.Integer': [ 'cds.Int32', 'cds.Int64', 'cds.Integer64' ],
|
|
149
149
|
'cds.Integer64': [ 'cds.Int64' ],
|
|
150
150
|
'cds.Int64': [ 'cds.Integer64' ],
|
|
151
|
+
'cds.String': [ 'cds.LargeString' ],
|
|
151
152
|
};
|
|
152
153
|
|
|
153
154
|
const allowedTypeChanges = {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const BaseParser = require( '../gen/BaseParser' );
|
|
4
4
|
|
|
5
5
|
const { Location } = require( '../base/location' );
|
|
6
|
-
const { dictAdd, dictAddArray } = require('../
|
|
6
|
+
const { dictAdd, dictAddArray } = require('../compiler/dictionaries');
|
|
7
7
|
const { functionsWithoutParentheses } = require('./identifiers');
|
|
8
8
|
|
|
9
9
|
const { pathName } = require('../compiler/utils');
|
|
@@ -39,7 +39,7 @@ const valueTokens = {
|
|
|
39
39
|
true: true,
|
|
40
40
|
};
|
|
41
41
|
const valueTokensLength = Object.values( valueTokens ).length;
|
|
42
|
-
//
|
|
42
|
+
// if expectedArray contains all the following tokens, replace them by 'Literal'
|
|
43
43
|
const literalTokens = {
|
|
44
44
|
Number: true,
|
|
45
45
|
QuotedLiteral: true,
|
|
@@ -51,6 +51,29 @@ const literalTokens = {
|
|
|
51
51
|
};
|
|
52
52
|
const literalTokensLength = Object.values( literalTokens ).length;
|
|
53
53
|
|
|
54
|
+
// if expectedArray contains all the following tokens, replace them by 'Comparison'
|
|
55
|
+
const comparisonTokens = {
|
|
56
|
+
'=': true,
|
|
57
|
+
'<>': true,
|
|
58
|
+
'>': true,
|
|
59
|
+
'>=': true,
|
|
60
|
+
'<': true,
|
|
61
|
+
'<=': true,
|
|
62
|
+
'!=': true,
|
|
63
|
+
'==': true,
|
|
64
|
+
};
|
|
65
|
+
const comparisonTokensLength = Object.values( comparisonTokens ).length;
|
|
66
|
+
|
|
67
|
+
// if expectedArray contains all the following tokens, replace them by 'Operator'
|
|
68
|
+
const operatorTokens = {
|
|
69
|
+
'+': true,
|
|
70
|
+
'-': true,
|
|
71
|
+
'*': true,
|
|
72
|
+
'/': true,
|
|
73
|
+
'||': true,
|
|
74
|
+
};
|
|
75
|
+
const operatorTokensLength = Object.values( operatorTokens ).length;
|
|
76
|
+
|
|
54
77
|
const extensionDicts = {
|
|
55
78
|
elements: true, enum: true, params: true, returns: true,
|
|
56
79
|
};
|
|
@@ -127,6 +150,19 @@ class AstBuildingParser extends BaseParser {
|
|
|
127
150
|
if (withoutLiteralTokens.length + literalTokensLength === array.length)
|
|
128
151
|
array = [ 'Literal', ...withoutLiteralTokens ];
|
|
129
152
|
}
|
|
153
|
+
|
|
154
|
+
const withoutComparisonTokens = raw ? array : array.filter(
|
|
155
|
+
tok => comparisonTokens[tok] !== true
|
|
156
|
+
);
|
|
157
|
+
if (withoutComparisonTokens.length + comparisonTokensLength === array.length)
|
|
158
|
+
array = [ 'Comparison', ...withoutComparisonTokens ];
|
|
159
|
+
|
|
160
|
+
const withoutOperatorTokens = raw ? array : array.filter(
|
|
161
|
+
tok => operatorTokens[tok] !== true
|
|
162
|
+
);
|
|
163
|
+
if (withoutOperatorTokens.length + operatorTokensLength === array.length)
|
|
164
|
+
array = [ 'Operator', ...withoutOperatorTokens ];
|
|
165
|
+
|
|
130
166
|
return array.map( tok => this.antlrName( tok ) )
|
|
131
167
|
.sort( (a, b) => (tokenPrecedence(a) < tokenPrecedence(b) ? -1 : 1) );
|
|
132
168
|
}
|
|
@@ -328,7 +364,8 @@ class AstBuildingParser extends BaseParser {
|
|
|
328
364
|
// TODO: as leanCondition ? `order` should probably appear in the message for
|
|
329
365
|
// test3/Compiler/GrammarRobustness/InvalidSelectInWhere.err.cds
|
|
330
366
|
orderByLimitRestriction( _arg, mode ) {
|
|
331
|
-
if (mode &&
|
|
367
|
+
if (mode &&
|
|
368
|
+
(!this.$allowOrderByLimit && mode !== 'M' || this.precPost_( mode, 0 )))
|
|
332
369
|
return true;
|
|
333
370
|
this.$allowOrderByLimit = !mode;
|
|
334
371
|
return false;
|
package/lib/parsers/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
const lazyload = require('../
|
|
5
|
+
const lazyload = require('../utils/lazyload')( module );
|
|
6
6
|
const { CompilerAssertion } = require( '../base/error' );
|
|
7
7
|
const { createMessageFunctions } = require( '../base/messages' );
|
|
8
8
|
const { XsnSource } = require('../compiler/xsn-model');
|
|
@@ -11,7 +11,7 @@ const { transformForRelationalDBWithCsn } = require('../transform/forRelationalD
|
|
|
11
11
|
const {
|
|
12
12
|
renderReferentialConstraint, getIdentifierUtils,
|
|
13
13
|
} = require('./utils/sql');
|
|
14
|
-
const { sortCsn } = require('../
|
|
14
|
+
const { sortCsn } = require('../base/cloneCsn');
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Used only by `cdsc manageConstraints`.
|
package/lib/render/toCdl.js
CHANGED
|
@@ -20,14 +20,14 @@ const { escapeString, hasUnpairedUnicodeSurrogate } = require('./utils/stringEsc
|
|
|
20
20
|
const { checkCSNVersion } = require('../json/csnVersion');
|
|
21
21
|
const { normalizeTypeRef, forEachDefinition } = require('../model/csnUtils');
|
|
22
22
|
const enrichUniversalCsn = require('../transform/universalCsn/universalCsnEnricher');
|
|
23
|
-
const { isBetaEnabled } = require('../base/
|
|
23
|
+
const { isBetaEnabled } = require('../base/specialOptions');
|
|
24
24
|
const { ModelError, CompilerAssertion } = require('../base/error');
|
|
25
25
|
const { typeParameters, specialFunctions } = require('../compiler/builtins');
|
|
26
26
|
const { isAnnotationExpression } = require('../base/builtins');
|
|
27
27
|
const { forEach } = require('../utils/objectUtils');
|
|
28
28
|
const { isBuiltinType } = require('../base/builtins');
|
|
29
|
-
const { cloneFullCsn } = require('../
|
|
30
|
-
const { getKeysDict, implicitAs } = require('../
|
|
29
|
+
const { cloneFullCsn } = require('../base/cloneCsn');
|
|
30
|
+
const { getKeysDict, implicitAs } = require('../base/csnRefs');
|
|
31
31
|
const { undelimitedIdentifierRegex } = require('../parsers/identifiers');
|
|
32
32
|
const { getNormalizedQuery } = require('../model/csnUtils');
|
|
33
33
|
const {
|
package/lib/render/toHdbcds.js
CHANGED
|
@@ -18,13 +18,13 @@ const {
|
|
|
18
18
|
renderReferentialConstraint,
|
|
19
19
|
} = require('./utils/sql');
|
|
20
20
|
const DuplicateChecker = require('./DuplicateChecker');
|
|
21
|
-
const { isDeprecatedEnabled } = require('../base/
|
|
21
|
+
const { isDeprecatedEnabled } = require('../base/specialOptions');
|
|
22
22
|
const { checkCSNVersion } = require('../json/csnVersion');
|
|
23
23
|
const { timetrace } = require('../utils/timetrace');
|
|
24
24
|
|
|
25
25
|
const { smartId, delimitedId } = require('../sql-identifier');
|
|
26
26
|
const { ModelError, CompilerAssertion } = require('../base/error');
|
|
27
|
-
const { pathId } = require('../
|
|
27
|
+
const { pathId } = require('../base/csnRefs');
|
|
28
28
|
|
|
29
29
|
const $PROJECTION = '$projection';
|
|
30
30
|
const $SELF = '$self';
|
package/lib/render/toSql.js
CHANGED
|
@@ -24,15 +24,15 @@ const {
|
|
|
24
24
|
const DuplicateChecker = require('./DuplicateChecker');
|
|
25
25
|
const { checkCSNVersion } = require('../json/csnVersion');
|
|
26
26
|
const { timetrace } = require('../utils/timetrace');
|
|
27
|
-
const { isBetaEnabled, isDeprecatedEnabled } = require('../base/
|
|
27
|
+
const { isBetaEnabled, isDeprecatedEnabled } = require('../base/specialOptions');
|
|
28
28
|
const sqlIdentifiers = require('../sql-identifier');
|
|
29
|
-
const { sortCsn } = require('../
|
|
29
|
+
const { sortCsn } = require('../base/cloneCsn');
|
|
30
30
|
const { manageConstraints, manageConstraint } = require('./manageConstraints');
|
|
31
31
|
const { renderUniqueConstraintString, renderUniqueConstraintDrop, renderUniqueConstraintAdd } = require('./utils/unique');
|
|
32
32
|
const { ModelError, CompilerAssertion } = require('../base/error');
|
|
33
|
-
const { pathId } = require('../
|
|
33
|
+
const { pathId } = require('../base/csnRefs');
|
|
34
34
|
const { transformExprOperators } = require('./utils/operators');
|
|
35
|
-
const { exprAsTree, condAsTree } = require('../
|
|
35
|
+
const { exprAsTree, condAsTree } = require('../base/xprAsTree');
|
|
36
36
|
|
|
37
37
|
class SqlRenderEnvironment {
|
|
38
38
|
indent = '';
|
|
@@ -114,7 +114,7 @@ function toSqlDdl( csn, options, messageFunctions ) {
|
|
|
114
114
|
const {
|
|
115
115
|
error, warning, info, throwWithAnyError,
|
|
116
116
|
} = messageFunctions;
|
|
117
|
-
const { quoteSqlId, prepareIdentifier, renderArtifactName } = getIdentifierUtils(csn, options);
|
|
117
|
+
const { quoteSqlId, prepareIdentifier, renderArtifactName } = getIdentifierUtils(csn, options, warning);
|
|
118
118
|
const reportedMissingReplacements = Object.create(null);
|
|
119
119
|
|
|
120
120
|
const exprRenderer = createExpressionRenderer({
|
|
@@ -795,7 +795,7 @@ function toSqlDdl( csn, options, messageFunctions ) {
|
|
|
795
795
|
return '';
|
|
796
796
|
env = env.withSubPath([ 'elements', elementName ]);
|
|
797
797
|
const isPostgresAlterColumn = env.alterMode && env.changeType === 'migration' && options.sqlDialect === 'postgres';
|
|
798
|
-
const quotedElementName = quoteSqlId(elementName);
|
|
798
|
+
const quotedElementName = quoteSqlId(elementName, env.path);
|
|
799
799
|
if (duplicateChecker)
|
|
800
800
|
duplicateChecker.addElement(quotedElementName, elm.$location, elementName);
|
|
801
801
|
|
|
@@ -1451,7 +1451,7 @@ function toSqlDdl( csn, options, messageFunctions ) {
|
|
|
1451
1451
|
* @returns {string} Rendered type
|
|
1452
1452
|
*/
|
|
1453
1453
|
function renderBuiltinType( typeName ) {
|
|
1454
|
-
const types = cdsToSqlTypes[options.sqlDialect];
|
|
1454
|
+
const types = cdsToSqlTypes[options.sqliteRealAffinityForDecimal && options.sqlDialect === 'sqlite' ? 'sqlitereal' : options.sqlDialect];
|
|
1455
1455
|
const result = types?.[typeName] || cdsToSqlTypes.standard[typeName];
|
|
1456
1456
|
if (!result && options.testMode)
|
|
1457
1457
|
throw new CompilerAssertion(`Expected to find a type mapping for ${ typeName }`);
|
|
@@ -21,7 +21,7 @@ const {
|
|
|
21
21
|
hasValidSkipOrExists, forEachDefinition, getNamespace, getUnderscoredName,
|
|
22
22
|
} = require('../../model/csnUtils');
|
|
23
23
|
|
|
24
|
-
const { implicitAs } = require('../../
|
|
24
|
+
const { implicitAs } = require('../../base/csnRefs');
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Render the given function
|
|
@@ -294,7 +294,7 @@ const cdsToSqlTypes = {
|
|
|
294
294
|
'cds.Binary': 'BINARY_BLOB',
|
|
295
295
|
'cds.hana.BINARY': 'BINARY_BLOB',
|
|
296
296
|
'cds.hana.SMALLDECIMAL': 'SMALLDECIMAL',
|
|
297
|
-
'cds.Vector': '
|
|
297
|
+
'cds.Vector': 'FLOAT32',
|
|
298
298
|
'cds.Map': 'JSON_TEXT', // '_TEXT' suffix required for text affinity
|
|
299
299
|
},
|
|
300
300
|
plain: {
|
|
@@ -325,6 +325,13 @@ const cdsToSqlTypes = {
|
|
|
325
325
|
},
|
|
326
326
|
};
|
|
327
327
|
|
|
328
|
+
cdsToSqlTypes.sqlitereal = {
|
|
329
|
+
...cdsToSqlTypes.sqlite,
|
|
330
|
+
'cds.Decimal': 'REAL_DECIMAL',
|
|
331
|
+
'cds.DecimalFloat': 'REAL_DECIMAL',
|
|
332
|
+
'cds.hana.SMALLDECIMAL': 'REAL_SMALLDECIMAL',
|
|
333
|
+
};
|
|
334
|
+
|
|
328
335
|
// Type mapping from cds type names to HDBCDS type names:
|
|
329
336
|
// Only those types, that need mapping, are listed.
|
|
330
337
|
const cdsToHdbcdsTypes = {
|
package/lib/render/utils/sql.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
const { getResultingName } = require('../../model/csnUtils');
|
|
6
|
-
const { smartId, delimitedId } = require('../../sql-identifier');
|
|
6
|
+
const { smartId, delimitedId, sqlDialects } = require('../../sql-identifier');
|
|
7
7
|
const { ModelError } = require('../../base/error');
|
|
8
|
-
const { setProp } = require('../../
|
|
8
|
+
const { setProp } = require('../../utils/objectUtils');
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Render a given referential constraint as part of a SQL CREATE TABLE statement, or as .hdbconstraint artefact.
|
|
@@ -66,10 +66,12 @@ function renderReferentialConstraint( constraint, indent, toUpperCase, csn, opti
|
|
|
66
66
|
/**
|
|
67
67
|
* Get functions which can be used to prepare and quote SQL identifiers based on the options provided.
|
|
68
68
|
*
|
|
69
|
+
* @param {CSN.Model} csn
|
|
69
70
|
* @param {CSN.Options} options
|
|
71
|
+
* @param {function} warning
|
|
70
72
|
* @returns quoteSqlId and prepareIdentifier function
|
|
71
73
|
*/
|
|
72
|
-
function getIdentifierUtils( csn, options ) {
|
|
74
|
+
function getIdentifierUtils( csn, options, warning ) {
|
|
73
75
|
return { quoteSqlId, prepareIdentifier, renderArtifactName };
|
|
74
76
|
/**
|
|
75
77
|
* Return 'name' with appropriate "-quotes.
|
|
@@ -81,10 +83,17 @@ function getIdentifierUtils( csn, options ) {
|
|
|
81
83
|
* Complain about names that collide with known SQL keywords or functions
|
|
82
84
|
*
|
|
83
85
|
* @param {string} name Identifier to quote
|
|
86
|
+
* @param {CSN.Path} path Path to the identifier in the CSN model (for warnings)
|
|
84
87
|
* @returns {string} Quoted identifier
|
|
85
88
|
*/
|
|
86
|
-
function quoteSqlId( name ) {
|
|
89
|
+
function quoteSqlId( name, path ) {
|
|
87
90
|
name = prepareIdentifier(name);
|
|
91
|
+
const s = sqlDialects[options.sqlDialect];
|
|
92
|
+
if ( warning && name.length > s.maxIdentifierLength ) {
|
|
93
|
+
warning( 'query-invalid-identifier',
|
|
94
|
+
path,
|
|
95
|
+
{ name: options.sqlDialect, number: s.maxIdentifierLength });
|
|
96
|
+
}
|
|
88
97
|
|
|
89
98
|
switch (options.sqlMapping) {
|
|
90
99
|
case 'plain':
|
|
@@ -139,7 +148,7 @@ function getIdentifierUtils( csn, options ) {
|
|
|
139
148
|
* @returns {string} Artifact name
|
|
140
149
|
*/
|
|
141
150
|
function renderArtifactName( artifactName ) {
|
|
142
|
-
return quoteSqlId(getResultingName(csn, options.sqlMapping, artifactName));
|
|
151
|
+
return quoteSqlId(getResultingName(csn, options.sqlMapping, artifactName), [ 'definitions', artifactName ] );
|
|
143
152
|
}
|
|
144
153
|
}
|
|
145
154
|
|