我有以下函数
def retrieve_metadata(self, sample_name, workflow_execution_id):
print("Starting to retrieve meta data from Workflow for Sample {} and WorkflowExection {}".format(
sample_name, workflow_execution_id))
sql_query = """SELECT s.SampleName, s.ClientSampleId, s.ClientSubjectId, p.ProjectName, c.ClientName, s.ProjectId, e.WorkflowExecutionId from Sample s join project p on s.ProjectId = p.ProjectId join Client C on p.ClientId = c.ClientId left join SampleExecution e on e.SampleId = s.SampleId where s.SampleName = %s and e.WorkflowExecutionId = %s"""
package_data = (sample_name, workflow_execution_id)
for row in self.sql_reader.cursor.execute(sql_query, package_data):
temp_meta = MetaData(row.SampleName,
row.ClientSampleId,
row.ClientSubjectId,
row.ProjectName,
row.ClientName,
row.ProjectId,
row.WorkflowExecutionId,
)
self.input_data.append(temp_meta)
我最近更改了代码以接受参数,但我得到的错误是
File "/var/task/sql_scrapper.py", line 21, in retrieve_metadata
for row in self.sql_reader.cursor.execute(sql_query, package_data):
ProgrammingError: ('The SQL contains 0 parameter markers, but 2 parameters were supplied', 'HY000')
如何使用PYODBC解决此问题?
sql_query = """SELECT s.SampleName, s.ClientSampleId, s.ClientSubjectId, p.ProjectName, c.ClientName, s.ProjectId, e.WorkflowExecutionId from Sample s join project p on s.ProjectId = p.ProjectId join Client C on p.ClientId = c.ClientId left join SampleExecution e on e.SampleId = s.SampleId where s.SampleName = ? and e.WorkflowExecutionId = ?"""
从%s更改为?解决了这个问题。