[PyKDE] QSqlRecordInfo iteration...
Hans-Peter Jansen
hpj at urpla.net
Thu Jul 4 22:25:00 BST 2002
On Thu, 04 Jul 2002 18:48:11 +0100
"Phil Thompson" <phil at river-bank.demon.co.uk> wrote:
> 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
I'm staring on the code for a couple of hours now, but don't get a
grip on it. I think, the best way would be adding a method toList to
QSqlRecordInfo, but I'm missing some sip pieces, yet. Would you mind
being helpful once again. I swear, I will have a look into the diffs
this time.
Hans-Peter
More information about the PyQt
mailing list