Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Korakot Chaovavanich http://korakot.stumbleupon.com

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Simplify using SQL in pys60

I wrote a similar snippet a while ago.
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).

Auto-submit dropdown menu

Many users assume that a <select> element (dropdown menu)
will have its effect without pressing submit button.
(poor user...). The solution is to have it submit automatically.
   1  
   2  <select name='myfield' onchange='this.form.submit()'>
   3  <option .... >
   4  ...
   5  </select>
   6  </form>

Simply onchange='this.form.submit()'
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS