title: Search database
body: <p>Furthering my study of database use in python, I have come up with the following code based on Bryan Moyles excellent example:</p>
  
  <pre><code>from os   import system as cmd
  from time import sleep  as sleep
  try:
      from sqlite3 import dbapi2 as sqlite
  except ImportError:
      from pysqlite2 import dbapi2 as sqlite
  
  class search_db:
      def __init__(self, db, name):
          self.db = db_connection
          self.name = name
          self.dbc = self.db.cursor()
  
      def __getitem__(self, item):
          self.dbc.execute("select * from %s limit %s, 1" % (self.name, item))
          return self.dbc.fetchone()
  
  def search():
      customer_id  = []
      customer_ids = search_db(db_connection, "customers")
      for i in range(10000):
          if not "None" in str(customer_ids[i]): customer_id.append(customer_ids[i])
      return customer_id
  
  ## init ##
  db_name = 'customers'
  db_connection = sqlite.connect('program.db')
  db_curs = db_connection.cursor()
  
  search()
  </code></pre>
  
  <p>Sure, it's nothing fantastic, and I know I could probably optimise it a tad more; but as you can see, I've been trying hard to figure out how to search the database. I managed to retrieve entries that contain information in the database, which pulls out an entry number. I was thinking of using if loops to search the appended list values for a "GGS-<em>number</em>" entry, then using regular expressions to extract the line number - then printing the information relevant to the customer that the GGS number applies to. Has anyone got any ideas how I could do this in a better way? Also, I have a for i in range(10000), is there a more optimised form of this?</p>