
    R
h$                       d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZmZ ddlmZmZmZ ddlmZ ddlmZ ddlm Z  erddl!m"Z" ej#        j$        Z$ G d de def                   Z%dS )z
Psycopg Cursor object.
    )annotations)TracebackType)TYPE_CHECKINGAnyIterableIteratoroverload)contextmanager   )errors)pq)ParamsQuery)CopyWriter)Row
RowFactoryRowMaker)Self)Pipeline)
BaseCursor)
Connectionc                  D    e Zd ZdZdZedGd            ZedHd	            Zd
ddI fdZdJdZdKdZdLdZe	dMd            Z
e
j        dNd            Z
dOdZ	 dPd
d
ddQd&Zd'd(dRd-Z	 dPd
d.d/dSd3ZdTd5ZdUdVd8ZdWd9ZdXd:ZdYdZd?Ze	 dPd
d@d[dE            ZdLdFZ xZS )\Cursorpsycopg 
connectionConnection[Row]c                    d S Nr   )selfr   s     Y/var/www/html/01_SiteInternet/03_Maps/venv/lib/python3.11/site-packages/psycopg/cursor.py__init__zCursor.__init__#   s    58S    Connection[Any]row_factoryRowFactory[Row]c                   d S r    r   )r!   r   r&   s      r"   r#   zCursor.__init__&   s	     sr$   N)r&   RowFactory[Row] | Nonec               f    t                                          |           |p|j        | _        d S r    )superr#   r&   _row_factory)r!   r   r&   	__class__s      r"   r#   zCursor.__init__+   s3     	$$$'A:+Ar$   returnr   c                    | S r    r   r!   s    r"   	__enter__zCursor.__enter__1   s    r$   exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | NoneNonec                .    |                                   d S r    )close)r!   r2   r4   r6   s       r"   __exit__zCursor.__exit__4   s     	

r$   c                .    |                                   dS )zI
        Close the current cursor and free associated resources.
        N)_closer0   s    r"   r:   zCursor.close<   s     	r$   c                    | j         S )z9Writable attribute to control how result rows are formed.r,   r0   s    r"   r&   zCursor.row_factoryB   s       r$   c                F    || _         | j        r ||           | _        d S d S r    )r,   pgresult	_make_row)r!   r&   s     r"   r&   zCursor.row_factoryG   s3    '= 	/([..DNNN	/ 	/r$   RowMaker[Row]c                ,    |                      |           S r    r?   r0   s    r"   _make_row_makerzCursor._make_row_makerM   s      &&&r$   preparebinaryqueryr   paramsParams | NonerG   bool | NonerH   c          	        	 | j         j        5  | j                             |                     ||||                     ddd           n# 1 swxY w Y   n,# t          j        $ r}|                    d          d}~ww xY w| S )z=
        Execute a query or command to the database.
        rF   N)_connlockwait_execute_gene_NO_TRACEBACKwith_traceback)r!   rI   rJ   rG   rH   exs         r"   executezCursor.executeP   s    	*  
%%eVWV%TT                  	* 	* 	*##D)))	*s:   A 2A A AA AA B'A<<BF)	returning
params_seqIterable[Params]rW   boolc          	        	 t          j                    r| j        j        5  | j        j        }|r/| j                            |                     |||                     ddd           n# 1 swxY w Y   |s| j                                        5  | j        j        5  | j                            |                     |||                     ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   dS dS dS | j        j        5  | j                            |                     |||                     ddd           dS # 1 swxY w Y   dS # t          j
        $ r}|                    d          d}~ww xY w)zI
        Execute the same command with a sequence of input data.
        N)r   is_supportedrN   rO   	_pipelinerP   _executemany_gen_pipelinepipeline_executemany_gen_no_pipelinerR   rS   rT   )r!   rI   rX   rW   prU   s         r"   executemanyzCursor.executemanyd   s   	*$&&  Z_  
