
Originally Posted by
the86hitman
ok, the definitive answer to Databasing in Python after alot of messing around in Python Shell
Code:
import e32db
#initiate db access
db=e32db.Dbms()
dbv=e32db.Db_view()
#open database, if not exist, then create the file
try:
db.open(u'e:\\data\\python\\test.db')
except:
db.create(u'e:\\Python\\src\\test.db')
db.open(u'e:\\data\\python\\test.db')
#to create ur table
db.execute("create table table1 (id count,forename varchar, surname varchar)")
#contains three fields
#to insert data
db.execute("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 the current row
for i in range(1,self.dbv.col_count()+1):
print dbv.col(i) #prints each column data
dbv.next_line() #move to the next rowset
# use db.execute to perform insert/update/delete
# use dbv.prepare to fetch data
#
# this is only a framework guide, but you can put this into a class as per your own requirements
so far, my database is coming along swimmingly.
for a quick overview of sql statements i use
http://www.w3schools.com/php/php_mysql_intro.asp
any more queries, i'm happy to help

I still have problems, do not understand why I can not enter data in the database, paste the code
thanks
Code:
db=e32db.Dbms()
dbv=e32db.Db_view()
try:
db.open(u'e:\\Python\\src\\test.db')
except:
db.create(u'e:\\Python\\src\\test.db')
db.open(u'e:\\Python\\src\\test.db')
#to create ur table
db.execute(u"create table fuel (id counter, date varchar, priceLiter float, euro float, paid varchar, who varchar, km float, another long varchar)")
db.execute(u"insert into fuel values(1,'%s','%f','%f','%s','%s','%f','%s')" % (date, priceLiter, euro, paid, who, km, another))