sqlite3 update database with "?" - python
<p>I have: </p>

<p>database testing.db3
table: mytable
columns: 'name', 'status'</p>

<p>I do:</p>

<pre><code>con = sqlite3.connect('testing.db3')
cur = con.cursor()
cur.execute('select * from mytable where status is null')

data = cur.fetchone()
print(data[0])
</code></pre>

<p>as wanted I receive following result:</p>

<pre><code>('Johnny', 'None')
</code></pre>

<p>Now I am trying to update this line, it works if I do:</p>

<pre><code>cur.execute('UPDATE mytable SET status = "Online" WHERE name is "Johnny"')
</code></pre>

<p>However if I want to update it with '?', it just doesn't work. Any idea why?</p>

<pre><code>cur.execute('UPDATE mytable SET status = "Online" WHERE name is ?', data[0])
con.commit()
con.close()
</code></pre>

<p>Would appreciate any help. Thank you.</p>

<pre><code>cur.execute('UPDATE mytable SET status = "Online" WHERE name is ?', (data[0], ))
</code></pre>

<p><code>execute</code> expects a tuple as an input parameter. Therefore, even if you insert only a single value, you should format it as a tuple. </p>

<p>Although in your question you say that <code>data[0] = ('Johnny', 'None')</code>, in the comments you indicate that <code>data[0]</code> is the first value of the tuple. So I assume the latter one is the case.</p>

python sql sqlite3 insert