Skip to content

Commit

Permalink
Handle invalid view names with more than one period
Browse files Browse the repository at this point in the history
I've updated the code as recommended and added an error message should there there be too many periods. Thanks for the suggestion!
  • Loading branch information
gisn8 authored Oct 8, 2024
1 parent ccdd612 commit 18addb9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions python/plugins/db_manager/db_plugins/postgis/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,12 +1014,15 @@ def moveTable(self, table, new_table, new_schema=None):
self._commit()

def createView(self, view, query):
user_input = view
view_name_parts = view.split('.')

if '.' in user_input: # To allow view creation into specified schema
schema, view_name = user_input.split('.')
if len(view_name_parts) > 2:
# Raise an error when more than one period is used.
raise ValueError("Invalid view name: Please use the format 'schema.viewname', or enter only the viewname for the public schema.")
elif len(view_name_parts) == 2: # To allow view creation into specified schema
schema, view_name = view_name_parts
sql = "CREATE VIEW %s AS %s" % (self.quoteId([schema, view_name]), query)
else: # No schema specified; uses public
else: # No specific schema specified
sql = "CREATE VIEW %s AS %s" % (self.quoteId(view), query)
self._execute_and_commit(sql)

Expand Down

0 comments on commit 18addb9

Please sign in to comment.