04.08.2014 Views

o_18ufhmfmq19t513t3lgmn5l1qa8a.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

290 CHAPTER 13 ■ DATABASE SUPPORT<br />

Table 13-7. DB API Constructors and Special Values<br />

Name<br />

Date(year, month, day)<br />

Time(hour, minute, second)<br />

Timestamp(y, mon, d, h, min, s)<br />

DateFromTicks(ticks)<br />

TimeFromTicks(ticks)<br />

TimestampFromTicks(ticks)<br />

Binary(string)<br />

STRING<br />

BINARY<br />

NUMBER<br />

DATETIME<br />

ROWID<br />

Description<br />

Creates an object holding a date value<br />

Creates an object holding a time value<br />

Creates an object holding a timestamp value<br />

Creates an object holding a date value from ticks<br />

since epoch<br />

Creates an object holding a time value from ticks<br />

Creates an object holding a timestamp value from ticks<br />

Creates an object holding a binary string value<br />

Describes string-based column types (such as CHAR)<br />

Describes binary columns (such as LONG or RAW)<br />

Describes numeric columns<br />

Describes date/time columns<br />

Describes row ID columns<br />

Downloading and Installing pysqlite<br />

As mentioned previously, there are many SQL database engines available, with corresponding<br />

Python modules. Most of these database engines are meant to be run as server programs, and<br />

require administrator privileges even to install them. In order to lower the threshold for playing<br />

around with the Python DB API, I’ve chosen to use a tiny database engine called SQLite, which<br />

doesn’t have to be run as a standalone server, and which can work directly on local files, instead<br />

of with some centralized database storage mechanism.<br />

You can download pysqlite from the official Web page, http://pysqlite.org. For Linux<br />

systems with package manager systems, chances are you can get pysqlite and SQLite directly<br />

from the package manager. The Windows binaries for pysqlite actually include the database<br />

engine itself (that is, SQLite), so all you have to do is to download the pysqlite installer corresponding<br />

to your Python version, run it, and you’re all set.<br />

If you’re not using Windows, and your operating system does not have a package manager<br />

where you can find pysqlite and SQLite, you have to get the source packages for pysqlite and<br />

SQLite and compile them yourself.<br />

You can get the sources for SQLite from the SQLite Web page, http://sqlite.org. (Make<br />

sure you get one of the source packages where automatic code generation has already been<br />

performed.) Compiling SQLite is basically a matter of following the instructions in the included<br />

README file. When subsequently compiling pysqlite, you need to make sure that the compilation<br />

process can access the SQLite libraries and include files. If you’ve installed SQLite in some<br />

standard location, it may well be that the setup script in the SQLite distribution can find it on<br />

its own. In that case, you simply need to execute the following commands:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!