
    yh.                        S r SrS\-   rSSKrSSKrSSKrSSKrSSKrSSKJ	r
JrJr   \" \R                  S   5      r\(       a  \" \5         SSKrSSKrSS	KJr  S rSSKJr  S rS r\
R>                  r \
RB                  r"\RF                  " 5       r$SS jr%S r& " S S5      r' " S S5      r(\)S:X  a  \RT                  " \S-   5      eg!   Sr N= f! \ a    SSKr\R0                  " S
\SS9   Nf = f)a  adodbapi - A python DB API 2.0 (PEP 249) interface to Microsoft ADO

Copyright (C) 2002 Henrik Ekelund, versions 2.1 and later by Vernon Cole
* https://sourceforge.net/projects/pywin32
* https://github.com/mhammond/pywin32
* https://sourceforge.net/projects/adodbapi

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    django adaptations and refactoring by Adam Vandenberg

DB-API 2.0 specification: https://peps.python.org/pep-0249/

This module source should run correctly in CPython versions 2.7 and later,
or CPython 3.4 or later.
z2.6.2.0z
adodbapi v    N   )
ado_constsapibaseprocess_connect_stringADODBAPI_VERBOSEF)Dispatchz&pywin32 package required for adodbapi.   )
stacklevelc                     U " U5      $ N )objindexs     ic:\Users\julio\OneDrive\Documentos\Trabajo\IdeasFrscas\Cabanna\env\Lib\site-packages\adodbapi/adodbapi.pygetIndexedValuer   :   s    u:    )Mappingc                  ~     [         R                  " 5         [        S5      n U $ !   [        R                  " S5      e= f)NzADODB.Connectionz7Windows COM Error: Dispatch('ADODB.Connection') failed.)	pythoncomCoInitializer   apiInterfaceError)cs    r   make_COM_connecterr   B   sB    
 '(
 H	
  E
 	
s    $ <c                      [        5       n[        R                  " XS5      n UR                  U5        U$ ! [         a*  nSUR
                  -  n[        R                  " X45      eSnAff = f)av  Connect to a database.

call using:
:connection_string -- An ADODB formatted connection string, see:
     * https://www.connectionstrings.com
     * https://www.codeguru.com/dotnet/whats-in-an-ado-connection-string/
     * https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/connection-strings
:timeout -- A command timeout value, in seconds (default 30 seconds)
Tz Error opening connection to "%s"N)
Connectionr   processconnect	Exceptionconnection_stringr   OperationalError)argskwargscoemessages        r   r   r   M   sd     
B#++D$?F/


6	 /4r7K7KK""1../s   6 
A* %A%%A*c                 ,    U(       a  U  Vs/ s H  nSUR                   < S[        R                  UR                     < S[        R                  R                  UR                  [        UR                  5      S-   5      < SUR                  < SUR                  < SUR                  < SUR                  < 3PM     nnOU  Vs/ s H  nSUR                   < S[        R                  UR                     < S[        R                  R                  UR                  [        UR                  5      S-   5      < SUR                  < S	UR                  < SUR                  < 3PM     nnS
SR                  U5      -   S-   $ s  snf s  snf !    g= f)z]Format a collection of ADO Command Parameters.

Used by error reporting in _execute_command.
zName: , Dir.: , Type:  (unknown type), Size: 
, Value: "", Precision: , NumericScale: z, Precision: [
]z[])Nameadc
directions	DirectionadTypeNamesgetTypestrSizeValue	PrecisionNumericScalejoin)ADOparameters
show_valuepdescs       r   format_parametersrC   x   s5   
 ' 'A FFNN1;;/OO''AFF>O0OPFFGGKKNN	 '  D0 ' 'A FFNN1;;/OO''AFF>O0OPFFKKNN '   TYYt_$s**5s*   F B3F F B%F
,F 
F Fc                 "   U[         R                  ;   a"  [        U5      U l        U R	                  U5        g[        U[        5      (       aZ  [        U5      nU[         R                  ;   a'  U(       a  [        X@R                  5      nUSU U l	        OXl	        US:  a  X@l        gg[        U[        R                  5      (       a  Xl	        UR                  5       S   n[        UR                  5       S   5      nX`l        US:X  a  SU l        gUS:  a5  U* U l        U R                  U R                  :  a  U R                  U l        ggSU l        Xe-   U l        g[        U5      [         R"                  ;   ab  U(       a/  U[         R$                  ;   a  [         R'                  U5      U l	        g[         R)                  U5      nXpl	        [        U5      U l        gU[*        R,                  :X  a  [*        R.                  U l        SU l	        gXl	        g)z>Configure the given ADO Parameter 'p' with the Python 'value'.Nr   r	   r   )r   adoBinaryTypeslenr:   AppendChunk
isinstancer9   adoStringTypesminr;   decimalDecimalas_tupler<   r=   typedateconvertertypesadoDateTimeTypesCOMDateDateObjectToIsoFormatStringr3   adEmpty	adIntegerr8   )rA   valueadotypesettings_knownlengthexponentdigit_countss           r   _configure_parameterr]      s    #$$$U	e	E3		Uc(((VVV,GVnAGGA:F  
E7??	+	+>>#A&%..*1-.!q=AN\&YAN{{Q^^+nn , AN%0AK	e++	+g)=)==#++E2AG 99%@AGVAF	CKK	MM 	
  r   c                      \ rS rSr\R
                  r\R                  r\R                  r\R                  r\R                  r	\R                  r
\R                  r\R                  r\R                  r\R                  r\R                  r\R                   r\S 5       rS r\4S jrS rS rS rS rS	 rS
 rS rS rS rS rS r S r!S r"S r#S r$S r%Sr&g)r      c                     [         $ )z;Return a reference to the DBAPI module for this Connection.)r   selfs    r   dbapiConnection.dbapi   s	     
r   c                     S U l         [        R                  U l        SU l        SU l        [
        R                  [        [        4   " 5       U l	        SU l
        SU l        S U l        SU l        SU l        g )NF r   )	connectorr   
paramstylesupportsTransactionsr    weakrefWeakValueDictionaryintCursorcursors	dbms_namedbms_versionerrorhandlertransaction_level_autocommitra   s    r   __init__Connection.__init__   sd    ..$)!!#223;?A !" r   c                 :   [         S:  a  [        SU< 35         US   U-  U l        UR                  SS5      U l        UR                  S[        R                  5      U l
        Xl        [         (       a!  [        [        < SU R                  < S	35        U" 5       U l        U R                  U R                  l        U R                  U R                  l        U R                  U R                  l         U R                  R#                  5          [+        U R                  R,                  S5      R.                  S:w  a  SU l        [+        U R                  R,                  S5      R.                  U l         [+        U R                  R,                  S5      R.                  U l        [:        U R                  l        U R0                  (       af  [>        U R                  l         [C        UR                  SS5      5      U l"        U RD                  (       d  U R                  RG                  5       U l$        OSU l"        SU;   a
  US   U l%        / U l&        [         (       a  [        S[O        U 5      -  5        g g ! [         a!  nU R	                  [
        S5         S nAGNoS nAff = f! [$        R&                   a1    U R	                  [$        R(                  S
U R                  -  5         GNf = f! [2        R4                   a     GNf = f! [2        R4                   a     GNvf = f)N	   zkwargs=r    z1Python string format error in connection string->timeout   modez attempting: ""zADO error trying to Open=%szTransaction DDLr   Tz	DBMS NamezDBMS Version
autocommitFrh   zadodbapi New connection at %X)(verboseprintr    r   _raiseConnectionErrorKeyErrorr7   rx   r3   adModeUnknownrz   r#   versionrg   ConnectionTimeoutConnectionStringModeOpenr   ErrorDatabaseErrorr   
Propertiesr;   ri   
pywintypes	com_errorro   rp   defaultCursorLocationCursorLocationdefaultIsolationLevelIsolationLevelboolrs   
BeginTransrr   rh   messagesid)rb   r#   connection_makerr%   s       r   r   Connection.connect   sy   Q;GF:&'	*+f4 " zz)R0JJvs'8'89	77D4J4JKL)++/<<(*.*@*@'"ii	NN!	t~~88:KLRRVWW,0) ))B)BKPVV	 /))>!e 
 )>%$$,ADNN)#FJJ|U$CDD##NN--/ &  $D6!$\2DO71BtH<= _  	&&M 	  yy 	&&!!-0F0FF	 ## 		 ## 		sN   I1 4J 5K' 4/L 1
J;JJAK$#K$'K?>K?LLc                 V    U R                   nUc  [        R                  nU" U S X5        g r   )rq   r   standardErrorHandlerrb   
errorclass
errorvalueehs       r   r    Connection._raiseConnectionError.  s)    :))B
4z.r   c                 "   U R                   c  gU R                  (       d,  U R                  (       a   U R                   R                  5         U R                   R	                  5         [
        (       a  [        S[        U 5      -  5        gg!    NB= f)z^close the underlying ADO Connection object,
rolling it back first if it supports transactions.Nz adodbapi Closed connection at %X)rg   rs   rr   RollbackTransCloser}   r~   r   ra   s    r   _closeAdoConnectionConnection._closeAdoConnection4  sp     >>!%%NN002 	74r$x?@ s   B
 
Bc                 d   [        U R                  R                  5       5      SS  H  nUR                  SS9  M     / U l         U R                  5         SU l
        g! [         aH  nU R                  [        R                  " 5       S   [        R                  " 5       S   5         SnANUSnAff = f)a%  Close the connection now (rather than whenever __del__ is called).

The connection will be unusable from this point forward;
an Error (or subclass) exception will be raised if any operation is attempted with the connection.
The same applies to all cursor objects trying to use the connection.
NT)dont_tell_mer   r   )listrn   valuescloser   r   r   r   sysexc_inforg   )rb   crsrr%   s      r   r   Connection.closeC  s     ,,./
D JJDJ)
 	M$$&   	M&&s||~a'8#,,.:KLL	Ms   A 
B/'>B**B/c                    / U l         U R                  (       d  g U R                  R                  5       U l        [
        S:  a  [        S[        U 5      -  5        U R                  (       dM  U R                  R                  [        R                  -  (       d   U R                  R                  5       U l        ggg! [         a*  nU R                  [        R                   U5         SnAgSnAff = f)a(  Commit any pending transaction to the database.

Note that if the database supports an auto-commit feature,
this must be initially off. An interface method may be provided to turn it back on.
Database modules that do not support transactions should implement this method with void functionality.
Nr   zcommit done on connection at %X)r   ri   rg   CommitTransrr   r}   r~   r   rs   
Attributesr3   adXactAbortRetainingr   r   r   r   ProgrammingErrorrb   r%   s     r   commitConnection.commitX  s     ((	@%)^^%?%?%AD"{7"T(BC  NN--0H0HH
 *.)B)B)D& I !  	@&&s';';Q??	@s   BB: :
C. C))C.c                    / U l         U R                  (       a   U R                  R                  5       U l        [        S:  a  [        S[        U 5      -  5        U R                  (       d_  U R                  R                  [        R                  -  (       d2  U R                  (       d   U R                  R                  5       U l        ggggg! [         a*  nU R                  [        R                  U5         SnAgSnAff = f)ap  In case a database does provide transactions this method causes the the database to roll back to
the start of any pending transaction. Closing a connection without committing the changes first will
cause an implicit rollback to be performed.

If the database does not support the functionality required by the method, the interface should
throw an exception in case the method is used.
The preferred approach is to not implement the method and thus have Python generate
an AttributeError in case the method is requested. This allows the programmer to check for database
capabilities using the standard hasattr() function.

For some dynamically configured interfaces it may not be appropriate to require dynamically making
the method available. These interfaces should then raise a NotSupportedError to indicate the
non-ability to perform the roll back when the method is invoked.
r   z!rollback done on connection at %XN)r   rr   rg   r   r}   r~   r   rs   r   r3   r   r   r   r   r   r   r   s     r   	_rollbackConnection._rollbackr  s     ""D)-)E)E)G&Q;=4HI''NN--0H0HH
  11151J1J1L. 2 I ( #  D**3+?+?CCDs   B-C 
D  C;;D c                    US:X  aD  U R                   (       a2  [        R                  U S[        U5      5         U R	                  5         g g US:X  aK  U[
        R                  ;  a6  U R                  [
        R                  SU< S[
        R                  < 35        OUS:X  a  [        R                  " U5      n[        R                  XU5        g !    g = f)Nr|   rs   rh   zparamstyle=z not in:variantConversions)
ri   object__setattr__r   r   r   accepted_paramstylesr   NotSupportedErrorcopy)rb   namerV   s      r   r   Connection.__setattr__  s    <((""4UDNN$ \!C444**))!%(33K3K2NO ))IIe$E4u-s   C Cc                     US:X  a(  U R                   (       a  U R                  $ [        S5      eUS:X  a  U R                  $ [        SU-  5      e)Nrollbackz,this data provider does not support Rollbackr|   z2no such attribute in ADO connection object as="%s")ri   r   AttributeErrorrs   rb   items     r   __getattr__Connection.__getattr__  sV    J((NN %%STT\!### DtK r   c                 *    / U l         [        U 5      nU$ )z0Return a new Cursor Object using the connection.)r   rm   )rb   r   s     r   cursorConnection.cursor  s    4Lr   c                 6    [        U5      nXR                  U'   g)z3message from a new cursor proclaiming its existenceN)r   rn   )rb   r   oids      r   
_i_am_hereConnection._i_am_here  s    h Sr   c                 @     U R                   [        U5      	 g!    g= f)z<message from a cursor giving connection a chance to clean upN)rn   r   )rb   r   s     r   _i_am_closingConnection._i_am_closing  s!    	RX&	s    c           
      F   U R                   R                  R                  nU(       a  [        SU-  5        U R                   R                   H  n[        SUR                  -  5        [        SUR
                  < S[        R                  R                  UR
                  S5      < S35        UR
                  [        R                  :X  a  [        S5        [        SUR                  -  5        [        SUR                  -  5        [        S	UR                  -  5        M     g )
NzADO Errors:(%i)zDescription: %szError:  unknownzATimeout Error: Try using adodbpi.connect(constr,timeout=Nseconds)z
Source: %szNativeError: %szSQL State: %s)rg   ErrorsCountr~   DescriptionNumberr3   	adoErrorsr7   ado_error_TIMEOUTSourceNativeErrorSQLState)rb   jr%   s      r   printADOerrorsConnection.printADOerrors  s    NN!!''#a'(&&A#amm34QXXs}}/@/@9/UVWxx3000W ,)*#amm34/AJJ./ 'r   c                     U R                   b`  U R                   R                   HF  n[        UR                  5      nUR	                  S5      (       d  US:X  d  M6  [
        R                  s  $    [
        R                  $ )a5  Introspect the current ADO Errors and determine an appropriate error class.

Error.SQLState is a SQL-defined error condition, per the SQL specification:
https://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt

The 23000 class of errors are integrity errors.
Error 40002 is a transactional integrity error.
2340002)rg   r   r9   r   
startswithr   IntegrityErrorr   )rb   r%   states      r   _suggest_error_classConnection._suggest_error_class  sa     >>%^^**AJJ##D))Ug-=--- +    r   c                 B     U R                  5         S U l        g !    N= fr   )r   rg   ra   s    r   __del__Connection.__del__  s&    	$$& 	s    c                     U $ r   r   ra   s    r   	__enter__Connection.__enter__  s    r   c                 T    U(       a  U R                  5         g U R                  5         g r   )r   r   rb   exc_typeexc_valexc_tbs       r   __exit__Connection.__exit__  s    NNKKMr   c                    U R                   R                  S5      n/ nUR                  (       dT  [        UR                  S5      R
                  nUR                  U5        UR                  5         UR                  (       d  MT  AU$ )N   
TABLE_NAME)rg   
OpenSchemaEOFr   Fieldsr;   appendMoveNext)rb   schematablesr   s       r   get_table_namesConnection.get_table_names  sc    **2.**"6==,?EEDMM$OO *** r   )rs   r    rg   rn   ro   rp   rq   r#   r   rz   rh   ri   rx   rr   N)'__name__
__module____qualname____firstlineno__r   Warningr   r   	DataErrorr   r!   r   InternalErrorr   r   FetchFailedErrorr}   propertyrc   rt   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __static_attributes__r   r   r   r   r      s    kkGIIE''NI%%M++''N%%M--++++kkG 
! 0B 7>r/A*@4 DD.("!
0! 	r   r   c                      \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS$S jrS r\R&                  4S jrS rS rS rS%S jrS rS$S jrS%S jrS rS%S jrS rS%S jrS r S r!S r"S%S  jr#S! r$\%" \$SSS"5      r&S#r'g)&rm   i  c                    S U l         SU l        / U l        Xl        UR                  U l        / U l        SU l        S U l        / U l        0 U l	        SU l
        S U l        SU l        UR                  U l        SU l        UR                  U 5        [         (       a2  [#        S[$        ['        U 5      ['        U R                  5      4-  5        g g )NFr   r   z%s New cursor at %X on conn %X)command_ado_preparedr   
connectionrh   _parameter_namesrecordset_is_remoters
converterscolumnNamesnumberOfColumns_descriptionrowcountrq   	arraysizer   r}   r~   r   r   )rb   r  s     r   rt   Cursor.__init__!  s    "$$// "#(   &33d#70BtHb&9:; r   c                 .    [        U R                  S 5      $ r   )iterfetchonera   s    r   __iter__Cursor.__iter__8  s    DMM4((r   c                 ,    Xl         S U l        SU l        g )Nsetup)r  r  r  )rb   	operations     r   prepareCursor.prepare;  s      $r   c                 @    U R                  5       nU(       a  U$ [        er   )r  StopIteration)rb   rs     r   __next__Cursor.__next__@  s    MMOHr   c                     U $ )8Allow database cursors to be used with context managers.r   ra   s    r   r   Cursor.__enter__F  s    r   c                 $    U R                  5         g)r*  Nr   r   s       r   r   Cursor.__exit__J  s    

r   c                 j    U R                   nUc  [        R                  nU" U R                  XU5        g r   )rq   r   r   r  r   s       r   _raiseCursorErrorCursor._raiseCursorErrorN  s-    :))B
4??Dj9r   c                    / U l         0 U l        S U l        Ub  UR                  [        R
                  :X  a  S U l        SU l        g Xl        [        R                  U l
        UR                  R                  U l         U R                  R                  n[!        U R                  5       Hq  n[#        U R                  R                  U5      n U R                   R%                  X$R&                     5        X0R                  UR.                  R1                  5       '   Ms     g ! [         a    [        R                  n Nf = f! [(         a0    U R+                  [        R,                  SUR&                  -  5         Nf = f)Nr   z"Data column of Unknown ADO type=%s)r  r  r  Stater3   adStateClosedr  r  r   	RS_WIN_32recordset_formatr   r   r  r   r   ranger   r   r8   r   r0  r  r2   lower)rb   	recordsetvarConifs        r   build_column_infoCursor.build_column_infoT  s1     9??c6G6G#GDG#$D  #(//55	,__77F t++,A2A&&66N 01QVV\\^, -  	,++F	,  &&%%'Kaff'Ts$   =D 'D>D;:D;>7E87E8c           
          U R                   c  S U l        g / n[        U R                  5       H  n[	        U R                   R
                  U5      nU R                   R                  (       d  U R                   R                  (       a  S nOUR                  n[        UR                  [        R                  -  5      nUR                  UR                  UR                  UUR                   UR"                  UR$                  U45        M     Xl        g r   )r  r  r7  r  r   r   r   BOF
ActualSizer   r   r3   adFldMayBeNullr   r2   r8   DefinedSizer<   r=   )rb   rB   r;  r<  display_sizenull_oks         r   _makeDescriptionFromRSCursor._makeDescriptionFromRSq  s    77? $Dt++,A2Aww{{dggkk#  !||1<<#*<*<<=GKKFFFF MMKKNN
 -& !r   c                 \    U R                   (       d  U R                  5         U R                   $ r   )r  rF  ra   s    r   get_descriptionCursor.get_description  s#      '')   r   c                 Z    US:X  a  U R                  5       $ [        R                  X5        g )Ndescription)rI  r   __getattribute__r   s     r   r   Cursor.__getattr__  s*    = ''))	
r   c                 H   U R                   c  U R                  5         [        U[        5      (       a  U R                   U   nSUS   < S[        R
                  R                  US   [        US   5      S-   5      < SUS   < SUS	   < S
US   < SUS   < SUS   < 3nU$ )z-Format db_api description tuple for printing.zName= r   z, Type= r   r*   z, DispSize= r	   z, IntSize=    z, Precision=    z	, Scale=    z NullOK=   )rL  rF  rH   rl   r3   r6   r7   r9   )rb   drB   s      r   format_descriptionCursor.format_description  s    #'')a  #A !##AaD#ad)6G*GH!!!!!	 	 r   c                 z   U R                   c  g/ U l        U R                  (       aI  U R                  R                  [        R
                  :w  a!  U R                  R                  5         SU l        U(       d  U R                   R                  U 5        SU l         [        (       a  [        S[        U 5      -  5        gg)zClose the cursor now (rather than whenever __del__ is called).
The cursor will be unusable from this point forward; an Error (or subclass)
exception will be raised if any operation is attempted with the cursor.
Nzadodbapi Closed cursor at %X)r  r   r  r3  r3   r4  r   r   r}   r~   r   )rb   r   s     r   r   Cursor.close  s    
 ??"GG):)::GGMMODGOO))  	 702d8;< r   c                 4     U R                  5         g !    g = fr   r-  ra   s    r   r   Cursor.__del__  s    	JJL	s    c                 :   S U l         / U l        U R                  c!  U R                  [        R
                  S 5        g  [        S5      U l         U R                  R                  U R                   l        U R                  R                  U R                   l
        XR                   l        U R                  U R                   l        [        U R                  5      U R                   l        g !   U R                  [        R"                  SU R                  < 35         g = f)NzADODB.Commandz,Error creating new ADODB.Command object for )cmdr   r  r0  r   r   r   rg   ActiveConnectionrx   CommandTimeoutCommandTypecommandTextCommandTextr   r  Preparedr   )rb   command_types     r   _new_commandCursor._new_command  s    ??"""3#5#5t<	0DH(,(A(ADHH%&*oo&=&=DHH##/HH #'#3#3DHH  $T%7%7 8DHH	""!!>t?O?O>RSs   B)C( (0Dc           	      D   S U l         S nSn[        (       a  [        SU R                  -  5         U R                  R                  5       u  p UR                  U l        U R#                  U5        g ! [         a  nSn[        US5      (       a  U[        UR                  5      S-   -  nUSU R                  < S[        U R                  R                  S5      < 3-  nU R                  R                  5       nU R                  XT5         S nANS nAff = f!   X l         N= f)	Nr  zExecuting command="%s"rf   r"   r0   z	Command:
z
Parameters:
T)return_valuer}   r~   r`  r\  Executer   hasattrr9   r"   rC   
Parametersr  r   r0  RecordCountr  r=  )rb   r9  countr%   _messageklasss         r   _execute_commandCursor._execute_command  s     	7*T-=-==>	4#xx//1I	"%11DM 	y)  		4Hq&!!CK$..  !$(("5"5t< H OO88:E""533		4	"!Ms$   A0 D 0
D:BDDDc                     U R                   $ r   )r  ra   s    r   get_rowcountCursor.get_rowcount  s    }}r   c                    / n[        U R                  R                  5       GH;  n[        S:  a  [	        SUR
                  < S[        R                  UR                     < S[        R                  R                  UR                  [        UR                  5      S-   5      < SUR                  < SUR                  < SUR                  < S	UR                   < 35        ["        R$                  " UR                  ["        R&                  UR                     5      nUR                  [        R(                  :X  a  UU l        X0l        GM*  UR/                  U5        GM>     U$ )
zwith some providers, returned parameters and the .return_value are not available until
after the last recordset has been read.  In that case, you must coll nextset() until it
returns None, then call this method to get your returned information.r	   zReturned=Name: r(   r)   r*   r+   r,   r-   r.   )tupler\  rj  r}   r~   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r   convert_to_pythonr   adParamReturnValuereturnValuerg  r   )rb   retLstrA   pyObjects       r   get_returned_parametersCursor.get_returned_parameters  s     txx**+A{ q{{3++AFFCKBS4ST
 ,,QWWc6L6LQVV6TUH{{c444   %-!h'- ,. r   Nc                    / U l         Xl        U R                  [        R                  S9  U R                  USS9  [        S:  a*  [        S[        U R                  R                  S5      5        U R                  5         U R                  5       $ )a$  Call a stored database procedure with the given name.
The sequence of parameters must contain one entry for each
argument that the sproc expects. The result of the
call is returned as modified copy of the input
sequence.  Input parameters are left untouched, output and
input/output parameters replaced with possibly new values.

The sproc may also provide a result set as output,
which is available through the standard .fetch*() methods.
Extension: A "return_value" property may be set on the
cursor if the sproc defines an integer return value.
)rc  T)sprocr	   z Calling Stored Proc with Params=)r  r`  rd  r3   adCmdStoredProc_buildADOparameterListr}   r~   rC   r\  rj  ro  r{  )rb   procname
parameterss      r   callprocCursor.callproc"  s     !##s':':;##Jd#;Q;2!$(("5"5t< 	++--r   c                    U R                   S;   a  [        R                  " U5      u  ol        U$ U R                   S:X  d%  U R                   S:X  a2  [	        U[
        5      (       a  [        R                  " U5      u  ol        U$ )N)formatpyformatnameddynamic)rh   r   changeFormatToQmarkr  rH   r   changeNamedToQmarkrb   r!  r  s      r   _reformat_operationCursor._reformat_operation;  st    ??44/2/F/Fy/Q,I,  __'OOy(Z
G-L-L/2/E/E0,I, r   c           	         Xl         Uc  / nSnU(       a   U R                  R                  R                  5         [        S:  a9  [        S[        U R                  R                  S5      5        [        SU< 35        Sn[        U5      U R                  R                  R                  S-
  :w  a:  [        R                  " SU R                  R                  R                  S-
  -  5      e U(       d  U/ :w  Ga  S	nU(       a  U R                  (       aZ  [        U R                  5       H@  u  pE[        U R                  R                  U5      n [        XaU   UR                   U5        MB     g U H  n	[        U R                  R                  U5      nUR4                  [(        R6                  :X  a%  US-  n[        U R                  R                  U5      n [        XiUR                   U5        US-  nM     g U R                  (       a  U R                   Hy  n
X   n[        R8                  " U5      nU R                  R;                  X[(        R<                  5      n[        XkX5         U R                  R                  R?                  U5        M{     OU(       a^  U R                  R;                  S[(        R@                  [(        R6                  5      nU R                  R                  R?                  U5        U H  nSU-  n[        R8                  " U5      nU R                  R;                  X[(        R<                  5      n[        XkX5         U R                  R                  R?                  U5        US-  nM     U RB                  S:X  a  SU l!        g g g ! [        R                   a    [        (       a  [        S5         GNf = f! ["         a  nS
R%                  UR&                  [(        R*                  " UR                   5      UR,                  X   5      nU R/                  [        R0                  U SUR2                  < 35         S nAGM(  S nAff = f! ["         a  nS
R%                  UR&                  [(        R*                  " UR                   5      UR,                  U	5      nU R/                  [        R0                  U SUR2                  < 35         S nAGNS nAff = f! ["         a  nSR%                  UR&                  [(        R*                  " UR                   5      UR,                  U5      nU R/                  [        R0                  U SUR2                  < 35         S nAGMY  S nAff = f! ["         a  nSR%                  UR&                  [(        R*                  " UR                   5      UR,                  U5      nU R/                  [        R0                  U SUR2                  < 35         S nAGNS nAff = f)NFr	   zADO detected Params=TzProgram Parameters=r   z7You must supply %d parameters for this stored procedurezADO Parameter Refresh failedr   z.Error Converting Parameter {}: {}, {} <- {!r}
z->z,Error Building Parameter {}: {}, {} <- {!r}
z@RETURN_VALUEzp%ir   )"r  r\  rj  Refreshr}   r~   rC   rF   r   r   r   r   r  	enumerater   r]   r8   r   r  r2   r3   ado_type_namer;   r0  r  r"   r5   rw  pyTypeToADOTypeCreateParameteradParamInputAppendrU   r  )rb   r  r~  parameters_knownr;  pm_namerA   r%   rm  rV   	parm_nameelemrW   r   s                 r   r  Cursor._buildADOparameterListF  s   $J !##++-Q;.)$((*=*=tD /
~>?#'  z?dhh&9&9&?&?!&CC..Q88..44q8:  D
 J"$A((&/0E0E&F
+DHH,?,?C0 !g#6@P 'G" ",+DHH,?,?CKK3+A+AAFA /0C0CQ GA0166CST Q' ",, ((%)%:%:	)4"%"5"5d"; HH44%0@0@ -QgP HH//66q9 &;,  HH44+S]]C<R<R ++2215 *$qy"%"5"5d"; HH44 3+;+; -QgP HH//66q9 Q+ !+, %%0 & 1} % 99 789(  ) 	'X'_'_ ! # 1 1!&& 9 ! * 3	(H !22 #(2affZ/H 	(  ) 	'X'_'_ ! # 1 1!&& 9 ! %	(H !22 #(2affZ/H 	.  )  O V V$%FF$'$5$5aff$=$%GG$(	!" % !22 #(2affZ/H 8  )  O V V$%FF$'$5$5aff$=$%GG$(	!" % !22 #(2affZ/H sv   A)N OQ'%S%%U4*OO
QA8QQ
S"!A6SS"%
U1/A6U,,U14
W?>A6W::W?c                    U R                   ULd!  U R                  S:X  d  [        U S5      (       dR  U R                   ULa  SU l        Xl         / U l        U R                  S:X  d  U(       d  UOU R                  X5      U l        U R                  5         U R                  U5        [        S:  a*  [        S[        U R                  R                  S5      5        U R                  5         g)	aI  Prepare and execute a database operation (query or command).

Parameters may be provided as sequence or mapping and will be bound to variables in the operation.
Variables are specified in a database-specific notation
(see the module's paramstyle attribute for details). [5]
A reference to the operation will be retained by the cursor.
If the same operation object is passed in again, then the cursor
can optimize its behavior. This is most effective for algorithms
where the same operation is used, but different parameters are bound to it (many times).

For maximum efficiency when reusing an operation, it is best to use
the setinputsizes() method to specify the parameter types and sizes ahead of time.
It is legal for a parameter to not match the predefined information;
the implementation should compensate, possibly with a loss of efficiency.

The parameters may also be specified as list of tuples to e.g. insert multiple rows in
a single operation, but this kind of usage is depreciated: executemany() should be used instead.

Return value is not defined.

[5] The module will use the __getitem__ method of the parameters object to map either positions
(integers) or names (strings) to parameter values. This allows for both sequences and mappings
to be used as input.
The term "bound" refers to the process of binding an input value to a database execution buffer.
In practical terms, this means that the input value is directly used as a value in the operation.
The client should not be required to "escape" the value so that it can be used -- the value
should be equal to the actual database value.r   r`  FqmarkrP  zParams=TN)r  r  ri  r  rh   r  r`  rd  r  r}   r~   rC   r\  rj  ro  r  s      r   executeCursor.execute  s    : LL	)!!W,4//||9,%*"($&D! OOw.j --iD 
 	##J/Q;).txx/B/BDIJr   c                     [        5       U l        SnU R                  U5        U HG  nU R                  U R                  U5        U R
                  S:X  a  SnUS:w  d  M9  X0R
                  -  nMI     X0l        g)zPrepare a database operation (query or command)
and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters.

    Return values are not defined.
r   r  N)r   r   r"  r  r  r  )rb   r!  seq_of_parameterstotal_recordcountparamss        r   executemanyCursor.executemany  si     Y'FLLv.}}"$&! B&!]]2! ( *r   c                 ~   U R                   b  U R                  c!  U R                  [        R                  S5        gU R                  R
                  [        R                  :X  d6  U R                  R                  (       d  U R                  R                  (       a
  [        5       $ U(       a  U R                  R                  U5      nOU R                  R                  5       nU R                  [        R                  :X  a  [        U5      U R                  -  nO[        US   5      n[        R                   " X#U 5      nU$ )zoFetch rows from the current recordset.

limit -- Number of rows to fetch, or None (default) to fetch all rows.
Nz/fetch() on closed connection or empty query setr   )r  r  r0  r   r  r3  r3   r4  r@  r   r   GetRowsr6  RS_ARRAYrF   r  SQLrows)rb   limitado_resultsrY   fetchObjects        r   _fetchCursor._fetch  s    
 ??"dggo""$$&W 77==C---6M''//%0K''//+K!!S\\1 K D$8$88  Q(Fkk
 r   c                 L    / U l         U R                  S5      nU(       a  US   $ g)zFetch the next row of a query result set, returning a single sequence,
or None when no more data is available.

An Error (or subclass) exception is raised if the previous call to executeXXX()
did not produce any result set or no call was issued yet.
r   r   Nr   r  )rb   results     r   r  Cursor.fetchone$  s(     Q!9r   c                 P    / U l         Uc  U R                  nU R                  U5      $ )a}  Fetch the next set of rows of a query result, returning a list of tuples. An empty sequence is returned when no more rows are available.

The number of rows to fetch per call is specified by the parameter.
If it is not given, the cursor's arraysize determines the number of rows to be fetched.
The method should try to fetch as many rows as indicated by the size parameter.
If this is not possible due to the specified number of rows not being available,
fewer rows may be returned.

An Error (or subclass) exception is raised if the previous call to executeXXX()
did not produce any result set or no call was issued yet.

Note there are performance considerations involved with the size parameter.
For optimal performance, it is usually best to use the arraysize attribute.
If the size parameter is used, then it is best for it to retain the same value from
one fetchmany() call to the next.
)r   r  r  )rb   sizes     r   	fetchmanyCursor.fetchmany1  s(    " <>>D{{4  r   c                 0    / U l         U R                  5       $ )aU  Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples).

Note that the cursor's arraysize attribute
can affect the performance of this operation.
An Error (or subclass) exception is raised if the previous call to executeXXX()
did not produce any result set or no call was issued yet.
r  ra   s    r   fetchallCursor.fetchallG  s     {{}r   c                    / U l         U R                  b  U R                  c!  U R                  [        R
                  S5        g U R                  R                  5       nWS   nUc  gU R                  U5        g! [        R                   a4  nU R                  [        R                  UR                  5         SnAN^SnAff = f)a  Skip to the next available recordset, discarding any remaining rows from the current recordset.

If there are no more sets, the method returns None. Otherwise, it returns a true
value and subsequent calls to the fetch methods will return rows from the next result set.

An Error (or subclass) exception is raised if the previous call to executeXXX()
did not produce any result set or no call was issued yet.
Nz1nextset() on closed connection or empty query setr   T)r   r  r  r0  r   r!   NextRecordsetr   r   r   r"   r=  )rb   rsTupleexcr9  s       r   nextsetCursor.nextsetR  s     ??"dggo""$$D 	Dgg++-G AJ	y) ## 	D""3#8#8#((CC	Ds   A9 9C*B<<Cc                     g r   r   )rb   sizess     r   setinputsizesCursor.setinputsizesm      r   c                     g r   r   )rb   r  columns      r   setoutputsizeCursor.setoutputsizep  r  r   c                      U R                   c  U R                  nU$ U R                   SU R                   < 3n U$ !   S n U$ = f)Nz,parameters=)r  r`  )rb   rets     r   _last_queryCursor._last_querys  sY    	&&&
 
 ))*,t6IJ 
	C
s   < < Azreturns the last query executed)r  r  r  r  r\  r  r  r`  r  r  rq   r   r  r  rh   r6  r  rx  rg  r  r  Fr   )(r   r  r  r  rt   r  r"  r'  r   r   r0  r=  rF  rI  r   rU  r   r   r3   	adCmdTextrd  ro  rr  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  queryr	  r   r   r   rm   rm     s    4.)%
:1:!6!

(=. ), (*D@.2	||. `*$<!,	6 [$.OPEr   rm   __main__z! cannot be run as a main program.r  )+__doc____version__r   r   rK   osr   rj   rf   r   r3   r   r   r   rl   environr}   r~   r   r   win32com.clientr   ImportErrorwarningswarnImportWarningr   collections.abcr   r   r   adXactReadCommittedr   adUseClientr   pythonDateTimeConverterrO   rC   r]   r   rm   r   r   r   r   r   <module>r     s"  : 

$   	 
  G G"**/01G 	'NY( $/< //   ++-#L2lo of	v	Q v	Qr z


w)LL
MM k"G  YMM:MVWXYs   C C CC43C4