Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Python and sqlite trouble

I can't show the data from database sqlite in python.

connection = sqlite3.connect('db')
connection.cursor().execute('CREATE TABLE IF NOT EXISTS users ( \
 id TEXT, \
 name TEXT, \
 avatar TEXT \
 )')
# In cycle:
query = 'INSERT INTO users VALUES ("' + str(friend.id) + '", "' + friend.name + '", "' + friend.avatar +'" )'
print query
connection.cursor().execute(query)
connection.commit()
# After cycle
print connection.cursor().fetchall()

Sample output of query variable:

INSERT INTO users VALUES ("111", "Some Name", "http://avatar/path" )

In result, fetchall returns empty tuple. Why?


UPD Forgotten code:

connection.cursor().execute('SELECT * FROM users')
connection.cursor().fetchall()

→ []

Answer*

Draft saved
Draft discarded
Cancel
2
  • I think he's referring to the quotes, although I'm guessing that the mismatch is not really present in your code since you don't get a Python syntax error, and since the INSERT statement prints out ok. Commented Jul 31, 2010 at 17:01
  • @larry-lustig @msw oh sorry, that's my fault. There is passing constant string and I forgot to take out the quotes after replacing it with simple string. Commented Jul 31, 2010 at 17:06

default

AltStyle によって変換されたページ (->オリジナル) /