有一个脑电波,并设法使用 python 转换器来运行它pyodbc
。这可以在它们自己的批处理中执行查询,同时保持单个连接。我的 Python Caller tramsformer 是这样的:
import fmeobjects
import pyodbc
class FeatureCreator(object):
def __init__(self):
pass
def input(self,feature):
newFeature = fmeobjects.FMEFeature()
connectionStr = f"DRIVER={{SQL Server}};SERVER={FME_MacroValues['Server']};Trusted_Connection=yes;"
if FME_MacroValues['Database'] != '':
connectionStr += f"DATABASE={FME_MacroValues['Database']};"
connection = pyodbc.connect(connectionStr)
cursor = connection.cursor()
cursor.execute("SET SHOWPLAN_XML ON;")
cursor.commit()
cursor.execute(feature.getAttribute('query'))
results = cursor.fetchall()[0][0]
newFeature.setAttribute("showplan", results)
self.pyoutput(newFeature)
def close(self):
pass