ó
żb]c           @   sľ   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 Z d e f d
     YZ e e d  Z d e	 f d     YZ d S(   i   (   t   exc(   t   util(   t   _generative(   t   Insert(   t   ClauseElement(   t   alias(   t   public_factoryR   t   insertc           B   s>   e  Z d  Z e d    Z e j d    Z e d    Z	 RS(   s   MySQL-specific implementation of INSERT.

    Adds methods for MySQL-specific syntaxes such as ON DUPLICATE KEY UPDATE.

    .. versionadded:: 1.2

    c         C   s
   |  j  j S(   sŻ  Provide the "inserted" namespace for an ON DUPLICATE KEY UPDATE statement

        MySQL's ON DUPLICATE KEY UPDATE clause allows reference to the row
        that would be inserted, via a special function called ``VALUES()``.
        This attribute provides all columns in this row to be referenceable
        such that they will render within a ``VALUES()`` function inside the
        ON DUPLICATE KEY UPDATE clause.    The attribute is named ``.inserted``
        so as not to conflict with the existing :meth:`.Insert.values` method.

        .. seealso::

            :ref:`mysql_insert_on_duplicate_key_update` - example of how
            to use :attr:`.Insert.inserted`

        (   t   inserted_aliast   columns(   t   self(    (    s<   lib/python2.7/site-packages/sqlalchemy/dialects/mysql/dml.pyt   inserted   s    c         C   s   t  |  j d d S(   Nt   nameR   (   R   t   table(   R
   (    (    s<   lib/python2.7/site-packages/sqlalchemy/dialects/mysql/dml.pyR   )   s    c         O   s   | r | r t  j d   n  | rU t |  d k rH t  j d   n  | d } n | } t |  d d  } t | |  |  _ |  S(   s*  
        Specifies the ON DUPLICATE KEY UPDATE clause.

        :param \**kw:  Column keys linked to UPDATE values.  The
         values may be any SQL expression or supported literal Python
         values.

        .. warning:: This dictionary does **not** take into account
           Python-specified default UPDATE values or generation functions,
           e.g. those specified using :paramref:`.Column.onupdate`.
           These values will not be exercised for an ON DUPLICATE KEY UPDATE
           style of UPDATE, unless values are manually specified here.

        :param \*args: As an alternative to passing key/value parameters,
         a dictionary or list of 2-tuples can be passed as a single positional
         argument.

         Passing a single dictionary is equivalent to the keyword argument
         form::

            insert().on_duplicate_key_update({"name": "some name"})

         Passing a list of 2-tuples indicates that the parameter assignments
         in the UPDATE clause should be ordered as sent, in a manner similar
         to that described for the :class:`.Update` construct overall
         in :ref:`updates_order_parameters`::

            insert().on_duplicate_key_update(
                [("name", "some name"), ("value", "some value")])

         .. versionchanged:: 1.3 parameters can be specified as a dictionary
            or list of 2-tuples; the latter form provides for parameter
            ordering.


        .. versionadded:: 1.2

        .. seealso::

            :ref:`mysql_insert_on_duplicate_key_update`

        s9   Can't pass kwargs and positional arguments simultaneouslyi   sD   Only a single dictionary or list of tuples is accepted positionally.i    R   N(   R    t   ArgumentErrort   lent   getattrt   Nonet   OnDuplicateClauset   _post_values_clause(   R
   t   argst   kwt   valuesR   (    (    s<   lib/python2.7/site-packages/sqlalchemy/dialects/mysql/dml.pyt   on_duplicate_key_update-   s    ,(
   t   __name__t
   __module__t   __doc__t   propertyR   R   t   memoized_propertyR   R   R   (    (    (    s<   lib/python2.7/site-packages/sqlalchemy/dialects/mysql/dml.pyR      s   s   .dialects.mysql.insertR   c           B   s   e  Z d  Z d Z d   Z RS(   R   c         C   s   | |  _  t | t  rb | rb t | d t  rb g  | D] \ } } | ^ q8 |  _ t |  } n  | sy t | t  r t d   n  | |  _ d  S(   Ni    s/   update parameter must be a non-empty dictionary(   R   t
   isinstancet   listt   tuplet   _parameter_orderingt   dictt
   ValueErrort   update(   R
   R   R#   t   keyt   value(    (    s<   lib/python2.7/site-packages/sqlalchemy/dialects/mysql/dml.pyt   __init__u   s    	"N(   R   R   t   __visit_name__R   R    R&   (    (    (    s<   lib/python2.7/site-packages/sqlalchemy/dialects/mysql/dml.pyR   p   s   N(   R   R   (   t    R    R   t   sql.baseR   t   sql.dmlR   t   StandardInsertt   sql.elementsR   t   sql.expressionR   t   util.langhelpersR   t   __all__R   R   (    (    (    s<   lib/python2.7/site-packages/sqlalchemy/dialects/mysql/dml.pyt   <module>   s   `