在sqlite3控制台中使用ASCII查看blob数据作为hexdump

前端之家收集整理的这篇文章主要介绍了在sqlite3控制台中使用ASCII查看blob数据作为hexdump前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在sqlite表中有一列数据存储为blob.具体来说,它是一个序列化的POJO( java对象).

无论哪种方式,我想在sqlite控制台中将其视为十六进制转储,有点像这样:

0000000000  |The correction f|
0000000016  |or the aberratio|
0000000032  |n of light is sa|
0000000048  |id,.on high auth|
0000000064  |ority,not to be|
0000000080  | perfect even in|
0000000096  | that most perfe|
0000000112  |ct organ,the.ey|
0000000128  |e..|

我知道语句SELECT HEX(obj)FROM data WHERE rowid = 1将获取数据只是十六进制,但现在我想把它管道输出到一个能给我一个hexdump视图的东西.

PS – 我知道我试图查看的数据是二进制(序列化POJO),但我想看看里面的实验是什么.所以,即使最终结果是神秘的,请告诉我!

更新:
我尝试了一些建议,但发现sqlite3没有输出完整的十六进制.我期待大约500字节,但改为10:

root@ubuntu:~# sqlite3 IceCream.db "select hex(obj) from Customers where rowid=1;" 
ACED00057372002D6564752E6761746563682E7365636C6173732E70726F6A656374322E637573746F6D65722E437573746F6D6572000000000000000102000B4C0007616464726573737400124C6A6176612F6C616E672F537472696E673B4C0012617661696C61626C65467265654974656D737400134C6A6176612F6C616E672F496E74656765723B4C00096269727468446174657400104C6A6176612F7574696C2F446174653B4C000C646973636F756E745261746571007E00024C000966697273744E616D6571007E00014C000A676F6C645374617475737400134C6A6176612F6C616E672F426F6F6C65616E3B4C00086C6173744E616D6571007E00014C000D6D6F6E74686C79506F696E747371007E00024C0013706F696E74734561726E656450657254696D657400134C6A6176612F7574696C2F486173684D61703B4C000B746F74616C506F696E747371007E00024C000876697053696E636571007E0003787200386564752E6761746563682E7365636C6173732E70726F6A656374322E73797374656D732E446174616261736553657269616C4F626A65637400000000000000010200024C000269647400104C6A6176612F6C616E672F4C6F6E673B4C00166C61737454696D654F626A6563744D6F64696669656471007E000778707372000E6A6176612E6C616E672E4C6F6E673B8BE490CC8F23DF0200014A000576616C7565787200106A6176612E6C616E672E4E756D62657286AC951D0B94E08B020000787000000000000000017371007E0009000001497757AAFB740006436172736F6E737200116A6176612E6C616E672E496E746567657212E2A0A4F781873802000149000576616C75657871007E000A000000007372000E6A6176612E7574696C2E44617465686A81014B59741903000078707708000001349BB816607871007E000F74000442696C6C737200116A6176612E6C616E672E426F6F6C65616ECD207280D59CFAEE0200015A000576616C7565787000740005313233205471007E000F737200116A6176612E7574696C2E486173684D61700507DAC1C31660D103000146000A6C6F6164466163746F7278703F400000770800000010000000007871007E000F70


root@ubuntu:~# sqlite3 IceCream.db "select obj from Customers where rowid=1;" | hexdump -C
00000000  ac ed 0a                                          |...|
00000003
sqlite3 shell无法在二进制数据转储中显示ASCII值.

您必须将其输出通过管道传输到单独的工具中:

sqlite3 test.db "SELECT MyBlob FROM MyTable WHERE ID = 42;" | hexdump -C
sqlite3 test.db "SELECT MyBlob FROM MyTable WHERE ID = 42;" | xxd -g1

但是,sqlite3将blob转换为字符串以显示它,因此如果blob包含零字节,这将不起作用.

您必须将blob输出为十六进制,然后将其转换回二进制,以便您可以以所需的格式显示它:

sqlite3 test.db "SELECT quote(MyBlob) FROM MyTable WHERE id = 42;"  \
| cut -d\' -f2                                                      \
| xxd -r -p                                                         \
| xxd -g1
原文链接:https://www.f2er.com/sqlite/197615.html

猜你在找的Sqlite相关文章