,A 
 ::5*iXX                  ,,..  
  
 ::5*iXX                                   
 Z_  JOO99%YWW                     	* 	* 	*##D)))	*s   E >A+E +A//E 2A/3E C10CC1C	C1!C	"C1%E 1C55E 8C59E E 0E>E EE EE F'E<<Fr   rH   sizerd   intIterator[Row]c          	   #    K   | j         j        rt          j        d          | j        j        5  	 | j                            |                     ||||                     d}| j                            |                     |                    rit          |          D ]*}| j
                            || j                  }| n|V  +d}| j                            |                     |                    in,# t          j        $ r}|                    d          d}~ww xY w| j         j        t           k    r| j                                         	 | j                            |                     d                    r/	 | j                            |                     d                    /n# t$          $ r Y nw xY w	 | j                            |                     d                     n# t$          $ r Y nw xY wn# | j         j        t           k    r| j                                         	 | j                            |                     d                    r/	 | j                            |                     d                    /n# t$          $ r Y nw xY w	 | j                            |                     d                     w # t$          $ r Y w w xY ww xY wddd           dS # 1 swxY w Y   dS )a  
        Iterate row-by-row on a result from the database.

        :param size: if greater than 1, results will be retrieved by chunks of
            this size from the server (but still yielded row-by-row); this is only
            available from version 17 of the libpq.
        z(stream() cannot be used in pipeline moderc   TNF)first)_pgconnpipeline_statusrR   ProgrammingErrorrN   rO   rP   _stream_send_gen_stream_fetchone_genrange_txload_rowrB   rS   rT   transaction_statusACTIVE_try_cancel	Exception)	r!   rI   rJ   rH   rd   rh   posrecrU   s	            r"   streamzCursor.stream   s      <' 	Q$%OPPPZ_ 	 	
))%T)RR   jood&?&?&F&FGG "$T{{ " ""h//T^DD;!E!				!E jood&?&?&F&FGG " ? . . .''---. <2f<< J**,,,"jood.G.Ge.G.T.TUU !  #jood.G.Ge.G.T.TUU !$   

