1

This is my first post to this forum and I hope the problem I am asking for solution is explained clearly . I am using QSqlTableModel and QSqlTableView for viewing a table of the DB. The cached table model is what I was looking for, that's why I chose QSqlTableModel(are there any other models?). Now I need to parse to xml all the queries cached, once I do submitAll() - I have chosen OnManualSubmit as edit strategy. I tried to write a subclass of QSqlTableModel and overload insertRowInTable/updateRowInTable/deleteRowFromTable, but the cache is accessed by a d-pointer to a private class and I don't find another way to get the cached prepared statements for then parsing them to xml. Is this solution I have thought not possible?

I am looking forward to any replies.

1 Answers1

0

QSqlTableModel inherits QSqlQueyModel, which has a public

QSqlQuery QSqlQueryModel::query () const

You can either connect to the four change signals that QSqlTableModel emits

void    beforeDelete ( int row )
void    beforeInsert ( QSqlRecord & record )
void    beforeUpdate ( int row, QSqlRecord & record )
void    primeInsert ( int row, QSqlRecord & record )

(problem: I think primeInsert and BeforeInsert can be emitted for the same event, not sure thought)

Subclass and reimplement submit() to emit a signal wich contains QSqlQuery before calling parent submit:

bool YourChildModel::submit ()
 {
    emit yourSignal(query());
    return QSqlTableModel::submit()
 }

QsqlQuery has

QString QSqlQuery::lastQuery () const
Returns the text of the current query being used, or an empty string if there is no current query text.

QString QSqlQuery::executedQuery () const
Returns the last query that was successfully executed.
In most cases this function returns the same string as lastQuery(). If a prepared query with placeholders is executed on a DBMS that does not support it, the preparation of this query is emulated. The placeholders in the original query are replaced with their bound values to form a new query. This function returns the modified query. It is mostly useful for debugging purposes.

Which would serve to parse to xml.

trompa
  • 1,967
  • 1
  • 18
  • 26