Results 1 to 9 of 9

Thread: Cannot create MySQL stored procedure / views from Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2007
    Posts
    36
    Thanks
    5
    Thanked 3 Times in 1 Post

    Default Re: Cannot create MySQL stored procedure / views from Qt

    Qt Code:
    1. //Main program
    2. int main(int argc, char *argv[])
    3. {
    4. QApplication app(argc, argv);
    5. db = QSqlDatabase::addDatabase("QMYSQL");
    6. db.setHostName("localhost");
    7. db.setUserName("root");
    8. db.setPassword("root");
    9. db.setDatabaseName("test");
    10. if(db.open())
    11. {
    12. QString create_tables_sql;
    13.  
    14. create_tables_sql = "DELIMITER $$ \n\
    15. CREATE PROCEDURE Fun() \n\
    16. BEGIN \n\
    17. SELECT * FROM test; \n\
    18. END $$ \n\
    19. DELIMITER ; ";
    20.  
    21. qDebug() << create_tables_sql;
    22. QSqlQuery me;
    23. if (!me.exec(create_tables_sql))
    24. {
    25. qDebug() << "Query exec problem";
    26. ; }
    27. qDebug() << me.lastError(); //QSqlError(-1, "", "")
    28. exit(1);
    29. }
    30. else
    31. {
    32. qDebug() << "Db not open";
    33. exit(1);
    34. }
    35.  
    36. return app.exec();
    37. }
    To copy to clipboard, switch view to plain text mode 

    Query exec problem
    QSqlError(1064, "QMYSQL: Unable to execute query", "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$
    CREATE PROCEDURE Fun()
    BEGIN
    SELECT * FROM test;
    END $$
    DELIMI' at line 1")

  2. #2
    Join Date
    Sep 2007
    Posts
    36
    Thanks
    5
    Thanked 3 Times in 1 Post

    Default Re: Cannot create MySQL stored procedure / views from Qt

    Now it seems to work when I remove the delimiter statements.

    I will test it more and report back

  3. #3
    Join Date
    Sep 2007
    Posts
    36
    Thanks
    5
    Thanked 3 Times in 1 Post

    Default Re: Cannot create MySQL stored procedure / views from Qt

    here is the code.

    Qt Code:
    1. QString create_tables_sql;
    2.  
    3. create_tables_sql = "CREATE PROCEDURE Fun() \n\
    4. BEGIN \n\
    5. SELECT * FROM test; \n\
    6. END";
    7.  
    8. qDebug() << create_tables_sql;
    9. if (!me.exec(create_tables_sql))
    10. {
    11. qDebug() << "Query exec problem";
    12. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2007
    Posts
    36
    Thanks
    5
    Thanked 3 Times in 1 Post

    Default Re: Cannot create MySQL stored procedure / views from Qt

    Its working perfectly now.

    1. Do not use the DELIMTER statements

    Qt Code:
    1. QString procedure = "CREATE PROCEDURE Fun() \n\
    2. BEGIN \n\
    3. SELECT * FROM test; \n\
    4. END ;";
    5.  
    6. me.exec(procedure);
    To copy to clipboard, switch view to plain text mode 

    2. Do not call drop procedure in the same query.

Similar Threads

  1. Accessing REF CURSOR in Stored Procedure from Qt
    By sureshbabu in forum Qt Programming
    Replies: 3
    Last Post: 11th August 2010, 16:51
  2. Stored procedure and ODBC
    By filya in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2010, 09:40
  3. Accessing array (TABLE TYPE) in Stored Procedure from Qt
    By sureshbabu in forum Qt Programming
    Replies: 0
    Last Post: 26th September 2007, 12:36
  4. no record returns from stored procedure
    By mandal in forum Qt Programming
    Replies: 0
    Last Post: 26th April 2007, 15:45
  5. 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
  •  
Qt is a trademark of The Qt Company.