from pgConnection import PgConnection
import os

class Osmddbb:
    def __init__(self):
        pass

    def defineosmlayer(self, osmtype, osmsubtype, doc):
        pgconn = PgConnection("spainOSM")

        query = '''UPDATE planet_osm_polygon SET docname= '{}' WHERE {} ='{}';'''.format(doc,osmtype,osmsubtype)
        pgconn.cursor.execute(query)
        pgconn.connection.commit()

        query = '''UPDATE planet_osm_point SET docname= '{}' WHERE {} ='{}';'''.format(doc,osmtype,osmsubtype)
        pgconn.cursor.execute(query)
        pgconn.connection.commit()

        query = '''UPDATE planet_osm_line SET docname= '{}' WHERE {} ='{}';'''.format(doc,osmtype,osmsubtype)
        pgconn.cursor.execute(query)
        pgconn.connection.commit()

        query = '''UPDATE planet_osm_roads SET docname= '{}' WHERE {} ='{}';'''.format(doc,osmtype,osmsubtype)
        pgconn.cursor.execute(query)
        pgconn.connection.commit()

        print("doc '{}' finished".format(doc))