
    i#                       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jF                  jH                  Z$ G d de def         Z%y)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                      e Zd ZdZdZedd       Ze	 	 	 	 dd       Zdd	 	 	 d  fdZd!dZ	 	 	 	 	 	 	 	 d"d	Zd#d
Ze	d$d       Z
e
j                  d%d       Z
d&dZ	 d'ddd	 	 	 	 	 	 	 	 	 d(dZdd	 	 	 	 	 	 	 d)dZ	 d'ddd	 	 	 	 	 	 	 	 	 d*dZd+dZd,d-dZd.dZd/dZd0d1dZe	 d'dd	 	 	 	 	 	 	 d2d       Zd#dZ xZS )3Cursorpsycopg c                     y Nr   )self
connections     n/var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/venv/lib/python3.12/site-packages/psycopg/cursor.py__init__zCursor.__init__#   s    58    c                    y r   r   )r   r    row_factorys      r!   r"   zCursor.__init__&   s     r#   N)r%   c               N    t         |   |       |xs |j                  | _        y r   )superr"   r%   _row_factory)r   r    r%   	__class__s      r!   r"   zCursor.__init__+   s%     	$'A:+A+Ar#   c                    | S r   r   r   s    r!   	__enter__zCursor.__enter__1   s    r#   c                $    | j                          y r   )close)r   exc_typeexc_valexc_tbs       r!   __exit__zCursor.__exit__4   s     	

r#   c                $    | j                          y)zI
        Close the current cursor and free associated resources.
        N)_closer+   s    r!   r.   zCursor.close<   s     	r#   c                    | j                   S )z9Writable attribute to control how result rows are formed.r(   r+   s    r!   r%   zCursor.row_factoryB   s        r#   c                F    || _         | j                  r ||       | _        y y r   )r(   pgresult	_make_row)r   r%   s     r!   r%   zCursor.row_factoryG   s"    '==(.DN r#   c                $    | j                  |       S r   r6   r+   s    r!   _make_row_makerzCursor._make_row_makerM   s      &&r#   preparebinaryc          	        	 | j                   j                  5  | j                   j                  | j                  ||||             ddd       | S # 1 sw Y   | S xY w# t        j
                  $ r}|j                  d      d}~ww xY w)z=
        Execute a query or command to the database.
        r<   N)_connlockwait_execute_gene_NO_TRACEBACKwith_traceback)r   queryparamsr=   r>   exs         r!   executezCursor.executeP   s}    	* 

%%eVWV%T    	*##D))	*s4   A /AA AA A B1BBF)	returningc          	     r   	 | j                   j                  5  t        j                         r| j                   j                  r-| j                   j                  | j                  |||             n|| j                   j                         5  | j                   j                  | j                  |||             ddd       n,| j                   j                  | j                  |||             ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w# t        j                  $ r}|j                  d      d}~ww xY w)zI
        Execute the same command with a sequence of input data.
        N)r@   rA   r   is_supported	_pipelinerB   _executemany_gen_pipeline_pipeline_nolock_executemany_gen_no_pipelinerD   rE   rF   )r   rG   
