简体   繁体   English

尝试解包 sqlite3 行时出错

[英]Error when trying to depack sqlite3 row

I'm using python to access an sqlite db.我正在使用 python 访问一个 sqlite 数据库。 I'm accessing a copy of the Firefox cookie db.我正在访问 Firefox cookie 数据库的副本。

I'm trying to follow the advice giving here by jjm in: http://stackoverflow.com/questions/12325234/python-tuple-indices-must-be-integers-not-str-when-selecting-from-mysql-table我正在尝试遵循 jjm 在此处给出的建议: http ://stackoverflow.com/questions/12325234/python-tuple-indices-must-be-integers-not-str-when-selecting-from-mysql-桌子

I would like to unpack the row variable into simple variable names.我想将行变量解压缩为简单的变量名。 I do not understand what type of variable I am getting with row.我不明白我用 row 得到的是什么类型的变量。 Is it an array?是数组吗?

with con:
    cur = con.cursor()    
    # 
    cur.execute("SELECT \
        name, \
        value, \
        host, \
        datetime((expiry/1000000), 'unixepoch'), \
        expiry, \
        datetime((lastAccessed/1000000), 'unixepoch'), \
        datetime((creationTime/1000000), 'unixepoch') \
        FROM moz_cookies \
        WHERE baseDomain = 'apple.com' AND name = 's_ppv'")      

    rows = cur.fetchall()
    print ( len(rows) )


    for row in rows:
        if debug >= 1:
            # Indexes are 0 offset. 
            print ("row is = ")
            print (row)

            aName, aValue, aHost, aDisplayExpire, aExpire = row

failing on "aName, aValue, aHost, aDisplayExpire, aExpire = row" variable debug is set to 1. Here is the output. “aName、aValue、aHost、aDisplayExpire、aExpire = row”变量调试失败设置为 1。这是输出。

1
row is = 
(u's_ppv', u'acs%253A%253Aadf%253A%253Aprofile%253Auser%2520profile%2520%2528en_US%2529%2C78%2C78%2C576%2C', u'.apple.com', u'2015-07-01 01:47:46', 1435715266000000L, u'2015-07-01 01:27:46', u'2015-06-15 16:12:15')
Traceback (most recent call last):
  File "./adjust-ASC-Time.bash", line 188, in <module>
    aName, aValue, aHost, aDisplayExpire, aExpire = row
ValueError: too many values to unpack

I chopped off the end of the vector.我砍掉了向量的末端。

aName, aValue, aHost, aDisplayExpire, aExpire = row[:5] aName、aValue、aHost、aDisplayExpire、aExpire = row[:5]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM