summaryrefslogtreecommitdiff
path: root/pynslcd/group.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/group.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/group.py')
-rw-r--r--pynslcd/group.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/pynslcd/group.py b/pynslcd/group.py
index 2868d96..f893ac1 100644
--- a/pynslcd/group.py
+++ b/pynslcd/group.py
@@ -75,12 +75,26 @@ class Search(search.LDAPSearch):
class Cache(cache.Cache):
+ create_sql = '''
+ CREATE TABLE IF NOT EXISTS `group_cache`
+ ( `cn` TEXT PRIMARY KEY,
+ `userPassword` TEXT,
+ `gidNumber` INTEGER NOT NULL UNIQUE,
+ `mtime` TIMESTAMP NOT NULL );
+ CREATE TABLE IF NOT EXISTS `group_3_cache`
+ ( `group` TEXT NOT NULL,
+ `memberUid` TEXT NOT NULL,
+ FOREIGN KEY(`group`) REFERENCES `group_cache`(`cn`)
+ ON DELETE CASCADE ON UPDATE CASCADE );
+ CREATE INDEX IF NOT EXISTS `group_3_idx` ON `group_3_cache`(`group`);
+ '''
+
retrieve_sql = '''
SELECT `cn`, `userPassword`, `gidNumber`, `memberUid`
FROM `group_cache`
LEFT JOIN `group_3_cache`
ON `group_3_cache`.`group` = `group_cache`.`cn`
- '''
+ '''
def retrieve(self, parameters):
query = cache.Query(self.retrieve_sql, parameters)