- cur = context.db.cursor(cursor_factory=psycopg2.extras.DictCursor)
-
- for row in context.table:
- pid = NominatimID(row['object']).get_place_id(cur)
- cur.execute("""SELECT *, ST_X(centroid) as cx, ST_Y(centroid) as cy
- FROM search_name WHERE place_id = %s""", (pid, ))
- assert cur.rowcount > 0, "No rows found for " + row['object']
-
- for res in cur:
- for h in row.headings:
- if h in ('name_vector', 'nameaddress_vector'):
- terms = [x.strip() for x in row[h].split(',') if not x.strip().startswith('#')]
- words = [x.strip()[1:] for x in row[h].split(',') if x.strip().startswith('#')]
- subcur = context.db.cursor()
- subcur.execute(""" SELECT word_id, word_token
- FROM word, (SELECT unnest(%s::TEXT[]) as term) t
- WHERE word_token = make_standard_name(t.term)
- and class is null and country_code is null
- and operator is null
- UNION
- SELECT word_id, word_token
- FROM word, (SELECT unnest(%s::TEXT[]) as term) t
- WHERE word_token = ' ' || make_standard_name(t.term)
- and class is null and country_code is null
- and operator is null
- """,
- (terms, words))
- if not exclude:
- assert subcur.rowcount >= len(terms) + len(words), \
- "No word entry found for " + row[h] + ". Entries found: " + str(subcur.rowcount)
- for wid in subcur:
- if exclude:
- assert wid[0] not in res[h], "Found term for %s/%s: %s" % (pid, h, wid[1])
- else:
- assert wid[0] in res[h], "Missing term for %s/%s: %s" % (pid, h, wid[1])
- else:
- assert_db_column(res, h, row[h], context)
-
-
- context.db.commit()
+ with context.db.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
+ for row in context.table:
+ pid = NominatimID(row['object']).get_place_id(cur)
+ cur.execute("""SELECT *, ST_X(centroid) as cx, ST_Y(centroid) as cy
+ FROM search_name WHERE place_id = %s""", (pid, ))
+ assert cur.rowcount > 0, "No rows found for " + row['object']
+
+ for res in cur:
+ for h in row.headings:
+ if h in ('name_vector', 'nameaddress_vector'):
+ terms = [x.strip() for x in row[h].split(',') if not x.strip().startswith('#')]
+ words = [x.strip()[1:] for x in row[h].split(',') if x.strip().startswith('#')]
+ with context.db.cursor() as subcur:
+ subcur.execute(""" SELECT word_id, word_token
+ FROM word, (SELECT unnest(%s::TEXT[]) as term) t
+ WHERE word_token = make_standard_name(t.term)
+ and class is null and country_code is null
+ and operator is null
+ UNION
+ SELECT word_id, word_token
+ FROM word, (SELECT unnest(%s::TEXT[]) as term) t
+ WHERE word_token = ' ' || make_standard_name(t.term)
+ and class is null and country_code is null
+ and operator is null
+ """,
+ (terms, words))
+ if not exclude:
+ assert subcur.rowcount >= len(terms) + len(words), \
+ "No word entry found for " + row[h] + ". Entries found: " + str(subcur.rowcount)
+ for wid in subcur:
+ if exclude:
+ assert wid[0] not in res[h], "Found term for %s/%s: %s" % (pid, h, wid[1])
+ else:
+ assert wid[0] in res[h], "Missing term for %s/%s: %s" % (pid, h, wid[1])
+ else:
+ assert_db_column(res, h, row[h], context)