Getting at Your Data

In this section we show how to execute SQL queries and fetch data using ODBC, DAO, and ADO. First, you need a database. The examples for this chapter include an Access database called pydbdemos.mdb . You could as easily use any database you can access, of course modifying the SQL statements as needed. The sample database consists of a list of clients and invoices, with the structure shown in Figure 13.2.

Structure of PYDBDEMOS database
Figure 13.2. Structure of PYDBDEMOS database

If you wish to use the sample database, you need to configure an ODBC data source as follows:

  1. Click on Start Settings Control Panel 32-bit ODBC User (or system) DSN Add.

  2. Select Microsoft Access Driver from the list of drivers.

  3. Enter the name PYDBDEMOS in the box for Data Source Name.

  4. Click the Select button and locate the file pydbdemos.mdb.

  5. Click OK. The new data source should now be visible in the list.

  6. Click OK to close the ODBC Data Source Administrator. Some versions of Windows contain a bug that causes an error message at this point. Ignore any messages; your data source is registered correctly.

Since Access isn’t a server, we have worked with Sybase SQL Anywhere for some of the advanced examples. This is an excellent commercial database engine costing little more than Access and part of a range of products ranging from embedded database engines to enterprise servers. We’ve kept the Sybase examples to a minimum ...

Get Python Programming On Win32 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.