MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / returning_clause

Method returning_clause

lib/sqlalchemy/dialects/oracle/base.py:1473–1537  ·  view source on GitHub ↗
(
        self, stmt, returning_cols, *, populate_result_map, **kw
    )

Source from the content-addressed store, hash-verified

1471 return " " + alias_name_text
1472
1473 def returning_clause(
1474 self, stmt, returning_cols, *, populate_result_map, **kw
1475 ):
1476 columns = []
1477 binds = []
1478
1479 for i, column in enumerate(
1480 expression._select_iterables(returning_cols)
1481 ):
1482 if (
1483 self.isupdate
1484 and isinstance(column, sa_schema.Column)
1485 and isinstance(column.server_default, Computed)
1486 and not self.dialect._supports_update_returning_computed_cols
1487 ):
1488 util.warn(
1489 "Computed columns don't work with Oracle Database UPDATE "
1490 "statements that use RETURNING; the value of the column "
1491 "*before* the UPDATE takes place is returned. It is "
1492 "advised to not use RETURNING with an Oracle Database "
1493 "computed column. Consider setting implicit_returning "
1494 "to False on the Table object in order to avoid implicit "
1495 "RETURNING clauses from being generated for this Table."
1496 )
1497 if column.type._has_column_expression:
1498 col_expr = column.type.column_expression(column)
1499 else:
1500 col_expr = column
1501
1502 outparam = sql.outparam("ret_%d" % i, type_=column.type)
1503 self.binds[outparam.key] = outparam
1504 binds.append(
1505 self.bindparam_string(self._truncate_bindparam(outparam))
1506 )
1507
1508 # has_out_parameters would in a normal case be set to True
1509 # as a result of the compiler visiting an outparam() object.
1510 # in this case, the above outparam() objects are not being
1511 # visited. Ensure the statement itself didn't have other
1512 # outparam() objects independently.
1513 # technically, this could be supported, but as it would be
1514 # a very strange use case without a clear rationale, disallow it
1515 if self.has_out_parameters:
1516 raise exc.InvalidRequestError(
1517 "Using explicit outparam() objects with "
1518 "UpdateBase.returning() in the same Core DML statement "
1519 "is not supported in the Oracle Database dialects."
1520 )
1521
1522 self._oracle_returning = True
1523
1524 columns.append(self.process(col_expr, within_columns_clause=False))
1525 if populate_result_map:
1526 self._add_to_result_map(
1527 getattr(col_expr, "name", col_expr._anon_name_label),
1528 getattr(col_expr, "name", col_expr._anon_name_label),
1529 (
1530 column,

Callers

nothing calls this directly

Calls 8

_truncate_bindparamMethod · 0.80
_add_to_result_mapMethod · 0.80
warnMethod · 0.45
column_expressionMethod · 0.45
appendMethod · 0.45
bindparam_stringMethod · 0.45
processMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected