Categories: S60 | Python | Code Examples
This page was last modified 03:05, 27 July 2008.
Database in PyS60
From Forum Nokia Wiki
Contents |
Introduction
The Symbian OS in Nokia S60 smart phones include a relational database engine and PyS60 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 PyS60 port of MySQL-Python available.
e32db Module
This interface in PyS60 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.
Related link
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Question about locating a file by pys60 | yanhua | Python | 2 | 2007-10-29 22:57 |
| database -S60 3-rd edition | remyag | General Symbian C++ | 8 | 2008-07-08 06:40 |
| Pys60 Help Creating a Splash Screen | PyNewbie08 | Python | 9 | 2008-07-29 06:29 |
| How to use extensions | jetherton | Python | 9 | 2006-11-24 12:12 |
| [announce] PyS60 port of MySQL for Python | jhnwkmn | Python | 4 | 2008-07-26 03:23 |
