[python-win32] Python 3.7: difficulties importing adodbapi after installation

Sibylle Koczian Sibylle.Koczian at t-online.de
Sun Aug 19 14:45:43 EDT 2018


Hello,

Am 17.08.2018 um 16:34 schrieb Vernon D. Cole:
> The hassle is because I have not fulfilled my responsibility to keep 
> adodbapi maintained properly for these last few years. I now work in a 
> Linux shop and have almost nothing to do with databases, so my work on 
> Windows database software keeps taking a back seat to other 
> responsibilities.  This weekend, I will finally have some time.
> 

Thank you for your answer - but now I've got something I really can't 
understand:

I can connect to MS Access databases (*.mdb and *.accdb), and I can 
execute SELECT queries (didn't try any writing to the databases yet) - 
as long as the field list doesn't contain a DateTime field. If it does, 
then the query is executed, but as soon as I try to get to the results, 
the program simply finishes. No error message of any kind, and if the 
call to curs.fetchall() (or a loop "for record in curs: ...") is 
enclosed in try ... finally, then not even the "finally" part seems to 
be reached.

This is new. Using Python 3.6 and earlier versions queries with DateTime 
fields in the field list had the expected results.

The same queries using pyodbc are executed correctly.

Script to try this (needs database and table informations, of course):
#####################################################################
import logging
import adodbapi

# Connection information
cConnform = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};"
cDatabase = r"X:\Path\to\database\db.accdb"    # or db.mdb

sql_nodate = """SELECT ID, Item FROM mytable WHERE ID > ?"""
sql_date = """SELECT ID, Item, datefield FROM mytable WHERE ID > ?"""

def exec_query(sql, params, conn):
     curs = conn.cursor()
     try:
         curs.execute(sql, params)
         logging.debug("Query executed: %s, Parameter: %s", sql, params)
         result = curs.fetchall()
         logging.debug("Results: %d", len(result))
     finally:
         logging.debug("Cursor closed.")
         curs.close()
     return result

def test(connstr):
     testid = 700     # must be adapted
     conn = adodbapi.connect(connstr)
     try:
         nodate = exec_query(sql_nodate, (testid,), conn)
         logging.debug("Query without date field: %d records",
                       len(nodate))
         for record in nodate:
             print(record)
         withdate = exec_query(sql_date, (testid,), conn)
         logging.debug("Query with date field")
         for record in withdate:
             print(record)
     finally:
         conn.close()
     logging.debug("Fertig.")

def main():
     logging.basicConfig(level=logging.DEBUG)
     connstr = cConnform.format(cDatabase)
     test(connstr)

if __name__ == "__main__":
     main()



More information about the python-win32 mailing list