Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
basic
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xrm
basic
Commits
a9b152db
Commit
a9b152db
authored
5 years ago
by
Andre Loreth
Browse files
Options
Downloads
Patches
Plain Diff
Sql_lib: add translateWithQuotes function for preparedStatement quoting
parent
554df3c9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
process/Sql_lib/process.js
+46
-0
46 additions, 0 deletions
process/Sql_lib/process.js
with
46 additions
and
0 deletions
process/Sql_lib/process.js
+
46
−
0
View file @
a9b152db
...
@@ -1859,3 +1859,49 @@ SqlUtils.getResolvingCaseWhen = function(pKeyValueArray, pDbFieldName, pLocale)
...
@@ -1859,3 +1859,49 @@ SqlUtils.getResolvingCaseWhen = function(pKeyValueArray, pDbFieldName, pLocale)
resSql
=
[
resSql
,
preparedValues
];
resSql
=
[
resSql
,
preparedValues
];
return
resSql
;
return
resSql
;
};
};
/**
* Will quote all prepared statement values from the given statement.
* @param {[String, String[]]} pStatement Same as first paraemter of db.translateStatement.
* @param {([String, String[]]) => String} pExecutionCallback A function which must return the final SQL.
* @return The SQL, same as the result of db.translateStatement.
*/
SqlUtils
.
translateWithQuotes
=
function
(
pStatement
,
pExecutionCallback
)
{
// Validate type of incoming paramter.
if
(
!
(
pStatement
instanceof
Array
))
return
null
;
// The second element of the array has to be an array.
if
(
!
(
pStatement
[
1
]
instanceof
Array
))
return
null
;
// As the second element represents the prepared statements we need to map it...
var
preparedStatements
=
pStatement
[
1
].
map
(
function
(
pValue
)
{
// Just in case as a fallback value..
if
(
!
(
pValue
instanceof
Array
))
return
pValue
;
// As the first element represents the value it will be quoted here.
return
[
db
.
quote
(
pValue
[
0
]),
pValue
[
1
]];
});
return
pExecutionCallback
([
pStatement
[
0
],
preparedStatements
]);
}
/**
* Will quote all prepared statement values from the given statement.
* @param {[String, String[]]} pStatement Same as the first parameter of db.translateStatement.
* @returns {String} The SQL, same as the result of db.translateStatement.
*/
SqlUtils
.
translateStatementWithQuotes
=
function
(
pStatement
)
{
return
SqlUtils
.
translateWithQuotes
(
pStatement
,
db
.
translateStatement
);
}
/**
* Will quote all prepared statement values from the given statement.
* @param {[String, String[]]} pStatement Same as the first parameter of db.translateCondition.
* @returns {String} The SQL, same as the result of db.translateCondition.
*/
SqlUtils
.
translateConditionWithQuotes
=
function
(
pStatement
)
{
return
SqlUtils
.
translateWithQuotes
(
pStatement
,
db
.
translateCondition
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment