开发者

Python: - How to search SQLite3 DB for Blob type?

开发者 https://www.devze.com 2023-04-09 14:43 出处:网络
Following on fro开发者_StackOverflow社区m; Python - Reading BLOB type from SQLite3 DB Python - Converting Hex to INT/CHAR

Following on fro开发者_StackOverflow社区m;

Python - Reading BLOB type from SQLite3 DB

Python - Converting Hex to INT/CHAR

I have a script that now queries a sqlite3 database with a given id. From this id it finds the IP of that device. This is all done within table1. It then takes this found IP and goes to table2.

Within table2 it then tries to do a search for rows which have the field IP that matches the previously discovered IP.

Thanks to help in the previous questions I have managed to convert the original blob type that the IP is stored in the sqlite3 database into a readable format (into hex and then into an actual IP). Now I have found that I can't actually do an sql where command to then search for this. Perhaps naively I tried to do a search for the original return value from my first search however this returns a buffer

(<read-write buffer ptr 0x7f251c86d778, size 4 at 0x7f251c86d738>,)

This is something I can't obviously use to search for an exact copy of the blob as it contains other information. The only solution I have thought of is to traverse the db and convert each IP from a blob into hex and do a comparison against my previously stored variable where it has been converted into hex from the previous table.

Is this the only way I can perform a search like this? I have enjoyed a lot of help on this today so I am happy for pointers in the right direction

Code Excerpt: This returns the IP from the first table

rows = c.execute('select ip from table1 where name= ' + "\"" + host + "\"") 
   for row in rows:
       print str(row[0]).encode("hex")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号