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 28 of file dbsqlite.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 29 of file dbsqlite.py.

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

◆ __del__()

def python.dbsqlite.SQLhash.__del__ (   self)

Definition at line 133 of file dbsqlite.py.

133  def __del__(self):
134  self.close()
135 

Member Function Documentation

◆ __bool__()

def python.dbsqlite.SQLhash.__bool__ (   self)

Definition at line 51 of file dbsqlite.py.

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

◆ __contains__()

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

Definition at line 80 of file dbsqlite.py.

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

◆ __delitem__()

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

Definition at line 98 of file dbsqlite.py.

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

◆ __getitem__()

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

Definition at line 84 of file dbsqlite.py.

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

◆ __iter__()

def python.dbsqlite.SQLhash.__iter__ (   self)

Definition at line 65 of file dbsqlite.py.

65  def __iter__(self):
66  return self.iterkeys()
67 

◆ __len__()

def python.dbsqlite.SQLhash.__len__ (   self)

Definition at line 47 of file dbsqlite.py.

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

◆ __setitem__()

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

Definition at line 92 of file dbsqlite.py.

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

◆ clear()

def python.dbsqlite.SQLhash.clear (   self)

Definition at line 118 of file dbsqlite.py.

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

◆ close()

def python.dbsqlite.SQLhash.close (   self)

Definition at line 127 of file dbsqlite.py.

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

◆ items()

def python.dbsqlite.SQLhash.items (   self)

Definition at line 62 of file dbsqlite.py.

62  def items(self):
63  return list(self.iteritems())
64 

◆ iteritems()

def python.dbsqlite.SQLhash.iteritems (   self)

Definition at line 76 of file dbsqlite.py.

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

◆ iterkeys()

def python.dbsqlite.SQLhash.iterkeys (   self)

Definition at line 68 of file dbsqlite.py.

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

◆ itervalues()

def python.dbsqlite.SQLhash.itervalues (   self)

Definition at line 72 of file dbsqlite.py.

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

◆ keys()

def python.dbsqlite.SQLhash.keys (   self)

Definition at line 56 of file dbsqlite.py.

56  def keys(self):
57  return list(self.iterkeys())
58 

◆ sync()

def python.dbsqlite.SQLhash.sync (   self)

Definition at line 123 of file dbsqlite.py.

123  def sync(self):
124  if self.conn is not None:
125  self.conn.commit()
126 

◆ update()

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

Definition at line 105 of file dbsqlite.py.

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

◆ values()

def python.dbsqlite.SQLhash.values (   self)

Definition at line 59 of file dbsqlite.py.

59  def values(self):
60  return list(self.itervalues())
61 

Member Data Documentation

◆ conn

python.dbsqlite.SQLhash.conn

Definition at line 41 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:812
python.Bindings.__iter__
__iter__
Definition: Control/AthenaPython/python/Bindings.py:783
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:797
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
python.Bindings.iterkeys
iterkeys
Definition: Control/AthenaPython/python/Bindings.py:802
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
dqt_zlumi_pandas.update
update
Definition: dqt_zlumi_pandas.py:42
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
python.AthDsoLogger.__del__
def __del__(self)
Definition: AthDsoLogger.py:82
python.Bindings.__setitem__
__setitem__
Definition: Control/AthenaPython/python/Bindings.py:763
python.Bindings.itervalues
itervalues
Definition: Control/AthenaPython/python/Bindings.py:807
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
calibdata.commit
bool commit
Definition: calibdata.py:832
python.Bindings.__getitem__
__getitem__
Definition: Control/AthenaPython/python/Bindings.py:771
python.Bindings.__contains__
__contains__
Definition: Control/AthenaPython/python/Bindings.py:757