gpt4 book ai didi

python - SQLAlchemy 查询不返回所有大文本字段

转载 作者:行者123 更新时间:2023-12-04 20:19:34 27 4
gpt4 key购买 nike

首先,这里有一些关于我的环境:

  • 使用 MSSMS 作为我的数据库管理工具。
  • 使用 Django 1.3
  • 使用 SQLAlchemy

  • 我在数据库中有一个没有最大长度的文本字段。其中有 890591 个字符长的文本。

    当我使用 SQLAlchemy 检索此字段时它被截断为 64512 个字符。我也用其他几个大行尝试过,它总是被截断为 64512。
    SELECT @@TEXTSIZE返回一些荒谬的值,如 160 万,所以这不是问题。如果我这样做 SELECT DATALENGTH(field)它返回正确的 890591。所以它似乎不是数据库,它似乎是 SQLAlchemy .或者它可能是一些 Python 限制。

    有任何想法吗?我似乎不知所措。

    编辑:这是要求的更多信息:

    操作系统:Debian 5.0.9

    SQLAlchemy:0.7.3

    SQL:MS Sql Server 2008

    数据库连接:mssql+pymssql://name:password@server/dbname

    pymssql 版本:1.0.2

    有问题的型号:
    class RACReport(Base):
    __tablename__ = 'RACReport'
    id = Column(properUUID(), primary_key=True, nullable=False, default=genuuid4, server_default=text('NEWID()'))
    client_id = Column(properUUID(), ForeignKey(Client.id), nullable=False)
    rawdata = Column(Text(), nullable=True)
    rawtime = Column(DateTime(), nullable=True, default=datetime.datetime.now())
    processeddata = Column(Text(), nullable=True)
    processedtime = Column(DateTime(), nullable=True)
    reportstartdate = Column(DateTime(), nullable=False)
    reportenddata = Column(DateTime(), nullable=False)
    numberofdocs = Column(Integer(), nullable=True)
    RACReport.__table__.schema='rac'

    class properUUID(st.TypeDecorator):
    impl = mssql.MSUniqueIdentifier
    def process_result_value(self, value, dialect):
    if value:
    return str(uuid.UUID(bytes_le=value))

    def genuuid4():
    return str(uuid.uuid4())

    rawdata 和 processdata 是他遇到问题的两个字段。

    这是一个测试查询和回显:
    rac.session.query(rac.RACReport).filter(rac.RACReport.id=='8fb76cb7-d752-45af-a20a-3b85d5e7b8a6').all() 2011-11-17 09:39:46,890 INFO sqlalchemy.engine.base.Engine SELECT [RACReport_1].id AS [rac_RACReport_id], [RACReport_1].client_id AS [rac_RACReport_client_id], [RACReport_1].rawdata AS [rac_RACReport_rawdata], [RACReport_1].rawtime AS [rac_RACReport_rawtime], [RACReport_1].processeddata AS [rac_RACReport_processeddata], [RACReport_1].processedtime AS [rac_RACReport_processedtime], [RACReport_1].reportstartdate AS [rac_RACReport_reportstartdate], [RACReport_1].reportenddate AS [rac_RACReport_reportenddate]
    FROM rac.[RACReport] AS [RACReport_1]
    WHERE [RACReport_1].id = %(id_1)s
    2011-11-17 09:39:46,890 INFO sqlalchemy.engine.base.Engine {'id_1': '8fb76cb7-d752-45af-a20a-3b85d5e7b8a6'}

    最佳答案

    我对 *nix 与 SQL Server 的连接知之甚少,但简单的谷歌搜索表明该问题与 FreeTDS 有关。配置:

  • 关于 SO 的相关问题:Data ended at 64512 characters - MSSQL // PHP // OPENSuSE // APACHE2 .
  • 另一个问答摘自 here :

  • My text data are being truncated or are causing my client to break.

    The text data type is different from char and varchar types. The maximum data length of a text column is governed by the textsize connection option. Microsoft claims in their documentation to use a default textsize of 4000 characters, but in fact their implementation is inconsistent. Sometimes text columns are returned with a size of 4 GB!

    The best solution is to make sure you set the textsize option to a reasonable value when establishing a connection. For example:


    1> set textsize 10000 
    2> go

    See also the text size option in freetds.conf.



    只是一个旁注:您似乎正在使用 pymssql 的相当过时的版本.

    关于python - SQLAlchemy 查询不返回所有大文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8160564/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com