有誰知道如何從一個SQL查詢鍊金術對象ResultProxy行數不通過的結果集循環? ResultProxy.rowcount屬性顯示爲0,我認爲它的值爲2.對於更新,它顯示了受影響的行數,這是我所期望的。SQL鍊金術ResultProxy.rowcount不應該是零
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine = create_engine(
'oracle+cx_oracle://user:[email protected]:port/database'
)
session = sessionmaker(
bind = engine
, autocommit = False
, autoflush = False
)()
sql_text = u"""
SELECT 1 AS Val FROM dual UNION ALL
SELECT 2 AS Val FROM dual
"""
results = session.execute(sql_text)
print '%s rows returned by query...\n' % results.rowcount
print results.keys()
for i in results:
print repr(i)
輸出:
0 rows returned by query...
[u'val']
(1,)
(2,)