好吧,我试图弄清楚如何使我的变量传递给我的方法,这很容易。我遇到的主要问题是,我在方法中需要该变量的值等于where语句中的值。有人告诉我使用%s等于正在通过的值,但是Mariadb不喜欢语法。任何帮助将不胜感激。
def ERRORDISPLAY(ErrorTpye):
#value = ErrorType
conn = connection.MySQLConnection(user = 'user', password = '123456',
host = 'localhost', database= 'HomeConnect')
cursor = conn.cursor()
query = ("SELECT errNumber, description FROM Error_List WHERE errNumber = %s value %s")
num = ErrorType
cursor.execut(query,(num))
for (description) in cursor:
return print(num, description)
ERRORDISPLAY(1)
我明白了。我不得不将整数铸成一个字符串。由于某种原因,PI W的Mariadb不喜欢某些语法。所以看起来应该这样:
def ERRORDISPLAY(ErrorTpye):
conn = connection.MySQLConnection(user = 'user', password = '123456',
host = 'localhost', database= 'HomeConnect')
cursor = conn.cursor()
value = ErrorList
query = ("SELECT errNumber, description FROM Error_List WHERE errNumber =" + str(value))
cursor.execute(query, (value))
for (description) in cursor:
return print(num, description)
ERRORDISPLAY(1)