Choosing a database engine

There are many database engines available that can be accessed from Python, both commercial and open source (http://wiki.python.org/moin/DatabaseInterfaces). Choosing the right database is not a trivial task as it might not only depend on functional requirements, but also on performance, the available budget, and hard to define requirements like easy maintenance.

In the applications we develop in this book, we have chosen to use the SQLite database engine (http://www.sqlite.org) for a number of reasons. First, it is free and included in Python's standard distribution. This is important for people writing books because it means that everyone who is able to run Python has access to the SQLite database engine as well. However, this is not a toy database: as a matter of fact, SQLite is a database that is used in many smartphones and high-profile applications like Firefox to store things like configurations and bookmarks. Furthermore, it is reliable and robust and, on top of that, quite fast.

It does have some drawbacks as well: first of all, it uses its own dialect of SQL (the language used to interact with the database) but to be fair, most database engines use their own dialect.

More seriously, the focus of SQLite is on embedded systems, the most visible consequence of that is that it doesn't have facilities to limit user access to a subset of tables and columns. There is just a single file on the filesystem that holds the contents of the database and the access rights to the file are determined by the filesystem on which it resides.

The final issue is not so much a drawback as a point of serious attention: SQLite does not enforce types. In many databases, the type defined for column determines rigidly what you can store in that column. When a column is defined as an INTEGER, the database engine, in general, won't allow you to store a string or a boolean value, whereas, SQLite does. This isn't as strange as it sounds once you compare it with the way Python manages variables. In Python, it is perfectly valid to define a variable and assign an integer to it, and later assign a string to the same variable. A variable in Python is just like a column in SQLite; it is just a pointer to a value and that value is not simply the value itself but also has an explicitly associated type.

The combination of availability, reliability, and a type system closely resembling Python's native way of dealing with values makes SQLite a very suitable database engine in many applications, although specific applications may have requirements that may be better served by other database engines, like PostgreSQL or MySQL. The latter might be an attractive alternative if your application will run on a web server that already provides MySQL.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.198.59