簡體   English   中英

SQLite 字節到 SQLite 文件

[英]SQLite byte to SQLite File

我有一個已轉換為字節格式的 .sqlite 文件,我想知道如何將其轉換為可以在其中操作和讀取數據的格式。

代碼在python中,數據庫在sqlite中。

什么都有幫助! 想有個方向去。

b'SQLite format 3\x00\x10\x00\x01\x01\x00@  \x00\x04\xa4\xb2\x00\x00\x0f\xed\x00\x00\x04~\x00\x00\x00\x18\x00\x00\x002\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\xa4\xb2\x00.S`\x05\x00\x00\x00\x0b\x0f\xc9\x00\x00\x00\x08F\x0f\xfb\x0f\xf6\x0f\xf1\x0f\xec\x0f\xe7\x0f\xe2\x0f\xdd\x0f\xd8\x0f\xd3\x0f\xce\x0f\xc9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x

如果這只是原始字節,您應該能夠將其保存到文件中:

1.准備一些數據
$ sqlite3 test.sqlite
SQLite version 3.36.0 2021-06-18 18:36:39
Enter ".help" for usage hints.
sqlite> CREATE TABLE t1 (c1 INT);
sqlite> INSERT INTO t1 VALUES (1);
sqlite> SELECT * FROM t1;
1
sqlite> .quit
2.從字節創建一個新的數據庫文件:
>>> db = bytes(open("test.sqlite", "rb").read())
>>> db[:20]
b'SQLite format 3\x00\x10\x00\x01\x01'
>>> open("new.sqlite", "wb").write(db)
8192
3. 測試
>>> import sqlite3
>>> con = sqlite3.connect("new.sqlite")
>>> cur = con.cursor()
>>> for row in cur.execute("SELECT * FROM t1"): print(row)
... 
(1,)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM