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

Return to Revisions

4 of 4
edited body; deleted 2 characters in body
Max Frai
  • 64.7k
  • 82
  • 206
  • 311

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()

→ []

Max Frai
  • 64.7k
  • 82
  • 206
  • 311
default

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