public
Description: A simple wxPython app for sorting and searching though guitar tablature and other musical notation.
Homepage: http://www.dimblewik.com/
Clone URL: git://github.com/jameyc/tabmanager.git
tabmanager / database.py
100644 61 lines (55 sloc) 2.184 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/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"]