1import sqlite3
2
3try:
4 sqliteConnection = sqlite3.connect('SQLite_Python.db')
5 cursor = sqliteConnection.cursor()
6 print("Database created and Successfully Connected to SQLite")
7
8 sqlite_select_Query = "select sqlite_version();"
9 cursor.execute(sqlite_select_Query)
10 record = cursor.fetchall()
11 print("SQLite Database Version is: ", record)
12 cursor.close()
13
14except sqlite3.Error as error:
15 print("Error while connecting to sqlite", error)
16finally:
17 if (sqliteConnection):
18 sqliteConnection.close()
19 print("The SQLite connection is closed")
1#Fetches the next row of a query result set, returning a single sequence, or None when no more data is available.
2import sqlite3
3
4con = sqlite3.connect(":memory:")
5cur = con.cursor()
6cur.executescript("""
7 create table samples(
8 id,
9 value
10 );
11 insert into samples(id, value)
12 values (
13 '123',
14 'abcdef'
15 );
16 """)
17cur.execute("SELECT * from samples")
18print cur.fetchone()
19OUTPUT
20(u'123', u'abcdef')