gpt4 book ai didi

SQLAlchemy bool 值与 bool 值

转载 作者:行者123 更新时间:2023-12-01 23:13:16 27 4
gpt4 key购买 nike

我可以看到 BOOLEAN 覆盖了 __visit_name__

class BOOLEAN(Boolean):
__visit_name__ = 'BOOLEAN'

控制调度员选择的访问者方法

def _compiler_dispatch(self, visitor, **kw):
visit_attr = 'visit_%s' % self.__visit_name__
try:
meth = getattr(visitor, visit_attr)

对于 MS SQL,访问者是 MSSQLCompiler,它派生自 GenericTypeCompiler。现在,MSSQLCompiler 覆盖 visit_boolean:

def visit_boolean(self, type_, **kw):
return self.visit_BIT(type_)

但它不会覆盖 visit_BOOLEAN,因此列类型 Boolean 解析为“BIT”,而 BOOLEAN(通过父类(super class))解析为“BOOLEAN”,这不是有效的 MS SQL 类型。

为什么会出现这种不一致? MSSQLCompiler 是否需要覆盖 visit_BOOLEAN,还是我遗漏了什么? BooleanBOOLEAN 类型在概念上有什么区别?

最佳答案

Booleangeneric type :

Generic types specify a column that can read, write and store a particular type of Python data. SQLAlchemy will choose the best database column type available on the target database when issuing a CREATE TABLE statement.

BOOLEANSQL type :

This category of types refers to types that are either part of the SQL standard, or are potentially found within a subset of database backends. Unlike the “generic” types, the SQL standard/multi-vendor types have no guarantee of working on all backends, and will only work on those backends that explicitly support them by name. That is, the type will always emit its exact name in DDL with CREATE TABLE is issued.

没有不一致,因为它们是不同的东西。

关于SQLAlchemy bool 值与 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51029761/

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