Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import sqlite3 as sql
- import sys
- class SQLManager():
- def __init__(self, db):
- self.db = db
- self.con = sql.connect(self.db)
- self.cur = None
- def select(self):
- self.cur = self.con.cursor()
- self.cur.execute("SELECT * FROM songs")
- while True:
- row = self.cur.fetchone()
- if row == None:
- break
- print "ID: {0}, Nombre: {1}, Duracion: {2}".format(row[0], row[1], row[2])
- self.con.close()
- def insert(self):
- songs = (
- (1, "dubstep1", "10:00"),
- (2, "dubstep2", "05:40")
- )
- try:
- self.cur = self.con.cursor()
- self.cur.execute("DROP TABLE IF EXISTS songs")
- self.cur.execute("CREATE TABLE songs (ID INT, NAME TEXT, LENGTH TEXT)")
- self.cur.executemany("INSERT INTO songs VALUES (?, ?, ?)", songs)
- self.con.commit()
- except sql.Error, e:
- if self.con:
- self.con.rollback()
- print "Error %s:" % e.args[0]
- sys.exit(1)
- finally:
- if self.con:
- self.con.close()
Advertisement
Add Comment
Please, Sign In to add comment