In [1]:
import sqlite3

In [2]:
conn = sqlite3.connect('db.sqlite3')

In [3]:
conn.execute('create table cars(id integer primary key, title text, ports text, year text)')


Out[3]:
<sqlite3.Cursor at 0x108acaab0>

In [4]:
conn.commit()

In [5]:
car = {'title': 'Gol 2011 completo', 'ports': '4 portas', 'year': '2010/2011'}

In [6]:
car


Out[6]:
{'ports': '4 portas', 'title': 'Gol 2011 completo', 'year': '2010/2011'}

In [8]:
conn.execute('insert into cars(title, ports, year) values (:title, :ports, :year)', car)


Out[8]:
<sqlite3.Cursor at 0x108aca8f0>

In [9]:
conn.commit()

In [10]:
result = conn.execute('select title, ports, year from cars')

In [11]:
for car in result:
    print(car)


('Gol 2011 completo', '4 portas', '2010/2011')

In [12]:
result = conn.execute('select id, title, ports, year from cars')

In [13]:
for car in result:
    print(car)


(1, 'Gol 2011 completo', '4 portas', '2010/2011')

In [14]:
car = {'title': 'Gol 2011 completo', 'ports': '4 portas', 'year': '2010/2011'}
conn.execute('insert into cars(title, ports, year) values (:title, :ports, :year)', car)


Out[14]:
<sqlite3.Cursor at 0x108bdc650>

In [15]:
conn.commit()

In [16]:
result = conn.execute('select id, title, ports, year from cars')

In [17]:
for car in result:
    print(car)


(1, 'Gol 2011 completo', '4 portas', '2010/2011')
(2, 'Gol 2011 completo', '4 portas', '2010/2011')

In [18]:
conn.close()

In [19]:
result = conn.execute('select id, title, ports, year from cars')


---------------------------------------------------------------------------
ProgrammingError                          Traceback (most recent call last)
<ipython-input-19-17466315254e> in <module>()
----> 1 result = conn.execute('select id, title, ports, year from cars')

ProgrammingError: Cannot operate on a closed database.

In [ ]: