· 7 years ago · Oct 30, 2018, 10:02 AM
1>>> import sqlite3
2>>> conn = sqlite3.connect('example.db')
3>>> c = conn.cursor()
4>>> c.execute('pragma encoding')
5<sqlite3.Cursor object at 0x7f441ce90e30>
6>>> rows = c.fetchall()
7>>> for row in rows:
8... print(row)
9...
10('UTF-8',)
11>>> sql_create_projects_table = """ CREATE TABLE IF NOT EXISTS projects (
12... id integer PRIMARY KEY,
13... name text NOT NULL,
14... begin_date text,
15... end_date text
16... ); """
17>>> c.execute('pragma encoding=UTF16')
18<sqlite3.Cursor object at 0x7f441ce90e30>
19>>> c.execute(sql_create_projects_table)
20<sqlite3.Cursor object at 0x7f441ce90e30>
21>>> rows = c.fetchall()
22>>> for row in rows:
23... print(row)
24...
25>>> sql = ''' INSERT INTO projects(name,begin_date,end_date)
26... VALUES(?,?,?) '''
27>>> project = ('Cool App with SQLite & Python', '2015-01-01', '2015-01-30');
28>>> cur.execute(sql, project)
29Traceback (most recent call last):
30 File "<stdin>", line 1, in <module>
31NameError: name 'cur' is not defined
32>>> c.execute(sql, project)
33<sqlite3.Cursor object at 0x7f441ce90e30>
34>>> c.execute("SELECT * FROM projects")
35<sqlite3.Cursor object at 0x7f441ce90e30>
36>>> rows = c.fetchall()
37>>> for row in rows:
38... print(row)
39...
40(1, 'Cool App with SQLite & Python', '2015-01-01', '2015-01-30')
41>>> c.execute('pragma encoding')
42<sqlite3.Cursor object at 0x7f441ce90e30>
43>>> rows = c.fetchall()
44>>> for row in rows:
45... print(row)
46...
47('UTF-16le',)
48>>> exit()
49(general) ➜ ~ python3
50Python 3.5.2 (default, Nov 23 2017, 16:37:01)
51[GCC 5.4.0 20160609] on linux
52Type "help", "copyright", "credits" or "license" for more information.
53>>> import sqlite3
54>>> conn = sqlite3.connect('example.db')
55>>> c = conn.cursor()
56>>> c.execute('pragma encoding')
57<sqlite3.Cursor object at 0x7fab8b225e30>
58>>> rows = c.fetchall()
59>>> for row in rows:
60... print(row)
61...
62('UTF-16le',)