Skip to content

Commit

Permalink
Major temp table conversion (merge branch dev, closes #17)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimolzak committed Feb 23, 2021
2 parents 0b4d07d + 1487ada commit bec4dd6
Show file tree
Hide file tree
Showing 6 changed files with 7,816 additions and 7,779 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.log
*.docx
instruct-trigger-manual.txt
*.png
7,255 changes: 3,625 additions & 3,630 deletions Fobt.sql

Large diffs are not rendered by default.

8,291 changes: 4,143 additions & 4,148 deletions Lung.sql

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions advanced/instruct-graph.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
graph {

INSTRUCT -- Clinical
INSTRUCT -- Data
Data[label="Data", style=filled, color=black, fontcolor=white]
Data -- EPRP
SQL[label="SQL\ne-triggers"]
Data -- SQL
cp[label="Change\npackage"]
etc[label="etc..."]
Clinical -- cp
Clinical -- etc
}
5 changes: 4 additions & 1 deletion advanced/makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pdfs = Fobt.pdf Lung.pdf Triggers-Overview.pdf
pdfs = Fobt.pdf Lung.pdf Triggers-Overview.pdf instruct-graph.png
mod_sql = HCC_altered.sql IDA_altered.sql
manual = instruct-trigger-manual.pdf instruct-trigger-manual.docx instruct-trigger-manual.txt

Expand Down Expand Up @@ -30,6 +30,9 @@ Triggers-Overview.pdf : Triggers-Overview.md
%_altered.sql : ../unmodified/%.sql transform.py
python transform.py $< > $@

%.png: %.dot
dot -Tpng -o $@ $<

.PHONY : clean

clean :
Expand Down
30 changes: 30 additions & 0 deletions advanced/transform_temptables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# usage:
# Go to root directory of this repo.

# python ./advanced/transform_temptables.py Lung.sql > Lung_tt.sql

# ... and then do diff or move Lung_tt and Fobt_tt to overwrite
# Lung.sql and Fobt.sql. This is not incorporated into makefile at
# present, because it's designed to run once and only once, and then
# git commit the result.

import sys
import re
assert sys.version_info.major >= 3

fh = open(sys.argv[1])
mydb_backref = re.compile("\[MyDB\]\.\[MySchema\]\.\[?(\w+)\]?", re.IGNORECASE)
# [MyDB].[MySchema].[table_name]

for L in fh.read().splitlines():
comment = ''
m = mydb_backref.search(L)
if m:
table_name = m.group(1)
if 'OBJECT_ID' in L:
comment = ' --altered (object_id temp table)'
L = mydb_backref.sub('tempdb.dbo.#' + table_name, L)
else:
comment = ' --altered (temp table)'
L = mydb_backref.sub('#' + table_name, L)
print(L + comment)

0 comments on commit bec4dd6

Please sign in to comment.