-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23db_create_table.py
More file actions
28 lines (25 loc) · 817 Bytes
/
23db_create_table.py
File metadata and controls
28 lines (25 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python
import sqlite3
dbPath = "DBtesty/db01.sqlite"
tableName = "t21"
try:
con = sqlite3.connect(dbPath)
print("OK: connected to", dbPath)
except sqlite3.Error as error:
print("Problem to connect to {}: {}".format(dbPath, error))
else:
try:
with con:
cur = con.cursor()
query = """
CREATE TABLE {}(
id INTEGER PRIMARY KEY AUTOINCREMENT,
col01 INTEGER NOT NULL,
col02 REAL,
col04 TEXT DEFAULT CURRENT_TIMESTAMP,
col05 BLOB
)""".format(tableName)
cur.execute(query)
print("Table created:", tableName)
except sqlite3.Error as error:
print("Problem to create table:", error)