简体   繁体   中英

Sqlalchemy cx_Oracle create_engine: cannot set arraysize

Based on the sqlalchemy docs I should be able to set arraysize on cxOracle. however setting it as a create_engine arg doesn't work: http://docs.sqlalchemy.org/en/rel_0_9/dialects/oracle.html#dialect-oracle-cx_oracle-connect

import sqlalchemy
    url = sqlalchemy.engine.url.make_url(r'oracle+cx_oracle://user:pass@host:port/dbname') # replaced with appropriate db connection
    engine = sqlalchemy.create_engine(url, arraysize=50000)
    cursor = engine.raw_connection().cursor()
    print cursor.arraysize
    #still only 50

even setting it in the connection string also doesn't work:

import sqlalchemy
url = sqlalchemy.engine.url.make_url(r'r'oracle+cx_oracle://user:pass@host:port/dbname?arraysize=5000')
engine = sqlalchemy.create_engine(url)
cursor = engine.raw_connection().cursor()
print cursor.arraysize

am I doing something stupid? or can someone post a snippet that successfully sets the arraysize at the engine level.

I think the issue here is that you're making a end-run around the normal mechanism by which SQLAlchemy would get and configure the cursor for its own use. By using raw_connection you're getting the cursor from the underlying DB driver (cx_oracle) directly, which defaults to an arraysize of 50. If you were using some of the "usual" SQLAlchemy objects (eg by getting a connection from the engine and calling execute on it), then you'd be going through the code path at https://github.com/zzzeek/sqlalchemy/blob/rel_0_9_10/lib/sqlalchemy/dialects/oracle/cx_oracle.py#L526 which would indeed set the passed-in arraysize on the cursor that SQLAlchemy would use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM