Python, Sqlite not saving results on the file
Question: I have this code in Python:

    
    
    conn = sqlite3.connect("people.db")
    cursor = conn.cursor()
    
    sql = 'create table if not exists people (id integer, name VARCHAR(255))'
    cursor.execute(sql)
    conn.commit()
    
    sql = 'insert into people VALUES (3, "test")'
    cursor.execute(sql)
    conn.commit()   
    
    sql = 'insert into people VALUES (5, "test")'
    cursor.execute(sql)
    conn.commit()  
    
    print 'Printing all inserted'
    cursor.execute("select * from people")
    for row in cursor.fetchall():
        print row
    
    cursor.close()
    conn.close()
    

But seems is never saving to the database, there is always the same elements
on the db as if it was not saving anything.

On the other side If I try to access the db file via sqlite it I got this
error:

    
    
    Unable to open database "people.db": file is encrypted or is not a database
    

I found on some other answers to use `conn.commit` instead of `conn.commit()`
but is not changing the results.

Any idea?


Answer: This seems to work alright for me ("In database" increases on each run):

    
    
    import random, sqlite3
    
    conn = sqlite3.connect("people.db")
    cursor = conn.cursor()
    
    sql = 'create table if not exists people (id integer, name VARCHAR(255))'
    cursor.execute(sql)
    
    for x in xrange(5):
        cursor.execute('insert into people VALUES (?, "test")', (random.randint(1, 10000),))
    conn.commit()
    
    cursor.execute("select count(*) from people")
    print "In database:", cursor.fetchone()[0]
    

