
     h                        d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
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 ddlmZ ddlmZ erddlmZ  G d dedef   ee         Zy)z$
psycopg server-side cursor (sync).
    )annotations)TYPE_CHECKINGAnyoverload)warn)IterableIterator   )errors)ParamsQuery)Row
RowFactory)Cursor)Self)ServerCursorMixin)
Connectionc                      e Zd ZdZdZeddd	 	 	 	 	 	 	 dd       Zeddd	 	 	 	 	 	 	 	 	 dd       Zdddd	 	 	 	 	 	 	 	 	 dd	Zdd
Zd fdZ	 ddd	 	 	 	 	 	 	 	 	 ddZdd	 	 	 	 	 	 	 ddZ	ddZ
dddZd dZd!dZd"d#dZ xZS )$ServerCursorpsycopg NF)
scrollablewithholdc                    y Nr   )self
connectionnamer   r   s        P/var/www/tech_portal/venv/lib/python3.12/site-packages/psycopg/_server_cursor.py__init__zServerCursor.__init__   s         c                    y r   r   r   r   r   row_factoryr   r   s         r   r    zServerCursor.__init__)   s     r!   )r$   r   r   c                   t        j                  | ||xs |j                         t        j                  | |||       y )N)r$   )r   r    r$   r   r#   s         r   r    zServerCursor.__init__4   s8     	*+*O9O9O	
 	""4z8Dr!   c                F    | j                   st        d|  dt               y y )Nzthe server-side cursor z[ was deleted while still open. Please use 'with' or '.close()' to close the cursor properly)closedr   ResourceWarning)r   s    r   __del__zServerCursor.__del__B   s,    {{)$  0K  L r!   c                "   | j                   j                  5  | j                  r
	 ddd       y| j                   j                  s)| j                   j                  | j	                                t
        |           ddd       y# 1 sw Y   yxY w)zI
        Close the current cursor and free associated resources.
        N)_connlockr'   wait
_close_gensuperclose)r   	__class__s    r   r0   zServerCursor.closeI   sh     ZZ__ 	{{	 	 ::$$

 12GMO	 	 	s   BABB)binaryc                  |rt        dt        |      d          | j                  j                  rt	        j
                  d      	 | 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)zC
        Open a cursor to execute a query to the database.
        zkeyword not supported: r   z2server-side cursors not supported in pipeline modeN)	TypeErrorlist_pgconnpipeline_statuseNotSupportedErrorr+   r,   r-   _declare_gen_NO_TRACEBACKwith_traceback)r   queryparamsr2   kwargsexs         r   executezServerCursor.executeT   s     5d6l1o5FGHH<<''%%D 	* J

 1 1% HIJ
 J
   	*##D))	*s6   	B# -BB# B B#  B# #C6CCT)	returningc               ,    t        j                  d      )z/Method not implemented for server-side cursors.z0executemany not supported on server-side cursors)r8   r9   )r   r=   
params_seqrB   s       r   executemanyzServerCursor.executemanyn   s     !!"TUUr!   c                    | j                   j                  5  | j                   j                  | j                  d            }d d d        r| xj                  dz  c_        |d   S y # 1 sw Y   &xY w)Nr
   r   )r+   r,   r-   
_fetch_gen_posr   recss     r   fetchonezServerCursor.fetchonet   sY    ZZ__ 	7::??4??1#56D	7IINI7N	7 	7s   +A''A0c                   |s| j                   }| j                  j                  5  | j                  j                  | j	                  |            }d d d        | xj
                  t              z  c_        |S # 1 sw Y   )xY wr   )	arraysizer+   r,   r-   rG   rH   len)r   sizerJ   s      r   	fetchmanyzServerCursor.fetchmany}   s`    >>DZZ__ 	:::??4??4#89D	:		SY		: 	:s   +A88Bc                    | j                   j                  5  | j                   j                  | j                  d             }d d d        | xj                  t              z  c_        |S # 1 sw Y   )xY wr   )r+   r,   r-   rG   rH   rN   rI   s     r   fetchallzServerCursor.fetchall   sT    ZZ__ 	:::??4??4#89D	:		SY		: 	:s   +A**A3c              #  >  K   	 | j                   j                  5  | j                   j                  | j                  | j                              }d d d        D ]  }| xj
                  dz  c_        |  t        |      | j                  k  ry # 1 sw Y   CxY ww)Nr
   )r+   r,   r-   rG   itersizerH   rN   )r   rJ   recs      r   __iter__zServerCursor.__iter__   s      Gzztt}}'EFG 		Q		 4y4==( G Gs   B5BABBBc                    | j                   j                  5  | j                   j                  | j                  ||             d d d        |dk(  r| xj                  |z  c_        y || _        y # 1 sw Y   ,xY w)Nrelative)r+   r,   r-   _scroll_genrH   )r   valuemodes      r   scrollzServerCursor.scroll   s^    ZZ__ 	;JJOOD,,UD9:	; :IIIDI	; 	;s   ,A..A7)r   zConnection[Row]r   strr   bool | Noner   bool)
r   Connection[Any]r   r]   r$   zRowFactory[Row]r   r^   r   r_   )
r   r`   r   r]   r$   zRowFactory[Row] | Noner   r^   r   r_   )returnNoner   )
r=   r   r>   zParams | Noner2   r^   r?   r   ra   r   )r=   r   rD   zIterable[Params]rB   r_   ra   rb   )ra   z
Row | None)r   )rO   intra   	list[Row])ra   rd   )ra   zIterator[Row])rX   )rZ   rc   r[   r]   ra   rb   )__name__
__module____qualname__	__slots__r   r    r)   r0   rA   rE   rK   rP   rR   rV   r\   __classcell__)r1   s   @r   r   r      s|   JI #'# 
      #'# 
 %     /3"&E#E E
 ,E  E E	 !%
 # 
   
6 PTVV(8VHLV	V r!   r   r`   N)__doc__
__future__r   typingr   r   r   warningsr   collections.abcr   r	    r   r8   abcr   r   rowsr   r   cursorr   _compatr   _server_cursor_baser   r   r   r   r   r!   r   <module>ru      sS    # / /  .   !   2&A$%6%;<fSk Ar!   