0

in my Qt (4.8.1) based application I need to retrieve the definition of a view stored in a MySql database.

The code I'm using is

QSqlQuery query;   
query.prepare(QString("SHOW CREATE VIEW %1").arg(viewName));

qDebug() << "actually sending this query: " << query.lastQuery();
qDebug() << "exec retuned " << query.exec();
qDebug() << "last error reported as " << query.lastError();
qDebug() << "size = " << query.size();
qDebug() << "numRowsAffected" << query.numRowsAffected();

QString viewCreateString;
if (query.first()) {
    viewCreateString = query.value(1).toString();
    qDebug() << "got this create view record" << viewCreateString;
}

When I run the above code I get the following result:

actually sending this query:  "SHOW CREATE VIEW AC_STATE_V" 
exec retuned  true 
last error reported as  QSqlError(-1, "", "") 
size =  -1 
numRowsAffected -1 

Note that:

  1. if I run the very same (cut&paste) command from within a MySql Workbench SQLTab connected to the same DB using the same credentials I do get the expected results (i.e.view exists and user got sufficient rights to retrieve it)
  2. all of the above is also valid for a TABLE

0 Answers0