
    +h                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ  G d de      Z ej>                  dd       G d de             Z  ej>                  dd        G d! d"e             Z! ej>                  dd#       G d$ d%e             Z" G d& d'ejF                  eeeeeee
      Z$ G d( d)e$      Z% G d* d+e%      Z& G d, d-e'      Z( G d. d/e(e%      Z) G d0 d1e(e$      Z*y2)3zd
Provide :class:`_expression.Insert`, :class:`_expression.Update` and
:class:`_expression.Delete`.

    )NullType   )	coercions)roles)util)_entity_namespace_key)_exclusive_against)_from_objects)_generative)ColumnCollection)CompileState)DialectKWArgs)
Executable)HasCompileState)BooleanClauseList)ClauseElement)Null)HasCTE)HasPrefixes)ReturnsRows)InternalTraversal   )exc)collections_abcc                       e Zd ZdZdZdZdZdZdZdZ	dZ
dZd Zed        Zed        Zed        Zed        Zd	 Zd
 Zd Zd Zd Zd Zy)DMLStateTNFc                     t               NNotImplementedErrorself	statementcompilerkws       E/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/sql/dml.py__init__zDMLState.__init__0   s    !##    c                 H    |j                   j                  |j                   dS )N)nametable)r+   r*   )clsr#   s     r&   get_entity_descriptionzDMLState.get_entity_description3   s    !,,yGGr(   c                 p    |j                   D cg c]  }|j                  |j                  |d c}S c c}w )N)r*   typeexpr)_all_selected_columnskeyr/   )r,   r#   cs      r&   !get_returning_column_descriptionsz*DMLState.get_returning_column_descriptions7   s?     44
 	 
 	
 
s   !3c                 .    | j                   j                  S r   )r#   r+   r"   s    r&   	dml_tablezDMLState.dml_tableB   s    ~~###r(   c                     |D cg c]X  \  }}t        j                  t        j                  |      t        j                  t        j                  |t               d      fZ c}}S c c}}w )NT)type_is_crud)r   expectr   DMLColumnRoleExpressionElementRoler   )r,   r#   kv_iteratorkvs        r&   _get_crud_kv_pairszDMLState._get_crud_kv_pairsF   sd     $
 1   !4!4a8  //"* 	
 	
 
s   AA'c                 ^   g }t        t        j                  |j                              }|d   h}|j                  D ]Y  }t        |      D ]I  }|j                  |j                        s|j                  |       |j                  |j                         K [ |j                  |dd         |S )Nr   r   )listsql_utiltables_from_leftmostr+   _where_criteriar
   intersection_cloned_setappendupdateextend)r"   r#   froms
all_tablesseencrititems          r&   _make_extra_fromszDMLState._make_extra_fromsU   s    (77	HI
1-- 	.D%d+ .(()9)9:LL&D,,-.	. 	Z^$r(   c                 j   |j                   s0t        j                  d|j                  j	                         z        |j
                  D ]  }|D cg c]\  }t        |t        j                        r>t        |j                  j                  |      D ci c]  \  }}|j                  | c}}n|^ }}}}| j                  r*d| _        d| _        || _        | j                  d   | _        | j                  s| j#                          | j                  j%                  |        y c c}}w c c}}}w )Nz6%s construct does not support multiple parameter sets.FTr   )_supports_multi_parametersr   InvalidRequestError__visit_name__upper_multi_values
isinstancer   Sequencezipr+   r3   r2   _no_parameters_has_multi_parameters_multi_parameters_dict_parameters_cant_mix_formats_errorrK   )r"   r#   
parametersparameter_setr3   valuemulti_parameterss          r&   _process_multi_valueszDMLState._process_multi_valuesd   s1   33))+-6-E-E-K-K-MN 
 $11 	@J &0    " m_-E-EF %(	(9(9=$I 5 EE5L
 ##    ""&+#-1*)9&(,(>(>q(A%//,,.&&--.>?'	@ s   AD.
D(+D.
(D.
c                     | j                   r d| _        |j                  | _        d| _         y | j                  r| j	                          y y )NF)r[   r\   _valuesr^   r_   )r"   r#   s     r&   _process_valueszDMLState._process_values   sC    ).D&$-$5$5D!"'D''((* (r(   c                    |j                   }| j                  r9d| _        t        |      | _        || _         |D cg c]  \  }}|	 c}}| _        y | j
                  r| j                          y t        j                  d      c c}}w )NFzQCan only invoke ordered_values() once, and not mixed with any other values() call)	_ordered_valuesr[   dictr^   _parameter_orderingr\   r_   r   rT   )r"   r#   r`   r2   rb   s        r&   _process_ordered_valuesz DMLState._process_ordered_values   s}    ..
"'D$($4D!#-D >H'I
U'ID$''((*))/ 	 (Js   Bc                     |j                   D ci c]1  }t        j                  t        j                  |d      t               3 }}| j                  rd| _        || _        y J d       c c}w )NT)as_keyFz%This statement already has parameters)_select_namesr   r;   r   r<   r   r[   r^   )r"   r#   r*   r`   s       r&   _process_select_valueszDMLState._process_select_values   sq     "//
 U00$tDdfL

 

 "'D$.D! BAA5
s   6A)c                 ,    t        j                  d      )NzCan't mix single and multiple VALUES formats in one INSERT statement; one style appends to a list while the other replaces values, so the intent is ambiguous.)r   rT   r6   s    r&   r_   z DMLState._cant_mix_formats_error   s    %%
 	
r(   )__name__
__module____qualname__r[   r^   r]   ri   rk   r\   isupdateisdeleteisinsertr'   classmethodr-   r4   propertyr7   rA   rQ   rd   rg   rl   rp   r_    r(   r&   r   r   %   s    NO!HHH$ H H 
 
 $ $ 
 
