-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlite3thing.py
67 lines (61 loc) · 2.68 KB
/
sqlite3thing.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sqlite3
import csv
from sqlite3 import Error
def create_connection(db_file):
""" create a database connection to the SQLite database
specified by db_file
:param db_file: database file
:return: Connection object or None
"""
try:
conn = sqlite3.connect(db_file)
return conn
except Error as e:
print(e)
return None
def create_table(conn, create_table_sql):
""" create a table from the create_table_sql statement
:param conn: Connection object
:param create_table_sql: a CREATE TABLE statement
:return:
"""
try:
c = conn.cursor()
c.execute(create_table_sql)
except Error as e:
print(e)
def main():
database = "credit.db"
sql_create_credit_table = """CREATE TABLE credit_card_info (
post_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
limit_bal INTEGER NOT NULL,
sex INTEGER NOT NULL,
education INTEGER NOT NULL,
marriage INTEGER NOT NULL,
age INTEGER NOT NULL,
pay_0 INTEGER NOT NULL,
pay_1 INTEGER NOT NULL,
pay_2 INTEGER NOT NULL,
pay_3 INTEGER NOT NULL,
pay_4 INTEGER NOT NULL,
pay_6 INTEGER NOT NULL,
bill_amt1 INTEGER NOT NULL,
bill_amt2 INTEGER NOT NULL,
bill_amt3 INTEGER NOT NULL,
bill_amt4 INTEGER NOT NULL,
bill_amt5 INTEGER NOT NULL,
bill_amt6 INTEGER NOT NULL,
pay_amt1 INTEGER NOT NULL,
pay_amt2 INTEGER NOT NULL,
pay_amt3 INTEGER NOT NULL,
pay_amt4 INTEGER NOT NULL,
pay_amt5 INTEGER NOT NULL,
pay_amt6 INTEGER NOT NULL,
default_payment_next_month INTEGER NOT NULL);"""
conn = create_connection(database)
if conn is not None:
create_table(conn,sql_create_credit_table)
else:
print("Error: cannot create the database connection.")
if __name__ == '__main__':
main()