Results 1 to 8 of 8

Thread: Stored procedure return values problem

  1. #1
    Join Date
    Aug 2007
    Posts
    11
    Qt products
    Qt3
    Platforms
    Windows

    Default Stored procedure return values problem

    Hi all,

    I'm having a problem with a character value being returned by one of my stored procedures in Oracle using the OCi driver.

    I create a QString to retrieve the data into but I found that I also have to create a char* variable to bind to the procedure value:

    QString fp;
    char fpc[525];
    ...
    query.bindValue(1, fpc, QSql:ut);
    ...
    query.exec();
    ...
    fp = query.boundValue(1).toString();

    Is this the correct approach? The thing is, the value of fp is, of course, fixed length & padded with garbage characters after the "real" value. How can I get rid of those garbage characters? Maybe this isn't really a stored procedure question just a character string manipulation question.

    Thanks very much,
    Jim

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Stored procedure return values problem

    Why do you use a char* for?
    The second parameter for the QSqlResult::bindValue is a QVariant, meaning that you can pass a QString or even an empty QVariant.
    You can retrieve the QString with QVariant::toString().

    You're getting rubbish at the end of the char array because it is not null terminated.

    Regards

  3. #3
    Join Date
    Aug 2007
    Posts
    11
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Stored procedure return values problem

    Thanks, Marcel.

    The reason I'm using char* for the bind variable is that when I use the QString, I get an error about the character buffer being too small.

    Is there, maybe, something I need to change on the stored procedure? The particular parameter is currently specified as VARCHAR2 with no field width value - this returned character string could be thousands of characters long (but it's not a clob).

    Cheers,
    Jim

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Stored procedure return values problem

    What if you pass an empty QVariant?
    Qt Code:
    1. query.bindValue(1, v, QSql:: Out);
    2. QString s = v.toString();
    To copy to clipboard, switch view to plain text mode 

    This way, the entire buffer should fit in there, even if the length is unknown.

    BTW, I thought VARCHAR2 always has a size entry.

    Regards

  5. #5
    Join Date
    Aug 2007
    Posts
    11
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Stored procedure return values problem

    Hi Marcel,

    I tried the QVariant but got a null returned. The only way I have been able to get a returned value is to use a char*.

    The actual problem I have in using the returned value, which is a list of numbers, is that after converting the comma-delimited string to a QStringList, when converting each number string to a double, the last number gets an error because of, I guess, the non-null-terminated value.

    (The numbers are vertices of a polygon retrieved from an Oracle Spatial object)

    Cheers,
    Jim

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Stored procedure return values problem

    then use this prior to calling bindValue:
    Qt Code:
    1. memset(fpc, 0, sizeof(char)*525);
    To copy to clipboard, switch view to plain text mode 

    This way you make sure you will always have a null at the end of your string, in case the stored procedure returns a smaller number of characters.

    You can even increase the size of the array to 1024 or 2048, but make sure to create it on the heap, not on the stack.

    Regards

  7. #7
    Join Date
    Aug 2007
    Posts
    11
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Stored procedure return values problem

    Rats! That gives a null returned value.
    Cheers,

    Jim

  8. #8
    Join Date
    Aug 2007
    Posts
    11
    Qt products
    Qt3
    Platforms
    Windows

    Thumbs down Re: Stored procedure return values problem

    Hi all,

    My company finally got my Qt maintenance renewed so I could pose this to Trolltech. They say it is a bug in Qt 3.3.x which also exists in Qt 4.

    I have had to revise my stored procedures to append a ",end" at the end of any returned strings so I can then extract the substring to the left of that.

    Cheers,
    Jim
    Cheers,

    Jim

Similar Threads

  1. Stored procedure and ODBC
    By filya in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2010, 09:40
  2. no record returns from stored procedure
    By mandal in forum Qt Programming
    Replies: 0
    Last Post: 26th April 2007, 15:45
  3. MySql Stored Procedures Woes
    By stevey in forum Qt Programming
    Replies: 9
    Last Post: 19th October 2006, 13:58

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.