Hi Mike,

thanks again!

On 2018-01-15 23:17, Mike Bayer wrote:
> On Mon, Jan 15, 2018 at 3:18 PM, Stefan Schwarzer
> <sschwar...@sschwarzer.net> wrote:
>> On 2018-01-12 16:33, Mike Bayer wrote:> On Fri, Jan 12, 2018 at 7:14 AM, 
>> Stefan Schwarzer
>>> <sschwar...@sschwarzer.net> wrote:
> the issue you refer to with Anthony refers to a new use case for the
> cx_Oracle DBAPI, where we use setinputsizes() again and use a
> different datatype for strings.   So that would need to be added to
> SQLAlchemy's cx_Oracle dialect as an option, which can either be on a
> per-datatype basis or engine-wide (engine-wide is easier to implement
> and use however I'm not sure which is more appropriate).
> 
> You can probably get this to work right now doing this:
> 
> from sqlalchemy.dialects.oracle import _OracleString
> class NCHAR(_OracleNVarChar):
>     def get_dbapi_type(self, dbapi):
>         return cx_Oracle.NCHAR
> 
> and then add cx_Oracle.NCHAR to the dialect._include_setinputsizes list.

The following works for me:


import sqlalchemy.types
import sqlalchemy.dialects.oracle.cx_oracle as cx_oracle_dialect


class OracleNVarChar(cx_oracle_dialect._OracleNVarChar):
    def get_dbapi_type(self, dbapi):
        return cx_Oracle.NCHAR

cx_oracle_dialect.OracleDialect_cx_oracle.colspecs[sqlalchemy.types.Unicode] = 
OracleNVarChar


metadata = sa.MetaData()

test_table = sa.Table("utf8_test", metadata, sa.Column("text", sa.Unicode(20)))

connect_string = "oracle+cx_oracle://..."
engine = sa.create_engine(connect_string, echo='debug')
engine.dialect._include_setinputsizes.add(cx_Oracle.NCHAR)


Changes to your version:

- Changed import. I wasn't sure whether your import or
  the base class was wrong.

- Added assignment to `colspecs` dictionary

> I've proposed a few ways we might be able to add this API here:
> 
> https://bitbucket.org/zzzeek/sqlalchemy/issues/4163/cx_oracle-requires-method-to-force-use-of

I added a comment to this ticket.

Best regards,
Stefan

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to