'sqlite3.Connection'对象没有属性'serialize'

问题描述 投票:0回答:1

我想在linux中使用sqlite的序列化/反序列化方法。 所以我需要 python 3.11 和 sqlite >= 3.39 https://docs.python.org/3/library/sqlite3.html

然后我获取了python 3.11.4的docker镜像并编译了最新版本的sqlite,然后替换了库。

RUN cd /opt/sqlite && tar -zxf sqlite-autoconf-3430000.tar.gz && cd /opt/sqlite/sqlite-autoconf-3430000 && \
    CFLAGS="-Os -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS=1 -DSQLITE_ENABLE_DESERIALIZE=1 -DSQLITE_MEMDB_DEFAULT_MAXSIZE=17179869184 -DSQLITE_MAX_MEMORY=17179869184 -DSQLITE_MAX_ALLOCATION_SIZE=2147483391 " ./configure  && \
    make install && LD_RUN_PATH=/usr/local/lib ./configure --enable-optimizations
ENV LD_LIBRARY_PATH=/usr/local/lib

Sqlite 工作正常,但如果我运行:

import sqlite3
print(sqlite3.version) -> 2.6.0
print(sqlite3.sqlite_version) -> 3.43.0
conn = sqlite3.connect(':memory:')
conn.serialize()

我收到错误

'sqlite3.Connection' object has no attribute 'serialize'

貌似db-api接口没有更新。有人可以帮助我吗?

python linux docker sqlite
1个回答
0
投票

使用这个 Dockerfile :

FROM python:3.11.4

WORKDIR /app

当我构建并运行图像时:

$ docker run -it test bash
root@96227679cac0:/app# python -V
Python 3.11.4
root@96227679cac0:/app# python
Python 3.11.4 (main, Aug 16 2023, 19:58:34) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> print(sqlite3.version) 
2.6.0
>>> print(sqlite3.sqlite_version) 
3.40.1
>>> conn = sqlite3.connect(':memory:')
>>> conn.serialize()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
sqlite3.OperationalError: unable to serialize 'main'
>>>

您可以看到

serialize
可用。

© www.soinside.com 2019 - 2024. All rights reserved.