Results 1 to 7 of 7

Thread: Qt4: How to use Stored Procedures?

  1. #1
    Join Date
    Aug 2006
    Location
    Germany
    Posts
    15
    Thanks
    1
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qt4: How to use Stored Procedures?

    Hello,

    how can i use Stored Procedures in Qt4?
    I like to save information in a MySQL table. The return of this should be the unique ID from the new row.
    Or is there a way to do this without Stored Procedures?

    Thanks a lot!

    Martin

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4: How to use Stored Procedures?

    Quote Originally Posted by pinktroll
    how can i use Stored Procedures in Qt4?
    Everything depends on the database you use.

    http://doc.trolltech.com/4.1/sql-dri...cedure-support

    Quote Originally Posted by pinktroll
    Or is there a way to do this without Stored Procedures?
    I don't use MySQL, but in PostgreSQL you can do it like this:

    SQL Code:
    1. INSERT ...;
    2. SELECT currval( 'sequence_name' );
    To copy to clipboard, switch view to plain text mode 

    Maybe MySQL has a similar method, for example using @variables?

    Anyway creating stored procedures for common queries might reduce the number of mistakes and increase performance.

  3. The following user says thank you to jacek for this useful post:

    pinktroll (27th August 2006)

  4. #3
    Join Date
    Aug 2006
    Location
    Germany
    Posts
    15
    Thanks
    1
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt4: How to use Stored Procedures?

    uuuh.. i am blind!
    I tried with INOUT parameters also without them..
    but i always used query.bindValue().. and thats not working, right?
    So thank you very much!

    p.s. MySQL has a similar method to PostgreSQL currval(), its called mysql_insert_id().

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4: How to use Stored Procedures?

    Quote Originally Posted by pinktroll
    but i always used query.bindValue().. and thats not working, right?
    bindValue() is for setting and boundValue() for reading, but MySQL is a special case --- see the link above.

  6. #5
    Join Date
    Aug 2006
    Location
    Germany
    Posts
    15
    Thanks
    1
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt4: How to use Stored Procedures?

    bindValue() is for setting and boundValue() for reading, but MySQL is a special case --- see the link above.
    Thats waht i notized.. in some cases MySQL is really different..
    So it means using stored procedures with MySQL will stick my application to that database?

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4: How to use Stored Procedures?

    Quote Originally Posted by pinktroll
    So it means using stored procedures with MySQL will stick my application to that database?
    Stored procedures handling usually differs between databases, but you could try to create a workaround. For example by writing a function that invokes stored procedure --- this way you will have only one place where you will have to handle the differences.

  8. #7
    Join Date
    Aug 2006
    Location
    Germany
    Posts
    15
    Thanks
    1
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt4: How to use Stored Procedures?

    That would be a solution. Til now i don`t need the functionality to switch database system i`m still learning Qt and C++. But i will keep it in mind, maybe i find a easy way of handling with it.
    Could be a nice feature to impress my boss
    Thanks for your great help!

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.