由于我在MySQLdb模块中创建了许多API,现在我需要切换到sqlalchemy,我希望使用sqlalchemy核心,这样就不需要进行太多更改。我现在正在使用MySQL。
当我使用db.session.execute
更改为之前为Mysqldb工作的cur.execute(
时,发生了错误。
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Stock' is not defined
以下是sqlalchemy的代码
db = SQLAlchemy(app)
@app.route('/KJ/<Stock>', methods=['GET'])
def KJstock(Stock):
try:
call = db.session.execute("SELECT * FROM KJ WHERE Stock LIKE %s",(Stock,))
col = ['index','Stock','Name','MACD','STOCH','RSI','ATR','Bollinger','SMA','SMAcross',]
c = call.fetchall()
d = [OrderedDict(zip(col,t)) for t in c]
except Exception:
return 'Error: unable to fetch items'
return jsonify({'Stock': d})