Results 1 to 3 of 3

Thread: Stored procedure and ODBC

  1. #1
    Join Date
    Dec 2006
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Stored procedure and ODBC

    I have a strange problem with QT handling stored procedures.
    I’m trying to execute stored procedure on MS SQL using ODBC and QT
    Assume that I already established connection to the database.

    QSqlQueryModel model;
    model.setQuery("{CALL test_proc}", m_Database );

    if test_proc procedure is defined like

    CREATE PROCEDURE TEST_PROC
    AS
    SELECT TOP 10 TITLE_ID, TITLE FROM TITLES

    Everything is OK. The model receives data and I can display it in the table.

    If test_proc procedure is defined like

    CREATE PROCEDURE TEST_PROC
    AS
    SELECT TOP 10 TITLE_ID, TITLE FROM TITLES
    RETURN 0

    The model thinks that there is no data to receive and shows me that record set is empty.

    I have tried to use the same procedures without using model but result was the same.
    No matter if model is used or QSqlQuery as soon as I add RETURN 0 or any return for that matter I’ll receive no result.
    Please do not suggest removing RETURN because this is a vendor stored procedure and can not be modified by me.
    The procedure above is for demonstrating my point and is not representing actual data.

    Thank you for you help

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Stored procedure and ODBC

    I'm not an SQL expert - but doesn't the "RETURN 0" just return a zero? Anyway, I guess that it returns something useful in real life. The QSqlQuery documentation for the next method says "Retrieves the next record in the result, if available, and positions the query on the retrieved record. Note that the result must be in an active state and isSelect() must return true before calling this function or it will do nothing and return false.". This tells me that a non-select return value will give you the results that you are experiencing. I suggest that you bring this up in the Task Tracker.

  3. #3
    Join Date
    Apr 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Stored procedure and ODBC

    I have your problem too.
    If you use a declare statement too, I think you will fail.
    I searched a lot. I find that it is probably ODBC limitations.
    you can not have return statement in odbc connection.
    if you use a QSqlQuery and set forwardOnly param to true and call your sp with this signiture you will not fail :"{CALL test_proc()}"

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.