【发布时间】:2017-08-15 09:59:04
【问题描述】:
我希望你能帮助我,因为我已经被这个问题困扰了一段时间。第一次在这里发帖,什么不是。我先说我是一名自动化测试人员,有一点 Python 经验,但我不是专家。
我一直在绞尽脑汁试图解决这个问题,我不知道这是 cx_Oracle 的限制还是什么,但我找不到有类似问题的人。我几乎没有使用 cx_Oracle 的经验。
所以,这是我正在尝试做的一个小例子。我无法发布整个内容,因为我对其进行了多少更改和移动,这有点混乱。我只是想尝试做一个我所拥有的非常基本的版本;
def test(self):
#Driver is set up
var1 = driver.find_element_by_name('blah').text
var1 = str(var1)
#Do some other stuff on the page
return var1
def foo():
#Setup cx_Oracle and connect to DB
sql = ('SELECT value FROM table WHERE ref = :1')
c.execute(sql, (var1,)
#Verify the results of the query
class testcase(unittest.Testcase):
def test_case(self):
setUp(self)
test(self)
foo()
没有错误消息或类似的东西。它似乎没有看到变量的值。当我硬编码 var1 的值时,它可以工作并返回结果,就好像我通过 DBeaver 查询了数据库一样。
我尝试将所有内容放在同一个函数中并获得相同的结果。
我尝试如下传递 var1,但仍然得到相同的结果:
def test(self):
#Driver is set up
var1 = driver.find_element_by_name('blah').text
#Do some other stuff on the page
return var1
def foo(var1):
#Setup cx_Oracle and connect to DB
sql = ('SELECT value FROM table WHERE ref = :1')
c.execute(sql, (var1,))
#Verify the results of the query
class testcase(unittest.Testcase):
def test_case(self):
setUp(self)
var1 = test(self)
print (var1)
foo(var1)
我一直在使用this as a reference for binding variables,但这些方法都不适合我。
所以,总而言之,我有 2 个函数,我想将一个变量从一个传递到另一个,但 cx_Oracle 似乎不喜欢它。我选择 cx_Oracle 是因为 pyodbc 和 pypyodbc 似乎不想连接到我正在尝试与之交谈的 Oracle 10g DB。如果有人知道更好的工具,我什至愿意使用另一种工具?
如果您需要更多详细信息,请告诉我。
【问题讨论】:
标签: python sql oracle selenium cx-oracle