This is a follow on from: Python - Converting Hex to INT/CHAR
I now have a working solution for converting the stored hex value of an IP from an sqlite3 db into a readable and usable format. However up until now I have been testing by copying and pasting the values directly from a sqlite3 db viewer.
I have been trying to poll the db with a script to lookup that information however I have discovered that it apparantly stores blob data into a buffer which isn't instantly human readable.
For example, the IP 192.168.0.1 is stored as blob type under the field ip as X'C0A80001'
Since I worked from a copied and pasted example into my code I have constructed code to strip the X' and ' from the hex to be able to then convert it. What I cannot get is that value from the database (X'C0A80001' <- this value that I can view with a db manager). Searching I found http://eli.thegreenplace.net/2009/05/29/storing-blobs-in-a-sqlite-db-with-pythonpysqlite/ which showed an example of reading blobs to and from a sqlite db but their methods didn't work. They displayed the error;
print row[0], str(row[1]).encode('hex') IndexError: tuple index out of range
I am fairly new to Python so apologies if I am missing something basic but any pointers or code examples anyone has to help me get my head around this would be appreciated.
EDIT: Doh, didn't paste the code from the above example;
c = conn.cursor()
c.execute('select ip from item where name = ' + "\'" + host + "\'")
for row in c:
print row[0], str(row[1]).encode('hex')
It may be my understanding thats really off here as to why I can't read it back the way I want to
UPDATE: Using the below answer I modified my code to;
rows = c.execute('select ip from item where name= ' + "\"" + host + "\"")
for row in rows:
print str(row[0]).encode("hex")