diff options
| author | Simo Sorce <simo@redhat.com> | 2015-04-01 14:13:41 -0400 |
|---|---|---|
| committer | Simo Sorce <simo@redhat.com> | 2015-04-01 20:21:33 -0400 |
| commit | ce33244e99c311856b405aa36acbd7f35db393ab (patch) | |
| tree | 1df2c3fa6aea1091fa9a30fd5358e7509fa22bad /custodia/store | |
| parent | 531f83b91ddfe5c811bad5b1aebfc9beb9fca1b1 (diff) | |
| download | custodia-ce33244e99c311856b405aa36acbd7f35db393ab.tar.gz custodia-ce33244e99c311856b405aa36acbd7f35db393ab.tar.xz custodia-ce33244e99c311856b405aa36acbd7f35db393ab.zip | |
Fix sqlite store bugs
Use print statement that works in python3
Create table so that keys are unique.
Return directly the bare value associated with the key, if any.
Diffstat (limited to 'custodia/store')
| -rw-r--r-- | custodia/store/sqlite.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/custodia/store/sqlite.py b/custodia/store/sqlite.py index f5908d0..9373ada 100644 --- a/custodia/store/sqlite.py +++ b/custodia/store/sqlite.py @@ -1,5 +1,6 @@ # Copyright (C) 2015 Custodia Project Contributors - see LICENSE file +from __future__ import print_function from custodia.store.interface import CSStore, CSStoreError import os import sqlite3 @@ -7,7 +8,7 @@ import sys def log_error(error): - print >> sys.stderr, error + print(error, file=sys.stderr) class SqliteStore(CSStore): @@ -26,15 +27,19 @@ class SqliteStore(CSStore): try: conn = sqlite3.connect(self.dburi) c = conn.cursor() - r = c.execute(query, (key)) + r = c.execute(query, (key,)) value = r.fetchall() except sqlite3.Error as err: log_error("Error fetching key %s: [%r]" % (key, repr(err))) raise CSStoreError('Error occurred while trying to get key') - return value + if len(value) > 0: + return value[0][0] + else: + return None def _create(self, cur): - create = "CREATE TABLE IF NOT EXISTS %s (key, value)" % self.table + create = "CREATE TABLE IF NOT EXISTS %s " \ + "(key PRIMARY KEY UNIQUE, value)" % self.table cur.execute(create) def set(self, key, value): |