@8+ B
r(   r   defaultinsertc                   >    e Zd ZdZdZd Zej                  d        Zy)InsertDMLStateTFc                     || _         d| _        |j                  r| j                  |       |j                  | j                  |       |j                  r| j                  |       y y NT)r#   rw   ro   rp   rf   rg   rW   rd   r!   s       r&   r'   zInsertDMLState.__init__   s]    """''	2(  +""&&y1 #r(   c                     | j                   D cg c]&  }t        j                  t        j                  |      ( c}S c c}w r   )r^   r   expect_as_keyr   r<   )r"   cols     r&   _insert_col_keyszInsertDMLState._insert_col_keys   s=    
 ,,
 ##E$7$7=
 	
 
s   +=N)	rr   rs   rt   rw   include_table_with_column_exprsr'   r   memoized_propertyr   rz   r(   r&   r~   r~      s,    H&+#	2 

 
r(   r~   rJ   c                       e Zd ZdZdZd Zy)UpdateDMLStateTFc                 |   || _         d| _        |j                  | _        |j                  | j	                  |       n;|j
                  | j                  |       n|j                  r| j                  |       | j                  |      x| _
        }|xr | j                  x| _        }|xr |j                  | _        y r   )r#   ru   _preserve_parameter_orderri   rl   rf   rg   rW   rd   rQ   _extra_fromsr^   is_multitable'render_table_with_column_in_update_fromr   )r"   r#   r$   r%   efmts         r&   r'   zUpdateDMLState.__init__   s    ")2)L)L&$$0((3*  +$$&&y1!%!7!7	!BBB"$">)>)>>RC8CC 	,r(   N)rr   rs   rt   ru   r   r'   rz   r(   r&   r   r      s    H&+#
r(   r   deletec                       e Zd ZdZd Zy)DeleteDMLStateTc                 L    || _         d| _        | j                  |      | _        y r   )r#   rv   rQ   r   r!   s       r&   r'   zDeleteDMLState.__init__   s#    " 229=r(   N)rr   rs   rt   rv   r'   rz   r(   r&   r   r      s    H>r(   r   c                   6   e Zd ZdZdZej                  j                  ddi      Z ej                         Z
dZdZdZdZdZed        Zd	 Zd
 Zed        Zd Zd Zd Z eee      Zed        Zed        Zed        Zedd       Zed        Zed        Zy)
UpdateBasezDForm the base for ``INSERT``, ``UPDATE``, and ``DELETE`` statements.update_base
autocommitTFNrz   c                     t        dddddddd	      }t        j                  di |D ci c]  }|d
||   d|z  d|z  dz  f c}S c c}w )NzThe :paramref:`%(func)s.whereclause` parameter will be removed in SQLAlchemy 2.0.  Please refer to the :meth:`%(classname)s.where` method.zThe :paramref:`%(func)s.values` parameter will be removed in SQLAlchemy 2.0.  Please refer to the :meth:`%(classname)s.values` method.zuThe :paramref:`%(func)s.bind` parameter will be removed in SQLAlchemy 2.0.  Please use explicit connection execution.zThe :paramref:`%(func)s.inline` parameter will be removed in SQLAlchemy 2.0.  Please use the :meth:`%(classname)s.inline` method.zThe :paramref:`%(func)s.prefixes parameter will be removed in SQLAlchemy 2.0.  Please use the :meth:`%(classname)s.prefix_with` method.zThe :paramref:`%(func)s.return_defaults` parameter will be removed in SQLAlchemy 2.0.  Please use the :meth:`%(classname)s.return_defaults` method.zThe :paramref:`%(func)s.returning` parameter will be removed in SQLAlchemy 2.0.  Please use the :meth:`%(classname)s.returning`` method.zThe :paramref:`%(func)s.preserve_parameter_order` parameter will be removed in SQLAlchemy 2.0.   Use the :meth:`%(classname)s.ordered_values` method with a list of tuples. )whereclausevaluesbindinlineprefixesreturn_defaults	returningpreserve_parameter_orderz2.0z_expression.%s)func	classnamerz   )rj   r   deprecated_params)r,   fn_nameclsnamenamesparam_to_method_lookupr*   s         r&   _constructor_20_deprecationsz'UpdateBase._constructor_20_deprecations  s     "&67
M7@
;
Q-"
^ %% 
 "
  *40 07 :%5%? 

 	

s   A	c                 b    j                   j                  fd| j                  D               y )Nc              3   @   K   | ]  }|j                          y wr   )_make_proxy).0r   
fromclauses     r&   	<genexpr>zAUpdateBase._generate_fromclause_column_proxies.<locals>.<genexpr>F  s      4
,/COOJ'4
s   )_columns_populate_separate_keys
_returning)r"   r   s    `r&   #_generate_fromclause_column_proxiesz.UpdateBase._generate_fromclause_column_proxiesE  s(    33 4
37??4
 	
r(   c                     t        d      )zSet the parameters for the statement.

        This method raises ``NotImplementedError`` on the base class,
        and is overridden by :class:`.ValuesBase` to provide the
        SET/VALUES clause of UPDATE and INSERT.

        zparams() is not supported for INSERT/UPDATE/DELETE statements. To set the values for an INSERT or UPDATE statement, use stmt.values(**parameters).r   )r"   argr%   s      r&   paramszUpdateBase.paramsJ  s     "*
 	
r(   c                 &    | j                  |       y)a  Add dialect options to this INSERT/UPDATE/DELETE object.

        e.g.::

            upd = table.update().dialect_options(mysql_limit=10)

        .. versionadded: 1.4 - this method supersedes the dialect options
           associated with the constructor.


        N)_validate_dialect_kwargs)r"   opts     r&   with_dialect_optionszUpdateBase.with_dialect_optionsX  s     	%%c*r(   c                 ~    t        j                  d| j                  j                  z         | j	                  |       y )NzPassing dialect keyword arguments directly to the %s constructor is deprecated and will be removed in SQLAlchemy 2.0.  Please use the ``with_dialect_options()`` method.)r   warn_deprecated_20	__class__rr   r   )r"   
