SqlAlchemy release: 1.2.13

DBMS: Oracle

Python version: 3.7.2

 

I can successfully write integers > 2**32 to my test Oracle database, but when 
I read them back via the SqlAlchemy engine the results are incorrect. This only 
happens in Python 3. It is not a cx_Oracle problem, because cx_Oracle reads the 
same bigint values correctly. The test script shown below executes all 
combinations of SqlAlchemy and cx_Oracle write/read for the value 2**33 
(8589934592), and produces the following output:

 

SA Write - SA Read (0,)

SA Write - CX Read (8589934592,)

CX Write - SA Read (0,)

CX Write - CX Read (8589934592,)

 

---- Test script ---


import cx_Oracle
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

tableName = 'BIGINT_TEST'

createTable = """
    CREATE TABLE %s (Int64Col NUMBER(20)) 
"""

writeTable = """
    INSERT INTO %s (Int64Col) values(:1)
"""

values = { '1': 8589934592 }

readTable = """
    SELECT * FROM %s
"""

dropTable = """
    DROP TABLE %s
"""

def main():
    # cx_Oracle cursor
    connection = None
    cursor = None
    dsn = cx_Oracle.makedsn('xxxx', xxxx, sid='xxxx')
    connection = cx_Oracle.connect(user='xxxx',
                                   password='xxxx',
                                   dsn=dsn)
    cursor = connection.cursor()

    # SqlAlchemy engine
    cstr = 'oracle://xxxx@{dsn}'.format(dsn=dsn)
    engine = create_engine(
        cstr,
        convert_unicode=False,
        pool_recycle=10,
        pool_size=50,
        echo=True
    )
    Session = sessionmaker(bind=engine)
    session = Session()

    try:
        cursor.execute(dropTable % tableName)
    except Exception as err:
        pass
    try:
        engine.execute(createTable % tableName)
        engine.execute(writeTable % tableName, values)
        session.commit()
        for result in engine.execute(readTable % tableName):
            print('\nSA Write - SA Read %s' % str(result))
        for result in cursor.execute(readTable % tableName):
            print('\nSA Write - CX Read %s' % str(result))
    except Exception as err:
        print(err)
    finally:
        if cursor is not None:
            cursor.execute('DROP TABLE %s' % tableName)

    try:
        cursor.execute(dropTable % tableName)
    except Exception as err:
        pass
    try:
        cursor.execute(createTable % tableName)
        cursor.execute(writeTable % tableName, values)
        connection.commit()
        for result in engine.execute(readTable % tableName):
            print('\nCX Write - SA Read %s' % str(result))
        for result in cursor.execute(readTable % tableName):
            print('\nCX Write - CX Read %s' % str(result))
    except Exception as err:
        print(err)
    finally:
        if cursor is not None:
            cursor.execute('DROP TABLE %s' % tableName)

 

This message, and any attachments, is for the intended recipient(s) only, may 
contain information that is privileged, confidential and/or proprietary and 
subject to important terms and conditions available at 
http://www.bankofamerica.com/emaildisclaimer. If you are not the intended 
recipient, please delete this message.

-- 
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