cruzjoey0507 / pyfilemaker

Automatically exported from code.google.com/p/pyfilemaker
0 stars 0 forks source link

New method to get number of records in a table #6

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
This isn't a bug, but I don't know how else to contribute this concept
back, plus get feedback on what I've done.

For an indexer I was building I wanted to know how many records existed in
a database table. I'm _very_ new to Python, so this almost certainly isn't
very good code, however it's doing what I needed.

What I noticed from doing a FindAny was that the total-count was returned
in the XML from FM, and then in the header of the records object. What I
wanted was just that number...

Within FMServer.py > class FMServer: I've added

    def getRecordCount(self):

        uu = urllib.urlencode

        request = []
        request.append( uu( {'-db': self._db}))
        request.append( uu( {'-lay': self._layout}))
        request.append('-findany')

        result = self._doRequest( request )

        parser = xml2obj.Xml2Obj()
        return
parser.ParseString(result).getElements('datasource')[0].attributes['total-count'
]

Any feedback on how to do this better would be most appreciated, otherwise,
I hope that it's helpful to others one day...

Cheers
Steve

Original issue reported on code.google.com by matatiro...@gmail.com on 24 Nov 2009 at 7:49