I want to know if a row exists already in one of my tables, in this case coll
. In order to do this I played around with SQLite in the shell a little and stumbled upon SELECT EXISTS(SELECT 1 FROM coll WHERE ceeb="1234")
. In SQLite this works perfectly and it returns either a 0
or a 1
-- which is exactly what I wanted. So, with code in hand, I wrote up a quick Python script to see if I could get this to work for me before sticking it into my program. This is what I came up with:
import sqlite3
conn = sqlite3.connect('stu.db')
c = conn.cursor()
sceeb = int(raw_input(":> "))
ceeb_exists = c.execute('SELECT EXISTS(SELECT 1 FROM coll WHERE ceeb="%d" LIMIT 1)' % sceeb)
print ceeb_exists
Instead of assigning ceeb_exists
a 1
or a 0
it gives me an output that looks like <sqlite3.Cursor object at 0x01DF6860>
. What am I doing wrong here?
Aucun commentaire:
Enregistrer un commentaire