Mosi
Mosi

Reputation: 1258

Failed to execute "SHOW CREATE TABLE" query in Qt

Suppose I have a table called 'logs' in mysql and I want to get the create query of this table in Qt(5.2 mingw). Here is what I have done so far:

QSqlQuery query(connection);

query.prepare("SHOW CREATE TABLE logs");
if(query.exec())
{
    if(query.next())
        query.value(1).toString();
}

After executing the code, the query.exec() returns true but the query.next() returns false. This query executes successfully in the mysql client(navicat) so I'm pretty sure about the query.

Note that QSqlQuery::lastError() gives -1 means no error!

I'll appreciate for any guidance or help.

Upvotes: 0

Views: 330

Answers (1)

RobbieE
RobbieE

Reputation: 4360

query.next() is only appropriate when executing a SELECT statement. It has no meaning for any other SQL statement.

Upvotes: 1

Related Questions