def load_dialect_impl(self, dialect: dialects) -> DialectType:
"""
SQLAlchemy wraps all database-specific features into
dialects, which are then responsible for generating the SQL code
for a specific DB type when loading in data. ``load_dialect_impl``
is called when CRUD (create, update, delete operations) needs to be
done on the database. This method is responsible for telling
SQLAlchemy how to configure the dialect to write this type
:param dialect: The loaded dialect
:return: The type descriptor for this type.
"""
if dialect.name == 'postgresql':
return dialect.type_descriptor(postgresql.UUID())
else:
return dialect.type_descriptor(CHAR(32))
python类CHAR的实例源码
def __init__(self, length=None, **kwargs):
super(CHAR, self).__init__(length=length, **kwargs)
def normalize_name(self, name):
# Remove trailing spaces: FB uses a CHAR() type,
# that is padded with spaces
name = name and name.rstrip()
if name is None:
return None
elif name.upper() == name and \
not self.identifier_preparer._requires_quotes(name.lower()):
return name.lower()
else:
return name
def get_col_spec(self):
return "CHAR(%(length)s)" % {'length' : self.length}
def get_col_spec(self):
return "CHAR(%(length)s)" % {'length' : self.length}
def get_col_spec(self):
return "CHAR(%(length)s)" % {'length' : self.length}
def get_col_spec(self):
return "CHAR(%(length)s)" % {'length' : self.length}
def load_dialect_impl(self, dialect):
if dialect.name == 'postgresql':
return dialect.type_descriptor(UUID())
else:
return dialect.type_descriptor(CHAR(32))
def __init__(self, length=None, **kwargs):
super(CHAR, self).__init__(length=length, **kwargs)
def normalize_name(self, name):
# Remove trailing spaces: FB uses a CHAR() type,
# that is padded with spaces
name = name and name.rstrip()
if name is None:
return None
elif name.upper() == name and \
not self.identifier_preparer._requires_quotes(name.lower()):
return name.lower()
else:
return name
def __init__(self, length=None, **kwargs):
super(CHAR, self).__init__(length=length, **kwargs)
def normalize_name(self, name):
# Remove trailing spaces: FB uses a CHAR() type,
# that is padded with spaces
name = name and name.rstrip()
if name is None:
return None
elif name.upper() == name and \
not self.identifier_preparer._requires_quotes(name.lower()):
return name.lower()
else:
return name
def __init__(self, length=None, **kwargs):
"""Construct a CHAR.
:param length: Maximum data length, in characters.
:param binary: Optional, use the default binary collation for the
national character set. This does not affect the type of data
stored, use a BINARY type for binary data.
:param collation: Optional, request a particular collation. Must be
compatible with the national character set.
"""
super(CHAR, self).__init__(length=length, **kwargs)
def key_deal():
from_ = Column('from', CHAR(10))
#??????
#Column?????????????????????
def __init__(self, length=None, **kwargs):
super(CHAR, self).__init__(length=length, **kwargs)
def normalize_name(self, name):
# Remove trailing spaces: FB uses a CHAR() type,
# that is padded with spaces
name = name and name.rstrip()
if name is None:
return None
elif name.upper() == name and \
not self.identifier_preparer._requires_quotes(name.lower()):
return name.lower()
else:
return name
def __init__(self, length=None, **kwargs):
"""Construct a CHAR.
:param length: Maximum data length, in characters.
:param binary: Optional, use the default binary collation for the
national character set. This does not affect the type of data
stored, use a BINARY type for binary data.
:param collation: Optional, request a particular collation. Must be
compatible with the national character set.
"""
super(CHAR, self).__init__(length=length, **kwargs)
def __init__(self, length=None, **kwargs):
super(CHAR, self).__init__(length=length, **kwargs)
def normalize_name(self, name):
# Remove trailing spaces: FB uses a CHAR() type,
# that is padded with spaces
name = name and name.rstrip()
if name is None:
return None
elif name.upper() == name and \
not self.identifier_preparer._requires_quotes(name.lower()):
return name.lower()
else:
return name
def __init__(self, length=None, **kwargs):
super(CHAR, self).__init__(length=length, **kwargs)
def normalize_name(self, name):
# Remove trailing spaces: FB uses a CHAR() type,
# that is padded with spaces
name = name and name.rstrip()
if name is None:
return None
elif name.upper() == name and \
not self.identifier_preparer._requires_quotes(name.lower()):
return name.lower()
elif name.lower() == name:
return quoted_name(name, quote=True)
else:
return name
def __init__(self, length=None, **kwargs):
super(CHAR, self).__init__(length=length, **kwargs)
def normalize_name(self, name):
# Remove trailing spaces: FB uses a CHAR() type,
# that is padded with spaces
name = name and name.rstrip()
if name is None:
return None
elif name.upper() == name and \
not self.identifier_preparer._requires_quotes(name.lower()):
return name.lower()
else:
return name
def __init__(self, length=None, **kwargs):
"""Construct a CHAR.
:param length: Maximum data length, in characters.
:param binary: Optional, use the default binary collation for the
national character set. This does not affect the type of data
stored, use a BINARY type for binary data.
:param collation: Optional, request a particular collation. Must be
compatible with the national character set.
"""
super(CHAR, self).__init__(length=length, **kwargs)
def __init__(self, length=None, **kwargs):
super(CHAR, self).__init__(length=length, **kwargs)
def normalize_name(self, name):
# Remove trailing spaces: FB uses a CHAR() type,
# that is padded with spaces
name = name and name.rstrip()
if name is None:
return None
elif name.upper() == name and \
not self.identifier_preparer._requires_quotes(name.lower()):
return name.lower()
else:
return name
def test_name_sqlite(self) -> None:
"""
Tests that if the name ``sqlite`` is given to the database, then a
CHAR descriptor comes back out with 32 characters
"""
uuid_instance = DB_UUID()
dialect_impl = uuid_instance.load_dialect_impl(self.sqlite_dialect)
self.assertIsInstance(
dialect_impl, self.sqlite_dialect.type_descriptor(
CHAR(32)
).__class__
)
def test_bind_uuid_something_else(self, uuid: UUID) -> None:
"""
Tests that the UUID gets de-hyphenated if using the CHAR 32 type, same
as always.
:param uuid: A randomly-generated UUID to store
"""
db_uuid = DB_UUID()
value_to_store = db_uuid.process_bind_param(
uuid, self.sqlite_dialect
)
self.assertEqual(
value_to_store, "%.32x" % int(uuid)
)
def load_dialect_impl(self, dialect):
# IPv6 is 128 bits => 2^128 == 3.4e38 => 39 digits
return dialect.type_descriptor(types.CHAR(39))
def load_dialect_impl(self, dialect):
if dialect.name == 'sqlite':
return dialect.type_descriptor(sqlite.CHAR)
return dialect.type_descriptor(self.impl)