Python

Moderators: None (Apply to moderate this forum)
Number of threads: 473
Number of posts: 1172

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Sqlite3 trouble Posted by Brontesinho on 16 Nov 2010 at 4:30 PM
I'm having some trouble with sqlite3 on my windows mobile device. Sometimes it happens that commit is not working.

Here is the code, that I'm using:
    
def OnSaveProfile(self, event):
        naziv = self.edt_title.text
        if not naziv:
            gui.Message.ok(u"Error!", u"Enter profile title!", icon='error', parent=self)
            return 0
        potnik = self.edt_st_potn.text
        if not potnik:
            gui.Message.ok(u"Error!", u"Enter number of worker!", icon='error', parent=self)
            return 0
        baza = self.com_baza.text
        
        #Here I connect to the database
        conn = orodja.povezava_na_bazo(self, "Nastavitve")
        c = conn.cursor()
        c.execute("Select nast_koda from Nastavitve where nast_koda = 'prof_%(naziv)s'" % {"naziv": naziv})
        dRez = c.fetchone()
        cins = conn.cursor()
        if dRez:#Checking if I need to update or insert new value
            retexec = cins.execute("Update Nastavitve set nast_vrednost = ? where nast_koda = ?", (potnik + "," + baza, "prof_"+naziv))
        else:
            retexec = cins.execute("Insert into Nastavitve Values (?, ?)", ("prof_"+naziv, potnik + "," + baza))
        
        print "Total changes", retexec.connection.total_changes #this returns 1 

        c2 = conn.cursor()
        c2.execute("Select nast_koda from Nastavitve where nast_koda = 'prof_%(naziv)s'" % {"naziv": naziv})
        dRez2 = c2.fetchone()
        #Test if new value is in the table before commit
        print "PredComm", dRez2#I always get the rasult here 
        
        ret = conn.commit()
        c1 = conn.cursor()
        c1.execute("Select nast_koda from Nastavitve where nast_koda = 'prof_%(naziv)s'" % {"naziv": naziv})
        dRez1 = c1.fetchone()
        #Test if new value is in the table after commit
        print "PoComm", dRez1#Sometimes happens that dRez1 == None
        print "Total changes", retexec.connection.total_changes #this returns 1 
         
        self.Osvezi_profile()
        pass


I call function OnSaveProfile when I click some button on form. This code is meant to insert or update some data in table 'Nastavitve'. It works most of time, but sometimes the data just doen't inserts into table. When I click the button again, then it works fine (sometimes not on first click, but on second, third, ...). There is always data in table before commit. After commit it is sometimes gone. It looks like that instead of commit sqlite3 executes rollback.

I've done integrity_check and it returned 'ok'. I have PRAGMA synchronous set to 2-FULL. I've tried different isolation_level-s with no success.

I'm having trouble only on windows mobile device. When I run the application on desktop PC it always works fine.

So is this a bug on Windows Mobile or am I doing something wrong?

Thanks in advance for answer.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.