O'Reilly logo

Python Programming On Win32 by Mark Hammond, Andy Robinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required