I've written some docs on how this is handled in Camelot, the
same principles apply for Elixir though

http://downloads.conceptive.be/downloads/camelot/doc/sphinx/build/doc/under_the_hood.html


On Fri, 2011-02-25 at 12:30 -0800, Magnus Pettersson wrote:
> I have written all classes that handles the sqlite database in one
> python file called "mediaDatabase.py" and then i want to import that
> module into another file "mediaGui.py" to be able to query and write
> to the database. but i always get a sqlalchemy.exc.OperationalError
> that table does not exist or databse is locked (think it was the
> "table does not exist" if i actually created and filled and some
> entrys into the database.sqlite file from within the mediaDatabase.py,
> and i get "database is locked" when i created the sqlite file and
> entities from within the "mediaGui.py" file
> 
> Here is the locked exception:
> sqlalchemy.exc.OperationalError: (OperationalError) database is locked
> u'INSERT INTO mediadatabase_item (path, title, type, year, "imdbID",
> genres, library_path) VALUES (?, ?, ?, ?, ?, ?, ?)' (u'V:/Movies/',
> u'Bedtime Stories', 'movie', u'2008', None, None, None)
> 
> I tried to read around about sqlalchemy and found out that i need to
> do something with the metadata or session but i cant figure out what &
> how & where to put stuff
> 
> A extract from mediaDatabase.py:
> 
> from elixir import *
> dbfile = "mediaDatabase.sqlite"
> 
> class Database:
>     def initDb(self):
>         metadata.bind = "sqlite:///%s" % dbfile
>         setup_all()
>         if not os.path.exists(dbfile):
>             create_all()
> 
>     def saveData(self):
>         session.commit()
> 
>     def parseMediaItem(self,media):
>         item =
> Item(path=media["path"],title=media["title"],type=media["type"])
>         libs = Library.query.all()
>         for lib in libs:
>             if lib.path == item.path:
>                 lib.items.append(item)
>                 foundlib = True
>                 break
> 
> class File(Entity):
>     path = Field(Unicode, required=True)
>     filename = Field(Unicode, required=True)
>     ext = Field(Unicode,required=True)
>     item = ManyToOne("Item")
> 
> class Library(Entity):
>     path = Field(Unicode, primary_key=True)
>     name = Field(Unicode)
>     items = OneToMany("Item")
> 
> 
> And some lines from mediaGui.py :
> 
> from mediaDatabase import Database,Item,Library,File
> MDB = Database()
> 
> class MainForm(QtGui.QMainWindow, Ui_MainWindow):
>       #init etc here
> 
>       def update(self):
>              #some code here
>             MDB.parseMediaItem(m)  # HERE comes the error, right now
> when writing its a
> 
> 
> if __name__ == "__main__":
>     MDB.initDb()
> 


-- 
You received this message because you are subscribed to the Google Groups 
"SQLElixir" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlelixir?hl=en.

Reply via email to