Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ADITO_Update_Upgrade
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository 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
ADITO_Update_Upgrade
Commits
fb01b933
Commit
fb01b933
authored
5 years ago
by
Johannes Hörmann
Browse files
Options
Downloads
Patches
Plain Diff
add methods wrapping db. functions to sqlbuilder
parent
994b2cb0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
entity/Person_entity/entityfields/campaignactiongroup/children/sqltests/onActionProcess.js
+11
-1
11 additions, 1 deletion
.../campaignactiongroup/children/sqltests/onActionProcess.js
process/Sql_lib/process.js
+179
-16
179 additions, 16 deletions
process/Sql_lib/process.js
with
190 additions
and
17 deletions
entity/Person_entity/entityfields/campaignactiongroup/children/sqltests/onActionProcess.js
+
11
−
1
View file @
fb01b933
...
...
@@ -330,13 +330,23 @@ var ifSetTests = [
pTester
.
assert
(
0
,
actual
.
_where
.
preparedValues
.
length
,
"
no params should be added
"
);
}],
[
"
empty s
ubquerie
s
"
,
function
(
pTester
)
[
"
empty s
imple condition
s
"
,
function
(
pTester
)
{
var
actual
=
new
SqlBuilder
()
.
orIfSet
(
""
)
.
andIfSet
([
""
,
[]])
.
andIfSet
(
new
SqlBuilder
())
pTester
.
assert
(
""
,
actual
.
_where
.
_sqlStorage
,
"
no sql should be added
"
);
pTester
.
assert
(
0
,
actual
.
_where
.
preparedValues
.
length
,
"
no params should be added
"
);
}],
[
"
empty subqueries
"
,
function
(
pTester
)
{
var
actual
=
new
SqlBuilder
()
.
orIfSet
(
"
PERSON.FIRSTNAME
"
,
[
""
,
[]])
.
andIfSet
(
"
PERSON.LASTNAME
"
,
new
SqlBuilder
())
pTester
.
assert
(
""
,
actual
.
_where
.
_sqlStorage
,
"
no sql should be added
"
);
pTester
.
assert
(
0
,
actual
.
_where
.
preparedValues
.
length
,
"
no params should be added
"
);
}]
...
...
This diff is collapsed.
Click to expand it.
process/Sql_lib/process.js
+
179
−
16
View file @
fb01b933
...
...
@@ -754,10 +754,15 @@ SqlBuilder.begin = function(pAlias)
* @return {String} the sql as string
*/
SqlBuilder
.
prototype
.
toString
=
function
()
{
if
(
this
.
build
()[
0
]
!==
""
)
{
var
built
=
this
.
build
()
if
(
built
[
0
]
!==
""
)
{
return
SqlUtils
.
translateStatementWithQuotes
(
this
.
build
());
if
(
!
this
.
isFullSelect
()
&&
this
.
hasCondition
())
return
SqlUtils
.
translateConditionWithQuotes
(
built
,
this
.
alias
);
else
return
SqlUtils
.
translateStatementWithQuotes
(
built
,
this
.
alias
);
}
return
""
;
...
...
@@ -840,7 +845,7 @@ SqlBuilder.prototype.leftJoin = function(pTable, pCondition, pAlias)
* a string (without the where keyword), a SqlCondition or an array (for prepared queries).
*
* @return {SqlBuilder} current SqlBuilder object
* @deprecated
* @deprecated
use .and()
*/
SqlBuilder
.
prototype
.
where
=
function
(
pCondition
)
{
...
...
@@ -895,13 +900,20 @@ SqlBuilder.prototype._whereCondition = function(pCondition, pMandatory, pAddPrep
{
// add only brackets if needed
var
sqlString
=
sql
.
_where
.
_sqlStorage
;
if
(
pBrackets
)
sqlString
=
"
(
"
+
sqlString
+
"
)
"
;
var
condString
=
sqlString
;
if
(
condString
.
trim
()
!=
""
)
{
if
(
pBrackets
)
condString
=
"
(
"
+
condString
+
"
)
"
;
pAddPreparedConditionCallback
([
condString
,
sql
.
_where
.
preparedValues
],
pBrackets
);
return
this
;
}
else
if
(
pMandatory
)
{
throw
SqlBuilder
.
ERROR_INVALID_CONDITION_VALUE_TYPE
();
}
return
this
;
}
...
...
@@ -925,7 +937,15 @@ SqlBuilder.prototype._whereSubquery = function(pSubquery, pMandatory, pCondition
// Both can be handled by _prepare
if
(
Array
.
isArray
(
sql
)
||
typeofSql
==
"
string
"
)
{
pAddPreparedConditionCallback
(
this
.
_prepare
(
undefined
,
sql
,
pCondition
));
if
(
sql
[
0
])
{
pAddPreparedConditionCallback
(
this
.
_prepare
(
undefined
,
sql
,
pCondition
));
}
else
if
(
pMandatory
)
{
throw
SqlBuilder
.
ERROR_INVALID_SUBQUERY_TYPE
();
}
return
this
;
}
...
...
@@ -939,7 +959,8 @@ SqlBuilder.prototype._whereSubquery = function(pSubquery, pMandatory, pCondition
{
throw
SqlBuilder
.
ERROR_NO_CONDITION
();
}
logging
.
log
(
JSON
.
stringify
([
subQuery
],
null
,
"
\t
"
))
if
(
subQuery
.
isFullSelect
())
{
var
preparedObj
=
subQuery
.
build
();
...
...
@@ -1087,7 +1108,7 @@ SqlBuilder.prototype._or = function(pFieldOrCond, pValue, pMandatory, pCond, pFi
}
else
if
(
that
.
hasCondition
()
&&
!
that
.
_where
.
_lastWasOr
)
{
var
cond
=
pPreparedCondition
[
0
];
let
cond
=
pPreparedCondition
[
0
];
if
(
!
pAlreadySurroundedByBrackets
)
cond
=
"
(
"
+
pPreparedCondition
[
0
]
+
"
)
"
;
...
...
@@ -1098,7 +1119,7 @@ SqlBuilder.prototype._or = function(pFieldOrCond, pValue, pMandatory, pCond, pFi
}
else
if
(
that
.
hasCondition
()
&&
that
.
_where
.
_lastWasOr
)
{
var
cond
=
pPreparedCondition
[
0
];
let
cond
=
pPreparedCondition
[
0
];
if
(
!
pAlreadySurroundedByBrackets
)
cond
=
"
(
"
+
pPreparedCondition
[
0
]
+
"
)
"
;
...
...
@@ -1397,12 +1418,142 @@ SqlBuilder.prototype.build = function()
* It resolves all prepared values.
* @param {String} [pAlias=undefined] the alias to use for db.translateStatement
* @return {String} plain SQL statement
*
* @deprecated use .toString()
*/
SqlBuilder
.
prototype
.
translate
=
function
(
pAlias
)
SqlBuilder
.
prototype
.
translate
=
function
()
{
return
this
.
toString
();
}
SqlBuilder
.
prototype
.
updateData
=
function
(
pExecuteOnlyIfConditionExists
,
pTableName
,
pColumns
,
pColumnTypes
,
pValues
,
pTimeout
)
{
if
(
this
.
_checkForDelete
(
pExecuteOnlyIfConditionExists
))
{
db
.
updateData
(
(
pTableName
?
pTableName
:
this
.
_from
),
pColumns
,
pColumnTypes
,
pValues
,
this
.
buildCondition
(),
(
this
.
alias
?
this
.
alias
:
db
.
getCurrentAlias
()),
(
pTimeout
?
pTimeout
:
-
1
));
}
}
SqlBuilder
.
prototype
.
deleteData
=
function
(
pExecuteOnlyIfConditionExists
,
pTableName
,
pTimeout
)
{
if
(
this
.
_checkForUpdate
(
pExecuteOnlyIfConditionExists
))
{
return
db
.
deleteData
(
(
pTableName
?
pTableName
:
this
.
_from
),
this
.
buildCondition
(),
(
this
.
alias
?
this
.
alias
:
db
.
getCurrentAlias
()),
(
pTimeout
?
pTimeout
:
-
1
));
}
else
{
return
0
;
}
}
SqlBuilder
.
prototype
.
cell
=
function
(
pExecuteOnlyIfConditionExists
)
{
if
(
this
.
_checkForSelect
(
pExecuteOnlyIfConditionExists
))
{
return
db
.
cell
(
this
.
build
(),
(
this
.
alias
?
this
.
alias
:
db
.
getCurrentAlias
()));
}
else
{
return
""
;
}
}
SqlBuilder
.
prototype
.
array
=
function
(
pType
,
pExecuteOnlyIfConditionExists
,
pMaxRows
,
pTimeout
)
{
return
SqlUtils
.
translateStatementWithQuotes
(
this
.
build
(),
pAlias
);
if
(
this
.
_checkForSelect
(
pExecuteOnlyIfConditionExists
))
{
return
db
.
array
(
pType
,
this
.
build
(),
(
this
.
alias
?
this
.
alias
:
db
.
getCurrentAlias
()),
(
pMaxRows
?
pMaxRows
:
0
),
(
pTimeout
?
pTimeout
:
-
1
));
}
else
{
return
[];
}
}
SqlBuilder
.
prototype
.
arrayPage
=
function
(
pStartIndex
,
pRowCount
,
pExecuteOnlyIfConditionExists
,
pTimeout
)
{
if
(
this
.
_checkForSelect
(
pExecuteOnlyIfConditionExists
))
{
return
db
.
arrayPage
(
pType
,
this
.
build
(),
(
this
.
alias
?
this
.
alias
:
db
.
getCurrentAlias
()),
pStartIndex
,
pRowCount
,
(
pTimeout
?
pTimeout
:
-
1
));
}
else
{
return
[];
}
}
SqlBuilder
.
prototype
.
table
=
function
(
pExecuteOnlyIfConditionExists
,
pMaxRows
,
pTimeout
)
{
if
(
this
.
_checkForSelect
(
pExecuteOnlyIfConditionExists
))
{
return
db
.
table
(
this
.
build
(),
(
this
.
alias
?
this
.
alias
:
db
.
getCurrentAlias
()),
(
pMaxRows
?
pMaxRows
:
0
),
(
pTimeout
?
pTimeout
:
-
1
));
}
else
{
return
[];
}
}
SqlBuilder
.
prototype
.
tablePage
=
function
(
pStartIndex
,
pRowCount
,
pExecuteOnlyIfConditionExists
,
pTimeout
)
{
if
(
this
.
_checkForSelect
(
pExecuteOnlyIfConditionExists
))
{
return
db
.
tablePage
(
this
.
build
(),
(
this
.
alias
?
this
.
alias
:
db
.
getCurrentAlias
()),
pStartIndex
,
pRowCount
,
(
pTimeout
?
pTimeout
:
-
1
));
}
else
{
return
[];
}
}
SqlBuilder
.
prototype
.
_checkForUpdate
=
function
(
pExecuteOnlyIfConditionExists
)
{
if
(
pExecuteOnlyIfConditionExists
==
undefined
)
pExecuteOnlyIfConditionExists
=
true
;
return
!
pExecuteOnlyIfConditionExists
||
this
.
hasCondition
();
}
SqlBuilder
.
prototype
.
_checkForSelect
=
function
(
pExecuteOnlyIfConditionExists
)
{
if
(
pExecuteOnlyIfConditionExists
==
undefined
)
pExecuteOnlyIfConditionExists
=
false
;
if
(
this
.
isFullSelect
())
{
return
!
pExecuteOnlyIfConditionExists
||
this
.
hasCondition
();
}
else
{
// TODO: error
throw
new
Error
()
}
}
/**
*provides functions for masking sql functions
...
...
@@ -2362,8 +2513,14 @@ SqlUtils.translateWithQuotes = function(pStatement, pExecutionCallback) {
* @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
,
function
(
pValue
)
{
return
db
.
translateStatement
(
pValue
)});
SqlUtils
.
translateStatementWithQuotes
=
function
(
pStatement
,
pAlias
)
{
return
SqlUtils
.
translateWithQuotes
(
pStatement
,
function
(
pValue
)
{
if
(
pAlias
)
return
db
.
translateStatement
(
pValue
,
pAlias
)
else
return
db
.
translateStatement
(
pValue
)
});
}
/**
...
...
@@ -2371,8 +2528,14 @@ SqlUtils.translateStatementWithQuotes = function(pStatement) {
* @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
,
function
(
pValue
)
{
return
db
.
translateCondition
(
pValue
)});
SqlUtils
.
translateConditionWithQuotes
=
function
(
pStatement
,
pAlias
)
{
return
SqlUtils
.
translateWithQuotes
(
pStatement
,
function
(
pValue
)
{
if
(
pAlias
)
return
db
.
translateCondition
(
pValue
,
pAlias
)
else
return
db
.
translateCondition
(
pValue
)
});
}
SqlUtils
.
parseField
=
function
(
pField
)
...
...
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