Python: convert buffer type of SQLITE column into string

Posted by Volatil3 on Stack Overflow See other posts from Stack Overflow or by Volatil3
Published on 2012-11-11T11:52:33Z Indexed on 2012/11/11 17:00 UTC
Read the original article Hit count: 395

Filed under:
|
|
|

I am new to Python 2.6. I have been trying to fetch date datetime value which is in yyyy-mm-dd hh:m:ss format back in my Python program. On checking the column type in Python I get the error: 'buffer' object has no attribute 'decode'. I want to use the strptime() function to split the date data and use it but I can't find how to convert a buffer to string. The following is a sample of my code (also available here):

conn = sqlite3.connect("mrp.db.db", detect_types=sqlite3.PARSE_DECLTYPES)
cursor = conn.cursor()
qryT = """
    SELECT dateDefinitionTest FROM t
    WHERE IDproject = 4 AND IDstatus = 5
    ORDER BY priority, setDate DESC
"""
rec = (4,4)
cursor.execute(qryT,rec)
resultsetTasks = cursor.fetchall()
cursor.close()  # closing the resultset
for item in resultsetTasks:
    taskDetails = {}
    _f = item[10].decode("utf-8")

The exception I get is:

'buffer' object has no attribute 'decode'

© Stack Overflow or respective owner

Related posts about python

Related posts about sqlite