cur.execute('CREATE TABLE IF NOT EXISTS updates ( `ext` TET, `update_time` INTEGER, `file_count` INTEGER);')
defregexp(expr,item):
returnre.search(expr,item)isnotNone
ext_database.create_function("REGEXP",2,regexp)
@ -19,17 +21,41 @@ class Searcher:
self.index='{}_index'.format(ext)
self.__init_table__()
def__init_table__(self):
self.cur.execute('CREATE TABLE IF NOT EXISTS ? (`name` TEXT,`fullpath` TEXT,UNIQUE(name,fullpath));',[self.ext])
self.cur.execute('CREATE INDEX IF NOT EXISTS ? ON ? ( `name`, `fullpath` )',[self.index,self.ext])
def_update_(self,update_mtimes):
# update logic
self.cur.executemany('INSERT OR IGNORE INTO ? VALUES (?,?)',params)
self.cur.execute('INSERT INTO updates VALUES (?, ?, ?)',[self.ext,time,count])
def_commit_(self):
self.cur.execute('CREATE TABLE IF NOT EXISTS {} (`name` TEXT,`fullpath` TEXT, `update_time` INTEGER,UNIQUE(name,fullpath));'.format(self.ext))
self.cur.execute('CREATE INDEX IF NOT EXISTS {} ON {} ( `name`, `fullpath` )'.format(self.index,self.ext))
self.cur.execute(
'INSERT INTO updates (ext,update_time,file_count) SELECT :ext, 0, 0 WHERE NOT EXISTS(SELECT 1 FROM updates WHERE ext = :ext AND update_time = 0 AND file_count = 0);',
{'ext':self.ext}
)
self.commit()
defupdate(self,update_mtimes):
self.cur.execute('SELECT update_time FROM updates WHERE ext=? ORDER BY update_time DESC LIMIT 1;',[self.ext])
last_update=self.cur.fetchone()[0]
# input(str(last_update))
_time=int(time.time())
files=_update.update(
self.ext,
config.getlist(self.ext,'paths'),
last_update,
update_mtimes
)
self.cur.executemany('INSERT OR IGNORE INTO {} VALUES (?,?,?)'.format(self.ext),(row+[_time]forrowinfiles))
self.cur.execute('INSERT INTO updates VALUES (?, ?, ?)',[self.ext,_time,len(files)])
self.commit()
defcommit(self):
ext_database.commit()
defclose(self):
ext_database.close()
defsearch(query,regex=False):
ifregex:
self.cur.execute('SELECT * FROM ? WHERE name REGEXP ?',[self.ext,query])
self.cur.execute('SELECT * FROM ? WHERE name REGEXP ?;',[self.ext,query])
else:
self.cur.execute('SELECT * FROM ? WHERE name LIKE ?',[self.ext,query])
returnself.cur.fetchall()
self.cur.execute('SELECT * FROM ? WHERE name LIKE ?;',[self.ext,query])