could somebody tell me how to get out parameter of Stored Procedure
for example:
CREATE PROCEDURE `proc_userByAdd`(in_username varchar(20), in_password varchar(40), OUT out_result int)
BEGIN
DECLARE tmp_userid INT DEFAULT 0;
DECLARE txn_error INT DEFAULT 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN
SET txn_error=1;
END;
set out_result = 1;
START TRANSACTION;
insert into userinfo(username,password) values(in_username,in_password);
IF txn_error THEN
set out_result = 0;
ROLLBACK ;
END IF;
select LAST_INSERT_ID() into tmp_userid;
insert into user_role(roleid,userid) values(in_roleid,tmp_userid);
IF txn_error THEN
set out_result =0;
ROLLBACK ;
END IF;
COMMIT;
END
CREATE PROCEDURE `proc_userByAdd`(in_username varchar(20), in_password varchar(40), OUT out_result int)
BEGIN
DECLARE tmp_userid INT DEFAULT 0;
DECLARE txn_error INT DEFAULT 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN
SET txn_error=1;
END;
set out_result = 1;
START TRANSACTION;
insert into userinfo(username,password) values(in_username,in_password);
IF txn_error THEN
set out_result = 0;
ROLLBACK ;
END IF;
select LAST_INSERT_ID() into tmp_userid;
insert into user_role(roleid,userid) values(in_roleid,tmp_userid);
IF txn_error THEN
set out_result =0;
ROLLBACK ;
END IF;
COMMIT;
END
To copy to clipboard, switch view to plain text mode
int result = 1;
query.prepare("call proc_userByAdd(?,?,?,?)");
query.bindValue(0,username);
query.bindValue(1,password);
query.bindValue(2,roleid);
query.bindValue(3,0,QSql::Out);
if(!query.exec())
{
WRTLOG(tr("[DBERROR][USERMANAGE][addUser]%1\r\n[sql]%2").arg(query.lastError().text(),query.lastQuery()),DEBUG);
result = 0;
}
else
{
result = query.boundValue(3).toInt();
}
QSqlQuery query(db_tmp);
int result = 1;
query.prepare("call proc_userByAdd(?,?,?,?)");
query.bindValue(0,username);
query.bindValue(1,password);
query.bindValue(2,roleid);
query.bindValue(3,0,QSql::Out);
if(!query.exec())
{
WRTLOG(tr("[DBERROR][USERMANAGE][addUser]%1\r\n[sql]%2").arg(query.lastError().text(),query.lastQuery()),DEBUG);
result = 0;
}
else
{
result = query.boundValue(3).toInt();
}
To copy to clipboard, switch view to plain text mode
Bookmarks