100 lines
1.5 KiB
Python
100 lines
1.5 KiB
Python
# This is a simple test plugin, to make sure everything is working
|
|
|
|
__author__="bjschuma"
|
|
__date__ ="$Dec 27, 2009 9:58:50 PM$"
|
|
|
|
|
|
global name, app, type, path, opt
|
|
name = "database"
|
|
app = "ocarina"
|
|
type = "core"
|
|
path = ""
|
|
opt = []
|
|
|
|
|
|
import settings
|
|
from bt.file import *
|
|
|
|
import sqlite3
|
|
|
|
#global conn, c
|
|
#conn = None
|
|
#c = None
|
|
global db
|
|
global conn
|
|
global vals
|
|
db = None
|
|
conn = None
|
|
vals = dict()
|
|
|
|
|
|
# Collect all information for what to insert
|
|
# Build into a large statement, then insert
|
|
# This will speed things up
|
|
# Reconnect to sqlite at every run, to avoid thread problems
|
|
|
|
|
|
def create():
|
|
global conn
|
|
conn.executescript("""
|
|
CREATE TABLE files
|
|
(
|
|
path TEXT PRIMARY KEY
|
|
);
|
|
|
|
CREATE TABLE artist
|
|
(
|
|
arid INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT UNIQUE
|
|
);
|
|
|
|
UPDATE SQLITE_SEQUENCE SET seq = 1 WHERE name = 'artist';
|
|
|
|
""")
|
|
|
|
global vals
|
|
vals["files"] = "?"
|
|
vals["artist"]= "?,?"
|
|
|
|
|
|
|
|
def open():
|
|
global db, conn
|
|
conn = sqlite3.connect(db)
|
|
conn.text_factory = str
|
|
|
|
|
|
def close():
|
|
global conn
|
|
conn.commit()
|
|
conn.close()
|
|
conn = None
|
|
|
|
|
|
def init():
|
|
global db
|
|
db = join(settings.get("ocarina"),"ocarina.db")
|
|
dbExists = checkPath(db)
|
|
open()
|
|
if dbExists == False:
|
|
create()
|
|
close()
|
|
|
|
|
|
def insert(table, values):
|
|
global conn
|
|
if conn == None:
|
|
open()
|
|
global vals
|
|
#c = conn.cursor()
|
|
#t = (file,)
|
|
conn.execute('INSERT OR IGNORE INTO ' + table + ' VALUES(' + vals[table] + ')',values)
|
|
#c.close()
|
|
|
|
|
|
def count(table):
|
|
global conn
|
|
if conn == None:
|
|
open()
|
|
result = conn.execute('select count(*) from '+ table)
|
|
return result.fetchone()[0] |