aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db/db.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/db/db.py b/db/db.py
index 9e9b2d8..71e458d 100644
--- a/db/db.py
+++ b/db/db.py
@@ -343,7 +343,7 @@ class VlanDB:
# Grab one column from multiple rows of a query; useful as a quick
# wrapper
- def _get_multi_elements(self, select_field, table, compare_field, value):
+ def _get_multi_elements(self, select_field, table, compare_field, value, sort_field):
# We really want to use psycopg's type handling deal with the
# (potentially) user-supplied data in the value field, so we
@@ -352,7 +352,7 @@ class VlanDB:
# as it will quote all the params like the table name. That
# doesn't work. So, we substitute a "%s" for "%s" here so we
# keep it after python's own string substitution.
- sql = "SELECT %s FROM %s WHERE %s = %s" % (select_field, table, compare_field, "%s")
+ sql = "SELECT %s FROM %s WHERE %s = %s ORDER BY %s ASC" % (select_field, table, compare_field, "%s", sort_field)
# Now, the next icky thing: we need to make sure that we're
# passing a dict so that psycopg2 can pick it apart properly
@@ -371,7 +371,7 @@ class VlanDB:
# Grab one column from multiple rows of a 2-part query; useful as
# a wrapper
- def _get_multi_elements2(self, select_field, table, compare_field1, value1, compare_field2, value2):
+ def _get_multi_elements2(self, select_field, table, compare_field1, value1, compare_field2, value2, sort_field):
# We really want to use psycopg's type handling deal with the
# (potentially) user-supplied data in the value field, so we
@@ -380,7 +380,7 @@ class VlanDB:
# as it will quote all the params like the table name. That
# doesn't work. So, we substitute a "%s" for "%s" here so we
# keep it after python's own string substitution.
- sql = "SELECT %s FROM %s WHERE %s = %s AND %s = %s" % (select_field, table, compare_field1, "%s", compare_field2, "%s")
+ sql = "SELECT %s FROM %s WHERE %s = %s AND %s = %s ORDER by %s ASC" % (select_field, table, compare_field1, "%s", compare_field2, "%s", sort_field)
data = (value1, value2)
self.cursor.execute(sql, data)
@@ -426,14 +426,14 @@ class VlanDB:
#
# Returns None on failure.
def get_ports_by_switch(self, switch_id):
- return self._get_multi_elements("port_id", "port", "switch_id", int(switch_id))
+ return self._get_multi_elements("port_id", "port", "switch_id", int(switch_id), "port_id")
# More complex lookup: look up all the trunk ports on a switch by
# ID
#
# Returns None on failure.
def get_trunk_port_names_by_switch(self, switch_id):
- return self._get_multi_elements2("name", "port", "switch_id", int(switch_id), "is_trunk", True)
+ return self._get_multi_elements2("name", "port", "switch_id", int(switch_id), "is_trunk", True, "port_id")
# Simple lookup: look up a port by its name and its parent switch
# by ID, and return the ID of the port.
@@ -468,21 +468,21 @@ class VlanDB:
#
# Returns None on failure.
def get_ports_by_current_vlan(self, vlan_id):
- return self._get_multi_elements("port_id", "port", "current_vlan_id", int(vlan_id))
+ return self._get_multi_elements("port_id", "port", "current_vlan_id", int(vlan_id), "port_id")
# Simple lookup: look up a base VLAN by ID, and return the IDs
# of all the ports on that VLAN.
#
# Returns None on failure.
def get_ports_by_base_vlan(self, vlan_id):
- return self._get_multi_elements("port_id", "port", "base_vlan_id", int(vlan_id))
+ return self._get_multi_elements("port_id", "port", "base_vlan_id", int(vlan_id), "port_id")
# Simple lookup: look up a trunk by ID, and return the IDs of the
# ports on both ends of that trunk.
#
# Returns None on failure.
def get_ports_by_trunk(self, trunk_id):
- return self._get_multi_elements("port_id", "port", "trunk_id", int(trunk_id))
+ return self._get_multi_elements("port_id", "port", "trunk_id", int(trunk_id), "port_id")
# Simple lookup: look up a VLAN by ID, and return all the details
# of that VLAN.