dialect_kws     r&   #_validate_dialect_kwargs_deprecatedz.UpdateBase._validate_dialect_kwargs_deprecatedg  s:    F ~~&&(	
 	%%j1r(   c                 J    | j                   xs | j                  j                  S )zuReturn a 'bind' linked to this :class:`.UpdateBase`
        or a :class:`_schema.Table` associated with it.

        )_bindr+   r   r6   s    r&   r   zUpdateBase.bindp  s    
 zz,TZZ__,r(   c                     || _         y r   )r   )r"   r   s     r&   	_set_bindzUpdateBase._set_bindw  s	    
r(   c                     | j                   rt        j                  d      | xj                  t	        d |D              z  c_        y)a  Add a :term:`RETURNING` or equivalent clause to this statement.

        e.g.:

        .. sourcecode:: pycon+sql

            >>> stmt = (
            ...     table.update()
            ...     .where(table.c.data == "value")
            ...     .values(status="X")
            ...     .returning(table.c.server_flag, table.c.updated_timestamp)
            ... )
            >>> print(stmt)
            UPDATE some_table SET status=:status
            WHERE some_table.data = :data_1
            RETURNING some_table.server_flag, some_table.updated_timestamp

        The method may be invoked multiple times to add new entries to the
        list of expressions to be returned.

        .. versionadded:: 1.4.0b2 The method may be invoked multiple times to
         add new entries to the list of expressions to be returned.

        The given collection of column expressions should be derived from the
        table that is the target of the INSERT, UPDATE, or DELETE.  While
        :class:`_schema.Column` objects are typical, the elements can also be
        expressions:

        .. sourcecode:: pycon+sql

            >>> stmt = table.insert().returning(
            ...     (table.c.first_name + " " + table.c.last_name).label("fullname")
            ... )
            >>> print(stmt)
            INSERT INTO some_table (first_name, last_name)
            VALUES (:first_name, :last_name)
            RETURNING some_table.first_name || :first_name_1 || some_table.last_name AS fullname

        Upon compilation, a RETURNING clause, or database equivalent,
        will be rendered within the statement.   For INSERT and UPDATE,
        the values are the newly inserted/updated values.  For DELETE,
        the values are those of the rows which were deleted.

        Upon execution, the values of the columns to be returned are made
        available via the result set and can be iterated using
        :meth:`_engine.CursorResult.fetchone` and similar.
        For DBAPIs which do not
        natively support returning values (i.e. cx_oracle), SQLAlchemy will
        approximate this behavior at the result level so that a reasonable
        amount of behavioral neutrality is provided.

        Note that not all databases/DBAPIs
        support RETURNING.   For those backends with no support,
        an exception is raised upon compilation and/or execution.
        For those who do support it, the functionality across backends
        varies greatly, including restrictions on executemany()
        and other statements which return multiple rows. Please
        read the documentation notes for the database in use in
        order to determine the availability of RETURNING.

        .. seealso::

          :meth:`.ValuesBase.return_defaults` - an alternative method tailored
          towards efficient fetching of server-side defaults and triggers
          for single-row INSERTs or UPDATEs.

          :ref:`tutorial_insert_returning` - in the :ref:`unified_tutorial`

        z9return_defaults() is already configured on this statementc              3   d   K   | ](  }t        j                  t        j                  |       * y wr   )r   r;   r   ColumnsClauseRoler   r3   s     r&   r   z'UpdateBase.returning.<locals>.<genexpr>  s(      !
=>IU44a8!
s   .0N)_return_defaultsr   rT   r   tupler"   colss     r&   r   zUpdateBase.returning|  sH    N   ))K  	5 !
BF!
 
 	
r(   c                     | j                   S r   )r   r6   s    r&   r1   z UpdateBase._all_selected_columns  s    r(   c                 V    t        d | j                  D              j                         S )zxReturn the RETURNING columns as a column collection for this
        statement.

        .. versionadded:: 1.4

        c              3   8   K   | ]  }|j                   |f  y wr   )r2   r   s     r&   r   z.UpdateBase.exported_columns.<locals>.<genexpr>  s       
QUUAJ 
s   )r   r1   as_immutabler6   s    r&   exported_columnszUpdateBase.exported_columns  s+        
 $ : : 
 

,.	r(   c                 h    || j                   }| j                  j                  ||f|i      | _        y)a  Add a table hint for a single table to this
        INSERT/UPDATE/DELETE statement.

        .. note::

         :meth:`.UpdateBase.with_hint` currently applies only to
         Microsoft SQL Server.  For MySQL INSERT/UPDATE/DELETE hints, use
         :meth:`.UpdateBase.prefix_with`.

        The text of the hint is rendered in the appropriate
        location for the database backend in use, relative
        to the :class:`_schema.Table` that is the subject of this
        statement, or optionally to that of the given
        :class:`_schema.Table` passed as the ``selectable`` argument.

        The ``dialect_name`` option will limit the rendering of a particular
        hint to a particular backend. Such as, to add a hint
        that only takes effect for SQL Server::

            mytable.insert().with_hint("WITH (PAGLOCK)", dialect_name="mssql")

        :param text: Text of the hint.
        :param selectable: optional :class:`_schema.Table` that specifies
         an element of the FROM clause within an UPDATE or DELETE
         to be the subject of the hint - applies only to certain backends.
        :param dialect_name: defaults to ``*``, if specified as the name
         of a particular dialect, will apply these hints only when
         that dialect is in use.
        N)r+   _hintsunion)r"   text
