ó ÃÌ4]c@sÒdZddlmZddlmZddlmZddlmZddlmZddlmZdd lm Z dd l m Z dd lm Z dd lmZejd „ƒZdefd„ƒYZdS(sãProvides an abstraction for obtaining database schema information. Usage Notes: Here are some general conventions when accessing the low level inspector methods such as get_table_names, get_columns, etc. 1. Inspector methods return lists of dicts in most cases for the following reasons: * They're both standard types that can be serialized. * Using a dict instead of a tuple allows easy expansion of attributes. * Using a list for the outer structure maintains order and is easy to work with (e.g. list comprehension [d['name'] for d in cols]). 2. Records that contain a name, such as the column name in a column record use the key 'name'. So for most return values, each record will have a 'name' attribute.. i(t Connectablei(texc(t inspection(tsql(tutil(t operators(tschema(t TypeEngine(t deprecated(t topologicalcOsª|jddƒ}|dkr1|||||ŽS|jtd„|Dƒƒtd„|jƒDƒƒf}|j|ƒ}|dkr¦|||||Ž}|||/scssA|]7\}}t|tjtjtfƒr||fVqdS(N(R RR t int_typestfloat(R tktv((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pys 1s (tgettNonet__name__ttupletitems(tfntselftcontargstkwR tkeytret((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pytcache(s   t InspectorcBs¸eZdZd„Zed„ƒZejeƒd„ƒZ e d„ƒZ d„Z e jdd'ƒd(d(d „ƒZd(d „Zd „Zd „Zd(d „Zd(d„Zd(d„Zd(d„Zeddƒd(d„ƒZd(d„Zd(d„Zd(d„Zd(d„Zd(d„Zd(d„Zd)e d(d„Z!d„Z"d„Z#d„Z$d„Z%de&j'fd e&j(fd!e&j)fd"e&j*fgZ+d#„Z,d$„Z-d%„Z.d&„Z/RS(*smPerforms database schema inspection. The Inspector acts as a proxy to the reflection methods of the :class:`~sqlalchemy.engine.interfaces.Dialect`, providing a consistent interface as well as caching support for previously fetched metadata. A :class:`.Inspector` object is usually created via the :func:`.inspect` function:: from sqlalchemy import inspect, create_engine engine = create_engine('...') insp = inspect(engine) The inspection method above is equivalent to using the :meth:`.Inspector.from_engine` method, i.e.:: engine = create_engine('...') insp = Inspector.from_engine(engine) Where above, the :class:`~sqlalchemy.engine.interfaces.Dialect` may opt to return an :class:`.Inspector` subclass that provides additional methods specific to the dialect's target database. cCsn||_t|dƒr'|j|_n ||_|j|krR|jƒjƒn|jj|_i|_dS(sjInitialize a new :class:`.Inspector`. :param bind: a :class:`~sqlalchemy.engine.Connectable`, which is typically an instance of :class:`~sqlalchemy.engine.Engine` or :class:`~sqlalchemy.engine.Connection`. For a dialect-specific instance of :class:`.Inspector`, see :meth:`.Inspector.from_engine` tengineN(tbindthasattrR!tconnecttclosetdialectR (RR"((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyt__init__Xs  cCs,t|jdƒr"|jj|ƒSt|ƒS(s‘Construct a new dialect-specific Inspector object from the given engine or connection. :param bind: a :class:`~sqlalchemy.engine.Connectable`, which is typically an instance of :class:`~sqlalchemy.engine.Engine` or :class:`~sqlalchemy.engine.Connection`. This method differs from direct a direct constructor call of :class:`.Inspector` in that the :class:`~sqlalchemy.engine.interfaces.Dialect` is given a chance to provide a dialect-specific :class:`.Inspector` instance, which may provide additional methods. See the example at :class:`.Inspector`. t inspector(R#R&R(R (tclsR"((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyt from_enginetscCs tj|ƒS(N(R R*(R"((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyt_insp‹scCs |jjS(sÏReturn the default schema name presented by the dialect for the current engine's database user. E.g. this is typically ``public`` for PostgreSQL and ``dbo`` for SQL Server. (R&tdefault_schema_name(R((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyR,s cCs2t|jdƒr.|jj|jd|jƒSgS(s!Return all schema names. tget_schema_namesR (R#R&R-R"R (R((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyR-šs torder_bys1.0sþThe :paramref:`get_table_names.order_by` parameter is deprecated and will be removed in a future release. Please refer to :meth:`.Inspector.get_sorted_table_and_fkc_names` for a more comprehensive solution to resolving foreign key cycles between tables.cCsÑt|jdƒr6|jj|j|d|jƒ}n|jj|ƒ}|dkrÍg}xU|D]M}xD|j||ƒD]0}||dkrz|j|d|fƒqzqzWqaWt t j ||ƒƒ}n|S(sÀReturn all table names in referred to within a particular schema. The names are expected to be real tables only, not views. Views are instead returned using the :meth:`.Inspector.get_view_names` method. :param schema: Schema name. If ``schema`` is left at ``None``, the database's default schema is used, else the named schema is searched. If the database does not support named schemas, behavior is undefined if ``schema`` is not passed as ``None``. For special quoting, use :class:`.quoted_name`. :param order_by: Optional, may be the string "foreign_key" to sort the result on foreign key dependencies. Does not automatically resolve cycles, and will raise :class:`.CircularDependencyError` if cycles exist. .. seealso:: :meth:`.Inspector.get_sorted_table_and_fkc_names` :attr:`.MetaData.sorted_tables` tget_table_namesR t foreign_keytreferred_table( R#R&R/R"R R!t table_namestget_foreign_keystappendtlistR tsort(RRR.ttnamesttuplesttnametfkey((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyR/¤s%   "c sµt|jdƒr6|jj|j|d|jƒ}n|jj|ƒ}tƒ}tƒ}i}x‚|D]z}|j||ƒ}tg|D]}|d^q‰ƒ||siN(R#R&R/R"R R!R2tsetR3taddR5R R6RtCircularDependencyErrortedgestremovetupdatet differenceR( RRR7R8tremaining_fkcstfknames_for_tableR9tfkeystfkR:tcandidate_sortterr((R=sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pytget_sorted_table_and_fkc_namesØs0    ' " #&cCs|jj|jd|jƒS(sÊreturn a list of temporary table names for the current bind. This method is unsupported by most dialects; currently only SQLite implements it. .. versionadded:: 1.0.0 R (R&tget_temp_table_namesR"R (R((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRLs cCs|jj|jd|jƒS(sÉreturn a list of temporary view names for the current bind. This method is unsupported by most dialects; currently only SQLite implements it. .. versionadded:: 1.0.0 R (R&tget_temp_view_namesR"R (R((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRMs cKs;t|jdƒr7|jj|j||d|j|SiS(sÑReturn a dictionary of options specified when the table of the given name was created. This currently includes some options that apply to MySQL tables. :param table_name: string name of the table. For special quoting, use :class:`.quoted_name`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. tget_table_optionsR (R#R&RNR"R (Rt table_nameRR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRN*s cCs|jj|j|d|jƒS(s±Return all view names in `schema`. :param schema: Optional, retrieve names from a non-default schema. For special quoting, use :class:`.quoted_name`. R (R&tget_view_namesR"R (RR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRP>s cCs"|jj|j||d|jƒS(s±Return definition for `view_name`. :param schema: Optional, retrieve names from a non-default schema. For special quoting, use :class:`.quoted_name`. R (R&tget_view_definitionR"R (Rt view_nameR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRQJs cKse|jj|j||d|j|}x7|D]/}|d}t|tƒs.|ƒ|dhs(RR?R"R&tschema_for_objectR;tdicttreflection_optionsRNR_t_validate_dialect_kwargsRtpy2kR tstrtdecodetencodingtFalseRTtTruet_reflect_columnRtNoSuchTableErrort _reflect_pkt _reflect_fkt_reflect_indexest_reflect_unique_constraintst_reflect_check_constraintst_reflect_table_comment(RR`tinclude_columnstexclude_columnst resolve_fkst _extend_onR&RRORcttbl_optst found_tabletcols_by_orig_nametcol_d((R`sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyt reflecttable:sŠ        c s±ˆd}|jj||ˆƒˆd}|r<||ksN|rR||krRdSˆd}t‡fd†dddddd gDƒƒ} d ˆkrª| jˆd ƒng} ˆjd ƒdk rCˆd } t| tjj ƒrüt j | d t ƒ} n7t| t j ƒs3t j tjˆd ƒd t ƒ} n| j| ƒnd ˆkrb|jˆ| ƒnt j||| | Ž||<} | j|jkr t | _n|j| ƒdS(NR;RSc3s+|]!}|ˆkr|ˆ|fVqdS(N((R R(Rz(sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pys Óstnullablet autoincrementtquotetinfoRtcommenttdialect_optionstdefaultt _reflectedtsequence(tdispatchtcolumn_reflectRbRCRRR Rtelementst TextClauset sa_schemat DefaultClauseRjt FetchedValuettextR4t_reflect_col_sequencetColumnRt primary_keyt append_column( RR`RzRsRtRyt orig_nameR;RWtcol_kwtcolargsR‚tcol((RzsO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRkÀsB        cCs{d|krw|d}tj|dddƒ}d|krK|d|_nd|krg|d|_n|j|ƒndS(NR„R;itstartt increment(R‰tSequenceR•R–R4(RRzR“tseqR„((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRùs    c Csƒ|j|||j}|rg|dD](}||kr)||kr)||^q)}|jdƒ|j_|jj|ƒndS(NRXR;(RYR_RRR;t_reload( RRORR`RyRttpk_constpktpk_cols((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRms(c  CsÙ|j|||j} xº| D]²} | d} g| dD]%} | |krY|| jn| ^q:} |r†t| ƒj|ƒr†qn| d}| d}| d}g}|dk r#|rðtj||jdt d|d|j d ||nxš|D]%}|j d j |||gƒƒq÷Wnj|r`tj||jdt d|j dtj d ||nx*|D]"}|j d j ||gƒƒqgWd | kr¦| d }ni}|jtj| || d t |ƒqWdS( NR;RXtreferred_schemaR1treferred_columnstautoloadRt autoload_withRvt.toptionst link_to_name(R3R_RR>t intersectionRR‰tTabletmetadataRjR"R4tjoint BLANK_SCHEMAtappend_constrainttForeignKeyConstraint(RRORR`RyRtRuRvRcRGtfkey_dtconnametcRXRR1RžtrefspectcolumnR¢((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRns^   3                  tasctdesct nullsfirstt nullslastc CsÓ|j||ƒ}xº|D]²} | d} | d} | jdiƒ} | d} | jddƒ}| jdiƒ}| jdƒ}|rÄt| ƒj|ƒ rÄtjd |d j| ƒfƒqn|rÐqng}xº| D]²}y'||krü||n |j|}Wn.tk r:tjd |||fƒqÝnX| j|d ƒ}x2|j D]'\}}||krW||ƒ}qWqWW|j |ƒqÝWt j | d ||t t|jƒƒd| fgƒŽqWdS(NR;t column_namestcolumn_sortingtuniqueRStindexRtduplicates_constraints5Omitting %s key for (%s), key covers omitted columns.s, s5%s key '%s' was not located in columns for table '%s't_table((R[RR>tissubsetRtwarnR§R­tKeyErrort_index_sort_exprsR4R‰tIndexRbR5R(RRORR`RyRsRtRctindexestindex_dR;tcolumnsRµR¶tflavorRt duplicatestidx_colsR­tidx_colt c_sortingRtop((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRogsF        cCs=y|j||ƒ}Wntk r*dSXx |D]} | d} | d} | jdƒ} |r—t| ƒj|ƒ r—tjddj| ƒƒq2n| r£q2ng} xm| D]e}y'||krÏ||n |j|}Wn(t k rtjd||fƒq°X| j |ƒq°W|j t j d| | Œƒq2WdS(NR;R´tduplicates_indexsDOmitting unique constraint key for (%s), key covers omitted columns.s, sDunique constraint key '%s' was not located in columns for table '%s'(R\tNotImplementedErrorRR>RºRR»R§R­R¼R4R©R‰tUniqueConstraint(RRORR`RyRsRtRct constraintstconst_dR¬RÁRÃtconstrained_colsR­tconstrained_col((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRp¡s6       c CsVy|j||ƒ}Wntk r*dSXx$|D]} |jtj| ƒq2WdS(N(R^RÉR©R‰tCheckConstraint( RRORR`RyRsRtRcRËRÌ((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRqÔs   cCsDy|j||ƒ}Wntk r*dSX|jddƒ|_dS(NRŒ(R]RÉRRR€(RRORR`Rct comment_dict((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRrçs  (s1.0sþThe :paramref:`get_table_names.order_by` parameter is deprecated and will be removed in a future release. Please refer to :meth:`.Inspector.get_sorted_table_and_fkc_names` for a more comprehensive solution to resolving foreign key cycles between tables.N((0Rt __module__t__doc__R't classmethodR*Rt _inspectsRR+tpropertyR,R-Rtdeprecated_paramsRR/RKRLRMRNRPRQRTRRZRYR3R[R\R]R^RjR{RkRRmRnRtasc_optdesc_opt nullsfirst_opt nullslast_opR½RoRpRqRr(((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyR =sT  * 8  (  # (    € 9  I    : 3 N(RÒtbaseRtRRRRRRR‰t sql.type_apiRRR t decoratorRtobjectR (((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyts