Kieth,

thanks for the info, however, I tested the following code on a LOCAL copy of 
the database, 
one where at the sqlite3 command line I was able to do an insert without 
problems, and yet, 
the python code returned the 'database is locked; error message in the code (I 
used a 
wxpython messagebox widget to display the error).

Why would it return a locked message in this case?

Here's the code:

        def OnSave(self, event):
                self.dbupdated = True
                self.pub_title = self.pub_text.GetValue()
                self.pub_remarks = self.remarks_text.GetValue()
                print self.pub_title
                print self.pub_remarks
                # update relevant tables(s)
                self.cdata.execute('insert into publishers(publisher_name, 
remarks)  values("test", "remarks");')
                
                try:
                        self.database.commit()
                except sqlite.Error, dberr:
                        wx.MessageBox(dberr.args[0], 'DB Warning', 
wx.OK)
                        self.dbupdated = False
                        
                # clear fields
                if self.dbupdated:
                        self.pub_text.SetValue(' ')
                        self.remarks_text.SetValue(' ')
                        
                print 'dbupdated = ' , self.dbupdated
                print self.add
                self.add = False
                print self.add

sqlite3 version 3.7.4

Mark


On Friday, October 03, 2014 10:37:06 PM Keith Medcalf wrote:
> Yes.  pysqlite/sqlite3 in python tries to manage transactions for you by
> automatically starting them, and you need to commit them yourself.  This is
> controlled by the isolation_level attribute set on the connection (can also
> be set as a parameter when you open the connection).
> 
> The default value is '' (an empty string).  Other valid values are
> 'IMMEDIATE', 'EXCLUSIVE' and None.  Basically, pysqlite tries to detect the
> type of statement you are running and if it is a DML statement (select,
> insert, update, delete) it automatically begins a transaction for you if
> one is not in progress by first doing a 'BEGIN '+isolation_level.  If the
> statement is something other than DML, then it will 'COMMIT' before
> executing the DDL (CREATE/DROP) then it will 'COMMIT' after executing it. 
> It does not know about the "WITH" statement, so treats those as DDL rather
> than DML.
> 
> Setting isolation_level to None tells pysqlite/sqlite3 to not manage
> transactions and let the SQLite3 engine do it as it would from the C
> interface or the sqlite3.exe command line tool (what the dbapi calls
> autocommit mode), so you have to issue your own BEGIN and COMMIT/ROLLBACK
> commands where you want them and the pysqlite/sqlite3 interface modules
> will not attempt to begin or commit transactions for you.
> On Friday, 3 October, 2014 21:48, you wrote:
> >Ah, ok.  after doing a database commit I get the error going to stderr.
> >Now it's just a matter
> >of capturing/redirecting the stderr output and using an except there.
> >
> >On Friday, October 03, 2014 11:35:08 PM you wrote:
> >> the sqlite3 command line doesn't require a commit, it gave an error
> >> after the attempted insert command.
> >> 
> >> pysqlite requires one?
> >> 
> >> Mark
> >> 
> >> On Friday, October 03, 2014 09:06:56 PM Keith Medcalf wrote:
> >> > Are you committing the change?
> >> > 
> >> > >-----Original Message-----
> >> > >From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
> >> > >boun...@sqlite.org] On Behalf Of Mark Halegua
> >> > >Sent: Friday, 3 October, 2014 20:58
> >> > >To: sqlite-users@sqlite.org
> >> > >Subject: [sqlite] passing error messages to pysqlite
> >> > >
> >> > >I have a sqlite3 database.  In the networkied are I have the db is
> >
> >locked
> >
> >> > >(wee've
> >> > >discussed this before, and I'm using it mostly on a local machine,
> >
> >but I
> >
> >> > >need to
> >> > >test certain conditions, networking being one).
> >> > >
> >> > >In the sqlite3 command line, when I try to insert new info I get a
> >
> >dabase
> >
> >> > >locked
> >> > >message.
> >> > >
> >> > >Hosever, when I do the same in python with pysqlite, it doesn't
> >
> >return
> >
> >> > >anything
> >> > >and the code proceeds as if nothing happened, and the program just
> >
> >goes
> >
> >> > >on,
> >> > >even though the data wasn't saved/
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to