selectabledialect_names       r&   	with_hintzUpdateBase.with_hint  s3    > Jkk''*l)CT(JKr(   c                 P    t         j                  |       j                  } ||       S )a=  Return a :term:`plugin-enabled` description of the table and/or
        entity which this DML construct is operating against.

        This attribute is generally useful when using the ORM, as an
        extended structure which includes information about mapped
        entities is returned.  The section :ref:`queryguide_inspection`
        contains more background.

        For a Core statement, the structure returned by this accessor
        is derived from the :attr:`.UpdateBase.table` attribute, and
        refers to the :class:`.Table` being inserted, updated, or deleted::

            >>> stmt = insert(user_table)
            >>> stmt.entity_description
            {
                "name": "user_table",
                "table": Table("user_table", ...)
            }

        .. versionadded:: 1.4.33

        .. seealso::

            :attr:`.UpdateBase.returning_column_descriptions`

            :attr:`.Select.column_descriptions` - entity information for
            a :func:`.select` construct

            :ref:`queryguide_inspection` - ORM background

        )r   get_plugin_classr-   r"   meths     r&   entity_descriptionzUpdateBase.entity_description   s%    B ((.EEDzr(   c                 P    t         j                  |       j                  } ||       S )a  Return a :term:`plugin-enabled` description of the columns
        which this DML construct is RETURNING against, in other words
        the expressions established as part of :meth:`.UpdateBase.returning`.

        This attribute is generally useful when using the ORM, as an
        extended structure which includes information about mapped
        entities is returned.  The section :ref:`queryguide_inspection`
        contains more background.

        For a Core statement, the structure returned by this accessor is
        derived from the same objects that are returned by the
        :attr:`.UpdateBase.exported_columns` accessor::

            >>> stmt = insert(user_table).returning(user_table.c.id, user_table.c.name)
            >>> stmt.entity_description
            [
                {
                    "name": "id",
                    "type": Integer,
                    "expr": Column("id", Integer(), table=<user>, ...)
                },
                {
                    "name": "name",
                    "type": String(),
                    "expr": Column("name", String(), table=<user>, ...)
                },
            ]

        .. versionadded:: 1.4.33

        .. seealso::

            :attr:`.UpdateBase.entity_description`

            :attr:`.Select.column_descriptions` - entity information for
            a :func:`.select` construct

            :ref:`queryguide_inspection` - ORM background

        )r   r   r4   r   s     r&   returning_column_descriptionsz(UpdateBase.returning_column_descriptions$  s-    T ((

+
+ 	 Dzr(   )N*) rr   rs   rt   __doc__rU   r   _execution_optionsr   r   immutabledictr   named_with_columnr   _return_defaults_columnsr   is_dmlrx   r   r   r   r   r   r   r   r   ry   r   r1   r   r   r   r   rz   r(   r&   r   r      s%    O"N#66<<	t  T!F#JF=
 =
~


 + +2- D)$DL
 L
\   
 
 !L !LF ! !F , ,r(   r   c                       e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZd Ze eddd	d
d      d               Ze edddidei      d               Zy)
ValuesBasezTSupplies support for :meth:`.ValuesBase.values` to
    INSERT and UPDATE constructs.values_baseFNrz   c                     t        j                  t        j                  ||       | _        || j
                  j                  | |       |r| j                  |       y y )Napply_propagate_attrs)r   r;   r   DMLTableRoler+   r   non_generative_setup_prefixes)r"   r+   r   r   s       r&   r'   zValuesBase.__init__f  sS    %%T

 KK&&tV4  * r(   ro   ri   z,This construct already inserts from a SELECT1This statement already has ordered values present)ro   ri   )msgsc                    |r|d   }|rt        j                  d      t        |      dkD  rt        j                  d      | j                  st	        |t
        j                        ru|r5t	        |d   t        t        t        f      r| xj                  |fz  c_
        yt        | j                  j                  |      D ci c]  \  }}|j                  | }}}nJ| j                  r>t	        |t
        j                        s$t        d      |}|rt        j                  d      t         j#                  |       j$                  }| j                  r || |      | _        y || |j)                               D ci c]  \  }}||
 }}}| j*                  r!| j*                  j-                  |      | _        yt/        j0                  |      | _        yc c}}w c c}}w )a  Specify a fixed VALUES clause for an INSERT statement, or the SET
        clause for an UPDATE.

        Note that the :class:`_expression.Insert` and
        :class:`_expression.Update`
        constructs support
        per-execution time formatting of the VALUES and/or SET clauses,
        based on the arguments passed to :meth:`_engine.Connection.execute`.
        However, the :meth:`.ValuesBase.values` method can be used to "fix" a
        particular set of parameters into the statement.

        Multiple calls to :meth:`.ValuesBase.values` will produce a new
        construct, each one with the parameter list modified to include
        the new parameters sent.  In the typical case of a single
        dictionary of parameters, the newly passed keys will replace
        the same keys in the previous construct.  In the case of a list-based
        "multiple values" construct, each new list of values is extended
        onto the existing list of values.

        :param \**kwargs: key value pairs representing the string key
          of a :class:`_schema.Column`
          mapped to the value to be rendered into the
          VALUES or SET clause::

                users.insert().values(name="some name")

                users.update().where(users.c.id==5).values(name="some name")

        :param \*args: As an alternative to passing key/value parameters,
         a dictionary, tuple, or list of dictionaries or tuples can be passed
         as a single positional argument in order to form the VALUES or
         SET clause of the statement.  The forms that are accepted vary
         based on whether this is an :class:`_expression.Insert` or an
         :class:`_expression.Update` construct.

         For either an :class:`_expression.Insert` or
         :class:`_expression.Update`
         construct, a single dictionary can be passed, which works the same as
         that of the kwargs form::

            users.insert().values({"name": "some name"})

            users.update().values({"name": "some new name"})

         Also for either form but more typically for the
         :class:`_expression.Insert` construct, a tuple that contains an
         entry for every column in the table is also accepted::

            users.insert().values((5, "some name"))

         The :class:`_expression.Insert` construct also supports being
         passed a list of dictionaries or full-table-tuples, which on the
         server will render the less common SQL syntax of "multiple values" -
         this syntax is supported on backends such as SQLite, PostgreSQL,
         MySQL, but not necessarily others::

            users.insert().values([
                                {"name": "some name"},
                                {"name": "some other name"},
                                {"name": "yet another name"},
                            ])

         The above form would render a multiple VALUES statement similar to::

                INSERT INTO users (name) VALUES
                                (:name_1),
                                (:name_2),
                                (:name_3)

         It is essential to note that **passing multiple values is
         NOT the same as using traditional executemany() form**.  The above
         syntax is a **special** syntax not typically used.  To emit an
         INSERT statement against multiple rows, the normal method is
         to pass a multiple values list to the
         :meth:`_engine.Connection.execute`
         method, which is supported by all database backends and is generally
         more efficient for a very large number of parameters.

           .. seealso::

               :ref:`tutorial_multiple_parameters` - an introduction to
               the traditional Core method of multiple parameter set
               invocation for INSERTs and other statements.

           .. versionchanged:: 1.0.0 an INSERT that uses a multiple-VALUES
              clause, even a list of length one,
              implies that the :paramref:`_expression.Insert.inline`
              flag is set to
              True, indicating that the statement will not attempt to fetch
              the "last inserted primary key" or other defaults.  The
              statement deals with an arbitrary number of rows, so the
              :attr:`_engine.CursorResult.inserted_primary_key`
              accessor does not
              apply.

           .. versionchanged:: 1.0.0 A multiple-VALUES INSERT now supports
              columns with Python side default values and callables in the
              same way as that of an "executemany" style of invocation; the
              callable is invoked for each row.   See :ref:`bug_3288`
              for other details.

          The UPDATE construct also supports rendering the SET parameters
          in a specific order.  For this feature refer to the
          :meth:`_expression.Update.ordered_values` method.

           .. seealso::

              :meth:`_expression.Update.ordered_values`


        r   z;Can't pass positional and kwargs to values() simultaneouslyr   zWOnly a single dictionary/tuple or list of dictionaries/tuples is accepted positionally.NzOWhen preserve_parameter_order is True, values() only accepts a list of 2-tuples)r   ArgumentErrorlenr   rX   r   rY   rC   rj   r   rW   rZ   r+   r3   r2   
