<s> """<STR_LIT>""" <EOL> import operator <EOL> import re <EOL> from sqlalchemy . sql import compiler , expression , text , bindparam <EOL> from sqlalchemy . engine import default , base , reflection <EOL> from sqlalchemy import types as sqltypes <EOL> from sqlalchemy . sql import operators as sql_operators <EOL> from sqlalchemy import schema as sa_schema <EOL> from sqlalchemy import util , sql , exc <EOL> from sqlalchemy . types import CHAR , VARCHAR , TIME , NCHAR , NVARCHAR , TEXT , DATE , DATETIME , FLOAT , NUMERIC , BIGINT , INT , INTEGER , SMALLINT , BINARY , VARBINARY , DECIMAL , TIMESTAMP , Unicode , UnicodeText , REAL <EOL> RESERVED_WORDS = set ( [ <EOL> "<STR_LIT>" , "<STR_LIT:all>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT:date>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:default>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:end>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:float>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:index>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:int>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT:key>" , "<STR_LIT>" , "<STR_LIT:left>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT:message>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:null>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT:right>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT:start>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT:time>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT:to>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT:user>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> ] ) <EOL> class _SybaseUnitypeMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def result_processor ( self , dialect , coltype ) : <EOL> def process ( value ) : <EOL> if value is not None : <EOL> return str ( value ) <EOL> else : <EOL> return None <EOL> return process <EOL> class UNICHAR ( _SybaseUnitypeMixin , sqltypes . Unicode ) : <EOL> __visit_name__ = '<STR_LIT>' <EOL> class UNIVARCHAR ( _SybaseUnitypeMixin , sqltypes . Unicode ) : <EOL> __visit_name__ = '<STR_LIT>' <EOL> class UNITEXT ( _SybaseUnitypeMixin , sqltypes . UnicodeText ) : <EOL> __visit_name__ = '<STR_LIT>' <EOL> class TINYINT ( sqltypes . Integer ) : <EOL> __visit_name__ = '<STR_LIT>' <EOL> class BIT ( sqltypes . TypeEngine ) : <EOL> __visit_name__ = '<STR_LIT>' <EOL> class MONEY ( sqltypes . TypeEngine ) : <EOL> __visit_name__ = "<STR_LIT>" <EOL> class SMALLMONEY ( sqltypes . TypeEngine ) : <EOL> __visit_name__ = "<STR_LIT>" <EOL> class UNIQUEIDENTIFIER ( sqltypes . TypeEngine ) : <EOL> __visit_name__ = "<STR_LIT>" <EOL> class IMAGE ( sqltypes . LargeBinary ) : <EOL> __visit_name__ = '<STR_LIT>' <EOL> class SybaseTypeCompiler ( compiler . GenericTypeCompiler ) : <EOL> def visit_large_binary ( self , type_ ) : <EOL> return self . visit_IMAGE ( type_ ) <EOL> def visit_boolean ( self , type_ ) : <EOL> return self . visit_BIT ( type_ ) <EOL> def visit_unicode ( self , type_ ) : <EOL> return self . visit_NVARCHAR ( type_ ) <EOL> def visit_UNICHAR ( self , type_ ) : <EOL> return "<STR_LIT>" % type_ . length <EOL> def visit_UNIVARCHAR ( self , type_ ) : <EOL> return "<STR_LIT>" % type_ . length <EOL> def visit_UNITEXT ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_TINYINT ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_IMAGE ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_BIT ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_MONEY ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_SMALLMONEY ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> def visit_UNIQUEIDENTIFIER ( self , type_ ) : <EOL> return "<STR_LIT>" <EOL> ischema_names = { <EOL> '<STR_LIT>' : BIGINT , <EOL> '<STR_LIT:int>' : INTEGER , <EOL> '<STR_LIT>' : INTEGER , <EOL> '<STR_LIT>' : SMALLINT , <EOL> '<STR_LIT>' : TINYINT , <EOL> '<STR_LIT>' : BIGINT , <EOL> '<STR_LIT>' : INTEGER , <EOL> '<STR_LIT>' : SMALLINT , <EOL> '<STR_LIT>' : NUMERIC , <EOL> '<STR_LIT>' : DECIMAL , <EOL> '<STR_LIT>' : DECIMAL , <EOL> '<STR_LIT:float>' : FLOAT , <EOL> '<STR_LIT>' : NUMERIC , <EOL> '<STR_LIT>' : NUMERIC , <EOL> '<STR_LIT>' : REAL , <EOL> '<STR_LIT>' : SMALLMONEY , <EOL> '<STR_LIT>' : MONEY , <EOL> '<STR_LIT>' : DATETIME , <EOL> '<STR_LIT>' : DATETIME , <EOL> '<STR_LIT:date>' : DATE , <EOL> '<STR_LIT:time>' : TIME , <EOL> '<STR_LIT>' : CHAR , <EOL> '<STR_LIT>' : CHAR , <EOL> '<STR_LIT>' : VARCHAR , <EOL> '<STR_LIT>' : VARCHAR , <EOL> '<STR_LIT>' : VARCHAR , <EOL> '<STR_LIT>' : UNICHAR , <EOL> '<STR_LIT>' : UNIVARCHAR , <EOL> '<STR_LIT>' : NCHAR , <EOL> '<STR_LIT>' : NCHAR , <EOL> '<STR_LIT>' : NCHAR , <EOL> '<STR_LIT>' : NVARCHAR , <EOL> '<STR_LIT>' : NVARCHAR , <EOL> '<STR_LIT>' : NVARCHAR , <EOL> '<STR_LIT>' : NVARCHAR , <EOL> '<STR_LIT:text>' : TEXT , <EOL> '<STR_LIT>' : UNITEXT , <EOL> '<STR_LIT>' : BINARY , <EOL> '<STR_LIT>' : VARBINARY , <EOL> '<STR_LIT:image>' : IMAGE , <EOL> '<STR_LIT>' : BIT , <EOL> '<STR_LIT>' : TEXT , <EOL> '<STR_LIT>' : TIMESTAMP , <EOL> '<STR_LIT>' : UNIQUEIDENTIFIER , <EOL> } <EOL> class SybaseInspector ( reflection . Inspector ) : <EOL> def __init__ ( self , conn ) : <EOL> reflection . Inspector . __init__ ( self , conn ) <EOL> def get_table_id ( self , table_name , schema = None ) : <EOL> """<STR_LIT>""" <EOL> return self . dialect . get_table_id ( self . bind , table_name , schema , <EOL> info_cache = self . info_cache ) <EOL> class SybaseExecutionContext ( default . DefaultExecutionContext ) : <EOL> _enable_identity_insert = False <EOL> def set_ddl_autocommit ( self , connection , value ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def pre_exec ( self ) : <EOL> if self . isinsert : <EOL> tbl = self . compiled . statement . table <EOL> seq_column = tbl . _autoincrement_column <EOL> insert_has_sequence = seq_column is not None <EOL> if insert_has_sequence : <EOL> self . _enable_identity_insert = seq_column . key in self . compiled_parameters [ <NUM_LIT:0> ] <EOL> else : <EOL> self . _enable_identity_insert = False <EOL> if self . _enable_identity_insert : <EOL> self . cursor . execute ( <EOL> "<STR_LIT>" % <EOL> self . dialect . identifier_preparer . format_table ( tbl ) ) <EOL> if self . isddl : <EOL> if not self . should_autocommit : <EOL> raise exc . InvalidRequestError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . root_connection . engine . logger . info ( <EOL> "<STR_LIT>" ) <EOL> self . set_ddl_autocommit ( <EOL> self . root_connection . connection . connection , <EOL> True ) <EOL> def post_exec ( self ) : <EOL> if self . isddl : <EOL> self . set_ddl_autocommit ( self . root_connection , False ) <EOL> if self . _enable_identity_insert : <EOL> self . cursor . execute ( <EOL> "<STR_LIT>" % <EOL> self . dialect . identifier_preparer . <EOL> format_table ( self . compiled . statement . table ) <EOL> ) <EOL> def get_lastrowid ( self ) : <EOL> cursor = self . create_cursor ( ) <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> lastrowid = cursor . fetchone ( ) [ <NUM_LIT:0> ] <EOL> cursor . close ( ) <EOL> return lastrowid <EOL> class SybaseSQLCompiler ( compiler . SQLCompiler ) : <EOL> ansi_bind_rules = True <EOL> extract_map = util . update_copy ( <EOL> compiler . SQLCompiler . extract_map , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> def get_select_precolumns ( self , select ) : <EOL> s = select . _distinct and "<STR_LIT>" or "<STR_LIT>" <EOL> if select . _limit : <EOL> s += "<STR_LIT>" % ( select . _limit , ) <EOL> if select . _offset : <EOL> if not select . _limit : <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" % ( select . _offset + <NUM_LIT:1> , ) <EOL> return s <EOL> def get_from_hint_text ( self , table , text ) : <EOL> return text <EOL> def limit_clause ( self , select ) : <EOL> return "<STR_LIT>" <EOL> def visit_extract ( self , extract , ** kw ) : <EOL> field = self . extract_map . get ( extract . field , extract . field ) <EOL> return '<STR_LIT>' % ( <EOL> field , self . process ( extract . expr , ** kw ) ) <EOL> def visit_now_func ( self , fn , ** kw ) : <EOL> return "<STR_LIT>" <EOL> def for_update_clause ( self , select ) : <EOL> return '<STR_LIT>' <EOL> def order_by_clause ( self , select , ** kw ) : <EOL> kw [ '<STR_LIT>' ] = True <EOL> order_by = self . process ( select . _order_by_clause , ** kw ) <EOL> if order_by and ( not self . is_subquery ( ) or select . _limit ) : <EOL> return "<STR_LIT>" + order_by <EOL> else : <EOL> return "<STR_LIT>" <EOL> class SybaseDDLCompiler ( compiler . DDLCompiler ) : <EOL> def get_column_specification ( self , column , ** kwargs ) : <EOL> colspec = self . preparer . format_column ( column ) + "<STR_LIT:U+0020>" + self . dialect . type_compiler . process ( column . type ) <EOL> if column . table is None : <EOL> raise exc . CompileError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> seq_col = column . table . _autoincrement_column <EOL> if seq_col is column : <EOL> sequence = isinstance ( column . default , sa_schema . Sequence ) and column . default <EOL> if sequence : <EOL> start , increment = sequence . start or <NUM_LIT:1> , sequence . increment or <NUM_LIT:1> <EOL> else : <EOL> start , increment = <NUM_LIT:1> , <NUM_LIT:1> <EOL> if ( start , increment ) == ( <NUM_LIT:1> , <NUM_LIT:1> ) : <EOL> colspec += "<STR_LIT>" <EOL> else : <EOL> colspec += "<STR_LIT>" % ( start , increment ) <EOL> else : <EOL> default = self . get_column_default_string ( column ) <EOL> if default is not None : <EOL> colspec += "<STR_LIT>" + default <EOL> if column . nullable is not None : <EOL> if not column . nullable or column . primary_key : <EOL> colspec += "<STR_LIT>" <EOL> else : <EOL> colspec += "<STR_LIT>" <EOL> return colspec <EOL> def visit_drop_index ( self , drop ) : <EOL> index = drop . element <EOL> return "<STR_LIT>" % ( <EOL> self . preparer . quote_identifier ( index . table . name ) , <EOL> self . _prepared_index_name ( drop . element , <EOL> include_schema = False ) <EOL> ) <EOL> class SybaseIdentifierPreparer ( compiler . IdentifierPreparer ) : <EOL> reserved_words = RESERVED_WORDS <EOL> class SybaseDialect ( default . DefaultDialect ) : <EOL> name = '<STR_LIT>' <EOL> supports_unicode_statements = False <EOL> supports_sane_rowcount = False <EOL> supports_sane_multi_rowcount = False <EOL> supports_native_boolean = False <EOL> supports_unicode_binds = False <EOL> postfetch_lastrowid = True <EOL> colspecs = { } <EOL> ischema_names = ischema_names <EOL> type_compiler = SybaseTypeCompiler <EOL> statement_compiler = SybaseSQLCompiler <EOL> ddl_compiler = SybaseDDLCompiler <EOL> preparer = SybaseIdentifierPreparer <EOL> inspector = SybaseInspector <EOL> construct_arguments = [ ] <EOL> def _get_default_schema_name ( self , connection ) : <EOL> return connection . scalar ( <EOL> text ( "<STR_LIT>" , <EOL> typemap = { '<STR_LIT>' : Unicode } ) <EOL> ) <EOL> def initialize ( self , connection ) : <EOL> super ( SybaseDialect , self ) . initialize ( connection ) <EOL> if self . server_version_info is not None and self . server_version_info < ( <NUM_LIT:15> , ) : <EOL> self . max_identifier_length = <NUM_LIT:30> <EOL> else : <EOL> self . max_identifier_length = <NUM_LIT:255> <EOL> def get_table_id ( self , connection , table_name , schema = None , ** kw ) : <EOL> """<STR_LIT>""" <EOL> table_id = None <EOL> if schema is None : <EOL> schema = self . default_schema_name <EOL> TABLEID_SQL = text ( """<STR_LIT>""" ) <EOL> if util . py2k : <EOL> if isinstance ( schema , unicode ) : <EOL> schema = schema . encode ( "<STR_LIT:ascii>" ) <EOL> if isinstance ( table_name , unicode ) : <EOL> table_name = table_name . encode ( "<STR_LIT:ascii>" ) <EOL> result = connection . execute ( TABLEID_SQL , <EOL> schema_name = schema , <EOL> table_name = table_name ) <EOL> table_id = result . scalar ( ) <EOL> if table_id is None : <EOL> raise exc . NoSuchTableError ( table_name ) <EOL> return table_id <EOL> @ reflection . cache <EOL> def get_columns ( self , connection , table_name , schema = None , ** kw ) : <EOL> table_id = self . get_table_id ( connection , table_name , schema , <EOL> info_cache = kw . get ( "<STR_LIT>" ) ) <EOL> COLUMN_SQL = text ( """<STR_LIT>""" ) <EOL> results = connection . execute ( COLUMN_SQL , table_id = table_id ) <EOL> columns = [ ] <EOL> for ( name , type_ , nullable , autoincrement , default , precision , scale , <EOL> length ) in results : <EOL> col_info = self . _get_column_info ( name , type_ , bool ( nullable ) , <EOL> bool ( autoincrement ) , <EOL> default , precision , scale , <EOL> length ) <EOL> columns . append ( col_info ) <EOL> return columns <EOL> def _get_column_info ( self , name , type_ , nullable , autoincrement , default , <EOL> precision , scale , length ) : <EOL> coltype = self . ischema_names . get ( type_ , None ) <EOL> kwargs = { } <EOL> if coltype in ( NUMERIC , DECIMAL ) : <EOL> args = ( precision , scale ) <EOL> elif coltype == FLOAT : <EOL> args = ( precision , ) <EOL> elif coltype in ( CHAR , VARCHAR , UNICHAR , UNIVARCHAR , NCHAR , NVARCHAR ) : <EOL> args = ( length , ) <EOL> else : <EOL> args = ( ) <EOL> if coltype : <EOL> coltype = coltype ( * args , ** kwargs ) <EOL> else : <EOL> util . warn ( "<STR_LIT>" % <EOL> ( type_ , name ) ) <EOL> coltype = sqltypes . NULLTYPE <EOL> if default : <EOL> default = re . sub ( "<STR_LIT>" , "<STR_LIT>" , default ) . strip ( ) <EOL> default = re . sub ( "<STR_LIT>" , lambda m : m . group ( <NUM_LIT:1> ) , default ) <EOL> else : <EOL> default = None <EOL> column_info = dict ( name = name , type = coltype , nullable = nullable , <EOL> default = default , autoincrement = autoincrement ) <EOL> return column_info <EOL> @ reflection . cache <EOL> def get_foreign_keys ( self , connection , table_name , schema = None , ** kw ) : <EOL> table_id = self . get_table_id ( connection , table_name , schema , <EOL> info_cache = kw . get ( "<STR_LIT>" ) ) <EOL> table_cache = { } <EOL> column_cache = { } <EOL> foreign_keys = [ ] <EOL> table_cache [ table_id ] = { "<STR_LIT:name>" : table_name , "<STR_LIT>" : schema } <EOL> COLUMN_SQL = text ( """<STR_LIT>""" ) <EOL> results = connection . execute ( COLUMN_SQL , table_id = table_id ) <EOL> columns = { } <EOL> for col in results : <EOL> columns [ col [ "<STR_LIT:id>" ] ] = col [ "<STR_LIT:name>" ] <EOL> column_cache [ table_id ] = columns <EOL> REFCONSTRAINT_SQL = text ( """<STR_LIT>""" ) <EOL> referential_constraints = connection . execute ( REFCONSTRAINT_SQL , <EOL> table_id = table_id ) <EOL> REFTABLE_SQL = text ( """<STR_LIT>""" ) <EOL> for r in referential_constraints : <EOL> reftable_id = r [ "<STR_LIT>" ] <EOL> if reftable_id not in table_cache : <EOL> c = connection . execute ( REFTABLE_SQL , table_id = reftable_id ) <EOL> reftable = c . fetchone ( ) <EOL> c . close ( ) <EOL> table_info = { "<STR_LIT:name>" : reftable [ "<STR_LIT:name>" ] , "<STR_LIT>" : None } <EOL> if ( schema is not None or <EOL> reftable [ "<STR_LIT>" ] != self . default_schema_name ) : <EOL> table_info [ "<STR_LIT>" ] = reftable [ "<STR_LIT>" ] <EOL> table_cache [ reftable_id ] = table_info <EOL> results = connection . execute ( COLUMN_SQL , table_id = reftable_id ) <EOL> reftable_columns = { } <EOL> for col in results : <EOL> reftable_columns [ col [ "<STR_LIT:id>" ] ] = col [ "<STR_LIT:name>" ] <EOL> column_cache [ reftable_id ] = reftable_columns <EOL> reftable = table_cache [ reftable_id ] <EOL> reftable_columns = column_cache [ reftable_id ] <EOL> constrained_columns = [ ] <EOL> referred_columns = [ ] <EOL> for i in range ( <NUM_LIT:1> , r [ "<STR_LIT:count>" ] + <NUM_LIT:1> ) : <EOL> constrained_columns . append ( columns [ r [ "<STR_LIT>" % i ] ] ) <EOL> referred_columns . append ( reftable_columns [ r [ "<STR_LIT>" % i ] ] ) <EOL> fk_info = { <EOL> "<STR_LIT>" : constrained_columns , <EOL> "<STR_LIT>" : reftable [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : reftable [ "<STR_LIT:name>" ] , <EOL> "<STR_LIT>" : referred_columns , <EOL> "<STR_LIT:name>" : r [ "<STR_LIT:name>" ] <EOL> } <EOL> foreign_keys . append ( fk_info ) <EOL> return foreign_keys <EOL> @ reflection . cache <EOL> def get_indexes ( self , connection , table_name , schema = None , ** kw ) : <EOL> table_id = self . get_table_id ( connection , table_name , schema , <EOL> info_cache = kw . get ( "<STR_LIT>" ) ) <EOL> INDEX_SQL = text ( """<STR_LIT>""" ) <EOL> results = connection . execute ( INDEX_SQL , table_id = table_id ) <EOL> indexes = [ ] <EOL> for r in results : <EOL> column_names = [ ] <EOL> for i in range ( <NUM_LIT:1> , r [ "<STR_LIT:count>" ] ) : <EOL> column_names . append ( r [ "<STR_LIT>" % ( i , ) ] ) <EOL> index_info = { "<STR_LIT:name>" : r [ "<STR_LIT:name>" ] , <EOL> "<STR_LIT>" : bool ( r [ "<STR_LIT>" ] ) , <EOL> "<STR_LIT>" : column_names } <EOL> indexes . append ( index_info ) <EOL> return indexes <EOL> @ reflection . cache <EOL> def get_pk_constraint ( self , connection , table_name , schema = None , ** kw ) : <EOL> table_id = self . get_table_id ( connection , table_name , schema , <EOL> info_cache = kw . get ( "<STR_LIT>" ) ) <EOL> PK_SQL = text ( """<STR_LIT>""" ) <EOL> results = connection . execute ( PK_SQL , table_id = table_id ) <EOL> pks = results . fetchone ( ) <EOL> results . close ( ) <EOL> constrained_columns = [ ] <EOL> for i in range ( <NUM_LIT:1> , pks [ "<STR_LIT:count>" ] + <NUM_LIT:1> ) : <EOL> constrained_columns . append ( pks [ "<STR_LIT>" % ( i , ) ] ) <EOL> return { "<STR_LIT>" : constrained_columns , <EOL> "<STR_LIT:name>" : pks [ "<STR_LIT:name>" ] } <EOL> @ reflection . cache <EOL> def get_schema_names ( self , connection , ** kw ) : <EOL> SCHEMA_SQL = text ( "<STR_LIT>" ) <EOL> schemas = connection . execute ( SCHEMA_SQL ) <EOL> return [ s [ "<STR_LIT:name>" ] for s in schemas ] <EOL> @ reflection . cache <EOL> def get_table_names ( self , connection , schema = None , ** kw ) : <EOL> if schema is None : <EOL> schema = self . default_schema_name <EOL> TABLE_SQL = text ( """<STR_LIT>""" ) <EOL> if util . py2k : <EOL> if isinstance ( schema , unicode ) : <EOL> schema = schema . encode ( "<STR_LIT:ascii>" ) <EOL> tables = connection . execute ( TABLE_SQL , schema_name = schema ) <EOL> return [ t [ "<STR_LIT:name>" ] for t in tables ] <EOL> @ reflection . cache <EOL> def get_view_definition ( self , connection , view_name , schema = None , ** kw ) : <EOL> if schema is None : <EOL> schema = self . default_schema_name <EOL> VIEW_DEF_SQL = text ( """<STR_LIT>""" ) <EOL> if util . py2k : <EOL> if isinstance ( view_name , unicode ) : <EOL> view_name = view_name . encode ( "<STR_LIT:ascii>" ) <EOL> view = connection . execute ( VIEW_DEF_SQL , view_name = view_name ) <EOL> return view . scalar ( ) <EOL> @ reflection . cache <EOL> def get_view_names ( self , connection , schema = None , ** kw ) : <EOL> if schema is None : <EOL> schema = self . default_schema_name <EOL> VIEW_SQL = text ( """<STR_LIT>""" ) <EOL> if util . py2k : <EOL> if isinstance ( schema , unicode ) : <EOL> schema = schema . encode ( "<STR_LIT:ascii>" ) <EOL> views = connection . execute ( VIEW_SQL , schema_name = schema ) <EOL> return [ v [ "<STR_LIT:name>" ] for v in views ] <EOL> def has_table ( self , connection , table_name , schema = None ) : <EOL> try : <EOL> self . get_table_id ( connection , table_name , schema ) <EOL> except exc . NoSuchTableError : <EOL> return False <EOL> else : <EOL> return True </s>
