MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _sentinel_column_characteristics

Method _sentinel_column_characteristics

lib/sqlalchemy/sql/schema.py:1216–1363  ·  view source on GitHub ↗

determine a candidate column (or columns, in case of a client generated composite primary key) which can be used as an "insert sentinel" for an INSERT statement. The returned structure, :class:`_SentinelColumnCharacterization`, includes all the details needed by :cla

(
        self,
    )

Source from the content-addressed store, hash-verified

1214
1215 @util.ro_memoized_property
1216 def _sentinel_column_characteristics(
1217 self,
1218 ) -> _SentinelColumnCharacterization:
1219 """determine a candidate column (or columns, in case of a client
1220 generated composite primary key) which can be used as an
1221 "insert sentinel" for an INSERT statement.
1222
1223 The returned structure, :class:`_SentinelColumnCharacterization`,
1224 includes all the details needed by :class:`.Dialect` and
1225 :class:`.SQLCompiler` to determine if these column(s) can be used
1226 as an INSERT..RETURNING sentinel for a particular database
1227 dialect.
1228
1229 .. versionadded:: 2.0.10
1230
1231 """
1232
1233 sentinel_is_explicit = False
1234 sentinel_is_autoinc = False
1235 the_sentinel: Optional[_typing_Sequence[Column[Any]]] = None
1236
1237 # see if a column was explicitly marked "insert_sentinel=True".
1238 explicit_sentinel_col = self._sentinel_column
1239
1240 if explicit_sentinel_col is not None:
1241 the_sentinel = (explicit_sentinel_col,)
1242 sentinel_is_explicit = True
1243
1244 autoinc_col = self._autoincrement_column
1245 if sentinel_is_explicit and explicit_sentinel_col is autoinc_col:
1246 assert autoinc_col is not None
1247 sentinel_is_autoinc = True
1248 elif explicit_sentinel_col is None and autoinc_col is not None:
1249 the_sentinel = (autoinc_col,)
1250 sentinel_is_autoinc = True
1251
1252 default_characterization = _SentinelDefaultCharacterization.UNKNOWN
1253
1254 if the_sentinel:
1255 the_sentinel_zero = the_sentinel[0]
1256 if the_sentinel_zero.identity:
1257 if the_sentinel_zero.identity._increment_is_negative:
1258 if sentinel_is_explicit:
1259 raise exc.InvalidRequestError(
1260 "Can't use IDENTITY default with negative "
1261 "increment as an explicit sentinel column"
1262 )
1263 else:
1264 if sentinel_is_autoinc:
1265 autoinc_col = None
1266 sentinel_is_autoinc = False
1267 the_sentinel = None
1268 else:
1269 default_characterization = (
1270 _SentinelDefaultCharacterization.IDENTITY
1271 )
1272 elif (
1273 the_sentinel_zero.default is None

Callers

nothing calls this directly

Calls 2

default_is_sequenceFunction · 0.85

Tested by

no test coverage detected