Skip to content
Snippets Groups Projects
Commit 6e732f1d authored by Rafael S Castilho's avatar Rafael S Castilho
Browse files

add update generation script

parent 420b7738
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
import sys
import pymonetdb
## function to create a series of updates to set the new info
# on the table that is missing it
def makeUpdate(outfile, table, col, col1, ano, QR):
out = open(outfile, 'w')
for i in QR:
print("UPDATE", table, file=out)
print("SET ", col1, " = \'", i[1].replace("\'", "\\\'"),
"\'", sep='', file=out, end=' ')
print("WHERE ano_censo = ", ano, " AND ",
col, " = ", i[0], ";", file=out)
## function to make querries in the database and
# save the results in QR
def querryDatabase(QR):
connection = pymonetdb.connect(username="monetdb", password="monetdb",
hostname="localhost",
database="dados_educacionais")
cursor = connection.cursor()
cursor.arraysize = 100
cursor.execute('SELECT DISTINCT '+col+','+col1+' FROM '+table+' WHERE ano_censo = '+ano+' ORDER BY '+col)
# select must happen in COD, NAME fashion, or the case
# generation will go wrong
QR.append(cursor.fetchall())
col = sys.argv[1] # col with code
col1 = sys.argv[2] # col with name
outfile = sys.argv[3] # name of output file
table = sys.argv[4] # table to be querryed
tableUp = sys.argv[5] # table to be updated
ano = sys.argv[6] # year to apply update
querryRes = [] # will recieve database querry result
querryDatabase(querryRes)
QR = querryRes[0]
querryRes = []
makeUpdate(outfile, tableUp, col, col1, ano, QR)
...@@ -52,3 +52,4 @@ ORDER BY ...@@ -52,3 +52,4 @@ ORDER BY
estado.regiao_id ASC, estado.regiao_id ASC,
fies.ano_censo ASC, fies.ano_censo ASC,
ano_censo ASC ano_censo ASC
;
\ No newline at end of file
...@@ -26,4 +26,5 @@ GROUP BY ...@@ -26,4 +26,5 @@ GROUP BY
ORDER BY ORDER BY
inst.ano_censo ASC, inst.ano_censo ASC,
nome_ies ASC nome_ies ASC
\ No newline at end of file ;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment