Skip to content

Commit

Permalink
fix: Add execute() method
Browse files Browse the repository at this point in the history
  • Loading branch information
rsavoye committed Feb 8, 2024
1 parent 7aebf04 commit 2d453e4
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions osm_rawdata/postgres.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python3

# Copyright (c) 2022 Humanitarian OpenStreetMap Team
# Copyright (c) 2022, 2023, 2024 Humanitarian OpenStreetMap Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -353,6 +353,26 @@ def createTable(

return True

def execute(self,
sql: str,
):
"""
Execute a raw SQL query and return the results.
Args:
sql (str): The SQL to execute
Returns:
(list): The results of the query
"""
# print(sql)
try:
result = self.dbcursor.execute(sql)
return self.dbcursor.fetchall()
except:
log.error(f"Couldn't execute query! {sql}")
return list()

def queryLocal(
self,
query: str,
Expand Down Expand Up @@ -394,7 +414,7 @@ def queryLocal(
self.dbcursor.execute(query)
try:
result = self.dbcursor.fetchall()
log.debug("SQL Query returned %d records" % len(result))
# log.debug("SQL Query returned %d records" % len(result))
except:
return FeatureCollection(features)

Expand Down

0 comments on commit 2d453e4

Please sign in to comment.