MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / __init__

Method __init__

lib/sqlalchemy/dialects/mysql/enumerated.py:122–183  ·  view source on GitHub ↗

Construct a SET. E.g.:: Column("myset", SET("foo", "bar", "baz")) The list of potential values is required in the case that this set will be used to generate DDL for a table, or if the :paramref:`.SET.retrieve_as_bitwise` flag is set to True. :pa

(self, *values: str, **kw: Any)

Source from the content-addressed store, hash-verified

120 __visit_name__ = "SET"
121
122 def __init__(self, *values: str, **kw: Any):
123 """Construct a SET.
124
125 E.g.::
126
127 Column("myset", SET("foo", "bar", "baz"))
128
129 The list of potential values is required in the case that this
130 set will be used to generate DDL for a table, or if the
131 :paramref:`.SET.retrieve_as_bitwise` flag is set to True.
132
133 :param values: The range of valid values for this SET. The values
134 are not quoted, they will be escaped and surrounded by single
135 quotes when generating the schema.
136
137 :param convert_unicode: Same flag as that of
138 :paramref:`.String.convert_unicode`.
139
140 :param collation: same as that of :paramref:`.String.collation`
141
142 :param charset: same as that of :paramref:`.VARCHAR.charset`.
143
144 :param ascii: same as that of :paramref:`.VARCHAR.ascii`.
145
146 :param unicode: same as that of :paramref:`.VARCHAR.unicode`.
147
148 :param binary: same as that of :paramref:`.VARCHAR.binary`.
149
150 :param retrieve_as_bitwise: if True, the data for the set type will be
151 persisted and selected using an integer value, where a set is coerced
152 into a bitwise mask for persistence. MySQL allows this mode which
153 has the advantage of being able to store values unambiguously,
154 such as the blank string ``''``. The datatype will appear
155 as the expression ``col + 0`` in a SELECT statement, so that the
156 value is coerced into an integer value in result sets.
157 This flag is required if one wishes
158 to persist a set that can store the blank string ``''`` as a value.
159
160 .. warning::
161
162 When using :paramref:`.mysql.SET.retrieve_as_bitwise`, it is
163 essential that the list of set values is expressed in the
164 **exact same order** as exists on the MySQL database.
165
166 """
167 self.retrieve_as_bitwise = kw.pop("retrieve_as_bitwise", False)
168 self.values = tuple(values)
169 if not self.retrieve_as_bitwise and "" in values:
170 raise exc.ArgumentError(
171 "Can't use the blank value '' in a SET without "
172 "setting retrieve_as_bitwise=True"
173 )
174 if self.retrieve_as_bitwise:
175 self._inversed_bitmap: dict[str, int] = {
176 value: 2**idx for idx, value in enumerate(self.values)
177 }
178 self._bitmap: dict[int, str] = {
179 2**idx: value for idx, value in enumerate(self.values)

Callers 1

__init__Method · 0.45

Calls 3

maxClass · 0.85
popMethod · 0.45
setdefaultMethod · 0.45

Tested by

no test coverage detected