Check if row exists in SQLite with Python
<p>I want to know if a row exists already in one of my tables, in this case <code>coll</code>. In order to do this I played around with SQLite in the shell a little and stumbled upon <code>SELECT EXISTS(SELECT 1 FROM coll WHERE ceeb="1234")</code>. In SQLite this works perfectly and it returns either a <code>0</code> or a <code>1</code>-- 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:</p>

<pre><code>import sqlite3

conn = sqlite3.connect('stu.db')
c = conn.cursor()

sceeb = int(raw_input(":&gt; "))

ceeb_exists = c.execute('SELECT EXISTS(SELECT 1 FROM coll WHERE ceeb="%d" LIMIT 1)' % sceeb)

print ceeb_exists
</code></pre>

<p>Instead of assigning <code>ceeb_exists</code>a <code>1</code> or a <code>0</code> it gives me an output that looks like <code>&lt;sqlite3.Cursor object at 0x01DF6860&gt;</code>. What am I doing wrong here?</p>