ocarina/src/core/ct/db.py

70 lines
1.5 KiB
Python

#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Jan 27, 2010 6:21:27 PM$"
from bt.message import write
from bt import sql
def init():
if sql.dbexists() == True:
return
table = sql.CTable("library")
table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT")
table.addcol("name","TEXT","UNIQUE")
table.addcol("path","TEXT","UNIQUE")
table.execute()
table = sql.CTable("artist")
table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT")
table.addcol("name","TEXT","UNIQUE")
table.execute()
table = sql.CTable("album")
table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT")
table.addcol("name","TEXT","UNIQUE")
table.execute()
table = sql.CTable("track")
table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT")
table.addcol("artist","INTEGER")
table.addcol("album","INTEGER")
table.addcol("count","INTEGER")
table.addcol("length","INTEGER")
table.addcol("name","TEXT")
table.addcol("path","TEXT","UNIQUE")
table.execute()
table = sql.CTable("libtrack")
table.addcol("library","INTEGER")
table.addcol("track","INTEGER")
table.execute()
def newlib(name,path):
try:
ins = sql.Insert('library',[None,name,path])
ins.execute()
except:
pass
def rmlib(name):
rm = sql.Remove("library","name='"+name+"'")
rm.execute()
def listlib():
sel = sql.Select("*","library")
result = sel.execute().fetchall()
write("Id Name Path")
write("------------------")
for row in result:
write( str(row[0]) + " " +
row[1] + " " + row[2] )