Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

(Difference between revisions)

Archived:Complete SQL database guide for PySymbian

From Wiki
Jump to: navigation, search
jimgilmour1 (Talk | contribs)
m (spelling)
the86hitman (Talk | contribs)
Line 7: Line 7:
 
|id=
 
|id=
 
|platform= S60 2nd Edition, S60 3rd Edition
 
|platform= S60 2nd Edition, S60 3rd Edition
|devices=  
+
|devices= E71
 
|category=Python
 
|category=Python
 
|subcategory=Database
 
|subcategory=Database
Line 31: Line 31:
 
#to create table which contains three fields
 
#to create table which contains three fields
 
db.execute(u"create table table1 (id count,forename varchar, surname varchar)")
 
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
 
#to insert data
Line 60: Line 60:
 
* [[How to use SQL]]
 
* [[How to use SQL]]
 
* [[Database in PyS60]]
 
* [[Database in PyS60]]
 +
* [http://pys60.garage.maemo.org/doc/s60/node100.html SQL Data Types]
 +
* [http://www.w3schools.com/PHP/php_mysql_create.asp SQL Statements syntax]

Revision as of 17:06, 15 August 2009

File:More work needed.gif



Article Metadata
Tested with
Devices(s): E71
Compatibility
Platform(s): S60 2nd Edition, S60 3rd Edition
Article
Keywords: e32db, e32dbm
Created: (13 Aug 2009)
Last edited: the86hitman (15 Aug 2009)

Introduction

There are two database interfaces in PyS60, e32dbm and e32db.

e32dbm is required for dictionary functions only (code example at Database in PyS60). Whereas, e32db allows further SQL processing as will be shown here.

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.

Related Links

76 page views in the last 30 days.
×