错误:1318 PROCEDURE |的参数数量不正确烧瓶

时间:2016-05-12 09:54:48

标签: python mysql stored-procedures flask

我收到此错误消息。仅当 _query 具有单个字符时才有效。其他明智的投掷和错误消息。我正在使用 MySQL扩展 Flask

  

{   错误:"(1318,' PROCEDURE alexspider.SearchStore的参数数量不正确;预期为1,得到2')"   }

MySQL程序:

DELIMITER $$
CREATE PROCEDURE SearchStore(
 IN Keyword VARCHAR(50))
BEGIN
 SELECT * 
 FROM noones
 WHERE name LIKE CONCAT('%', Keyword, '%');
END$$
DELIMITER ;

Flask app.py

@app.route('/search', methods=['POST'])
def search():
    try:
        # Read the posted values from the UI
        _query = request.form['query']

        # Validationg the search Quoey
        if _query:
            conn = mysql.connect()
            cursor = conn.cursor()
            cursor.callproc('SearchStore', _query)
            stores = cursor.fetchall()
            if len(stores) > 0:
                stores_dict = []
                for store in stores:
                    store_dict  ={
                    'name': store[2],
                    'url': store[3],
                    'cashback': store[4]}
                    stores_dict.append(store_dict)
                return json.dumps(stores_dict)
            else:
                return render_template('error.hml', error = 'This is error message')

    except Exception as e:
        return json.dumps({'error': str(e)})
    finally:
        cursor.close()
        conn.close()

0 个答案:

没有答案