[DAO Database in win32] What is more efficient

Arturo Pérez Mulas arturo_perez at wanadoo.es
Tue Dec 5 10:57:48 EST 2000


Hello,

I am accessing an Access database under Windows NT from Python. I am
using Mark's python windows extensions to access through the DAO
objects, and I have a question and a performance comment:

a) When I open a connection and create a recordset executing an arbitrary
SQL instruction, as follows:

db = dbengine.OpenDatabase("filename")
SQL_query = 'SELECT Table1.Column1, Table2.Colum2  FROM Table1 INNER JOIN Table2 ON (Table1.Num = Table2.Num)  WHERE (((Table1.ID)="name"));'
myrecordset = self.db.OpenRecordset(SQL_BCSet_query)


Is there any way to check if the resulting recordset is empty?



b) I need to add a register to a database but being sure that one particular field is not repeated; I have no access to the predefined structure of the
database, so I need to check manually if such a register exists before adding it; which of the following is more efficient?:

        - make an SQL query restricting the table records with "WHERE field = desired_value" and then check if the resulting recordset is empty

        - retrieve the whole table to a recordset, and check the records one by one:

                myrecordset.MoveFirst()
                while not myrecordset.EOF:
                    if myrecordset.Fields(n) == desired_value:
                        print "found in db"
                        break
                    myrecordset.MoveNext()

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20001205/ea4818fe/attachment.html>


More information about the Python-list mailing list