I've found a solution to the reflect problem, but, given my limited 
knowledge of SQLAlchemy, I do not know how it performs and whether there is 
better one.


from sqlalchemy import create_engine, event, MetaData
from sqlalchemy.schema import SchemaItem, Table
from sqlalchemy.sql.elements import quoted_name
engine = create_engine("oracle://MYSCHEMA:myschema@127.0.0.1:1521/XE")
schemaname = "MYSCHEMA"
metadata = MetaData(
    bind=engine,
    schema=schemaname,
    reflect=True,
    quote_schema=True)


def fix_case(target, parent):
    if type(parent) == MetaData:
        (name, dest) = target.name, target
    else:
        (name, dest) = parent.name, parent
    if name.isupper():
        name = name.lower()
    setattr(dest, "name", quoted_name(name, quote=True))

event.listen(SchemaItem, "after_parent_attach" , fix_case)

tablename = "y"
Table(
    quoted_name(tablename, quote=True),
    metadata,
    schema=schemaname,
    autoload=True,
    extend_existing=True)



Il giorno venerdì 2 ottobre 2015 17:12:12 UTC+2, Michael Bayer ha scritto:
>
>
>
> On 10/2/15 9:44 AM, Massimiliano della Rovere wrote:
>
> cx-Oracle==5.2
> SQLAlchemy==1.0.8
>
> I'm in the weird situation of dealing with an Oracle database with 
> lowercase identifiers (they were created by another software that escapes 
> always table/schema/index identifiers).
>
> I get a "NoSuchTableError" whenever I issue a 
>
> MetaData(bind=engine, reflect=True) 
>
> or a
>
> Table( 
>     "tablename",
>     metadata, 
>     schema="SCHEMA", 
>     autoload=True, 
>     extend_existing=True, 
>     quote=True)
>
> statement and it doesn't change whether the "quote" parameter is added or 
> not.
>
> Is there a way to make SQLAlchemy escape identifiers always, without case 
> mangling?
>
>
> you get NoSuchTable on straight MetaData(reflect=True)?    Please post a 
> bug report with the full table def I'd have to test that.   
>
> using quoted_name will definitely quote the value: 
> http://docs.sqlalchemy.org/en/rel_1_0/core/sqlelement.html?highlight=quoted#sqlalchemy.sql.elements.quoted_name
>
>
>
>
>
>
>
> Thanks
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+...@googlegroups.com <javascript:>.
> To post to this group, send email to sqlal...@googlegroups.com 
> <javascript:>.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to