multi = True,但到底在哪里?

时间:2017-03-12 00:13:13

标签: python python-3.x pandas sqlalchemy

我编写了一个脚本,可以将数据从excel表导入MySQL数据库。然后我执行一个查询来选择数据并将其放在数据库中。 MySQL包含两个语句,一个设置变量,第二个执行select。但是我看到multi = True错误,我理解错误,但我很困惑,我必须提到multi = True。

if __name__ == "__main__":
    gesdb_engine_str = 'mysql+mysqlconnector://dbuser:dbpass@localhost/dbname'
    gesdb_engine = sqlalchemy.create_engine(gesdb_engine_str, echo=False, encoding='utf-8', multi - )
    gesdb_connection = gesdb_engine.connect()
    file_name = "tmp/dataload/so_tracking.XLSX"
    df = pd.read_excel(file_name, converters={'Billing Doc.': str, 'Sales Order': str})
    if df.shape[1] == 35 and compare_columns(list(df.columns.values)) == 1:
        # insert_so(df)
        # insert_so_lineitem(df)
        # insert_billing(df)
        scriptFile = open('script.sql','r')
        script = scriptFile.read()
        df2 = pd.read_sql(script, gesdb_connection)

    else:
        print("Incorrect column count, column order or column headers.\n")

错误:

File "C:\winpython\python-3.5.2.amd64\lib\site-packages\mysql\connector\cursor.py", line 511, in execute
    "Use multi=True when executing multiple statements")
sqlalchemy.exc.InterfaceError: (mysql.connector.errors.InterfaceError) Use multi=True when executing multiple statements [SQL: "SET @last_sales_order := 0, @next_open = 0; SELECT `Open`, .....

Script.sql示例:

SET @last_sales_order := 0, @next_open = 0;
SELECT `Open`, .....

0 个答案:

没有答案