PDA

View Full Version : Qt4: How to use Stored Procedures?



pinktroll
27th August 2006, 13:00
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

jacek
27th August 2006, 14:04
how can i use Stored Procedures in Qt4?
Everything depends on the database you use.

http://doc.trolltech.com/4.1/sql-driver.html#stored-procedure-support


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:

INSERT ...;
SELECT currval( 'sequence_name' );

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.

pinktroll
27th August 2006, 16:09
uuuh.. i am blind! :o
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().

jacek
27th August 2006, 17:11
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.

pinktroll
28th August 2006, 11:08
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?

jacek
28th August 2006, 13:09
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.

pinktroll
28th August 2006, 14:46
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 :cool:
Thanks for your great help!