Files
@ 1c3d9df86fb1
Branch filter:
Location: Morevna/src/db.py - annotation
1c3d9df86fb1
1.0 KiB
text/x-python
switched from persistent to transient sockets
95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 6f31f20feb06 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 95bfc9d72133 | import sqlite3
import time
COMMIT_TIME=2 # s
class DB:
def __init__(self,filename):
self.filename=filename
self.connection=sqlite3.connect(self.filename)
self.connection.row_factory=sqlite3.Row
self.commitTime=time.time()
def setup(self):
# !! err if exists
self.connection.execute("""create table `hashes` (
`sector_id` integer primary key,
`sector_hash` blob not null,
`updated` integer
)""")
self.connection.commit()
## Inserts hash into the DB.
#
# @param sectorHash bytes object containing the hash
def insertHash(self,sectorId,sectorHash):
# !! if not connection
res=self.connection.execute("""insert or replace into `hashes` (`sector_id`, `sector_hash`, `updated`)
values (?, ?, strftime('%s','now'))""", (sectorId,sectorHash))
t=time.time()
if t-self.commitTime > COMMIT_TIME:
self.connection.commit()
self.commitTime=t
return res
def listHashes(self):
# !! if not connection
return self.connection.execute("""select * from `hashes` order by `sector_id` asc""")
|