コード例 #1
0
ファイル: DB.py プロジェクト: qiuliangflash/FileSearch
def deleteAbsolutePathFromFileTable(DBhandle, tableCount, fileName):
    baseName = osBase.getBaseName(fileName)
    dirName = osBase.getDirName(fileName)
    if "'" in fileName:
        DBhandle.execute('select * from %s where FileName = "%s"' % ("filepath_" + str(tableCount), baseName))
    else:
        DBhandle.execute("select * from %s where FileName = '%s'" % ("filepath_" + str(tableCount), baseName))
    result = DBhandle.fetchall()
    if len(result) == 0:
        return

    for i in range(len(result)):
        matchCount = 0
        previousId = result[i][1]
        list = range(tableCount - 1)
        list.reverse()
        for j in list:
            DBhandle.execute("select * from %s where CurrentId = %d" % ("filepath_" + str(j + 1), previousId))
            searchResult = DBhandle.fetchall()
            if len(searchResult) > 0 and osBase.getBaseName(dirName) == searchResult[0][2]:
                matchCount += 1
                previousId = searchResult[0][1]
                dirName = osBase.getDirName(dirName)
            else:
                break
        if matchCount == tableCount - 1:
            DBhandle.execute("delete from %s where CurrentId = '%s'" % ("filepath_" + str(tableCount), result[i][0]))
            break
コード例 #2
0
ファイル: DB.py プロジェクト: qiuliangflash/FileSearch
def insertAbsolutePathToFileTable(DBhandle, tableCount, filePath):
    dirName = osBase.getDirName(filePath)
    globalTableCount = getFileTableCount(filePath[0])

    if globalTableCount < tableCount:
        setFileTableCount(tableCount)
        DBhandle.execute(
            "create table %s (CurrentId INTEGER, PreviousId INTEGER, FileName text)" % "filepath_" + str(tableCount)
        )
        storeCurrentId = 1
    else:
        DBhandle.execute("select max(CurrentId) from %s" % "filepath_" + str(tableCount))
        result = DBhandle.fetchall()
        storeCurrentId = result[0][0] + 1

    baseName = osBase.getBaseName(dirName)

    if "'" in baseName:
        DBhandle.execute('select * from %s where FileName = "%s"' % ("filepath_" + str(tableCount - 1), baseName))
    else:
        DBhandle.execute("select * from %s where FileName = '%s'" % ("filepath_" + str(tableCount - 1), baseName))
    result = DBhandle.fetchall()
    if len(result) == 0:
        return
    if tableCount == 2:
        return insertFileTable(
            DBhandle, "filepath_" + str(tableCount), storeCurrentId, result[0][0], osBase.getBaseName(filePath)
        )

    dirName = osBase.getDirName(dirName)
    for i in range(len(result)):
        count = 0
        previousId = result[i][0]
        tableList = range(tableCount - 1)
        tableList.reverse()
        for j in tableList:
            DBhandle.execute("select * from % s where CurrentId = %d" % ("filepath_" + str(j + 1), result[i][0]))
            newResult = DBhandle.fetchall()
            if newResult[0][2] != osBase.getBaseName(dirName):
                break
            else:
                count += 1
                previousId = newResult[0][1]
                dirName = osBase.getDirName(dirName)
        if count == tableCount - 1:
            previousId = result[i][0]
            break
    insertFileTable(DBhandle, "filepath_" + str(tableCount), storeCurrentId, previousId, os.path.basename(filePath))