Created
March 10, 2017 15:30
-
-
Save chriscorwin/c54e2a6ea3ee27b1f421cf764726646c to your computer and use it in GitHub Desktop.
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
| #sSQL = (' | |
| LOCK TABLE '+#cattable+' WRITE; | |
| -- 1 | |
| SELECT @myLeft := lft, @myRight := rgt, @myWidth := rgt - lft + 1 FROM '+#cattable+' WHERE id = '+#id2+'; | |
| -- 2 | |
| UPDATE '+#cattable+' SET rgt = (rgt*-1), lft = (lft*-1) WHERE lft BETWEEN @myLeft AND @myRight; | |
| -- 3 | |
| UPDATE '+#cattable+' SET rgt = rgt - @myWidth WHERE rgt > @myRight; | |
| UPDATE '+#cattable+' SET lft = lft - @myWidth WHERE lft > @myRight; | |
| -- 4a | |
| SELECT @myLeft2 := lft, @myRight2 := rgt, @myWidth2 := rgt - lft + 1 FROM '+#cattable+' WHERE id = '+#id+'; | |
| -- 4 & 5 | |
| UPDATE '+#cattable+' SET rgt = rgt + @myWidth WHERE rgt > @myRight2; | |
| UPDATE '+#cattable+' SET lft = lft + @myWidth WHERE lft > @myRight2; | |
| -- 6 | |
| -- SELECT @x := (@myRight2 + 1) - (lft * -1) FROM '+#cattable+' WHERE id = '+#id+'; | |
| SELECT @x := lft FROM '+#cattable+' WHERE id = '+#id+'; | |
| SELECT @y := rgt FROM '+#cattable+' WHERE id = '+#id+'; | |
| -- 8 | |
| UPDATE '+#cattable+' SET rgt = (rgt - (@y - @x + 1)) WHERE rgt < 0; | |
| UPDATE '+#cattable+' SET lft = (lft - (@y - @x + 1)) WHERE lft < 0; | |
| UPDATE '+#cattable+' SET rgt = rgt * -1 WHERE rgt < 0; | |
| UPDATE '+#cattable+' SET lft = lft * -1 WHERE lft < 0; | |
| UNLOCK TABLES; | |
| '); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment