Skip to content

Commit bb5ed0e

Browse files
committed
Use Connection.execute shortcut instead of explicit cursors
1 parent 1432f6a commit bb5ed0e

2 files changed

Lines changed: 4 additions & 10 deletions

File tree

Mergin/diff.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def get_row_from_db(db_conn, schema_table, entry_changes):
7575
Fetches a single row from DB's table based on the values of pkeys
7676
in changeset entry
7777
"""
78-
c = db_conn.cursor()
7978
where_clauses = []
8079
query_params = []
8180

@@ -88,9 +87,7 @@ def get_row_from_db(db_conn, schema_table, entry_changes):
8887
# We parameterize values securely; table/column names are trusted internal schema objects.
8988
query = 'SELECT * FROM "{}" WHERE {}'.format(schema_table.name, " AND ".join(where_clauses)) # nosec B608
9089

91-
c.execute(query, tuple(query_params))
92-
93-
return c.fetchone()
90+
return db_conn.execute(query, tuple(query_params)).fetchone()
9491

9592

9693
def parse_gpkg_geom_encoding(wkb_with_gpkg_hdr):

Mergin/processing/algs/download_vector_tiles.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,23 @@ def create(self):
5656
"CREATE UNIQUE INDEX tile_index on tiles (zoom_level, tile_column, tile_row);"
5757
"COMMIT;"
5858
)
59-
cur = self.conn.cursor()
60-
cur.executescript(sql)
59+
self.conn.executescript(sql)
6160
return True
6261

6362
def set_metadata_value(self, key, value):
6463
if self.conn is None:
6564
return
6665

6766
params = (key, value)
68-
cur = self.conn.cursor()
69-
cur.execute("insert into metadata values (?, ?)", params)
67+
self.conn.execute("insert into metadata values (?, ?)", params)
7068
self.conn.commit()
7169

7270
def set_tile_data(self, z, x, y, data):
7371
if self.conn is None:
7472
return
7573

7674
params = (z, x, y, data)
77-
cur = self.conn.cursor()
78-
cur.execute("insert into tiles values (?, ?, ?, ?)", params)
75+
self.conn.execute("insert into tiles values (?, ?, ?, ?)", params)
7976
self.conn.commit()
8077

8178
def close(self):

0 commit comments

Comments
 (0)