ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.dbsqlite.SQLhash Class Reference
Inheritance diagram for python.dbsqlite.SQLhash:
Collaboration diagram for python.dbsqlite.SQLhash:

Public Member Functions

def __init__ (self, filename=':memory:', flags='r', mode=None)
 
def __len__ (self)
 
def __bool__ (self)
 
def keys (self)
 
def values (self)
 
def items (self)
 
def __iter__ (self)
 
def iterkeys (self)
 
def itervalues (self)
 
def iteritems (self)
 
def __contains__ (self, key)
 
def __getitem__ (self, key)
 
def __setitem__ (self, key, value)
 
def __delitem__ (self, key)
 
def update (self, items=(), **kwds)
 
def clear (self)
 
def sync (self)
 
def close (self)
 
def __del__ (self)
 

Public Attributes

 conn
 

Detailed Description

Definition at line 26 of file dbsqlite.py.

Constructor & Destructor Documentation

◆ __init__()

def python.dbsqlite.SQLhash.__init__ (   self,
  filename = ':memory:',
  flags = 'r',
  mode = None 
)

Definition at line 27 of file dbsqlite.py.

27  def __init__(self, filename=':memory:', flags='r', mode=None): # XXX add flag/mode handling
28  # c -- create if it doesn't exist
29  # n -- new empty
30  # w -- open existing
31  # r -- readonly
32  if 'n' in flags:
33  import os
34  if os.path.exists(filename):
35  os.remove(filename)
36 
37  MAKE_SHELF = 'CREATE TABLE IF NOT EXISTS shelf (key TEXT PRIMARY KEY NOT NULL, value BLOB)'
38  self.conn = sqlite3.connect(filename)
39  self.conn.text_factory = str
40  if 'r' not in flags or filename==':memory:':
41  self.conn.execute(MAKE_SHELF)
42  self.conn.commit()
43 
44 

◆ __del__()

def python.dbsqlite.SQLhash.__del__ (   self)

Definition at line 131 of file dbsqlite.py.

131  def __del__(self):
132  self.close()
133 

Member Function Documentation

◆ __bool__()

def python.dbsqlite.SQLhash.__bool__ (   self)

Definition at line 49 of file dbsqlite.py.

49  def __bool__(self):
50  # returns None if count is zero
51  GET_BOOL = 'SELECT MAX(ROWID) FROM shelf'
52  return self.conn.execute(GET_BOOL).fetchone()[0] is not None
53 

◆ __contains__()

def python.dbsqlite.SQLhash.__contains__ (   self,
  key 
)

Definition at line 78 of file dbsqlite.py.

78  def __contains__(self, key):
79  HAS_ITEM = 'SELECT 1 FROM shelf WHERE key = ?'
80  return self.conn.execute(HAS_ITEM, (key,)).fetchone() is not None
81 

◆ __delitem__()

def python.dbsqlite.SQLhash.__delitem__ (   self,
  key 
)

Definition at line 96 of file dbsqlite.py.

96  def __delitem__(self, key):
97  if key not in self:
98  raise KeyError(key)
99  DEL_ITEM = 'DELETE FROM shelf WHERE key = ?'
100  self.conn.execute(DEL_ITEM, (key,))
101  #self.conn.commit()
102 

◆ __getitem__()

def python.dbsqlite.SQLhash.__getitem__ (   self,
  key 
)

Definition at line 82 of file dbsqlite.py.

82  def __getitem__(self, key):
83  GET_ITEM = 'SELECT value FROM shelf WHERE key = ?'
84  item = self.conn.execute(GET_ITEM, (key,)).fetchone()
85  if item is None:
86  raise KeyError(key)
87 
88  return pickle.loads(item[0])
89 

◆ __iter__()

def python.dbsqlite.SQLhash.__iter__ (   self)

Definition at line 63 of file dbsqlite.py.

63  def __iter__(self):
64  return self.iterkeys()
65 

◆ __len__()

def python.dbsqlite.SQLhash.__len__ (   self)

Definition at line 45 of file dbsqlite.py.

45  def __len__(self):
46  GET_LEN = 'SELECT COUNT(*) FROM shelf'
47  return self.conn.execute(GET_LEN).fetchone()[0]
48 

◆ __setitem__()

def python.dbsqlite.SQLhash.__setitem__ (   self,
  key,
  value 
)

Definition at line 90 of file dbsqlite.py.

