aboutsummaryrefslogtreecommitdiff
path: root/scripts/rpki/sql.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2007-09-12 00:39:41 +0000
committerRob Austein <sra@hactrn.net>2007-09-12 00:39:41 +0000
commit062f9729c115a80bd74f900a3a8284de81985acc (patch)
treee5af3cc72d58f77165ca6c26923cb484b858ead6 /scripts/rpki/sql.py
parent63acecdc38a602eafb5beb49fb0b9b4a291c3378 (diff)
Checkpoint
svn path=/scripts/rpki/left_right.py; revision=943
Diffstat (limited to 'scripts/rpki/sql.py')
-rw-r--r--scripts/rpki/sql.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/scripts/rpki/sql.py b/scripts/rpki/sql.py
index c7c0fe0d..7064bd2b 100644
--- a/scripts/rpki/sql.py
+++ b/scripts/rpki/sql.py
@@ -64,7 +64,9 @@ class sql_persistant(object):
def sql_fetch(cls, db, cur=None, select_dict=None, sql_parent=None):
"""Fetch rows from SQL based on a canned query and a set of
keyword arguments, and instantiate them as objects, returning a
- list of the instantiated objects.
+ list of the instantiated objects. If the object definition
+ indicates an index field (sql_id_name), this method instead
+ returns as dictionary using the index field as the key.
This is a class method because in general we don't even know how
many matches the SQL lookup will return until after we've
@@ -83,6 +85,8 @@ class sql_persistant(object):
self_dict = self.sql_encode()
for k,v in self.sql_children:
setattr(self, k, v.sql_fetch(db, cur, self_dict, self))
+ if cls.sql_id_name is not None:
+ result = dict((getattr(i, cls.sql_id_name), i) for i in result)
return result
def sql_store(self, db, cur=None):