Results 1 to 2 of 2

Thread: qt how get out parameter of Stored Procedure?

  1. #1
    Join Date
    Dec 2008
    Location
    chinese
    Posts
    47
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default qt how get out parameter of Stored Procedure?

    could somebody tell me how to get out parameter of Stored Procedure
    for example:


    Qt Code:
    1. CREATE PROCEDURE `proc_userByAdd`(in_username varchar(20), in_password varchar(40), OUT out_result int)
    2. BEGIN
    3. DECLARE tmp_userid INT DEFAULT 0;
    4. DECLARE txn_error INT DEFAULT 0;
    5. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN
    6. SET txn_error=1;
    7. END;
    8. set out_result = 1;
    9. START TRANSACTION;
    10. insert into userinfo(username,password) values(in_username,in_password);
    11. IF txn_error THEN
    12. set out_result = 0;
    13. ROLLBACK ;
    14. END IF;
    15. select LAST_INSERT_ID() into tmp_userid;
    16. insert into user_role(roleid,userid) values(in_roleid,tmp_userid);
    17. IF txn_error THEN
    18. set out_result =0;
    19. ROLLBACK ;
    20. END IF;
    21. COMMIT;
    22. END
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QSqlQuery query(db_tmp);
    2. int result = 1;
    3.  
    4. query.prepare("call proc_userByAdd(?,?,?,?)");
    5. query.bindValue(0,username);
    6. query.bindValue(1,password);
    7. query.bindValue(2,roleid);
    8. query.bindValue(3,0,QSql::Out);
    9.  
    10. if(!query.exec())
    11. {
    12. WRTLOG(tr("[DBERROR][USERMANAGE][addUser]%1\r\n[sql]%2").arg(query.lastError().text(),query.lastQuery()),DEBUG);
    13. result = 0;
    14. }
    15. else
    16. {
    17. result = query.boundValue(3).toInt();
    18. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qt how get out parameter of Stored Procedure?

    Your code with boundValue should be fine.
    I'm a rebel in the S.D.G.

Similar Threads

  1. Stored procedure and ODBC
    By filya in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2010, 08:40
  2. Problem calling stored procedure.. Help!
    By triperzonak in forum Qt Programming
    Replies: 4
    Last Post: 15th March 2010, 08:34
  3. Cannot create MySQL stored procedure / views from Qt
    By pshah.mumbai in forum Qt Programming
    Replies: 8
    Last Post: 8th October 2008, 16:22
  4. Accessing array (TABLE TYPE) in Stored Procedure from Qt
    By sureshbabu in forum Qt Programming
    Replies: 0
    Last Post: 26th September 2007, 11:36
  5. no record returns from stored procedure
    By mandal in forum Qt Programming
    Replies: 0
    Last Post: 26th April 2007, 14:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.