90  def __setitem__(self, key, value):
91  ADD_ITEM = 'REPLACE INTO shelf (key, value) VALUES (?,?)'
92  value = pickle.dumps(value)
93  self.conn.execute(ADD_ITEM, (key, value))
94  #self.conn.commit()
95 

◆ clear()

def python.dbsqlite.SQLhash.clear (   self)

Definition at line 116 of file dbsqlite.py.

116  def clear(self):
117  CLEAR_ALL = 'DELETE FROM shelf; VACUUM;'
118  self.conn.executescript(CLEAR_ALL)
119  self.conn.commit()
120 

◆ close()

def python.dbsqlite.SQLhash.close (   self)

Definition at line 125 of file dbsqlite.py.

125  def close(self):
126  if self.conn is not None:
127  self.conn.commit()
128  self.conn.close()
129  self.conn = None
130 

◆ items()

def python.dbsqlite.SQLhash.items (   self)

Definition at line 60 of file dbsqlite.py.

60  def items(self):
61  return list(self.iteritems())
62 

◆ iteritems()

def python.dbsqlite.SQLhash.iteritems (   self)

Definition at line 74 of file dbsqlite.py.

74  def iteritems(self):
75  GET_ITEMS = 'SELECT key, value FROM shelf ORDER BY ROWID'
76  return SQLHashItemIterator(self.conn, GET_ITEMS, (0, 1))
77 

◆ iterkeys()

def python.dbsqlite.SQLhash.iterkeys (   self)

Definition at line 66 of file dbsqlite.py.

66  def iterkeys(self):
67  GET_KEYS = 'SELECT key FROM shelf ORDER BY ROWID'
68  return SQLHashKeyIterator(self.conn, GET_KEYS, (0,))
69 

◆ itervalues()

def python.dbsqlite.SQLhash.itervalues (   self)

Definition at line 70 of file dbsqlite.py.

70  def itervalues(self):
71  GET_VALUES = 'SELECT value FROM shelf ORDER BY ROWID'
72  return SQLHashValueIterator(self.conn, GET_VALUES, (0,))
73 

◆ keys()

def python.dbsqlite.SQLhash.keys (   self)

Definition at line 54 of file dbsqlite.py.

54  def keys(self):
55  return list(self.iterkeys())
56 

◆ sync()

def python.dbsqlite.SQLhash.sync (   self)

Definition at line 121 of file dbsqlite.py.

121  def sync(self):
122  if self.conn is not None:
123  self.conn.commit()
124 

◆ update()

def python.dbsqlite.SQLhash.update (   self,
  items = (),
**  kwds 
)

Definition at line 103 of file dbsqlite.py.

103  def update(self, items=(), **kwds):
104  try:
105  items = items.items()
106  items = [(k,pickle.dumps(v)) for k,v in items]
107  except AttributeError:
108  pass
109 
110  UPDATE_ITEMS = 'REPLACE INTO shelf (key, value) VALUES (?, ?)'
111  self.conn.executemany(UPDATE_ITEMS, items)
112  self.conn.commit()
113  if kwds:
114  self.update(kwds)
115 

◆ values()

def python.dbsqlite.SQLhash.values (   self)

Definition at line 57 of file dbsqlite.py.

57  def values(self):
58  return list(self.itervalues())
59 

Member Data Documentation

◆ conn

python.dbsqlite.SQLhash.conn

Definition at line 39 of file dbsqlite.py.


The documentation for this class was generated from the following file:
python.Bindings.iteritems
iteritems
Definition: Control/AthenaPython/python/Bindings.py:823
python.Bindings.__iter__
__iter__
Definition: Control/AthenaPython/python/Bindings.py:794
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:808
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
python.Bindings.iterkeys
iterkeys
Definition: Control/AthenaPython/python/Bindings.py:813
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:71
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
python.AthDsoLogger.__del__
def __del__(self)
Definition: AthDsoLogger.py:81
python.Bindings.__setitem__
__setitem__
Definition: Control/AthenaPython/python/Bindings.py:774
python.Bindings.itervalues
itervalues
Definition: Control/AthenaPython/python/Bindings.py:818
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:801
calibdata.commit
bool commit
Definition: calibdata.py:831
python.Bindings.__getitem__
__getitem__
Definition: Control/AthenaPython/python/Bindings.py:782
python.Bindings.__contains__
__contains__
Definition: Control/AthenaPython/python/Bindings.py:768