(A(A(A(N(NOOOO$    =4<2f<< J**,,,"jood.G.Ge.G.T.TUU !  #jood.G.Ge.G.T.TUU !$   

(A(A(A(N(NOOOO$    =!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   K4C	C;:H;D$
DD$$H'.K4AF43K44
G>K4 GK4.G43K44
H>K4 HK4/K$5AJK$
J 	K$J 	 K$$.KK$
K 	K$K 	 K$$K44K8;K8
Row | Nonec                    |                                   |                                  | j                            | j        | j                  }|| xj        dz  c_        |S )z
        Return the next record from the current recordset.

        Return `!None` the recordset is finished.

        :rtype: Row | None, with Row defined by `row_factory`
        Nr   )_fetch_pipeline_check_result_for_fetchro   rp   _posrB   )r!   records     r"   fetchonezCursor.fetchone   s]     	$$&&&""49dn==IINIIr$   r   	list[Row]c                @   |                                   |                                  | j        sJ |s| j        }| j                            | j        t          | j        |z   | j        j                  | j	                  }| xj        t          |          z  c_        |S )z
        Return the next `!size` records from the current recordset.

        `!size` default to `!self.arraysize` if not specified.

        :rtype: Sequence[Row], with Row defined by `row_factory`
        )rz   r{   rA   	arraysizero   	load_rowsr|   minntuplesrB   len)r!   rd   recordss      r"   	fetchmanyzCursor.fetchmany   s     	$$&&&} 	">D($$Is49t+T]-BCCT^
 
 			S\\!		r$   c                    |                                   |                                  | j        sJ | j                            | j        | j        j        | j                  }| j        j        | _        |S )z
        Return all the remaining records from the current recordset.

        :rtype: Sequence[Row], with Row defined by `row_factory`
        )rz   r{   rA   ro   r   r|   r   rB   )r!   r   s     r"   fetchallzCursor.fetchall   si     	$$&&&}($$TY0Et~VVM)	r$   c              #      K                                                                        d fd}	  | j                  }|d S  xj        dz  c_        |V  ))	Nru   re   r.   rx   c                D    j                             | j                  S r    )ro   rp   rB   )ru   r!   s    r"   loadzCursor.__iter__.<locals>.load   s    8$$S$.999r$   Tr   )ru   re   r.   rx   )rz   r{   r|   )r!   r   rows   `  r"   __iter__zCursor.__iter__   s      $$&&&	: 	: 	: 	: 	: 	:	$ty//C{IINIIIII	r$   relativevaluemodestrc                Z    |                                   |                     ||           dS )a  
        Move the cursor in the result set to a new position according to mode.

        If `!mode` is ``'relative'`` (default), `!value` is taken as offset to
        the current position in the result set; if set to ``'absolute'``,
        `!value` states an absolute target position.

        Raise `!IndexError` in case a scroll operation would leave the result
        set. In this case the position will not change.
        N)rz   _scroll)r!   r   r   s      r"   scrollzCursor.scroll   s0     	UD!!!!!r$   writer	statementr   Writer | NoneIterator[Copy]c             #    K   	 | j         j        5  | j                             |                     ||                     ddd           n# 1 swxY w Y   t	          | |          5 }|V  ddd           n# 1 swxY w Y   n,# t
          j        $ r}|                    d          d}~ww xY w|                     d           dS )zU
        Initiate a :sql:`COPY` operation and return an object to manage it.
        Nr   r   )	rN   rO   rP   _start_copy_genr   rR   rS   rT   _select_current_result)r!   r   rJ   r   copyrU   s         r"   r   zCursor.copy  sa     	* I I
 4 4Y G GHHHI I I I I I I I I I I I I I I d6*** d


               	* 	* 	*##D)))	*
 	##A&&&&&s]   B /AB AB AB 'A8,B 8A<<B ?A< B B-B((B-c                   | j         durr| j        sm| j        j        rc| j        j        5  | j                            | j        j                            d                     d d d            d S # 1 swxY w Y   d S d S d S d S )NFT)flush)_execmany_returningrA   rN   r]   rO   rP   
_fetch_genr0   s    r"   rz   zCursor._fetch_pipeline  s    $E11] 2
$ 2  M M

 4 ? ?d ? K KLLLM M M M M M M M M M M M M M M M M M	 211111s   9A//A36A3)r   r   )r   r%   r&   r'   )r   r%   r&   r)   )r.   r   )r2   r3   r4   r5   r6   r7   r.   r8   )r.   r8   )r.   r'   )r&   r'   r.   r8   )r.   rC   r    )
rI   r   rJ   rK   rG   rL   rH   rL   r.   r   )rI   r   rX   rY   rW   rZ   r.   r8   )
rI   r   rJ   rK   rH   rL   rd   re   r.   rf   )r.   rx   )r   )rd   re   r.   r   )r.   r   )r.   rf   )r   )r   re   r   r   r.   r8   )r   r   rJ   rK   r   r   r.   r   )__name__
__module____qualname__	__slots__r	   r#   r1   r;   r:   propertyr&   setterrE   rV   rb   rw   r~   r   r   r   r   r
   r   rz   __classcell__)r-   s   @r"   r   r      sr       JI888 X8   X
 UYB B B B B B B B          ! ! ! X! / / / /
' ' ' ' !%
  $"     * PU* * * * * *B !%1
 #1 1 1 1 1 1f       (      " " " " "  !%'
 !%' ' ' ' ' ^'.M M M M M M M Mr$   r   r%   N)&__doc__
__future__r   typesr   typingr   r   r   r   r	   
contextlibr
    r   rR   r   abcr   r   r   r   r   rowsr   r   r   _compatr   r]   r   _cursor_baser   r   r   TransactionStatusrr   r   r   r$   r"   <module>r      s    # " " " " "       C C C C C C C C C C C C C C % % % % % %                             + + + + + + + + + +             $ $ $ $ $ $ '&&&&&&			$AM AM AM AM AMZ)3./ AM AM AM AM AMr$   