Skip to content

Commit

Permalink
Fix incorrect sqlite execution
Browse files Browse the repository at this point in the history
it required a tupple, not a value
  • Loading branch information
nyurik committed Aug 2, 2019
1 parent a11ae13 commit 4ea3733
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions bin/generate-metadata
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ def update_metadata(mbtiles_file, metadata, force=False):
conn = sqlite3.connect(mbtiles_file)
cursor = conn.cursor()

def upsert_entry(key, value):
def upsert_entry(entry_key, entry_value):
# ID should be overwritten always!
if not force and key != 'id':
cursor.execute("SELECT value FROM metadata WHERE name = ?", key)
for row in cursor:
if not force and entry_key != 'id':
cursor.execute("SELECT value FROM metadata WHERE name = ?", (entry_key, ))
for entry_row in cursor:
# Skip if the value exists
# print(f"{key}={row}")
if row[0]:
# print(f"{entry_key}={entry_row}")
if entry_row[0]:
return
conn.execute("DELETE FROM metadata WHERE name=?", key)
conn.execute("INSERT INTO metadata VALUES(?, ?)", (key, value))
conn.execute("DELETE FROM metadata WHERE name=?", (entry_key, ))
conn.execute("INSERT INTO metadata VALUES(?, ?)", (entry_key, entry_value, ))

for key, value in metadata.items():
upsert_entry(key, value)
Expand All @@ -110,6 +110,7 @@ def update_metadata(mbtiles_file, metadata, force=False):
for row in cursor:
metadata_json = row[1]
break

if metadata_json:
obj = json.loads(metadata_json)
# Remove Layer - contains connections and SQLs
Expand All @@ -136,12 +137,13 @@ def update_metadata(mbtiles_file, metadata, force=False):
layer['maxzoom'] = maxzoom
# Save json back into metadata minified
metadata_json = json.dumps(obj, separators=(',', ':'))
cursor.execute("REPLACE INTO metadata VALUES (?, ?)", ('json', metadata_json))
cursor.execute("REPLACE INTO metadata VALUES (?, ?)", ('json', metadata_json, ))
conn.commit()

conn.commit()
conn.close()


if __name__ == '__main__':
args = docopt(__doc__, version=openmaptiles.__version__, options_first=True)
force = args.get('--force', False)
Expand Down

0 comments on commit 4ea3733

Please sign in to comment.