Results 1 to 15 of 15

Thread: QSqlQuery Fails when calling stored procedures taking QString>127 chars- -HELP!!!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default QSqlQuery Fails when calling stored procedures taking QString>127 chars- -HELP!!!

    hi there!!


    I am having problems on porting a sql app from qt3 to qt4.
    I must tell u that i dont know SQL and i have not used QSql before.. i was porting an application to qt 4 so i got some knowlegde of SQL and qt's SQL module.

    the application connects to a MS SQL server 7.0 database on network (QODBC).
    i call QSqlDataBase::addDatabase("QODBC", "myID"); and all other initializing functions and the
    database is connnected succesfully.
    now i can execute simple SQL queries without any problem.

    The problem is on calling the stored procedure on the database.

    i made a small, very simple stored procedure whose code is ->

    sql Code:
    1. CREATE proc GetTransactionTest
    2. @pin_type nvarchar(20),
    3. @pou_year numeric(4) output,
    4. @pou_text nvarchar(2000) output
    5. AS
    6.  
    7. begin
    8.  
    9. ----- Initialize out parameters ----
    10. SELECT @pou_trans_year=2007
    11. SELECT @pou_trans_text="Some long text from record"
    12. ------------------------------------
    13. end
    To copy to clipboard, switch view to plain text mode 
    this procedure takes one input "pin_type" and two output parameters viz "pou_year",
    "pou_text".

    now i have the sqlquery code in my app like this ->

    Qt Code:
    1. void MyClass::callDBprocedure() {
    2. QSqlQuery *query=new QSqlQuery(database);
    3.  
    4. //This commented line works fine, that means the connection is correct.
    5. //query->exec("SELECT something FROM anything")
    6.  
    7. //problem lines
    8. query->prepare("{call GetTransactionTest(?,?,?)}");
    9. type="MY_TYPE" //QString
    10. year=0; //int
    11. text.fill(' ',2000); //QString
    12. query.bindValue(0,type);
    13. query.bindValue(1,year,QSql::Out);
    14. query.bindValue(2,text,QSql::Out);
    15. if(query->exec())
    16. {
    17. //success
    18. }
    19. else
    20. {
    21. //Always gets here.
    22. }
    23.  
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 
    Because our output parameter needs 2000 charecters i have to do "text.fill(' ',2000) or text.resize(2000)", but
    as i resize this to any length greater than 127 the query fails. and lastError() returns the following string

    [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead(recv()).[Microsoft][ODBC SQL Server Driver][DBNETLIB]General Network
    error. Check your network documentation. QODBC3: Unable to execute statement.
    the query succeeds when i write text.fill(' ', 127) (any value less then 127).
    All of this was working fine on the same network with same stored procedure in my Qt3.3.6 application.

    please.. help... has anyone had this kind of problem before??
    Last edited by jpn; 16th January 2009 at 16:51. Reason: missing [code] tags

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.