class CommonSql:
    def __init__(self,pgconn):
        self._pgconn = pgconn
        self._cursor = pgconn.cursor

    def insert_properties(self, geom_text, geom_type, properties_elements, properties_names):
        if geom_type == 'Polygon': 
            query = '''INSERT INTO cartography.features ( geom_polygon, prop1_value, prop1_code, prop2_value, prop2_code, prop3_value, prop3_code, prop4_value, prop4_code )
                        VALUES
                        (ST_Transform(ST_GeomFromText('{}',2249),4326), '{}','{}','{}','{}','{}','{}','{}','{}') ;'''.format(geom_text,
                        properties_elements[0], properties_names[0],properties_elements[1],properties_names[1],properties_elements[2],
                        properties_names[2],properties_elements[3], properties_names[3])

        if geom_type == 'Linestring': 
            query = '''INSERT INTO cartography.features ( geom_linestring, prop1_value, prop1_code, prop2_value, prop2_code, prop3_value, prop3_code, prop4_value, prop4_code )
                        VALUES
                        ('{}', ST_Transform(ST_GeomFromText('{}',2249),4326), '{}','{}','{}','{}','{}','{}','{}','{}') ;'''.format(
                        geom_text,properties_elements[0], properties_names[0],properties_elements[1],properties_names[1],
                        properties_elements[2], properties_names[2],properties_elements[3], properties_names[3])

            
        if geom_type == 'Points':
          query = '''INSERT INTO cartography.features ( geom_point, prop1_value, prop1_code, prop2_value, prop2_code, prop3_value, prop3_code, prop4_value, prop4_code )
                        VALUES
                        ('{}', ST_Transform(ST_GeomFromText('{}',2249),4326), '{}','{}','{}','{}','{}','{}','{}','{}') ;'''.format(
                        geom_text,properties_elements[0], properties_names[0],properties_elements[1],properties_names[1],
                        properties_elements[2], properties_names[2],properties_elements[3], properties_names[3])

        try:
            self._cursor.execute(query)
            self._pgconn.connection.commit()
            #count = self._cursor.rowcount
        except Exception as ex :
            print("ERROR: ", type(ex), ex.args)
            return None