summaryrefslogtreecommitdiff
path: root/pynslcd/alias.py
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2013-04-16 17:48:10 +0200
committerArthur de Jong <arthur@arthurdejong.org>2013-08-17 12:31:36 +0200
commitb0b57234790da62c9dd6ba11b3093e9b80678f94 (patch)
tree0d0ac7b04bce86d760b5ed96928abaf59d31fafc /pynslcd/alias.py
parent84d22e608b03c154d11e54ff34d7b87bf1d78cfa (diff)
Move cache table creation to modules
This also moves the creation of a SQLite database connection to a _get_connection() function to ensure the cache is only created when the caches are instantiated.
Diffstat (limited to 'pynslcd/alias.py')
-rw-r--r--pynslcd/alias.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/pynslcd/alias.py b/pynslcd/alias.py
index 46c4d6b..bf313c4 100644
--- a/pynslcd/alias.py
+++ b/pynslcd/alias.py
@@ -37,13 +37,25 @@ class Search(search.LDAPSearch):
class Cache(cache.Cache):
+ create_sql = '''
+ CREATE TABLE IF NOT EXISTS `alias_cache`
+ ( `cn` TEXT PRIMARY KEY COLLATE NOCASE,
+ `mtime` TIMESTAMP NOT NULL );
+ CREATE TABLE IF NOT EXISTS `alias_1_cache`
+ ( `alias` TEXT NOT NULL COLLATE NOCASE,
+ `rfc822MailMember` TEXT NOT NULL,
+ FOREIGN KEY(`alias`) REFERENCES `alias_cache`(`cn`)
+ ON DELETE CASCADE ON UPDATE CASCADE );
+ CREATE INDEX IF NOT EXISTS `alias_1_idx` ON `alias_1_cache`(`alias`);
+ '''
+
retrieve_sql = '''
SELECT `alias_cache`.`cn` AS `cn`,
`alias_1_cache`.`rfc822MailMember` AS `rfc822MailMember`
FROM `alias_cache`
LEFT JOIN `alias_1_cache`
ON `alias_1_cache`.`alias` = `alias_cache`.`cn`
- '''
+ '''
def retrieve(self, parameters):
query = cache.Query(self.retrieve_sql, parameters)