尝试使用sqlalchemy从数据库读取值时出现错误结果

时间:2019-02-21 17:02:33

标签: python sqlalchemy cx-oracle

我正在尝试使用cx_oracle和sqlalchemy通过python从数据库查询 我发现cx_oracle似乎给出了正确的结果,而sql_alchemy给出了错误的结果

数据库中的实际价值:3,360,000,000 使用sqlalchemy时:-934,967,296 使用cx_oracle时:3,360,000,000

我想使用sqlalachemy。您能告诉我我的代码有什么问题吗?我认为这可能是溢出错误。

代码cx_oracle

class DatabaseConnection:
    def __init__(self, ip, port, SID, user_name, password):
        self.ip = ip  # ip address of the host
        self.port = port  # port of the host
        self.SID = SID  # SID
        self.user_name = user_name  # user name of the database
        self.password = password  # password of the database

    # function to connect to the database
    def connect(self):
        dsn_tns = cx_Oracle.makedsn(self.ip, self.port, self.SID)
        db = cx_Oracle.connect(self.user_name, self.password, dsn_tns)
        return db

    database = DatabaseConnection(host, port, SID, user_name, password)
    db = database.connect()
    sql_bp = "some sql query"
    bp1 = pd.read_sql(sql_bp, db)

代码sqlalchemy:

    engine_query = 

    "oracle+cx_oracle://"+user_name+":"+password+"@"+host+":"+port+"/"+SID
    engine = create_engine(engine_query)
    Session = sessionmaker(bind=engine)
    session = Session()
    bp = pd.read_sql(sql_bp, engine)

0 个答案:

没有答案