开发者

how to assign an sql value to this python variable

开发者 https://www.devze.com 2023-03-06 18:25 出处:网络
ok i got this as simple as i can, everythings working and i need one last thing before I\'m done with this issue

ok i got this as simple as i can, everythings working and i need one last thing before I'm done with this issue i am using sqlite3 module in python i also have very limited sql expierance

the problem- i need to take the only value out of an sql table; the tablename is saves and the row id is 0 the name of the row is lvl. i need to then assign this as the value of the python variable lvl. Then on closure of the program i need to update the sql table with the current value of the python variable lvl (it will take the place of the data i just retrieved--there will also be numerous operations in between).

My code for assigning the value of the python Variable

conn = sql.connect('databaserm/database')
curs = conn.cursor()
curs.execute('SELECT 0 FROM saves')
lvl = curs.fetchone()
conn.commit
conn.close()

after running this i get the output None

and my code for adding data to the database on closure

            elif choice == q:
                if choice == q:
                    cn = sqlite3.connect('/databaserm/database')
                    curs = cn.cursor()
                    curs.execute('INSERT INTO saves (lvl) VALU开发者_C百科ES (?)', lvl)        
                    cn.commit
                    cn.close()
                loop1 = 0
                loop = 10000
                print "Goodbye!"
                sys.exit(0)

after running this with a preloaded database and the previous code ommited i get a connection error

i would be overjoyed at any help i'm offered and hope to work out a solution to this soon


SELECT 0 FROM saves is not sensible (or valid) SQL, you probably want to do something like SELECT * FROM saves WHERE lvl = 0

I suggest reading some sql tutorial

0

精彩评论

暂无评论...
验证码 换一张
取 消