snower / TorMySQL

The highest performance asynchronous MySQL driver by PyMySQL
MIT License
308 stars 63 forks source link

tormysql怎么调用存储过程 #45

Closed zuanzuanshao closed 4 years ago

zuanzuanshao commented 4 years ago

从 tormysql.helpers.ConnectionPool 拿到的连接池,怎么可以 callproc

zuanzuanshao commented 4 years ago

献上代码:

    connection = yield self.tormysql.helpers.ConnectionPool(**kwargs).connect()
    cursor = connection.cursor()
    cursor.callproc(procname, args)
    result = yield self.async_pools.execute('select @_%s_0' % procname)
    result = cursor.fetchall()

查看 pymysql 源码:

    Compatibility warning: PEP-249 specifies that any modified
    parameters must be returned. This is currently impossible
    as they are only available by storing them in a server
    variable and then retrieved by a query. Since stored
    procedures return zero or more result sets, there is no
    reliable way to get at OUT or INOUT parameters via callproc.
    The server variables are named @_procname_n, where procname
    is the parameter above and n is the position of the parameter
    (from zero). Once all result sets generated by the procedure
    have been fetched, you can issue a SELECT @_procname_0, ...
    query using .execute() to get any OUT or INOUT values.

    Compatibility warning: The act of calling a stored procedure
    itself creates an empty result set. This appears after any
    result sets generated by the procedure. This is non-standard
    behavior with respect to the DB-API. Be sure to use nextset()
    to advance through all result sets; otherwise you may get
    disconnected.

可找到解决方法。