[PyKDE] QSqlRecordInfo iteration...

Phil Thompson phil at river-bank.demon.co.uk
Thu Jul 4 19:53:00 BST 2002


Hans-Peter Jansen wrote:

> Hi Phil,
> 
> today I've tried to iterate through the fields of a table, similar to
> void SqlEx::dbConnect() in sqlex.ui.h. While iterating through the
> list of tables is perfectly possible, the same action failed for
> a QValueList of QSqlRecordInfos. This is the corresponding c++ code:
> 
>     QStringList tables = db->tables();
>     for ( QStringList::Iterator it = tables.begin(); it != tables.end(); ++it ) {
>     QListViewItem* lvi = new QListViewItem( lv, *it );
>     QSqlRecordInfo ri = db->recordInfo ( *it );
>     for ( QSqlRecordInfo::Iterator it = ri.begin(); it != ri.end(); ++it ) {
>         QString req;
>         if ( (*it).isRequired() > 0 ) {
>         req = "Yes";
>         } else if ( (*it).isRequired() == 0 ) {
>         req = "No";
>         } else {
>         req = "?";
>         }
>         QListViewItem* fi = new QListViewItem( lvi, (*it).name(),  +
> 				QVariant::typeToName((*it).type() ), req );
>         lvi->insertItem( fi );
>     }
>     lv->insertItem( lvi );
>     }
> 
> I bluntly patched sip/qvaluelist.sip with something hopefully taking the
> right direction, but unfortunetely siping failed:
> 
> sip: QSqlRecordInfo is undefined
> ******************************************************************************
> Error: /usr/local/bin/sip failed with an exit code of 1.
> 
> Now, that I haven't any real grasp on sip, I'm stuck.
> 
> Any ideas, how to preceed?


Yuck. Throughout the rest of PyQt a QValueList is mapped to a Python 
list. It would be fairly easy (and consistent) to map a QSqlRecordInfo 
to a Python list of QSqlFieldInfo instances.

The only disadvantage I can see is that you would lose the toRecord() 
method.

The other approach is to add the methods you need from QValueList into 
QSqlRecordInfo - SIP doesn't care if methods aren't in the right place, 
so long as the compiler is happy. However, it looks like most of the 
potentially useful QValueList methods deal with iterators - which SIP 
won't like.

Phil




More information about the PyQt mailing list