ValueErrorr   r   rA   ri   itemsrf   r   r   r   )	r"   argskwargsr   r3   rb   kv_generatorr?   r@   s	            r&   r   zValuesBase.valueso  s   t  q'C''%  TQ''D 
 33
_--9 :c!ftT5.AB&&3&0& 58

c4JK5quue|KK//
_--9 !?  C''D   006II))#/c#:D $0syy{$CDDAq1a4DCD||#||11#6#11#6E L< Es   G<Gr   z1RETURNING is already configured on this statement)r   defaultsc                      d| _         || _        y)a  Make use of a :term:`RETURNING` clause for the purpose
        of fetching server-side expressions and defaults.

        E.g.::

            stmt = table.insert().values(data='newdata').return_defaults()

            result = connection.execute(stmt)

            server_created_at = result.returned_defaults['created_at']

        When used against a backend that supports RETURNING, all column
        values generated by SQL expression or server-side-default will be
        added to any existing RETURNING clause, provided that
        :meth:`.UpdateBase.returning` is not used simultaneously.  The column
        values will then be available on the result using the
        :attr:`_engine.CursorResult.returned_defaults` accessor as
        a dictionary,
        referring to values keyed to the :class:`_schema.Column`
        object as well as
        its ``.key``.

        This method differs from :meth:`.UpdateBase.returning` in these ways:

        1. :meth:`.ValuesBase.return_defaults` is only intended for use with an
           INSERT or an UPDATE statement that matches exactly one row per
           parameter set. While the RETURNING construct in the general sense
           supports multiple rows for a multi-row UPDATE or DELETE statement,
           or for special cases of INSERT that return multiple rows (e.g.
           INSERT from SELECT, multi-valued VALUES clause),
           :meth:`.ValuesBase.return_defaults` is intended only for an
           "ORM-style" single-row INSERT/UPDATE statement.  The row
           returned by the statement is also consumed implicitly when
           :meth:`.ValuesBase.return_defaults` is used.  By contrast,
           :meth:`.UpdateBase.returning` leaves the RETURNING result-set intact
           with a collection of any number of rows.

        2. It is compatible with the existing logic to fetch auto-generated
           primary key values, also known as "implicit returning".  Backends
           that support RETURNING will automatically make use of RETURNING in
           order to fetch the value of newly generated primary keys; while the
           :meth:`.UpdateBase.returning` method circumvents this behavior,
           :meth:`.ValuesBase.return_defaults` leaves it intact.

        3. It can be called against any backend.  Backends that don't support
           RETURNING will skip the usage of the feature, rather than raising
           an exception.  The return value of
           :attr:`_engine.CursorResult.returned_defaults` will be ``None``

        4. An INSERT statement invoked with executemany() is supported if the
           backend database driver supports the
           ``insert_executemany_returning`` feature, currently this includes
           PostgreSQL with psycopg2.  When executemany is used, the
           :attr:`_engine.CursorResult.returned_defaults_rows` and
           :attr:`_engine.CursorResult.inserted_primary_key_rows` accessors
           will return the inserted defaults and primary keys.

           .. versionadded:: 1.4

        :meth:`.ValuesBase.return_defaults` is used by the ORM to provide
        an efficient implementation for the ``eager_defaults`` feature of
        :func:`.mapper`.

        :param cols: optional list of column key names or
         :class:`_schema.Column`
         objects.  If omitted, all column expressions evaluated on the server
         are added to the returning list.

        .. versionadded:: 0.9.0

        .. seealso::

            :meth:`.UpdateBase.returning`

            :attr:`_engine.CursorResult.returned_defaults`

            :attr:`_engine.CursorResult.returned_defaults_rows`

            :attr:`_engine.CursorResult.inserted_primary_key`

            :attr:`_engine.CursorResult.inserted_primary_key_rows`

        TN)r   r   r   s     r&   r   zValuesBase.return_defaults)  s    x !%(,%r(   )rr   rs   rt   r   rU   rS   r   select_post_values_clauserf   rW   ri   ro   r   r'   r   r	   r   r   rz   r(   r&   r   r   T  s    % #N!& %FGMOMJ+ K 
n7 n7` M
 
+U- U-r(   r   c                        e Zd ZdZdZdZdZdZdZde	j                  fde	j                  fde	j                  fd	e	j                  fd
e	j                  fde	j                  fde	j                  fde	j                  fde	j                   fde	j                  fde	j                  fgej$                  z   ej(                  z   ej,                  z   ej0                  z   Zej7                  dd g d      	 	 	 	 	 	 d fd	       Zed        Zedd       Z xZ S )InsertzRepresent an INSERT construct.

    The :class:`_expression.Insert` object is created using the
    :func:`_expression.insert()` function.

    r|   TNFr+   _inlinero   rf   rW   r   r   r   r   r   r   )r   r   r   r   r   r   c                     t         t        |   |||       || _        || _        |r|| _        |r| j                  |       |r d| _        t        |t              s|| _
        yyy)a  Construct an :class:`_expression.Insert` object.

        E.g.::

            from sqlalchemy import insert

            stmt = (
                insert(user_table).
                values(name='username', fullname='Full Username')
            )

        Similar functionality is available via the
        :meth:`_expression.TableClause.insert` method on
        :class:`_schema.Table`.

        .. seealso::

            :ref:`tutorial_core_insert` - in the :ref:`unified_tutorial`


        :param table: :class:`_expression.TableClause`
         which is the subject of the
         insert.

        :param values: collection of values to be inserted; see
         :meth:`_expression.Insert.values`
         for a description of allowed formats here.
         Can be omitted entirely; a :class:`_expression.Insert` construct
         will also dynamically render the VALUES clause at execution time
         based on the parameters passed to :meth:`_engine.Connection.execute`.

        :param inline: if True, no attempt will be made to retrieve the
         SQL-generated default values to be provided within the statement;
         in particular,
         this allows SQL expressions to be rendered 'inline' within the
         statement without the need to pre-execute them beforehand; for
         backends that support "returning", this turns off the "implicit
         returning" feature for the statement.

        If both :paramref:`_expression.Insert.values` and compile-time bind
        parameters are present, the compile-time bind parameters override the
        information specified within :paramref:`_expression.Insert.values` on a
        per-key basis.

        The keys within :paramref:`_expression.Insert.values` can be either
        :class:`~sqlalchemy.schema.Column` objects or their string
        identifiers. Each key may reference one of:

        * a literal data value (i.e. string, number, etc.);
        * a Column object;
        * a SELECT statement.

        If a ``SELECT`` statement is specified which references this
        ``INSERT`` statement's table, the statement will be correlated
        against the ``INSERT`` statement.

        .. seealso::

            :ref:`tutorial_core_insert` - in the :ref:`unified_tutorial`

        TN)superr   r'   r   r   r   r   r   rX   boolr   )
r"   r+   r   r   r   r   r   r   r   r   s
            r&   r'   zInsert.__init__  si    h 	fd$UFH=
'DO44Z@$(D!ot40?- 5 r(   c                     d| _         y)a  Make this :class:`_expression.Insert` construct "inline" .

        When set, no attempt will be made to retrieve the
        SQL-generated default values to be provided within the statement;
        in particular,
        this allows SQL expressions to be rendered 'inline' within the
        statement without the need to pre-execute them beforehand; for
        backends that support "returning", this turns off the "implicit
        returning" feature for the statement.


        .. versionchanged:: 1.4 the :paramref:`_expression.Insert.inline`
           parameter
           is now superseded by the :meth:`_expression.Insert.inline` method.

        TNr   r6   s    r&   r   zInsert.inline  s    $ r(   c                     | j                   rt        j                  d      || _        d| _        || _        t        j                  t        j                  |      | _
        y)a	  Return a new :class:`_expression.Insert` construct which represents
        an ``INSERT...FROM SELECT`` statement.

        e.g.::

            sel = select(table1.c.a, table1.c.b).where(table1.c.c > 5)
            ins = table2.insert().from_select(['a', 'b'], sel)

        :param names: a sequence of string column names or
         :class:`_schema.Column`
         objects representing the target columns.
        :param select: a :func:`_expression.select` construct,
         :class:`_expression.FromClause`
         or other construct which resolves into a
         :class:`_expression.FromClause`,
         such as an ORM :class:`_query.Query` object, etc.  The order of
         columns returned from this FROM clause should correspond to the
         order of columns sent as the ``names`` parameter;  while this
         is not checked before passing along to the database, the database
         would normally raise an exception if these column lists don't
         correspond.
        :param include_defaults: if True, non-server default values and
         SQL expressions as specified on :class:`_schema.Column` objects
         (as documented in :ref:`metadata_defaults_toplevel`) not
         otherwise specified in the list of names will be rendered
         into the INSERT and SELECT statements, so that these values are also
         included in the data to be inserted.

         .. note:: A Python-side default that uses a Python callable function
            will only be invoked **once** for the whole statement, and **not
            per row**.

         .. versionadded:: 1.0.0 - :meth:`_expression.Insert.from_select`
            now renders
            Python-side and SQL expression column defaults into the
            SELECT statement for columns otherwise not included in the
            list of column names.

        .. versionchanged:: 1.0.0 an INSERT that uses FROM SELECT
           implies that the :paramref:`_expression.insert.inline`
           flag is set to
           True, indicating that the statement will not attempt to fetch
           the "last inserted primary key" or other defaults.  The statement
           deals with an arbitrary number of rows, so the
           :attr:`_engine.CursorResult.inserted_primary_key`
           accessor does not apply.

        z0This construct already inserts value expressionsTN)rf   r   rT   ro   r   #include_insert_from_select_defaultsr   r;   r   DMLSelectRoler   )r"   r   r   include_defaultss       r&   from_selectzInsert.from_select&  sU    f <<))B  #3C0&&u':':FCr(   )NFNNNF)T)!rr   rs   rt   r   rU   rS   r   r  	is_insertr   dp_clauseelement
dp_booleandp_string_listdp_dml_valuesdp_dml_multi_valuesdp_clauseelement_tupledp_table_hint_listr    _has_prefixes_traverse_internalsr   "_dialect_kwargs_traverse_internalsr   _executable_traverse_internalsr   _has_ctes_traverse_internals_traverse_internalsr   r   r'   r   r   r  __classcell__r   s   @r&   r   r     s    N!%F*/'I '889)445/>>?)778/CCD(99:"$5$F$FG,CCD(;;<!2!=!=>*!88	
  
6
6!	7" 
:
:#	;$ 
3
3%	4& 
-
-'	. . ,,	
 S@S@j  & :D :Dr(   r   c                   B    e Zd ZdZed        Zd Zd Zd Ze	d        Z
y)DMLWhereBaserz   c                     |D ]<  }t        j                  t        j                  |      }| xj                  |fz  c_        > y)a  Return a new construct with the given expression(s) added to
        its WHERE clause, joined to the existing clause via AND, if any.

        Both :meth:`_dml.Update.where` and :meth:`_dml.Delete.where`
        support multiple-table forms, including database-specific
        ``UPDATE...FROM`` as well as ``DELETE..USING``.  For backends that
        don't have multiple-table support, a backend agnostic approach
        to using multiple tables is to make use of correlated subqueries.
        See the linked tutorial sections below for examples.

        .. seealso::

            :ref:`tutorial_correlated_updates`

            :ref:`tutorial_update_from`

            :ref:`tutorial_multi_table_deletes`

        N)r   r;   r   WhereHavingRolerF   )r"   r   	criterionwhere_criterias       r&   wherezDMLWhereBase.whereg  s?    , % 	6I&--e.C.CYON  ^$55 	6r(   c                       | j                   | S )zbA synonym for the :meth:`_dml.DMLWhereBase.where` method.

        .. versionadded:: 1.4

        )r  )r"   criterias     r&   filterzDMLWhereBase.filter  s     tzz8$$r(   c                     | j                   S r   )r+   r6   s    r&   _filter_by_zerozDMLWhereBase._filter_by_zero  s    zzr(   c                     | j                         }|j                         D cg c]  \  }}t        ||      |k(   }}} | j                  | S c c}}w )zWapply the given filtering criterion as a WHERE clause
        to this select.

        )r#  r   r   r!  )r"   r   from_entityr2   rb   clausess         r&   	filter_byzDMLWhereBase.filter_by  s_    
 **, %lln
U "+s3u<
 
 t{{G$$	
s   Ac                 @    t        j                  | j                        S )a  Return the completed WHERE clause for this :class:`.DMLWhereBase`
        statement.

        This assembles the current collection of WHERE criteria
        into a single :class:`_expression.BooleanClauseList` construct.


        .. versionadded:: 1.4

        )r   _construct_for_whereclauserF   r6   s    r&   r   zDMLWhereBase.whereclause  s      !;;  
 	
r(   N)rr   rs   rt   rF   r   r  r!  r#  r'  ry   r   rz   r(   r&   r  r  d  s<    O6 62%% 
 
r(   r  c            
           e Zd ZdZdZdZdej                  fdej                  fdej                  fdej                  fdej                  fd	ej                  fd
ej                  fdej                  fdej                  fg	ej                  z   ej                   z   ej$                  z   ej(                  z   Zej/                  dd g d      	 	 	 	 	 	 	 	 d fd	       Zed        Zed        Z xZS )UpdatezRepresent an Update construct.

    The :class:`_expression.Update` object is created using the
    :func:`_expression.update()` function.

    rJ   Tr+   rF   r   ri   rf   r   r   r   r   )r   r   r   r   r   r   r   r   c
                    |	| _         t        t        |   |||       || _        |r|| _        |8| xj                  t        j                  t        j                  |      fz  c_        || _        |
r| j                  |
       || _        y)a  Construct an :class:`_expression.Update` object.

        E.g.::

            from sqlalchemy import update

            stmt = (
                update(user_table).
                where(user_table.c.id == 5).
                values(name='user #5')
            )

        Similar functionality is available via the
        :meth:`_expression.TableClause.update` method on
        :class:`_schema.Table`.

        :param table: A :class:`_schema.Table`
         object representing the database
         table to be updated.

        :param whereclause: Optional SQL expression describing the ``WHERE``
         condition of the ``UPDATE`` statement; is equivalent to using the
         more modern :meth:`~Update.where()` method to specify the ``WHERE``
         clause.

        :param values:
          Optional dictionary which specifies the ``SET`` conditions of the
          ``UPDATE``.  If left as ``None``, the ``SET``
          conditions are determined from those parameters passed to the
          statement during the execution and/or compilation of the
          statement.   When compiled standalone without any parameters,
          the ``SET`` clause generates for all columns.

          Modern applications may prefer to use the generative
          :meth:`_expression.Update.values` method to set the values of the
          UPDATE statement.

        :param inline:
          if True, SQL defaults present on :class:`_schema.Column` objects via
          the ``default`` keyword will be compiled 'inline' into the statement
          and not pre-executed.  This means that their values will not
          be available in the dictionary returned from
          :meth:`_engine.CursorResult.last_updated_params`.

        :param preserve_parameter_order: if True, the update statement is
          expected to receive parameters **only** via the
          :meth:`_expression.Update.values` method,
          and they must be passed as a Python
          ``list`` of 2-tuples. The rendered UPDATE statement will emit the SET
          clause for each referenced column maintaining this order.

          .. versionadded:: 1.0.10

          .. seealso::

            :ref:`updates_order_parameters` - illustrates the
            :meth:`_expression.Update.ordered_values` method.

        If both ``values`` and compile-time bind parameters are present, the
        compile-time bind parameters override the information specified
        within ``values`` on a per-key basis.

        The keys within ``values`` can be either :class:`_schema.Column`
        objects or their string identifiers (specifically the "key" of the
        :class:`_schema.Column`, normally but not necessarily equivalent to
        its "name").  Normally, the
        :class:`_schema.Column` objects used here are expected to be
        part of the target :class:`_schema.Table` that is the table
        to be updated.  However when using MySQL, a multiple-table
        UPDATE statement can refer to columns from any of
        the tables referred to in the WHERE clause.

        The values referred to in ``values`` are typically:

        * a literal data value (i.e. string, number, etc.)
        * a SQL expression, such as a related :class:`_schema.Column`,
          a scalar-returning :func:`_expression.select` construct,
          etc.

        When combining :func:`_expression.select` constructs within the
        values clause of an :func:`_expression.update`
        construct, the subquery represented
        by the :func:`_expression.select` should be *correlated* to the
        parent table, that is, providing criterion which links the table inside
        the subquery to the outer table being updated::

            users.update().values(
                    name=select(addresses.c.email_address).\
                            where(addresses.c.user_id==users.c.id).\
                            scalar_subquery()
                )

        .. seealso::

            :ref:`inserts_and_updates` - SQL Expression
            Language Tutorial


        N)r   r   r+  r'   r   r   rF   r   r;   r   r  r   r   r   )r"   r+   r   r   r   r   r   r   r   r   r   r   s              r&   r'   zUpdate.__init__  s    | *B&fd$UFH=
'DO"    !6!6D%   44Z@ /r(   c                     | j                   rt        j                  d      | j                  rt        j                  d      t        j                  |       j                  } || |      | _        y)a  Specify the VALUES clause of this UPDATE statement with an explicit
        parameter ordering that will be maintained in the SET clause of the
        resulting UPDATE statement.

        E.g.::

            stmt = table.update().ordered_values(
                ("name", "ed"), ("ident": "foo")
            )

        .. seealso::

           :ref:`tutorial_parameter_ordered_updates` - full example of the
           :meth:`_expression.Update.ordered_values` method.

        .. versionchanged:: 1.4 The :meth:`_expression.Update.ordered_values`
           method
           supersedes the
           :paramref:`_expression.update.preserve_parameter_order`
           parameter, which will be removed in SQLAlchemy 2.0.

        z)This statement already has values presentr   N)rf   r   r   ri   r   r   rA   )r"   r   r   s      r&   ordered_valueszUpdate.ordered_valuesY  si    0 <<##;  !!##C   006II+D$7r(   c                     d| _         y)aJ  Make this :class:`_expression.Update` construct "inline" .

        When set, SQL defaults present on :class:`_schema.Column`
        objects via the
        ``default`` keyword will be compiled 'inline' into the statement and
        not pre-executed.  This means that their values will not be available
        in the dictionary returned from
        :meth:`_engine.CursorResult.last_updated_params`.

        .. versionchanged:: 1.4 the :paramref:`_expression.update.inline`
           parameter
           is now superseded by the :meth:`_expression.Update.inline` method.

        TNr  r6   s    r&   r   zUpdate.inline}  s      r(   )NNFNNNFF)rr   rs   rt   r   rU   	is_updater   r
  r  r  dp_dml_ordered_valuesr  r  r   r  r   r  r   r  r   r  r  r   r   r'   r   r.  r   r  r  s   @r&   r+  r+    sY    NI '889 1 H HI)445 1 G GH)778,CCD(;;<!2!=!=>*!88	
 
6
6	7 
:
:	;  
3
3!	4" 
-
-#	. * ,,		
" !&|0|0| !8 !8F  r(   r+  c                   ,   e Zd ZdZdZdZdej                  fdej                  fdej                  fdej                  fge
j                  z   ej                  z   ej                  z   ej"                  z   Zej)                  dd g d      	 	 	 	 dd
       Zy	)DeletezRepresent a DELETE construct.

    The :class:`_expression.Delete` object is created using the
    :func:`_expression.delete()` function.

    r   Tr+   rF   r   r   )r   r   r   r   r   Nc                 <   || _         t        j                  t        j                  ||       | _        |r|| _        |r| j                  |       |8| xj                  t        j                  t        j                  |      fz  c_        |r| j                  |       yy)a  Construct :class:`_expression.Delete` object.

        E.g.::

            from sqlalchemy import delete

            stmt = (
                delete(user_table).
                where(user_table.c.id == 5)
            )

        Similar functionality is available via the
        :meth:`_expression.TableClause.delete` method on
        :class:`_schema.Table`.

        .. seealso::

            :ref:`inserts_and_updates` - in the
            :ref:`1.x tutorial <sqlexpression_toplevel>`

            :ref:`tutorial_core_update_delete` - in the :ref:`unified_tutorial`


        :param table: The table to delete rows from.

        :param whereclause: Optional SQL expression describing the ``WHERE``
         condition of the ``DELETE`` statement; is equivalent to using the
         more modern :meth:`~Delete.where()` method to specify the ``WHERE``
         clause.

        .. seealso::

            :ref:`deletes` - SQL Expression Tutorial

        r   N)r   r   r;   r   r   r+   r   r   rF   r  r   )r"   r+   r   r   r   r   r   s          r&   r'   zDelete.__init__  s    b 
%%T

 'DO  *"    !6!6D%   44Z@ r(   )NNNN)rr   rs   rt   r   rU   	is_deleter   r
  r  r  r   r  r   r  r   r  r   r  r  r   r   r'   rz   r(   r&   r3  r3    s     NI '889 1 H HI,CCD(;;<		
 
6
6	7 
:
:	; 
3
3	4 
-
-		.  ,,B <A
<Ar(   r3  N)+r   sqlalchemy.typesr    r   r   r   rD   baser   r	   r
   r   r   r   r   r   r   elementsr   r   r   r   r   r   r   visitorsr   r   r   r   
plugin_forr~   r   r   DMLRoler   r   r   objectr  r+  r3  rz   r(   r&   <module>r>     sY  
 &    ' $   "    ! ' #   # # '   "G
| G
T H-
X 
 .
2 H-
X 
 .
, H->X > .>f	MM
fRr- r-j	XDZ XDvE
6 E
Pa\: aHZA\: ZAr(   