mercredi 4 mai 2016

Are there some alternatives cursor iterating in Sqlite using python?

Hi and in advance sorry for my bad english.

There is one problem with iterating cursor in SQlite using python. Actually, i have cursor on this query

cursor = con.execute( "SELECT RgdCode from " "info_cli_otgr_201503 as a where CliCode=\"" + str(clicode) + "\" ")

it is quite fast for me, i check performance of this piece of code (there aren't any problems in here). then i do this

list=[a[0] for a in cursor]

it is too slowly, but i don't know why? expected value of length list is 10-15 items( data items is only integer). Please, give me some advice, maybe problem in sqlite, this cursor very slow ( i try to use fetchAll() and similar

the time on extra needs in seconds 0.0020012855529785156 it consist from query, append()(in another list) and so on

this time with iterating cursor 0.09606122970581055

the below full code

def getSpecifyRgdCodeByClient(clicode):
    cursor = con.execute(
        "SELECT RgdCode from "
        "info_cli_otgr_201503 as a where CliCode=\"" + str(clicode) + "\" ")
    list=[a[0] for a in cursor]
    return list

if __name__ == "__main__":
    listOfCliCode=getListOfClicode()
    listOfRgdCode=getListOfRgdCode()
    print("length CliCode: ",len(listOfCliCode))
    print("length RgdCode: ",len(listOfRgdCode))
    allcli=[]
    col=0
    for clicode in listOfCliCode:
        allcli.append(getSpecifiedRgdCodeByClient(clicode))

Aucun commentaire:

Enregistrer un commentaire