Results 1 to 2 of 2

Thread: QSqlQuery Create View query doesn't work

  1. #1
    Join Date
    May 2013
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default QSqlQuery Create View query doesn't work

    Hello!

    I'm writing a program in Qt 4.7.4 under Windows 7 with QtCreator. But in the process of writing I met a strange problem: Create view does not work for QSqlQuery.

    the source code looks like the following;

    QString sql;
    QSqlQuery query(mydb); //mydb is defined elsewhere

    sql = "Create View SalesCount as SELECT Sales.Year, Count(Sales.ID) AS SalesCount FROM Sales GROUP BY Sales.Year;";
    query.prepare(sql);
    query.exec();

    I am expecting that I can see the view SalesCount in the database (I am using dbForge for mysql). However, I can not see it anywhere. But the same technique works well for tables. So what's wrong here?

    I beg for your help.
    Sincerely, jason.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlQuery Create View query doesn't work

    Is mydb open? Does QSqlQuery::prepare() return true? What about QSqlQuery::exec()? Have you looked at QSqlQuery::lastError()? Have you tried the SQL without the trailing semicolon?

Similar Threads

  1. QSqlQuery: Query Problem...
    By TCB13 in forum Newbie
    Replies: 2
    Last Post: 28th August 2011, 20:01
  2. QSqlQuery and non-sql query
    By zygmunt in forum Qt Programming
    Replies: 6
    Last Post: 19th January 2011, 18:44
  3. Replies: 2
    Last Post: 3rd April 2010, 10:32
  4. QSqlQuery and seek() - doesn't work on first call.
    By amicitas in forum Qt Programming
    Replies: 1
    Last Post: 2nd October 2008, 17:25
  5. Complex query in QSqlQuery
    By xgoan in forum Qt Programming
    Replies: 20
    Last Post: 17th March 2008, 12:04

Tags for this Thread

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.