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...



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

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

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