I here post the entire code ,, I also checked by making the variable as global,.. but no way<<<>>
Code:
import e32db,sys,traceback,e32,appuifw
#initiate db access
db=e32db.Dbms()
dbv=e32db.Db_view()
dbname = u'e:\\python\\details.db'
#open database, if it does not exist, then create it
try:
db.open(dbname)
except:
db.create(dbname)
db.open(dbname)
#Create the database table
try:
# note that the id field is auto-incremented when new rows are added
db.execute(u"CREATE TABLE list (id counter, name VARCHAR)")
print "Table Created"
except SymbianError:
print "Error Creating table: "
#print traceback.format_exception(*sys.exc_info())
print sys.exc_info()[0]
print sys.exc_info()[1]
print sys.exc_info()[2]
# attempt to insert data
def add():
try:
nme = appuifw.query(u'Enter name', 'text')
#From the article, slightly modified:
db.execute(u"INSERT INTO list (name) VALUES (%s)" % nme)
print "Data Inserted"
except SymbianError:
print "Could not insert data: ", SymbianError.args
print sys.exc_info()[0]
print sys.exc_info()[1]
print sys.exc_info()[2]
#to fetch the whole dataset
def view():
try:
dbv.prepare(db,u'SELECT * FROM list')
for i in range(1,dbv.count_line()+1): #1 to number of rows
dbv.get_line() #grabs the current row
for i in range(1,dbv.col_count()+1):
print dbv.col(i) #prints each column data
dbv.next_line() #move to the next rowset[[Category:Entertainment]]
except SymbianError:
print "failed to read database: "
print sys.exc_info()[0]
print sys.exc_info()[1]
print sys.exc_info()[2]
def quit():
db.close() # close the database
app_lock.signal()
appuifw.app.exit_key_handler=quit
appuifw.app.menu = [(u"ADD", add),(u"VIEW", view), (u"Exit", quit)]#MENU
app_lock=e32.Ao_lock()
app_lock.wait()