Archived:Complete SQL database guide for PySymbian
Aquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.
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.
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
Tested with
Devices(s): E71
Compatibility
Platform(s): S60 2nd Edition, S60 3rd Edition
Article
Keywords: e32db, e32dbm
Created: the86hitman
(13 Aug 2009)
Last edited: hamishwillee
(08 May 2013)
Introduction
There are two database interfaces in PySymbian, e32dbm and e32db.
e32dbm is required for dictionary functions only (code example at Archived:Database in PySymbian). Whereas, e32db allows further SQL processing as will be shown here.
Source code
import e32db
#initiate database objects
db=e32db.Dbms()
dbv=e32db.Db_view()
#open database, if not exist, then create the file
db.open(u"e:\\data\\python\\test.db","c")
#to create table which contains three fields
db.execute(u"create table table1 (id count,forename varchar, surname varchar)")
# for value types see http://pys60.garage.maemo.org/doc/s60/node100.html
#to insert data
db.execute(u"insert into table values(1,'joe','bloggs')")
#notice, the 1 is required to increment the key!
#to fetch the whole dataset
dbv.prepare(db,u"select * from table1")
for i in range(1,dbv.count_line()+1): #1 to number of rows
dbv.get_line() #grabs data from the currently selected row
for i in range(1,self.dbv.col_count()+1):
print dbv.col(i) #prints each column data
dbv.next_line() #selects the next row
- Use db.execute(unicode(sql statement)) to perform insert/update/delete
- Use dbv.prepare(db,unicode(sql statement)) to fetch data
This is only a framework for you to use. There are many ready-to-use classes available, if you prefer, but its less erroneous if you understand the code yourself.
If you need more help, you can post to this thread.


Contents
Geoffers - Adding variable to database.
I'm new to this so this maybe very obvious to everyone else? This bit of code gets data from user and adds it to database, hope its helpfull, took me a while to figure it out;
geoffers 21:01, 15 February 2012 (EET)
Hamishwillee - Geoffers - integrate into article?
Hi Geoffers
Thanks for this. We don't have that many useful docs on PySymbian DBMS - this one, How to use SQL, A simple ORM SQL for python, and possibly the best one Working database example for e32db in PySymbian. Surprisingly the book (Python on Symbian missed this topic.
As the new "expert" would you be able to see whether your code fits into any of these? Much more useful in an article than as comment!
Regards Hamish
(Community Services Manager, Nokia)hamishwillee 05:41, 17 February 2012 (EET)
Dhingson - HI to All
i'm starting to study Python for Symbian S60 3rd edition and I want to make a Mobile Dictionary and 'im using SQLite as my Database . Do Python have a search command ???Thank you :)Dhingson 17:16, 24 September 2012 (EEST)
Hamishwillee - Perhaps ask on the forums
Hi Dhingson
I don't really understand what you mean - you can run SQL queries as documented. Other documents that might clear this up for you are Database in PySymbian, Persistent Storage in PySymbian, Working database example for e32db in PySymbian, How to use SQL on DBMS database with PySymbian
If that doesn't help - I suggest you raise the query on the discussion boards
Note also that this runtime is no longer under development, so while its great for prototyping stuff, it is not suitable for commercial apps.
Regards
Hamishhamishwillee 08:36, 25 September 2012 (EEST)