-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage_db.py
52 lines (44 loc) · 1.41 KB
/
manage_db.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
import sqlite3 as sql
# loads the selected database for host view
def load_database(path, filename):
conn = sql.connect(path+filename)
conn.row_factory = sql.Row
c = conn.cursor()
# create the table if doesn't exist
print("creating table")
c.execute('''CREATE TABLE IF NOT EXISTS hosts(
host_id INTEGER PRIMARY KEY,
hostname TEXT,
ip TEXT,
port INTEGER,
service TEXT,
continent TEXT,
country TEXT,
city TEXT,
lat TEXT,
long TEXT,
img_file TEXT,
UNIQUE(ip, port))''')
conn.commit()
c.execute("SELECT * FROM hosts")
rows = c.fetchall()
return rows
# will create a database but not open it within the host view
def create_db(path, filename):
conn = sql.connect(path+filename)
c = conn.cursor()
# create the table if doesn't exist
c.execute('''CREATE TABLE IF NOT EXISTS hosts(
host_id INTEGER PRIMARY KEY,
hostname TEXT,
ip TEXT,
port INTEGER,
service TEXT,
continent TEXT,
country TEXT,
city TEXT,
lat TEXT,
long TEXT,
img_file TEXT,
UNIQUE(ip, port))''')
conn.commit()