My first attempt at a Python SQLite class to use in an app

Not sure if its the best way to do it, but it works.

# -*- coding: utf-8 -*-

# make sure it's a new style class
__metaclass__ = type

import sqlite3 as lite
import sys

class SqlMgr:

def __init__(self):

self.dbPath = 'buildings.db'
self.con = None

def getConnection(self, dbPath):

self.con = lite.connect(dbPath)
print "connection created"
except lite.Error, e:

print "Error %s:" % e.args[0]

def query(self,sql):

rows = []


#with self.con:
cur = self.con.cursor()

# print "the first element in rows will be the column names."
column_names = [x[0] for x in cur.description]

while True:
row = cur.fetchone()

if row == None:


except lite.Error, e:

print "Error %s:" % e.args[0]

return rows

def main():

sqlmgr = SqlMgr()

print "the first element in rows will be the column names."
rows = sqlmgr.query("select * from buildings")
cols = rows.pop(0)

print "column names"
print cols
print "data"
print rows

if __name__ == "__main__":


Add a Comment...



It's perfect time to make a few plans for the long run and it is time to be happy. I have read this submit and if I may just I desire to counsel you few fascinating things or suggestions. Perhaps you could write next articles referring to this article. I wish to learn even more things approximately it!wholesale ncaa jerseys - 7/21/2017

Awesome! Its genuinely remarkable piece of writing, I have got much clear idea on the topic of from this piece of writing. maglie calcio a poco prezzo - 6/30/2017

Along with this, digital marketing also takes you to places where you have never recently been before; in the hearts associated with millions of consumers all around the planet.Let's talk about what you don't want in a survival knife. K. A survival knife is a tool to enhance your ability or probability of survival in extreme conditions, most likely, outdoors. Your new home will look like a hacked up, Cheap NFL Jerseys Shop, unbalanced mess of a stick hut." George Burns"If you live to the age of - 6/22/2017

Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I've been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates. - 6/02/2017

Wow that was unusual. I just wrote an incredibly long comment but after I clicked submit my comment didn't appear. Grrrr... well I'm not writing all that over again. Anyway, just wanted to say great blog! nuova maglia milan 2017 - 5/16/2017

Hi, I do believe this is a great website. I stumbledupon it ; ) I am going to return yet again since i have book marked it. Money and freedom is the greatest way to change, may you be rich and continue to help other people. Fotballdrakter Mexico tredje - 4/22/2017

I read this paragraph completely about the comparison of hottest and earlier technologies, it's amazing article. fotballdrakter - 4/17/2017

Very great post. I just stumbled upon your weblog and wanted to mention that I have truly enjoyed browsing your blog posts. In any case I will be subscribing to your feed and I am hoping you write again soon! maglie calcio poco prezzo - 4/01/2017

Great post. I was checking continuously this blog and I'm impressed! Extremely useful information specifically the last part :) I care for such information a lot. I was seeking this particular information for a very long time. Thank you and best of luck. fodboldtrøjer - 3/31/2017

I got this web site from my buddy who told me about this website and now this time I am browsing this web site and reading very informative articles at this time. Maglia Chelsea Bambino - 3/31/2017