#!/usr/bin/env python ## This file is part of Tab Manager ## Copyright: 2007 Jamey Campbell ## ## Tab Manager is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## Tab Manager is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program. If not, see http://www.gnu.org/licenses/ . from pysqlite2 import dbapi2 as sqlite import prefs class Connection : #accept an sql string, execute, and return results as a dictionary def fetch(self, sql): self.con = sqlite.connect("local.db") #Setting the row factory type to row so we can access by name self.con.row_factory = sqlite.Row self.cursor = self.con.cursor() self.cursor.execute(sql) results = self.cursor.fetchall() self.cursor.close() self.con.close() return results def insert(self, sql): self.con = sqlite.connect("local.db") self.cursor = self.con.cursor() self.cursor.execute(sql[0], sql[1]) self.con.commit() self.cursor.close() self.con.close() ## This function gets the full list of songs and is what we run at startup, ## just because I'm lazy and it looks decent at startup. Later might make ## startup either blank, or remember previous view. # #helper functions # #test code... ignore this if __name__ == "__main__": mycon = Connection() list = mycon.fetch(""" SELECT `artists`.`artist` , `songs`.`title` , `songs`.`id`, `songs`.`favorite`, `songs`.`study` FROM songs INNER JOIN artists ON songs.artist = artists.id WHERE `songs`.`study` = "1" ORDER BY `artists`.`artist` ASC , `songs`.`title` ASC """) print list[0]["artist"]