2016-05-12 107 views
1

我收到此錯誤消息。它只在_query具有單個字符時起作用。其他明智的投擲和錯誤信息。我正在使用MySQL擴展燒瓶錯誤:1318 PROCEDURE的參數數量不正確|燒瓶

{ error: "(1318, 'Incorrect number of arguments for PROCEDURE alexspider.SearchStore; expected 1, got 2')" }

MySQL的步驟:

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

燒瓶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

你的程序調用語句是什麼? –

+0

'cursor.callproc('SearchStore',_query)' –

+1

它清楚地表明你在你的程序中傳遞了2個參數,而你的程序只有1個輸入參數類型 –

回答

1

在這一行,

cursor.callproc('SearchStore', _query) 

您必須將參數作爲列表傳遞。 像這樣,

cursor.callproc('SearchStore', [_query,]) 
+0

謝謝索拉夫!真的行 :) –