-
Notifications
You must be signed in to change notification settings - Fork 2
Disable triggers by default and add trigger helpers #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KyleKincer
wants to merge
1
commit into
main
Choose a base branch
from
codex/disable-triggers-by-default-and-add-methods
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,15 +8,19 @@ property assert : cs:C1710.Assert | |
| property stats : cs:C1710.UnitStatsTracker | ||
| property failureCallChain : Collection | ||
| property classInstance : 4D:C1709.Object | ||
| property triggersGloballyEnabled : Boolean | ||
| property triggersEnabledTables : Collection | ||
|
|
||
| Class constructor() | ||
| This:C1470.failed:=False:C215 | ||
| This:C1470.done:=False:C215 | ||
| This:C1470.failed:=False:C215 | ||
| This:C1470.done:=False:C215 | ||
| This:C1470.logMessages:=[] | ||
| This:C1470.assertions:=[] | ||
| This:C1470.assert:=cs:C1710.Assert.new() | ||
| This:C1470.stats:=cs:C1710.UnitStatsTracker.new() | ||
| This:C1470.failureCallChain:=Null | ||
| This:C1470._resetTriggerTracking() | ||
| This:C1470.disableAllTriggers() | ||
|
|
||
| Function log($message : Text) | ||
| This:C1470.logMessages.push($message) | ||
|
|
@@ -59,12 +63,119 @@ Function fatal() | |
| This:C1470.failureCallChain:=Call chain:C1662 | ||
|
|
||
| Function resetForNewTest() | ||
| This:C1470.failed:=False:C215 | ||
| This:C1470.done:=False:C215 | ||
| This:C1470.disableAllTriggers() | ||
| This:C1470.failed:=False:C215 | ||
| This:C1470.done:=False:C215 | ||
| This:C1470.logMessages:=[] | ||
| This:C1470.assertions:=[] | ||
| This:C1470.stats.resetStatistics() | ||
| This:C1470.failureCallChain:=Null | ||
|
|
||
| Function disableAllTriggers() | ||
| This:C1470._executeSQL("ALTER DATABASE DISABLE TRIGGERS") | ||
|
|
||
| If (This:C1470.triggersEnabledTables#Null:C1517) | ||
| var $tableName : Text | ||
| For each ($tableName; This:C1470.triggersEnabledTables) | ||
| This:C1470._disableTriggersForTable($tableName) | ||
| End for each | ||
| End if | ||
|
|
||
| This:C1470._resetTriggerTracking() | ||
|
|
||
| Function enableAllTriggers() | ||
| This:C1470._executeSQL("ALTER DATABASE ENABLE TRIGGERS") | ||
| This:C1470.triggersGloballyEnabled:=True:C214 | ||
|
|
||
| Function enableTableTriggers($tableName : Text) | ||
| If ($tableName=Null:C1517) | ||
| return | ||
| End if | ||
|
|
||
| If ($tableName="") | ||
| return | ||
| End if | ||
|
|
||
| var $statement : Text | ||
| $statement:="ALTER TABLE "+This:C1470._quoteIdentifier($tableName)+" ENABLE TRIGGERS" | ||
| This:C1470._executeSQL($statement) | ||
|
|
||
| If (This:C1470.triggersEnabledTables=Null:C1517) | ||
| This:C1470.triggersEnabledTables:=[] | ||
| End if | ||
|
|
||
| If (This:C1470.triggersEnabledTables.indexOf($tableName)<0) | ||
| This:C1470.triggersEnabledTables.push($tableName) | ||
| End if | ||
|
|
||
| Function disableTableTriggers($tableName : Text) | ||
| If ($tableName=Null:C1517) | ||
| return | ||
| End if | ||
|
|
||
| If ($tableName="") | ||
| return | ||
| End if | ||
|
|
||
| This:C1470._disableTriggersForTable($tableName) | ||
|
|
||
| If (This:C1470.triggersEnabledTables#Null:C1517) | ||
| var $index : Integer | ||
| $index:=This:C1470.triggersEnabledTables.indexOf($tableName) | ||
| If ($index>=0) | ||
| This:C1470.triggersEnabledTables.remove($index) | ||
| End if | ||
| End if | ||
|
|
||
| Function restoreTriggerDefaults() | ||
| This:C1470.disableAllTriggers() | ||
|
|
||
| Function _disableTriggersForTable($tableName : Text) | ||
| If ($tableName=Null:C1517) | ||
| return | ||
| End if | ||
|
|
||
| If ($tableName="") | ||
| return | ||
| End if | ||
|
|
||
| var $statement : Text | ||
| $statement:="ALTER TABLE "+This:C1470._quoteIdentifier($tableName)+" DISABLE TRIGGERS" | ||
| This:C1470._executeSQL($statement) | ||
|
|
||
| Function _quoteIdentifier($identifier : Text) : Text | ||
| If ($identifier=Null:C1517) | ||
| return "\"\"" | ||
| End if | ||
|
|
||
| var $escaped : Text | ||
| $escaped:=Replace string:C233($identifier; "\""; "\"\"") | ||
| return "\""+$escaped+"\"" | ||
|
|
||
| Function _executeSQL($statement : Text) | ||
| If ($statement="") | ||
| return | ||
| End if | ||
|
|
||
| var $finalStatement : Text | ||
| $finalStatement:=$statement | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this final statement thing achieving anything? Feels like $statement could just be modified directly trhoughout the function. |
||
|
|
||
| If (Length:C16($finalStatement)>0) | ||
| var $lastChar : Text | ||
| $lastChar:=Substring:C12($finalStatement; Length:C16($finalStatement); 1) | ||
| If ($lastChar#";") | ||
| $finalStatement:=$finalStatement+";" | ||
| End if | ||
| End if | ||
|
|
||
| This:C1470._performSQLExecution($finalStatement) | ||
|
|
||
| Function _performSQLExecution($statement : Text) | ||
| SQL EXECUTE($statement) | ||
|
|
||
| Function _resetTriggerTracking() | ||
| This:C1470.triggersGloballyEnabled:=False:C215 | ||
| This:C1470.triggersEnabledTables:=[] | ||
|
|
||
| Function run($name : Text; $subtest : 4D:C1709.Function; $data : Variant) : Boolean | ||
| // Execute a named subtest with its own Testing context | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| Class extends Testing | ||
|
|
||
| property executedStatements : Collection | ||
|
|
||
| Class constructor() | ||
| Super:C1705() | ||
|
|
||
| If (This:C1470.executedStatements=Null:C1517) | ||
| This:C1470.executedStatements:=[] | ||
| End if | ||
|
|
||
| Function _performSQLExecution($statement : Text) | ||
| If (This:C1470.executedStatements=Null:C1517) | ||
| This:C1470.executedStatements:=[] | ||
| End if | ||
|
|
||
| This:C1470.executedStatements.push($statement) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.