params_seqrK   rI   s        r!   executemanyzCursor.executemanyd   s   	* ((* zz++

 ::5*iX
 "ZZ88:  JJOO $ > >$):y!"  JJOO99%YW#   (  	*##D))	*sM   D A2D
-C575D,D 5C>	:DD
D 
D D6 D11D6r   r>   sizec          	   #  "  K   | j                   j                  rt        j                  d      | j                  j
                  5  	 | j                  j                  | j                  ||||             d}| j                  j                  | j                  |            x}rqt        |j                        D ]*  }| j                  j                  || j                         , d}| j                  j                  | j                  |            x}rq| j                   j                   t"        k(  r| j                  j%                          	 | j                  j                  | j                  d            r-	 | j                  j                  | j                  d            r-	 | j                  j                  | j                  d             ddd       y# t        j                  $ r}|j                  d      d}~ww xY w# t&        $ r Y lw xY w# t&        $ r Y Ow xY w# | j                   j                   t"        k(  r| j                  j%                          	 | j                  j                  | j                  d            r-	 | j                  j                  | j                  d            r-n# t&        $ r Y nw xY w	 | j                  j                  | j                  d             w # t&        $ r Y w w xY ww xY w# 1 sw Y   yxY ww)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 moderT   TFN)first)_pgconnpipeline_statusrD   ProgrammingErrorr@   rA   rB   _stream_send_gen_stream_fetchone_genrangentuples_txload_rowr9   rE   rF   transaction_statusACTIVE_try_cancel	Exception)	r   rG   rH   r>   rU   rW   resposrI   s	            r!   streamzCursor.stream   s     <<''$$%OPPZZ__ 	

))%T)R !ZZ__T-F-Fu-MNNcN$S[[1 E"hh//T^^DDE!E "ZZ__T-F-Fu-MNNcN <<22f< JJ**,"jjood.G.Ge.G.TU  #jjood.G.Ge.G.TU

(A(A(A(NO5	 	 ?? .''--. %  %  <<22f< JJ**,"jjood.G.Ge.G.TU  #jjood.G.Ge.G.TU$ 


(A(A(A(NO$  =	 	s   ALLCG7LAH$+H	LH+G<<HH"	HLHL	HLHL"8L AJ43L 4	K 	=L ?K 	 L +K0/L 0	K<	9L ;K<	<L  LLLc                   | j                          | j                         }| j                  |j                  k  rG| j                  j                  | j                  | j                        }| xj                  dz  c_        |S y)z
        Return the next record from the current recordset.

        Return `!None` the recordset is finished.

        :rtype: Row | None, with Row defined by `row_factory`
        r   N_fetch_pipeline_check_result_for_fetch_posr^   r_   r`   r9   )r   re   records      r!   fetchonezCursor.fetchone   sa     	**,99s{{"XX&&tyy$..AFIINIMr#   c                B   | j                          | j                         }|s| j                  }| j                  j	                  | j
                  t        | j
                  |z   |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`
        )
rj   rk   	arraysizer_   	load_rowsrl   minr^   r9   len)r   rU   re   recordss       r!   	fetchmanyzCursor.fetchmany   sz     	**,>>D(($$IIs499t+S[[94>>
 			S\!	r#   c                    | 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`
        )rj   rk   r_   rq   rl   r^   r9   )r   re   rt   s      r!   fetchallzCursor.fetchall   sR     	**,(($$TYYT^^LKK	r#   c              #  F  K   | j                          | j                         }| j                  |j                  k  rd| j                  j                  | j                  | j                        }| xj                  dz  c_        | | j                  |j                  k  rcy y w)Nr   ri   )r   re   rows      r!   __iter__zCursor.__iter__   sr     **,ii#++%((##DIIt~~>CIINII ii#++%s   BB!B!c                H    | j                          | j                  ||       y)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)rj   _scroll)r   valuemodes      r!   scrollzCursor.scroll   s     	UD!r#   writerc             #    K   	 | j                   j                  5  | j                   j                  | j                  ||             ddd       t	        | |      5 }| ddd       | j                  d       y# 1 sw Y   5xY w# 1 sw Y   'xY w# t
        j                  $ r}|j                  d      d}~ww xY ww)zU
        Initiate a :sql:`COPY` operation and return an object to manage it.
        Nr   r   )	r@   rA   rB   _start_copy_genr   rD   rE   rF   _select_current_result)r   	statementrH   r   copyrI   s         r!   r   zCursor.copy   s     	* I

 4 4Y GHI d6* d
 	##A&I I  	*##D))	*sW   B>B ,A:B B B (B>:B?B BB B;%B66B;;B>c                >   | j                   dur| j                  sv| j                  j                  r_| j                  j                  5  | j                  j                  | j                  j                  j                  d             d d d        y y y y # 1 sw Y   y xY w)NFT)flush)_execmany_returningr8   r@   rN   rA   rB   
_fetch_genr+   s    r!   rj   zCursor._fetch_pipeline  s    $$E1]]

$$ M



 4 4 ? ?d ? KLM M % # 2M Ms   A BB)r    zConnection[Row])r    Connection[Any]r%   RowFactory[Row])r    r   r%   zRowFactory[Row] | None)returnr   )r/   ztype[BaseException] | Noner0   zBaseException | Noner1   zTracebackType | Noner   None)r   r   )r   r   )r%   r   r   r   )r   zRowMaker[Row]r   )
rG   r   rH   Params | Noner=   bool | Noner>   r   r   r   )rG   r   rR   zIterable[Params]rK   boolr   r   )
rG   r   rH   r   r>   r   rU   intr   Iterator[Row])r   z
Row | None)r   )rU   r   r   	list[Row])r   r   )r   r   )relative)r}   r   r~   strr   r   )r   r   rH   r   r   zWriter | Noner   zIterator[Copy])__name__
__module____qualname__	__slots__r	   r"   r,   r2   r.   propertyr%   setterr;   rJ   rS   rg   rn   ru   rw   rz   r   r
   r   rj   __classcell__)r)   s   @r!   r   r      s   JI8 8);J 
 UYB)B;QB, & %	
 
 ! ! / /
' !%
  $" 
   
* PU**(8*HL*	*B !%.
 #.. .
 . . 
.` &
"  !%'
 !%'' '
 ' 
' '.Mr#   r   r   N)&__doc__
__future__r   typesr   typingr   r   r   r   r	   
contextlibr
    r   rD   r   abcr   r   r   r   r   rowsr   r   r   _compatr   rN   r   _cursor_baser   r    r   TransactionStatusrb   r   r   r#   r!   <module>r      sh    #  C C %     + +   $&				$	$xMZ)3./ xMr#   