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

Type Objects and Constructors

Many databases need to have the input in a particular format in order to bind to an operation’s input parameters. For example, if an input is destined for a DATE column, it must be bound to the database in a particular string format. Similar problems exist for “Row ID” columns or large binary items (e.g., BLOBs or RAW columns). This presents problems for Python since the parameters to the executeXXX() method are untyped. When the database module sees a Python string object, it doesn’t know if it should be bound as a simple CHAR column, as a raw BINARY item, or as a DATE.

To overcome this problem, a module must provide the constructors defined here to create objects that can hold special values. When passed to the cursor methods, the module can then detect the proper type of the input parameter and bind it accordingly.

A cursor object’s description attribute returns information about each of the result columns of a query. The type_code must compare equal to one of type objects defined here. Type objects may be equal to more than one type code (e.g., DATETIME could be equal to the type codes for date, time, and timestamp columns; see the implementation hints later in this appendix for details).

The module exports the following constructors and singletons:

Date( year,month,day )

This function constructs an object holding a date value.

Time( hour,minute,second )

This function constructs an object holding a time value.

Timestamp( year,month,day,hour,minute,second ...

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