Simplify using SQL in pys60
This one add a select_all function and try/except for type 16 (long varbin).
1 2 import e32db 3 db = e32db.Dbms() 4 dbv = e32db.Db_view() 5 db.open(u'C:\\system\\data\\bookmarks1.db') 6 7 def select_row(query): 8 dbv.prepare(db, unicode(query)) 9 dbv.first_line() 10 dbv.get_line() 11 result = [] 12 for i in range(dbv.col_count()): 13 try: 14 result.append(dbv.col(i+1)) 15 except: # in case coltype 16 16 result.append(None) 17 return result 18 19 def select_all(query): 20 dbv.prepare(db, unicode(query)) 21 dbv.first_line() 22 rows = [] 23 for i in range(dbv.count_line()): 24 dbv.get_line() 25 result = [] 26 for i in range(dbv.col_count()): 27 try: 28 result.append(dbv.col(i+1)) 29 except: # in case coltype 16 30 result.append(None) 31 rows.append(result) 32 dbv.next_line() 33 return rows
Now I can simply call
1 2 >>> select_row('SELECT * FROM Favourites') # 1 row 3 >>> select_all('SELECT * FROM Favourites') # all rows
For non-select SQL, you can simply use db.execute(query).