gpt4 book ai didi

python - 错误 1318 : Incorrect number of arguments for PROCEDURE ComicHub. sp_createUser;预期 3,得到 4

转载 作者:可可西里 更新时间:2023-11-01 07:43:54 26 4
gpt4 key购买 nike

我在运行这段代码时一直报错 1318,我应该有 4 个参数:usernameemailpassword位置。它正在拾取 4,但认为它只需要 3 个参数。数据库和 Python 的代码如下。

python :

@app.route('/userSignUp',methods = ['POST'])
def userSignUp():
try:
#read values from signup form
_username = request.form['username']
_email = request.form['email']
_password = request.form['password']
_location = request.form['location']

#validate recieved values
if _username and _email and _password and _location:

cur = mysql.connection.cursor()
_hashed_password = generate_password_hash(_password)

cur.callproc('sp_createUser', (_username, _email, _hashed_password, _location))

data = cur.fetchall()
cur.close()
if len(data) is 0:
mysql.connection.commit()
return json.dumps({'success':'User created successfully!'})
else:
return json.dumps({'error':str(data[0])})
else:
return json.dumps({'html':'<span>Enter the required fields</span>'})

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

SQL:

# Create Database for ComicHub
CREATE DATABASE ComicHub;

# Create Table 'users' for ComicHub
CREATE TABLE `ComicHub`.`tbl_user` (
`user_id` BIGINT NULL AUTO_INCREMENT,
`user_username` VARCHAR(45) NULL,
`user_email` VARCHAR(45) NULL,
`user_password` VARCHAR(45) NULL,
`user_location` VARCHAR(66) NULL,
PRIMARY KEY (`user_id`)
);

# PROCEDURE for creating users from passed in data
USE `ComicHub`;
DELIMITER $$
CREATE PROCEDURE `sp_createUser` (
IN p_username VARCHAR(20),
IN p_email VARCHAR(20),
IN p_password VARCHAR(20),
IN P_location VARCHAR(20)
)
BEGIN
#check if user already exists
IF (select exists (select 1 from tbl_user where user_username = p_username) ) THEN

select 'Username Already Exists!';

ELSE

insert into tbl_user
(
user_username,
user_email,
user_password,
user_location
)
values
(
p_username,
p_email,
p_password,
p_location
);

END IF;
END$$
DELIMITER ;

最佳答案

没关系,现在修复了,我意识到我没有更新 MySQL Workbench 中的数据库。我知道这很愚蠢,但这是漫长的一天!

关于python - 错误 1318 : Incorrect number of arguments for PROCEDURE ComicHub. sp_createUser;预期 3,得到 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36898001/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com