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.
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?