45 self.
conn = sqlite3.connect(filename, 1, 0,
None)
47 self.
c = self.conn.cursor()
55 self.c.execute(
'create table if not exists p2data (date integer, data collate binary)')
58 except sqlite3.OperationalError:
60 logger.warning(
"Database opening failed, database locked")
72 val = (timestamp,datas)
74 req =
'insert into p2data values (?,?)'
76 self.insertBuff.append(val)
80 logger.debug(
"Inserted "+str(len(self.
insertBuff))+
" datas")
82 except sqlite3.OperationalError:
83 if len(self.
insertBuff) > P2DbStore.INSERTBUFFSZ:
84 logger.warning(
"Data lost after failing too many times to insert because of database lock.")
85 self.insertBuff.pop(0)
87 logger.debug(
'Data inserted in db')
88 logger.debug(
'Data stored in database')
101 req =
'select * from p2data'
103 req +=
' where date >= ?'
112 req +=
' order by date'
114 logger.debug(
'Executing : \''+req+
'\' on database')
121 self.c.execute(req, val)
122 res = self.c.fetchall()
124 except sqlite3.OperationalError:
126 logger.warning(
"Database reading failed, database locked")
139 req =
'SELECT * FROM p2data ORDER BY date LIMIT 1'
140 self.c.execute(req, ())
141 res = self.c.fetchone()
143 except sqlite3.OperationalError:
145 logger.warning(
"Database reading failed, database locked")
160 req =
'SELECT * FROM p2data ORDER BY date DESC LIMIT 10'
161 self.c.execute(req,())
162 res = self.c.fetchall()
164 except sqlite3.OperationalError:
166 logger.warning(
"Database reading failed, database locked")