mň
4RćAc           @   sď   d  Z  d d d !Z d k l Z d k l Z d k Z d k Z d k l Z l	 Z	 l
 Z
 d k l Z d	 k l Z d k Z d k Z d
 k l Z l Z l Z l Z l Z d k l Z l Z l Z d k l Z d e e i f d     YZ d S(   s)   $Id: db.py 620 2005-01-13 10:49:24Z fog $s   $Revision: 1.31.2.7 $i   iţ˙˙˙(   s   TM(   s   dbi_dbN(   s   strips   splits   find(   s   time(   s   ListType(   s   NUMBERs   STRINGs   INTEGERs   FLOATs   DATETIME(   s   BOOLEANs   ROWIDs   LONGINTEGER(   s   ConflictErrort   DBc           B   s   t  Z d  Z Z Z d d  Z d   Z d   Z d   Z	 d   Z
 d d d
  Z d   Z d  d  d  Z d   Z d   Z RS(   Ns   utf-8c         C   sF   | |  _  | |  _ | |  _ |  i |  i   |  _ d |  _ d |  _ d  S(   Ni    (	   t
   connectiont   selft   tilevelt   enct   encodingt   connectt   dbt   failurest   calls(   R   R   R   R   (    (    t<   /home2/kennisonb/webapps/zope/Zope/Products/ZPsycopgDA/db.pyt   __init__l   s    				c         C   s)   t  i |  } | i t |  i   | S(   N(   t   psycopgR   R   t   ot   set_isolation_levelt   intR   R   (   R   R   R   (    (    R
   R   t   s    c         G   s/   t  |  d  o |  i o |  i i   n d  S(   NR   (   t   hasattrR   R   t   commit(   R   t   ignored(    (    R
   t   _finishy   s    c         G   s/   t  |  d  o |  i o |  i i   n d  S(   NR   (   R   R   R   t   rollback(   R   R   (    (    R
   t   _abort}   s    c         C   sB   t  |  d  p |  i o |  i |  i  |  _ n |  i i   S(   s   Obtains a cursor in a safe way.R   N(   R   R   R   R   R   t   cursor(   R   (    (    R
   t   _cursor   s     i    t   TABLEt   VIEWc         C   s   |  i   |  i   } | i d  g  } | i } xG | i   D]9 \ } } | | j o  | h  d | <d | < q? q? W| i   | S(   Ns  SELECT t.tablename AS NAME, 'TABLE' AS TYPE FROM pg_tables t WHERE tableowner <> 'postgres' UNION SELECT v.viewname AS NAME, 'VIEW' AS TYPE FROM pg_views v WHERE viewowner <> 'postgres' UNION SELECT t.tablename AS NAME, 'SYSTEM_TABLE' AS TYPE FROM pg_tables t WHERE tableowner = 'postgres' UNION SELECT v.viewname AS NAME, 'SYSTEM_TABLE' AS TYPE FROM pg_views v WHERE viewowner = 'postgres' t
   TABLE_NAMEt
   TABLE_TYPE(   R   t	   _registerR   t   ct   executet   rt   appendt   at   fetchallt   namet   typt   _caret   close(   R   t   rdbR%   R!   R   R#   R   R$   (    (    R
   t   tables   s    
	 $
c         C   sG  |  i   |  i   } y | i d |  } Wn f  Sn X| i } g  } | i	 } xí | D]ĺ \ } }
 } } } } }	 |
 t j o8 |
 t j o
 t }
 q|
 t j o
 t }
 qt }
 nL |
 t j o
 t }
 n5 |
 t j o
 t }
 n |
 t j o
 t }
 n t }
 | h  d | <d |
 i <d d <d d <d d < qZ W| S(   Ns   select * from "%s" where 1=0t   Namet   Typet	   Precisioni    t   Scalet   Nullable(   R   R   R   R   R   t
   table_nameR   t   descriptiont   descR    R!   R#   t   typet   widtht   dst   pt   scalet   null_okt   NUMBERt   INTEGERt   FLOATt   BOOLEANt   ROWIDt   DATETIMEt   STRING(   R   R.   R!   R   R5   R#   R4   R2   R   R6   R1   R3   R0   (    (    R
   t   columns   s4    
		 





>c         C   su  |  i   |  i d |  _ f  } g  } d } |  i   } y(xt d  t
 t t | d    D]ő}	 t |	  t j o$ |  i o |	 i |  i  }	 q n y0 | o | i |	 |  } n | i |	  } Wnt i j
 o˛ } y |  i   Wn n X|  i |  i  y0 | o | i |	 |  } n | i |	  } WqŰt i t i f j
 o6 } | i d i d  d j o
 t   n |  qŰXnO t i t i f j
 o6 } | i d i d  d j o
 t   n |  n X| i! d  j	 og | d } | i! | j o | d j o d d  n | o | i# |  } n | i$   } | i! } q] q] Wd |  _% Wn% t& j
 o } |  i(   |  n Xg  } xÚ | D]Ň \ } } } } } } }
 | t1 j o. | t2 j p | t3 j o
 d } q6d	 } nL | t5 j o
 d	 } n5 | t6 j o
 d } n | t7 j o
 d
 } n d } | i8 h  d | <d | <d | <d |
 < qW| | f S(   Ni   i    t    s   concurrent updatei˙˙˙˙s   Query Errors&   Multiple select schema are not allowedt   it   nt   dt   sR#   R1   R2   t   null(9   R   R   R	   R0   t   resultt   nselectsR   R   t   filtert   Nonet   mapt   stript   splitt   query_stringt   qsR1   t   unicodeR   t   encodet
   query_dataR   R   R   t   OperationalErrort   perrR&   R   R   t   ProgrammingErrort   IntegrityErrort   argst   findt   ConflictErrorR/   t   max_rowst	   fetchmanyR"   R   t   StandardErrort   errR   t   itemsR#   R$   R2   R3   R4   R5   R6   R7   R8   t   LONGINTEGERt   typsR:   R;   R<   R    (   R   RL   RX   RP   RE   R5   R2   RR   RF   RM   R6   R$   R3   R0   R   R#   R[   R\   R4   R   R^   (    (    R
   t   queryž   s|    
" 




  




5c         C   s   |  i i   d |  _ d S(   s   Close the connection.N(   R   R   R&   RH   (   R   (    (    R
   R&     s     c         C   s   d S(   s   Zope 2.6 added this one.i   N(    (   R   (    (    R
   t   sortKey  s     (   s   TABLEs   VIEW(   t   __name__t
   __module__RH   t   _p_oidt
   _p_changedt   _registeredR   R   R   R   R   R(   R>   R_   R&   R`   (    (    (    R
   R    h   s   					 P	(   t   __doc__t   __version__t   Shared.DC.ZRDB.TMt   TMt   Shared.DC.ZRDBt   dbi_dbt   stringt   sysRJ   RK   RV   t   timet   typest   ListTypet   siteR   R7   R=   R8   R9   R<   R:   R;   R]   t   ZODB.POSExceptionRW   R    (   R    Rq   RW   Rk   RJ   RV   R=   Ri   RK   R8   Rg   Rl   R7   R<   Rm   Rp   R]   R9   R:   R   R;   Rn   (    (    R
   t   ?V   s   		%