Archived:Database in PySymbian
All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.
Article Metadata
Contents |
Introduction
The Symbian OS in Nokia S60 smart phones include a relational database engine and PySymbian provides two good interfaces to that. Both the interfaces can be found by the following two modules.
- e32db Module
- e32dbm Module
Note also that there is an experimental port of PySymbian port of MySQL-Python available.
e32db Module
This interface in PySymbian provides a low level access to database. Its supports transaction and querying with the use of Simple Query Language . This Module can be very useful for applications that needs to store relationally organized data and want to perform queries frequently. In the e32db case the database is local more than a real thats why this module is not frequently used.
e32dbm module
In most cases the e32dbm module is used the reason for this is e32dbm module is very simple and it supports a lots of dictionary functions like adding, deleting the key-value pairs. The code snippet will make it more clear about this module. e32dbm module actually is a mixture of file and a dictionary. It is simply opened as file and operated as a dictionary.
import e32dbm #import the module
file_nam = u"e:\\python\\wiki.db" #assign the name of the file to a variable
def write(): #define the write function to write in a database
db = e32dbm.open(file_nam,"c") #open the file
db[u"name"] = u" Gargi Das "
db[u"place"] = u"Bhavnagar"
db[u"Country"] = u"india"
db.close()
def read(): #define a read function to read a database
db = e32dbm.open(file_nam,"r") #open a file
for key, value in db.items(): #read it using the dictionary concept.
print "KEY", key, "VALUES", value
db.close()
print "writing database......................."
write()
print "reading database......................."
read()
the code above seems to be very self explanatory and one thing to mention is the modes in which we can access different database files.
Modes of accessing a database file
The following are the modes in which one can open a database file.
- r - opens a database file for reading only.
- w - opens a database file for reading and writing.
- c - opens a database file for reading and writing. It creates a new database file if the file doesn't exist.
- n - opens a database for reading and writing. It creates and empty database if the database doesn't exist or clears the previous one.


(no comments yet)